Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2017 07:48
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 anonymous/82acf9ff31961df031e2928a5457f6d1 to your computer and use it in GitHub Desktop.
Save anonymous/82acf9ff31961df031e2928a5457f6d1 to your computer and use it in GitHub Desktop.
#include <tuple>
#include <typeinfo>
#include <type_traits>
#include <iostream>
template <typename F>
struct make_tuple_of_params;
template <typename Ret, typename... Args>
struct make_tuple_of_params<Ret(*)(Args...)>
{
using type = std::tuple<Args...>;
};
template <typename F>
using make_tuple_of_params_t = typename make_tuple_of_params<F>::type;
template <typename F, typename Tuple, std::size_t... I>
void dispatch_to_c(F f, Tuple & t, std::index_sequence<I...>)
{
f(std::get<I>(t)...);
}
template <typename F, typename P>
void magic_wand(F f, P& p)
{
static constexpr auto t_count = std::tuple_size<P>::value;
dispatch_to_c(f,p, std::make_index_sequence<t_count>());
}
bool test_func(int in1, float in2, int* out1, float* out2)
{
*out1 = in1;
*out2 = in2;
return true;
}
int main(int argc, char** argv)
{
int o1;
float o2;
magic_wand(test_func, std::make_tuple(1,2.0f,&o1,&o2));
std::cout << o1 << "\n" << o2 << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment