
STL学习
文章平均质量分 91
pisuto
这个作者很懒,什么都没留下…
展开
-
C++ template meta-programming 一步步实现快速排序
参考链接:https://github.com/MagicBowen/tlp/tree/master/include/tlp、https://www.jianshu.com/p/b56d59f77d53 具体代码实现:https://github.com/pisuto/tinySTLLearning/tree/master/Test/TemplateMetaProgramLearning 一、数值结构 在实现快速排序之前,首先是定义存储数据的类型结构。在模板元编程中,每一个值其实是使用一个...原创 2021-10-04 11:56:10 · 254 阅读 · 0 评论 -
C++ STL basic_string.h
全部代码(待续...) #pragma once // 字符串类型 #include <iostream> #include <cassert> #include "iterator.h" #include "memory.h" #include "functional.h" namespace tinySTL { template<typename CharType> struct char_traits { using char_type =原创 2020-09-29 19:57:34 · 818 阅读 · 0 评论 -
C++ STL util.h
全部代码 #pragma once // util.h中主要包括一些通用工具,包括 move, forward, swap 等函数,以及 pair 等 #include "type_traits.h" namespace tinySTL { // move // 如果想取得对某一对象执行移动操作,不要将其声明为常量,因为针对常量对象执行的 // 移动操作将变换为复制操作 template<typename T> remove_reference_t<T>&原创 2020-09-29 19:55:36 · 1542 阅读 · 0 评论 -
C++ STL uninitialized.h
全部代码 #pragma once #include "algobase.h" #include "construct.h" #include "iterator.h" #include "type_traits.h" #include "util.h" namespace tinySTL { // uninitialize_copy 把[first, last)上的内容复制到以result为起始处的空间,返回复制结束的位置 template<typename InputIter, ty原创 2020-09-29 19:54:16 · 335 阅读 · 0 评论 -
C++ STL type_traits.h
全部代码 #pragma once #include <type_traits> // 可以继续添加 namespace tinySTL { // enable_if template<bool B, typename T = void> struct enable_if {}; template<typename T> struct enable_if<true, T> { using type = T; }; temp原创 2020-09-29 19:52:32 · 380 阅读 · 0 评论 -
C++ STL iterator.h
全部代码 #pragma once #include "type_traits.h" namespace tinySTL { // 五种迭代器类型 struct input_iterator_tag {}; struct output_iterator_tag {}; struct forward_iterator_tag : public input_iterator_tag {}; struct bidirectional_iterator_tag : public forward_原创 2020-09-29 19:51:26 · 411 阅读 · 0 评论 -
C++ STL functional.h
全部代码 #pragma once // 包含函数对象和哈希函数 functor仿函数 namespace tinySTL { // 定义一元函数的参数类别和返回值型别 template<typename Arg, typename Result> struct unarg_function { using argument_type = Arg; using result_type = Result; }; // 二元函数 template<typenam原创 2020-09-29 19:50:34 · 425 阅读 · 0 评论 -
C++ STL construct.h
全部代码 #pragma once #include <new> #include "type_traits.h" #include "iterator.h" namespace tinySTL { // construct template<typename T> void construct(T* p) { ::new((void*)p) T(); } template<typename T1, typename T2> void co原创 2020-09-29 19:49:24 · 305 阅读 · 0 评论 -
C++ STL allocator.h
全部代码 #pragma once #include "alloc.h" namespace tinySTL { template <typename T, typename Alloc> class allocator { public: using value_type = T; using pointer = T*; using const_pointer = const T*; using reference原创 2020-09-29 19:47:54 · 332 阅读 · 0 评论 -
C++ STL alloc.h
全部代码 #pragma once #include <new> #include <cstdio> namespace tinySTL { // 4 = sizeof FreeList union FreeList { union FreeList* next; char data[1]; }; // 为了便于管理,二级空间配置器在分配的时候都是以8的倍数对齐。也就是说 // 二级配置器会将任何小块内存的需求上调到8的倍数处(例如:要7个字节,会 /原创 2020-09-29 19:46:46 · 345 阅读 · 0 评论 -
C++ STL algobase.h
全部代码 #pragma once #include <cstring> #include "util.h" #include "iterator.h" namespace tinySTL { template<typename T> const T& max(const T& lhs, const T& rhs) { return lhs < rhs ? rhs : lhs; } template<typename T,原创 2020-09-29 19:45:18 · 683 阅读 · 0 评论 -
C++ STL memory.h 系列二
智能指针 参考书录:Effective Modern C++ 第四章 智能指针 1. unique_ptr unique_ptr比auto_ptr更为高级,使用移动语义实现了原对象的置空,以下是一个例子: class A { public: A() {} A(const A&) = delete; A(A&&) { std::cout << "move construction" << std::endl; } }; A原创 2020-09-18 11:38:41 · 356 阅读 · 0 评论 -
C++ STL memory.h 系列一
智能指针 “memory.h” 几个常见的智能指针: 1. auto_ptr 参考链接:https://github.com/Alinshans/MyTinySTL/blob/master/MyTinySTL/memory.h 可以使用unique_ptr替换auto_ptr的功能 其中,并没有类似于unique_ptr、shared_ptr、weak_ptr的判断初始化和赋值时类型不同带来的问题 //----------------------------------------------原创 2020-09-17 20:37:18 · 911 阅读 · 1 评论