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,



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



Python Recommendations:

C++ & C++11 Recommendations:

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.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.