I need to convert a boost::tuple
to the corresponding boost::fusion::tuple
. I have figured out the corresponding type.
But I expect there is an inbuilt function to do this. I really don't want to reinvent such things. I have searched in the boost fusion documentation but didn't find any.
c++14 version:
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) );
}
I am unaware of a built-in version.
Add trailing -> decltype(boost::fusion::make_tuple( get<Is>(std::forward<T>(in))... ))
in c++11. You also need make_index_sequence
, which probably has a boost equivalent.