简体   繁体   English

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

[英]Convert boost::parameter_types to std::tuple

I believe there are some ways to do this with MPL and fusion, but since I'm new to boost, it's kinda hard to figure out.我相信有一些方法可以用 MPL 和融合来做到这一点,但由于我是新手,所以很难弄清楚。

It doesn't matter whether the tuple is of std's or boost's, what I'm trying to ultimately achieve is:不管元组是 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()
}

I've tried using fold, but failed to figure out what should be in the third template argument.我试过使用 fold,但未能弄清楚第三个模板参数中应该包含什么。

Haven't tested it, but the following should work:还没有测试过,但以下应该有效:

#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>()>()));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM