I was wondering the other day whether it is possible in C++ (any standard) to initialize a map in an initializer list of a constructor with a loop or a more complex procedure than literals such that I can make it a const member variable?
class MyClass {
public:
const int myInt;
const std::unordered_map<int, int> map;
MyClass(int i) : myInt(i), /* initialize map like: for(int i = 0; i < myInt; ++i) { map[i] = whatever; } { }
}
i? You won't be able to do that with literals, or (even recursive ) constexpressions, or (even recursive) templates becauseiis not known at compile time. The problem is the overhead in passing a map by value with pre-move standards/implementations.