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
   );
 


 


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2019 ITdaan.com 粤ICP备14056181号