Is `std::array` default constructible where `T` is not default constructible?

后端 未结 3 1912
谎友^
谎友^ 2021-01-08 00:18

Consider the code below:

#include 

struct T
{
    T() = delete;
};

int main()
{
    std::array a;
    a.size();
}
<
3条回答
  •  遥遥无期
    2021-01-08 00:26

    Thanks to @T.C., as pointed out in his comment, it's addressed in LWG 2157, which is still an open issue as of this writing.

    The proposed resolution adds this bullet point (emphasis mine):

    The unspecified internal structure of array for this case shall allow initializations like:

    array a = { };
    

    and said initializations must be valid even when T is not default-constructible.

    So it's clear that the intended behavior is to have std::array default constructible even when T is not.

提交回复
热议问题