Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef _LIBCPP___TYPE_TRAITS_IS_SWAPPABLE_H |
10 | #define _LIBCPP___TYPE_TRAITS_IS_SWAPPABLE_H |
11 | |
12 | #include <__config> |
13 | #include <__cstddef/size_t.h> |
14 | #include <__type_traits/add_lvalue_reference.h> |
15 | #include <__type_traits/enable_if.h> |
16 | #include <__type_traits/integral_constant.h> |
17 | #include <__type_traits/is_assignable.h> |
18 | #include <__type_traits/is_constructible.h> |
19 | #include <__type_traits/is_nothrow_assignable.h> |
20 | #include <__type_traits/is_nothrow_constructible.h> |
21 | #include <__type_traits/void_t.h> |
22 | #include <__utility/declval.h> |
23 | |
24 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
25 | # pragma GCC system_header |
26 | #endif |
27 | |
28 | _LIBCPP_BEGIN_NAMESPACE_STD |
29 | |
30 | template <class _Tp, class _Up, class = void> |
31 | inline const bool __is_swappable_with_v = false; |
32 | |
33 | template <class _Tp> |
34 | inline const bool __is_swappable_v = __is_swappable_with_v<_Tp&, _Tp&>; |
35 | |
36 | template <class _Tp, class _Up, bool = __is_swappable_with_v<_Tp, _Up> > |
37 | inline const bool __is_nothrow_swappable_with_v = false; |
38 | |
39 | template <class _Tp> |
40 | inline const bool __is_nothrow_swappable_v = __is_nothrow_swappable_with_v<_Tp&, _Tp&>; |
41 | |
42 | #ifndef _LIBCPP_CXX03_LANG |
43 | template <class _Tp> |
44 | using __swap_result_t _LIBCPP_NODEBUG = |
45 | __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>; |
46 | #else |
47 | template <class> |
48 | using __swap_result_t _LIBCPP_NODEBUG = void; |
49 | #endif |
50 | |
51 | template <class _Tp> |
52 | inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 __swap_result_t<_Tp> swap(_Tp& __x, _Tp& __y) |
53 | _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value&& is_nothrow_move_assignable<_Tp>::value); |
54 | |
55 | template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> = 0> |
56 | inline _LIBCPP_HIDE_FROM_ABI |
57 | _LIBCPP_CONSTEXPR_SINCE_CXX20 void swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable_v<_Tp>); |
58 | |
59 | // ALL generic swap overloads MUST already have a declaration available at this point. |
60 | |
61 | template <class _Tp, class _Up> |
62 | inline const bool __is_swappable_with_v<_Tp, |
63 | _Up, |
64 | __void_t<decltype(swap(std::declval<_Tp>(), std::declval<_Up>())), |
65 | decltype(swap(std::declval<_Up>(), std::declval<_Tp>()))> > = true; |
66 | |
67 | #ifndef _LIBCPP_CXX03_LANG // C++03 doesn't have noexcept, so things are never nothrow swappable |
68 | template <class _Tp, class _Up> |
69 | inline const bool __is_nothrow_swappable_with_v<_Tp, _Up, true> = |
70 | noexcept(swap(std::declval<_Tp>(), std::declval<_Up>())) && |
71 | noexcept(swap(std::declval<_Up>(), std::declval<_Tp>())); |
72 | #endif |
73 | |
74 | #if _LIBCPP_STD_VER >= 17 |
75 | |
76 | template <class _Tp, class _Up> |
77 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_with_v = __is_swappable_with_v<_Tp, _Up>; |
78 | |
79 | template <class _Tp, class _Up> |
80 | struct _LIBCPP_NO_SPECIALIZATIONS is_swappable_with : bool_constant<is_swappable_with_v<_Tp, _Up>> {}; |
81 | |
82 | template <class _Tp> |
83 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_v = |
84 | is_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>; |
85 | |
86 | template <class _Tp> |
87 | struct _LIBCPP_NO_SPECIALIZATIONS is_swappable : bool_constant<is_swappable_v<_Tp>> {}; |
88 | |
89 | template <class _Tp, class _Up> |
90 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_with_v = __is_nothrow_swappable_with_v<_Tp, _Up>; |
91 | |
92 | template <class _Tp, class _Up> |
93 | struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable_with : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {}; |
94 | |
95 | template <class _Tp> |
96 | _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_v = |
97 | is_nothrow_swappable_with_v<__add_lvalue_reference_t<_Tp>, __add_lvalue_reference_t<_Tp>>; |
98 | |
99 | template <class _Tp> |
100 | struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable : bool_constant<is_nothrow_swappable_v<_Tp>> {}; |
101 | |
102 | #endif // _LIBCPP_STD_VER >= 17 |
103 | |
104 | _LIBCPP_END_NAMESPACE_STD |
105 | |
106 | #endif // _LIBCPP___TYPE_TRAITS_IS_SWAPPABLE_H |
107 |
Warning: This file is not a C or C++ file. It does not have highlighting.