libstdc++: move.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#ifndef _MOVE_H
31#define _MOVE_H 1
32
34#if __cplusplus < 201103L
36#else
37# include <type_traits>
38#endif
39
40namespace std _GLIBCXX_VISIBILITY(default)
41{
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
43
44
45
46
47
48
49 template<typename _Tp>
50 inline _GLIBCXX_CONSTEXPR _Tp*
52 { return __builtin_addressof(__r); }
53
54#if __cplusplus >= 201103L
55
56
57
58
59
60
61
62
63
64
65
66
67 template<typename _Tp>
68 _GLIBCXX_NODISCARD
69 constexpr _Tp&&
70 forward(typename std::remove_reference<_Tp>::type& __t) noexcept
71 { return static_cast<_Tp&&>(__t); }
72
73
74
75
76
77
78
79 template<typename _Tp>
80 _GLIBCXX_NODISCARD
81 constexpr _Tp&&
82 forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
83 {
85 "std::forward must not be used to convert an rvalue to an lvalue");
86 return static_cast<_Tp&&>(__t);
87 }
88
89#if __glibcxx_forward_like
90 template<typename _Tp, typename _Up>
91 struct __like_impl;
92
93 template<typename _Tp, typename _Up>
94 struct __like_impl<_Tp&, _Up&>
95 { using type = _Up&; };
96
97 template<typename _Tp, typename _Up>
98 struct __like_impl<const _Tp&, _Up&>
99 { using type = const _Up&; };
100
101 template<typename _Tp, typename _Up>
102 struct __like_impl<_Tp&&, _Up&>
103 { using type = _Up&&; };
104
105 template<typename _Tp, typename _Up>
106 struct __like_impl<const _Tp&&, _Up&>
107 { using type = const _Up&&; };
108
109 template<typename _Tp, typename _Up>
110 using __like_t = typename __like_impl<_Tp&&, _Up&>::type;
111
112 template<typename _Tp, typename _Up>
113 [[nodiscard]]
114 constexpr __like_t<_Tp, _Up>
115 forward_like(_Up&& __x) noexcept
116 { return static_cast<__like_t<_Tp, _Up>>(__x); }
117#endif
118
119
120
121
122
123
124 template<typename _Tp>
125 _GLIBCXX_NODISCARD
126 constexpr typename std::remove_reference<_Tp>::type&&
128 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
129
130
131 template<typename _Tp>
132 struct __move_if_noexcept_cond
133 : public __and_<__not_<is_nothrow_move_constructible<_Tp>>,
134 is_copy_constructible<_Tp>>::type { };
135
136
137
138
139
140
141
142
143
144 template<typename _Tp>
145 _GLIBCXX_NODISCARD
146 constexpr
147 __conditional_t<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>
150
151
152
153
154
155
156
157
158
159
160 template<typename _Tp>
161 _GLIBCXX_NODISCARD
162 inline _GLIBCXX17_CONSTEXPR _Tp*
165
166
167
168 template<typename _Tp>
169 const _Tp* addressof(const _Tp&&) = delete;
170
171
172 template <typename _Tp, typename _Up = _Tp>
173 _GLIBCXX20_CONSTEXPR
174 inline _Tp
175 __exchange(_Tp& __obj, _Up&& __new_val)
176 {
177 _Tp __old_val = std::move(__obj);
178 __obj = std::forward<_Up>(__new_val);
179 return __old_val;
180 }
181
182
183
184#define _GLIBCXX_FWDREF(_Tp) _Tp&&
185#define _GLIBCXX_MOVE(__val) std::move(__val)
186#define _GLIBCXX_FORWARD(_Tp, __val) std::forward<_Tp>(__val)
187#else
188#define _GLIBCXX_FWDREF(_Tp) const _Tp&
189#define _GLIBCXX_MOVE(__val) (__val)
190#define _GLIBCXX_FORWARD(_Tp, __val) (__val)
191#endif
192
193
194
195
196
197
198
199
200
201
202
203
204 template<typename _Tp>
205 _GLIBCXX20_CONSTEXPR
206 inline
207#if __cplusplus >= 201103L
208 typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>,
209 is_move_constructible<_Tp>,
210 is_move_assignable<_Tp>>::value>::type
211#else
212 void
213#endif
214 swap(_Tp& __a, _Tp& __b)
217 {
218#if __cplusplus < 201103L
219
220 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
221#endif
222 _Tp __tmp = _GLIBCXX_MOVE(__a);
223 __a = _GLIBCXX_MOVE(__b);
224 __b = _GLIBCXX_MOVE(__tmp);
225 }
226
227
228
229
230 template<typename _Tp, size_t _Nm>
231 _GLIBCXX20_CONSTEXPR
232 inline
233#if __cplusplus >= 201103L
234 typename enable_if<__is_swappable<_Tp>::value>::type
235#else
236 void
237#endif
238 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
239 _GLIBCXX_NOEXCEPT_IF(__is_nothrow_swappable<_Tp>::value)
240 {
241 for (size_t __n = 0; __n < _Nm; ++__n)
242 swap(__a[__n], __b[__n]);
243 }
244
245
246_GLIBCXX_END_NAMESPACE_VERSION
247}
248
249#endif
constexpr __conditional_t< __move_if_noexcept_cond< _Tp >::value, const _Tp &, _Tp && > move_if_noexcept(_Tp &__x) noexcept
Conditionally convert a value to an rvalue.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
is_nothrow_move_constructible
is_nothrow_move_assignable