• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>nth_element</title>
5<link rel="stylesheet" href="../../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../../index.html" title="Chapter 1. Range 2.0">
8<link rel="up" href="../mutating.html" title="Mutating algorithms">
9<link rel="prev" href="merge.html" title="merge">
10<link rel="next" href="partial_sort.html" title="partial_sort">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="merge.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mutating.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="partial_sort.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h5 class="title">
27<a name="range.reference.algorithms.mutating.nth_element"></a><a class="link" href="nth_element.html" title="nth_element">nth_element</a>
28</h5></div></div></div>
29<h6>
30<a name="range.reference.algorithms.mutating.nth_element.h0"></a>
31            <span class="phrase"><a name="range.reference.algorithms.mutating.nth_element.prototype"></a></span><a class="link" href="nth_element.html#range.reference.algorithms.mutating.nth_element.prototype">Prototype</a>
32          </h6>
33<p>
34</p>
35<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;</span>
36<span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">nth_element</span><span class="special">(</span>
37    <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span>
38    <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="identifier">RandomAccessRange</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">nth</span><span class="special">);</span>
39
40<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;</span>
41<span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">nth_element</span><span class="special">(</span>
42    <span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span>
43    <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">nth</span><span class="special">);</span>
44
45<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;</span>
46<span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">nth_element</span><span class="special">(</span>
47    <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span>
48    <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="identifier">RandomAccessRange</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">nth</span><span class="special">,</span>
49    <span class="identifier">BinaryPredicate</span> <span class="identifier">sort_pred</span><span class="special">);</span>
50
51<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;</span>
52<span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">nth_element</span><span class="special">(</span>
53    <span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span>
54    <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">nth</span><span class="special">,</span>
55    <span class="identifier">BinaryPredicate</span> <span class="identifier">sort_pred</span><span class="special">);</span>
56</pre>
57<p>
58          </p>
59<h6>
60<a name="range.reference.algorithms.mutating.nth_element.h1"></a>
61            <span class="phrase"><a name="range.reference.algorithms.mutating.nth_element.description"></a></span><a class="link" href="nth_element.html#range.reference.algorithms.mutating.nth_element.description">Description</a>
62          </h6>
63<p>
64            <code class="computeroutput"><span class="identifier">nth_element</span></code> partially
65            orders a range of elements. <code class="computeroutput"><span class="identifier">nth_element</span></code>
66            arranges the range <code class="computeroutput"><span class="identifier">rng</span></code>
67            such that the element corresponding with the iterator <code class="computeroutput"><span class="identifier">nth</span></code>
68            is the same as the element that would be in that position if <code class="computeroutput"><span class="identifier">rng</span></code> has been sorted.
69          </p>
70<h6>
71<a name="range.reference.algorithms.mutating.nth_element.h2"></a>
72            <span class="phrase"><a name="range.reference.algorithms.mutating.nth_element.definition"></a></span><a class="link" href="nth_element.html#range.reference.algorithms.mutating.nth_element.definition">Definition</a>
73          </h6>
74<p>
75            Defined in the header file <code class="computeroutput"><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">algorithm</span><span class="special">/</span><span class="identifier">nth_element</span><span class="special">.</span><span class="identifier">hpp</span></code>
76          </p>
77<h6>
78<a name="range.reference.algorithms.mutating.nth_element.h3"></a>
79            <span class="phrase"><a name="range.reference.algorithms.mutating.nth_element.requirements"></a></span><a class="link" href="nth_element.html#range.reference.algorithms.mutating.nth_element.requirements">Requirements</a>
80          </h6>
81<p>
82            <span class="bold"><strong>For the non-predicate version:</strong></span>
83          </p>
84<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
85<li class="listitem">
86                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
87                is a model of the <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random
88                Access Range</a> Concept.
89              </li>
90<li class="listitem">
91                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
92                is mutable.
93              </li>
94<li class="listitem">
95                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
96                value type is a model of the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code>.
97              </li>
98<li class="listitem">
99                The ordering relation on <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
100                value type is a <span class="bold"><strong><span class="emphasis"><em>strict weak ordering</em></span></strong></span>,
101                as defined in the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code>
102                requirements.
103              </li>
104</ul></div>
105<p>
106            <span class="bold"><strong>For the predicate version:</strong></span>
107          </p>
108<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
109<li class="listitem">
110                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
111                is a model of the <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random
112                Access Range</a> Concept.
113              </li>
114<li class="listitem">
115                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
116                is mutable.
117              </li>
118<li class="listitem">
119                <code class="computeroutput"><span class="identifier">BinaryPredicate</span></code> is
120                a model of the <code class="computeroutput"><span class="identifier">StrictWeakOrderingConcept</span></code>.
121              </li>
122<li class="listitem">
123                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
124                value type is convertible to both of <code class="computeroutput"><span class="identifier">BinaryPredicate</span></code>'s
125                argument types.
126              </li>
127</ul></div>
128<h6>
129<a name="range.reference.algorithms.mutating.nth_element.h4"></a>
130            <span class="phrase"><a name="range.reference.algorithms.mutating.nth_element.complexity"></a></span><a class="link" href="nth_element.html#range.reference.algorithms.mutating.nth_element.complexity">Complexity</a>
131          </h6>
132<p>
133            On average, linear in <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code>.
134          </p>
135</div>
136<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
137<td align="left"></td>
138<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
139      Neil Groves<p>
140        Distributed under the Boost Software License, Version 1.0. (See accompanying
141        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
142      </p>
143</div></td>
144</tr></table>
145<hr>
146<div class="spirit-nav">
147<a accesskey="p" href="merge.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../mutating.html"><img src="../../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="partial_sort.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
148</div>
149</body>
150</html>
151