C++ map insert 另一个map的子集
C++map中 会有insert操作,举个例子
存在map A,我们截取一部分到map B中,void insert (InputIterator first, InputIterator last) ,截取的部分是 first 到 last 前一个迭代器的值
// map::insert (C++98)
#include <iostream>
#include <map> int main ()
{
std::map<char,int> mymap; // first insert function version (single parameter):
mymap.insert ( std::pair<char,int>('a',) );
mymap.insert ( std::pair<char,int>('z',) ); std::pair<std::map<char,int>::iterator,bool> ret;
ret = mymap.insert ( std::pair<char,int>('z',) );
if (ret.second==false) {
std::cout << "element 'z' already existed";
std::cout << " with a value of " << ret.first->second << '\n';
} // second insert function version (with hint position):
std::map<char,int>::iterator it = mymap.begin();
mymap.insert (it, std::pair<char,int>('b',)); // max efficiency inserting
mymap.insert (it, std::pair<char,int>('c',)); // no max efficiency inserting // third insert function version (range insertion):
std::map<char,int> anothermap;
anothermap.insert(mymap.begin(),mymap.find('c')); // showing contents:
std::cout << "mymap contains:\n";
for (it=mymap.begin(); it!=mymap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n'; std::cout << "anothermap contains:\n";
for (it=anothermap.begin(); it!=anothermap.end(); ++it)
std::cout << it->first << " => " << it->second << '\n'; return ;
}
输出结果:
element 'z' already existed with a value of
mymap contains:
a =>
b =>
c =>
z =>
anothermap contains:
a =>
b =>
详细信息可参考: http://www.cplusplus.com/reference/map/map/insert/
C++ map insert 另一个map的子集的更多相关文章
- java map添加另一个map时候 键值对的类型要一致
java map添加另一个map时候 键值对的类型要一致
- C++ map.insert: pair和make_pair区别
C++ map.insert: pair和make_pair区别 \*********************************\ map<uint32_t, string> tem ...
- 条目二十四《当效率至关重要时,请在map::operator[]与map::insert之间谨慎做出选择》
条目二十四<当效率至关重要时,请在map::operator[]与map::insert之间谨慎做出选择> 当效率至关重要时,应该在map::operator[]和map::insert之 ...
- 理解ThreadLocal —— 一个map的key
作用: 当工作于多线程中的对象使用ThreadLocal维护变量时,threadLocal为每个使用该变量的线程分配一个独立的变量副本. 接口方法: protected T initialValue( ...
- Map.putAll方法——追加另一个Map对象到当前Map集合(转)
该方法用来追加另一个Map对象到当前Map集合对象,它会把另一个Map集合对象中的所有内容添加到当前Map集合对象. 语法 putAll(Map<? extends K,? extends V ...
- C++ map.insert 传参类型不同,构造/析构次数不同
1. 传参方式 使用 insert 为 map 插值时,insert 的传参包含以下几种可能: make_pair 生成对象 pair(key_type, value_type) 生成对象 pair( ...
- mybatia的mypper.xml文件,参数类型为map,map里有一个键值对的值为数组,如何解析,例子可供参考,接上文,发现更简便的方法,不必传数组,只需传字符串用逗号隔开即可
是这样的 先看参数 map.put("orgId", "1818"); map.put("childDeps", "1000,10 ...
- 获取map中的一个value值以及遍历map获得map里所有key、value的值
前言: 1.声明一个map: Map map = new HashMap();2.向map中放值,注意:map是key-value的形式存放的.如: map.put(”sa”,”dd”); 3.从ma ...
- 求一个Map中最大的value值,同时列出键,值
求一个Map中最大的value值,同时列出键,值 方法1. public static void main(String[] args){ Map map=new HashMap(); map.p ...
随机推荐
- ecosystem.config
ecosystem.config.js module.exports = { apps : [{ name : 'TOB_NODE', script : 'app.js', // 开发环境变量 env ...
- BZOJ1002 [FJOI2007]轮状病毒(最小生成树计数)
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 7125 Solved: 3878[Submit][Status][Discuss] Descripti ...
- CodeForces 5C Longest Regular Backet sequence
This is yet another problem dealing with regular bracket sequences. We should remind you that a brac ...
- 如何手动实现TryInsert和InsertOrUpdate
在日常开发中,我们有时会需要对数据的插入操作进行定制.比如,如果表里已有某某记录就不写入新纪录,或者表里没该记录就插入,否则就更新.前者我们称为TryInsert,后者为InsertOrUpdate( ...
- 记录我的 python 学习历程-Day06 is id == / 代码块 / 集合 / 深浅拷贝
一.is == id 用法 在Python中,id是内存地址, 你只要创建一个数据(对象)那么就会在内存中开辟一个空间,将这个数据临时加载到内存中,这个空间有一个唯一标识,就好比是身份证号,标识这个空 ...
- 【docker】Dockerfile
[docker]Dockerfile 转载: ============================================================= =============== ...
- 《Java知识应用》Java-线程池(ScheduledExecutorService)
先回顾一下,Runnable 的使用方法. package demo.knowledgepoints.scheduledtask.run; /*** * 线程类 */public class Thre ...
- 表达式和运算符知识总结(js)
文章目录: 一. 表达式和语句的区别 二. 自增自减运算符的运算规则 一. 表达式和语句的区别 表达式(expression)是JavaScript中的一个短语,JavaScript解释器会将其计算( ...
- [ASP.NET Core 3框架揭秘] 依赖注入[2]:IoC模式
正如我们在<依赖注入:控制反转>提到过的,很多人将IoC理解为一种"面向对象的设计模式",实际上IoC不仅与面向对象没有必然的联系,它自身甚至算不上是一种设计模式.一般 ...
- Thread.Sleep线程休眠-小白向
try { Thread.sleep(); } catch (InterruptedException e) { } 首先这段代码的作用是使当前进程沉睡2S,展现给用户的结果就是画面维持两秒,有个“正 ...