Ís it possible to create a vector from an integer sequence?

Hi,

Is it possible to fill an array with an integer sequence inspired by an idea like so: (I know it does not compile... it's just an idea)

1
2
3
4
		vector<int> vec;
		using seq = make_integer_sequence<int, 10>;
		vec[i] = std::get<i>(seq)...


I am aware of code to create a tuple from an array, like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
// Convert array into a tuple
template<typename Array, std::size_t... I>
decltype(auto) a2t_impl(const Array& a, std::index_sequence<I...>)
{
    return std::make_tuple(a[I]...);
}
 
template<typename T, std::size_t N, typename Indices = std::make_index_sequence<N>>
decltype(auto) a2t(const std::array<T, N>& a)
{
    return a2t_impl(a, Indices());
}



Ideas?

Thanks,
Juan
Last edited on
1
2
3
4
5
template < typename T, T... VALUES >
std::vector<T> make_vector() { return std::vector<T> { VALUES... } ; }

template < typename T, T... VALUES >
std::vector<T> make_vector( std::integer_sequence<T,VALUES...> ) { return make_vector<T,VALUES...>() ; }

http://coliru.stacked-crooked.com/a/960dd1a7061f47f8
Thanks JLBorges!! As always you provide the perfect answer!!

Juan
Topic archived. No new replies allowed.