Reputation: 13575
Since std::array hasn't an explicit constructor and my compiler doesn't support initialization list. I'd like to make a std::array with a function like
template<class T, int N>
std::array<T, N> makeArray(T const& t0 = 0, T const& t1 = 0, T const& t2 = 0,
T const& t3 = 0, T const& t4 = 0, T const& t5 = 0,
T const& t6 = 0, T const& t7 = 0, T const& t8 = 0)
{
...
}
Just list 9 elements, can be more. How to implement the function?
Upvotes: 0
Views: 1122
Reputation: 208476
Implementing a make_array
is a bad idea in general, but the way to create an std::array
out of a set of values is using aggregate-initialization:
std::array<int,5> a = { 1, 2, 3, 4, 5 };
Note that it is not an std::initializer_list<int>
.
Upvotes: 4