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
30template <class _Tp, class _Up, class = void>
31inline const bool __is_swappable_with_v = false;
32
33template <class _Tp>
34inline const bool __is_swappable_v = __is_swappable_with_v<_Tp&, _Tp&>;
35
36template <class _Tp, class _Up, bool = __is_swappable_with_v<_Tp, _Up> >
37inline const bool __is_nothrow_swappable_with_v = false;
38
39template <class _Tp>
40inline const bool __is_nothrow_swappable_v = __is_nothrow_swappable_with_v<_Tp&, _Tp&>;
41
42#ifndef _LIBCPP_CXX03_LANG
43template <class _Tp>
44using __swap_result_t _LIBCPP_NODEBUG =
45 __enable_if_t<is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value>;
46#else
47template <class>
48using __swap_result_t _LIBCPP_NODEBUG = void;
49#endif
50
51template <class _Tp>
52inline _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
55template <class _Tp, size_t _Np, __enable_if_t<__is_swappable_v<_Tp>, int> = 0>
56inline _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
61template <class _Tp, class _Up>
62inline 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
68template <class _Tp, class _Up>
69inline 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
76template <class _Tp, class _Up>
77_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_swappable_with_v = __is_swappable_with_v<_Tp, _Up>;
78
79template <class _Tp, class _Up>
80struct _LIBCPP_NO_SPECIALIZATIONS is_swappable_with : bool_constant<is_swappable_with_v<_Tp, _Up>> {};
81
82template <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
86template <class _Tp>
87struct _LIBCPP_NO_SPECIALIZATIONS is_swappable : bool_constant<is_swappable_v<_Tp>> {};
88
89template <class _Tp, class _Up>
90_LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_swappable_with_v = __is_nothrow_swappable_with_v<_Tp, _Up>;
91
92template <class _Tp, class _Up>
93struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_swappable_with : bool_constant<is_nothrow_swappable_with_v<_Tp, _Up>> {};
94
95template <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
99template <class _Tp>
100struct _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.

source code of libcxx/include/__type_traits/is_swappable.h