• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>stable_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="stable_partition.html" title="stable_partition">
10<link rel="next" href="swap_ranges.html" title="swap_ranges">
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="stable_partition.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="swap_ranges.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.stable_sort"></a><a class="link" href="stable_sort.html" title="stable_sort">stable_sort</a>
28</h5></div></div></div>
29<h6>
30<a name="range.reference.algorithms.mutating.stable_sort.h0"></a>
31            <span class="phrase"><a name="range.reference.algorithms.mutating.stable_sort.prototype"></a></span><a class="link" href="stable_sort.html#range.reference.algorithms.mutating.stable_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">stable_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">stable_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">stable_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">stable_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.stable_sort.h1"></a>
51            <span class="phrase"><a name="range.reference.algorithms.mutating.stable_sort.description"></a></span><a class="link" href="stable_sort.html#range.reference.algorithms.mutating.stable_sort.description">Description</a>
52          </h6>
53<p>
54            <code class="computeroutput"><span class="identifier">stable_sort</span></code> sorts the
55            elements in <code class="computeroutput"><span class="identifier">rng</span></code> into
56            ascending order. <code class="computeroutput"><span class="identifier">stable_sort</span></code>
57            is guaranteed to be stable. The order is preserved for equivalent elements.
58          </p>
59<p>
60            For versions of the <code class="computeroutput"><span class="identifier">stable_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">stable_sort</span></code>
69            function with a predicate, ascending order is designed 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.stable_sort.h2"></a>
74            <span class="phrase"><a name="range.reference.algorithms.mutating.stable_sort.definition"></a></span><a class="link" href="stable_sort.html#range.reference.algorithms.mutating.stable_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">stable_sort</span><span class="special">.</span><span class="identifier">hpp</span></code>
78          </p>
79<h6>
80<a name="range.reference.algorithms.mutating.stable_sort.h3"></a>
81            <span class="phrase"><a name="range.reference.algorithms.mutating.stable_sort.requirements"></a></span><a class="link" href="stable_sort.html#range.reference.algorithms.mutating.stable_sort.requirements">Requirements</a>
82          </h6>
83<p>
84            <span class="bold"><strong>For versions of stable_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 stable_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.stable_sort.h4"></a>
132            <span class="phrase"><a name="range.reference.algorithms.mutating.stable_sort.complexity"></a></span><a class="link" href="stable_sort.html#range.reference.algorithms.mutating.stable_sort.complexity">Complexity</a>
133          </h6>
134<p>
135            Best case: <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">N</span><span class="special">)</span></code>
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            Worst case: <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><span class="number">2</span><span class="special">)</span></code>
138            comparisons, where <code class="computeroutput"><span class="identifier">N</span></code>
139            is <code class="computeroutput"><span class="identifier">distance</span><span class="special">(</span><span class="identifier">rng</span><span class="special">)</span></code>.
140          </p>
141</div>
142<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
143<td align="left"></td>
144<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
145      Neil Groves<p>
146        Distributed under the Boost Software License, Version 1.0. (See accompanying
147        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>)
148      </p>
149</div></td>
150</tr></table>
151<hr>
152<div class="spirit-nav">
153<a accesskey="p" href="stable_partition.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="swap_ranges.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a>
154</div>
155</body>
156</html>
157