#include #include #include #define BOOST_MOVE_RETURNS_T 1 #define BOOST_MOVE_RETURNS_RV_T 2 //#define BOOST_MOVE_RETURN_OPTION BOOST_MOVE_RETURNS_T #define BOOST_MOVE_RETURN_OPTION BOOST_MOVE_RETURNS_RV_T namespace boost { namespace detail{ template class rv { private: rv &operator=(const rv&); T& r_; public: explicit rv(T& r) : r_(r) {} T* operator->() {return &r_;} T& operator*() {return r_;} }; } //namespace detail template class is_movable { public: static const bool value = boost::is_convertible< T, detail::rv >::value; }; #if (BOOST_MOVE_RETURN_OPTION == BOOST_MOVE_RETURNS_T) template typename boost::enable_if, T >::type move(T& t) { return T(detail::rv(t)); } #elif (BOOST_MOVE_RETURN_OPTION == BOOST_MOVE_RETURNS_RV_T) template typename boost::enable_if, detail::rv >::type move(T& t) { return detail::rv(t); } #else #error "Bad option" #endif } //namespace boost class movable { movable(movable &); movable & operator=(movable &); public: operator boost::detail::rv() { return boost::detail::rv(*this); } movable() {} movable(boost::detail::rv) {} movable & operator=(boost::detail::rv) { return *this; } }; movable function(movable m) { return movable(boost::move(m)); } int main() { BOOST_STATIC_ASSERT((boost::is_movable::value == true)); //this works both with Visual 7.1 and GCC 4.3 movable m; movable m2(boost::move(m)); movable m3(function(movable(boost::move(m2)))); return 0; }