STL源代码学习(vector篇)】的更多相关文章

#include <concept_checks.h> #include<stl_allocate.h> /// The vector base class's constructor and destructor allocate ///(but don't initialize) storage. This makes exception safety easier. template <class _Tp, class _Alloc> class _Vector_…
一.容器vector 使用vector你必须包含头文件<vector>: #include<vector> 型别vector是一个定义于namespace std内的template: template<class _Ty, class _Ax = allocator<_Ty> > 第二个參数定义内存模型. 我们一般採用默认的内存模型. 二.vector的功能 vector模塑出一个动态数组.vector将其元拷贝到内部的动态数组中. 元素之间总是存在某种顺…
///STL list为双向循环链表 struct _List_node_base { _List_node_base* _M_next; _List_node_base* _M_prev; }; template <class _Tp> struct _List_node : public _List_node_base { _Tp _M_data; }; struct _List_iterator_base { typedef size_t size_type; typedef ptrdi…
stl_heap.h ///STL中使用的是大顶堆 /// Heap-manipulation functions: push_heap, pop_heap, make_heap, sort_heap. template <class _RandomAccessIterator, class _Distance, class _Tp> void __push_heap(_RandomAccessIterator __first, _Distance __holeIndex, _Distance…
///因为篇幅太长,因此,删去了非常多接口,仅仅分析了内部实现,算法对迭代器的要求也被删去 /// search. template <class _ForwardIter1, class _ForwardIter2> _ForwardIter1 search(_ForwardIter1 __first1, _ForwardIter1 __last1, _ForwardIter2 __first2, _ForwardIter2 __last2) { /// Test for empty ran…
stl_deque.h /** Class invariants: * For any nonsingular iterator i: * i.node is the address of an element in the map array. The * contents of i.node is a pointer to the beginning of a node. * i.first == *(i.node) * i.last == i.first + node_size * i.c…
///stl_slist.h ///list为双向循环链表,slist为单向链表.某些操作效率更高 ///slist是SGI额外提供的单向链表,不属于C++标准 struct _Slist_node_base { _Slist_node_base* _M_next; }; ///将__new_node链在__prev_node后面 inline _Slist_node_base* __slist_make_link(_Slist_node_base* __prev_node, _Slist_no…
<<STL源代码剖析>> 侯捷著 非常早就买了这本书, 一直没看, 如今在实验室师兄代码的时候发现里面使用了大量泛型编程的内容, 让我有了先看看这本书的想法. 看之前我对于泛型编程了解甚少, STL倒使用的比較熟练. 看完这本书之后, 仅仅能表示曾经对于STL的使用真是跟小孩玩似得, 仅仅懂其冰山一角. 在真正的深入到源代码之后, 对于STL中不easy理解的部分如 迭代器(iterator), 仿函数(functor), 配接器(adapter)才有了一个彻彻底底的了解, 这样的…
前言 因为在前文的<STL算法剖析>中,源代码剖析许多.不方便学习,也不方便以后复习,这里把这些算法进行归类.对他们单独的源代码剖析进行解说.本文介绍的STL算法中的remove删除算法.源代码中介绍了函数remove.remove_copy.remove_if.remove_copy_if.unique.unique_copy. 并对这些函数的源代码进行具体的剖析.并适当给出使用样例,具体详见以下源代码剖析. remove移除算法源代码剖析 // remove, remove_if, rem…
前言 因为在前文的<STL算法剖析>中.源代码剖析许多.不方便学习.也不方便以后复习,这里把这些算法进行归类.对他们单独的源代码剖析进行解说.本文介绍的STL算法中的merge合并算法. 源代码中介绍了函数merge.inplace_merge.并对这些函数的源代码进行具体的剖析,并适当给出使用样例,具体详见以下源代码剖析. merge合并算法源代码剖析 // merge, with and without an explicitly supplied comparison function.…