我有一个功能,这使得使用unordered_map和它的只有这个功能在我的课,它使用它:填充静态unordered_map局部变量
void my_func(){
static std::unordered_map<int,int> my_map;
//I only want this to be done the first time the function is called.
my_map[1] = 1;
my_map[2] = 3;
//etc
}
我如何可以插入的元素,以我的静态unordered_map所以他们只在我的函数第一次被调用时插入(就像内存分配只是第一次)?
可能吗?
使用'static bool'作为标志来检查它是否已初始化? – Mine