⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  <pre class="example-code"> int nums[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int* result; int start = 0; int end = 10;           int targets[] = { 9, 4, 7 }; result = find_first_of( nums + start, nums + end, targets + 0, targets + 2 ); if( *result == nums[end] ) {   cout &lt;&lt; &quot;Did not find any of { 9, 4, 7 }&quot; &lt;&lt; endl; } else {   cout &lt;&lt; &quot;Found a matching target: &quot; &lt;&lt; *result &lt;&lt; endl; }              </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="adjacent_find.html">adjacent_find</a><br>    <a href="find.html">find</a><br>    <a href="find_end.html">find_end</a><br>    <a href="find_if.html">find_if</a><br>    (Standard C String and Character) <a href=    "../stdstring/strpbrk.html">strpbrk</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    find_if  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  iterator find_if( iterator start, iterator end, UnPred up );</pre>  <p>The find_if() function searches for the first element between  <em>start</em> and <em>end</em> for which the unary predicate  <em>up</em> returns true.</p>  <p>If such an element is found, an iterator pointing to that element  is returned. Otherwise, an iterator pointing to <em>end</em> is  returned.</p>  <p>For example, the following code uses find_if() and a  &quot;greater-than-zero&quot; unary predicate to the first positive,  non-zero number in a list of numbers:</p>  <pre class="example-code"> int nums[] = { 0, -1, -2, -3, -4, 342, -5 }; int* result; int start = 0; int end = 7;            result = find_if( nums + start, nums + end, bind2nd(greater&lt;int&gt;(), 0)); if( *result == nums[end] ) {   cout &lt;&lt; &quot;Did not find any number greater than zero&quot; &lt;&lt; endl; } else {   cout &lt;&lt; &quot;Found a positive non-zero number: &quot; &lt;&lt; *result &lt;&lt; endl; }              </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="adjacent_find.html">adjacent_find</a><br>    <a href="equal.html">equal</a><br>    <a href="find.html">find</a><br>    <a href="find_end.html">find_end</a><br>    <a href="find_first_of.html">find_first_of</a><br>    <a href="search_n.html">search_n</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    for_each  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  UnaryFunction for_each( iterator start, iterator end, UnaryFunction f );</pre>  <p>The for_each() algorithm applies the function <em>f</em> to each  of the elements between <em>start</em> and <em>end</em>. The return  value of for_each() is <em>f</em>.</p>  <p>For example, the following code snippets define a unary function  then use it to increment all of the elements of an array:</p>  <pre class="example-code"> template&lt;class <a href="../containers.html">TYPE</a>&gt; struct increment : public unary_function&lt;<a href="../containers.html">TYPE</a>, void&gt; {   void operator() (<a href="../containers.html">TYPE</a>&amp; x) {     x++;   } };              ...             int nums[] = {3, 4, 2, 9, 15, 267}; const int N = 6;                cout &lt;&lt; &quot;Before, nums[] is: &quot;; for( int i = 0; i &lt; N; i++ ) {   cout &lt;&lt; nums[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl;             for_each( nums, nums + N, increment&lt;int&gt;() );             cout &lt;&lt; &quot;After, nums[] is: &quot;; for( int i = 0; i &lt; N; i++ ) {   cout &lt;&lt; nums[i] &lt;&lt; &quot; &quot;; } cout &lt;&lt; endl;            </pre>  <p>The above code displays the following output:</p>  <pre class="example-code"> Before, nums[] is: 3 4 2 9 15 267 After, nums[] is: 4 5 3 10 16 268              </pre>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    generate  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  void generate( iterator start, iterator end, Generator g );</pre>  <p>The generate() function runs the Generator function object  <em>g</em> a number of times, saving the result of each execution in  the range [<em>start</em>,<em>end</em>).</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="copy.html">copy</a><br>    <a href="fill.html">fill</a><br>    <a href="generate_n.html">generate_n</a><br>    <a href="transform.html">transform</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    generate_n  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  iterator generate_n( iterator result, size_t num, Generator g );</pre>  <p>The generate_n() function runs the Generator function object  <em>g</em> <em>num</em> times, saving the result of each execution in  <em>result</em>, (<em>result</em>+1), etc.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="generate.html">generate</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    includes  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  bool includes( iterator start1, iterator end1, iterator start2, iterator end2 );  bool includes( iterator start1, iterator end1, iterator start2, iterator end2, StrictWeakOrdering cmp );</pre>  <p>The includes() algorithm returns true if every element in  [<em>start2</em>,<em>end2</em>) is also in  [<em>start1</em>,<em>end1</em>). Both of the given ranges must be  sorted in ascending order.</p>  <p>By default, the &lt; operator is used to compare elements. If the  strict weak ordering function object <em>cmp</em> is given, then it  is used instead.</p>  <p>includes() runs in <a href="../complexity.html">linear  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="set_difference.html">set_difference</a><br>    <a href="set_intersection.html">set_intersection</a><br>    <a href=    "set_symmetric_difference.html">set_symmetric_difference</a><br>    <a href="set_union.html">set_union</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    inner_product  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;numeric&gt;  <a href="../containers.html">TYPE</a> inner_product( iterator start1, iterator end1, iterator start2, <a href="../containers.html">TYPE</a> val );  <a href="../containers.html">TYPE</a> inner_product( iterator start1, iterator end1, iterator start2, <a href="../containers.html">TYPE</a> val, BinaryFunction f1, BinaryFunction f2 );</pre>  <p>The inner_product() function computes the inner product of  [<em>start1</em>,<em>end1</em>) and a range of the same size starting  at <em>start2</em>.</p>  <p>inner_product() runs in <a href="../complexity.html">linear  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="accumulate.html">accumulate</a><br>    <a href="adjacent_difference.html">adjacent_difference</a><br>    <a href="count.html">count</a><br>    <a href="partial_sum.html">partial_sum</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    inplace_merge  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  inline void inplace_merge( iterator start, iterator middle, iterator end );  inline void inplace_merge( iterator start, iterator middle, iterator end, StrictWeakOrdering cmp );</pre>  <p>The inplace_merge() function is similar to the merge() function,  but instead of creating a new sorted range of elements,  inplace_merge() alters the existing ranges to perform the merge  in-place.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="merge.html">merge</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    is_heap  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  bool is_heap( iterator start, iterator end );  bool is_heap( iterator start, iterator end, StrictWeakOrdering cmp );</pre>  <p>The is_heap() function returns true if the given range  [<em>start</em>,<em>end</em>) is a heap.</p>  <p>If the strict weak ordering comparison function object  <em>cmp</em> is given, then it is used instead of the &lt; operator  to compare elements.</p>  <p>is_heap() runs in <a href="../complexity.html">linear  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="make_heap.html">make_heap</a><br>    <a href="pop_heap.html">pop_heap</a><br>    <a href="push_heap.html">push_heap</a><br>    <a href="sort_heap.html">sort_heap</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    is_sorted  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  bool is_sorted( iterator start, iterator end );  bool is_sorted( iterator start, iterator end, StrictWeakOrdering cmp );</pre>  <p>The is_sorted() algorithm returns true if the elements in the  range [<em>start</em>,<em>end</em>) are sorted in ascending  order.</p>  <p>By default, the &lt; operator is used to compare elements. If the  strict weak order function object <em>cmp</em> is given, then it is  used instead.</p>  <p>is_sorted() runs in <a href="../complexity.html">linear  time</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="binary_search.html">binary_search</a><br>    <a href="partial_sort.html">partial_sort</a><br>    <a href="partial_sort_copy.html">partial_sort_copy</a><br>    <a href="sort.html">sort</a><br>    <a href="stable_sort.html">stable_sort</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    iter_swap  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  inline void iter_swap( iterator a, iterator b );</pre>  <p>A call to iter_swap() exchanges the values of two elements exactly  as a call to</p>  <pre class="example-code"> swap( *a, *b );                </pre>  <p>would.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="swap.html">swap</a><br>    <a href="swap_ranges.html">swap_ranges</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    lexicographical_compare  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;algorithm&gt;  bool lexicographical_compare( iterator start1, iterator end1, iterator start2, iterator end2 );  bool lexicographical_compare( iterator start1, iterator end1, iterator start2, iterator end2, BinPred p );</pre>  <p>The lexicographical_compare() function returns true if the range  of elements [<em>start1</em>,<em>end1</em>) is lexicographically less  than the range of elements [<em>start2</em>,<em>end2</em>).</p>  <p>If you&#39;re confused about what lexicographic means, it might  help to know that dictionaries are ordered lexicographically.</p>  <p>lexicographical_compare() runs in <a href=

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -