algorithm 非修改性序列操作源码

template<class _II, class _Fn> inline
 _Fn for_each(_II _F, _II _L, _Fn _Op)
 {for (; _F != _L; ++_F)
  _Op(*_F);
 return (_Op); }
  // TEMPLATE FUNCTION find
template<class _II, class _Ty> inline
 _II find(_II _F, _II _L, const _Ty& _V)
 {for (; _F != _L; ++_F)
  if (*_F == _V)
   break;
 return (_F); }
  // TEMPLATE FUNCTION find_if
template<class _II, class _Pr> inline
 _II find_if(_II _F, _II _L, _Pr _P)
 {for (; _F != _L; ++_F)
  if (_P(*_F))
   break;
 return (_F); }
  // TEMPLATE FUNCTION adjacent_find
template<class _FI> inline
 _FI adjacent_find(_FI _F, _FI _L)
 {for (_FI _Fb; (_Fb = _F) != _L && ++_F != _L; )
  if (*_Fb == *_F)
   return (_Fb);
 return (_L); }
  // TEMPLATE FUNCTION adjacent_find WITH PRED
template<class _FI, class _Pr> inline
 _FI adjacent_find(_FI _F, _FI _L, _Pr _P)
 {for (_FI _Fb; (_Fb = _F) != _L && ++_F != _L; )
  if (_P(*_Fb, *_F))
   return (_Fb);
 return (_L); }
  // TEMPLATE FUNCTION count
template<class _II, class _Ty> inline
 _CNTSIZ(_II) count(_II _F, _II _L, const _Ty& _V)
 {_CNTSIZ(_II) _N = 0;
 for (; _F != _L; ++_F)
  if (*_F == _V)
   ++_N;
 return (_N); }
  // TEMPLATE FUNCTION count_if
template<class _II, class _Pr> inline
 _CNTSIZ(_II) count_if(_II _F, _II _L, _Pr _P)
 {_CNTSIZ(_II) _N = 0;
 for (; _F != _L; ++_F)
  if (_P(*_F))
   ++_N;
 return (_N); }

template<class _II1, class _II2> inline
 pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X)
 {for (; _F != _L && *_F == *_X; ++_F, ++_X)
  ;
 return (pair<_II1, _II2>(_F, _X)); }
  // TEMPLATE FUNCTION mismatch WITH PRED
template<class _II1, class _II2, class _Pr> inline
 pair<_II1, _II2> mismatch(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
 {for (; _F != _L && _P(*_F, *_X); ++_F, ++_X)
  ;
 return (pair<_II1, _II2>(_F, _X)); }

  // TEMPLATE FUNCTION equal
template<class _II1, class _II2> inline
 bool equal(_II1 _F, _II1 _L, _II2 _X)
 {return (mismatch(_F, _L, _X).first == _L); }
  // TEMPLATE FUNCTION equal WITH PRED
template<class _II1, class _II2, class _Pr> inline
 bool equal(_II1 _F, _II1 _L, _II2 _X, _Pr _P)
 {return (mismatch(_F, _L, _X, _P).first == _L); }

search
Searches for the first occurrence of a sequence within a target range whose elements are
 equal to those in a given sequence of elements or whose elements are equivalent in a sense
 specified by a binary predicate to the elements in the given sequence.

 
template<class ForwardIterator1, class ForwardIterator2>
   ForwardIterator1 search(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      ForwardIterator2 _First2,
      ForwardIterator2 _Last2
   );
template<class ForwardIterator1, class ForwardIterator2, class Pr>
   ForwardIterator1 search(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      ForwardIterator2 _First2,
      ForwardIterator2 _Last2
      BinaryPredicate _Comp
   );
 
search_n
Searches for the first subsequence in a range that of a specified number
of elements having a particular value or a relation to that value as specified by a binary predicate.
 
template<class ForwardIterator1, class Diff2, class Type>
   ForwardIterator1 search_n(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      Size2 _Count,
      const Type& _Val
   );
template<class ForwardIterator1, class Size2, class Type, class BinaryPredicate>
   ForwardIterator1 search_n(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      Size2 _Count,
      const Type& _Val,
      BinaryPredicate _Comp
   );
 
find_end
Looks in a range for the last subsequence that is identical to a
specified sequence or that is equivalent in a sense specified by a binary predicate.
 
template<class ForwardIterator1, class ForwardIterator2>
   ForwardIterator1 find_end(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      ForwardIterator2 _First2,
      ForwardIterator2 _Last2
   );
template<class ForwardIterator1, class ForwardIterator2, class Pr>
   ForwardIterator1 find_end(
      ForwardIterator1 _First1,
      ForwardIterator1 _Last1,
      ForwardIterator2 _First2,
      ForwardIterator2 _Last2,
      BinaryPredicate _Comp
   );
 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值