Let's say I have a class without a default constructor called Foo
.
If I were using an std::vector
, I could do this:
std::vector<Foo> vec(100, Foo(5));
This would create a vector of 100 elements, each with value Foo(5)
.
How do I do the same with std::array<Foo, 100>
?
I obviously do not want to list out Foo(5)
explicitly 100 times in an initializer list. And yet I cannot wait till after the array is constructed to initialize it, since the lack of default constructor will produce a compiler error.
Bonus points for a solution that allows me to avoid the copy constructor as well, by supplying explicit constructor arguments similar to "placement new" or emplace
functions.