How can one initialize static map, where value is std::unique_ptr
?
static void f()
{
static std::map&
The Problem is that constructing from std::initializer-list copies its contents. (objects in std::initializer_list
are inherently const
).
To solve your problem: You can initialize the map from a separate function...
std::map> init(){
std::map> mp;
mp[0] = std::make_unique();
mp[1] = std::make_unique();
//...etc
return mp;
}
And then call it
static void f()
{
static std::map> mp = init();
}
See it Live On Coliru