std::initializer_list is a feature in the C++ standard library that allows initialization of arrays, vectors and other container classes using a list of values enclosed in braces. It was introduced in C++11 to provide an easy way to initialize container classes with a variable number of elements.
Example 1: Initializing an Array using std::initializer_list
```c++ int arr[] = {1, 2, 3, 4, 5}; // normal array initialization std::initializer_list list = {1, 2, 3, 4, 5}; // using std::initializer_list
In the above code, we can see the difference between initializing a normal array and using std::initializer_list to initialize an array.
Example 2: Initializing a Vector using std::initializer_list
c++
std::vector vec{1, 2, 3, 4, 5}; // using std::initializer_list to initialize a vector
```
Here, we can see how std::initializer_list can be used to initialize a vector with a list of values without specifying the number of elements beforehand.
The package library that provides the std::initializer_list feature is the C++ Standard Library.
C++ (Cpp) initializer_list - 30 examples found. These are the top rated real world C++ (Cpp) examples of std::initializer_list extracted from open source projects. You can rate examples to help us improve the quality of examples.