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