1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>equal_range</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="../non_mutating.html" title="Non-mutating algorithms"> 9<link rel="prev" href="equal.html" title="equal"> 10<link rel="next" href="for_each.html" title="for_each"> 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="equal.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../non_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="for_each.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.non_mutating.equal_range"></a><a class="link" href="equal_range.html" title="equal_range">equal_range</a> 28</h5></div></div></div> 29<h6> 30<a name="range.reference.algorithms.non_mutating.equal_range.h0"></a> 31 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.prototype"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.prototype">Prototype</a> 32 </h6> 33<p> 34</p> 35<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span> 36 <span class="keyword">class</span> <span class="identifier">ForwardRange</span><span class="special">,</span> 37 <span class="keyword">class</span> <span class="identifier">Value</span> 38 <span class="special">></span> 39<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> 40 <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> 41<span class="identifier">equal_range</span><span class="special">(</span><span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Value</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span> 42 43<span class="keyword">template</span><span class="special"><</span> 44 <span class="keyword">class</span> <span class="identifier">ForwardRange</span><span class="special">,</span> 45 <span class="keyword">class</span> <span class="identifier">Value</span> 46 <span class="special">></span> 47<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> 48 <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> 49<span class="identifier">equal_range</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Value</span><span class="special">&</span> <span class="identifier">val</span><span class="special">);</span> 50 51<span class="keyword">template</span><span class="special"><</span> 52 <span class="keyword">class</span> <span class="identifier">ForwardRange</span><span class="special">,</span> 53 <span class="keyword">class</span> <span class="identifier">Value</span><span class="special">,</span> 54 <span class="keyword">class</span> <span class="identifier">SortPredicate</span> 55 <span class="special">></span> 56<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> 57 <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> 58<span class="identifier">equal_range</span><span class="special">(</span><span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Value</span><span class="special">&</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">SortPredicate</span> <span class="identifier">pred</span><span class="special">);</span> 59 60<span class="keyword">template</span><span class="special"><</span> 61 <span class="keyword">class</span> <span class="identifier">ForwardRange</span><span class="special">,</span> 62 <span class="keyword">class</span> <span class="identifier">Value</span><span class="special">,</span> 63 <span class="keyword">class</span> <span class="identifier">SortPredicate</span> 64 <span class="special">></span> 65<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> 66 <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> 67<span class="identifier">equal_range</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">rng</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Value</span><span class="special">&</span> <span class="identifier">val</span><span class="special">,</span> <span class="identifier">SortPredicate</span> <span class="identifier">pred</span><span class="special">);</span> 68</pre> 69<p> 70 </p> 71<h6> 72<a name="range.reference.algorithms.non_mutating.equal_range.h1"></a> 73 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.description"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.description">Description</a> 74 </h6> 75<p> 76 <code class="computeroutput"><span class="identifier">equal_range</span></code> returns a 77 range in the form of a pair of iterators where all of the elements are 78 equal to <code class="computeroutput"><span class="identifier">val</span></code>. If no values 79 are found that are equal to <code class="computeroutput"><span class="identifier">val</span></code>, 80 then an empty range is returned, hence <code class="computeroutput"><span class="identifier">result</span><span class="special">.</span><span class="identifier">first</span> <span class="special">==</span> <span class="identifier">result</span><span class="special">.</span><span class="identifier">second</span></code>. 81 For the non-predicate versions of <code class="computeroutput"><span class="identifier">equal_range</span></code> 82 the equality of elements is determined by <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code>. For the predicate versions of <code class="computeroutput"><span class="identifier">equal_range</span></code> the equality of elements 83 is determined by <code class="computeroutput"><span class="identifier">pred</span></code>. 84 </p> 85<h6> 86<a name="range.reference.algorithms.non_mutating.equal_range.h2"></a> 87 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.definition"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.definition">Definition</a> 88 </h6> 89<p> 90 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">equal_range</span><span class="special">.</span><span class="identifier">hpp</span></code> 91 </p> 92<h6> 93<a name="range.reference.algorithms.non_mutating.equal_range.h3"></a> 94 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.requirements"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.requirements">Requirements</a> 95 </h6> 96<p> 97 <span class="bold"><strong>For the non-predicate versions:</strong></span> 98 </p> 99<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 100<li class="listitem"> 101 <code class="computeroutput"><span class="identifier">ForwardRange</span></code> is a 102 model of the <a class="link" href="../../../concepts/forward_range.html" title="Forward Range">Forward 103 Range</a> Concept. 104 </li> 105<li class="listitem"> 106 <code class="computeroutput"><span class="identifier">Value</span></code> is a model 107 of the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code>. 108 </li> 109<li class="listitem"> 110 The ordering of objects of type <code class="computeroutput"><span class="identifier">Value</span></code> 111 is a <span class="bold"><strong><span class="emphasis"><em>strict weak ordering</em></span></strong></span>, 112 as defined in the <code class="computeroutput"><span class="identifier">LessThanComparableConcept</span></code> 113 requirements. 114 </li> 115<li class="listitem"> 116 <code class="computeroutput"><span class="identifier">ForwardRange</span></code>'s value 117 type is the same type as <code class="computeroutput"><span class="identifier">Value</span></code>. 118 </li> 119</ul></div> 120<p> 121 <span class="bold"><strong>For the predicate versions:</strong></span> 122 </p> 123<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 124<li class="listitem"> 125 <code class="computeroutput"><span class="identifier">ForwardRange</span></code> is a 126 model of the <a class="link" href="../../../concepts/forward_range.html" title="Forward Range">Forward 127 Range</a> Concept. 128 </li> 129<li class="listitem"> 130 <code class="computeroutput"><span class="identifier">SortPredicate</span></code> is 131 a model of the <code class="computeroutput"><span class="identifier">StrictWeakOrderingConcept</span></code>. 132 </li> 133<li class="listitem"> 134 <code class="computeroutput"><span class="identifier">ForwardRange</span></code>'s value 135 type is the same as <code class="computeroutput"><span class="identifier">Value</span></code>. 136 </li> 137<li class="listitem"> 138 <code class="computeroutput"><span class="identifier">ForwardRange</span></code>'s value 139 type is convertible to both of <code class="computeroutput"><span class="identifier">SortPredicate</span></code>'s 140 argument types. 141 </li> 142</ul></div> 143<h6> 144<a name="range.reference.algorithms.non_mutating.equal_range.h4"></a> 145 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.precondition_"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.precondition_">Precondition:</a> 146 </h6> 147<p> 148 For the non-predicate versions: <code class="computeroutput"><span class="identifier">rng</span></code> 149 is ordered in ascending order according to <code class="computeroutput"><span class="keyword">operator</span><span class="special"><</span></code>. 150 </p> 151<p> 152 For the predicate versions: <code class="computeroutput"><span class="identifier">rng</span></code> 153 is ordered in ascending order according to <code class="computeroutput"><span class="identifier">pred</span></code>. 154 </p> 155<h6> 156<a name="range.reference.algorithms.non_mutating.equal_range.h5"></a> 157 <span class="phrase"><a name="range.reference.algorithms.non_mutating.equal_range.complexity"></a></span><a class="link" href="equal_range.html#range.reference.algorithms.non_mutating.equal_range.complexity">Complexity</a> 158 </h6> 159<p> 160 For random-access ranges, the complexity is <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">log</span> <span class="identifier">N</span><span class="special">)</span></code>, 161 otherwise the complexity is <code class="computeroutput"><span class="identifier">O</span><span class="special">(</span><span class="identifier">N</span><span class="special">)</span></code>. 162 </p> 163</div> 164<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 165<td align="left"></td> 166<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen, 167 Neil Groves<p> 168 Distributed under the Boost Software License, Version 1.0. (See accompanying 169 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>) 170 </p> 171</div></td> 172</tr></table> 173<hr> 174<div class="spirit-nav"> 175<a accesskey="p" href="equal.html"><img src="../../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../non_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="for_each.html"><img src="../../../../../../../../doc/src/images/next.png" alt="Next"></a> 176</div> 177</body> 178</html> 179