• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>sort</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="rotate_copy.html" title="rotate_copy">
10<link rel="next" href="stable_partition.html" title="stable_partition">
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="rotate_copy.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="stable_partition.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.sort"></a><a class="link" href="sort.html" title="sort">sort</a>
28</h5></div></div></div>
29<h6>
30<a name="range.reference.algorithms.mutating.sort.h0"></a>
31            <span class="phrase"><a name="range.reference.algorithms.mutating.sort.prototype"></a></span><a class="link" href="sort.html#range.reference.algorithms.mutating.sort.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">sort</span><span class="special">(</span><span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">);</span>
37
38<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>
39<span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">sort</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">);</span>
40
41<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">BinaryPredicate</span><span class="special">&gt;</span>
42<span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">sort</span><span class="special">(</span><span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span> <span class="identifier">BinaryPredicate</span> <span class="identifier">pred</span><span class="special">);</span>
43
44<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessRange</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">BinaryPredicate</span><span class="special">&gt;</span>
45<span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">sort</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">RandomAccessRange</span><span class="special">&amp;</span> <span class="identifier">rng</span><span class="special">,</span> <span class="identifier">BinaryPredicate</span> <span class="identifier">pred</span><span class="special">);</span>
46</pre>
47<p>
48          </p>
49<h6>
50<a name="range.reference.algorithms.mutating.sort.h1"></a>
51            <span class="phrase"><a name="range.reference.algorithms.mutating.sort.description"></a></span><a class="link" href="sort.html#range.reference.algorithms.mutating.sort.description">Description</a>
52          </h6>
53<p>
54            <code class="computeroutput"><span class="identifier">sort</span></code> sorts the elements
55            in <code class="computeroutput"><span class="identifier">rng</span></code> into ascending
56            order. <code class="computeroutput"><span class="identifier">sort</span></code> is not guaranteed
57            to be stable. Returns the sorted range.
58          </p>
59<p>
60            For versions of the <code class="computeroutput"><span class="identifier">sort</span></code>
61            function without a predicate, ascending order is defined by <code class="computeroutput"><span class="keyword">operator</span><span class="special">&lt;()</span></code>
62            such that for all adjacent elements <code class="computeroutput"><span class="special">[</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">]</span></code>,
63            <code class="computeroutput"><span class="identifier">y</span> <span class="special">&lt;</span>
64            <span class="identifier">x</span> <span class="special">==</span>
65            <span class="keyword">false</span></code>.
66          </p>
67<p>
68            For versions of the <code class="computeroutput"><span class="identifier">sort</span></code>
69            function with a predicate, ascending order is defined by <code class="computeroutput"><span class="identifier">pred</span></code> such that for all adjacent elements
70            <code class="computeroutput"><span class="special">[</span><span class="identifier">x</span><span class="special">,</span><span class="identifier">y</span><span class="special">]</span></code>, <code class="computeroutput"><span class="identifier">pred</span><span class="special">(</span><span class="identifier">y</span><span class="special">,</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="keyword">false</span></code>.
71          </p>
72<h6>
73<a name="range.reference.algorithms.mutating.sort.h2"></a>
74            <span class="phrase"><a name="range.reference.algorithms.mutating.sort.definition"></a></span><a class="link" href="sort.html#range.reference.algorithms.mutating.sort.definition">Definition</a>
75          </h6>
76<p>
77            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">sort</span><span class="special">.</span><span class="identifier">hpp</span></code>
78          </p>
79<h6>
80<a name="range.reference.algorithms.mutating.sort.h3"></a>
81            <span class="phrase"><a name="range.reference.algorithms.mutating.sort.requirements"></a></span><a class="link" href="sort.html#range.reference.algorithms.mutating.sort.requirements">Requirements</a>
82          </h6>
83<p>
84            <span class="bold"><strong>For versions of sort without a predicate:</strong></span>
85          </p>
86<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
87<li class="listitem">
88                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
89                is a model of the <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random
90                Access Range</a> Concept.
91              </li>
92<li class="listitem">
93                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
94                is mutable.
95              </li>
96<li class="listitem">
97                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
98                value type is a model of the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code>.
99              </li>
100<li class="listitem">
101                The ordering relation on <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
102                value type is a <span class="bold"><strong>strict weak ordering</strong></span>,
103                as defined in the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code>
104                requirements.
105              </li>
106</ul></div>
107<p>
108            <span class="bold"><strong>For versions of sort with a predicate</strong></span>
109          </p>
110<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
111<li class="listitem">
112                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
113                is a model of the <a class="link" href="../../../concepts/random_access_range.html" title="Random Access Range">Random
114                Access Range</a> Concept.
115              </li>
116<li class="listitem">
117                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>
118                is mutable.
119              </li>
120<li class="listitem">
121                <code class="computeroutput"><span class="identifier">BinaryPredicate</span></code> is
122                a model of the <code class="computeroutput"><span class="identifier">StrictWeakOrderingConcept</span></code>.
123              </li>
124<li class="listitem">
125                <code class="computeroutput"><span class="identifier">RandomAccessRange</span></code>'s
126                value type is convertible to both of <code class="computeroutput"><span class="identifier">BinaryPredicate</span></code>'s
127                argument types.
128              </li>
129</ul></div>
130<h6>
131<a name="range.reference.algorithms.mutating.sort.h4"></a>
132            <span class="phrase"><a name="range.reference.algorithms.mutating.sort.complexity"></a></span><a class="link" href="sort.html#range.reference.algorithms.mutating.sort.complexity">Complexity</a>
133          </h6>
134<p>
135            <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">N</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">N</span><span class="special">))</span></code> comparisons (both average and worst-case),
136            where <code class="computeroutput"><span class="identifier">N</span></code> is <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code>.
137          </p>
138</div>
139<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
140<td align="left"></td>
141<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
142      Neil Groves<p>
143        Distributed under the Boost Software License, Version 1.0. (See accompanying
144        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>)
145      </p>
146</div></td>
147</tr></table>
148<hr>
149<div class="spirit-nav">
150<a accesskey="p" href="rotate_copy.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="stable_partition.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
151</div>
152</body>
153</html>
154