Algorithm source code for non-modified sequence operations

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.