Summary
Jason explains the subtle but important differences between braced and parenthesized initialization when initializer_list constructors are present. Using vector as an example, vector{3, 4} creates a two-element vector [3, 4] by calling the initializer_list constructor, while vector(3, 4) creates three elements with value 4 by calling the size/value constructor. When a class provides an initializer_list constructor, braced initialization {} always prefers it over other constructors, which can lead to confusion. Jason advocates for requiring explicit std::initializer_list{...} syntax to make the intent clearer and avoid ambiguity.
Related C++ Standard Sections
This episode covers topics found in these sections of the C++ standard:
-
[initializer.list.syn]75% match -
[dcl.init.list]72% match -
[dcl.init]66% match