Boost C++ Libraries: Ticket #2243: value_initialized should have its own swap functions https://svn.boost.org/trac10/ticket/2243 <p> For a given type <code>T</code>, the current (1.36.0) version of <code>boost::value_initialized&lt;T&gt;</code> is <em>only</em> Swappable if it is both CopyConstructible and CopyAssignable. IMO, <code>value_initialized&lt;T&gt;</code> should be Swappable whenever <code>T</code> is Swappable. Moreover, when swapping <code>value_initialized&lt;T&gt;</code> objects, the custom swap function of <code>T</code> should be used, whenever available. </p> <p> I'd like to propose resolving this issue by adding a swap member function to <code>value_initialized&lt;T&gt;</code>, and a non-member swap that calls the member. (As recommended by Scott Meyers, Effective C++ Third Edition, Item 25: <em>Consider support for a non-throwing swap.</em>) </p> <p> I would like to have <code>value_initialized&lt;T&gt;::swap</code> calling <code>boost::swap</code> to swap its data, using the <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/boost/utility/swap.hpp"><span class="icon">​</span>boost::swap utility</a> by Joseph Gauterin <em>et al</em>, that was recently added to the trunk. The boost::swap utility internally uses <em>argument-dependent lookup</em> (ADL) to find the custom swap function of <code>T</code>, if available. Thereby it works around various compiler version specific bugs regarding ADL, as tested at <a href="http://www.boost.org/development/tests/trunk/developer/utility-swap_.html">utility-swap_.html</a>. Moreover, it supports swapping arrays (as requested by ticket <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2056" title="#2056: Feature Requests: Please add support for built-in arrays to boost::swap (closed: fixed)">#2056</a>), so <code>value_initialized&lt;T&gt;::swap</code> would also support having <code>T</code> as a built-in array type. </p> <p> Please take a look at the attached patch. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2243 Trac 1.4.3 niels_dekker Thu, 21 Aug 2008 19:33:59 GMT attachment set https://svn.boost.org/trac10/ticket/2243 https://svn.boost.org/trac10/ticket/2243 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">swap_value_initialized.patch</span> </li> </ul> Ticket niels_dekker Wed, 27 Aug 2008 16:05:01 GMT owner changed https://svn.boost.org/trac10/ticket/2243#comment:1 https://svn.boost.org/trac10/ticket/2243#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">No-Maintainer</span> to <span class="trac-author">Fernando Cacciola</span> </li> </ul> <p> Assigned to Fernando Cacciola. Fernando, I wouldn't mind committing the patch myself, but only if you think it's okay :-) </p> Ticket niels_dekker Thu, 28 Aug 2008 19:30:50 GMT owner changed https://svn.boost.org/trac10/ticket/2243#comment:2 https://svn.boost.org/trac10/ticket/2243#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Fernando Cacciola</span> to <span class="trac-author">niels_dekker</span> </li> </ul> <p> I've just committed the patch to the trunk: changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/48424" title="Added value_initialized::swap according to ticket #2243, as agreed ...">[48424]</a> and <a class="changeset" href="https://svn.boost.org/trac10/changeset/48425" title="Added value_initialized::swap documentation + test">[48425]</a>. Please note that before merging this to the release branch, <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/boost/utility/swap.hpp"><span class="icon">​</span>boost/utility/swap.hpp</a> should be added to the release branch. </p> Ticket Daniel James Sat, 27 Jun 2009 11:46:57 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2243#comment:3 https://svn.boost.org/trac10/ticket/2243#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> THis was merged by niels_dekker to release in <a class="changeset" href="https://svn.boost.org/trac10/changeset/49967" title="Merged value_initialized::swap from trunk [48424] and [48425], ...">[49967]</a>. </p> Ticket