Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nonstd #128

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions include/rest_rpc/cplusplus_14.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include <tuple>
#include <type_traits>

#if __cplusplus == 201103L

namespace std {
template <class T> struct unique_if { typedef unique_ptr<T> single_object; };
namespace nonstd {
template <class T> struct unique_if {
typedef std::unique_ptr<T> single_object;
};

template <class T> struct unique_if<T[]> {
typedef unique_ptr<T[]> unknown_bound;
typedef std::unique_ptr<T[]> unknown_bound;
};

template <class T, size_t N> struct unique_if<T[N]> {
Expand All @@ -20,12 +20,12 @@ template <class T, size_t N> struct unique_if<T[N]> {

template <class T, class... Args>
typename unique_if<T>::single_object make_unique(Args &&...args) {
return unique_ptr<T>(new T(forward<Args>(args)...));
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}

template <class T> typename unique_if<T>::unknown_bound make_unique(size_t n) {
typedef typename remove_extent<T>::type U;
return unique_ptr<T>(new U[n]());
typedef typename std::remove_extent<T>::type U;
return std::unique_ptr<T>(new U[n]());
}

template <class T, class... Args>
Expand Down Expand Up @@ -59,31 +59,32 @@ template <typename... T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;

template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;
using enable_if_t = typename std::enable_if<B, T>::type;

template <typename T> using remove_const_t = typename remove_const<T>::type;
template <typename T>
using remove_const_t = typename std::remove_const<T>::type;

template <typename T>
using remove_reference_t = typename remove_reference<T>::type;
using remove_reference_t = typename std::remove_reference<T>::type;

template <int I, typename T>
using tuple_element_t = typename tuple_element<I, T>::type;
using tuple_element_t = typename std::tuple_element<I, T>::type;

template <typename T> using decay_t = typename decay<T>::type;
template <typename T> using decay_t = typename std::decay<T>::type;

template <typename F, typename Tuple, size_t... Idx>
auto apply_helper(F &&f, Tuple &&tp, std::index_sequence<Idx...>)
auto apply_helper(F &&f, Tuple &&tp, nonstd::index_sequence<Idx...>)
-> decltype(std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(tp))...)) {
return std::forward<F>(f)(std::get<Idx>(std::forward<Tuple>(tp))...);
}

template <typename F, typename Tuple>
auto apply(F &&f, Tuple &&tp) -> decltype(apply_helper(
std::forward<F>(f), std::forward<Tuple>(tp),
std::make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{})) {
make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{})) {
return apply_helper(
std::forward<F>(f), std::forward<Tuple>(tp),
std::make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{});
make_index_sequence<std::tuple_size<decay_t<Tuple>>::value>{});
}

template <typename F, typename... Args>
Expand All @@ -92,8 +93,6 @@ auto invoke(F &&f, Args &&...args)
return std::forward<F>(f)(std::forward<Args>(args)...);
}

} // namespace std

#endif
} // namespace nonstd

#endif // REST_RPC_CPLUSPLUS_14_H_
27 changes: 14 additions & 13 deletions include/rest_rpc/meta_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace rest_rpc {

template <typename... Args, typename Func, std::size_t... Idx>
void for_each(const std::tuple<Args...> &t, Func &&f,
std::index_sequence<Idx...>) {
nonstd::index_sequence<Idx...>) {
(void)std::initializer_list<int>{(f(std::get<Idx>(t)), void(), 0)...};
}

template <typename... Args, typename Func, std::size_t... Idx>
void for_each_i(const std::tuple<Args...> &t, Func &&f,
std::index_sequence<Idx...>) {
nonstd::index_sequence<Idx...>) {
(void)std::initializer_list<int>{
(f(std::get<Idx>(t), std::integral_constant<size_t, Idx>{}), void(),
0)...};
Expand All @@ -32,14 +32,15 @@ struct function_traits<Ret(Arg, Args...)> {
typedef Ret (*pointer)(Arg, Args...);

typedef std::tuple<Arg, Args...> tuple_type;
typedef std::tuple<std::remove_const_t<std::remove_reference_t<Args>>...>
typedef std::tuple<
nonstd::remove_const_t<nonstd::remove_reference_t<Args>>...>
bare_tuple_type;
using args_tuple =
std::tuple<std::string, Arg,
std::remove_const_t<std::remove_reference_t<Args>>...>;
nonstd::remove_const_t<nonstd::remove_reference_t<Args>>...>;
using args_tuple_2nd =
std::tuple<std::string,
std::remove_const_t<std::remove_reference_t<Args>>...>;
nonstd::remove_const_t<nonstd::remove_reference_t<Args>>...>;
};

template <typename Ret> struct function_traits<Ret()> {
Expand Down Expand Up @@ -76,24 +77,24 @@ struct function_traits : function_traits<decltype(&Callable::operator())> {};

template <typename T>
using remove_const_reference_t =
std::remove_const_t<std::remove_reference_t<T>>;
nonstd::remove_const_t<nonstd::remove_reference_t<T>>;

template <size_t... Is>
auto make_tuple_from_sequence(std::index_sequence<Is...>)
auto make_tuple_from_sequence(nonstd::index_sequence<Is...>)
-> decltype(std::make_tuple(Is...)) {
std::make_tuple(Is...);
}

template <size_t N>
constexpr auto make_tuple_from_sequence()
-> decltype(make_tuple_from_sequence(std::make_index_sequence<N>{})) {
return make_tuple_from_sequence(std::make_index_sequence<N>{});
-> decltype(make_tuple_from_sequence(nonstd::make_index_sequence<N>{})) {
return make_tuple_from_sequence(nonstd::make_index_sequence<N>{});
}

namespace detail {
template <class Tuple, class F, std::size_t... Is>
void tuple_switch(const std::size_t i, Tuple &&t, F &&f,
std::index_sequence<Is...>) {
nonstd::index_sequence<Is...>) {
(void)std::initializer_list<int>{
(i == Is &&
((void)std::forward<F>(f)(std::integral_constant<size_t, Is>{}), 0))...};
Expand All @@ -102,14 +103,14 @@ void tuple_switch(const std::size_t i, Tuple &&t, F &&f,

template <class Tuple, class F>
inline void tuple_switch(const std::size_t i, Tuple &&t, F &&f) {
constexpr auto N = std::tuple_size<std::remove_reference_t<Tuple>>::value;
constexpr auto N = std::tuple_size<nonstd::remove_reference_t<Tuple>>::value;

detail::tuple_switch(i, std::forward<Tuple>(t), std::forward<F>(f),
std::make_index_sequence<N>{});
nonstd::make_index_sequence<N>{});
}

template <int N, typename... Args>
using nth_type_of = std::tuple_element_t<N, std::tuple<Args...>>;
using nth_type_of = nonstd::tuple_element_t<N, std::tuple<Args...>>;

template <typename... Args>
using last_type_of = nth_type_of<sizeof...(Args) - 1, Args...>;
Expand Down
14 changes: 7 additions & 7 deletions include/rest_rpc/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class router : asio::noncopyable {

template <typename F, size_t... I, typename... Args>
static typename std::result_of<F(std::weak_ptr<connection>, Args...)>::type
call_helper(const F &f, const std::index_sequence<I...> &,
call_helper(const F &f, const nonstd::index_sequence<I...> &,
std::tuple<Args...> tup, std::weak_ptr<connection> ptr) {
return f(ptr, std::move(std::get<I>(tup))...);
}
Expand All @@ -129,8 +129,8 @@ class router : asio::noncopyable {
F(std::weak_ptr<connection>, Args...)>::type>::value>::type
call(const F &f, std::weak_ptr<connection> ptr, std::string &result,
std::tuple<Args...> tp) {
call_helper(f, std::make_index_sequence<sizeof...(Args)>{}, std::move(tp),
ptr);
call_helper(f, nonstd::make_index_sequence<sizeof...(Args)>{},
std::move(tp), ptr);
result = msgpack_codec::pack_args_str(result_code::OK);
}

Expand All @@ -139,7 +139,7 @@ class router : asio::noncopyable {
F(std::weak_ptr<connection>, Args...)>::type>::value>::type
call(const F &f, std::weak_ptr<connection> ptr, std::string &result,
std::tuple<Args...> tp) {
auto r = call_helper(f, std::make_index_sequence<sizeof...(Args)>{},
auto r = call_helper(f, nonstd::make_index_sequence<sizeof...(Args)>{},
std::move(tp), ptr);
msgpack_codec codec;
result = msgpack_codec::pack_args_str(result_code::OK, r);
Expand All @@ -149,7 +149,7 @@ class router : asio::noncopyable {
static
typename std::result_of<F(Self, std::weak_ptr<connection>, Args...)>::type
call_member_helper(const F &f, Self *self,
const std::index_sequence<Indexes...> &,
const nonstd::index_sequence<Indexes...> &,
std::tuple<Args...> tup,
std::weak_ptr<connection> ptr =
std::shared_ptr<connection>{nullptr}) {
Expand All @@ -162,7 +162,7 @@ class router : asio::noncopyable {
call_member(const F &f, Self *self, std::weak_ptr<connection> ptr,
std::string &result, std::tuple<Args...> tp) {
call_member_helper(f, self,
typename std::make_index_sequence<sizeof...(Args)>{},
typename nonstd::make_index_sequence<sizeof...(Args)>{},
std::move(tp), ptr);
result = msgpack_codec::pack_args_str(result_code::OK);
}
Expand All @@ -173,7 +173,7 @@ class router : asio::noncopyable {
call_member(const F &f, Self *self, std::weak_ptr<connection> ptr,
std::string &result, std::tuple<Args...> tp) {
auto r = call_member_helper(
f, self, typename std::make_index_sequence<sizeof...(Args)>{},
f, self, typename nonstd::make_index_sequence<sizeof...(Args)>{},
std::move(tp), ptr);
result = msgpack_codec::pack_args_str(result_code::OK, r);
}
Expand Down
Loading