Skip to content

Should ES.23 mention that ()-initialization is likely to be preferrable when dealing with containers containing types initializable from the container itself #2205

Open
@Aster89

Description

@Aster89

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions