描述
C++11有关于std::map的一个用法例子
涉及到了
emplace()
std::piecewise_construct
std::forward_as_tuple
代码
#include <map>
#include <tuple>
#include <iostream>
int main()
{
std::map<int,std::string> m;
// uses pair's piecewise constructor
m.emplace(std::piecewise_construct,std::forward_as_tuple(10),std::forward_as_tuple(3,'c'));
std::map<int,std::string>::iterator it;
it = m.begin();
while (it != m.end())
{
int first = it->first;
std::string second = it->second;
std::cout<<"key : "<<first<<" value : "<<second<<std::endl;
it++;
}
return 0;
}
结果输出为
key : 10 value : ccc