STL源码剖析
I_ren
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
STL源码剖析——基础
六大部件 模板 类模板 函数模板 成员模板(类拥有本身为类模板或函数模板的成员) 特化:优先选择特化版本 template<class T> struct __type_traits { ... }; template<> struct __type_traits<int> { ... }; template<> struct __type_traits<char> { ... }; .... 偏.原创 2020-07-07 19:08:15 · 679 阅读 · 0 评论 -
STL源码剖析——allocator
1 // in oom_malloc for(;;) { //如果没有设定内存不足处理例程,则直接抛出异常 if (0 == __malloc_alloc_oom_handler) {__THROW_BAD_ALLOC;} (*__malloc_alloc_oom_handler)(); result = malloc(n); if (result) return result; } 2 // free-list节点结构 union obj { un原创 2020-07-09 22:31:10 · 358 阅读 · 0 评论 -
STL源码剖析——Allocator
1 //构造 auto_ptr<string> ps(new string("jjhou"); //获取指针 ps.get(); //重载*, -> cout << *ps << endl; cout << ps->size() << endl; 2 //获取class类型的迭代器value_type template<class I> struct iterator_traits { typedef ty原创 2020-07-13 19:34:17 · 282 阅读 · 0 评论 -
STL源码剖析——vector
vector结构体: template <class T, class Alloc = alloc> class vector { public: typedef T value_type; typedef value_type* pointer; typedef value_type* iterator; typedef value_type& reference; typedef size_t size_typ原创 2020-07-21 17:34:01 · 302 阅读 · 0 评论 -
STL源码剖析——链表
list 环状双向列表 template <class T> struct __list_node { typedef void* void_pointer; void_pointer prev; void_pointer next; T data; } 迭代器 bidirectional iterators 插入删除过程中其他迭代器不受影响 template<class T, class Ref, class Ptr> st.原创 2020-07-21 17:34:57 · 427 阅读 · 0 评论 -
STL源码剖析——deque
1 template <class T, class Alloc = alloc> class vector { public: typedef T value_type; typedef value_type* pointer; typedef value_type* iterator; typedef value_type& reference; typedef size_t size_type; ty原创 2020-07-21 18:02:56 · 291 阅读 · 0 评论 -
STL源码剖析——容器适配器stack, queue
stack 不提供迭代器和遍历 //默认用deque进行适配 template<class T, class Sequence = deque<T>> class stack { friend bool operator==__STL_NULL_TMPL_ARGS(const stack&, const stack&); friend bool operator<__STL_NULL_TMPL_ARGS(const stack&a.原创 2020-07-21 18:31:33 · 228 阅读 · 0 评论 -
STL源码剖析——heap
binary_heap 一种完全二叉树 假设array[0]号元素设为无限大或无限小,则某个节点位于array[i]时,它的左孩子节点位于array[2i]处,右孩子节点位于array[2i+1]处,父节点位于array[i/2]处 插入元素:push_heap 首先需要将插入的元素放在vector尾部 进行上溯:与父节点比较,如果父节点小则交换位置,直到不需要对换或到达根节点为止 template <class RandomAccessIterator> in..原创 2020-07-22 18:24:48 · 265 阅读 · 0 评论 -
STL源码剖析——rb_tree, map, set
1 template <class Key, class Value, class KeyOfValue, class Compare, class Alloc = alloc> class rb_tree { protected: size_type node_count; link_type header; Compare key_compare; public: typedef __rb_tree_iterator<value_type, refe原创 2020-07-28 16:51:11 · 335 阅读 · 0 评论 -
STL源码剖析——hashtable, unordered_set, unordered_map
1 template <class Value> struct __hashtable_node { __hashtable_node *next; Value val; }; 1 template <class Value, class Key, class HashFcn, class ExtractKey, class EqualKey, class Alloc> struct __hashtable_iterator { node *cur;原创 2020-07-30 20:25:22 · 331 阅读 · 0 评论 -
STL源码剖析——算法
1 #include <numeric> //计算累积总和 template <class InputIterator, class T> T accumulate<InputIterator first, InputIterator last, T init) { for (; first != last; ++first) init = init + *first; return init; } //将相邻两元素的差(后-前)赋值给目原创 2020-08-14 15:01:28 · 465 阅读 · 0 评论 -
STL源码剖析——仿函数
仿函数定义与用法 用法: #include <functional> greater<int> ig; cout << ig(4,6) << endl; cout << greater<int>()(4,6) << endl; accumulate(iv.begin(), iv.end(), 1, multiplies<int>()); 可配接性 继承unary_function/binary_原创 2020-08-16 20:19:07 · 241 阅读 · 0 评论 -
STL源码剖析——适配器
设计模式定义 将一个class接口转换为另一个class接口 种类 容器adapter:stack, queue 迭代器adapter:reverse iterator, inserter iterator, iostream iterator 仿函数adapter 函数适配器 bind bind1st/bind2nd:绑定第1/2个参数 template <class Operation> class binder2nd : public unary_funct..原创 2020-08-19 17:48:17 · 240 阅读 · 0 评论 -
STL源码剖析——其他
哈希函数 自定义哈希函数: class CustomerHash { public: size_t operator() (const Customer &c) const { return hash_val(c.fname, c.Iname, c.no); } }; 库提供的hash_val函数: // 第一步调用 template <typename... Types> inline size_t hash_val(const Types&原创 2020-08-19 18:01:00 · 246 阅读 · 0 评论
分享