<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Class template polymorphic_allocator</title> <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.78.1"> <link rel="home" href="../../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> <link rel="up" href="../../../boost_container_header_reference.html#header.boost.container.pmr.polymorphic_allocator_hpp" title="Header <boost/container/pmr/polymorphic_allocator.hpp>"> <link rel="prev" href="monotonic_buffer_resource.html" title="Class monotonic_buffer_resource"> <link rel="next" href="operator_idm46583871492768.html" title="Function template operator=="> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table cellpadding="2" width="100%"><tr> <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td> <td align="center"><a href="../../../../../index.html">Home</a></td> <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td> <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> <td align="center"><a href="../../../../../more/index.htm">More</a></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="monotonic_buffer_resource.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../boost_container_header_reference.html#header.boost.container.pmr.polymorphic_allocator_hpp"><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="operator_idm46583871492768.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> </div> <div class="refentry"> <a name="boost.container.pmr.polymorphic_allocator"></a><div class="titlepage"></div> <div class="refnamediv"> <h2><span class="refentrytitle">Class template polymorphic_allocator</span></h2> <p>boost::container::pmr::polymorphic_allocator</p> </div> <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2> <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="../../../boost_container_header_reference.html#header.boost.container.pmr.polymorphic_allocator_hpp" title="Header <boost/container/pmr/polymorphic_allocator.hpp>">boost/container/pmr/polymorphic_allocator.hpp</a>> </span><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> T<span class="special">></span> <span class="keyword">class</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">{</span> <span class="keyword">public</span><span class="special">:</span> <span class="comment">// types</span> <span class="keyword">typedef</span> <span class="identifier">T</span> <a name="boost.container.pmr.polymorphic_allocator.value_type"></a><span class="identifier">value_type</span><span class="special">;</span> <span class="comment">// <a class="link" href="polymorphic_allocator.html#boost.container.pmr.polymorphic_allocatorconstruct-copy-destruct">construct/copy/destruct</a></span> <a class="link" href="polymorphic_allocator.html#idm46583871508784-bb"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> <a class="link" href="polymorphic_allocator.html#idm46583871506800-bb"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><a class="link" href="memory_resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span><span class="special">)</span><span class="special">;</span> <a class="link" href="polymorphic_allocator.html#idm46583871501872-bb"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span><span class="special">)</span><span class="special">;</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">></span> <a class="link" href="polymorphic_allocator.html#idm46583871499456-bb"><span class="identifier">polymorphic_allocator</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a><span class="special"><</span> <span class="identifier">U</span> <span class="special">></span> <span class="special">&</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span> <a class="link" href="polymorphic_allocator.html#idm46583871495920-bb"><span class="keyword">operator</span><span class="special">=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span><span class="special">)</span><span class="special">;</span> <span class="comment">// <a class="link" href="polymorphic_allocator.html#idm46583871535104-bb">public member functions</a></span> <span class="identifier">T</span> <span class="special">*</span> <a class="link" href="polymorphic_allocator.html#idm46583871534544-bb"><span class="identifier">allocate</span></a><span class="special">(</span><span class="identifier">size_t</span><span class="special">)</span><span class="special">;</span> <span class="keyword">void</span> <a class="link" href="polymorphic_allocator.html#idm46583871531536-bb"><span class="identifier">deallocate</span></a><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">)</span><span class="special">;</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> Args<span class="special">></span> <span class="keyword">void</span> <a class="link" href="polymorphic_allocator.html#idm46583871526064-bb"><span class="identifier">construct</span></a><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span><span class="special">,</span> <span class="identifier">Args</span> <span class="special">&&</span><span class="special">...</span><span class="special">)</span><span class="special">;</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">></span> <span class="keyword">void</span> <a class="link" href="polymorphic_allocator.html#idm46583871517376-bb"><span class="identifier">destroy</span></a><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span><span class="special">)</span><span class="special">;</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <a class="link" href="polymorphic_allocator.html#idm46583871514016-bb"><span class="identifier">select_on_container_copy_construction</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> <a class="link" href="memory_resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> <a class="link" href="polymorphic_allocator.html#idm46583871511328-bb"><span class="identifier">resource</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> <span class="special">}</span><span class="special">;</span></pre></div> <div class="refsect1"> <a name="idm45555398775360"></a><h2>Description</h2> <p>A specialization of class template <code class="computeroutput"><a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code> conforms to the Allocator requirements. Constructed with different memory resources, different instances of the same specialization of <code class="computeroutput"><a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a></code> can exhibit entirely different allocation behavior. This runtime polymorphism allows objects that use <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> to behave as if they used different allocator types at run time even though they use the same static allocator type. </p> <div class="refsect2"> <a name="idm45555398770784"></a><h3> <a name="boost.container.pmr.polymorphic_allocatorconstruct-copy-destruct"></a><code class="computeroutput">polymorphic_allocator</code> public construct/copy/destruct</h3> <div class="orderedlist"><ol class="orderedlist" type="1"> <li class="listitem"> <pre class="literallayout"><a name="idm46583871508784-bb"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre> <p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to <code class="computeroutput">get_default_resource()</code>. </p> </li> <li class="listitem"> <pre class="literallayout"><a name="idm46583871506800-bb"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><a class="link" href="memory_resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> r<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Requires</strong></span>: r is non-null.</p> <p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to r.</p> <p><span class="bold"><strong>Throws</strong></span>: Nothing</p> <p><span class="bold"><strong>Notes</strong></span>: This constructor provides an implicit conversion from memory_resource*. Non-standard extension: if r is null m_resource is set to get_default_resource(). </p> </li> <li class="listitem"> <pre class="literallayout"><a name="idm46583871501872-bb"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span> other<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p> </li> <li class="listitem"> <pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">></span> <a name="idm46583871499456-bb"></a><span class="identifier">polymorphic_allocator</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a><span class="special"><</span> <span class="identifier">U</span> <span class="special">></span> <span class="special">&</span> other<span class="special">)</span> <span class="keyword">noexcept</span><span class="special">;</span></pre> <p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p> </li> <li class="listitem"> <pre class="literallayout"><a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span> <a name="idm46583871495920-bb"></a><span class="keyword">operator</span><span class="special">=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <span class="special">&</span> other<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Effects</strong></span>: Sets m_resource to other.resource(). </p> </li> </ol></div> </div> <div class="refsect2"> <a name="idm45555398726448"></a><h3> <a name="idm46583871535104-bb"></a><code class="computeroutput">polymorphic_allocator</code> public member functions</h3> <div class="orderedlist"><ol class="orderedlist" type="1"> <li class="listitem"> <pre class="literallayout"><span class="identifier">T</span> <span class="special">*</span> <a name="idm46583871534544-bb"></a><span class="identifier">allocate</span><span class="special">(</span><span class="identifier">size_t</span> n<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Returns</strong></span>: Equivalent to <code class="computeroutput">static_cast<T*>(m_resource->allocate(n * sizeof(T), alignof(T)))</code>. </p> </li> <li class="listitem"> <pre class="literallayout"><span class="keyword">void</span> <a name="idm46583871531536-bb"></a><span class="identifier">deallocate</span><span class="special">(</span><span class="identifier">T</span> <span class="special">*</span> p<span class="special">,</span> <span class="identifier">size_t</span> n<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Requires</strong></span>: p was allocated from a memory resource, x, equal to *m_resource, using <code class="computeroutput">x.allocate(n * sizeof(T), alignof(T))</code>.</p> <p><span class="bold"><strong>Effects</strong></span>: Equivalent to m_resource->deallocate(p, n * sizeof(T), alignof(T)).</p> <p><span class="bold"><strong>Throws</strong></span>: Nothing. </p> </li> <li class="listitem"> <pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> Args<span class="special">></span> <span class="keyword">void</span> <a name="idm46583871526064-bb"></a><span class="identifier">construct</span><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span> p<span class="special">,</span> <span class="identifier">Args</span> <span class="special">&&</span><span class="special">...</span> args<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Requires</strong></span>: Uses-allocator construction of T with allocator <code class="computeroutput">this->resource()</code> and constructor arguments <code class="computeroutput">std::forward<Args>(args)...</code> is well-formed. [Note: uses-allocator construction is always well formed for types that do not use allocators. - end note]</p> <p><span class="bold"><strong>Effects</strong></span>: Construct a T object at p by uses-allocator construction with allocator <code class="computeroutput">this->resource()</code> and constructor arguments <code class="computeroutput">std::forward<Args>(args)...</code>.</p> <p><span class="bold"><strong>Throws</strong></span>: Nothing unless the constructor for T throws. </p> </li> <li class="listitem"> <pre class="literallayout"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> U<span class="special">></span> <span class="keyword">void</span> <a name="idm46583871517376-bb"></a><span class="identifier">destroy</span><span class="special">(</span><span class="identifier">U</span> <span class="special">*</span> p<span class="special">)</span><span class="special">;</span></pre> <p><span class="bold"><strong>Effects</strong></span>: p->~U(). </p> </li> <li class="listitem"> <pre class="literallayout"><a class="link" href="polymorphic_allocator.html" title="Class template polymorphic_allocator">polymorphic_allocator</a> <a name="idm46583871514016-bb"></a><span class="identifier">select_on_container_copy_construction</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre> <p><span class="bold"><strong>Returns</strong></span>: Equivalent to <code class="computeroutput">polymorphic_allocator()</code>. </p> </li> <li class="listitem"> <pre class="literallayout"><a class="link" href="memory_resource.html" title="Class memory_resource">memory_resource</a> <span class="special">*</span> <a name="idm46583871511328-bb"></a><span class="identifier">resource</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre> <p><span class="bold"><strong>Returns</strong></span>: m_resource. </p> </li> </ol></div> </div> </div> </div> <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> <td align="left"></td> <td align="right"><div class="copyright-footer">Copyright © 2009-2015 Ion Gaztanaga<p> Distributed under the Boost Software License, Version 1.0. (See accompanying 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>) </p> </div></td> </tr></table> <hr> <div class="spirit-nav"> <a accesskey="p" href="monotonic_buffer_resource.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../../boost_container_header_reference.html#header.boost.container.pmr.polymorphic_allocator_hpp"><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="operator_idm46583871492768.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a> </div> </body> </html>