move.hpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // Distributed under the Boost Software License, Version 1.0. (See
  2. // accompanying file LICENSE_1_0.txt or copy at
  3. // http://www.boost.org/LICENSE_1_0.txt)
  4. // (C) Copyright 2007-8 Anthony Williams
  5. // (C) Copyright 2011-2012 Vicente J. Botet Escriba
  6. #ifndef BOOST_THREAD_MOVE_HPP
  7. #define BOOST_THREAD_MOVE_HPP
  8. #include <boost/thread/detail/config.hpp>
  9. #ifndef BOOST_NO_SFINAE
  10. #include <boost/utility/enable_if.hpp>
  11. #include <boost/type_traits/is_convertible.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. #include <boost/type_traits/remove_cv.hpp>
  14. #include <boost/type_traits/decay.hpp>
  15. #endif
  16. #include <boost/thread/detail/delete.hpp>
  17. #include <boost/move/utility.hpp>
  18. #include <boost/move/traits.hpp>
  19. #include <boost/config/abi_prefix.hpp>
  20. namespace boost
  21. {
  22. namespace detail
  23. {
  24. template <typename T>
  25. struct enable_move_utility_emulation_dummy_specialization;
  26. template<typename T>
  27. struct thread_move_t
  28. {
  29. T& t;
  30. explicit thread_move_t(T& t_):
  31. t(t_)
  32. {}
  33. T& operator*() const
  34. {
  35. return t;
  36. }
  37. T* operator->() const
  38. {
  39. return &t;
  40. }
  41. private:
  42. void operator=(thread_move_t&);
  43. };
  44. }
  45. #if !defined BOOST_THREAD_USES_MOVE
  46. #ifndef BOOST_NO_SFINAE
  47. template<typename T>
  48. typename enable_if<boost::is_convertible<T&,boost::detail::thread_move_t<T> >, boost::detail::thread_move_t<T> >::type move(T& t)
  49. {
  50. return boost::detail::thread_move_t<T>(t);
  51. }
  52. #endif
  53. template<typename T>
  54. boost::detail::thread_move_t<T> move(boost::detail::thread_move_t<T> t)
  55. {
  56. return t;
  57. }
  58. #endif //#if !defined BOOST_THREAD_USES_MOVE
  59. }
  60. #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
  61. #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE)
  62. #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
  63. #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG
  64. #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END
  65. #define BOOST_THREAD_RV(V) V
  66. #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE
  67. #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE)
  68. #define BOOST_THREAD_DCL_MOVABLE(TYPE)
  69. #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \
  70. namespace detail { \
  71. template <typename T> \
  72. struct enable_move_utility_emulation_dummy_specialization<
  73. #define BOOST_THREAD_DCL_MOVABLE_END > \
  74. : integral_constant<bool, false> \
  75. {}; \
  76. }
  77. #elif ! defined BOOST_NO_CXX11_RVALUE_REFERENCES && defined BOOST_MSVC
  78. #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE)
  79. #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
  80. #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG
  81. #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END
  82. #define BOOST_THREAD_RV(V) V
  83. #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE
  84. #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE)
  85. #define BOOST_THREAD_DCL_MOVABLE(TYPE)
  86. #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \
  87. namespace detail { \
  88. template <typename T> \
  89. struct enable_move_utility_emulation_dummy_specialization<
  90. #define BOOST_THREAD_DCL_MOVABLE_END > \
  91. : integral_constant<bool, false> \
  92. {}; \
  93. }
  94. #else
  95. #if defined BOOST_THREAD_USES_MOVE
  96. #define BOOST_THREAD_RV_REF(TYPE) BOOST_RV_REF(TYPE)
  97. #define BOOST_THREAD_RV_REF_2_TEMPL_ARGS(TYPE) BOOST_RV_REF_2_TEMPL_ARGS(TYPE)
  98. #define BOOST_THREAD_RV_REF_BEG BOOST_RV_REF_BEG
  99. #define BOOST_THREAD_RV_REF_END BOOST_RV_REF_END
  100. #define BOOST_THREAD_RV(V) V
  101. #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE)
  102. #define BOOST_THREAD_DCL_MOVABLE(TYPE)
  103. #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \
  104. namespace detail { \
  105. template <typename T> \
  106. struct enable_move_utility_emulation_dummy_specialization<
  107. #define BOOST_THREAD_DCL_MOVABLE_END > \
  108. : integral_constant<bool, false> \
  109. {}; \
  110. }
  111. #else
  112. #define BOOST_THREAD_RV_REF(TYPE) boost::detail::thread_move_t< TYPE >
  113. #define BOOST_THREAD_RV_REF_BEG boost::detail::thread_move_t<
  114. #define BOOST_THREAD_RV_REF_END >
  115. #define BOOST_THREAD_RV(V) (*V)
  116. #define BOOST_THREAD_FWD_REF(TYPE) BOOST_FWD_REF(TYPE)
  117. #define BOOST_THREAD_DCL_MOVABLE(TYPE) \
  118. template <> \
  119. struct enable_move_utility_emulation< TYPE > \
  120. { \
  121. static const bool value = false; \
  122. };
  123. #define BOOST_THREAD_DCL_MOVABLE_BEG(T) \
  124. template <typename T> \
  125. struct enable_move_utility_emulation<
  126. #define BOOST_THREAD_DCL_MOVABLE_END > \
  127. { \
  128. static const bool value = false; \
  129. };
  130. #endif
  131. namespace boost
  132. {
  133. namespace detail
  134. {
  135. template <typename T>
  136. BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type)
  137. make_rv_ref(T v) BOOST_NOEXCEPT
  138. {
  139. return (BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type))(v);
  140. }
  141. // template <typename T>
  142. // BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type)
  143. // make_rv_ref(T &v) BOOST_NOEXCEPT
  144. // {
  145. // return (BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type))(v);
  146. // }
  147. // template <typename T>
  148. // const BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type)
  149. // make_rv_ref(T const&v) BOOST_NOEXCEPT
  150. // {
  151. // return (const BOOST_THREAD_RV_REF(typename ::boost::remove_cv<typename ::boost::remove_reference<T>::type>::type))(v);
  152. // }
  153. }
  154. }
  155. #define BOOST_THREAD_MAKE_RV_REF(RVALUE) RVALUE.move()
  156. //#define BOOST_THREAD_MAKE_RV_REF(RVALUE) boost::detail::make_rv_ref(RVALUE)
  157. #endif
  158. #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
  159. #define BOOST_THREAD_MOVABLE(TYPE)
  160. #else
  161. #if defined BOOST_THREAD_USES_MOVE
  162. #define BOOST_THREAD_MOVABLE(TYPE) \
  163. ::boost::rv<TYPE>& move() BOOST_NOEXCEPT \
  164. { \
  165. return *static_cast< ::boost::rv<TYPE>* >(this); \
  166. } \
  167. const ::boost::rv<TYPE>& move() const BOOST_NOEXCEPT \
  168. { \
  169. return *static_cast<const ::boost::rv<TYPE>* >(this); \
  170. } \
  171. operator ::boost::rv<TYPE>&() \
  172. { \
  173. return *static_cast< ::boost::rv<TYPE>* >(this); \
  174. } \
  175. operator const ::boost::rv<TYPE>&() const \
  176. { \
  177. return *static_cast<const ::boost::rv<TYPE>* >(this); \
  178. }\
  179. #else
  180. #define BOOST_THREAD_MOVABLE(TYPE) \
  181. operator ::boost::detail::thread_move_t<TYPE>() BOOST_NOEXCEPT \
  182. { \
  183. return move(); \
  184. } \
  185. ::boost::detail::thread_move_t<TYPE> move() BOOST_NOEXCEPT \
  186. { \
  187. ::boost::detail::thread_move_t<TYPE> x(*this); \
  188. return x; \
  189. } \
  190. #endif
  191. #endif
  192. #define BOOST_THREAD_MOVABLE_ONLY(TYPE) \
  193. BOOST_THREAD_NO_COPYABLE(TYPE) \
  194. BOOST_THREAD_MOVABLE(TYPE) \
  195. #define BOOST_THREAD_COPYABLE_AND_MOVABLE(TYPE) \
  196. BOOST_THREAD_MOVABLE(TYPE) \
  197. namespace boost
  198. { namespace thread_detail
  199. {
  200. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  201. template <class T>
  202. typename decay<T>::type
  203. decay_copy(T&& t)
  204. {
  205. return boost::forward<T>(t);
  206. }
  207. #else
  208. template <class T>
  209. typename decay<T>::type
  210. decay_copy(BOOST_THREAD_FWD_REF(T) t)
  211. {
  212. return boost::forward<T>(t);
  213. }
  214. #endif
  215. }
  216. }
  217. #include <boost/config/abi_suffix.hpp>
  218. #endif