1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Differences with standard maps</title> 5<link rel="stylesheet" href="../../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. Boost.Bimap"> 8<link rel="up" href="../the_tutorial.html" title="The tutorial"> 9<link rel="prev" href="the_collection_of_relations_type.html" title="The collection of relations type"> 10<link rel="next" href="useful_functions.html" title="Useful functions"> 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="the_collection_of_relations_type.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../the_tutorial.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="useful_functions.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="boost_bimap.the_tutorial.differences_with_standard_maps"></a><a class="link" href="differences_with_standard_maps.html" title="Differences with standard maps">Differences 28 with standard maps</a> 29</h3></div></div></div> 30<div class="toc"><dl class="toc"> 31<dt><span class="section"><a href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.insertion">Insertion</a></span></dt> 32<dt><span class="section"><a href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.iterator__value_type">iterator::value_type</a></span></dt> 33<dt><span class="section"><a href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.operator_____and_at__">operator[] 34 and at()</a></span></dt> 35<dt><span class="section"><a href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.complexity_of_operations">Complexity 36 of operations</a></span></dt> 37</dl></div> 38<div class="section"> 39<div class="titlepage"><div><div><h4 class="title"> 40<a name="boost_bimap.the_tutorial.differences_with_standard_maps.insertion"></a><a class="link" href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.insertion" title="Insertion">Insertion</a> 41</h4></div></div></div> 42<p> 43 Remember that a map can be interpreted as a relation between two collections. 44 In bimaps we have the freedom to change both collection types, imposing 45 constrains in each of them. Some insertions that we give for granted to 46 success in standard maps fails with bimaps. For example: 47 </p> 48<pre class="programlisting"><span class="identifier">bimap</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">></span> <span class="identifier">bm</span><span class="special">;</span> 49 50<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="string">"orange"</span><span class="special">);</span> 51<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="string">"orange"</span><span class="special">);</span> <span class="comment">// No effect! returns make_pair(iter,false)</span> 52</pre> 53<p> 54 The insertion will only succeed if it is allowed by all views of the <code class="computeroutput"><span class="identifier">bimap</span></code>. In the next snippet we define 55 the right collection as a multiset, when we try to insert the same two 56 elements the second insertion is allowed by the left map view because both 57 values are different and it is allowed by the right map view because it 58 is a non-unique collection type. 59 </p> 60<pre class="programlisting"><span class="identifier">bimap</span><span class="special"><</span><span class="keyword">int</span><span class="special">,</span> <span class="identifier">multiset_of</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">></span> <span class="special">></span> <span class="identifier">bm</span><span class="special">;</span> 61 62<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="string">"orange"</span><span class="special">);</span> 63<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="number">2</span><span class="special">,</span><span class="string">"orange"</span><span class="special">);</span> <span class="comment">// Insertion succeed!</span> 64</pre> 65<p> 66 If we use a custom collection of relation type, the insertion has to be 67 allowed by it too. 68 </p> 69</div> 70<div class="section"> 71<div class="titlepage"><div><div><h4 class="title"> 72<a name="boost_bimap.the_tutorial.differences_with_standard_maps.iterator__value_type"></a><a class="link" href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.iterator__value_type" title="iterator::value_type">iterator::value_type</a> 73</h4></div></div></div> 74<p> 75 The relations stored in the Bimap will not be in most cases modifiable 76 directly by iterators because both sides are used as keys of <span class="emphasis"><em>key-based</em></span> 77 sets. When a <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> left view iterator is dereferenced 78 the return type is <span class="emphasis"><em>signature-compatible</em></span> with a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span> <span class="keyword">const</span> <span class="identifier">A</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">B</span> <span class="special">></span></code>. 79 However there are some collection types that are not <span class="emphasis"><em>key_based</em></span>, 80 for example list_of. If a Bimap uses one of these collection types there 81 is no problem with modifying the data of that side. The following code 82 is valid: 83 </p> 84<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">bimap</span><span class="special"><</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">list_of</span><span class="special"><</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">></span> <span class="special">></span> <span class="identifier">bm_type</span><span class="special">;</span> 85<span class="identifier">bm_type</span> <span class="identifier">bm</span><span class="special">;</span> 86<span class="identifier">bm</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span> <span class="identifier">bm_type</span><span class="special">::</span><span class="identifier">relation</span><span class="special">(</span> <span class="number">1</span><span class="special">,</span> <span class="string">"one"</span> <span class="special">)</span> <span class="special">);</span> 87<span class="special">...</span> 88<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">find</span><span class="special">(</span><span class="number">1</span><span class="special">)-></span><span class="identifier">second</span> <span class="special">=</span> <span class="string">"1"</span><span class="special">;</span> <span class="comment">// Valid</span> 89</pre> 90<p> 91 In this case, when the iterator is dereferenced the return type is <span class="emphasis"><em>signature-compatible</em></span> 92 with a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">></span></code>. 93 </p> 94<p> 95 The following table shows the constness of the dereferenced data of each 96 collection type of: 97 </p> 98<div class="informaltable"><table class="table"> 99<colgroup> 100<col> 101<col> 102</colgroup> 103<thead><tr> 104<th> 105 <p> 106 Side collection type 107 </p> 108 </th> 109<th> 110 <p> 111 Dereferenced data 112 </p> 113 </th> 114</tr></thead> 115<tbody> 116<tr> 117<td> 118 <p> 119 <code class="computeroutput"><span class="identifier">set_of</span></code> 120 </p> 121 </td> 122<td> 123 <p> 124 <span class="emphasis"><em>constant</em></span> 125 </p> 126 </td> 127</tr> 128<tr> 129<td> 130 <p> 131 <code class="computeroutput"><span class="identifier">multiset_of</span></code> 132 </p> 133 </td> 134<td> 135 <p> 136 <span class="emphasis"><em>constant</em></span> 137 </p> 138 </td> 139</tr> 140<tr> 141<td> 142 <p> 143 <code class="computeroutput"><span class="identifier">unordered_set_of</span></code> 144 </p> 145 </td> 146<td> 147 <p> 148 <span class="emphasis"><em>constant</em></span> 149 </p> 150 </td> 151</tr> 152<tr> 153<td> 154 <p> 155 <code class="computeroutput"><span class="identifier">unordered_multiset_of</span></code> 156 </p> 157 </td> 158<td> 159 <p> 160 <span class="emphasis"><em>constant</em></span> 161 </p> 162 </td> 163</tr> 164<tr> 165<td> 166 <p> 167 <code class="computeroutput"><span class="identifier">list_of</span></code> 168 </p> 169 </td> 170<td> 171 <p> 172 <span class="emphasis"><em>mutable</em></span> 173 </p> 174 </td> 175</tr> 176<tr> 177<td> 178 <p> 179 <code class="computeroutput"><span class="identifier">vector_of</span></code> 180 </p> 181 </td> 182<td> 183 <p> 184 <span class="emphasis"><em>mutable</em></span> 185 </p> 186 </td> 187</tr> 188<tr> 189<td> 190 <p> 191 <code class="computeroutput"><span class="identifier">unconstrained_set_of</span></code> 192 </p> 193 </td> 194<td> 195 <p> 196 <span class="emphasis"><em>mutable</em></span> 197 </p> 198 </td> 199</tr> 200</tbody> 201</table></div> 202<p> 203 Here are some examples. When dereferenced the iterators returns a type 204 that is <span class="emphasis"><em>signature-compatible</em></span> with these types. 205 </p> 206<div class="informaltable"><table class="table"> 207<colgroup> 208<col> 209<col> 210</colgroup> 211<thead><tr> 212<th> 213 <p> 214 Bimap type 215 </p> 216 </th> 217<th> 218 <p> 219 Signature-compatible types 220 </p> 221 </th> 222</tr></thead> 223<tbody> 224<tr> 225<td> 226 <p> 227 <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> 228 </p> 229 </td> 230<td> 231 <p> 232 <code class="computeroutput"><span class="identifier">iterator</span> </code> <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">relation</span><span class="special"><</span><span class="keyword">const</span> 233 <span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">></span></code> 234 </p> 235 <p> 236 <code class="computeroutput"><span class="identifier">left_iterator</span> </code> 237 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 238 <span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">></span></code> 239 </p> 240 <p> 241 <code class="computeroutput"><span class="identifier">right_iterator</span></code> 242 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 243 <span class="identifier">B</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">></span></code> 244 </p> 245 </td> 246</tr> 247<tr> 248<td> 249 <p> 250 <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">multiset_of</span><span class="special"><</span><span class="identifier">A</span><span class="special">>,</span><span class="identifier">unordered_set_of</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> 251 <span class="special">></span></code> 252 </p> 253 </td> 254<td> 255 <p> 256 <code class="computeroutput"><span class="identifier">iterator</span> </code> <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">relation</span><span class="special"><</span><span class="keyword">const</span> 257 <span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">></span></code> 258 </p> 259 <p> 260 <code class="computeroutput"><span class="identifier">left_iterator</span> </code> 261 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 262 <span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">B</span><span class="special">></span></code> 263 </p> 264 <p> 265 <code class="computeroutput"><span class="identifier">right_iterator</span></code> 266 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 267 <span class="identifier">B</span><span class="special">,</span><span class="keyword">const</span> <span class="identifier">A</span><span class="special">></span></code> 268 </p> 269 </td> 270</tr> 271<tr> 272<td> 273 <p> 274 <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">set_of</span><span class="special"><</span><span class="identifier">A</span><span class="special">>,</span><span class="identifier">list_of</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> 275 <span class="special">></span></code> 276 </p> 277 </td> 278<td> 279 <p> 280 <code class="computeroutput"><span class="identifier">iterator</span> </code> <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">relation</span><span class="special"><</span><span class="keyword">const</span> 281 <span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> 282 </p> 283 <p> 284 <code class="computeroutput"><span class="identifier">left_iterator</span> </code> 285 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 286 <span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> 287 </p> 288 <p> 289 <code class="computeroutput"><span class="identifier">right_iterator</span></code> 290 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="identifier">B</span><span class="special">,</span><span class="keyword">const</span> 291 <span class="identifier">A</span><span class="special">></span></code> 292 </p> 293 </td> 294</tr> 295<tr> 296<td> 297 <p> 298 <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">vector_of</span><span class="special"><</span><span class="identifier">A</span><span class="special">>,</span><span class="identifier">set_of</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> 299 <span class="special">></span></code> 300 </p> 301 </td> 302<td> 303 <p> 304 <code class="computeroutput"><span class="identifier">iterator</span> </code> <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">relation</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> 305 <span class="identifier">B</span><span class="special">></span></code> 306 </p> 307 <p> 308 <code class="computeroutput"><span class="identifier">left_iterator</span> </code> 309 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="keyword">const</span> 310 <span class="identifier">B</span><span class="special">></span></code> 311 </p> 312 <p> 313 <code class="computeroutput"><span class="identifier">right_iterator</span></code> 314 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="keyword">const</span> 315 <span class="identifier">B</span><span class="special">,</span><span class="identifier">A</span><span class="special">></span></code> 316 </p> 317 </td> 318</tr> 319<tr> 320<td> 321 <p> 322 <code class="computeroutput"><span class="identifier">bimap</span><span class="special"><</span><span class="identifier">list_of</span><span class="special"><</span><span class="identifier">A</span><span class="special">>,</span><span class="identifier">unconstrained_set_of</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span> 323 <span class="special">></span></code> 324 </p> 325 </td> 326<td> 327 <p> 328 <code class="computeroutput"><span class="identifier">iterator</span> </code> <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">relation</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> 329 </p> 330 <p> 331 <code class="computeroutput"><span class="identifier">left_iterator</span> </code> 332 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="identifier">A</span><span class="special">,</span><span class="identifier">B</span><span class="special">></span></code> 333 </p> 334 <p> 335 <code class="computeroutput"><span class="identifier">right_iterator</span></code> 336 <span class="bold"><strong>-></strong></span> <code class="computeroutput"><span class="identifier">pair</span><span class="special"><</span><span class="identifier">B</span><span class="special">,</span><span class="identifier">A</span><span class="special">></span></code> 337 </p> 338 </td> 339</tr> 340</tbody> 341</table></div> 342</div> 343<div class="section"> 344<div class="titlepage"><div><div><h4 class="title"> 345<a name="boost_bimap.the_tutorial.differences_with_standard_maps.operator_____and_at__"></a><a class="link" href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.operator_____and_at__" title="operator[] and at()">operator[] 346 and at()</a> 347</h4></div></div></div> 348<p> 349 <code class="computeroutput"><span class="identifier">set_of</span></code> and <code class="computeroutput"><span class="identifier">unordered_set_of</span></code> map views overload 350 <code class="computeroutput"><span class="keyword">operator</span><span class="special">[]</span></code> 351 to retrieve the associated data of a given key only when the other collection 352 type is a mutable one. In these cases it works in the same way as the standard. 353 </p> 354<pre class="programlisting"><span class="identifier">bimap</span><span class="special"><</span> <span class="identifier">unorderd_set_of</span><span class="special"><</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">>,</span> <span class="identifier">list_of</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="special">></span> <span class="identifier">bm</span><span class="special">;</span> 355 356<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">[</span><span class="string">"one"</span><span class="special">]</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="comment">// Ok</span> 357</pre> 358<p> 359 The standard defines an access function for <code class="computeroutput"><span class="identifier">map</span></code> 360 and <code class="computeroutput"><span class="identifier">unordered_map</span></code>: 361 </p> 362<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">data_type</span> <span class="special">&</span> <span class="identifier">at</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">key_type</span> <span class="special">&</span> <span class="identifier">k</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 363 <span class="identifier">data_type</span> <span class="special">&</span> <span class="identifier">at</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">key_type</span> <span class="special">&</span> <span class="identifier">k</span><span class="special">);</span> 364</pre> 365<p> 366 These functions look for a key and returns the associated data value, but 367 throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">out_of_range</span></code> exception if the key is 368 not found. 369 </p> 370<p> 371 In bimaps the constant version of these functions is given for <code class="computeroutput"><span class="identifier">set_of</span></code> and <code class="computeroutput"><span class="identifier">unorderd_set_of</span></code> 372 map views independently of the other collection type. The mutable version 373 is only provided when the other collection type is mutable. 374 </p> 375<p> 376 The following examples shows the behaviour of <code class="computeroutput"><span class="identifier">at</span><span class="special">(</span><span class="identifier">key</span><span class="special">)</span></code> 377 </p> 378<p> 379 <a href="../../../../example/at_function_examples.cpp" target="_top">Go to source code</a> 380 </p> 381<p> 382</p> 383<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">bimap</span><span class="special"><</span> <span class="identifier">set_of</span><span class="special"><</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">>,</span> <span class="identifier">list_of</span><span class="special"><</span> <span class="keyword">int</span> <span class="special">></span> <span class="special">></span> <span class="identifier">bm_type</span><span class="special">;</span> 384<span class="identifier">bm_type</span> <span class="identifier">bm</span><span class="special">;</span> 385 386<span class="keyword">try</span> 387<span class="special">{</span> 388 <span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="string">"one"</span><span class="special">)</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="comment">// throws std::out_of_range</span> 389<span class="special">}</span> 390<span class="keyword">catch</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">out_of_range</span> <span class="special">&</span> <span class="identifier">e</span> <span class="special">)</span> <span class="special">{}</span> 391 392<span class="identifier">assert</span><span class="special">(</span> <span class="identifier">bm</span><span class="special">.</span><span class="identifier">empty</span><span class="special">()</span> <span class="special">);</span> 393 394<span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">[</span><span class="string">"one"</span><span class="special">]</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="comment">// Ok</span> 395 396<span class="identifier">assert</span><span class="special">(</span> <span class="identifier">bm</span><span class="special">.</span><span class="identifier">left</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="string">"one"</span><span class="special">)</span> <span class="special">==</span> <span class="number">1</span> <span class="special">);</span> <span class="comment">// Ok</span> 397</pre> 398<p> 399 </p> 400<p> 401</p> 402<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">bimap</span><span class="special"><</span> <span class="identifier">multiset_of</span><span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">>,</span> <span class="identifier">unordered_set_of</span><span class="special"><</span><span class="keyword">int</span><span class="special">></span> <span class="special">></span> <span class="identifier">bm_type</span><span class="special">;</span> 403<span class="identifier">bm_type</span> <span class="identifier">bm</span><span class="special">;</span> 404 405<span class="identifier">bm</span><span class="special">.</span><span class="identifier">right</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">=</span> <span class="string">"one"</span><span class="special">;</span> <span class="comment">// compilation error</span> 406 407<span class="identifier">bm</span><span class="special">.</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span> <span class="identifier">bm_type</span><span class="special">::</span><span class="identifier">right_value_type</span><span class="special">(</span><span class="number">1</span><span class="special">,</span><span class="string">"one"</span><span class="special">)</span> <span class="special">);</span> 408 409<span class="identifier">assert</span><span class="special">(</span> <span class="identifier">bm</span><span class="special">.</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="string">"one"</span> <span class="special">);</span> <span class="comment">// Ok</span> 410 411<span class="keyword">try</span> 412<span class="special">{</span> 413 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">bm</span><span class="special">.</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="number">2</span><span class="special">);</span> <span class="comment">// throws std::out_of_range</span> 414<span class="special">}</span> 415<span class="keyword">catch</span><span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">out_of_range</span> <span class="special">&</span> <span class="identifier">e</span> <span class="special">)</span> <span class="special">{}</span> 416 417<span class="identifier">bm</span><span class="special">.</span><span class="identifier">right</span><span class="special">.</span><span class="identifier">at</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">=</span> <span class="string">"1"</span><span class="special">;</span> <span class="comment">// compilation error</span> 418</pre> 419<p> 420 </p> 421</div> 422<div class="section"> 423<div class="titlepage"><div><div><h4 class="title"> 424<a name="boost_bimap.the_tutorial.differences_with_standard_maps.complexity_of_operations"></a><a class="link" href="differences_with_standard_maps.html#boost_bimap.the_tutorial.differences_with_standard_maps.complexity_of_operations" title="Complexity of operations">Complexity 425 of operations</a> 426</h4></div></div></div> 427<p> 428 The complexity of some operations is different in bimaps. Read <a class="link" href="../reference/bimap_reference.html#complexity_signature_explanation">the 429 reference</a> to find the complexity of each function. 430 </p> 431</div> 432</div> 433<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 434<td align="left"></td> 435<td align="right"><div class="copyright-footer">Copyright © 2006-2012 Matias Capeletto<p> 436 Distributed under the Boost Software License, Version 1.0. (See accompanying 437 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>) 438 </p> 439</div></td> 440</tr></table> 441<hr> 442<div class="spirit-nav"> 443<a accesskey="p" href="the_collection_of_relations_type.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../the_tutorial.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="useful_functions.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 444</div> 445</body> 446</html> 447