In this article we will discuss how to initialize a map with std::initialzer_list<T>.

Let’s create a map of string as key and int as value and initialize it with initializer_list i.e.

Here compiler will create following std::initializer_list<T> object internally,

Here T is a std::pair<const std::string, int> because map store the elements internally as a pair.

Initializing a map of string & vector

Complete Example is as follows,

Output:

Output:

Initializing a member variable map in constructor with std::initializer_list

Output:

 

Python Resources

C++11 / C++14 Resources

Design Patterns Resources

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Do Subscribe with us for more Articles / Tutorials like this,