2 * Copyright 2017 Jacob Lifshay
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 #ifndef UTIL_IS_SWAPPABLE_H_
25 #define UTIL_IS_SWAPPABLE_H_
28 #include <type_traits>
29 #include "is_referenceable.h"
31 namespace vulkan_cpu_util_is_swappable_unrelated_namespace
34 template <typename T
, typename U
, bool Is_Void
= std::is_void
<T
>::value
|| std::is_void
<T
>::value
>
35 class Is_swappable_with
40 typename
= decltype(swap(std::declval
<L
>(), std::declval
<R
>()))>
42 template <typename L
, typename R
>
46 static constexpr bool value
=
47 std::is_void
<decltype(fn
<T
, U
>(0))>::value
&& std::is_void
<decltype(fn
<U
, T
>(0))>::value
;
50 template <typename T
, typename U
>
51 class Is_swappable_with
<T
, U
, true>
54 static constexpr bool value
= false;
57 template <typename T
, typename U
, bool Is_Swappable_With
= Is_swappable_with
<T
, U
>::value
>
58 struct Is_nothrow_swappable_with
60 static constexpr bool value
= noexcept(swap(std::declval
<T
>(), std::declval
<U
>()))
61 && noexcept(swap(std::declval
<U
>(), std::declval
<T
>()));
64 template <typename T
, typename U
>
65 struct Is_nothrow_swappable_with
<T
, U
, false>
67 static constexpr bool value
= false;
75 template <typename T
, typename U
>
76 struct is_swappable_with
77 : public std::integral_constant
<bool,
78 vulkan_cpu_util_is_swappable_unrelated_namespace::
79 Is_swappable_with
<T
, U
>::value
>
83 template <typename T
, typename U
>
84 constexpr bool is_swappable_with_v
= is_swappable_with
<T
, U
>::value
;
86 template <typename T
, typename U
>
87 struct is_nothrow_swappable_with
88 : public std::integral_constant
<bool,
89 vulkan_cpu_util_is_swappable_unrelated_namespace::
90 Is_nothrow_swappable_with
<T
, U
>::value
>
94 template <typename T
, typename U
>
95 constexpr bool is_nothrow_swappable_with_v
= is_nothrow_swappable_with
<T
, U
>::value
;
99 template <typename T
, bool Is_Referenceable
= is_referenceable
<T
>::value
>
100 struct is_swappable_helper
102 static constexpr bool value
= is_swappable_with
<T
&, T
&>::value
;
105 template <typename T
>
106 struct is_swappable_helper
<T
, false>
108 static constexpr bool value
= false;
111 template <typename T
, bool Is_Referenceable
= is_referenceable
<T
>::value
>
112 struct is_nothrow_swappable_helper
114 static constexpr bool value
= is_nothrow_swappable_with
<T
&, T
&>::value
;
117 template <typename T
>
118 struct is_nothrow_swappable_helper
<T
, false>
120 static constexpr bool value
= false;
124 template <typename T
>
125 struct is_swappable
: public std::integral_constant
<bool, detail::is_swappable_helper
<T
>::value
>
129 template <typename T
>
130 constexpr bool is_swappable_v
= is_swappable
<T
>::value
;
132 template <typename T
>
133 struct is_nothrow_swappable
134 : public std::integral_constant
<bool, detail::is_nothrow_swappable_helper
<T
>::value
>
138 template <typename T
>
139 constexpr bool is_nothrow_swappable_v
= is_nothrow_swappable
<T
>::value
;
143 #endif /* UTIL_IS_SWAPPABLE_H_ */