//#include <tuple>
template <typename Array, std::size_t... N>
decltype(auto) array2tuple_impl(const Array &a, std::index_sequence<N...>)
{
return std::make_tuple(a[N]...);
}
template <typename T, std::size_t N>
decltype(auto) array2tuple(const std::array<T, N> &a)
{
return array2tuple_impl(a, std::make_index_sequence<N>{});
}
template <typename T, typename... U, unsigned... N>
decltype(auto) tuple2array_impl(std::tuple<U...> &t, std::index_sequence<N...>)
{
return std::array<T, sizeof...(U)>{{std::get<N>(t)...}};
}
template <typename T, typename... U>
decltype(auto) tuple2array(std::tuple<U...> t)
{
return tuple2array_impl<T>(t, std::make_index_sequence<sizeof...(U)>{});
}
网友评论