If I have std::tuple (where the type is homogeneous), is there a stock function or constructor to convert to std::array
You can do it non-recursively:
#include
#include
#include // see below
template
using Array = std::array;
template
inline Array
tuple_to_array2(const std::tuple& t, redi::index_tuple)
{
return Array{ std::get(t)... };
}
template
inline Array
tuple_to_array(const std::tuple& t)
{
using IndexTuple = typename redi::make_index_tuple<1+sizeof...(U)>::type;
return tuple_to_array2(t, IndexTuple());
}
See https://gitlab.com/redistd/redistd/blob/master/include/redi/index_tuple.h for my implementation of index_tuple, something like that is useful for working with tuples and similar variadic templates. A similar utility was standardised as std::index_sequence in C++14 (see index_seq.h for a standalone C++11 implementation).