STL源码学习_1 简介概述,仿函数
2016-09-21 01:48
330 查看
STL概述与介绍
1.STL c++标准模版库
STL库包含了c++的基本算法与数据结构的框架,设计精巧,突出了范型编程的特点2.STL 六大组件和运用
容器(containers)算法(algorithms)
迭代器(iterators)
仿函数(functors)
配接器(adapters)
配置器(allocators)
在之后的学习中会简单的介绍上述源码构造以及底层实现
3.仿函数
所谓仿函数是指针对某个class进行()重载,它就成为了一个仿函数。对于一个可配接的仿函数,还需要小小努力。// // Created by 王若璇 on 16/9/21. // #include <iostream> using namespace std; template <class T> //将operator()重载了,因此plus成了一个仿函数 struct Plus{ T operator()(const T& x,const T& y) const{ return x+y; } }; template <class T> struct Minus{ T operator()(const T& x,const T& y) const { return x-y; } }; int main(){ //以下产生仿函数对象 Plus<int> plusobj; Minus<int> minusobj; //以下使用仿函数 cout<<plusobj(3,5)<<endl; cout<<minusobj(3,5)<<endl; //以下直接产生仿函数的临时对象 并调用 cout<<Plus<int>()(4,10)<<endl; cout<<Minus<double>()(3.5,4.1)<<endl; return 0; }
运行以上代码结果测试正确,仿函数类似与构造函数,但又不同,会在之后的学习中继续研究。之后学习空间配置器(allocator)。近期更新。
相关文章推荐
- STL源码学习——仿函数和配接器
- STL之仿函数,适配器简介
- STL 学习笔记 ( 一. 概述 )
- STL源码学习——Vector(向量)
- C++ Standard Stl -- SGI STL源码学习笔记(02) Concepts Check
- STL源码学习----lower_bound和upper_bound算法
- STL学习笔记1—概述
- STL源码学习----next_permutation和prev_permutation算法
- C++ Standard Stl -- SGI STL源码学习笔记(06) stl_vector 与 一些问题的细化 2 push_back函数剖析
- STL源码剖析学习十七:算法之其他算法
- C++ Standard Stl -- SGI STL源码学习笔记(03) STL中的模板编译期检查与偏特化编译期检查
- STL 学习笔记 ( 一. 概述 )
- STL学习笔记----1.概述
- stl-stable_sort源码学习笔记
- STL源码学习——Lists(链表)
- chrome源码学习之启动流程简介
- stl-stable_sort源码学习笔记
- STL源码学习----迭代器及其适配器
- C++ Standard Stl -- SGI STL源码学习笔记(01) auto_ptr
- C++ Standard Stl -- SGI STL源码学习笔记(05) stl_vector 与 一些问题的细化 1