<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
equal_range [C++ Reference]
</title>
<meta name="generator" content="DokuWiki Release 2009-12-25c "Lemming"" />
<meta name="robots" content="index,follow" />
<meta name="date" content="2009-10-09T06:05:16-0700" />
<meta name="keywords" content="stl,set,equal_range" />
<link rel="search" type="application/opensearchdescription+xml" href="/wiki/lib/exe/opensearch.php" title="C++ Reference" />
<link rel="start" href="/wiki/" />
<link rel="contents" href="/wiki/stl/set/equal_range?do=index" title="Index" />
<link rel="alternate" type="application/rss+xml" title="Recent Changes" href="/wiki/feed.php" />
<link rel="alternate" type="application/rss+xml" title="Current Namespace" href="/wiki/feed.php?mode=list&ns=stl:set" />
<link rel="edit" title="Edit this page" href="/wiki/stl/set/equal_range?do=edit" />
<link rel="alternate" type="text/html" title="Plain HTML" href="/wiki/_export/xhtml/stl/set/equal_range" />
<link rel="alternate" type="text/plain" title="Wiki Markup" href="/wiki/_export/raw/stl/set/equal_range" />
<link rel="stylesheet" media="all" type="text/css" href="/wiki/lib/exe/css.php?s=all&t=custom1&tseed=1272971091" />
<link rel="stylesheet" media="screen" type="text/css" href="/wiki/lib/exe/css.php?t=custom1&tseed=1272971091" />
<link rel="stylesheet" media="print" type="text/css" href="/wiki/lib/exe/css.php?s=print&t=custom1&tseed=1272971091" />
<script type="text/javascript" charset="utf-8" ><!--//--><![CDATA[//><!--
var NS='stl:set';var JSINFO = {"id":"stl:set:equal_range","namespace":"stl:set"};
//--><!]]></script>
<script type="text/javascript" charset="utf-8" src="/wiki/lib/exe/js.php?tseed=1272971091" ></script>
<link rel="shortcut icon" href="/wiki/lib/tpl/custom1/images/favicon.png" />
</head>
<body>
<div class="dokuwiki">
<div class="stylehead">
<div class="breadcrumbs">
<span class="bchead">You are here: </span><a href="../../start.html" title="start">C++ Reference</a> » <a href="../../stl/start.html" title="stl:start">C++ Standard Template Library</a> » <a href="../../stl/set/start.html" title="stl:set:start">C++ Sets</a> » <a href="../../stl/set/equal_range.html" title="stl:set:equal_range">equal_range</a> </div>
</div>
<div class="page">
</script>
<script type="text/javascript">
_uacct = "UA-2828341-1";
urchinTracker();
</script>
<!-- wikipage start -->
<h2><a name="equal_range" id="equal_range">equal_range</a></h2>
<div class="level2">
<p>
Syntax:
</p>
<pre class="c code c++" style="font-family:monospace;"> <span class="co2">#include <set></span>
pair<span class="sy0"><</span>iterator<span class="sy0">,</span> iterator<span class="sy0">></span> equal_range<span class="br0">(</span> <span class="kw4">const</span> key_type<span class="sy0">&</span> key <span class="br0">)</span><span class="sy0">;</span>
pair<span class="sy0"><</span>const_iterator<span class="sy0">,</span> const_iterator<span class="sy0">></span> equal_range<span class="br0">(</span> <span class="kw4">const</span> key_type<span class="sy0">&</span> key <span class="br0">)</span> <span class="kw4">const</span><span class="sy0">;</span></pre>
<p>
The function equal_range() returns two iterators - one to the first element
that contains key, another to a point just after the last element that contains
key. In set containers, where no duplicate keys are allowed, the range will include one element at most.
</p>
<p>
If key does not match any key in the container, both the returned pointers point to nearest value greater than key, if any, or to set::end if key is greater than all the elements in the container.
</p>
<p>
Example:
</p>
<pre class="c code c++" style="font-family:monospace;"><span class="co1">// set::equal_elements</span>
<span class="co2">#include <iostream></span>
<span class="co2">#include <set></span>
using namespace std<span class="sy0">;</span>
<span class="kw4">int</span> main <span class="br0">(</span><span class="br0">)</span>
<span class="br0">{</span>
set<span class="sy0"><</span>int<span class="sy0">></span> myset<span class="sy0">;</span>
pair<span class="sy0"><</span>set<span class="sy0"><</span>int<span class="sy0">>::</span><span class="me2">iterator</span><span class="sy0">,</span>set<span class="sy0"><</span>int<span class="sy0">>::</span><span class="me2">iterator</span><span class="sy0">></span> ret<span class="sy0">;</span>
<span class="kw1">for</span> <span class="br0">(</span><span class="kw4">int</span> i<span class="sy0">=</span><span class="nu0">1</span><span class="sy0">;</span> i<span class="sy0"><=</span><span class="nu0">5</span><span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">)</span> myset.<span class="me1">insert</span><span class="br0">(</span>i<span class="sy0">*</span>10<span class="br0">)</span><span class="sy0">;</span> <span class="co1">// set: 10 20 30 40 50</span>
ret <span class="sy0">=</span> myset.<span class="me1">equal_range</span><span class="br0">(</span>30<span class="br0">)</span><span class="sy0">;</span>
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/cout.html"><span class="kw3">cout</span></a> <span class="sy0"><<</span> <span class="st0">"lower bound points to: "</span> <span class="sy0"><<</span> <span class="sy0">*</span>ret.<span class="me1">first</span> <span class="sy0"><<</span> endl<span class="sy0">;</span>
<a href="http://www.opengroup.org/onlinepubs/009695399/functions/cout.html"><span class="kw3">cout</span></a> <span class="sy0"><<</span> <span class="st0">"upper bound points to: "</span> <span class="sy0"><<</span> <span class="sy0">*</span>ret.<span class="me1">second</span> <span class="sy0"><<</span> endl<span class="sy0">;</span>
<span class="kw1">return</span> <span class="nu0">0</span><span class="sy0">;</span>
<span class="br0">}</span></pre>
</div>
<!-- wikipage stop -->
</div>
<div class="clearer"> </div>
<div class="stylefoot">
<div class="meta">
<div class="user">
</div>
<!--
<div class="doc">
stl/set/equal_range.txt · Last modified: 10/09/2009 06:05 by 124.255.102.233 </div>
-->
</div>
</div></div></body>
</html>