我需要将一个boost::tuple转换为相应的boost::fusion::tuple。我已经算出了相应的类型。
但我希望有一个内置的功能来做到这一点。我真的不想再发明这些东西了。我在boost融合文档中搜索过,但没有找到。
发布于 2018-10-05 14:17:34
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) );
}我不知道有一个内置版本。
在-> decltype(boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... ))中添加尾随c++11。您还需要make_index_sequence,它可能具有相当的助推功能。
实例化。
发布于 2018-10-05 14:26:05
你可以使用这样的方法:
template <class Tuple>
auto to_fusion(Tuple&& tuple)
{
std::apply(
[](auto&&... args){
return boost::fusion::make_tuple(decltype(args)(args)...);
},
std::forward<Tuple>(tuple));
}https://stackoverflow.com/questions/52667527
复制相似问题