It's something called an Initilizer list
. According to this website:
Initializer List is used in initializing the data members of a class.
The list of members to be initialized is indicated with constructor as
a comma-separated list followed by a colon.
Basically it adds elements into your std::map
(or in this case your std::unordered_map
) right while you're creating it.
More specifically, from @Aconcagua comment above :
The outer braces define
the initializer list
itself, the inner braces are shorthand for
constructing std::pair
s, which are used in the std::map
to store the keys
and corresponding values.
You can see this from this piece of code:
#include <iostream>
#include <map>
#include <unordered_map>
using namespace std;
int main()
{
map<int, int> c({{0, 1}, {1, 7}});
for (auto it = c.begin(); it!=c.end(); it++)
{
cout << it->first << " " << it->second << "\n";
}
}
Output:
0 1
1 7
There's also other data types that support this, for example std::vector
:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> test({0, 7, 9, 11, 3});
for (auto x : test) {cout << x << "\n";}
}
Output:
0
7
9
11
3
There's a lot of question regarding this:
And more info: https://en.cppreference.com/w/cpp/utility/initializer_list
*Cautions : As @Aconcagua mentioned below, using namespace std
is not considered a good practice, although it might save some typing time.