一烁兰、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