![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
STL源码剖析
打工的社畜
这个作者很懒,什么都没留下…
展开
-
STL源码剖析(第三章 迭代器概念与traits编程技法)
3.1 迭代器设计思维——STL关键所在3.2 迭代器是一种smart pointer这部分了解就好。3.3 迭代器相应型别迭代器的相应型别,即迭代器所指向对象的类型(之一,迭代器型别总共有五种)。要获得迭代器所指类型的解决办法是:利用function template的参数推导(argument deduction)机制。例如:template <class I,class T>void func_impl(I iter,T t){ T tmp; //这里解决了问题 T就是迭原创 2020-08-16 15:58:10 · 140 阅读 · 0 评论 -
STL源码剖析(第二章 空间配置器)
1.1 空间配置器以STL的实现角度而言,第一个需要介绍的就是空间配置器,因为整个STL的操作对象(所有的数值)都存放在容器之内,而容器一定需要配置空间以置放资料。并且allocator称之为“空间配置器”而不是”内存配置器“的原因是因为空间不一定是内存,也可以是其他的辅助空间比如磁盘等。1.1.1空间配置器的标准接口allocator::value_typeallocator::pointerallocator::const_pointerallocator::referencealloca原创 2020-08-15 09:31:10 · 213 阅读 · 0 评论 -
STL源码分析(第一章绪论)
1.1 STL 构成本书使用的是SGI实现的版本,1.1.1 六大组件1.容器(containers):各种数据结构,如vector,list,deque,set,map,用来存放数据。STL容器是一种类模板(calss template )。2.算法(algorithm):各种常用算法如sort、search、copy、erase等。STL算法是一种(函数模板)function template。3.迭代器(iterators):扮演容器与算法之间的“胶合剂”,是所谓的“泛型指针”。从实现角度看原创 2020-08-13 19:44:44 · 104 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之算法源码代码剖析(11个例子)
1.1 accumulate(两个版本)1.2 for_eachtemplate <class InputIterator, class Function>Function for_each(InputIterator first, InputIterator last, Function f) { for ( ; first != last; ++first) f(*first);//用可调用对象f来遍历操作 return f;}1.3 replace相关tem原创 2020-08-02 09:26:56 · 198 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之迭代器的分类(category)
1.1 迭代器1.1.1 迭代器的种类总共有五种。输入迭代器、输出迭代器、单向迭代器、双向迭代器、随机访问迭代器。1.1.2 计算迭代器之间的距离(注意不同类型之间的效率)根据迭代器的类型调用不同的_distance来计算template <class InputIterator, class Distance>inline void __distance(InputIterator first, InputIterator last, Distance& n,原创 2020-08-02 08:10:21 · 198 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之hash_set hash_map
1.1 hash_set (unordered_set)其底层实现使用的是hashtable#ifndef __SGI_STL_INTERNAL_HASH_SET_H#define __SGI_STL_INTERNAL_HASH_SET_H__STL_BEGIN_NAMESPACE#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)#pragma set woff原创 2020-08-01 14:55:59 · 144 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之 hashtable
1.1 hashtable1.1.1 hashtable的主体template <class Value>struct __hashtable_node{ __hashtable_node* next;//哈希冲突时的链表的下一指针域 Value val;//节点存储的值}; template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey,原创 2020-07-31 17:11:39 · 98 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之 map multimap
1.1 map1.1.1 map主体实现#ifndef __STL_LIMITED_DEFAULT_TEMPLATEStemplate <class Key, class T, class Compare = less<Key>, class Alloc = alloc>#elsetemplate <class Key, class T, class Compare, class Alloc = alloc>#endifclass map {public原创 2020-07-31 15:11:02 · 90 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之 set multiset
1.1 set1.1.1 主体实现#ifndef template <class Key, class Compare = less<Key>, class Alloc = alloc>#elsetemplate <class Key, class Compare, class Alloc = alloc>#endifclass set {public: // typedefs: typedef Key key_type; typedef原创 2020-07-31 14:37:13 · 96 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之RB -tree
1.1 RB-tree1.1.1 RB-tree主体部分template <class Key, class Value, class KeyOfValue, class Compare, class Alloc = alloc>class rb_tree {protected: typedef void* void_pointer; typedef __rb_tree_node_base* base_ptr; typedef __rb_tree_node原创 2020-07-31 11:11:09 · 117 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之deque、queue、stack
1.1 deque1.1.1 deque的主体实现其实现结构图:在内存中实现的形式是分段串接的形式。(分段连续)其中的map是一个T**(vector)实现,其中包含了指向各个内存块buffer的指针,若deque需要扩充内存的话,则使map中前面或后面的指针指向这块内存即可。源码实现:PS:我这里找的和ppt上的不一样,但是基本能看…template <class _Tp, class _Alloc>class _Deque_base : public _Deque_al原创 2020-07-30 15:42:24 · 175 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之array
1.1 Array (TR1版本)注意array没有构造和析构。其迭代器是一个原始指针。原创 2020-07-30 10:32:18 · 127 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之vector
1.1容器vector1.1.1主体实现:template <class _Tp, class _Alloc = allocator<_Tp> >class vector : protected _Vector_base<_Tp, _Alloc> { // requirements: __STL_CLASS_REQUIRES(_Tp, _Assignable);private: typedef _Vector_base<_Tp, _Allo原创 2020-07-30 10:17:14 · 139 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之List
1.1 List Node类型template <class _Tp>struct _List_node { typedef void* _Void_pointer; _Void_pointer _M_next;//后向指针 _Void_pointer _M_prev;//前向指针 _Tp _M_data;//数据域};1.2 List 具体实现1.2.1 List主体template <class _Tp, class _Alloc = __STL_DEFA原创 2020-07-29 15:21:00 · 89 阅读 · 0 评论 -
STL学习(自学手册+源码分析)之空间配置器
标题2.1空间配置器的标准接口allocator::value_typeallocator::pointerallocator::const_pointerallocator::referenceallocator::const_referenceallocator::size_typeallocator::difference_typeallocator::rebind(一个嵌套的class template。class rebind< U>拥有唯一成员other,那原创 2020-07-28 11:05:17 · 167 阅读 · 0 评论 -
STL学习(自学手册+源码分析)
1.2 STL六大组件 功能与运用1.容器(containers):各种数据结构,如vector,list,deque,set,map,用来存放数据。STL容器是一种类模板(calss template )。2.算法(algorithm):各种常用算法如sort、search、copy、erase等。STL算法是一种(函数模板)function template。3.迭代器(iterators):扮演容器与算法之间的“胶合剂”,是所谓的“泛型指针”。从实现角度看,迭代器是一种将*、->、++、–原创 2020-07-28 09:07:22 · 286 阅读 · 0 评论