0xh*_*ker 4 c++ std c++-standard-library c++11
为什么不std::map支持如下插入:
std::map<obj1, obj2> map_int;
void insert_map(obj1 &key, obj2 &val)
{
map_int.insert(key, val);
}
Run Code Online (Sandbox Code Playgroud)
我知道上面的内容不正确.我想知道是什么阻止了这样设计插入函数.它比创建一对IMO更直观.
它被称为emplace():
Run Code Online (Sandbox Code Playgroud)std::map<std::string, std::string> m; // uses pair's template constructor m.emplace("d", "ddd");