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

前端 未结 4 1705
南方客
南方客 2020-11-30 05:38

Is the absence of

std::array::array(const T& value);

an oversight? It seems mighty useful to me, and dynamic containers (

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 05:59

    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).

提交回复
热议问题