3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>is_partitioned_until</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="is_palindrome.html" title="is_palindrome">
10 <link rel="next" href="apply_permutation.html" title="apply_permutation">
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>
22 <div class="spirit-nav">
23 <a accesskey="p" href="is_palindrome.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="apply_permutation.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h3 class="title">
27 <a name="the_boost_algorithm_library.Misc.is_partitioned_until"></a><a class="link" href="is_partitioned_until.html" title="is_partitioned_until">is_partitioned_until
29 </h3></div></div></div>
31 The header file 'is_partitioned_until.hpp' contains two variants of a single
32 algorithm, <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>.
33 The algorithm tests to see if a sequence is partitioned according to a predicate;
34 in other words, all the items in the sequence that satisfy the predicate
35 are at the beginning of the sequence.
38 The routine <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>
39 takes a sequence and a predicate. It returns the last iterator 'it' in the
40 sequence [begin, end) for which the is_partitioned(begin, it) is true.
43 <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code> come
44 in two forms; the first one takes two iterators to define the range. The
45 second form takes a single range parameter, and uses Boost.Range to traverse
49 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h0"></a>
50 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.interface"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.interface">interface</a>
53 The function <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>
54 returns the last iterator 'it' in the sequence [begin, end) for which the
55 is_partitioned(begin, it) is true. There are two versions; one takes two
56 iterators, and the other takes a range.
60 <pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">InputIterator</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Predicate</span><span class="special">></span>
61 <span class="identifier">InputIterator</span> <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">InputIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">InputIterator</span> <span class="identifier">last</span><span class="special">,</span> <span class="identifier">Predicate</span> <span class="identifier">p</span> <span class="special">);</span>
62 <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Range</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Predicate</span><span class="special">></span>
63 <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">Predicate</span> <span class="identifier">p</span> <span class="special">);</span>
68 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h1"></a>
69 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.examples"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.examples">Examples</a>
72 Given the container <code class="computeroutput"><span class="identifier">c</span></code> containing
73 <code class="computeroutput"><span class="special">{</span> <span class="number">0</span><span class="special">,</span> <span class="number">1</span><span class="special">,</span>
74 <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">,</span> <span class="number">14</span><span class="special">,</span> <span class="number">15</span> <span class="special">}</span></code>,
77 <pre class="programlisting"><span class="keyword">bool</span> <span class="identifier">isOdd</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">i</span> <span class="special">%</span> <span class="number">2</span> <span class="special">==</span> <span class="number">1</span><span class="special">;</span> <span class="special">}</span>
78 <span class="keyword">bool</span> <span class="identifier">lessThan10</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">}</span>
80 <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">isOdd</span> <span class="special">)</span> <span class="special">--></span> <span class="identifier">iterator</span> <span class="identifier">to</span> <span class="char">'1'</span>
81 <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">lessThan10</span> <span class="special">)</span> <span class="special">--></span> <span class="identifier">end</span>
82 <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span> <span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span> <span class="special">(),</span> <span class="identifier">lessThan10</span> <span class="special">)</span> <span class="special">--></span> <span class="identifier">end</span>
83 <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span> <span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">begin</span> <span class="special">()</span> <span class="special">+</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">lessThan10</span> <span class="special">)</span> <span class="special">--></span> <span class="identifier">end</span>
84 <span class="identifier">is_partitioned_until</span> <span class="special">(</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span> <span class="special">(),</span> <span class="identifier">c</span><span class="special">.</span><span class="identifier">end</span> <span class="special">(),</span> <span class="identifier">isOdd</span> <span class="special">)</span> <span class="special">--></span> <span class="identifier">end</span> <span class="comment">// empty range</span>
89 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h2"></a>
90 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.iterator_requirements"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.iterator_requirements">Iterator
94 <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code> works
95 on all iterators except output iterators.
98 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h3"></a>
99 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.complexity"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.complexity">Complexity</a>
102 Both of the variants of <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>
103 run in <span class="emphasis"><em>O(N)</em></span> (linear) time; that is, they compare against
104 each element in the list once. If the sequence is found to be not partitioned
105 at any point, the routine will terminate immediately, without examining the
106 rest of the elements.
109 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h4"></a>
110 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.exception_safety"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.exception_safety">Exception
114 Both of the variants of <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>
115 take their parameters by value or const reference, and do not depend upon
116 any global state. Therefore, all the routines in this file provide the strong
120 <a name="the_boost_algorithm_library.Misc.is_partitioned_until.h5"></a>
121 <span class="phrase"><a name="the_boost_algorithm_library.Misc.is_partitioned_until.notes"></a></span><a class="link" href="is_partitioned_until.html#the_boost_algorithm_library.Misc.is_partitioned_until.notes">Notes</a>
123 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
124 <code class="computeroutput"><span class="identifier">is_partitioned_until</span></code>
125 returns iterator to the end for empty and single-element ranges, no matter
126 what predicate is passed to test against.
129 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
130 <td align="left"></td>
131 <td align="right"><div class="copyright-footer">Copyright © 2010-2012 Marshall Clow<p>
132 Distributed under the Boost Software License, Version 1.0. (See accompanying
133 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>)
138 <div class="spirit-nav">
139 <a accesskey="p" href="is_palindrome.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="apply_permutation.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>