Effective STL 笔记 – Item 6 ~ 7: Container and Object Pointer 中间两次笔记被删掉了,简单补一下: Item 3 中提到如果将对象直接放入容器中,可能会引发问题: 大量的拷贝行为要求对象的拷贝构造代价要小 试图将派生类放入存放基类的容器中会引发 Slicing 问题. 对此的简单方法就是在容器中保存对象 指针 ,但如果直接保存指针的话,我们需要自己维护和管理内存,容易混乱.最好的方法是保存 智能指针(smart pointer shared…
假设有个文件里面记录的一系列的 int 值,现在我们想把这些数值存到一个 List 里面,结合 Item 5, 我们可能会写出下面的代码: ifstream dataFile("ints.data"); list<int> data(istream_iterator<int>(dataFile), // Start of iterator istream_iterator()); // End of iterator 这段代码可以编译,但运行时并不工作,它不会去…
假设有一个容器中存放着 int ,Container<int> c, 现在想从其中删除数值 1963,可以有如下方法: 1: c.erase(remove(c.begin(), c.end(), 1963), c.end()); // c is continguous memory container 2: c.remove(1963); // c is list 3: c.erase(1963) // c is standard associative container 对于 contin…
百度云及其他网盘下载地址:点我 作者简介 Scott Meyers is one of the world's foremost authorities on C++, providing training and consulting services to clients worldwide. He is the author of the best-selling Effective C++ series of books (Effective C++, More Effective C+…
STL笔记(6)标准库:标准库中的排序算法 标准库:标准库中的排序算法The Standard Librarian: Sorting in the Standard Library Matthew Austern http://www.cuj.com/experts/1908/austern.htm?topic=experts 用泛型算法进行排序    C++标准24章有一个小节叫“Sorting and related operations”.它包含了很多对已序区间进行的操作,和三个排序用泛型…
Effective STL 学习笔记 Item 38 : Design functor classes for pass-by-value */--> div.org-src-container { font-size: 85%; font-family: monospace; } pre.src { background-color:#f8f4d7 } p {font-size: 15px} li {font-size: 15px} 严格来讲, C 和 C++ 都不支持将函数作为参数,真正作为…
Effective STL 学习笔记 Item 34: 了解哪些算法希望输入有序数据 */--> div.org-src-container { font-size: 85%; font-family: monospace; } pre.src { background-color:#f8f4d7 } p {font-size: 15px} li {font-size: 15px} 有些个算法对有序的和无序的数据都能应用,但多数情况下,他们在输入数据有序时才最有用. 下列算法要求输入数据必须有序…
Effective STL 学习笔记 Item 30: 保证目标区间足够大 */--> div.org-src-container { font-size: 85%; font-family: monospace; } p {font-size: 15px} li {font-size: 14px} Table of Contents 1. 容器区间与算法 2. back_inserter 3. front_inserter 4. inserter 5. inserter & reserve…
Effective STL 学习笔记 Item 26: Prefer Iterator to reverse_iterator and const_rever_itertor */--> div.org-src-container { font-size: 85%; font-family: monospace; } Table of Contents 1. Iterator 的类型 2. 迭代器之间的转换 3. Iterator is Special 4. 总结: 1 Iterator 的类型…
Effective STL 学习笔记: Item 22 ~ 24 */--> div.org-src-container { font-size: 85%; font-family: monospace; } Table of Contents 1. 避免 \(set \& multiset\) 在原位改变 Key 2. Consider replacing associative containers with sorted vectors 3. Choose carefully betw…