Created
February 20, 2014 10:30
-
-
Save Fuyutsubaki/9110821 to your computer and use it in GitHub Desktop.
[std::function<R(Args...)>] → [std::function<R(std::tuple<Args...>)]
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<functional> | |
#include<tuple> | |
namespace tupleple | |
{ | |
namespace deteil{ | |
template<size_t ...R> | |
struct size_t_List{}; | |
template<size_t N> | |
class make_size_t_List | |
{ | |
template<class T>struct Inc; | |
template<size_t ...R> | |
struct Inc<size_t_List<R...>> | |
{ | |
using type = size_t_List<0, (R + 1)...>; | |
}; | |
public: | |
using type = typename Inc<typename make_size_t_List<N - 1>::type>::type; | |
}; | |
template<> | |
struct make_size_t_List<0> | |
{ | |
using type = size_t_List<>; | |
}; | |
template<class R, class ...Args, size_t ...N > | |
std::function<R(std::tuple<Args...>&&)> fuse_cast_impl(const std::function<R(Args...)>&func, size_t_List<N...>) | |
{ | |
return [=](std::tuple<Args...>&&tuple) | |
{ | |
return func(std::get<N>(tuple)...); | |
}; | |
} | |
} | |
template<class R, class ...Args> | |
std::function<R(std::tuple<Args...>&&)> fuse_cast(const std::function<R(Args...)>&func) | |
{ | |
using List = typename make_size_t_List<sizeof...(Args)>::type; | |
return n_cast_impl(func, List()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment