I need to initialize all elements of a std::array
with a constant value, like it can be done with std::vector
.
#include <vector>
#include <array>
int main()
{
std::vector<int> v(10, 7); // OK
std::array<int, 10> a(7); // does not compile, pretty frustrating
}
Is there a way to do this elegantly?
Right now I'm using this:
std::array<int, 10> a;
for (auto & v : a)
v = 7;
but I'd like to avoid using explicit code for the initialisation.