Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / algorithm / doc / html / the_boost_algorithm_library / Misc / gather.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>gather</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="The Boost Algorithm Library">
8 <link rel="up" href="../../algorithm/Misc.html" title="Other Algorithms">
9 <link rel="prev" href="find_backward.html" title="find_backward">
10 <link rel="next" href="hex.html" title="hex">
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="find_backward.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../algorithm/Misc.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="hex.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="section">
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="the_boost_algorithm_library.Misc.gather"></a><a class="link" href="gather.html" title="gather">gather</a>
28 </h3></div></div></div>
29 <p>
30         The header file 'boost/algorithm/gather.hpp' contains two variants of a single
31         algorithm, <code class="computeroutput"><span class="identifier">gather</span></code>.
32       </p>
33 <p>
34         <code class="computeroutput"><span class="identifier">gather</span><span class="special">()</span></code>
35         takes a collection of elements defined by a pair of iterators and moves the
36         ones satisfying a predicate to them to a position (called the pivot) within
37         the sequence. The algorithm is stable. The result is a pair of iterators
38         that contains the items that satisfy the predicate.
39       </p>
40 <h5>
41 <a name="the_boost_algorithm_library.Misc.gather.h0"></a>
42         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.interface"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.interface">Interface</a>
43       </h5>
44 <p>
45         The function <code class="computeroutput"><span class="identifier">gather</span></code> returns
46         a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code> of iterators that denote the elements
47         that satisfy the predicate.
48       </p>
49 <p>
50         There are two versions; one takes two iterators, and the other takes a range.
51       </p>
52 <p>
53 </p>
54 <pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">algorithm</span> <span class="special">{</span>
55
56 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">BidirectionalIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Pred</span><span class="special">&gt;</span>
57 <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="identifier">BidirectionalIterator</span><span class="special">,</span><span class="identifier">BidirectionalIterator</span><span class="special">&gt;</span>
58 <span class="identifier">gather</span> <span class="special">(</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">BidirectionalIterator</span> <span class="identifier">pivot</span><span class="special">,</span> <span class="identifier">Pred</span> <span class="identifier">pred</span> <span class="special">);</span>
59
60 <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">BidirectionalRange</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Pred</span><span class="special">&gt;</span>
61 <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">BidirectionalRange</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">BidirectionalRange</span><span class="special">&gt;::</span><span class="identifier">type</span><span class="special">&gt;</span>
62 <span class="identifier">gather</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">BidirectionalRange</span> <span class="special">&amp;</span><span class="identifier">range</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_iterator</span><span class="special">&lt;</span><span class="keyword">const</span> <span class="identifier">BidirectionalRange</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">pivot</span><span class="special">,</span> <span class="identifier">Pred</span> <span class="identifier">pred</span> <span class="special">);</span>
63
64 <span class="special">}}</span>
65 </pre>
66 <p>
67       </p>
68 <h5>
69 <a name="the_boost_algorithm_library.Misc.gather.h1"></a>
70         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.examples"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.examples">Examples</a>
71       </h5>
72 <p>
73         Given an sequence containing:
74 </p>
75 <pre class="programlisting"><span class="number">0</span> <span class="number">1</span> <span class="number">2</span> <span class="number">3</span> <span class="number">4</span> <span class="number">5</span> <span class="number">6</span> <span class="number">7</span> <span class="number">8</span> <span class="number">9</span>
76 </pre>
77 <p>
78       </p>
79 <p>
80         a call to gather ( arr, arr + 10, arr + 4, IsEven ) will result in:
81       </p>
82 <p>
83 </p>
84 <pre class="programlisting"><span class="number">1</span> <span class="number">3</span> <span class="number">0</span> <span class="number">2</span> <span class="number">4</span> <span class="number">6</span> <span class="number">8</span> <span class="number">5</span> <span class="number">7</span> <span class="number">9</span>
85     <span class="special">|---|-----|</span>
86   <span class="identifier">first</span> <span class="special">|</span>  <span class="identifier">second</span>
87       <span class="identifier">pivot</span>
88 </pre>
89 <p>
90         where <code class="computeroutput"><span class="identifier">first</span></code> and <code class="computeroutput"><span class="identifier">second</span></code> are the fields of the pair that
91         is returned by the call.
92       </p>
93 <h5>
94 <a name="the_boost_algorithm_library.Misc.gather.h2"></a>
95         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.iterator_requirements"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.iterator_requirements">Iterator
96         Requirements</a>
97       </h5>
98 <p>
99         <code class="computeroutput"><span class="identifier">gather</span></code> work on bidirectional
100         iterators or better. This requirement comes from the usage of <code class="computeroutput"><span class="identifier">stable_partition</span></code>, which requires bidirectional
101         iterators. Some standard libraries (libstdc++ and libc++, for example) have
102         implementations of <code class="computeroutput"><span class="identifier">stable_partition</span></code>
103         that work with forward iterators. If that is the case, then <code class="computeroutput"><span class="identifier">gather</span></code> will work with forward iterators
104         as well.
105       </p>
106 <h5>
107 <a name="the_boost_algorithm_library.Misc.gather.h3"></a>
108         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.storage_requirements"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.storage_requirements">Storage
109         Requirements</a>
110       </h5>
111 <p>
112         <code class="computeroutput"><span class="identifier">gather</span></code> uses <code class="computeroutput"><span class="identifier">stable_partition</span></code>, which will attempt to
113         allocate temporary memory, but will work in-situ if there is none available.
114       </p>
115 <h5>
116 <a name="the_boost_algorithm_library.Misc.gather.h4"></a>
117         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.complexity"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.complexity">Complexity</a>
118       </h5>
119 <p>
120         If there is sufficient memory available, the run time is linear: <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">N</span><span class="special">)</span></code>
121       </p>
122 <p>
123         If there is not any memory available, then the run time is <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">N</span>
124         <span class="identifier">log</span> <span class="identifier">N</span><span class="special">)</span></code>.
125       </p>
126 <h5>
127 <a name="the_boost_algorithm_library.Misc.gather.h5"></a>
128         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.exception_safety"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.exception_safety">Exception
129         Safety</a>
130       </h5>
131 <h5>
132 <a name="the_boost_algorithm_library.Misc.gather.h6"></a>
133         <span class="phrase"><a name="the_boost_algorithm_library.Misc.gather.notes"></a></span><a class="link" href="gather.html#the_boost_algorithm_library.Misc.gather.notes">Notes</a>
134       </h5>
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 &#169; 2010-2012 Marshall Clow<p>
139         Distributed under the Boost Software License, Version 1.0. (See accompanying
140         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>)
141       </p>
142 </div></td>
143 </tr></table>
144 <hr>
145 <div class="spirit-nav">
146 <a accesskey="p" href="find_backward.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../algorithm/Misc.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="hex.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
147 </div>
148 </body>
149 </html>