@@ -74,10 +74,10 @@ constexpr bool optional = !expected<T> && optional_impl<T>::value;
74
74
75
75
namespace internal {
76
76
#if __cpp_concepts >= 201907L
77
- template <typename Type>
78
- concept tuple_size = requires (Type tuple) {
79
- std::tuple_size<remove_cvref_t <Type>>::value;
80
- };
77
+ template <typename Type>
78
+ concept tuple_size = requires (Type tuple) {
79
+ std::tuple_size<remove_cvref_t <Type>>::value;
80
+ };
81
81
#else
82
82
template <typename T, typename = void >
83
83
struct tuple_size_impl : std::false_type {};
@@ -91,79 +91,79 @@ template <typename T>
91
91
constexpr bool tuple_size = tuple_size_impl<T>::value;
92
92
#endif
93
93
94
- template <typename Type>
95
- constexpr inline bool is_compatible_v = false ;
96
-
97
- template <typename Type, uint64_t version>
98
- constexpr inline bool is_compatible_v<struct_pack::compatible<Type, version>> =
99
- true ;
100
-
101
- struct UniversalVectorType {
102
- template <typename T>
103
- operator std::vector<T>();
104
- };
94
+ template <typename Type>
95
+ constexpr inline bool is_compatible_v = false ;
105
96
106
- struct UniversalType {
107
- template <typename T>
108
- operator T ();
109
- };
97
+ template <typename Type, uint64_t version>
98
+ constexpr inline bool
99
+ is_compatible_v<struct_pack::compatible<Type, version>> = true ;
110
100
111
- struct UniversalIntegralType {
112
- template <typename T, typename = std:: enable_if_t <std::is_integral_v<T>> >
113
- operator T ();
114
- };
101
+ struct UniversalVectorType {
102
+ template <typename T>
103
+ operator std::vector<T> ();
104
+ };
115
105
116
- struct UniversalNullptrType {
117
- operator std::nullptr_t ();
118
- };
106
+ struct UniversalType {
107
+ template <typename T>
108
+ operator T ();
109
+ };
119
110
120
- struct UniversalOptionalType {
121
- template <typename U , typename = std::enable_if_t <optional<U >>>
122
- operator U ();
123
- };
111
+ struct UniversalIntegralType {
112
+ template <typename T , typename = std::enable_if_t <std::is_integral_v<T >>>
113
+ operator T ();
114
+ };
124
115
125
- struct UniversalCompatibleType {
126
- template <typename U, typename = std::enable_if_t <is_compatible_v<U>>>
127
- operator U ();
128
- };
116
+ struct UniversalNullptrType {
117
+ operator std::nullptr_t ();
118
+ };
129
119
130
- template <typename T, typename construct_param_t , typename = void ,
131
- typename ... Args>
132
- struct is_constructable_impl : std::false_type {};
133
- template <typename T, typename construct_param_t , typename ... Args>
134
- struct is_constructable_impl <
135
- T, construct_param_t ,
136
- std::void_t <decltype (T{{Args{}}..., {construct_param_t {}}})>, Args...>
137
- : std::true_type {};
120
+ struct UniversalOptionalType {
121
+ template <typename U, typename = std::enable_if_t <optional<U>>>
122
+ operator U ();
123
+ };
138
124
139
- template <typename T, typename construct_param_t , typename ... Args>
140
- constexpr bool is_constructable =
141
- is_constructable_impl<T, construct_param_t , void , Args...>::value;
125
+ struct UniversalCompatibleType {
126
+ template <typename U, typename = std::enable_if_t <is_compatible_v<U>>>
127
+ operator U ();
128
+ };
142
129
143
- template <typename T, typename ... Args>
144
- inline constexpr std::size_t members_count_impl () {
145
- if constexpr (is_constructable<T, UniversalVectorType, Args...>) {
146
- return members_count_impl<T, Args..., UniversalVectorType>();
147
- }
148
- else if constexpr (is_constructable<T, UniversalType, Args...>) {
149
- return members_count_impl<T, Args..., UniversalType>();
150
- }
151
- else if constexpr (is_constructable<T, UniversalOptionalType, Args...>) {
152
- return members_count_impl<T, Args..., UniversalOptionalType>();
153
- }
154
- else if constexpr (is_constructable<T, UniversalIntegralType, Args...>) {
155
- return members_count_impl<T, Args..., UniversalIntegralType>();
156
- }
157
- else if constexpr (is_constructable<T, UniversalNullptrType, Args...>) {
158
- return members_count_impl<T, Args..., UniversalNullptrType>();
130
+ template <typename T, typename construct_param_t , typename = void ,
131
+ typename ... Args>
132
+ struct is_constructable_impl : std::false_type {};
133
+ template <typename T, typename construct_param_t , typename ... Args>
134
+ struct is_constructable_impl <
135
+ T, construct_param_t ,
136
+ std::void_t <decltype (T{{Args{}}..., {construct_param_t {}}})>, Args...>
137
+ : std::true_type {};
138
+
139
+ template <typename T, typename construct_param_t , typename ... Args>
140
+ constexpr bool is_constructable =
141
+ is_constructable_impl<T, construct_param_t , void , Args...>::value;
142
+
143
+ template <typename T, typename ... Args>
144
+ inline constexpr std::size_t members_count_impl () {
145
+ if constexpr (is_constructable<T, UniversalVectorType, Args...>) {
146
+ return members_count_impl<T, Args..., UniversalVectorType>();
147
+ }
148
+ else if constexpr (is_constructable<T, UniversalType, Args...>) {
149
+ return members_count_impl<T, Args..., UniversalType>();
150
+ }
151
+ else if constexpr (is_constructable<T, UniversalOptionalType, Args...>) {
152
+ return members_count_impl<T, Args..., UniversalOptionalType>();
153
+ }
154
+ else if constexpr (is_constructable<T, UniversalIntegralType, Args...>) {
155
+ return members_count_impl<T, Args..., UniversalIntegralType>();
156
+ }
157
+ else if constexpr (is_constructable<T, UniversalNullptrType, Args...>) {
158
+ return members_count_impl<T, Args..., UniversalNullptrType>();
159
+ }
160
+ else if constexpr (is_constructable<T, UniversalCompatibleType, Args...>) {
161
+ return members_count_impl<T, Args..., UniversalCompatibleType>();
162
+ }
163
+ else {
164
+ return sizeof ...(Args);
165
+ }
159
166
}
160
- else if constexpr (is_constructable<T, UniversalCompatibleType, Args...>) {
161
- return members_count_impl<T, Args..., UniversalCompatibleType>();
162
- }
163
- else {
164
- return sizeof ...(Args);
165
- }
166
- }
167
167
} // namespace internal
168
168
169
169
template <typename T>
@@ -178,9 +178,12 @@ inline constexpr std::size_t members_count() {
178
178
else if constexpr (internal::tuple_size<type>) {
179
179
return std::tuple_size<type>::value;
180
180
}
181
- else {
181
+ else if constexpr (std::is_aggregate_v<type>) {
182
182
return internal::members_count_impl<type>();
183
183
}
184
+ else {
185
+ static_assert (!sizeof (T), " not supported type!" );
186
+ }
184
187
}
185
188
186
189
template <typename T>
0 commit comments