47 namespace json_details {
48 template<
template<
typename...>
typename Trait,
typename... Params>
50 using type = Trait<Params...>;
54 static_cast<bool>( std::declval<T>( ) ) );
58 template<
typename Constructor,
typename... Args>
59 struct constructor_cannot_be_invoked;
61 template<
typename Constructor,
typename... Args>
62 struct construction_result
64 daw::is_callable_v<Constructor, Args...>,
65 std::invoke_result<Constructor, Args...>,
66 daw::traits::identity<
67 constructor_cannot_be_invoked<Constructor, Args...>>> {};
70 namespace json_details {
71 template<
typename JsonMember>
72 using without_name =
typename JsonMember::without_name;
74 template<
typename JsonMember, JSONNAMETYPE NewName,
bool Cond>
75 using copy_name_when = daw::conditional_t<
76 Cond,
typename JsonMember::template with_name<NewName>, JsonMember>;
78 template<
typename JsonMember, JSONNAMETYPE NewName>
79 using copy_name_when_noname =
80 copy_name_when<JsonMember, NewName, is_no_name_v<JsonMember>>;
83 namespace json_details {
91 force_aggregate_construction_test1,
95 T::force_aggregate_construction );
107 json_details::force_aggregate_construction_test1<T> or
108 json_details::force_aggregate_construction_test2<T>;
110 namespace json_details {
111 template<
typename,
typename =
void>
112 struct json_constructor;
115 struct json_constructor<T,
std::void_t<typename T::constructor_t>> {
116 using type =
typename T::constructor_t;
120 using json_constructor_t =
typename json_constructor<T>::type;
122 template<
typename,
typename =
void>
126 struct json_result<T,
std::void_t<typename T::parse_to_t>> {
127 using type =
typename T::parse_to_t;
131 using json_result_t =
typename json_result<T>::type;
133 template<
typename,
typename =
void>
134 struct json_base_type;
137 struct json_base_type<T,
std::void_t<json_result_t<T>>> {
138 using type = json_result_t<T>;
142 using json_base_type_t =
typename json_base_type<T>::type;
145 is_default_default_constructor_type_v,
146 T::i_am_the_default_default_constructor_type );
149 T::has_stateless_allocator );
155 inline constexpr bool must_be_class_member_v =
false;
158 template<
typename Constructor,
typename T,
typename ParseState>
160 not json_details::has_data_contract_constructor_v<T> and
161 ( force_aggregate_construction_v<T> or
162 json_details::is_default_default_constructor_type_v<Constructor> or
163 not json_details::has_stateless_allocator_v<ParseState> );
165 template<
typename... Ts>
177 template<
typename Char,
typename CharTrait,
typename Allocator>
179 std::basic_string<Char, CharTrait, Allocator>> =
true;
183 std::bool_constant<can_single_allocation_string_v<T>>;
185 namespace json_details {
187 T::i_am_a_json_type );
189 template<
typename... Ts>
190 inline constexpr bool are_json_types_v = ( is_a_json_type_v<Ts> and ... );
195 T::i_am_an_ordered_member );
198 using is_an_ordered_member =
199 std::bool_constant<is_an_ordered_member_v<T>>;
202 T::i_am_a_json_tagged_variant );
205 using json_class_constructor_t_impl =
209 using data_contract_constructor_t =
212 template<
typename T,
typename Default>
213 using json_class_constructor_t = daw::detected_or_t<
214 typename daw::conditional_t<
215 std::is_same_v<use_default, Default>,
216 daw::conditional_t<has_data_contract_constructor_v<T>,
217 ident_trait<data_contract_constructor_t, T>,
218 ident_trait<default_constructor, T>>,
219 daw::traits::identity<Default>>::type,
220 json_class_constructor_t_impl, T>;
223 is_string_view_like_v, ( (
void)( std::data( std::declval<T>( ) ) ),
224 (
void)( std::size( std::declval<T>( ) ) ) ) );
226 static_assert( is_string_view_like_v<std::string_view> );
237 template<
typename CharT,
typename Traits,
typename Alloc>
238 inline constexpr bool
239 is_zero_terminated_string_v<std::basic_string<CharT, Traits, Alloc>> =
244 std::bool_constant<is_zero_terminated_string_v<T>>;
246 namespace json_details {
247 template<
typename ParsePolicy, auto Option>
248 using apply_policy_option_t =
249 typename ParsePolicy::template SetPolicyOptions<Option>;
251 template<
typename ParsePolicy,
typename String, auto Option>
252 using apply_zstring_policy_option_t = daw::conditional_t<
253 is_zero_terminated_string_v<daw::remove_cvref_t<String>>,
254 apply_policy_option_t<ParsePolicy, Option>, ParsePolicy>;
259 template<
typename ParsePolicy,
typename String>
260 inline constexpr bool can_use_runtime_zstring_v =
261 daw::sv2::is_daw_string_view<String> and
262 not ParsePolicy::is_zero_terminated_string and
263 not ParsePolicy::is_unchecked_input and not ParsePolicy::has_allocator;
265 template<
typename ParsePolicy>
266 using zstring_policy_t =
267 apply_policy_option_t<ParsePolicy, options::ZeroTerminatedString::yes>;
270 template<
typename ParsePolicy,
typename String>
271 [[nodiscard]]
constexpr bool is_runtime_zstring( String
const &json_data ) {
272 if constexpr( can_use_runtime_zstring_v<ParsePolicy, String> ) {
273 return json_data.is_zero_terminated( ) == daw::ZeroTerminated::Yes;
280 template<
typename String>
281 inline constexpr bool is_mutable_string_v =
282 not std::is_const_v<std::remove_pointer_t<std::remove_reference_t<
283 decltype( std::data( std::declval<String &&>( ) ) )>>>;
318 namespace json_details {
319 template<
typename T,
typename ParseState>
320 DAW_CPP20_CONCEPT all_json_members_must_exist_v =
321 not ignore_unknown_members_v<T> and
322 ( is_exact_class_mapping_v<T> or
323 ParseState::use_exact_mappings_by_default );
327 template<
template<
typename...>
typename T,
typename... Params>
328 struct identity_parts {
329 using type = T<Params...>;
340 std::is_pointer_v<T> or json_details::has_element_type<T>;
344 template<
typename Tuple,
typename =
void>
347 template<
typename... Ts>
349 using type = std::tuple<Ts...>;
351 static constexpr auto size =
sizeof...( Ts );
353 template<std::
size_t Idx>
356 template<std::
size_t Idx,
typename Tuple>
357 static constexpr decltype( auto )
get( Tuple &&tp ) {
358 return std::get<Idx>( DAW_FWD( tp ) );
362 template<
typename... Ts>
364 using type = daw::fwd_pack<Ts...>;
366 static constexpr auto size =
sizeof...( Ts );
368 template<std::
size_t Idx>
370 daw::remove_cvref_t<typename std::tuple_element_t<Idx, type>>;
372 template<std::
size_t Idx,
typename Tuple>
373 static constexpr decltype( auto )
get( Tuple &&tp ) {
374 return DAW_FWD( tp ).template get<Idx>( );
385 (std::is_copy_constructible_v<T> and std::is_copy_assignable_v<T>) or
386 ( std::is_move_constructible_v<T> and std::is_move_assignable_v<T> ) );
388 namespace json_details {
389 template<
typename,
typename =
void>
390 inline constexpr bool is_tuple_v =
false;
392 template<
typename... Ts>
393 inline constexpr bool is_tuple_v<std::tuple<Ts...>> =
true;
396 inline constexpr bool
397 is_tuple_v<T, typename tuple_elements_pack<T>::type> =
true;
400 using unwrapped_t = concepts::nullable_value_type_t<T>;
403 using mapped_type_t =
typename T::mapped_type;
406 using key_type_t =
typename T::key_type;
409#if true or defined( DAW_JSON_DISABLE_RANDOM )
411 DAW_CPP20_CONCEPT can_be_random_iterator_v =
false;
413 template<
bool IsKnown>
414 DAW_CPP20_CONCEPT can_be_random_iterator_v = IsKnown;
420 template<
typename JsonMember>
421 using literal_json_type_as_string =
typename JsonMember::as_string;
424 T::i_am_a_deduced_empty_class );
427 struct ensure_mapped {
428 static_assert( is_a_json_type_v<T>,
429 "The supplied type does not have a json_data_contract" );
434 using ensure_mapped_t =
typename ensure_mapped<T>::type;
436 DAW_MAKE_REQ_TRAIT_TYPE( is_json_member_list_v,
437 T::i_am_a_json_member_list );
440 using ordered_member_subtype_test =
typename T::json_member;
443 using ordered_member_subtype_t =
444 typename daw::detected_or_t<T, ordered_member_subtype_test, T>;
446 template<
typename T,
typename Default>
447 inline constexpr auto json_class_constructor =
448 json_class_constructor_t<T, Default>{ };
451 using json_nullable_member_type_t =
typename T::member_type;