Question: What is the right way of initializing a static map? Do we need a static function that will initialize it?

Answer: 
I would wrap the map inside a static object, and put the map initialisation code in the constructor of this object, this way you are sure the map is created before the initialisation code is executed.
In addition to the good top answer of using

```
const std::map<int, int> m = {{1,1},{4,2},{9,3},{16,4},{32,9}}

```

there's an additional possibility by directly calling a lambda that can be useful in a few cases:

```
const std::map<int, int> m = []()->auto {
  std::map<int, int> m;
  m[1]=1;
  m[4]=2;
  m[9]=3;
  m[16]=4;
  m[32]=9;
  return m;
}();

```

Clearly a simple initializer list is better when writing this from scratch with literal values, but it does open up additional possibilities:

```
const std::map<int, int> m = []()->auto {
  std::map<int, int> m;
  for(int i=1;i<5;++i) m[i*i]=i;
  m[32]=9;
  return m;
}();

```

(Obviously it should be a normal function if you want to re-use it; and this does require recent C++.)