#pragma once #ifndef CALL_H_ZXFACADH #define CALL_H_ZXFACADH #include #include "rpc/detail/func_tools.h" #include "rpc/detail/invoke.h" #include "rpc/detail/is_specialization_of.h" namespace rpc { namespace detail { //! \brief Calls a functor with argument provided directly template auto call(Functor f, Arg &&arg) -> decltype(f(std::forward(arg))) { return f(std::forward(arg)); } // Default behaviour is to assume C++11, overriding RPCLIB_CXX_STANDARD can use // newer standards: #if RPCLIB_CXX_STANDARD >= 14 template decltype(auto) call_helper(Functor func, std::tuple &¶ms, std::index_sequence) { return func(std::get(params)...); } //! \brief Calls a functor with arguments provided as a tuple template decltype(auto) call(Functor f, std::tuple &args) { return call_helper(f, std::forward>(args), std::index_sequence_for{}); } #else // N is number of arguments left in tuple to unpack template struct call_helper { template static auto call( Functor f, std::tuple& args_t, ArgsF&&... args_f) -> decltype(call_helper::call( f, args_t, std::get(args_t), std::forward(args_f)...)) { return call_helper::call( f, args_t, std::get(args_t), std::forward(args_f)... ); } }; template <> struct call_helper<0> { template static auto call( Functor f, std::tuple&, ArgsF&&... args_f) -> decltype(f(std::forward(args_f)...)) { return f(std::forward(args_f)...); } }; //! \brief Calls a functor with arguments provided as a tuple template auto call(Functor f, std::tuple& args_t) -> decltype(call_helper::call(f, args_t)) { return call_helper::call(f, args_t); } #endif } } #endif /* end of include guard: CALL_H_ZXFACADH */