如何std::map在使用该find方法后更新密钥的值?
我有这样的map和iterator声明:
map <char, int> m1;
map <char, int>::iterator m1_it;
typedef pair <char, int> count_pair;
Run Code Online (Sandbox Code Playgroud)
我正在使用地图来存储角色的出现次数.
我正在使用Visual C++ 2010.
C++引用告诉我们一个std :: map
typedef pair<const Key, T> value_type;
Run Code Online (Sandbox Code Playgroud)
是否可以强制键类型不是常量?我需要在模板方法中这样做
template<class T> // T represent a map in general (std::map, boost::unordered_map or whatever..)
void foo(const T& m)
{
typename T::value_type::first_type x;
x=0; // Wrong because x is const ...
}
Run Code Online (Sandbox Code Playgroud)