From ae6c005b87a1b19170a3dcb9736f98cd28225719 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sat, 27 Jan 2024 19:09:47 +0800 Subject: [PATCH 1/7] simplify router --- examples/client/main.cpp | 10 ++-- examples/server/main.cpp | 14 ++--- include/rest_rpc/connection.h | 13 ++++- include/rest_rpc/router.h | 106 ++++++++++++++++------------------ include/rest_rpc/rpc_server.h | 8 +-- 5 files changed, 77 insertions(+), 74 deletions(-) diff --git a/examples/client/main.cpp b/examples/client/main.cpp index c35d60a..bd12645 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -217,7 +217,7 @@ void test_echo() { } { - auto result = client.call("async_echo", "test"); + auto result = client.call("delay_echo", "test"); std::cout << result << std::endl; } } @@ -349,11 +349,11 @@ void test_callback() { rpc_client client; bool r = client.connect("127.0.0.1", 9000); - for (size_t i = 0; i < 100; i++) { + for (size_t i = 0; i < 10; i++) { std::string test = "test" + std::to_string(i + 1); // set timeout 100ms - client.async_call<100>( - "async_echo", + client.async_call<10000>( + "delay_echo", [](const asio::error_code &ec, string_view data) { if (ec) { std::cout << ec.value() << " timeout" << std::endl; @@ -361,7 +361,7 @@ void test_callback() { } auto str = as(data); - std::cout << "echo " << str << '\n'; + std::cout << "delay echo " << str << '\n'; }, test); diff --git a/examples/server/main.cpp b/examples/server/main.cpp index 3305c90..47da07f 100644 --- a/examples/server/main.cpp +++ b/examples/server/main.cpp @@ -75,11 +75,11 @@ std::string get_name(rpc_conn conn, const person &p) { // if you want to response later, you can use async model, you can control when // to response -void async_echo(rpc_conn conn, const std::string &src) { - auto req_id = - conn.lock()->request_id(); // note: you need keep the request id at that - // time, and pass it into the async thread - +void delay_echo(rpc_conn conn, const std::string &src) { + auto sp = conn.lock(); + sp->set_delay(true); + auto req_id = sp->request_id(); // note: you need keep the request id at that + // time, and pass it into the async thread std::thread thd([conn, req_id, src] { std::this_thread::sleep_for(std::chrono::seconds(1)); auto conn_sp = conn.lock(); @@ -121,7 +121,7 @@ dummy1 get_dummy(rpc_conn conn, dummy1 d) { return d; } int main() { // benchmark_test(); - rpc_server server(9000, std::thread::hardware_concurrency()); + rpc_server server(9000, std::thread::hardware_concurrency(), 3600); dummy d; server.register_handler("add", &dummy::add, &d); @@ -135,7 +135,7 @@ int main() { server.register_handler("upload", upload); server.register_handler("download", download); server.register_handler("get_name", get_name); - server.register_handler("async_echo", async_echo); + server.register_handler("delay_echo", delay_echo); server.register_handler("echo", echo); server.register_handler("get_int", get_int); diff --git a/include/rest_rpc/connection.h b/include/rest_rpc/connection.h index 1690aa3..7219e74 100644 --- a/include/rest_rpc/connection.h +++ b/include/rest_rpc/connection.h @@ -101,6 +101,8 @@ class connection : public std::enable_shared_from_this, callback_ = std::move(callback); } + void set_delay(bool delay) { delay_ = delay; } + void on_network_error(std::function, std::string)> &on_net_err) { on_net_err_ = &on_net_err; @@ -208,8 +210,14 @@ class connection : public std::enable_shared_from_this, if (!ec) { read_head(); if (req_type_ == request_type::req_res) { - router_.route(func_id, body_.data(), length, - this->shared_from_this()); + route_result_t ret = router_.route( + func_id, nonstd::string_view{body_.data(), length}, + this->shared_from_this()); + if (delay_) { + delay_ = false; + } else { + response(req_id_, std::move(ret.result)); + } } else if (req_type_ == request_type::sub_pub) { try { msgpack_codec codec; @@ -420,6 +428,7 @@ class connection : public std::enable_shared_from_this, nullptr; router &router_; nonstd::any user_data_; + bool delay_ = false; }; } // namespace rpc_service } // namespace rest_rpc diff --git a/include/rest_rpc/router.h b/include/rest_rpc/router.h index 1cde1dc..8f7d268 100644 --- a/include/rest_rpc/router.h +++ b/include/rest_rpc/router.h @@ -4,33 +4,38 @@ #include "codec.h" #include "md5.hpp" #include "meta_util.hpp" +#include "string_view.hpp" #include "use_asio.hpp" #include #include #include namespace rest_rpc { -enum class ExecMode { sync, async }; -const constexpr ExecMode Async = ExecMode::async; - namespace rpc_service { class connection; +enum class router_error { ok, no_such_function, has_exception, unkonw }; + +struct route_result_t { + router_error ec = router_error::unkonw; + std::string result; +}; + class router : asio::noncopyable { public: - template + template void register_handler(std::string const &name, Function f) { uint32_t key = MD5::MD5Hash32(name.data()); key2func_name_.emplace(key, name); - return register_nonmember_func(key, std::move(f)); + return register_nonmember_func(key, std::move(f)); } - template + template void register_handler(std::string const &name, const Function &f, Self *self) { uint32_t key = MD5::MD5Hash32(name.data()); key2func_name_.emplace(key, name); - return register_member_func(key, f, self); + return register_member_func(key, f, self); } void remove_handler(std::string const &name) { @@ -48,14 +53,9 @@ class router : asio::noncopyable { } template - void route(uint32_t key, const char *data, std::size_t size, - std::weak_ptr conn) { - auto conn_sp = conn.lock(); - if (!conn_sp) { - return; - } - - auto req_id = conn_sp->request_id(); + route_result_t route(uint32_t key, nonstd::string_view data, + std::weak_ptr conn) { + route_result_t route_result{}; std::string result; try { msgpack_codec codec; @@ -63,26 +63,28 @@ class router : asio::noncopyable { if (it == map_invokers_.end()) { result = codec.pack_args_str( result_code::FAIL, "unknown function: " + get_name_by_key(key)); - conn_sp->response(req_id, std::move(result)); - return; - } - - ExecMode model; - it->second(conn, data, size, result, model); - if (model == ExecMode::sync) { - if (result.size() >= MAX_BUF_LEN) { - result = codec.pack_args_str( - result_code::FAIL, - "the response result is out of range: more than 10M " + - get_name_by_key(key)); - } - conn_sp->response(req_id, std::move(result)); + route_result.ec = router_error::no_such_function; + } else { + it->second(conn, data, result); + route_result.ec = router_error::ok; } } catch (const std::exception &ex) { msgpack_codec codec; - result = codec.pack_args_str(result_code::FAIL, ex.what()); - conn_sp->response(req_id, std::move(result)); + result = codec.pack_args_str( + result_code::FAIL, + std::string("exception occur when call").append(ex.what())); + route_result.ec = router_error::has_exception; + } catch (...) { + msgpack_codec codec; + result = codec.pack_args_str( + result_code::FAIL, std::string("unknown exception occur when call ") + .append(get_name_by_key(key))); + route_result.ec = router_error::no_such_function; } + + route_result.result = std::move(result); + + return route_result; } router() = default; @@ -152,19 +154,15 @@ class router : asio::noncopyable { result = msgpack_codec::pack_args_str(result_code::OK, r); } - template struct invoker { - template + template struct invoker { static inline void apply(const Function &func, - std::weak_ptr conn, const char *data, - size_t size, std::string &result, - ExecMode &exe_model) { + std::weak_ptr conn, + nonstd::string_view str, std::string &result) { using args_tuple = typename function_traits::bare_tuple_type; - exe_model = ExecMode::sync; msgpack_codec codec; try { - auto tp = codec.unpack(data, size); + auto tp = codec.unpack(str.data(), str.size()); call(func, conn, result, std::move(tp)); - exe_model = model; } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } catch (const std::exception &e) { @@ -172,18 +170,16 @@ class router : asio::noncopyable { } } - template + template static inline void apply_member(const Function &func, Self *self, std::weak_ptr conn, - const char *data, size_t size, - std::string &result, ExecMode &exe_model) { + nonstd::string_view str, + std::string &result) { using args_tuple = typename function_traits::bare_tuple_type; - exe_model = ExecMode::sync; msgpack_codec codec; try { - auto tp = codec.unpack(data, size); + auto tp = codec.unpack(str.data(), str.size()); call_member(func, self, conn, result, std::move(tp)); - exe_model = model; } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } catch (const std::exception &e) { @@ -192,25 +188,23 @@ class router : asio::noncopyable { } }; - template + template void register_nonmember_func(uint32_t key, Function f) { this->map_invokers_[key] = {std::bind( - &invoker::template apply, std::move(f), - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5)}; + &invoker::apply, std::move(f), std::placeholders::_1, + std::placeholders::_2, std::placeholders::_3)}; } - template + template void register_member_func(uint32_t key, const Function &f, Self *self) { this->map_invokers_[key] = {std::bind( - &invoker::template apply_member, f, self, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5)}; + &invoker::template apply_member, f, self, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}; } - std::unordered_map< - uint32_t, std::function, const char *, - size_t, std::string &, ExecMode &model)>> + std::unordered_map, + nonstd::string_view, std::string &)>> map_invokers_; std::unordered_map key2func_name_; }; diff --git a/include/rest_rpc/rpc_server.h b/include/rest_rpc/rpc_server.h index 9aab7f2..28f3126 100644 --- a/include/rest_rpc/rpc_server.h +++ b/include/rest_rpc/rpc_server.h @@ -52,15 +52,15 @@ class rpc_server : private asio::noncopyable { void run() { io_service_pool_.run(); } - template + template void register_handler(std::string const &name, const Function &f) { - router_.register_handler(name, f); + router_.register_handler(name, f); } - template + template void register_handler(std::string const &name, const Function &f, Self *self) { - router_.register_handler(name, f, self); + router_.register_handler(name, f, self); } void set_conn_timeout_callback(std::function callback) { From 7b7714ceb4f929b46de13857278f985f94742925 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sat, 27 Jan 2024 19:53:55 +0800 Subject: [PATCH 2/7] simplify router --- include/rest_rpc/router.h | 42 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/include/rest_rpc/router.h b/include/rest_rpc/router.h index 8f7d268..bd1449c 100644 --- a/include/rest_rpc/router.h +++ b/include/rest_rpc/router.h @@ -154,52 +154,40 @@ class router : asio::noncopyable { result = msgpack_codec::pack_args_str(result_code::OK, r); } - template struct invoker { - static inline void apply(const Function &func, - std::weak_ptr conn, - nonstd::string_view str, std::string &result) { + template + void register_nonmember_func(uint32_t key, Function f) { + this->map_invokers_[key] = [f](std::weak_ptr conn, + nonstd::string_view str, + std::string &result) { using args_tuple = typename function_traits::bare_tuple_type; msgpack_codec codec; try { auto tp = codec.unpack(str.data(), str.size()); - call(func, conn, result, std::move(tp)); + call(f, conn, result, std::move(tp)); } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } catch (const std::exception &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } - } + }; + } - template - static inline void apply_member(const Function &func, Self *self, - std::weak_ptr conn, - nonstd::string_view str, - std::string &result) { + template + void register_member_func(uint32_t key, const Function &f, Self *self) { + this->map_invokers_[key] = [f, self](std::weak_ptr conn, + nonstd::string_view str, + std::string &result) { using args_tuple = typename function_traits::bare_tuple_type; msgpack_codec codec; try { auto tp = codec.unpack(str.data(), str.size()); - call_member(func, self, conn, result, std::move(tp)); + call_member(f, self, conn, result, std::move(tp)); } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } catch (const std::exception &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); } - } - }; - - template - void register_nonmember_func(uint32_t key, Function f) { - this->map_invokers_[key] = {std::bind( - &invoker::apply, std::move(f), std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3)}; - } - - template - void register_member_func(uint32_t key, const Function &f, Self *self) { - this->map_invokers_[key] = {std::bind( - &invoker::template apply_member, f, self, - std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)}; + }; } std::unordered_map Date: Sat, 27 Jan 2024 20:39:08 +0800 Subject: [PATCH 3/7] improve --- include/rest_rpc/router.h | 40 +++++++++++++++++++++++++++++------ include/rest_rpc/rpc_server.h | 8 +++---- tests/test_rest_rpc.cpp | 13 +++++++----- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/include/rest_rpc/router.h b/include/rest_rpc/router.h index bd1449c..e4bf9b1 100644 --- a/include/rest_rpc/router.h +++ b/include/rest_rpc/router.h @@ -21,21 +21,45 @@ struct route_result_t { std::string result; }; +template class helper_t { +public: + helper_t(Tuple &tp) : tp_(tp) {} + + void operator()() {} + +private: + Tuple &tp_; +}; + +template class helper_t { +public: + helper_t(Tuple &tp) : tp_(tp) {} + + void operator()() { + auto &arg = std::get::value - 1>(tp_); + msgpack_codec codec; + arg = codec.unpack(arg.data(), arg.size()); + } + +private: + Tuple &tp_; +}; + class router : asio::noncopyable { public: - template - void register_handler(std::string const &name, Function f) { + template + void register_handler(std::string const &name, Function f, bool pub = false) { uint32_t key = MD5::MD5Hash32(name.data()); key2func_name_.emplace(key, name); - return register_nonmember_func(key, std::move(f)); + return register_nonmember_func(key, std::move(f)); } - template + template void register_handler(std::string const &name, const Function &f, Self *self) { uint32_t key = MD5::MD5Hash32(name.data()); key2func_name_.emplace(key, name); - return register_member_func(key, f, self); + return register_member_func(key, f, self); } void remove_handler(std::string const &name) { @@ -154,7 +178,7 @@ class router : asio::noncopyable { result = msgpack_codec::pack_args_str(result_code::OK, r); } - template + template void register_nonmember_func(uint32_t key, Function f) { this->map_invokers_[key] = [f](std::weak_ptr conn, nonstd::string_view str, @@ -163,6 +187,7 @@ class router : asio::noncopyable { msgpack_codec codec; try { auto tp = codec.unpack(str.data(), str.size()); + helper_t{tp}(); call(f, conn, result, std::move(tp)); } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); @@ -172,7 +197,7 @@ class router : asio::noncopyable { }; } - template + template void register_member_func(uint32_t key, const Function &f, Self *self) { this->map_invokers_[key] = [f, self](std::weak_ptr conn, nonstd::string_view str, @@ -181,6 +206,7 @@ class router : asio::noncopyable { msgpack_codec codec; try { auto tp = codec.unpack(str.data(), str.size()); + helper_t{tp}(); call_member(f, self, conn, result, std::move(tp)); } catch (std::invalid_argument &e) { result = codec.pack_args_str(result_code::FAIL, e.what()); diff --git a/include/rest_rpc/rpc_server.h b/include/rest_rpc/rpc_server.h index 28f3126..11fcfa0 100644 --- a/include/rest_rpc/rpc_server.h +++ b/include/rest_rpc/rpc_server.h @@ -52,15 +52,15 @@ class rpc_server : private asio::noncopyable { void run() { io_service_pool_.run(); } - template + template void register_handler(std::string const &name, const Function &f) { - router_.register_handler(name, f); + router_.register_handler(name, f); } - template + template void register_handler(std::string const &name, const Function &f, Self *self) { - router_.register_handler(name, f, self); + router_.register_handler(name, f, self); } void set_conn_timeout_callback(std::function callback) { diff --git a/tests/test_rest_rpc.cpp b/tests/test_rest_rpc.cpp index 9b7f291..f3048a5 100644 --- a/tests/test_rest_rpc.cpp +++ b/tests/test_rest_rpc.cpp @@ -204,11 +204,12 @@ TEST_CASE("test_client_async_call_with_timeout") { TEST_CASE("test_client_subscribe") { rpc_server server(9000, std::thread::hardware_concurrency()); - server.register_handler("publish", - [&server](rpc_conn conn, std::string key, - std::string token, std::string val) { - server.publish(std::move(key), std::move(val)); - }); + server.register_handler( + "publish", [&server](rpc_conn conn, std::string key, std::string token, + std::string val) { + CHECK(val == "hello subscriber"); + server.publish(std::move(key), std::move(val)); + }); bool stop = false; std::thread thd([&server, &stop] { while (!stop) { @@ -221,6 +222,8 @@ TEST_CASE("test_client_subscribe") { rpc_client client; bool r = client.connect("127.0.0.1", 9000); CHECK(r); + client.publish("key", "hello subscriber"); + client.subscribe("key", [&stop](string_view data) { std::cout << data << "\n"; CHECK_EQ(data, "hello subscriber"); From a98f331dd170936059eb8498550f716aa97ac612 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 28 Jan 2024 09:18:10 +0800 Subject: [PATCH 4/7] nonstd --- include/rest_rpc/cplusplus_14.h | 29 ++++++++++++++++------------- include/rest_rpc/meta_util.hpp | 27 ++++++++++++++------------- include/rest_rpc/router.h | 14 +++++++------- 3 files changed, 37 insertions(+), 33 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; +using enable_if_t = typename std::enable_if::type; -template using remove_const_t = typename remove_const::type; +template +using remove_const_t = typename std::remove_const::type; template -using remove_reference_t = typename remove_reference::type; +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 @@ struct function_traits { 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 @@ class router : asio::noncopyable { 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 @@ class router : asio::noncopyable { 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 @@ class router : asio::noncopyable { 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 @@ class router : asio::noncopyable { 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 @@ class router : asio::noncopyable { 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 @@ class router : asio::noncopyable { 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); } From 6b2694116ff99764f278e0daf4572b15ba4e957f Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 28 Jan 2024 09:23:59 +0800 Subject: [PATCH 5/7] fix compile --- include/rest_rpc/cplusplus_14.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/rest_rpc/cplusplus_14.h b/include/rest_rpc/cplusplus_14.h index 6ae4298..c01a7c7 100644 --- a/include/rest_rpc/cplusplus_14.h +++ b/include/rest_rpc/cplusplus_14.h @@ -22,12 +22,12 @@ template struct unique_if { template typename unique_if::single_object make_unique(Args &&...args) { - return unique_ptr(new T(forward(args)...)); + return std::unique_ptr(new T(forward(args)...)); } template typename unique_if::unknown_bound make_unique(size_t n) { typedef typename std::remove_extent::type U; - return unique_ptr(new U[n]()); + return std::unique_ptr(new U[n]()); } template From eb959542d14f9d7d0b2619111545c79af6e843e7 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 28 Jan 2024 09:25:31 +0800 Subject: [PATCH 6/7] compile --- include/rest_rpc/cplusplus_14.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/rest_rpc/cplusplus_14.h b/include/rest_rpc/cplusplus_14.h index c01a7c7..0eb841e 100644 --- a/include/rest_rpc/cplusplus_14.h +++ b/include/rest_rpc/cplusplus_14.h @@ -22,7 +22,7 @@ template struct unique_if { template typename unique_if::single_object make_unique(Args &&...args) { - return std::unique_ptr(new T(forward(args)...)); + return std::unique_ptr(new T(std::forward(args)...)); } template typename unique_if::unknown_bound make_unique(size_t n) { From 706a38b5ac1bfd41a4dbf713ec3ec5cb964c9f43 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Sun, 28 Jan 2024 09:50:47 +0800 Subject: [PATCH 7/7] compile --- include/rest_rpc/cplusplus_14.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/rest_rpc/cplusplus_14.h b/include/rest_rpc/cplusplus_14.h index 0eb841e..cda912a 100644 --- a/include/rest_rpc/cplusplus_14.h +++ b/include/rest_rpc/cplusplus_14.h @@ -5,8 +5,6 @@ #include #include -#if __cplusplus == 201103L - namespace nonstd { template struct unique_if { typedef std::unique_ptr single_object; @@ -97,6 +95,4 @@ auto invoke(F &&f, Args &&...args) } // namespace nonstd -#endif - #endif // REST_RPC_CPLUSPLUS_14_H_