Boost C++ Libraries: Ticket #6606: Map: rbtree_node doesn't use allocator_traits to construct m_data https://svn.boost.org/trac10/ticket/6606 <p> I'm not at all sure what the best way to fix this is. The STL implementation that ships with the Visual Studio 11 preview calls allocate for the tree node and then construct for each of the members (the actual tree node constructor never gets called, as far as I can tell). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6606 Trac 1.4.3 Erik Jensen <Erik.Jensen@…> Fri, 24 Feb 2012 03:45:19 GMT <link>https://svn.boost.org/trac10/ticket/6606#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6606#comment:1</guid> <description> <p> I guess another option would be to tuck a class like this (which I just made up) into your details, somewhere: </p> <pre class="wiki">#include &lt;boost/type_traits.hpp&gt; template &lt;typename Ty, typename Alloc&gt; class allocator_constructed { public: template &lt;typename T, typename Args...&gt; allocator_constructed(const Alloc &amp;alloc, Args &amp;&amp;...args) : _alloc(alloc) { allocator_traits&lt;Alloc&gt;::construct(_alloc, static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data)), boost::forward&lt;Args&gt;(args)...); } ~manually_constructed() { allocator_traits&lt;Alloc&gt;::destroy(_alloc, static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data))); } Ty&amp; operator*() { return *static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data)); } const Ty&amp; operator*() const { return *static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data)); } Ty* operator-&gt;() { return static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data)); } const Ty* operator-&gt;() const { return static_cast&lt;Ty*&gt;(static_cast&lt;void*&gt;(&amp;data)); } private: Alloc _alloc; boost::aligned_storage&lt;sizeof(Ty), std::alignment_of&lt;Ty&gt;::value&gt; data; }; </pre><p> And then have members of this class. </p> </description> <category>Ticket</category> </item> <item> <author>Erik Jensen <Erik.Jensen@…></author> <pubDate>Thu, 22 Mar 2012 19:26:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6606#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6606#comment:2</guid> <description> <p> One further note: </p> <p> I was reading through the standard, and came across this (§23.2.1¶3): </p> <p> For the components affected by this subclause that declare an <strong><code>allocator_type</code></strong>, objects stored in these components shall be constructed using the <strong><code>allocator_traits&lt;allocator_type&gt;::construct</code></strong> function and destroyed using the <strong><code>allocator_traits&lt;allocator_type&gt;::destroy</code></strong> function (20.6.8.2). These functions are called only for the container’s element type, not for internal types used by the container. [ <em>Note:</em> This means, for example, that a node-based container might need to construct nodes containing aligned buffers and call construct to place the element into the buffer. <em>—end note</em> ] </p> <p> My understanding, then, is that while <code>construct</code> should be called for the pair, it should not be called for <code>rbtree_node</code> (which it currently is). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Ion Gaztañaga</dc:creator> <pubDate>Fri, 24 Aug 2012 21:32:16 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6606#comment:3 https://svn.boost.org/trac10/ticket/6606#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in Boost 1.50 </p> Ticket