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

Answer: 
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++.)
You have some very good answers here, but I'm to me, it looks like a case of "when all you know is a hammer"...

The simplest answer of to why there is no standard way to initialise a static map, is there is no good reason to ever use a static map... 

A map is a structure designed for fast lookup, of an unknown set of elements. If you know the elements before hand, simply use a C-array. Enter the values in a sorted manner, or run sort on them, if you can't do this. You can then get log(n) performance by using the stl::functions to loop-up entries, lower\_bound/upper\_bound. When I have tested this previously they normally perform at least 4 times faster than a map.

The advantages are many fold...
- faster performance (\*4, I've measured on many CPU's types, it's always around 4)
- simpler debugging. It's just easier to see what's going on with a linear layout.
- Trivial implementations of copy operations, should that become necessary.
- It allocates no memory at run time, so will never throw an exception.
- It's a standard interface, and so is very easy to share across, DLL's, or languages, etc.

I could go on, but if you want more, why not look at Stroustrup's many blogs on the subject.