isocpp / isocpp/CppCoreGuidelines
Should ES.23 mention that ()-initialization is likely to be preferrable when dealing with containers containing types initializable from the container itself
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 45.3k
- Forks
- 5.6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ES.23 in the linked C++ Core Guidelines and review the examples involving brace initialization of containers. Clarify whether the guidance should mention preferring ()-initialization when an element type can be constructed from the container itself, using the std::vectorstd::any example to verify the wording and outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100