Subject: Re: [Boost-bugs] [Boost C++ Libraries] #7418: Copyable and explicitly movable classes
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-06-13 10:04:56
#7418: Copyable and explicitly movable classes
-------------------------------+------------------------
Reporter: danieljames | Owner: igaztanaga
Type: Patches | Status: new
Milestone: To Be Determined | Component: move
Version: Boost 1.53.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+------------------------
Changes (by KaiSt <k.stuhlemmer@â¦>):
* version: Boost 1.52.0 => Boost 1.53.0
* type: Feature Requests => Patches
Comment:
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:
{{{
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))
{ }
};
}}}
If I use this implementation, pre-C++11 compiler users might use it with
bad surprising behaviour:
{{{
Movable m;
MovableUser mu(m); // this silently compile wit pre-C++11 compiler,
C++11 compiler correctly fails because of missing boost::move()
}}}
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():
{{{
Movable m;
MovableUser mu(boost::move(m)); // now correct
}}}
I hope, that helps. Please consider to add this patch or a similar
solution to new releases.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7418#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC