Skip to content

Commit

Permalink
Update CppCoreGuidelines.md
Browse files Browse the repository at this point in the history
Addressing the issue isocpp#2205 I opened myself.

I can't see why not contributing.
  • Loading branch information
Aster89 authored Sep 10, 2024
1 parent 50afe02 commit 7820e74
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -11165,6 +11165,16 @@ Use plain `{}`-initialization unless you specifically want to disable explicit c
// ...
}

##### Exception

For container-like types whose element type can be initialized from an instance of that very container
type iteself, e.g. `std::any` or a template parameter `T` of a template type having a constructor accepting `T`,
use `()` to avoid erroneously constructing a nested container:

vector<any> v{1,2,3};
vector<any> u{v}; // most likely unintended: u has 1 element of type any, which contains v
vector<any> w(v); // w is a copy of v

**See also**: [Discussion](#???)

##### Enforcement
Expand Down

0 comments on commit 7820e74

Please sign in to comment.