comparison DEPENDENCIES/generic/include/boost/move/utility.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
8 // See http://www.boost.org/libs/move for documentation. 8 // See http://www.boost.org/libs/move for documentation.
9 // 9 //
10 ////////////////////////////////////////////////////////////////////////////// 10 //////////////////////////////////////////////////////////////////////////////
11 11
12 //! \file 12 //! \file
13 //! This header includes core utilities from <tt><boost/move/utility_core.hpp></tt> and defines
14 //! some more advanced utilities such as:
13 15
14 #ifndef BOOST_MOVE_MOVE_UTILITY_HPP 16 #ifndef BOOST_MOVE_MOVE_UTILITY_HPP
15 #define BOOST_MOVE_MOVE_UTILITY_HPP 17 #define BOOST_MOVE_MOVE_UTILITY_HPP
16 18
19 #ifndef BOOST_CONFIG_HPP
20 # include <boost/config.hpp>
21 #endif
22 #
23 #if defined(BOOST_HAS_PRAGMA_ONCE)
24 # pragma once
25 #endif
26
17 #include <boost/move/detail/config_begin.hpp> 27 #include <boost/move/detail/config_begin.hpp>
18 #include <boost/move/core.hpp> 28 #include <boost/move/utility_core.hpp>
19 #include <boost/move/detail/meta_utils.hpp> 29 #include <boost/move/traits.hpp>
20 30
21 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED) 31 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_MOVE_DOXYGEN_INVOKED)
22 32
23 namespace boost { 33 namespace boost {
24 34
25 template<class T>
26 struct enable_move_utility_emulation
27 {
28 static const bool value = true;
29 };
30
31 ////////////////////////////////////////////////////////////////////////////// 35 //////////////////////////////////////////////////////////////////////////////
32 // 36 //
33 // move() 37 // move_if_noexcept()
34 // 38 //
35 ////////////////////////////////////////////////////////////////////////////// 39 //////////////////////////////////////////////////////////////////////////////
36 40
37 template <class T> 41 template <class T>
38 inline typename ::boost::move_detail::enable_if_c 42 inline typename ::boost::move_detail::enable_if_c
39 < enable_move_utility_emulation<T>::value && !has_move_emulation_enabled<T>::value, T&>::type 43 < enable_move_utility_emulation<T>::value && !has_move_emulation_enabled<T>::value
40 move(T& x) BOOST_NOEXCEPT 44 , typename ::boost::move_detail::add_const<T>::type &
45 >::type
46 move_if_noexcept(T& x) BOOST_NOEXCEPT
41 { 47 {
42 return x; 48 return x;
43 } 49 }
44 50
45 template <class T> 51 template <class T>
46 inline typename ::boost::move_detail::enable_if_c 52 inline typename ::boost::move_detail::enable_if_c
47 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value, rv<T>&>::type 53 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
48 move(T& x) BOOST_NOEXCEPT 54 && ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, rv<T>&>::type
55 move_if_noexcept(T& x) BOOST_NOEXCEPT
49 { 56 {
50 return *static_cast<rv<T>* >(::boost::move_detail::addressof(x)); 57 return *static_cast<rv<T>* >(::boost::move_detail::addressof(x));
51 } 58 }
52 59
53 template <class T> 60 template <class T>
54 inline typename ::boost::move_detail::enable_if_c 61 inline typename ::boost::move_detail::enable_if_c
55 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value, rv<T>&>::type 62 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
56 move(rv<T>& x) BOOST_NOEXCEPT 63 && ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
64 , rv<T>&
65 >::type
66 move_if_noexcept(rv<T>& x) BOOST_NOEXCEPT
57 { 67 {
58 return x; 68 return x;
59 } 69 }
60 70
61 //////////////////////////////////////////////////////////////////////////////
62 //
63 // forward()
64 //
65 //////////////////////////////////////////////////////////////////////////////
66
67 template <class T> 71 template <class T>
68 inline typename ::boost::move_detail::enable_if_c 72 inline typename ::boost::move_detail::enable_if_c
69 < enable_move_utility_emulation<T>::value && ::boost::move_detail::is_rv<T>::value, T &>::type 73 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
70 forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT 74 && !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
75 , typename ::boost::move_detail::add_const<T>::type &
76 >::type
77 move_if_noexcept(T& x) BOOST_NOEXCEPT
71 { 78 {
72 return const_cast<T&>(x); 79 return x;
73 } 80 }
74 81
75 template <class T> 82 template <class T>
76 inline typename ::boost::move_detail::enable_if_c 83 inline typename ::boost::move_detail::enable_if_c
77 < enable_move_utility_emulation<T>::value && !::boost::move_detail::is_rv<T>::value, const T &>::type 84 < enable_move_utility_emulation<T>::value && has_move_emulation_enabled<T>::value
78 forward(const typename ::boost::move_detail::identity<T>::type &x) BOOST_NOEXCEPT 85 && !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value
86 , typename ::boost::move_detail::add_const<T>::type &
87 >::type
88 move_if_noexcept(rv<T>& x) BOOST_NOEXCEPT
79 { 89 {
80 return x; 90 return x;
81 } 91 }
82 92
83 } //namespace boost 93 } //namespace boost
87 #if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) 97 #if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
88 #include <utility> 98 #include <utility>
89 99
90 namespace boost{ 100 namespace boost{
91 101
92 using ::std::move; 102 using ::std::move_if_noexcept;
93 using ::std::forward;
94 103
95 } //namespace boost 104 } //namespace boost
96 105
97 #else //!BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE 106 #else //!BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE
98 107
99 #include <boost/type_traits/remove_reference.hpp>
100
101 namespace boost { 108 namespace boost {
102
103 //! This trait's internal boolean `value` is false in compilers with rvalue references
104 //! and true in compilers without rvalue references.
105 //!
106 //! A user can specialize this trait for a type T to false to SFINAE out `move` and `forward`
107 //! so that the user can define a different move emulation for that type in namespace boost
108 //! (e.g. another Boost library for its types) and avoid any overload ambiguity.
109 template<class T>
110 struct enable_move_utility_emulation
111 {
112 static const bool value = false;
113 };
114 109
115 ////////////////////////////////////////////////////////////////////////////// 110 //////////////////////////////////////////////////////////////////////////////
116 // 111 //
117 // move 112 // move_if_noexcept()
118 // 113 //
119 ////////////////////////////////////////////////////////////////////////////// 114 //////////////////////////////////////////////////////////////////////////////
120
121 #if defined(BOOST_MOVE_DOXYGEN_INVOKED) 115 #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
122 //! This function provides a way to convert a reference into a rvalue reference 116 //! This function provides a way to convert a reference into a rvalue reference
123 //! in compilers with rvalue references. For other compilers converts T & into 117 //! in compilers with rvalue references. For other compilers converts T & into
124 //! <i>::boost::rv<T> &</i> so that move emulation is activated. 118 //! <i>::boost::rv<T> &</i> so that move emulation is activated. Reference
119 //! would be converted to rvalue reference only if input type is nothrow move
120 //! constructible or if it has no copy constructor. In all other cases const
121 //! reference would be returned
125 template <class T> 122 template <class T>
126 rvalue_reference move(input_reference) noexcept; 123 rvalue_reference_or_const_lvalue_reference move_if_noexcept(input_reference) noexcept;
127 124
128 #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES) 125 #else //BOOST_MOVE_DOXYGEN_INVOKED
129
130 //Old move approach, lvalues could bind to rvalue references
131 template <class T>
132 inline typename remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT
133 { return t; }
134
135 #else //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES
136 126
137 template <class T> 127 template <class T>
138 inline typename remove_reference<T>::type && move(T&& t) BOOST_NOEXCEPT 128 typename ::boost::move_detail::enable_if_c
139 { return static_cast<typename remove_reference<T>::type &&>(t); } 129 < ::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, T&&>::type
140 130 move_if_noexcept(T& x) BOOST_NOEXCEPT
141 #endif //BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES 131 { return ::boost::move(x); }
142
143 //////////////////////////////////////////////////////////////////////////////
144 //
145 // forward
146 //
147 //////////////////////////////////////////////////////////////////////////////
148
149
150 #if defined(BOOST_MOVE_DOXYGEN_INVOKED)
151 //! This function provides limited form of forwarding that is usually enough for
152 //! in-place construction and avoids the exponential overloading for
153 //! achieve the limited forwarding in C++03.
154 //!
155 //! For compilers with rvalue references this function provides perfect forwarding.
156 //!
157 //! Otherwise:
158 //! * If input_reference binds to const ::boost::rv<T> & then it output_reference is
159 //! ::boost::rv<T> &
160 //!
161 //! * Else, output_reference is equal to input_reference.
162 template <class T> output_reference forward(input_reference) noexcept;
163 #elif defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
164
165 //Old move approach, lvalues could bind to rvalue references
166 132
167 template <class T> 133 template <class T>
168 inline T&& forward(typename ::boost::move_detail::identity<T>::type&& t) BOOST_NOEXCEPT 134 typename ::boost::move_detail::enable_if_c
169 { return t; } 135 < !::boost::move_detail::is_nothrow_move_constructible_or_uncopyable<T>::value, const T&>::type
136 move_if_noexcept(T& x) BOOST_NOEXCEPT
137 { return x; }
170 138
171 #else //Old move 139 #endif //BOOST_MOVE_DOXYGEN_INVOKED
172
173 //Implementation #5 from N2951, thanks to Howard Hinnant
174
175 template <class T, class U>
176 inline T&& forward(U&& t
177 , typename ::boost::move_detail::enable_if_c<
178 move_detail::is_lvalue_reference<T>::value ? move_detail::is_lvalue_reference<U>::value : true>::type * = 0/*
179 , typename ::boost::move_detail::enable_if_c<
180 move_detail::is_convertible
181 <typename remove_reference<U>::type*, typename remove_reference<T>::type*>::value>::type * = 0*/) BOOST_NOEXCEPT
182 { return static_cast<T&&>(t); }
183
184 #endif //BOOST_MOVE_DOXYGEN_INVOKED
185 140
186 } //namespace boost { 141 } //namespace boost {
187 142
188 #endif //#if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE) 143 #endif //#if defined(BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE)
189 144