Phi
is_default_constructible.hpp
1 #ifndef INCG_PHI_CORE_TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_HPP
2 #define INCG_PHI_CORE_TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_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_constructible.hpp"
13 #include "phi/type_traits/integral_constant.hpp"
14 
15 #if PHI_SUPPORTS_IS_CONSTRUCTIBLE()
16 
17 # include "phi/compiler_support/warning.hpp"
18 
19 # define PHI_HAS_WORKING_IS_DEFAULT_CONSTRUCTIBLE() 1
20 
21 DETAIL_PHI_BEGIN_NAMESPACE()
22 
23 PHI_GCC_SUPPRESS_WARNING_PUSH()
24 PHI_GCC_SUPPRESS_WARNING("-Wignored-qualifiers")
25 
26 template <typename TypeT>
27 struct is_default_constructible : public integral_constant<bool, PHI_IS_CONSTRUCTIBLE(TypeT)>
28 {};
29 
30 template <typename TypeT>
31 struct is_not_default_constructible : public integral_constant<bool, !PHI_IS_CONSTRUCTIBLE(TypeT)>
32 {};
33 
34 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
35 
36 template <typename TypeT>
37 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_default_constructible_v = PHI_IS_CONSTRUCTIBLE(TypeT);
38 
39 template <typename TypeT>
40 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_default_constructible_v =
41  !PHI_IS_CONSTRUCTIBLE(TypeT);
42 
43 # endif
44 
45 PHI_GCC_SUPPRESS_WARNING_POP()
46 
47 DETAIL_PHI_END_NAMESPACE()
48 
49 #else
50 
51 # include "phi/core/size_t.hpp"
52 # include "phi/forward/std/pair.hpp"
53 # include "phi/type_traits/detail/yes_no_type.hpp"
54 # include "phi/type_traits/is_abstract.hpp"
55 # include "phi/type_traits/is_complete.hpp"
56 
57 # if PHI_HAS_WORKING_IS_ABSTRACT()
58 # define PHI_HAS_WORKING_IS_DEFAULT_CONSTRUCTIBLE() 1
59 # else
60 # define PHI_HAS_WORKING_IS_DEFAULT_CONSTRUCTIBLE() 0
61 # endif
62 
63 DETAIL_PHI_BEGIN_NAMESPACE()
64 
65 namespace detail
66 {
68  {
69  template <typename TypeT, typename = decltype(TypeT())>
70  static yes_type test(int);
71 
72  template <typename>
73  static no_type test(...);
74  };
75 
76  template <typename TypeT, bool Boolean>
78  {
79  static PHI_CONSTEXPR_AND_CONST bool value =
80  sizeof(is_default_constructible_imp::test<TypeT>(0)) == detail::sizeof_yes_type;
81  };
82 
83  template <typename TypeT>
85  {
86  static PHI_CONSTEXPR_AND_CONST bool value = false;
87  };
88 } // namespace detail
89 
90 template <typename TypeT>
92  : public integral_constant<bool, detail::is_default_constructible_abstract_filter<
93  TypeT, is_abstract<TypeT>::value>::value>
94 {
95  static_assert(is_complete<TypeT>::value,
96  "Arguments to is_default_constructible must be complete types");
97 };
98 
99 template <typename TypeT, size_t Size>
100 struct is_default_constructible<TypeT[Size]> : public is_default_constructible<TypeT>
101 {};
102 
103 template <typename TypeT>
104 struct is_default_constructible<TypeT[]> : public is_default_constructible<TypeT>
105 {};
106 
107 template <typename TypeT>
108 struct is_default_constructible<TypeT&> : public false_type
109 {};
110 
111 template <typename TypeT, typename OtherT>
112 struct is_default_constructible<std::pair<TypeT, OtherT>>
113  : public integral_constant<bool, is_default_constructible<TypeT>::value &&
114  is_default_constructible<OtherT>::value>
115 {};
116 
117 template <typename TypeT>
118 struct is_default_constructible<TypeT&&> : public false_type
119 {};
120 
121 template <>
123 {};
124 
125 template <>
126 struct is_default_constructible<void const> : public false_type
127 {};
128 
129 template <>
130 struct is_default_constructible<void volatile> : public false_type
131 {};
132 
133 template <>
134 struct is_default_constructible<void const volatile> : public false_type
135 {};
136 
137 template <typename TypeT>
139  : public integral_constant<bool, !is_default_constructible<TypeT>::value>
140 {};
141 
142 # if PHI_HAS_FEATURE_VARIABLE_TEMPLATE()
143 
144 template <typename TypeT>
145 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_default_constructible_v =
147 
148 template <typename TypeT>
149 PHI_INLINE_VARIABLE PHI_CONSTEXPR bool is_not_default_constructible_v =
151 
152 # endif
153 
154 DETAIL_PHI_END_NAMESPACE()
155 
156 #endif
157 
158 #endif // INCG_PHI_CORE_TYPE_TRAITS_IS_DEFAULT_CONSTRUCTIBLE_HPP
Definition: integral_constant.hpp:19
Definition: is_default_constructible.hpp:138
Definition: is_default_constructible.hpp:91
Definition: test_macros.hpp:18
Definition: yes_no_type.hpp:32
Definition: pair.hpp:35
Definition: initializer_list.hpp:21
Definition: is_default_constructible.hpp:77
Definition: is_complete.hpp:71
Definition: is_default_constructible.hpp:67
Definition: swap.hpp:23
Definition: yes_no_type.hpp:23