// 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 #include #include #include #include #include #endif #include #include #include #include #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES #include #endif namespace lslboost { namespace detail { template struct enable_move_utility_emulation_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&); }; } #if !defined BOOST_THREAD_USES_MOVE #ifndef BOOST_NO_SFINAE template typename enable_if >, lslboost::detail::thread_move_t >::type move(T& t) { return lslboost::detail::thread_move_t(t); } #endif template lslboost::detail::thread_move_t move(lslboost::detail::thread_move_t t) { return t; } #endif //#if !defined BOOST_THREAD_USES_MOVE } #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_THREAD_COPY_ASSIGN_REF(TYPE) BOOST_COPY_ASSIGN_REF(TYPE) #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(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 enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \ namespace detail { \ template \ struct enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #elif ! defined BOOST_NO_CXX11_RVALUE_REFERENCES && defined BOOST_MSVC #define BOOST_THREAD_COPY_ASSIGN_REF(TYPE) BOOST_COPY_ASSIGN_REF(TYPE) #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(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 enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \ namespace detail { \ template \ struct enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #else #if defined BOOST_THREAD_USES_MOVE #define BOOST_THREAD_COPY_ASSIGN_REF(TYPE) BOOST_COPY_ASSIGN_REF(TYPE) #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE) #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(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 enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \ namespace detail { \ template \ struct enable_move_utility_emulation_dummy_specialization< #define BOOST_THREAD_DCL_MOVABLE_END > \ : integral_constant \ {}; \ } #else #define BOOST_THREAD_COPY_ASSIGN_REF(TYPE) const TYPE& #define BOOST_THREAD_RV_REF(TYPE) lslboost::detail::thread_move_t< TYPE > #define BOOST_THREAD_RV_REF_BEG lslboost::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 enable_move_utility_emulation< TYPE > \ { \ static const bool value = false; \ }; #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \ template \ struct enable_move_utility_emulation< #define BOOST_THREAD_DCL_MOVABLE_BEG2(T1, T2) \ template \ struct enable_move_utility_emulation< #define BOOST_THREAD_DCL_MOVABLE_END > \ { \ static const bool value = false; \ }; #endif namespace lslboost { namespace detail { template BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type) make_rv_ref(T v) BOOST_NOEXCEPT { return (BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type))(v); } // template // BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type) // make_rv_ref(T &v) BOOST_NOEXCEPT // { // return (BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type))(v); // } // template // const BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type) // make_rv_ref(T const&v) BOOST_NOEXCEPT // { // return (const BOOST_THREAD_RV_REF(typename ::lslboost::remove_cv::type>::type))(v); // } } } #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE.move() //#define BOOST_THREAD_MAKE_RV_REF(RVALUE) lslboost::detail::make_rv_ref(RVALUE) #endif #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES #define BOOST_THREAD_MOVABLE(TYPE) #define BOOST_THREAD_COPYABLE(TYPE) #else #if defined BOOST_THREAD_USES_MOVE #define BOOST_THREAD_MOVABLE(TYPE) \ ::lslboost::rv& move() BOOST_NOEXCEPT \ { \ return *static_cast< ::lslboost::rv* >(this); \ } \ const ::lslboost::rv& move() const BOOST_NOEXCEPT \ { \ return *static_cast* >(this); \ } \ operator ::lslboost::rv&() \ { \ return *static_cast< ::lslboost::rv* >(this); \ } \ operator const ::lslboost::rv&() const \ { \ return *static_cast* >(this); \ }\ #define BOOST_THREAD_COPYABLE(TYPE) \ TYPE& operator=(TYPE &t)\ { this->operator=(static_cast &>(const_cast(t))); return *this;} #else #define BOOST_THREAD_MOVABLE(TYPE) \ operator ::lslboost::detail::thread_move_t() BOOST_NOEXCEPT \ { \ return move(); \ } \ ::lslboost::detail::thread_move_t move() BOOST_NOEXCEPT \ { \ ::lslboost::detail::thread_move_t x(*this); \ return x; \ } \ #define BOOST_THREAD_COPYABLE(TYPE) #endif #endif #define BOOST_THREAD_MOVABLE_ONLY(TYPE) \ BOOST_THREAD_NO_COPYABLE(TYPE) \ BOOST_THREAD_MOVABLE(TYPE) \ typedef int boost_move_no_copy_constructor_or_assign; \ #define BOOST_THREAD_COPYABLE_AND_MOVABLE(TYPE) \ BOOST_THREAD_COPYABLE(TYPE) \ BOOST_THREAD_MOVABLE(TYPE) \ namespace lslboost { namespace thread_detail { #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES #elif defined BOOST_THREAD_USES_MOVE template struct is_rv : ::lslboost::move_detail::is_rv {}; #else template struct is_rv : ::lslboost::integral_constant {}; template struct is_rv< ::lslboost::detail::thread_move_t > : ::lslboost::integral_constant {}; template struct is_rv< const ::lslboost::detail::thread_move_t > : ::lslboost::integral_constant {}; #endif #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template struct remove_reference : lslboost::remove_reference {}; template struct decay : lslboost::decay {}; #else template struct remove_reference { typedef Tp type; }; template struct remove_reference { typedef Tp type; }; template struct remove_reference< rv > { typedef Tp type; }; template struct decay { private: typedef typename lslboost::move_detail::remove_rvalue_reference::type Up0; typedef typename lslboost::remove_reference::type Up; public: typedef typename conditional < is_array::value, typename remove_extent::type*, typename conditional < is_function::value, typename add_pointer::type, typename remove_cv::type >::type >::type type; }; #endif #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES template typename decay::type decay_copy(T&& t) { return lslboost::forward(t); } typedef void (*void_fct_ptr)(); // inline void_fct_ptr // decay_copy(void (&t)()) // { // return &t; // } #else template typename decay::type decay_copy(BOOST_THREAD_FWD_REF(T) t) { return lslboost::forward(t); } #endif } } #include #endif