一、C++ 标准库的算法
1. 语言层面:
Container is Class template
Algorithm is function template
Iterator is class template
Functor is class template
Adapter is class template
Allocator is class template
Algorithm 需要充iterator 获取相关容器的信息;
二、iterator分类
1. struct input_iterator_tag{}
2. struct output_iterator_tag{}
3. struct forward_iterator_tag: public input_itertator_tag{}
4. struct bidirectional_iterator_tag:public forward_iterator_tag{}
5. struct random_access_iterator_tag:public bidirectional_iterator_tag{}
算法通过迭代器来访问相关数据, 通过iterator_traits获取iterator相关参数
三、算法
1. 形式如:
template <typename Iterator>
std::Algorithm(Iterator itr1, Iterator itr2, ...)
{ ... }
常用算法:
1. accumulate;
2. for_each
3. replace, replace_if , replace_copy
4. count , count_if
5. find, find_if
6. sort
7. reverse iterator, rbegin, rend
8. binary_search
9. functors: binary_function<T, T, T>, unary_function<T, T>
四、Adapters
1. 容器适配器
stack,queue对于deque
2. 函数适配器: 将函数, 仿函数(类operator())做为参数传入
binder2nd
not1
bind (C++11)
3. 迭代器重载
reverse_iterator
inserter
ostream_iterator
istream iterator