###《Effective STL》--Chapter1
点击查看Evernote原文。
#@author: gr
#@date: 2014-09-12
#@email: forgerui@gmail.com
Chapter1 容器
Topic 4: 调用empty而不是检查size()是否为0
当检查一个容器是否为空时,要使用empty而不是size()。empty在检查时的时间总是常数的,而对于size(),一些容器的实现可能是线性的(如list)。
Topic 5: 区间成员函数优先于与之对应的单元素成员函数
使用区间成员函数会得到更高的效率,其次,在可读性方面,使用区间成员函数也比自己写循环要好看多了。
区间创建
container::container(InputIterator begin, InputIterator end);
区间插入
//序列容器
void container::insert(iterator position, InputIterator begin, InputIterator end); //关联容器
void container::insert(InputIterator begin, InputIterator end);
区间删除
//序列容器
iterator container::erase(iterator begin, iterator end); //关联容器
void container::erase(iterator begin, iterator end);
区间赋值
void container::assign(InputIterator begin, InputIterator end);
Topic 9: 慎重选择删除元素的方法
要删除容器中有特定值的所有对象
如果容器是vector,string和deque,则使用erase-remove用法。//删除vector<int>中所有值为10的元素
c.erase(remove(c.bgein(), c.end(), 10), c.end());
如果容器是
list,则使用list::remove。l.remove(l.begin(), l.end(), 10);
如果容器是一个标准关联容器,则使用它的erase成员函数。
//删除关联容器中值为10的元素
m.erase(10);
在循环内删除某些元素
序列容器使用返回值更新迭代器。while(it != con.end()){
if (it->getCount() > theshold){
it = con.erase(it);
}else{
it++;
}
}
关联容器对迭代器递增操作。
while (it != con.end()){
if (it->getCount() > threshold){
con.erase(it++);
}else{
it++;
}
}
###《Effective STL》--Chapter1的更多相关文章
- 《Effective STL》学习笔记
http://www.cnblogs.com/arthurliu/archive/2011/08/07/2108386.html 作者:咆哮的马甲 出处:http://www.cnblogs.com/ ...
- ###《Effective STL》--Chapter3
点击查看Evernote原文. #@author: gr #@date: 2014-09-13 #@email: forgerui@gmail.com Chapter3 关联容器 Topic 22: ...
- ###《Effective STL》--Chapter5
点击查看Evernote原文. #@author: gr #@date: 2014-09-17 #@email: forgerui@gmail.com Chapter5 算法 Topic 30: 确保 ...
- ###《Effective STL》--Chapter6
点击查看Evernote原文. #@author: gr #@date: 2014-09-27 #@email: forgerui@gmail.com Chapter6 函数子.函数子类.函数及其他 ...
- ###《Effective STL》--Chapter7
点击查看Evernote原文. #@author: gr #@date: 2014-08-31 #@email: forgerui@gmail.com Chapter7 在程序中使用STL Topic ...
- ###《Effective STL》--Chapter2
点击查看Evernote原文. #@author: gr #@date: 2014-09-15 #@email: forgerui@gmail.com Chapter2 vector和string T ...
- ###《Effective STL》--Chapter4
点击查看Evernote原文. #@author: gr #@date: 2014-09-14 #@email: forgerui@gmail.com Chapter4 迭代器 Topic 26: i ...
- 容器使用的12条军规——《Effective+STL中文版》试读
容器使用的12条军规——<Effective+STL中文版>试读 还 记的自己早年在学校学习c++的时候,老师根本就没有讲STL,导致了自己后来跟人说 起会C++的时候总是被鄙视, ...
- 《Effective STL中文版》前言
<Effective STL中文版>前言 我第一次写关于STL(Standard Template Library,标准模板库)的介绍是在1995 年,当时我在More Effec ...
随机推荐
- other
1.http://handlebarsjs.com/ 2.grunt
- 使用poi将word转换为html
使用poi将word转换为html,支持doc,docx,转换后可以保持文字.表格.图片.样式 演示地址: https://www.xiaoyun.studio/app/preview.html 完整 ...
- [转] C++ Redistributable Package版本详解
我们使用的程序常常都需要C++ Redistributable Package的支持.C++ Redistributable Package有众多版本,给安装带了不便. 目前(2013-12-04) ...
- SQLite使用教程3 数据类型
http://www.runoob.com/sqlite/sqlite-data-types.html SQLite 数据类型 SQLite 数据类型是一个用来指定任何对象的数据类型的属性.SQLit ...
- [linux]发现一个vim的常用命令的图表,做的挺好,转过来
- .NET常用工具类集锦
不错的地址: http://www.cnblogs.com/flashbar/archive/2013/01/23/helper.html https://github.com/chrisyanghu ...
- ORA-12154 TNS无法解析指定的连接标识符
又是这个百无聊赖的问题,尽管问题芝麻点大,却让我们好找啊! 非常久没有安装oracle了.今天安装11g的时候,用PLSQL Developer连接时,就出现了这个俗不可耐的问题:ORA-12154 ...
- [置顶] 用Wireshark保存RTP的负载码流
这段时间工作太忙,有些日子没写文章了,今天准备了一篇Wireshark工具的一个小功能,在验证码流的时候非常好用,闲话不说,直接说步骤: 1.打开Wireshark抓取流媒体码流,然后用RTP过滤: ...
- 关于js的replace替换
关于js的replace替换 msgContent = msgContent.replace("a","b"); 这样的替换只会把第一个a替换成b,不会替换全部 ...
- android报错及解决1--Bitmap加载时,报bitmap size exceeds VM budget
报错描述: 用Bitmap加载图片资源时,报错java.lang.OutOfMemoryError: bitmap size exceeds VM budget 原因分析: android系统限制,只 ...