Skip to content

Instantly share code, notes, and snippets.

@heejune
Created August 16, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heejune/d17b0255251363343adc1a673404dd11 to your computer and use it in GitHub Desktop.
Save heejune/d17b0255251363343adc1a673404dd11 to your computer and use it in GitHub Desktop.
struct routing_record
{
virtual reply handle(void*) abstract;
};
template <typename T>
struct typed_routing_recored;
template <typename RetType, typename classTy, typename... ArgType>
struct typed_routing_recored<RetType(classTy::*)(ArgType...) const> : public routing_record
{
std::function<RetType(ArgType...)> stdfn;
typed_routing_recored(RetType(*pfn)(ArgType...))
: stdfn(pfn) {}
virtual reply handle(void* args) override
{
static const std::size_t typesize = sizeof...(ArgType);
auto tuple = static_cast<std::tuple<typename std::decay<ArgType>::type...>*> (args);
return _handle(*tuple, std::index_sequence_for<ArgType...>());
}
template <std::size_t... Is>
RetType _handle(const std::tuple<ArgType...>& tuple, std::index_sequence<Is...>)
{
return (stdfn)(std::get<Is>(tuple)...);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment