Boost logo

Boost Users :

Subject: Re: [Boost-users] [move] differences between results in C++03 and C++11 modes
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2014-02-11 08:11:04


El 11/02/2014 8:55, Adam Romanek escribió:
> Hi!
>
> Some time ago I encountered a problem with assigning the return value of
> boost::move() to a non-const reference in C++11 mode, but not in C++03
> mode. See [1] for a StackOverflow question that I created for this
> issue. It contains all the details so for brevity I won't repeat them
> here. Could anyone explain this issue? Is this a limitation of C++03
> emulation or a defect in the implementation?

Yes, it's a limitation of boost move. When called with the emulation
code boost::move() returns a type rv<T> & that is convertible to T (and
that is the key point to implement emulated move semantics). However in
C++11 you return a T&& (unnamed rvalue reference) which is not
assignable to T &.

In your case, as R is std::ostream &, the emulation return
rv<std::ostrean> (convertible to std::ostream &) and the C++11 version
returns std::ostream &&, which is not convertible to std::ostream &.

I guess we could add a new macro to boost move for return types. In
emulated mode, it moves the return value, In C++11 mode it only return
the value (If RVO can't be applied the compiler will do an implicit
move). Something like:

//return boost::move(r) in emulation
//return r in C++11
return BOOST_MOVE_RET(r);

If you think it's a good idea, please fill a ticket.

Best,

Ion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net