October 2011
Beginner to intermediate
1200 pages
35h 33m
English
initializer_list Template (C++11)The initializer_list template is another C++11 addition to the C++ library. You can use the initializer-list syntax to initialize an STL container to a list of values:
std::vector<double> payments {45.99, 39.23, 19.95, 89.01};
This would create a container for four elements and initialize the elements to the four values in the list. What makes this possible is that the container classes now have constructors taking an initializer_list<T> argument. A vector<double> object, for example, has a constructor that accepts an initializer_list<double> argument, and the previous declaration is the same as this:
std::vector<double> payments({45.99, 39.23, 19.95, 89.01});
Here, the list is written explicitly as a constructor ...
Read now
Unlock full access