【STL算法】常用算法原型整理
STL中常用算法的算法原型整理如下
//查找重复元素
_NODISCARD _FwdIt adjacent_find(const _FwdIt _First, _FwdIt _Last, _Pr _Pred);
_NODISCARD _FwdIt adjacent_find(const _FwdIt _First, const _FwdIt _Last);
//二分查找(有序数列)
_NODISCARD bool binary_search(_FwdIt _First, _FwdIt _Last, const _Ty& _Val, _Pr _Pred);
_NODISCARD bool binary_search(_FwdIt _First, _FwdIt _Last, const _Ty& _Val);
//计数
_NODISCARD _Iter_diff_t<_InIt> count(const _InIt _First, const _InIt _Last, const _Ty& _Val);
//计数(符合条件元素个数)
_NODISCARD _Iter_diff_t<_InIt> count_if(_InIt _First, _InIt _Last, _Pr _Pred);
//查找等于_Val的元素
_NODISCARD _InIt find(_InIt _First, const _InIt _Last, const _Ty& _Val);
//根据条件查找
_NODISCARD _InIt find_if(_InIt _First, const _InIt _Last, _Pr _Pred);
//合并两个有序序列
_DestTy* merge(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize], _Pr _Pred);
_OutIt merge(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest, _Pr _Pred);
_DestTy* merge(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize]);
_OutIt merge(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest);
//排序
void sort(const _RanIt _First, const _RanIt _Last, _Pr _Pred);
void sort(const _RanIt _First, const _RanIt _Last);
//随机排序
void random_shuffle(_RanIt _First, _RanIt _Last, _RngFn&& _RngFunc);
void random_shuffle(_RanIt _First, _RanIt _Last);
//倒序
void reverse(const _BidIt _First, const _BidIt _Last);
//复制
_DestTy* copy(_InIt _First, _InIt _Last, _DestTy (&_Dest)[_DestSize]);
_OutIt copy(_InIt _First, _InIt _Last, _OutIt _Dest);
//替换
void replace(const _FwdIt _First, const _FwdIt _Last, const _Ty& _Oldval, const _Ty& _Newval);
//按条件替换
void replace_if(const _FwdIt _First, const _FwdIt _Last, _Pr _Pred, const _Ty& _Val);
//交换
void swap(tuple<_Types...>& _Left, tuple<_Types...>& _Right);
void swap(basic_string<_Elem, _Traits, _Alloc>& _Left, basic_string<_Elem, _Traits, _Alloc>& _Right);
void swap(function<_Fty>& _Left, function<_Fty>& _Right);
void swap(_Ty (&_Left)[_Size], _Ty (&_Right)[_Size]);
void swap(_Ty& _Left, _Ty& _Right);
void swap(weak_ptr<_Ty>& _Left, weak_ptr<_Ty>& _Right);
void swap(shared_ptr<_Ty>& _Left, shared_ptr<_Ty>& _Right);
void swap(pair<_Ty1, _Ty2>& _Left, pair<_Ty1, _Ty2>& _Right);
//填充
void fill(const _FwdIt _First, const _FwdIt _Last, const _Ty& _Val);
//集合并集
_DestTy* set_union(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize], _Pr _Pred);
_DestTy* set_union(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize]);
_OutIt set_union(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest, _Pr _Pred);
_OutIt set_union(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest);
//交集
_DestTy* set_intersection(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize], _Pr _Pred);
_DestTy* set_intersection(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize]);
_OutIt set_intersection(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest, _Pr _Pred);
_OutIt set_intersection(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest);
//差集
_DestTy* set_difference(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize], _Pr _Pred);
_DestTy* set_difference(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _DestTy (&_Dest)[_DestSize]);
_OutIt set_difference(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest, _Pr _Pred);
_OutIt set_difference(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest);
//遍历
_Fn for_each(_InIt _First, _InIt _Last, _Fn _Func);
//遍历并修改
_DestTy* transform(const _InIt _First, const _InIt _Last, _DestTy (&_Dest)[_DestSize], _Fn _Func);
_OutIt transform(const _InIt _First, const _InIt _Last, _OutIt _Dest, _Fn _Func);
_DestTy* transform(const _InIt1 _First1, const _InIt1 _Last1, _InIt2 _First2, _DestTy (&_Dest)[_DestSize], _Fn _Func);
_OutIt transform(const _InIt1 _First1, const _InIt1 _Last1, const _InIt2 _First2, _OutIt _Dest, _Fn _Func);
_DestTy* transform(const _InIt1 _First1, const _InIt1 _Last1, _RightTy (&_First2)[_RightSize], _DestTy (&_Dest)[_DestSize], _Fn _Func);
_OutIt transform(const _InIt1 _First1, const _InIt1 _Last1, _RightTy (&_First2)[_RightSize], const _OutIt _Dest, _Fn _Func);