Uniform initialization uses braces to initialize variables and containers. It makes initialization more consistent and prevents narrowing conversions, such as silently assigning a double to an int. section 3.5
Braces can also make initialization easier to read and maintain:
- Initialize a container directly instead of filling it with repeated push_back calls. section 3.5
- Use braced in-class initializers to keep member defaults near their declarations; constructor-supplied values take precedence. section 2.5
Listing 3.11 Uniform initialization of a container and simple variable
int main() {
std::vector<int> v {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 33, 42}; #1
auto count {v.size()}; #2
std::cout << "the vector has " << count << " elements\n";
return 0;
}
See a vector and its count initialized with braces, replacing a sequence of push_back calls. section 3.5

