// 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) // (C) Copyright 2007-8 Anthony Williams // (C) Copyright 2011-2012 Vicente J. Botet Escriba #ifndef BOOST_THREAD_MOVE_HPP #define BOOST_THREAD_MOVE_HPP #include #ifndef BOOST_NO_SFINAE #include #include #include #include #include #endif #include #include #include namespace boost { namespace detail { template struct has_move_emulation_enabled_aux_dummy_specialization; template struct thread_move_t { T& t; explicit thread_move_t(T& t_): t(t_) {} T& operator*() const { return t; } T* operator->() const { return &t; } private: void operator=(thread_move_t&); }; } #ifndef BOOST_NO_SFINAE template typename enable_if >, boost::detail::thread_move_t >::type move(T& t) { return boost::detail::thread_move_t(t); } #endif template boost::detail::thread_move_t move(boost::detail::thread_move_t t) { return t; } } #if ! defined BOOST_NO_RVALUE_REFERENCES #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END #define BOOST_THREAD_RV(V) V #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE) #define BOOST_THREAD_DCL_MOVABLE(TYPE) #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \ namespace detail { \ template \ struct has_move_emulation_enabled_aux_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #elif ! defined BOOST_NO_RVALUE_REFERENCES && defined BOOST_MSVC #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END #define BOOST_THREAD_RV(V) V #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE) #define BOOST_THREAD_DCL_MOVABLE(TYPE) #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \ namespace detail { \ template \ struct has_move_emulation_enabled_aux_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #else #if defined BOOST_THREAD_USES_MOVE #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END #define BOOST_THREAD_RV(V) V #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE) #define BOOST_THREAD_DCL_MOVABLE(TYPE) #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \ namespace detail { \ template \ struct has_move_emulation_enabled_aux_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #else #define BOOST_THREAD_RV_REF(TYPE) boost::detail::thread_move_t< TYPE > #define BOOST_THREAD_RV_REF_BEG boost::detail::thread_move_t< #define BOOST_THREAD_RV_REF_END > #define BOOST_THREAD_RV(V) (*V) #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE) #define BOOST_THREAD_DCL_MOVABLE(TYPE) \ template <> \ struct has_move_emulation_enabled_aux< TYPE > \ : BOOST_MOVE_BOOST_NS::integral_constant \ {}; #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \ template \ struct has_move_emulation_enabled_aux< #define BOOST_THREAD_DCL_MOVABLE_END > \ : BOOST_MOVE_BOOST_NS::integral_constant \ {}; #endif namespace boost { namespace detail { template BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type) make_rv_ref(T v) BOOST_NOEXCEPT { return (BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type))(v); } // template // BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type) // make_rv_ref(T &v) BOOST_NOEXCEPT // { // return (BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type))(v); // } // template // const BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type) // make_rv_ref(T const&v) BOOST_NOEXCEPT // { // return (const BOOST_THREAD_RV_REF(typename ::boost::remove_cv::type>::type))(v); // } } } #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE.move() //#define BOOST_THREAD_MAKE_RV_REF(RVALUE) boost::detail::make_rv_ref(RVALUE) #endif #if ! defined BOOST_NO_RVALUE_REFERENCES #define BOOST_THREAD_MOVABLE(TYPE) #else #if defined BOOST_THREAD_USES_MOVE #define BOOST_THREAD_MOVABLE(TYPE) \ ::boost::rv& move() BOOST_NOEXCEPT \ { \ return *static_cast< ::boost::rv* >(this); \ } \ const ::boost::rv& move() const BOOST_NOEXCEPT \ { \ return *static_cast* >(this); \ } \ operator ::boost::rv&() \ { \ return *static_cast< ::boost::rv* >(this); \ } \ operator const ::boost::rv&() const \ { \ return *static_cast* >(this); \ }\ #else #define BOOST_THREAD_MOVABLE(TYPE) \ operator ::boost::detail::thread_move_t() BOOST_NOEXCEPT \ { \ return move(); \ } \ ::boost::detail::thread_move_t move() BOOST_NOEXCEPT \ { \ ::boost::detail::thread_move_t x(*this); \ return x; \ } \ #endif #endif #define BOOST_THREAD_MOVABLE_ONLY(TYPE) \ BOOST_THREAD_NO_COPYABLE(TYPE) \ BOOST_THREAD_MOVABLE(TYPE) \ #define BOOST_THREAD_COPYABLE_AND_MOVABLE(TYPE) \ BOOST_THREAD_MOVABLE(TYPE) \ #ifndef BOOST_NO_RVALUE_REFERENCES namespace boost { namespace thread_detail { template typename decay::type decay_copy(T&& t) { return boost::forward(t); } } } #endif #include #endif