【发布时间】:2015-07-02 14:10:25
【问题描述】:
在C++11中,std::unordered_map::operator[]有两个版本,分别是:
mapped_type& operator[] ( const key_type& k ); //1
mapped_type& operator[] ( key_type&& k ); //2
有两个问题:
1) 为什么第二个是必要的 - 第一个允许将常量传递给函数,因为第一个包含关键字 const
2) 例如,在这种情况下将调用哪个版本,1 或 2:
std::unordered_map<std::string, int> testmap;
testmap["test"] = 1;
【问题讨论】:
标签: c++ c++11 unordered-map rvalue-reference