1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2010-2012.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/move for documentation.
10 //////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_MOVE_MOVE_HELPERS_HPP
13 #define BOOST_MOVE_MOVE_HELPERS_HPP
15 #ifndef BOOST_CONFIG_HPP
16 # include <boost/config.hpp>
19 #if defined(BOOST_HAS_PRAGMA_ONCE)
23 #include <boost/move/utility_core.hpp>
24 #include <boost/move/detail/meta_utils.hpp>
26 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
28 #define BOOST_MOVE_CATCH_CONST(U) \
29 typename ::boost::move_detail::if_< ::boost::move_detail::is_class_or_union<U>, BOOST_CATCH_CONST_RLVALUE(U), const U &>::type
30 #define BOOST_MOVE_CATCH_RVALUE(U)\
31 typename ::boost::move_detail::if_< ::boost::move_detail::is_class_or_union<U>, BOOST_RV_REF(U), ::boost::move_detail::nat>::type
32 #define BOOST_MOVE_CATCH_FWD(U) BOOST_FWD_REF(U)
34 #define BOOST_MOVE_CATCH_CONST(U) const U &
35 #define BOOST_MOVE_CATCH_RVALUE(U) U &&
36 #define BOOST_MOVE_CATCH_FWD(U) U &&
39 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
40 #define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\
41 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_CONST(TYPE) x)\
42 { return FWD_FUNCTION(static_cast<const TYPE&>(x)); }\
44 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
45 { return FWD_FUNCTION(::boost::move(x)); }\
47 RETURN_VALUE PUB_FUNCTION(TYPE &x)\
48 { return FWD_FUNCTION(const_cast<const TYPE &>(x)); }\
50 template<class BOOST_MOVE_TEMPL_PARAM>\
51 typename ::boost::move_detail::enable_if_and\
53 , ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
54 , ::boost::move_detail::is_class_or_union<TYPE>\
55 , ::boost::has_move_emulation_disabled<BOOST_MOVE_TEMPL_PARAM>\
57 PUB_FUNCTION(const BOOST_MOVE_TEMPL_PARAM &u)\
58 { return FWD_FUNCTION(u); }\
60 template<class BOOST_MOVE_TEMPL_PARAM>\
61 typename ::boost::move_detail::disable_if_or\
63 , ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM> \
64 , ::boost::move_detail::and_ \
65 < ::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM> \
66 , ::boost::move_detail::is_class_or_union<BOOST_MOVE_TEMPL_PARAM> \
69 PUB_FUNCTION(const BOOST_MOVE_TEMPL_PARAM &u)\
72 return FWD_FUNCTION(::boost::move(t));\
76 #elif (defined(_MSC_VER) && (_MSC_VER == 1600))
78 #define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\
79 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_CONST(TYPE) x)\
80 { return FWD_FUNCTION(static_cast<const TYPE&>(x)); }\
82 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
83 { return FWD_FUNCTION(::boost::move(x)); }\
85 template<class BOOST_MOVE_TEMPL_PARAM>\
86 typename ::boost::move_detail::enable_if_c\
87 < !::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>::value\
88 , RETURN_VALUE >::type\
89 PUB_FUNCTION(const BOOST_MOVE_TEMPL_PARAM &u)\
92 return FWD_FUNCTION(::boost::move(t));\
98 #define BOOST_MOVE_CONVERSION_AWARE_CATCH(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION)\
99 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_CONST(TYPE) x)\
100 { return FWD_FUNCTION(static_cast<const TYPE&>(x)); }\
102 RETURN_VALUE PUB_FUNCTION(BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
103 { return FWD_FUNCTION(::boost::move(x)); }\
109 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
111 #define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
112 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
113 { return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
115 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
116 { return FWD_FUNCTION(arg1, ::boost::move(x)); }\
118 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, TYPE &x)\
119 { return FWD_FUNCTION(arg1, const_cast<const TYPE &>(x)); }\
121 template<class BOOST_MOVE_TEMPL_PARAM>\
122 typename ::boost::move_detail::enable_if_and\
124 , ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
125 , ::boost::has_move_emulation_disabled<BOOST_MOVE_TEMPL_PARAM>\
127 PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
128 { return FWD_FUNCTION(arg1, u); }\
130 template<class BOOST_MOVE_TEMPL_PARAM>\
131 typename ::boost::move_detail::disable_if_or\
133 , ::boost::move_detail::is_rv<BOOST_MOVE_TEMPL_PARAM>\
134 , ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM>\
135 , ::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO>\
137 PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
140 return FWD_FUNCTION(arg1, ::boost::move(t));\
144 #elif (defined(_MSC_VER) && (_MSC_VER == 1600))
146 #define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
147 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
148 { return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
150 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
151 { return FWD_FUNCTION(arg1, ::boost::move(x)); }\
153 template<class BOOST_MOVE_TEMPL_PARAM>\
154 typename ::boost::move_detail::disable_if_or\
156 , ::boost::move_detail::is_same<TYPE, BOOST_MOVE_TEMPL_PARAM> \
157 , ::boost::move_detail::is_convertible<BOOST_MOVE_TEMPL_PARAM, UNLESS_CONVERTIBLE_TO> \
159 PUB_FUNCTION(ARG1 arg1, const BOOST_MOVE_TEMPL_PARAM &u)\
162 return FWD_FUNCTION(arg1, ::boost::move(t));\
168 #define BOOST_MOVE_CONVERSION_AWARE_CATCH_1ARG(PUB_FUNCTION, TYPE, RETURN_VALUE, FWD_FUNCTION, ARG1, UNLESS_CONVERTIBLE_TO)\
169 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_CONST(TYPE) x)\
170 { return FWD_FUNCTION(arg1, static_cast<const TYPE&>(x)); }\
172 RETURN_VALUE PUB_FUNCTION(ARG1 arg1, BOOST_MOVE_CATCH_RVALUE(TYPE) x) \
173 { return FWD_FUNCTION(arg1, ::boost::move(x)); }\
178 #endif //#ifndef BOOST_MOVE_MOVE_HELPERS_HPP