提升ptr_map替换值
boost ptr_map replacing the value
给定一个键,我正在尝试替换一个值。 对于不使用指针的常规地图,我只是使用了以下调用
iter->second = object; //Where object was passed in by reference
如何使用 boost::p tr_map 实现相同的目标? 这里的概念是,我们使用derived_object替换整个类
iter->second = derived_object; //derived_object is a base_object pointer
这将解决问题:
the_map.replace(iter, derived_object);
当然,the_map
在哪里是iter
指向的地图。
请注意,ptr_map<K,V>::replace
返回一个ptr_map<K,V>::auto_type
,因此您可以根据需要获取替换的对象。当然,如果你忽略它,它就会被自动摧毁,你永远不需要知道它在那里。
相关文章:
- 模板参数替换失败,并且未完成隐式转换
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何用转义符替换字符串中的所有特殊字符
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- 在一个读写器队列中,我可以用volatile替换原子吗
- 用符号版本替换对函数的所有调用
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 替换基于地图的所有引用
- 将重物插入std::map
- 按平均值替换数组中的元素
- std::map:当元素不可默认构造时创建/替换元素
- 替换现有条目并在 std::map 中添加新条目
- std::map通过转换替换现有元素
- 为什么我不能将 std::map 替换为 std::unordered_map
- 用std::set替换std::map并按索引搜索