Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As for "how to write an allocator", <code>§ 20.6.9 [default.allocator]</code> has this to say about <code>std::allocator</code>:</p> <pre><code>#include &lt;new&gt; // specialize for void: template &lt;&gt; class allocator&lt;void&gt; { public: typedef void* pointer; typedef const void* const_pointer; // reference-to-void members are impossible. typedef void value_type; template &lt;class U&gt; struct rebind { typedef allocator&lt;U&gt; other; }; }; template &lt;class T&gt; class allocator { public: typedef size_t size_type; typedef ptrdiff_t difference_type; typedef T* pointer; typedef const T* const_pointer; typedef T&amp; reference; typedef const T&amp; const_reference; typedef T value_type; template &lt;class U&gt; struct rebind { typedef allocator&lt;U&gt; other; }; allocator() throw(); allocator(const allocator&amp;) throw(); template &lt;class U&gt; allocator(const allocator&lt;U&gt;&amp;) throw(); ~allocator(); pointer address(reference x) const throw(); const_pointer address(const_reference x) const throw(); pointer allocate(size_type, allocator&lt;void&gt;::const_pointer hint = 0); void deallocate(pointer p, size_type n) throw(); size_type max_size() const throw(); template&lt;class U, class... Args&gt; void construct(U* p, Args&amp;&amp;... args); template &lt;class U&gt; void destroy(U* p); }; </code></pre> <p>You'd probably want to add helper member functions that behave more like the <code>new</code> and <code>delete</code> we're used to.</p> <pre><code>template&lt;class... Args&gt; pointer alloc_and_constr(size_type n, Args&amp;&amp;... args); template &lt;class U&gt; pointer destr_and_dealloc(U* p); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload