Loading

STL标准库算法

STL标准库中的算法是什么?

算法是function template.
算法看不见Containers,对其一无所知,所以它所需要的一切信息都必须从iterators取得,而Iterators必须能够回答Algorithm的所有提问,才能搭配Algorithm的所有操作。
算法模板的形式如下:

template<typename Iterator>
Algorithm(Iterator it1,Iterator it2) {
    
}
另一种形式如下:
template<typename Iterator,typename Cmp> //第二个参数是传入一种准则
Algorithm(Iterator it1,Iterator it2,Cmp comp) { //Cmp是一种Functor
    
}
posted @ 2020-02-08 17:12  三只猫-  阅读(382)  评论(0编辑  收藏  举报