Boost C++ Libraries: Ticket #7418: Copyable and explicitly movable classes https://svn.boost.org/trac10/ticket/7418 <p> Making a class movable can have some unfortunate side effects, as far as I know these are all due to implementing implicit moves. So if possible, it's be useful to have a class where the move mechanism only kicks in when boost::move is explicitly used. This could be efficient for cases where the class is explicitly moved (e.g. in a move enable vector), but avoid the potential problems. </p> <p> I believe that this could be done by defining just the move construct and move assignment, but with no implicit conversions or other special functions. Then the main difficultly is modifying the <code>has_move_emulation_enabled</code> trait to support these types. Maybe the class could have a magic member typedef which is detected by sfinae, or maybe you can come up with something better. </p> <p> Does this sound like a good idea? I haven't tried implementing it, so I might be missing some problem with the idea. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7418 Trac 1.4.3 KaiSt <k.stuhlemmer@…> Thu, 13 Jun 2013 09:51:02 GMT attachment set https://svn.boost.org/trac10/ticket/7418 https://svn.boost.org/trac10/ticket/7418 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-move-1.53.diff</span> </li> </ul> <p> Extending boost/move by macro BOOST_RV_REF_WRAPPER() for safer usage. Patch has been created against Boost 1.53 </p> Ticket KaiSt <k.stuhlemmer@…> Thu, 13 Jun 2013 10:04:56 GMT version, type changed https://svn.boost.org/trac10/ticket/7418#comment:1 https://svn.boost.org/trac10/ticket/7418#comment:1 <ul> <li><strong>version</strong> <span class="trac-field-old">Boost 1.52.0</span> → <span class="trac-field-new">Boost 1.53.0</span> </li> <li><strong>type</strong> <span class="trac-field-old">Feature Requests</span> → <span class="trac-field-new">Patches</span> </li> </ul> <p> Hi, I locally solved the problem in Boost 1.53. May changes are attached as "boost-move-1.53.diff". To be sure we are talking about the same problem, let me explain, which problem I see. Let's assume the following use case: </p> <pre class="wiki"> class Movable { private: BOOST_MOVABLE_BUT_NOT_COPYABLE(Movable); public: Movable() : mNrMoves(0) { } Movable(BOOST_RV_REF(Movable) other) : mNrMoves(other.mNrMoves + 1) { other.mNrMoves = 0; } unsigned mNrMoves; }; struct MovableUser { Movable m; MovableUser(BOOST_RV_REF_WRAPPER(Movable) mi) : m(boost::move(mi)) { } }; </pre><p> If I use this implementation, pre-C++11 compiler users might use it with bad surprising behaviour: </p> <pre class="wiki"> Movable m; MovableUser mu(m); // this silently compile wit pre-C++11 compiler, C++11 compiler correctly fails because of missing boost::move() </pre><p> My fix just added a wrapper class for boost::rv and an accompanying macro BOOST_RV_REF_WRAPPER(). If You change Movable(BOOST_RV_REF(Movable) other) to Movable(BOOST_RV_REF_WRAPPER(Movable) other), then the example above also fails with pre-C++11 compiler enforcing the usage of boost::move(): </p> <pre class="wiki"> Movable m; MovableUser mu(boost::move(m)); // now correct </pre><p> I hope, that helps. Please consider to add this patch or a similar solution to new releases. </p> Ticket Ion Gaztañaga Thu, 30 Jun 2016 11:39:38 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7418#comment:2 https://svn.boost.org/trac10/ticket/7418#comment:2 <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">wontfix</span> </li> </ul> <p> Closing old bugs, this feature was not generally requested by users so closing as WONTFIX. </p> Ticket