C++0x Initialization Lists
Why Stack Overflow recommends it
Stack Overflow users link it as the primary source from C++'s creator when explaining or questioning the rationale behind brace initialization and initializer lists.
Recommended by 1 people across 1 different months, 2012 to 2013.
What it is
A 2007 Google Tech Talk by Bjarne Stroustrup on how C++0x (later C++11) would unify initialization syntax and allow initialization from general lists. It covers sequence constructors, homogeneous and heterogeneous initializer lists, constant expressions, narrowing prevention and variadic templates.
What people said
Recommends Fredrick Gauss · 2013-06 · Stack Overflow · on “What is benefit of this constructor definition”
i was like you, with the back old collage knowledge this usage seems weird. But then understand that by using this technique, custom class implementations give better performance on runtime. And here [this video] is a long explanation about initiatization lists from the father of C++.
Cites bitmask · 2012-09 · Stack Overflow · on “How generic is the {} construction syntax?”
In a talk about initialization lists [this video] , I understood Stroustrup basically saying that the new construction syntax with curly braces is supposed to be a general replacement for all the previous construction syntaxes: X x1(); // most vexing parse ... doesn't work as intended X x2(x1); X x3 = x1; X x4 = X(); Instead, the new syntax is supposed to be used uniformly as a possible replacement that you can use in every situation ... again, that's the core message that I took from his talk. Maybe I misunderstood him. So, the question is, how generic is this syntax? Is it possible to never use old-style construction in new C++11 code or are there situations where you have to revert? This quest
Cites fredoverflow · 2013-01 · Stack Overflow · on “Initializing scalars with braces”
In C and C++, one can initialize arrays and structs using braces: int a[] = {2, 3, 5, 7}; entry e = {"answer", 42}; However, in a talk from 2007 [this video] , Bjarne mentions that this syntax also works for scalars. I tried it: int i = {7}; And it actually works! What is the rationale behind allowing the initialization of scalars with braces? Note: I am specifically not talking about C++11 uniform initialization. This is good old C89 and C++98.