// // (C) Copyright Thomas Klimpel 2010. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // #ifndef BOOST_OPTIMIZED_MOVE_WRAPPER_HPP #define BOOST_OPTIMIZED_MOVE_WRAPPER_HPP #include #if defined(BOOST_NO_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED) namespace boost { // A wrapper class to fix the signature of the copy assignment operator // of a copyable and movable class using the optimized move emulation. template class optimized_move_wrapper : public OptimizedCopyAndMove { typedef OptimizedCopyAndMove base_t; public: // mark this type as movable, and provide the required conversion operators operator ::BOOST_MOVE_NAMESPACE::rv&() { return *reinterpret_cast< ::BOOST_MOVE_NAMESPACE::rv* >(this); } operator const ::BOOST_MOVE_NAMESPACE::rv&() const { return *reinterpret_cast* >(this); } // copy constructor optimized_move_wrapper(const optimized_move_wrapper& w) : base_t(w) {} // move constructor optimized_move_wrapper(BOOST_RV_REF(optimized_move_wrapper) w) : base_t(boost::move(static_cast(w))) {} // copy assignment operator with nice signature, using RVO for move assignment of temporaries optimized_move_wrapper& operator=(optimized_move_wrapper s) { base_t::operator=(boost::move(static_cast(s))); return *this; } // move assignment operator optimized_move_wrapper& operator=(BOOST_RV_REF(optimized_move_wrapper) b) { base_t::operator=(boost::move(static_cast(b))); return *this; } //optimized_move_wrapper(base_t& b) : base_t(b) {} //optimized_move_wrapper(BOOST_RV_REF(base_t) b) : base_t(b) {} //optimized_move_wrapper(const BOOST_RV_REF(base_t) b) : base_t(b) {} // forward constructor with no arguments optimized_move_wrapper() {} // forward constructors with 1 argument template explicit optimized_move_wrapper(BOOST_FWD_REF(MaybeRv) a) : base_t(boost::forward(a)) {} // forward constructors with 2 arguments template optimized_move_wrapper(BOOST_FWD_REF(MaybeRv1) a1, BOOST_FWD_REF(MaybeRv2) a2) : base_t(boost::forward(a1), boost::forward(a2)) {} // forward constructors with 3 arguments template optimized_move_wrapper(BOOST_FWD_REF(MaybeRv1) a1, BOOST_FWD_REF(MaybeRv2) a2, BOOST_FWD_REF(MaybeRv3) a3) : base_t(boost::forward(a1), boost::forward(a2), boost::forward(a3)) {} // forward copy and move assignment operators optimized_move_wrapper& operator=(base_t& b) { base_t::operator=(b); return *this; } optimized_move_wrapper& operator=(BOOST_RV_REF(base_t) b) { base_t::operator=(b); return *this; } optimized_move_wrapper& operator=(const BOOST_RV_REF(base_t) b) { base_t::operator=(b); return *this; } // forward other assignment operators template optimized_move_wrapper& operator=(BOOST_FWD_REF(MaybeRv) a) { base_t::operator=(boost::forward(a)); return *this; } }; } // namespace boost #define BOOST_OPTIMIZED_MOVE_WRAPPER(TYPE)\ boost::optimized_move_wrapper\ // #else //BOOST_NO_RVALUE_REFERENCES #define BOOST_OPTIMIZED_MOVE_WRAPPER(TYPE)\ TYPE\ // #endif #endif