• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>C++11/C++14/C++17 Conformance</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="../container.html" title="Chapter 9. Boost.Container">
10<link rel="prev" href="extended_allocators.html" title="Extended functionality: Extended allocators">
11<link rel="next" href="known_issues.html" title="Known Issues">
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="extended_allocators.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../container.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="known_issues.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="container.cpp_conformance"></a><a class="link" href="cpp_conformance.html" title="C++11/C++14/C++17 Conformance">C++11/C++14/C++17 Conformance</a>
29</h2></div></div></div>
30<div class="toc"><dl class="toc">
31<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.move_emplace">Move and Emplace</a></span></dt>
32<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.alloc_traits_move_traits">Stateful
33      allocators</a></span></dt>
34<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.scoped_allocator">Scoped allocators</a></span></dt>
35<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.insertion_hints">Insertion
36      hints in associative containers and preserving insertion ordering for elements
37      with equivalent keys</a></span></dt>
38<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.initializer_lists">Initializer
39      lists</a></span></dt>
40<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.null_iterators">Null Forward
41      Iterators</a></span></dt>
42<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.polymorphic_memory_resources">Polymorphic
43      Memory Resources </a></span></dt>
44<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.forward_list"><code class="computeroutput"><span class="identifier">forward_list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a></span></dt>
45<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.vector_exception_guarantees"><code class="computeroutput"><span class="identifier">vector</span></code> vs. <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>
46      exception guarantees</a></span></dt>
47<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.container_const_reference_parameters">Parameter
48      taken by const reference that can be changed</a></span></dt>
49<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.Vector_bool"><code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> specialization</a></span></dt>
50<dt><span class="section"><a href="cpp_conformance.html#container.cpp_conformance.non_standard_memset_initialization">Non-standard
51      value initialization using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code></a></span></dt>
52</dl></div>
53<p>
54      <span class="bold"><strong>Boost.Container</strong></span> aims for full C++11 conformance
55      except reasoned deviations, backporting as much as possible for C++03. Obviously,
56      this conformance is a work in progress so this section explains what C++11/C++14/C++17
57      features are implemented and which of them have been backported to earlier
58      standard conformig compilers.
59    </p>
60<div class="section">
61<div class="titlepage"><div><div><h3 class="title">
62<a name="container.cpp_conformance.move_emplace"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.move_emplace" title="Move and Emplace">Move and Emplace</a>
63</h3></div></div></div>
64<p>
65        For compilers with rvalue references and for those C++03 types that use
66        <a href="http://www.boost.org/libs/move" target="_top">Boost.Move</a> rvalue reference
67        emulation <span class="bold"><strong>Boost.Container</strong></span> supports all C++11
68        features related to move semantics: containers are movable, requirements
69        for <code class="computeroutput"><span class="identifier">value_type</span></code> are those
70        specified for C++11 containers.
71      </p>
72<p>
73        For compilers with variadic templates, <span class="bold"><strong>Boost.Container</strong></span>
74        supports placement insertion (<code class="computeroutput"><span class="identifier">emplace</span></code>,
75        ...) functions from C++11. For those compilers without variadic templates
76        support <span class="bold"><strong>Boost.Container</strong></span> uses the preprocessor
77        to create a set of overloads up to a finite number of parameters.
78      </p>
79</div>
80<div class="section">
81<div class="titlepage"><div><div><h3 class="title">
82<a name="container.cpp_conformance.alloc_traits_move_traits"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.alloc_traits_move_traits" title="Stateful allocators">Stateful
83      allocators</a>
84</h3></div></div></div>
85<p>
86        C++03 was not stateful-allocator friendly. For compactness of container objects
87        and for simplicity, it did not require containers to support allocators with
88        state: Allocator objects need not be stored in container objects. It was
89        not possible to store an allocator with state, say an allocator that holds
90        a pointer to an arena from which to allocate. C++03 allowed implementors
91        to suppose two allocators of the same type always compare equal (that means
92        that memory allocated by one allocator object could be deallocated by another
93        instance of the same type) and allocators were not swapped when the container
94        was swapped.
95      </p>
96<p>
97        C++11 further improves stateful allocator support through <a href="http://en.cppreference.com/w/cpp/memory/allocator_traits" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_traits</span></code></a>.
98        <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_traits</span></code> is the protocol between
99        a container and an allocator, and an allocator writer can customize its behaviour
100        (should the container propagate it in move constructor, swap, etc.?) following
101        <code class="computeroutput"><span class="identifier">allocator_traits</span></code> requirements.
102        <span class="bold"><strong>Boost.Container</strong></span> not only supports this model
103        with C++11 but also <span class="bold"><strong>backports it to C++03</strong></span>
104        via <code class="computeroutput"><a class="link" href="../boost/container/allocator_traits.html" title="Struct template allocator_traits">boost::container::allocator_traits</a></code>
105        including some C++17 changes. This class offers some workarounds for C++03
106        compilers to achieve the same allocator guarantees as <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator_traits</span></code>.
107      </p>
108<p>
109        In [Boost.Container] containers, if possible, a single allocator is hold
110        to construct <code class="computeroutput"><span class="identifier">value_type</span></code>s.
111        If the container needs an auxiliary allocator (e.g. an array allocator used
112        by <code class="computeroutput"><span class="identifier">deque</span></code> or <code class="computeroutput"><span class="identifier">stable_vector</span></code>), that allocator is also
113        stored in the container and initialized from the user-supplied allocator
114        when the container is constructed (i.e. it's not constructed on the fly when
115        auxiliary memory is needed).
116      </p>
117</div>
118<div class="section">
119<div class="titlepage"><div><div><h3 class="title">
120<a name="container.cpp_conformance.scoped_allocator"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.scoped_allocator" title="Scoped allocators">Scoped allocators</a>
121</h3></div></div></div>
122<p>
123        C++11 improves stateful allocators with the introduction of <a href="http://en.cppreference.com/w/cpp/memory/scoped_allocator_adaptor" target="_top"><code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">scoped_allocator_adaptor</span></code></a>
124        class template. <code class="computeroutput"><span class="identifier">scoped_allocator_adaptor</span></code>
125        is instantiated with one outer allocator and zero or more inner allocators.
126      </p>
127<p>
128        A scoped allocator is a mechanism to automatically propagate the state of
129        the allocator to the subobjects of a container in a controlled way. If instantiated
130        with only one allocator type, the inner allocator becomes the <code class="computeroutput"><span class="identifier">scoped_allocator_adaptor</span></code> itself, thus using
131        the same allocator resource for the container and every element within the
132        container and, if the elements themselves are containers, each of their elements
133        recursively. If instantiated with more than one allocator, the first allocator
134        is the outer allocator for use by the container, the second allocator is
135        passed to the constructors of the container's elements, and, if the elements
136        themselves are containers, the third allocator is passed to the elements'
137        elements, and so on.
138      </p>
139<p>
140        <span class="bold"><strong>Boost.Container</strong></span> implements its own <code class="computeroutput"><a class="link" href="../boost/container/scoped_allocator_adaptor.html" title="Class template scoped_allocator_adaptor">scoped_allocator_adaptor</a></code>
141        class and <span class="bold"><strong>backports this feature also to C++03 compilers</strong></span>.
142        Due to C++03 limitations, in those compilers the allocator propagation implemented
143        by <code class="computeroutput"><span class="identifier">scoped_allocator_adaptor</span><span class="special">::</span><span class="identifier">construct</span></code>
144        functions will be based on traits (<code class="computeroutput"><a class="link" href="../boost/container/construc_idm45641208064992.html" title="Struct template constructible_with_allocator_suffix">constructible_with_allocator_suffix</a></code>
145        and <code class="computeroutput"><a class="link" href="../boost/container/construc_idm45641208075360.html" title="Struct template constructible_with_allocator_prefix">constructible_with_allocator_prefix</a></code>)
146        proposed in <a href="http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2008/n2554.pdf" target="_top">N2554:
147        The Scoped Allocator Model (Rev 2) proposal</a>. In conforming C++11
148        compilers or compilers supporting SFINAE expressions (when <code class="computeroutput"><span class="identifier">BOOST_NO_SFINAE_EXPR</span></code> is NOT defined), traits
149        are ignored and C++11 rules (<code class="computeroutput"><span class="identifier">is_constructible</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span>
150        <span class="identifier">Args</span><span class="special">...,</span>
151        <span class="identifier">inner_allocator_type</span><span class="special">&gt;::</span><span class="identifier">value</span></code> and <code class="computeroutput"><span class="identifier">is_constructible</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">,</span>
152        <span class="identifier">allocator_arg_t</span><span class="special">,</span>
153        <span class="identifier">inner_allocator_type</span><span class="special">,</span>
154        <span class="identifier">Args</span><span class="special">...&gt;::</span><span class="identifier">value</span></code>) will be used to detect if the allocator
155        must be propagated with suffix or prefix allocator arguments.
156      </p>
157</div>
158<div class="section">
159<div class="titlepage"><div><div><h3 class="title">
160<a name="container.cpp_conformance.insertion_hints"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.insertion_hints" title="Insertion hints in associative containers and preserving insertion ordering for elements with equivalent keys">Insertion
161      hints in associative containers and preserving insertion ordering for elements
162      with equivalent keys</a>
163</h3></div></div></div>
164<p>
165        <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#233" target="_top">LWG
166        Issue #233</a> corrected a defect in C++98 and specified how equivalent
167        keys were to be inserted in associative containers. <span class="bold"><strong>Boost.Container</strong></span>
168        implements the C++11 changes that were specified in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1780.html" target="_top">N1780
169        <span class="emphasis"><em>Comments on LWG issue 233: Insertion hints in associative containers</em></span></a>:
170      </p>
171<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
172<li class="listitem">
173            <code class="computeroutput"><span class="identifier">a_eq</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span></code>:
174            If a range containing elements equivalent to t exists in a_eq, t is inserted
175            at the end of that range.
176          </li>
177<li class="listitem">
178            <code class="computeroutput"><span class="identifier">a_eq</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">p</span><span class="special">,</span><span class="identifier">t</span><span class="special">)</span></code>:
179            t is inserted as close as possible to the position just prior to p.
180          </li>
181</ul></div>
182</div>
183<div class="section">
184<div class="titlepage"><div><div><h3 class="title">
185<a name="container.cpp_conformance.initializer_lists"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.initializer_lists" title="Initializer lists">Initializer
186      lists</a>
187</h3></div></div></div>
188<p>
189        <span class="bold"><strong>Boost.Container</strong></span> supports initialization,
190        assignments and insertions from initializer lists in compilers that implement
191        this feature.
192      </p>
193</div>
194<div class="section">
195<div class="titlepage"><div><div><h3 class="title">
196<a name="container.cpp_conformance.null_iterators"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.null_iterators" title="Null Forward Iterators">Null Forward
197      Iterators</a>
198</h3></div></div></div>
199<p>
200        <span class="bold"><strong>Boost.Container</strong></span> implements <a href="http://www.open-std.org/JTC1/sc22/WG21/docs/papers/2013/n3644.pdf" target="_top">C++14
201        Null Forward Iterators</a>, which means that value-initialized iterators
202        may be compared and compare equal to other value-initialized iterators of
203        the same type. Value initialized iterators behave as if they refer past the
204        end of the same empty sequence (example taken from N3644):
205      </p>
206<pre class="programlisting"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span> <span class="special">=</span> <span class="special">{</span> <span class="special">...</span> <span class="special">};</span>
207<span class="keyword">auto</span> <span class="identifier">ni</span> <span class="special">=</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;::</span><span class="identifier">iterator</span><span class="special">();</span>
208<span class="keyword">auto</span> <span class="identifier">nd</span> <span class="special">=</span> <span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;::</span><span class="identifier">iterator</span><span class="special">();</span>
209<span class="identifier">ni</span> <span class="special">==</span> <span class="identifier">ni</span><span class="special">;</span> <span class="comment">// True.</span>
210<span class="identifier">nd</span> <span class="special">!=</span> <span class="identifier">nd</span><span class="special">;</span> <span class="comment">// False.</span>
211<span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">ni</span><span class="special">;</span> <span class="comment">// ??? (likely false in practice).</span>
212<span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">ni</span><span class="special">;</span>   <span class="comment">// ??? (likely false in practice).</span>
213<span class="identifier">ni</span> <span class="special">==</span> <span class="identifier">nd</span><span class="special">;</span> <span class="comment">// Won't compile.</span>
214</pre>
215</div>
216<div class="section">
217<div class="titlepage"><div><div><h3 class="title">
218<a name="container.cpp_conformance.polymorphic_memory_resources"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.polymorphic_memory_resources" title="Polymorphic Memory Resources">Polymorphic
219      Memory Resources </a>
220</h3></div></div></div>
221<p>
222        The document <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html" target="_top">C++
223        Extensions for Library Fundamentals (final draft)</a> includes classes
224        that provide allocator type erasure and runtime polymorphism. As Pablo Halpern,
225        the author of the proposal, explains in the paper (<a href="https://isocpp.org/files/papers/N3916.pdf" target="_top">N3916
226        Polymorphic Memory Resources (r2)</a>):
227      </p>
228<p>
229        <span class="quote">“<span class="quote"><span class="emphasis"><em>A significant impediment to effective memory management
230        in C++ has been the inability to use allocators in non-generic contexts.
231        In large software systems, most of the application program consists of non-generic
232        procedural or object-oriented code that is compiled once and linked many
233        times.</em></span></span>”</span>
234      </p>
235<p>
236        <span class="quote">“<span class="quote"><span class="emphasis"><em>Allocators in C++, however, have historically relied solely
237        on compile-time polymorphism, and therefore have not been suitable for use
238        in vocabulary types, which are passed through interfaces between separately-compiled
239        modules, because the allocator type necessarily affects the type of the object
240        that uses it. This proposal builds upon the improvements made to allocators
241        in C++11 and describes a set of facilities for runtime polymorphic memory
242        resources that interoperate with the existing compile-time polymorphic allocators.</em></span></span>”</span>
243      </p>
244<p>
245        Most utilities from the Fundamentals TS were merged into C++17, but <span class="bold"><strong>Boost.Container</strong></span> offers them for C++03, C++11 and C++14
246        compilers.
247      </p>
248<p>
249        <span class="bold"><strong>Boost.Container</strong></span> implements nearly all classes
250        of the proposal under the namespace <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">pmr</span></code>.
251        There are two groups,
252      </p>
253<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
254<li class="listitem">
255            Header only utilities (these don't require the separately compiled library):
256            <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
257<li class="listitem">
258                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/memory_resource.html" title="Class memory_resource">memory_resource</a></code>.
259                </li>
260<li class="listitem">
261                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/resource_adaptor.html" title="Type definition resource_adaptor">resource_adaptor</a></code>.
262                </li>
263</ul></div>
264          </li>
265<li class="listitem">
266            Utilities that require the the separately compiled library:
267            <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
268<li class="listitem">
269                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code>.
270                </li>
271<li class="listitem">
272                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/monotonic_buffer_resource.html" title="Class monotonic_buffer_resource">monotonic_buffer_resource</a></code>.
273                </li>
274<li class="listitem">
275                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/unsynchr_idm45641212301584.html" title="Class unsynchronized_pool_resource">unsynchronized_pool_resource</a></code>.
276                </li>
277<li class="listitem">
278                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/synchronized_pool_resource.html" title="Class synchronized_pool_resource">synchronized_pool_resource</a></code>.
279                </li>
280<li class="listitem">
281                  Global resource functions: <code class="computeroutput"><a class="link" href="../boost/container/pmr/get_default_resource.html" title="Function get_default_resource">get_default_resource</a></code>/
282                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/set_default_resource.html" title="Function set_default_resource">set_default_resource</a></code>/
283                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/new_delete_resource.html" title="Function new_delete_resource">new_delete_resource</a></code>/
284                  <code class="computeroutput"><a class="link" href="../boost/container/pmr/null_memory_resource.html" title="Function null_memory_resource">null_memory_resource</a></code>
285                </li>
286<li class="listitem">
287                  Aliases for boost containers using the polymorphic allocator (like
288                  <code class="computeroutput"><a class="link" href="../boost_container_header_reference.html#boost.container.pmr.vector">pmr::vector</a></code>,
289                  etc.)
290                </li>
291</ul></div>
292          </li>
293</ul></div>
294<p>
295        <span class="bold"><strong>Boost.Container</strong></span>'s polymorphic resource library
296        is usable from C++03 containers, and offers some alternative utilities if
297        the required C++11 features of the <span class="emphasis"><em>Library Fundamentals</em></span>
298        specification are not available.
299      </p>
300<p>
301        Let's review the usage example given in <a href="https://isocpp.org/files/papers/N3916.pdf" target="_top">N3916</a>
302        and see how it can be implemented using <span class="bold"><strong>Boost.Container</strong></span>:
303        <span class="emphasis"><em>Suppose we are processing a series of shopping lists, where a shopping
304        list is a container of strings, and storing them in a collection (a list)
305        of shopping lists. Each shopping list being processed uses a bounded amount
306        of memory that is needed for a short period of time, while the collection
307        of shopping lists uses an unbounded amount of memory and will exist for a
308        longer period of time. For efficiency, we can use a more time-efficient memory
309        allocator based on a finite buffer for the temporary shopping lists.</em></span>
310      </p>
311<p>
312        Let's see how <code class="computeroutput"><span class="identifier">ShoppingList</span></code>
313        can be defined to support an polymorphic memory resource that can allocate
314        memory from different underlying mechanisms. The most important details are:
315      </p>
316<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
317<li class="listitem">
318            It should declare that supports an allocator defining an <code class="computeroutput"><span class="identifier">allocator_type</span></code> typedef. This <code class="computeroutput"><span class="identifier">allocator_type</span></code> will be of type <code class="computeroutput"><a class="link" href="../boost/container/pmr/memory_resource.html" title="Class memory_resource">memory_resource *</a></code>,
319            which is a base class for polymorphic resources.
320          </li>
321<li class="listitem">
322            It must define constructors that take the the allocator as argument.
323            It can be implemented in two ways:
324            <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
325<li class="listitem">
326                  <code class="computeroutput"><span class="identifier">ShoppingList</span></code> has
327                  constructors taking <code class="computeroutput"><a class="link" href="../boost/container/pmr/memory_resource.html" title="Class memory_resource">memory_resource*</a></code>
328                  as the last argument.
329                </li>
330<li class="listitem">
331                  <code class="computeroutput"><span class="identifier">ShoppingList</span></code> has
332                  constructors taking <code class="computeroutput"><a class="link" href="../boost/container/allocator_arg_t.html" title="Type definition allocator_arg_t">allocator_arg_t</a></code>
333                  as the first argument and <code class="computeroutput"><a class="link" href="../boost/container/pmr/memory_resource.html" title="Class memory_resource">memory_resource*</a></code>
334                  as the second argument.
335                </li>
336</ul></div>
337          </li>
338</ul></div>
339<p>
340        <span class="bold"><strong>Note:</strong></span> <span class="emphasis"><em>In C++03 compilers, it is
341        required that the programmer specializes as <code class="computeroutput"><span class="keyword">true</span></code>
342        <code class="computeroutput"><a class="link" href="../boost/container/construc_idm45641208064992.html" title="Struct template constructible_with_allocator_suffix">constructible_with_allocator_suffix</a></code>
343        or <code class="computeroutput"><a class="link" href="../boost/container/construc_idm45641208075360.html" title="Struct template constructible_with_allocator_prefix">constructible_with_allocator_prefix</a></code>
344        as in C++03 there is no way to automatically detect the chosen option at
345        compile time. If no specialization is done, <span class="bold"><strong>Boost.Container</strong></span>
346        assumes the suffix option</em></span>.
347      </p>
348<p>
349</p>
350<pre class="programlisting"><span class="comment">//ShoppingList.hpp</span>
351<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container</span><span class="special">/</span><span class="identifier">pmr</span><span class="special">/</span><span class="identifier">vector</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
352<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container</span><span class="special">/</span><span class="identifier">pmr</span><span class="special">/</span><span class="identifier">string</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
353
354<span class="keyword">class</span> <span class="identifier">ShoppingList</span>
355<span class="special">{</span>
356   <span class="comment">// A vector of strings using polymorphic allocators. Every element</span>
357   <span class="comment">// of the vector will use the same allocator as the vector itself.</span>
358   <span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">pmr</span><span class="special">::</span><span class="identifier">vector_of</span>
359      <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">pmr</span><span class="special">::</span><span class="identifier">string</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">m_strvec</span><span class="special">;</span>
360   <span class="comment">//Alternatively in compilers that support template aliases:</span>
361   <span class="comment">//    boost::container::pmr::vector&lt;boost::container::pmr::string&gt; m_strvec;</span>
362   <span class="keyword">public</span><span class="special">:</span>
363
364   <span class="comment">// This makes uses_allocator&lt;ShoppingList, memory_resource*&gt;::value true</span>
365   <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">pmr</span><span class="special">::</span><span class="identifier">memory_resource</span><span class="special">*</span> <span class="identifier">allocator_type</span><span class="special">;</span>
366
367   <span class="comment">// If the allocator is not specified, "m_strvec" uses pmr::get_default_resource().</span>
368   <span class="keyword">explicit</span> <span class="identifier">ShoppingList</span><span class="special">(</span><span class="identifier">allocator_type</span> <span class="identifier">alloc</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span>
369      <span class="special">:</span> <span class="identifier">m_strvec</span><span class="special">(</span><span class="identifier">alloc</span><span class="special">)</span> <span class="special">{}</span>
370
371   <span class="comment">// Copy constructor. As allocator is not specified,</span>
372   <span class="comment">// "m_strvec" uses pmr::get_default_resource().</span>
373   <span class="identifier">ShoppingList</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">ShoppingList</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">)</span>
374      <span class="special">:</span> <span class="identifier">m_strvec</span><span class="special">(</span><span class="identifier">other</span><span class="special">.</span><span class="identifier">m_strvec</span><span class="special">)</span> <span class="special">{}</span>
375
376   <span class="comment">// Copy construct using the given memory_resource.</span>
377   <span class="identifier">ShoppingList</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">ShoppingList</span><span class="special">&amp;</span> <span class="identifier">other</span><span class="special">,</span> <span class="identifier">allocator_type</span> <span class="identifier">a</span><span class="special">)</span>
378      <span class="special">:</span> <span class="identifier">m_strvec</span><span class="special">(</span><span class="identifier">other</span><span class="special">.</span><span class="identifier">m_strvec</span><span class="special">,</span> <span class="identifier">a</span><span class="special">)</span> <span class="special">{}</span>
379
380   <span class="identifier">allocator_type</span> <span class="identifier">get_allocator</span><span class="special">()</span> <span class="keyword">const</span>
381   <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">m_strvec</span><span class="special">.</span><span class="identifier">get_allocator</span><span class="special">().</span><span class="identifier">resource</span><span class="special">();</span> <span class="special">}</span>
382
383   <span class="keyword">void</span> <span class="identifier">add_item</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span><span class="identifier">item</span><span class="special">)</span>
384   <span class="special">{</span> <span class="identifier">m_strvec</span><span class="special">.</span><span class="identifier">emplace_back</span><span class="special">(</span><span class="identifier">item</span><span class="special">);</span> <span class="special">}</span>
385
386   <span class="comment">//...</span>
387<span class="special">};</span>
388</pre>
389<p>
390      </p>
391<p>
392        <span class="emphasis"><em>However, this time-efficient allocator is not appropriate for the
393        longer lived collection of shopping lists. This example shows how those temporary
394        shopping lists, using a time-efficient allocator, can be used to populate
395        the long lived collection of shopping lists, using a general purpose allocator,
396        something that would be annoyingly difficult without the polymorphic allocators.</em></span>
397      </p>
398<p>
399        In <span class="bold"><strong>Boost.Container</strong></span> for the time-efficient
400        allocation we can use <code class="computeroutput"><a class="link" href="../boost/container/pmr/monotonic_buffer_resource.html" title="Class monotonic_buffer_resource">monotonic_buffer_resource</a></code>,
401        providing an external buffer that will be used until it's exhausted. In the
402        default configuration, when the buffer is exhausted, the default memory resource
403        will be used instead.
404      </p>
405<p>
406</p>
407<pre class="programlisting"><span class="preprocessor">#include</span> <span class="string">"ShoppingList.hpp"</span>
408<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cassert</span><span class="special">&gt;</span>
409<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container</span><span class="special">/</span><span class="identifier">pmr</span><span class="special">/</span><span class="identifier">list</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
410<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">container</span><span class="special">/</span><span class="identifier">pmr</span><span class="special">/</span><span class="identifier">monotonic_buffer_resource</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
411
412<span class="keyword">void</span> <span class="identifier">processShoppingList</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">ShoppingList</span><span class="special">&amp;)</span>
413<span class="special">{</span>  <span class="comment">/**/</span>   <span class="special">}</span>
414
415<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
416<span class="special">{</span>
417   <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">;</span>
418   <span class="comment">//All memory needed by folder and its contained objects will</span>
419   <span class="comment">//be allocated from the default memory resource (usually new/delete) </span>
420   <span class="identifier">pmr</span><span class="special">::</span><span class="identifier">list_of</span><span class="special">&lt;</span><span class="identifier">ShoppingList</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">folder</span><span class="special">;</span> <span class="comment">// Default allocator resource</span>
421   <span class="comment">//Alternatively in compilers that support template aliases:</span>
422   <span class="comment">//    boost::container::pmr::list&lt;ShoppingList&gt; folder;</span>
423   <span class="special">{</span>
424      <span class="keyword">char</span> <span class="identifier">buffer</span><span class="special">[</span><span class="number">1024</span><span class="special">];</span>
425      <span class="identifier">pmr</span><span class="special">::</span><span class="identifier">monotonic_buffer_resource</span> <span class="identifier">buf_rsrc</span><span class="special">(&amp;</span><span class="identifier">buffer</span><span class="special">,</span> <span class="number">1024</span><span class="special">);</span>
426
427      <span class="comment">//All memory needed by temporaryShoppingList will be allocated</span>
428      <span class="comment">//from the local buffer (speeds up "processShoppingList")</span>
429      <span class="identifier">ShoppingList</span> <span class="identifier">temporaryShoppingList</span><span class="special">(&amp;</span><span class="identifier">buf_rsrc</span><span class="special">);</span>
430      <span class="identifier">assert</span><span class="special">(&amp;</span><span class="identifier">buf_rsrc</span> <span class="special">==</span> <span class="identifier">temporaryShoppingList</span><span class="special">.</span><span class="identifier">get_allocator</span><span class="special">());</span>
431
432      <span class="comment">//list nodes, and strings "salt" and "pepper" will be allocated</span>
433      <span class="comment">//in the stack thanks to "monotonic_buffer_resource".</span>
434      <span class="identifier">temporaryShoppingList</span><span class="special">.</span><span class="identifier">add_item</span><span class="special">(</span><span class="string">"salt"</span><span class="special">);</span>
435      <span class="identifier">temporaryShoppingList</span><span class="special">.</span><span class="identifier">add_item</span><span class="special">(</span><span class="string">"pepper"</span><span class="special">);</span>
436      <span class="comment">//...</span>
437
438      <span class="comment">//All modifications and additions to "temporaryShoppingList"</span>
439      <span class="comment">//will use memory from "buffer" until it's exhausted.</span>
440      <span class="identifier">processShoppingList</span><span class="special">(</span><span class="identifier">temporaryShoppingList</span><span class="special">);</span>
441
442      <span class="comment">//Processing done, now insert it in "folder",</span>
443      <span class="comment">//which uses the default memory resource</span>
444      <span class="identifier">folder</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">temporaryShoppingList</span><span class="special">);</span>
445      <span class="identifier">assert</span><span class="special">(</span><span class="identifier">pmr</span><span class="special">::</span><span class="identifier">get_default_resource</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">folder</span><span class="special">.</span><span class="identifier">back</span><span class="special">().</span><span class="identifier">get_allocator</span><span class="special">());</span>
446      <span class="comment">//temporaryShoppingList, buf_rsrc, and buffer go out of scope</span>
447   <span class="special">}</span>
448   <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
449<span class="special">}</span>
450</pre>
451<p>
452      </p>
453<p>
454        <span class="emphasis"><em>Notice that the shopping lists within <code class="computeroutput"><span class="identifier">folder</span></code>
455        use the default allocator resource whereas the shopping list <code class="computeroutput"><span class="identifier">temporaryShoppingList</span></code> uses the short-lived
456        but very fast <code class="computeroutput"><span class="identifier">buf_rsrc</span></code>. Despite
457        using different allocators, you can insert <code class="computeroutput"><span class="identifier">temporaryShoppingList</span></code>
458        into folder because they have the same <code class="computeroutput"><span class="identifier">ShoppingList</span></code>
459        type. Also, while <code class="computeroutput"><span class="identifier">ShoppingList</span></code>
460        uses memory_resource directly, <code class="computeroutput"><a class="link" href="../boost_container_header_reference.html#boost.container.pmr.list">pmr::list</a></code>,
461        <code class="computeroutput"><a class="link" href="../boost_container_header_reference.html#boost.container.pmr.vector">pmr::vector</a></code> and
462        <code class="computeroutput"><a class="link" href="../boost_container_header_reference.html#boost.container.pmr.string">pmr::string</a></code> all
463        use <code class="computeroutput"><a class="link" href="../boost/container/pmr/polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code>.</em></span>
464      </p>
465<p>
466        <span class="emphasis"><em>The resource passed to the <code class="computeroutput"><span class="identifier">ShoppingList</span></code>
467        constructor is propagated to the vector and each string within that <code class="computeroutput"><span class="identifier">ShoppingList</span></code>. Similarly, the resource used
468        to construct <code class="computeroutput"><span class="identifier">folder</span></code> is propagated
469        to the constructors of the ShoppingLists that are inserted into the list
470        (and to the strings within those <code class="computeroutput"><span class="identifier">ShoppingLists</span></code>).
471        The <code class="computeroutput"><a class="link" href="../boost/container/pmr/polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code>
472        template is designed to be almost interchangeable with a pointer to <code class="computeroutput"><a class="link" href="../boost/container/pmr/memory_resource.html" title="Class memory_resource">memory_resource</a></code>,
473        thus producing a <span class="emphasis"><em>bridge</em></span> between the template-policy
474        style of allocator and the polymorphic-base-class style of allocator.</em></span>
475      </p>
476<p>
477        This example actually shows how easy is to use <span class="bold"><strong>Boost.Container</strong></span>
478        to write type-erasured allocator-capable classes even in C++03 compilers.
479      </p>
480</div>
481<div class="section">
482<div class="titlepage"><div><div><h3 class="title">
483<a name="container.cpp_conformance.forward_list"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.forward_list" title="forward_list&lt;T&gt;"><code class="computeroutput"><span class="identifier">forward_list</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code></a>
484</h3></div></div></div>
485<p>
486        <span class="bold"><strong>Boost.Container</strong></span> does not offer C++11 <code class="computeroutput"><span class="identifier">forward_list</span></code> container yet, but it will
487        be available in future versions.
488      </p>
489</div>
490<div class="section">
491<div class="titlepage"><div><div><h3 class="title">
492<a name="container.cpp_conformance.vector_exception_guarantees"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.vector_exception_guarantees" title="vector vs. std::vector exception guarantees"><code class="computeroutput"><span class="identifier">vector</span></code> vs. <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>
493      exception guarantees</a>
494</h3></div></div></div>
495<p>
496        <code class="computeroutput"><a class="link" href="../boost/container/vector.html" title="Class template vector">vector</a></code> does not support
497        the strong exception guarantees given by <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span></code>
498        in functions like <code class="computeroutput"><span class="identifier">insert</span></code>,
499        <code class="computeroutput"><span class="identifier">push_back</span></code>, <code class="computeroutput"><span class="identifier">emplace</span></code>, <code class="computeroutput"><span class="identifier">emplace_back</span></code>,
500        <code class="computeroutput"><span class="identifier">resize</span></code>, <code class="computeroutput"><span class="identifier">reserve</span></code>
501        or <code class="computeroutput"><span class="identifier">shrink_to_fit</span></code> for either
502        copyable or no-throw moveable classes. In C++11 <a href="http://en.cppreference.com/w/cpp/utility/move_if_noexcept" target="_top">move_if_noexcept</a>
503        is used to maintain C++03 exception safety guarantees combined with C++11
504        move semantics. This strong exception guarantee degrades the insertion performance
505        of copyable and throwing-moveable types, degrading moves to copies when such
506        types are inserted in the vector using the aforementioned members.
507      </p>
508<p>
509        This strong exception guarantee also precludes the possibility of using some
510        type of in-place reallocations that can further improve the insertion performance
511        of <code class="computeroutput"><span class="identifier">vector</span></code> See <a class="link" href="extended_allocators.html" title="Extended functionality: Extended allocators">Extended
512        Allocators</a> to know more about these optimizations.
513      </p>
514<p>
515        <code class="computeroutput"><a class="link" href="../boost/container/vector.html" title="Class template vector">vector</a></code> always uses
516        move constructors/assignments to rearrange elements in the vector and uses
517        memory expansion mechanisms if the allocator supports them, while offering
518        only basic safety guarantees. It trades off exception guarantees for an improved
519        performance.
520      </p>
521</div>
522<div class="section">
523<div class="titlepage"><div><div><h3 class="title">
524<a name="container.cpp_conformance.container_const_reference_parameters"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.container_const_reference_parameters" title="Parameter taken by const reference that can be changed">Parameter
525      taken by const reference that can be changed</a>
526</h3></div></div></div>
527<p>
528        Several container operations use a parameter taken by const reference that
529        can be changed during execution of the function. <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#526" target="_top">LWG
530        Issue 526 (<span class="emphasis"><em>Is it undefined if a function in the standard changes
531        in parameters?</em></span>)</a> discusses them:
532      </p>
533<pre class="programlisting"><span class="comment">//Given std::vector&lt;int&gt; v</span>
534<span class="identifier">v</span><span class="special">.</span><span class="identifier">insert</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">[</span><span class="number">2</span><span class="special">]);</span>
535<span class="comment">//v[2] can be changed by moving elements of vector</span>
536
537<span class="comment">//Given std::list&lt;int&gt; l:</span>
538<span class="identifier">l</span><span class="special">.</span><span class="identifier">remove</span><span class="special">(*</span><span class="identifier">l</span><span class="special">.</span><span class="identifier">begin</span><span class="special">())</span>
539<span class="comment">//The operation could delete the first element, and then continue trying to access it.</span>
540</pre>
541<p>
542        The adopted resolution, NAD (Not A Defect), implies that previous operations
543        must be well-defined. This requires code to detect a reference to an inserted
544        element and an additional copy in that case, impacting performance even when
545        references to already inserted objects are not used. Note that equivalent
546        functions taking rvalue references or iterator ranges require elements not
547        already inserted in the container.
548      </p>
549<p>
550        <span class="bold"><strong>Boost.Container</strong></span> prioritizes performance
551        and has not implemented the NAD resolution: in functions that might modify
552        the argument, the library requires references to elements not stored in the
553        container. Using references to inserted elements yields to undefined behaviour
554        (although in debug mode, this precondition violation could be notified via
555        BOOST_ASSERT).
556      </p>
557</div>
558<div class="section">
559<div class="titlepage"><div><div><h3 class="title">
560<a name="container.cpp_conformance.Vector_bool"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.Vector_bool" title="vector&lt;bool&gt; specialization"><code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> specialization</a>
561</h3></div></div></div>
562<p>
563        <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> specialization
564        has been quite problematic, and there have been several unsuccessful tries
565        to deprecate or remove it from the standard. <span class="bold"><strong>Boost.Container</strong></span>
566        does not implement it as there is a superior <a href="http://www.boost.org/libs/dynamic_bitset/" target="_top">Boost.DynamicBitset</a>
567        solution. For issues with <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code>
568        see the following papers:
569      </p>
570<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
571<li class="listitem">
572            <a href="http://howardhinnant.github.io/onvectorbool.html" target="_top">On <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code></a>
573          </li>
574<li class="listitem">
575            <a href="http://www.gotw.ca/publications/N1211.pdf" target="_top">vector&lt;bool&gt;:
576            N1211: More Problems, Better Solutions</a>,
577          </li>
578<li class="listitem">
579            <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2160.html" target="_top">N2160:
580            Library Issue 96: Fixing vector&lt;bool&gt;</a>,
581          </li>
582<li class="listitem">
583            <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2204.html" target="_top">N2204
584            A Specification to deprecate vector&lt;bool&gt;</a>.
585          </li>
586</ul></div>
587<p>
588        Quotes:
589      </p>
590<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
591<li class="listitem">
592            <span class="quote">“<span class="quote"><span class="emphasis"><em>But it is a shame that the C++ committee gave this excellent
593            data structure the name vector&lt;bool&gt; and that it gives no guidance
594            nor encouragement on the critical generic algorithms that need to be
595            optimized for this data structure. Consequently, few std::lib implementations
596            go to this trouble.</em></span></span>”</span>
597          </li>
598<li class="listitem">
599            <span class="quote">“<span class="quote"><span class="emphasis"><em>In 1998, admitting that the committee made a mistake
600            was controversial. Since then Java has had to deprecate such significant
601            portions of their libraries that the idea C++ would be ridiculed for
602            deprecating a single minor template specialization seems quaint.</em></span></span>”</span>
603          </li>
604<li class="listitem">
605            <span class="quote">“<span class="quote"><span class="emphasis"><em><code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> is not a container and <code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;::</span><span class="identifier">iterator</span></code> is not a random-access iterator
606            (or even a forward or bidirectional iterator either, for that matter).
607            This has already broken user code in the field in mysterious ways.</em></span></span>”</span>
608          </li>
609<li class="listitem">
610            <span class="quote">“<span class="quote"><span class="emphasis"><em><code class="computeroutput"><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code> forces a specific (and potentially
611            bad) optimization choice on all users by enshrining it in the standard.
612            The optimization is premature; different users have different requirements.
613            This too has already hurt users who have been forced to implement workarounds
614            to disable the 'optimization' (e.g., by using a vector&lt;char&gt; and
615            manually casting to/from bool).</em></span></span>”</span>
616          </li>
617</ul></div>
618<p>
619        So <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;::</span><span class="identifier">iterator</span></code> returns real <code class="computeroutput"><span class="keyword">bool</span></code>
620        references and works as a fully compliant container. If you need a memory
621        optimized version of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">container</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">bool</span><span class="special">&gt;</span></code>,
622        please use <a href="http://www.boost.org/libs/dynamic_bitset/" target="_top">Boost.DynamicBitset</a>.
623      </p>
624</div>
625<div class="section">
626<div class="titlepage"><div><div><h3 class="title">
627<a name="container.cpp_conformance.non_standard_memset_initialization"></a><a class="link" href="cpp_conformance.html#container.cpp_conformance.non_standard_memset_initialization" title="Non-standard value initialization using std::memset">Non-standard
628      value initialization using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code></a>
629</h3></div></div></div>
630<p>
631        <span class="bold"><strong>Boost.Container</strong></span> uses <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code>
632        with a zero value to initialize some types as in most platforms this initialization
633        yields to the desired value initialization with improved performance.
634      </p>
635<p>
636        Following the C11 standard, <span class="bold"><strong>Boost.Container</strong></span>
637        assumes that <span class="emphasis"><em>for any integer type, the object representation where
638        all the bits are zero shall be a representation of the value zero in that
639        type</em></span>. Since <code class="computeroutput"><span class="identifier">_Bool</span></code>/<code class="computeroutput"><span class="keyword">wchar_t</span></code>/<code class="computeroutput"><span class="keyword">char16_t</span></code>/<code class="computeroutput"><span class="keyword">char32_t</span></code> are also integer types in C, it considers
640        all C++ integral types as initializable via <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code>.
641      </p>
642<p>
643        By default, <span class="bold"><strong>Boost.Container</strong></span> also considers
644        floating point types to be initializable using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code>.
645        Most platforms are compatible with this initialization, but in case this
646        initialization is not desirable the user can <code class="computeroutput"><span class="preprocessor">#define</span>
647        <span class="identifier">BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO</span></code>
648        before including library headers.
649      </p>
650<p>
651        By default, it also considers pointer types (pointer and pointer to function
652        types, excluding member object and member function pointers) to be initializable
653        using <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code>. Most platforms are compatible with
654        this initialization, but in case this initialization is not desired the user
655        can <code class="computeroutput"><span class="preprocessor">#define</span> <span class="identifier">BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO</span></code>
656        before including library headers.
657      </p>
658<p>
659        If neither <code class="computeroutput"><span class="identifier">BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO</span></code>
660        nor <code class="computeroutput"><span class="identifier">BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO</span></code>
661        is defined <span class="bold"><strong>Boost.Container</strong></span> also considers
662        POD types to be value initializable via <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">memset</span></code>
663        with value zero.
664      </p>
665</div>
666</div>
667<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
668<td align="left"></td>
669<td align="right"><div class="copyright-footer">Copyright © 2009-2018 Ion Gaztanaga<p>
670        Distributed under the Boost Software License, Version 1.0. (See accompanying
671        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>)
672      </p>
673</div></td>
674</tr></table>
675<hr>
676<div class="spirit-nav">
677<a accesskey="p" href="extended_allocators.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../container.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="known_issues.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
678</div>
679</body>
680</html>
681