将 `boost::tuple` 转换为 `boost::fusion::tuple`
convert `boost::tuple` to `boost::fusion::tuple`
我需要将 boost::tuple
转换为对应的 boost::fusion::tuple
。我已经弄清楚对应的类型了
但我希望有一个内置函数可以执行此操作。我真的不想重新发明这样的东西。我在 boost fusion 文档中进行了搜索,但没有找到任何内容。
c++14版本:
template<std::size_t...Is, class T>
auto to_fusion( std::index_sequence<Is...>, T&& in ) {
using std::get;
return boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... );
}
template<class...Ts>
auto to_fusion( boost::tuple<Ts...> in ) {
return to_fusion( std::make_index_sequence<::boost::tuples::length< boost::tuple<Ts...>>::value>{}, std::move(in) );
}
template<class...Ts>
boost::fusion::tuple<Ts...> to_fusion( std::tuple<Ts...> in ) {
return to_fusion( std::make_index_sequence<sizeof...(Ts)>{}, std::move(in) );
}
我不知道内置版本。
在 c++11 中添加尾随 -> decltype(boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... ))
。您还需要 make_index_sequence
,它可能具有等效的提升效果。
您可以使用类似的东西:
template <class Tuple>
auto to_fusion(Tuple&& tuple)
{
std::apply(
[](auto&&... args){
return boost::fusion::make_tuple(decltype(args)(args)...);
},
std::forward<Tuple>(tuple));
}
我需要将 boost::tuple
转换为对应的 boost::fusion::tuple
。我已经弄清楚对应的类型了
但我希望有一个内置函数可以执行此操作。我真的不想重新发明这样的东西。我在 boost fusion 文档中进行了搜索,但没有找到任何内容。
c++14版本:
template<std::size_t...Is, class T>
auto to_fusion( std::index_sequence<Is...>, T&& in ) {
using std::get;
return boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... );
}
template<class...Ts>
auto to_fusion( boost::tuple<Ts...> in ) {
return to_fusion( std::make_index_sequence<::boost::tuples::length< boost::tuple<Ts...>>::value>{}, std::move(in) );
}
template<class...Ts>
boost::fusion::tuple<Ts...> to_fusion( std::tuple<Ts...> in ) {
return to_fusion( std::make_index_sequence<sizeof...(Ts)>{}, std::move(in) );
}
我不知道内置版本。
在 c++11 中添加尾随 -> decltype(boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... ))
。您还需要 make_index_sequence
,它可能具有等效的提升效果。
您可以使用类似的东西:
template <class Tuple>
auto to_fusion(Tuple&& tuple)
{
std::apply(
[](auto&&... args){
return boost::fusion::make_tuple(decltype(args)(args)...);
},
std::forward<Tuple>(tuple));
}