将boost::parameter_types转换为std::tuple



我相信有一些方法可以通过MPL和融合来实现这一点,但由于我是新手,所以很难弄清楚。

元组是std还是boost并不重要,我试图最终实现的是:

template<T>
void some_func()
{
// declare a tuple contains types of which in boost::function_types::parameter_types<T>
// insert values to the tuple
// call std::apply()
}

我尝试过使用fold,但没能弄清楚第三个模板参数中应该包含什么。

尚未对其进行测试,但以下内容应该有效:

#include <type_traits>
#include <tuple>
#include <boost/mpl/at.hpp> // For at
namespace detail {
template<class ParamSequence, std::size_t ...Indices>
auto unpack_params(ParamSequence, std::index_sequence<Indices...>) -> std::tuple<boost::mpl::at<ParamSequence, Indices>...>;
}
template<class Function>
using param_tuple_t = decltype(detail::unpack_params(boost::function_types::parameter_types<Function>(), std::make_index_sequence<boost::function_types::function_arity<Function>::value>()>()));

最新更新