Phi
is_destructible.hpp
1 #ifndef INCG_PHI_CORE_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
2 #define INCG_PHI_CORE_TYPE_TRAITS_IS_DESTRUCTIBLE_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/compiler_support/constexpr.hpp"
11 #include "phi/compiler_support/inline_variables.hpp"
12 #include "phi/compiler_support/intrinsics/is_destructible.hpp"
13 #include "phi/type_traits/integral_constant.hpp"
14 
15 #if PHI_SUPPORTS_IS_DESTRUCTIBLE()
16 
17 DETAIL_PHI_BEGIN_NAMESPACE()
18 
19 template <typename TypeT>
20 struct is_destructible : public integral_constant<bool, PHI_IS_DESTRUCTIBLE(TypeT)>
21 {};
22 
23 template <typename TypeT>
24 struct is_not_destructible : public integral_constant<bool, !PHI_IS_DESTRUCTIBLE(TypeT)>
25 {};
26 
27 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
28 
29 template <typename TypeT>
30 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_destructible_v = PHI_IS_DESTRUCTIBLE(TypeT);
31 
32 template <typename TypeT>
33 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_destructible_v = !PHI_IS_DESTRUCTIBLE(TypeT);
34 
35 # endif
36 
37 #else
38 
39 # include "phi/core/declval.hpp"
40 # include "phi/type_traits/detail/yes_no_type.hpp"
41 # include "phi/type_traits/is_function.hpp"
42 # include "phi/type_traits/is_reference.hpp"
43 # include "phi/type_traits/remove_all_extents.hpp"
44 
45 DETAIL_PHI_BEGIN_NAMESPACE()
46 
47 namespace detail
48 {
49  template <typename>
51  {
52  using type = int;
53  };
54 
55  template <typename TypeT>
57  {
58  template <typename Type1T>
59  static yes_type test(
60  typename is_destructible_apply<decltype(declval<Type1T&>().~Type1T())>::type);
61 
62  template <typename Type1T>
63  static no_type test(...);
64 
65  // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
66  static PHI_CONSTEXPR_AND_CONST bool value = sizeof(test<TypeT>(12)) == sizeof_yes_type;
67  };
68 
69  template <typename TypeT, bool>
71 
72  template <typename TypeT>
73  struct destructible_impl<TypeT, false>
74  : public integral_constant<
75  bool, is_destructor_wellformed<typename remove_all_extents<TypeT>::type>::value>
76  {};
77 
78  template <typename TypeT>
79  struct destructible_impl<TypeT, true> : public true_type
80  {};
81 
82  template <typename TypeT, bool>
84 
85  template <typename TypeT>
86  struct destructible_false<TypeT, false>
87  : public destructible_impl<TypeT, is_reference<TypeT>::value>
88  {};
89 
90  template <typename TypeT>
91  struct destructible_false<TypeT, true> : public false_type
92  {};
93 } // namespace detail
94 
95 template <typename TypeT>
96 struct is_destructible : public detail::destructible_false<TypeT, is_function<TypeT>::value>
97 {};
98 
99 template <typename TypeT>
100 struct is_destructible<TypeT[]> : public false_type
101 {};
102 
103 template <>
104 struct is_destructible<void> : public false_type
105 {};
106 
107 template <typename TypeT>
108 struct is_not_destructible : public integral_constant<bool, !is_destructible<TypeT>::value>
109 {};
110 
111 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
112 
113 template <typename TypeT>
114 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_destructible_v = is_destructible<TypeT>::value;
115 
116 template <typename TypeT>
117 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_destructible_v = is_not_destructible<TypeT>::value;
118 
119 # endif
120 
121 #endif
122 
123 DETAIL_PHI_END_NAMESPACE()
124 
125 #endif // INCG_PHI_CORE_TYPE_TRAITS_IS_DESTRUCTIBLE_HPP
Definition: integral_constant.hpp:19
Definition: test_macros.hpp:18
Definition: yes_no_type.hpp:32
Definition: is_destructible.hpp:108
Definition: swap.hpp:23
Definition: is_destructible.hpp:96
Definition: is_destructible.hpp:70
Definition: is_destructible.hpp:56
Definition: yes_no_type.hpp:23
Definition: is_destructible.hpp:50
Definition: is_destructible.hpp:83