Here's ES.23.
Should that mention that one might want to prefer ()-initialization to {}-initialization when initializing a container of elements of a given type from a container of the same type, when the inner type can be constructed from the vector itself?
I'm referring to the fact that
std::vector<std::any> v{1,2,3};
std::vector<std::any> w{v};
will result in w having length 1, with its only element v[0] having been initialized from v. I think this can be surprising to most programmers.
A similar scenario happens when, instead of std::any, the type inside the container has a templated constructor, like in this case.
Here's ES.23.
Should that mention that one might want to prefer
()-initialization to{}-initialization when initializing a container of elements of a given type from a container of the same type, when the inner type can be constructed from the vector itself?I'm referring to the fact that
will result in
whaving length 1, with its only elementv[0]having been initialized fromv. I think this can be surprising to most programmers.A similar scenario happens when, instead of
std::any, the type inside the container has a templated constructor, like in this case.