std::array<int, 3> arr6 = std::array<int, 3>({1, 2, 3});
std::array<int, 3> arr7 = std::array<int, 3>({{1, 2, 3}});
These are examples of copy-initialization; similar to 1 and 2, there's a temporary created (through the expression std::array<int, 3>({1, 2, 3})
)
and this temporary is copied/moved to the named destination variable. This can be elided as well. As far as I know, an implementation could
write an explicit array(array const&) = default;
constructor and not violate the Standard; this would make those examples ill-formed.
explicit array(array const&) = default;
would make the example ill-formed. But if the statement of the author is correct, it seems strange to me whether such a syntax would be considered as valid or not valid is compiler-dependent.Hello.
In this answer: http://stackoverflow.com/questions/20519992/array-declaration-and-initialization-in-c11
the author of the answer says:
-----------------------------------------------------------------std::array<int, 3> arr6 = std::array<int, 3>({1, 2, 3}); std::array<int, 3> arr7 = std::array<int, 3>({{1, 2, 3}});
These are examples of copy-initialization; similar to 1 and 2, there's a temporary created (through the expression
std::array<int, 3>({1, 2, 3})
) and this temporary is copied/moved to the named destination variable.
This can be elided as well. As far as I know, an implementation could write an
explicit array(array const&) = default;
constructor and not violate the Standard; this would make those examples ill-formed.
-----------------------------------------------------------------
It compiles well under g++ 4.8.0, and I am not sure why definingexplicit array(array const&) = default;
would make the example ill-formed. But if the statement of the author is correct, it seems strange to me whether such a syntax would be considered as valid or not valid is compiler-dependent.
explicit constructors are disqualified from copy-list-initialization, which is the form of initialization used for initializer list arguments to function calls.