Phi
is_nothrow_swappable_with.hpp
1 #ifndef INCG_PHI_CORE_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP
2 #define INCG_PHI_CORE_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP
3 
4 #include "phi/phi_config.hpp"
5 
6 #if PHI_HAS_EXTENSION_PRAGMA_ONCE()
7 # pragma once
8 #endif
9 
10 #include "phi/algorithm/swap.hpp"
11 #include "phi/compiler_support/constexpr.hpp"
12 #include "phi/compiler_support/inline_variables.hpp"
13 #include "phi/compiler_support/noexcept.hpp"
14 #include "phi/compiler_support/warning.hpp"
15 #include "phi/core/declval.hpp"
16 #include "phi/type_traits/integral_constant.hpp"
17 #include "phi/type_traits/is_swappable_with.hpp"
18 
19 DETAIL_PHI_BEGIN_NAMESPACE()
20 
21 PHI_GCC_SUPPRESS_WARNING_PUSH()
22 PHI_GCC_SUPPRESS_WARNING("-Wnoexcept")
23 
24 namespace detail
25 {
26  template <typename TypeT, typename OtherT = TypeT,
27  bool IsSwappable = is_swappable_with<TypeT, OtherT>::value>
29  {
30  static PHI_CONSTEXPR_AND_CONST bool value =
31  PHI_NOEXCEPT_EXPR(swap(declval<TypeT>(), declval<OtherT>())) &&
32  PHI_NOEXCEPT_EXPR(swap(declval<OtherT>(), declval<TypeT>()));
33  };
34 
35  template <typename TypeT, typename OtherT>
36  struct is_nothrow_swappable_with_impl<TypeT, OtherT, false> : public false_type
37  {};
38 } // namespace detail
39 
40 template <typename TypeT, typename OtherT>
42  : public integral_constant<bool, detail::is_nothrow_swappable_with_impl<TypeT, OtherT>::value>
43 {};
44 
45 template <typename TypeT, typename OtherT>
47  : public integral_constant<bool, !is_nothrow_swappable_with<TypeT, OtherT>::value>
48 {};
49 
50 PHI_GCC_SUPPRESS_WARNING_POP()
51 
52 #if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
53 
54 template <typename TypeT, typename OtherT>
55 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_nothrow_swappable_with_v =
57 
58 template <typename TypeT, typename OtherT>
59 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_nothrow_swappable_with_v =
61 
62 #endif
63 
64 DETAIL_PHI_END_NAMESPACE()
65 
66 #endif // INCG_PHI_CORE_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_WITH_HPP
Definition: integral_constant.hpp:19
Definition: is_nothrow_swappable_with.hpp:46
Definition: is_nothrow_swappable_with.hpp:28
Definition: swap.hpp:23
Definition: is_swappable_with.hpp:41
Definition: is_nothrow_swappable_with.hpp:41