1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Standard Compliance</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../unordered.html" title="Chapter 44. Boost.Unordered"> 10<link rel="prev" href="comparison.html" title="Comparison with Associative Containers"> 11<link rel="next" href="rationale.html" title="Implementation Rationale"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<a accesskey="p" href="comparison.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../unordered.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="rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="unordered.compliance"></a><a class="link" href="compliance.html" title="Standard Compliance">Standard Compliance</a> 29</h2></div></div></div> 30<div class="toc"><dl class="toc"> 31<dt><span class="section"><a href="compliance.html#unordered.compliance.move">Move emulation</a></span></dt> 32<dt><span class="section"><a href="compliance.html#unordered.compliance.allocator_compliance">Use of allocators</a></span></dt> 33<dt><span class="section"><a href="compliance.html#unordered.compliance.construction">Construction/Destruction 34 using allocators</a></span></dt> 35<dt><span class="section"><a href="compliance.html#unordered.compliance.pointer_traits">Pointer Traits</a></span></dt> 36<dt><span class="section"><a href="compliance.html#unordered.compliance.pairs0">Pairs</a></span></dt> 37<dt><span class="section"><a href="compliance.html#unordered.compliance.misc">Miscellaneous</a></span></dt> 38</dl></div> 39<p> 40 The intent of Boost.Unordered is to implement a close (but imperfect) implementation 41 of the C++17 standard, that will work with C++98 upwards. The wide compatibility 42 does mean some comprimises have to be made. With a compiler and library that 43 fully support C++11, the differences should be minor. 44 </p> 45<div class="section"> 46<div class="titlepage"><div><div><h3 class="title"> 47<a name="unordered.compliance.move"></a><a class="link" href="compliance.html#unordered.compliance.move" title="Move emulation">Move emulation</a> 48</h3></div></div></div> 49<p> 50 Support for move semantics is implemented using Boost.Move. If rvalue references 51 are available it will use them, but if not it uses a close, but imperfect 52 emulation. On such compilers: 53 </p> 54<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 55<li class="listitem"> 56 Non-copyable objects can be stored in the containers. They can be constructed 57 in place using <code class="computeroutput"><span class="identifier">emplace</span></code>, 58 or if they support Boost.Move, moved into place. 59 </li> 60<li class="listitem"> 61 The containers themselves are not movable. 62 </li> 63<li class="listitem"> 64 Argument forwarding is not perfect. 65 </li> 66</ul></div> 67</div> 68<div class="section"> 69<div class="titlepage"><div><div><h3 class="title"> 70<a name="unordered.compliance.allocator_compliance"></a><a class="link" href="compliance.html#unordered.compliance.allocator_compliance" title="Use of allocators">Use of allocators</a> 71</h3></div></div></div> 72<p> 73 C++11 introduced a new allocator system. It's backwards compatible due to 74 the lax requirements for allocators in the old standard, but might need some 75 changes for allocators which worked with the old versions of the unordered 76 containers. It uses a traits class, <code class="computeroutput"><span class="identifier">allocator_traits</span></code> 77 to handle the allocator adding extra functionality, and making some methods 78 and types optional. During development a stable release of <code class="computeroutput"><span class="identifier">allocator_traits</span></code> wasn't available so an 79 internal partial implementation is always used in this version. Hopefully 80 a future version will use the standard implementation where available. 81 </p> 82<p> 83 The member functions <code class="computeroutput"><span class="identifier">construct</span></code>, 84 <code class="computeroutput"><span class="identifier">destroy</span></code> and <code class="computeroutput"><span class="identifier">max_size</span></code> are now optional, if they're not 85 available a fallback is used. A full implementation of <code class="computeroutput"><span class="identifier">allocator_traits</span></code> 86 requires sophisticated member function detection so that the fallback is 87 used whenever the member function call is not well formed. This requires 88 support for SFINAE expressions, which are available on GCC from version 4.4 89 and Clang. 90 </p> 91<p> 92 On other compilers, there's just a test to see if the allocator has a member, 93 but no check that it can be called. So rather than using a fallback there 94 will just be a compile error. 95 </p> 96<p> 97 <code class="computeroutput"><span class="identifier">propagate_on_container_copy_assignment</span></code>, 98 <code class="computeroutput"><span class="identifier">propagate_on_container_move_assignment</span></code>, 99 <code class="computeroutput"><span class="identifier">propagate_on_container_swap</span></code> 100 and <code class="computeroutput"><span class="identifier">select_on_container_copy_construction</span></code> 101 are also supported. Due to imperfect move emulation, some assignments might 102 check <code class="computeroutput"><span class="identifier">propagate_on_container_copy_assignment</span></code> 103 on some compilers and <code class="computeroutput"><span class="identifier">propagate_on_container_move_assignment</span></code> 104 on others. 105 </p> 106</div> 107<div class="section"> 108<div class="titlepage"><div><div><h3 class="title"> 109<a name="unordered.compliance.construction"></a><a class="link" href="compliance.html#unordered.compliance.construction" title="Construction/Destruction using allocators">Construction/Destruction 110 using allocators</a> 111</h3></div></div></div> 112<p> 113 The following support is required for full use of C++11 style construction/destruction: 114 </p> 115<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 116<li class="listitem"> 117 Variadic templates. 118 </li> 119<li class="listitem"> 120 Piecewise construction of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code>. 121 </li> 122<li class="listitem"> 123 Either <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_traits</span></code> or expression SFINAE. 124 </li> 125</ul></div> 126<p> 127 This is detected using Boost.Config. The macro <code class="computeroutput"><span class="identifier">BOOST_UNORDERED_CXX11_CONSTRUCTION</span></code> 128 will be set to 1 if it is found, or 0 otherwise. 129 </p> 130<p> 131 When this is the case <code class="computeroutput"><span class="identifier">allocator_traits</span><span class="special">::</span><span class="identifier">construct</span></code> 132 and <code class="computeroutput"><span class="identifier">allocator_traits</span><span class="special">::</span><span class="identifier">destroy</span></code> will always be used, apart from 133 when piecewise constructing a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code> 134 using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">tuple</span></code> (see <a class="link" href="compliance.html#unordered.compliance.pairs">below</a>), 135 but that should be easily avoided. 136 </p> 137<p> 138 When support is not available <code class="computeroutput"><span class="identifier">allocator_traits</span><span class="special">::</span><span class="identifier">construct</span></code> 139 and <code class="computeroutput"><span class="identifier">allocator_traits</span><span class="special">::</span><span class="identifier">destroy</span></code> are never called. 140 </p> 141</div> 142<div class="section"> 143<div class="titlepage"><div><div><h3 class="title"> 144<a name="unordered.compliance.pointer_traits"></a><a class="link" href="compliance.html#unordered.compliance.pointer_traits" title="Pointer Traits">Pointer Traits</a> 145</h3></div></div></div> 146<p> 147 <code class="computeroutput"><span class="identifier">pointer_traits</span></code> aren't used. 148 Instead, pointer types are obtained from rebound allocators, this can cause 149 problems if the allocator can't be used with incomplete types. If <code class="computeroutput"><span class="identifier">const_pointer</span></code> is not defined in the allocator, 150 <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">pointer_to_other</span><span class="special"><</span><span class="identifier">pointer</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">value_type</span><span class="special">>::</span><span class="identifier">type</span></code> 151 is used to obtain a const pointer. 152 </p> 153</div> 154<div class="section"> 155<div class="titlepage"><div><div><h3 class="title"> 156<a name="unordered.compliance.pairs0"></a><a name="unordered.compliance.pairs"></a><a class="link" href="compliance.html#unordered.compliance.pairs0" title="Pairs">Pairs</a> 157</h3></div></div></div> 158<p> 159 Since the containers use <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code> 160 they're limited to the version from the current standard library. But since 161 C++11 <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code>'s <code class="computeroutput"><span class="identifier">piecewise_construct</span></code> 162 based constructor is very useful, <code class="computeroutput"><span class="identifier">emplace</span></code> 163 emulates it with a <code class="computeroutput"><span class="identifier">piecewise_construct</span></code> 164 in the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">unordered</span></code> namespace. So for example, the 165 following will work: 166 </p> 167<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">unordered_multimap</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">std</span><span class="special">::</span><span class="identifier">complex</span><span class="special">></span> <span class="identifier">x</span><span class="special">;</span> 168 169<span class="identifier">x</span><span class="special">.</span><span class="identifier">emplace</span><span class="special">(</span> 170 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unordered</span><span class="special">::</span><span class="identifier">piecewise_construct</span><span class="special">,</span> 171 <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_tuple</span><span class="special">(</span><span class="string">"key"</span><span class="special">),</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">make_tuple</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">));</span> 172</pre> 173<p> 174 Older drafts of the standard also supported variadic constructors for <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span></code>, 175 where the first argument would be used for the first part of the pair, and 176 the remaining for the second part. 177 </p> 178</div> 179<div class="section"> 180<div class="titlepage"><div><div><h3 class="title"> 181<a name="unordered.compliance.misc"></a><a class="link" href="compliance.html#unordered.compliance.misc" title="Miscellaneous">Miscellaneous</a> 182</h3></div></div></div> 183<p> 184 When swapping, <code class="computeroutput"><span class="identifier">Pred</span></code> and 185 <code class="computeroutput"><span class="identifier">Hash</span></code> are not currently swapped 186 by calling <code class="computeroutput"><span class="identifier">swap</span></code>, their copy 187 constructors are used. As a consequence when swapping an exception may be 188 thrown from their copy constructor. 189 </p> 190<p> 191 Variadic constructor arguments for <code class="computeroutput"><span class="identifier">emplace</span></code> 192 are only used when both rvalue references and variadic template parameters 193 are available. Otherwise <code class="computeroutput"><span class="identifier">emplace</span></code> 194 can only take up to 10 constructors arguments. 195 </p> 196</div> 197</div> 198<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 199<td align="left"></td> 200<td align="right"><div class="copyright-footer">Copyright © 2003, 2004 Jeremy B. Maitin-Shepard<br>Copyright © 2005-2008 Daniel 201 James<p> 202 Distributed under the Boost Software License, Version 1.0. (See accompanying 203 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>) 204 </p> 205</div></td> 206</tr></table> 207<hr> 208<div class="spirit-nav"> 209<a accesskey="p" href="comparison.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../unordered.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="rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 210</div> 211</body> 212</html> 213