Why does std::array not have an constructor that takes a value for the array to be filled with?

std::array is, by design, an aggregate, so has no user-declared constructors.

As you say, you could use fill after default constructing. Since it’s an aggregate, default construction won’t zero the memory, but will leave it uninitialised (if the contained type is trivially initialisable).

Leave a Comment