From Jason Turner
Watch on YouTube

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.

Resources

Tags