How can one initialize static map, where value is std::unique_ptr?
static void f()
{
static std::map&
another way to do this is to use a lambda. it's the same as using a separate function but puts the map's initialisation closer to the action. In this case I've used a combination of an auto& and decltype to avoid having to name the type of the map, but that's just for fun.
Note that the argument passed into the lambda is a reference to an object that has not yet been constructed at the point of the call, so we must not reference it in any way. It's only used for type deduction.
#include
#include
Here's another way. In this case we've passed a temporary into the lambda and relied on copy elision/RVO.
#include
#include
And yet another way, using a lambda capture in a mutable lambda.
#include
#include