替换std :: map中的键 [英] Replace a key in a std::map

查看:117
本文介绍了替换std :: map中的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用std :: map保存一些内容,关键是Guid *.

I'm using the std::map to save some stuff, the key is Guid*.

typedef boost::tuple<c_ptr, handler_ptr> ctuple;
typedef std::map<GUID *, ctuple> c_map;

我的问题是: 我有办法在std :: map中更改项目的键吗? 其他将现有数据复制到具有新密钥的新项目,并删除上一个/旧项目(使用旧密钥)

My question is: Do I have a way to change the key of an item in the std::map? OTHER THAN copy the existing data to a new item that have the new key and remove the prev/old item (with the old key)

谢谢

推荐答案

我是否可以在std :: map中更改项目的键?

Do I have a way to change the key of an item in the std::map?

否.

这就是为什么std::map<Key, Value>中的value_typestd::pair<Key const, Value>的原因(注意const应用于Key).

This is why value_type of std::map<Key, Value> is std::pair<Key const, Value> (notice const applied to Key).

这篇关于替换std :: map中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆