Created
April 28, 2017 07:48
-
-
Save anonymous/82acf9ff31961df031e2928a5457f6d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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