29 #ifndef _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST
30 #define _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST 1
32 #pragma GCC system_header
34 #if __cplusplus <= 201103L
44 namespace std _GLIBCXX_VISIBILITY(default)
46 namespace experimental
48 inline namespace fundamentals_v2
50 _GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template <
typename _Tp>
68 typedef remove_reference_t<decltype(*std::declval<_Tp&>())> element_type;
71 template <
typename _Up>
75 template <
typename _Up>
76 struct __is_propagate_const<propagate_const<_Up>> :
true_type
79 template <
typename _Up>
80 friend constexpr
const _Up&
82 template <
typename _Up>
86 template <
typename _Up>
87 static constexpr element_type*
88 __to_raw_pointer(_Up* __u)
91 template <
typename _Up>
92 static constexpr element_type*
93 __to_raw_pointer(_Up& __u)
96 template <
typename _Up>
97 static constexpr
const element_type*
98 __to_raw_pointer(
const _Up* __u)
101 template <
typename _Up>
102 static constexpr
const element_type*
103 __to_raw_pointer(
const _Up& __u)
104 {
return __u.get(); }
107 static_assert(__and_<
is_object<
typename remove_pointer<_Tp>::type>,
110 "propagate_const requires a class or a pointer to an"
114 constexpr propagate_const() =
default;
115 propagate_const(
const propagate_const& __p) =
delete;
116 constexpr propagate_const(propagate_const&& __p) =
default;
117 template <
typename _Up,
typename
118 enable_if<__and_<is_constructible<_Tp, _Up&&>,
119 is_convertible<_Up&&, _Tp>>::value,
bool
122 : _M_t(std::move(get_underlying(__pu)))
124 template <
typename _Up,
typename
125 enable_if<__and_<is_constructible<_Tp, _Up&&>,
126 __not_<is_convertible<_Up&&, _Tp>>>::value,
129 : _M_t(std::move(get_underlying(__pu)))
131 template <
typename _Up,
typename
132 enable_if<__and_<is_constructible<_Tp, _Up&&>,
133 is_convertible<_Up&&, _Tp>,
134 __not_<__is_propagate_const<
135 typename decay<_Up>::type>>
136 >::value,
bool>::type=
true>
137 constexpr propagate_const(_Up&& __u)
138 : _M_t(std::forward<_Up>(__u))
140 template <
typename _Up,
typename
141 enable_if<__and_<is_constructible<_Tp, _Up&&>,
142 __not_<is_convertible<_Up&&, _Tp>>,
143 __not_<__is_propagate_const<
144 typename decay<_Up>::type>>
145 >::value,
bool>::type=
false>
146 constexpr
explicit propagate_const(_Up&& __u)
147 : _M_t(std::forward<_Up>(__u))
151 propagate_const& operator=(
const propagate_const& __p) =
delete;
152 constexpr propagate_const& operator=(propagate_const&& __p) =
default;
154 template <
typename _Up,
typename =
155 typename enable_if<is_convertible<_Up&&, _Tp>::value>::type>
158 _M_t = std::move(get_underlying(__pu));
162 template <
typename _Up,
typename =
163 typename enable_if<__and_<is_convertible<_Up&&, _Tp>,
164 __not_<__is_propagate_const<
165 typename decay<_Up>::type>>
167 constexpr propagate_const& operator=(_Up&& __u)
169 _M_t = std::forward<_Up>(__u);
174 explicit constexpr
operator bool()
const
179 constexpr
const element_type* operator->()
const
184 template <
typename _Up = _Tp,
185 typename enable_if<__or_<is_pointer<_Up>,
188 >::value,
bool>::type =
true>
189 constexpr
operator const element_type*()
const
194 constexpr
const element_type& operator*()
const
199 constexpr
const element_type*
get()
const
201 return __to_raw_pointer(_M_t);
205 constexpr element_type* operator->()
210 template <
typename _Up = _Tp,
211 typename enable_if<__or_<is_pointer<_Up>,
214 >::value,
bool>::type =
true>
215 constexpr
operator element_type*()
220 constexpr element_type& operator*()
225 constexpr element_type*
get()
227 return __to_raw_pointer(_M_t);
232 swap(propagate_const& __pt) noexcept(__is_nothrow_swappable<_Tp>::value)
235 swap(_M_t, get_underlying(__pt));
243 template <
typename _Tp>
247 return get_underlying(__pt) ==
nullptr;
250 template <
typename _Tp>
252 operator==(nullptr_t,
const propagate_const<_Tp>& __pu)
254 return nullptr == get_underlying(__pu);
257 template <
typename _Tp>
259 operator!=(
const propagate_const<_Tp>& __pt, nullptr_t)
261 return get_underlying(__pt) !=
nullptr;
264 template <
typename _Tp>
265 constexpr
bool operator!=(nullptr_t,
const propagate_const<_Tp>& __pu)
267 return nullptr != get_underlying(__pu);
270 template <
typename _Tp,
typename _Up>
272 operator==(
const propagate_const<_Tp>& __pt,
273 const propagate_const<_Up>& __pu)
275 return get_underlying(__pt) == get_underlying(__pu);
278 template <
typename _Tp,
typename _Up>
280 operator!=(
const propagate_const<_Tp>& __pt,
281 const propagate_const<_Up>& __pu)
283 return get_underlying(__pt) != get_underlying(__pu);
286 template <
typename _Tp,
typename _Up>
288 operator<(const propagate_const<_Tp>& __pt,
289 const propagate_const<_Up>& __pu)
291 return get_underlying(__pt) < get_underlying(__pu);
294 template <
typename _Tp,
typename _Up>
296 operator>(
const propagate_const<_Tp>& __pt,
297 const propagate_const<_Up>& __pu)
299 return get_underlying(__pt) > get_underlying(__pu);
302 template <
typename _Tp,
typename _Up>
304 operator<=(const propagate_const<_Tp>& __pt,
305 const propagate_const<_Up>& __pu)
307 return get_underlying(__pt) <= get_underlying(__pu);
310 template <
typename _Tp,
typename _Up>
312 operator>=(
const propagate_const<_Tp>& __pt,
313 const propagate_const<_Up>& __pu)
315 return get_underlying(__pt) >= get_underlying(__pu);
318 template <
typename _Tp,
typename _Up>
320 operator==(
const propagate_const<_Tp>& __pt,
const _Up& __u)
322 return get_underlying(__pt) == __u;
325 template <
typename _Tp,
typename _Up>
327 operator!=(
const propagate_const<_Tp>& __pt,
const _Up& __u)
329 return get_underlying(__pt) != __u;
332 template <
typename _Tp,
typename _Up>
334 operator<(const propagate_const<_Tp>& __pt,
const _Up& __u)
336 return get_underlying(__pt) < __u;
339 template <
typename _Tp,
typename _Up>
341 operator>(
const propagate_const<_Tp>& __pt,
const _Up& __u)
343 return get_underlying(__pt) > __u;
346 template <
typename _Tp,
typename _Up>
348 operator<=(const propagate_const<_Tp>& __pt,
const _Up& __u)
350 return get_underlying(__pt) <= __u;
353 template <
typename _Tp,
typename _Up>
355 operator>=(
const propagate_const<_Tp>& __pt,
const _Up& __u)
357 return get_underlying(__pt) >= __u;
360 template <
typename _Tp,
typename _Up>
362 operator==(
const _Tp& __t,
const propagate_const<_Up>& __pu)
364 return __t == get_underlying(__pu);
367 template <
typename _Tp,
typename _Up>
369 operator!=(
const _Tp& __t,
const propagate_const<_Up>& __pu)
371 return __t != get_underlying(__pu);
374 template <
typename _Tp,
typename _Up>
376 operator<(const _Tp& __t, const propagate_const<_Up>& __pu)
378 return __t < get_underlying(__pu);
381 template <
typename _Tp,
typename _Up>
383 operator>(
const _Tp& __t,
const propagate_const<_Up>& __pu)
385 return __t > get_underlying(__pu);
388 template <
typename _Tp,
typename _Up>
390 operator<=(const _Tp& __t, const propagate_const<_Up>& __pu)
392 return __t <= get_underlying(__pu);
395 template <
typename _Tp,
typename _Up>
397 operator>=(
const _Tp& __t,
const propagate_const<_Up>& __pu)
399 return __t >= get_underlying(__pu);
403 template <
typename _Tp>
405 swap(propagate_const<_Tp>& __pt, propagate_const<_Tp>& __pt2)
406 noexcept(__is_nothrow_swappable<_Tp>::value)
412 template <
typename _Tp>
414 get_underlying(
const propagate_const<_Tp>& __pt) noexcept
419 template <
typename _Tp>
421 get_underlying(propagate_const<_Tp>& __pt) noexcept
427 _GLIBCXX_END_NAMESPACE_VERSION
432 template <
typename _Tp>
433 struct hash<experimental::propagate_const<_Tp>>
435 using result_type = size_t;
436 using argument_type = experimental::propagate_const<_Tp>;
439 operator()(
const experimental::propagate_const<_Tp>& __t)
const
440 noexcept(noexcept(hash<_Tp>{}(get_underlying(__t))))
442 return hash<_Tp>{}(get_underlying(__t));
447 template <
typename _Tp>
448 struct equal_to<experimental::propagate_const<_Tp>>
451 operator()(
const experimental::propagate_const<_Tp>& __x,
452 const experimental::propagate_const<_Tp>& __y)
const
454 return equal_to<_Tp>{}(get_underlying(__x), get_underlying(__y));
462 template <
typename _Tp>
463 struct not_equal_to<experimental::propagate_const<_Tp>>
466 operator()(
const experimental::propagate_const<_Tp>& __x,
467 const experimental::propagate_const<_Tp>& __y)
const
469 return not_equal_to<_Tp>{}(get_underlying(__x), get_underlying(__y));
477 template <
typename _Tp>
478 struct less<experimental::propagate_const<_Tp>>
481 operator()(
const experimental::propagate_const<_Tp>& __x,
482 const experimental::propagate_const<_Tp>& __y)
const
484 return less<_Tp>{}(get_underlying(__x), get_underlying(__y));
492 template <
typename _Tp>
493 struct greater<experimental::propagate_const<_Tp>>
496 operator()(
const experimental::propagate_const<_Tp>& __x,
497 const experimental::propagate_const<_Tp>& __y)
const
499 return greater<_Tp>{}(get_underlying(__x), get_underlying(__y));
507 template <
typename _Tp>
508 struct less_equal<experimental::propagate_const<_Tp>>
511 operator()(
const experimental::propagate_const<_Tp>& __x,
512 const experimental::propagate_const<_Tp>& __y)
const
514 return less_equal<_Tp>{}(get_underlying(__x), get_underlying(__y));
522 template <
typename _Tp>
523 struct greater_equal<experimental::propagate_const<_Tp>>
526 operator()(
const experimental::propagate_const<_Tp>& __x,
527 const experimental::propagate_const<_Tp>& __y)
const
529 return greater_equal<_Tp>{}(get_underlying(__x), get_underlying(__y));
540 #endif // _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST
_Tp second_argument_type
second_argument_type is the type of the second argument
bool result_type
result_type is the return type
Const-propagating wrapper.
_Tp first_argument_type
first_argument_type is the type of the first argument