From a98f331dd170936059eb8498550f716aa97ac612 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 28 Jan 2024 09:18:10 +0800 Subject: [PATCH] nonstd --- include/rest_rpc/cplusplus_14.h | 31 +++++++++++++++++-------------- include/rest_rpc/meta_util.hpp | 27 ++++++++++++++------------- include/rest_rpc/router.h | 14 +++++++------- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/include/rest_rpc/cplusplus_14.h b/include/rest_rpc/cplusplus_14.h index ac95c98..6ae4298 100644 --- a/include/rest_rpc/cplusplus_14.h +++ b/include/rest_rpc/cplusplus_14.h @@ -7,11 +7,13 @@ #if __cplusplus == 201103L -namespace std { -template struct unique_if { typedef unique_ptr single_object; }; +namespace nonstd { +template struct unique_if { + typedef std::unique_ptr single_object; +}; template struct unique_if { - typedef unique_ptr unknown_bound; + typedef std::unique_ptr unknown_bound; }; template struct unique_if { @@ -24,7 +26,7 @@ typename unique_if::single_object make_unique(Args &&...args) { } template typename unique_if::unknown_bound make_unique(size_t n) { - typedef typename remove_extent::type U; + typedef typename std::remove_extent::type U; return unique_ptr(new U[n]()); } @@ -59,20 +61,21 @@ template using index_sequence_for = make_index_sequence; template -using enable_if_t = typename enable_if::type; - -template using remove_const_t = typename remove_const::type; +using enable_if_t = typename std::enable_if::type; template -using remove_reference_t = typename remove_reference::type; +using remove_const_t = typename std::remove_const::type; + +template +using remove_reference_t = typename std::remove_reference::type; template -using tuple_element_t = typename tuple_element::type; +using tuple_element_t = typename std::tuple_element::type; -template using decay_t = typename decay::type; +template using decay_t = typename std::decay::type; template -auto apply_helper(F &&f, Tuple &&tp, std::index_sequence) +auto apply_helper(F &&f, Tuple &&tp, nonstd::index_sequence) -> decltype(std::forward(f)(std::get(std::forward(tp))...)) { return std::forward(f)(std::get(std::forward(tp))...); } @@ -80,10 +83,10 @@ auto apply_helper(F &&f, Tuple &&tp, std::index_sequence) template auto apply(F &&f, Tuple &&tp) -> decltype(apply_helper( std::forward(f), std::forward(tp), - std::make_index_sequence>::value>{})) { + make_index_sequence>::value>{})) { return apply_helper( std::forward(f), std::forward(tp), - std::make_index_sequence>::value>{}); + make_index_sequence>::value>{}); } template @@ -92,7 +95,7 @@ auto invoke(F &&f, Args &&...args) return std::forward(f)(std::forward(args)...); } -} // namespace std +} // namespace nonstd #endif diff --git a/include/rest_rpc/meta_util.hpp b/include/rest_rpc/meta_util.hpp index 8fb6a98..a2fe80e 100644 --- a/include/rest_rpc/meta_util.hpp +++ b/include/rest_rpc/meta_util.hpp @@ -8,13 +8,13 @@ namespace rest_rpc { template void for_each(const std::tuple &t, Func &&f, - std::index_sequence) { + nonstd::index_sequence) { (void)std::initializer_list{(f(std::get(t)), void(), 0)...}; } template void for_each_i(const std::tuple &t, Func &&f, - std::index_sequence) { + nonstd::index_sequence) { (void)std::initializer_list{ (f(std::get(t), std::integral_constant{}), void(), 0)...}; @@ -32,14 +32,15 @@ public: typedef Ret (*pointer)(Arg, Args...); typedef std::tuple tuple_type; - typedef std::tuple>...> + typedef std::tuple< + nonstd::remove_const_t>...> bare_tuple_type; using args_tuple = std::tuple>...>; + nonstd::remove_const_t>...>; using args_tuple_2nd = std::tuple>...>; + nonstd::remove_const_t>...>; }; template struct function_traits { @@ -76,24 +77,24 @@ struct function_traits : function_traits {}; template using remove_const_reference_t = - std::remove_const_t>; + nonstd::remove_const_t>; template -auto make_tuple_from_sequence(std::index_sequence) +auto make_tuple_from_sequence(nonstd::index_sequence) -> decltype(std::make_tuple(Is...)) { std::make_tuple(Is...); } template constexpr auto make_tuple_from_sequence() - -> decltype(make_tuple_from_sequence(std::make_index_sequence{})) { - return make_tuple_from_sequence(std::make_index_sequence{}); + -> decltype(make_tuple_from_sequence(nonstd::make_index_sequence{})) { + return make_tuple_from_sequence(nonstd::make_index_sequence{}); } namespace detail { template void tuple_switch(const std::size_t i, Tuple &&t, F &&f, - std::index_sequence) { + nonstd::index_sequence) { (void)std::initializer_list{ (i == Is && ((void)std::forward(f)(std::integral_constant{}), 0))...}; @@ -102,14 +103,14 @@ void tuple_switch(const std::size_t i, Tuple &&t, F &&f, template inline void tuple_switch(const std::size_t i, Tuple &&t, F &&f) { - constexpr auto N = std::tuple_size>::value; + constexpr auto N = std::tuple_size>::value; detail::tuple_switch(i, std::forward(t), std::forward(f), - std::make_index_sequence{}); + nonstd::make_index_sequence{}); } template -using nth_type_of = std::tuple_element_t>; +using nth_type_of = nonstd::tuple_element_t>; template using last_type_of = nth_type_of; diff --git a/include/rest_rpc/router.h b/include/rest_rpc/router.h index e4bf9b1..d9c4d06 100644 --- a/include/rest_rpc/router.h +++ b/include/rest_rpc/router.h @@ -119,7 +119,7 @@ private: template static typename std::result_of, Args...)>::type - call_helper(const F &f, const std::index_sequence &, + call_helper(const F &f, const nonstd::index_sequence &, std::tuple tup, std::weak_ptr ptr) { return f(ptr, std::move(std::get(tup))...); } @@ -129,8 +129,8 @@ private: F(std::weak_ptr, Args...)>::type>::value>::type call(const F &f, std::weak_ptr ptr, std::string &result, std::tuple tp) { - call_helper(f, std::make_index_sequence{}, std::move(tp), - ptr); + call_helper(f, nonstd::make_index_sequence{}, + std::move(tp), ptr); result = msgpack_codec::pack_args_str(result_code::OK); } @@ -139,7 +139,7 @@ private: F(std::weak_ptr, Args...)>::type>::value>::type call(const F &f, std::weak_ptr ptr, std::string &result, std::tuple tp) { - auto r = call_helper(f, std::make_index_sequence{}, + auto r = call_helper(f, nonstd::make_index_sequence{}, std::move(tp), ptr); msgpack_codec codec; result = msgpack_codec::pack_args_str(result_code::OK, r); @@ -149,7 +149,7 @@ private: static typename std::result_of, Args...)>::type call_member_helper(const F &f, Self *self, - const std::index_sequence &, + const nonstd::index_sequence &, std::tuple tup, std::weak_ptr ptr = std::shared_ptr{nullptr}) { @@ -162,7 +162,7 @@ private: call_member(const F &f, Self *self, std::weak_ptr ptr, std::string &result, std::tuple tp) { call_member_helper(f, self, - typename std::make_index_sequence{}, + typename nonstd::make_index_sequence{}, std::move(tp), ptr); result = msgpack_codec::pack_args_str(result_code::OK); } @@ -173,7 +173,7 @@ private: call_member(const F &f, Self *self, std::weak_ptr ptr, std::string &result, std::tuple tp) { auto r = call_member_helper( - f, self, typename std::make_index_sequence{}, + f, self, typename nonstd::make_index_sequence{}, std::move(tp), ptr); result = msgpack_codec::pack_args_str(result_code::OK, r); }