2014-02-11 14:11 GMT+01:00 Ion Gaztañaga
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 rvstd::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);
+1 I've written and use such a macro myself. Regards, Kris