C++ STL源代码学习之算法篇】的更多相关文章

///因为篇幅太长,因此,删去了非常多接口,仅仅分析了内部实现,算法对迭代器的要求也被删去 /// 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中.算法是常常被使用的,算法在整个STL中起到很关键的数据.本节介绍的是一些基本算法,包括equal.fill.fill_n,iter_swap.lexicographical_compare.max,min.mismatch,swap,copy,copy_backward.copy_n.当中一个比較重要的算法就是copy.针对copy的剖析在源代码中能够看到具体的注解. 本文剖析的源代码出自SGL STL中的<stl_algobase.h>文件. 基本算法剖析 #ifndef…
///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…
///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…
#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算法剖析>中,源代码剖析许多.不方便学习,也不方便以后复习,这里把这些算法进行归类.对他们单独的源代码剖析进行解说.本文介绍的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.…