📄 algorith.html
字号:
It then returns <CODE>first1 + N</CODE>.If no such value exists, the function returns <CODE>last1</CODE>.It evaluates the predicate at most <CODE>(last2 - first2) *(last1 - first1 - (last2 - first2) + 1)</CODE> times.</P><P>The second template function behaves the same, except thatthe predicate is <CODE>pred(*(first1 + N + M), *(first2 + N + M))</CODE>.</P><H2><A NAME="find_first_of"><CODE>find_first_of</CODE></A></H2><PRE>template<class FwdIt1, class FwdIt2> FwdIt1 <B>find_first_of</B>(FwdIt1 first1, FwdIt1 last1, FwdIt2 first2, FwdIt2 last2);template<class FwdIt1, class FwdIt2, class Pr> FwdIt1 <B>find_first_of</B>(FwdIt1 first1, FwdIt1 last1, FwdIt2 first2, FwdIt2 last2, Pr pred);</PRE><P>The first template function determines the lowest value of<CODE>N</CODE> in the range <CODE>[0, last1 - first1)</CODE> such thatfor some <CODE>M</CODE> in the range <CODE>[0, last2 - first2)</CODE>,the predicate <CODE>*(first1 + N) == *(first2 + M)</CODE> is true.Here, <CODE>operator==</CODE> must perform a<A HREF="lib_stl.html#pairwise comparison">pairwise comparison</A>between its operands.It then returns <CODE>first1 + N</CODE>.If no such value exists, the function returns <CODE>last1</CODE>.It evaluates the predicate at most<CODE>(last1 - first1) * (last2 - first2)</CODE> times.</P><P>The second template function behaves the same, except thatthe predicate is <CODE>pred(*(first1 + N), *(first2 + M))</CODE>.</P><H2><A NAME="find_if"><CODE>find_if</CODE></A></H2><PRE>template<class InIt, class Pr> InIt <B>find_if</B>(InIt first, InIt last, Pr pred);</PRE><P>The template function determines the lowest value of <CODE>N</CODE>in the range <CODE>[0, last - first)</CODE> for which the predicate<CODE>pred(*(first + N))</CODE> is true.It then returns <CODE>first + N</CODE>.If no such value exists, the function returns <CODE>last</CODE>.It evaluates the predicate at most oncefor each <CODE>N</CODE>.</P><H2><A NAME="for_each"><CODE>for_each</CODE></A></H2><PRE>template<class InIt, class Fn1> Fn1 <B>for_each</B>(InIt first, InIt last, Fn1 func);</PRE><P>The template function evaluates <CODE>func(*(first + N))</CODE> once foreach <CODE>N</CODE> in the range <CODE>[0, last - first)</CODE>.It then returns <CODE>func</CODE>.</P><H2><A NAME="generate"><CODE>generate</CODE></A></H2><PRE>template<class FwdIt, class Fn0> void <B>generate</B>(FwdIt first, FwdIt last, Fn0 func);</PRE><P>The template function evaluates <CODE>*(first + N) = func()</CODE> once foreach <CODE>N</CODE> in the range <CODE>[0, last - first)</CODE>.</P><H2><A NAME="generate_n"><CODE>generate_n</CODE></A></H2><PRE>template<class OutIt, class Pr, class Fn0> void <B>generate_n</B>(OutIt first, Diff count, Fn0 func);</PRE><P>The template function evaluates <CODE>*(first + N) = func()</CODE> once foreach <CODE>N</CODE> in the range <CODE>[0, count)</CODE>.</P><H2><A NAME="includes"><CODE>includes</CODE></A></H2><PRE>template<class InIt1, class InIt2> bool <B>includes</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2);template<class InIt1, class InIt2, class Pr> bool <B>includes</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2, Pr pred);</PRE><P>The first template function determines whethera value of <CODE>N</CODE> existsin the range <CODE>[0, last2 - first2)</CODE> such that,for each <CODE>M</CODE> in the range <CODE>[0, last1 - first1)</CODE>,<CODE>*(first1 + M)</CODE> and <CODE>*(first2 + N)</CODE> do not have<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>,where the elements designated by iteratorsin the ranges <CODE>[first1, last1)</CODE>and <CODE>[first2, last2)</CODE> each form a sequence<A HREF="lib_stl.html#sequence ordering">ordered by</A> <CODE>operator<</CODE>.If so, the function returns false.If no such value exists, it returns true.Thus, the function determines whether the ordered sequencedesignated by iterators in the range<CODE>[first2, last2)</CODE> all have equivalent ordering with someelement designated by iterators in the range<CODE>[first1, last1)</CODE>.</P><P>The function evaluates the predicate at most<CODE>2 * ((last1 - first1) + (last2 - first2)) - 1</CODE> times.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="inplace_merge"><CODE>inplace_merge</CODE></A></H2><PRE>template<class BidIt> void <B>inplace_merge</B>(BidIt first, BidIt mid, BidIt last);template<class BidIt, class Pr> void <B>inplace_merge</B>(BidIt first, BidIt mid, BidIt last, Pr pred);</PRE><P>The first template function reorders thesequences designated by iterators in the ranges <CODE>[first, mid)</CODE>and <CODE>[mid, last)</CODE>, each<A HREF="lib_stl.html#sequence ordering">ordered by</A> <CODE>operator<</CODE>,to form a merged sequence of length <CODE>last - first</CODE>beginning at <CODE>first</CODE> also ordered by <CODE>operator<</CODE>.The merge occurs without altering the relative order ofelements within either original sequence. Moreover, for any two elementsfrom different original sequences that have<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>,the element from the ordered range <CODE>[first, mid)</CODE>precedes the other.</P><P>The function evaluates the ordering predicate<CODE>X < Y</CODE> at most<CODE>ceil((last - first) * log(last - first))</CODE> times.(Given enough temporary storage, it can evaluate the predicate at most<CODE>(last - first) - 1</CODE> times.)</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="iter_swap"><CODE>iter_swap</CODE></A></H2><PRE>template<class FwdIt1, class FwdIt2> void <B>iter_swap</B>(FwdIt1 left, FwdIt2 right);</PRE><P>The template function leaves the value originally stored in<CODE>*right</CODE> subsequently stored in <CODE>*left</CODE>,and the value originally stored in <CODE>*left</CODE>subsequently stored in <CODE>*right</CODE>.</P><H2><A NAME="lexicographical_compare"><CODE>lexicographical_compare</CODE></A></H2><PRE>template<class InIt1, class InIt2> bool <B>lexicographical_compare</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2);template<class InIt1, class InIt2, class Pr> bool <B>lexicographical_compare</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2, Pr pred);</PRE><P>The first template function determines <CODE>K</CODE>,the number of elements to compare as the smaller of<CODE>last1 - first1</CODE> and <CODE>last2 - first2</CODE>.It then determines the lowest value of <CODE>N</CODE>in the range <CODE>[0, K)</CODE> for which<CODE>*(first1 + N)</CODE> and <CODE>*(first2 + N)</CODE> do not have<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>.If no such value exists, the function returns true only if<CODE>K < (last2 - first2)</CODE>. Otherwise, it returnstrue only if <CODE>*(first1 + N) < *(first2 + N)</CODE>.Thus, the function returns true only if the sequence designatedby iterators in the range <CODE>[first1, last1)</CODE> islexicographically less than the other sequence.</P><P>The function evaluates the ordering predicate<CODE>X < Y</CODE> at most <CODE>2 * K</CODE> times.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="lower_bound"><CODE>lower_bound</CODE></A></H2><PRE>template<class FwdIt, class Ty> FwdIt <B>lower_bound</B>(FwdIt first, FwdIt last, const Ty& val);template<class FwdIt, class Ty, class Pr> FwdIt <B>lower_bound</B>(FwdIt first, FwdIt last, const Ty& val, Pr pred);</PRE><P>The first template function determines the highest value of <CODE>N</CODE>in the range <CODE>(0, last - first]</CODE> such that,for each <CODE>M</CODE> in the range <CODE>[0, N)</CODE>the predicate <CODE>*(first + M) < val</CODE> is true,where the elements designated by iteratorsin the range <CODE>[first, last)</CODE> form a sequence<A HREF="lib_stl.html#sequence ordering">ordered by</A> <CODE>operator<</CODE>.It then returns <CODE>first + N</CODE>.Thus, the function determines the lowest positionbefore which <CODE>val</CODE> can be inserted in the sequenceand still preserve its ordering.</P><P>The function evaluates the ordering predicate <CODE>X < Y</CODE> at most<CODE>ceil(log(last - first)) + 1</CODE> times.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="make_heap"><CODE>make_heap</CODE></A></H2><PRE>template<class RanIt> void <B>make_heap</B>(RanIt first, RanIt last);template<class RanIt, class Pr> void <B>make_heap</B>(RanIt first, RanIt last, Pr pred);</PRE><P>The first template function reorders the sequencedesignated by iterators in therange <CODE>[first, last)</CODE> to form a heap<A HREF="lib_stl.html#heap ordering">ordered by</A> <CODE>operator<</CODE>.</P><P>The function evaluates the ordering predicate<CODE>X < Y</CODE> at most<CODE>3 * (last - first)</CODE> times.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="max"><CODE>max</CODE></A></H2><PRE>template<class Ty> const Ty& <B>max</B>(const Ty& left, const Ty& right);template<class Ty, class Pr> const Ty& <B>max</B>(const Ty& left, const Ty& right, Pr pred);</PRE><P>The first template function returns <CODE>right</CODE> if<CODE>left < right</CODE>. Otherwise it returns <CODE>left</CODE>.<CODE>Ty</CODE> need supply only a single-argument constructor and adestructor.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="max_element"><CODE>max_element</CODE></A></H2><PRE>template<class FwdIt> FwdIt <B>max_element</B>(FwdIt first, FwdIt last);template<class FwdIt, class Pr> FwdIt <B>max_element</B>(FwdIt first, FwdIt last, Pr pred);</PRE><P>The first template function determines the lowest value of <CODE>N</CODE>in the range <CODE>[0, last - first)</CODE> such that,for each <CODE>M</CODE> in the range <CODE>[0, last - first)</CODE>the predicate <CODE>*(first + N) < *(first + M)</CODE> is false.It then returns <CODE>first + N</CODE>.Thus, the function determines the lowest positionthat contains the largest value in the sequence.</P><P>The function evaluates the ordering predicate<CODE>X < Y</CODE> exactly<CODE>max((last - first) - 1, 0)</CODE> times.</P><P>The second template function behaves the same, except thatit replaces <CODE>operator<(X, Y)</CODE> with<CODE>pred(X, Y)</CODE>.</P><H2><A NAME="merge"><CODE>merge</CODE></A></H2><PRE>template<class InIt1, class InIt2, class OutIt> OutIt <B>merge</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2, OutIt dest);template<class InIt1, class InIt2, class OutIt, class Pr> OutIt <B>merge</B>(InIt1 first1, InIt1 last1, InIt2 first2, InIt2 last2, OutIt dest, Pr pred);</PRE><P>The first template function determines <CODE>K</CODE>,the number of elements to copy as <CODE>(last1 - first1) +(last2 - first2)</CODE>. It then alternatelycopies two sequences, designated by iteratorsin the ranges <CODE>[first1, last1)</CODE>and <CODE>[first2, last2)</CODE> and each<A HREF="lib_stl.html#sequence ordering">ordered by</A> <CODE>operator<</CODE>,to form a merged sequence of length <CODE>K</CODE> beginningat <CODE>dest</CODE>, also ordered by <CODE>operator<</CODE>.The function then returns <CODE>dest + K</CODE>.</P><P>The merge occurs without altering the relative order ofelements within either sequence. Moreover, for any two elementsfrom different sequences that have<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>,the element from the ordered range <CODE>[first1, last1)</CODE>precedes the other. Thus, the function merges two orderedsequences to form another ordered sequence.</P><P>If <CODE>dest</CODE> and <CODE>first1</CODE> designate regions of storage,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -