21 #include <daw/cpp_17.h>
22 #include <daw/daw_fwd_pack_apply.h>
23 #include <daw/daw_move.h>
24 #include <daw/daw_traits.h>
27 #include <string_view>
28 #include <type_traits>
41 namespace json_details {
42 template<
template<
typename...>
typename Trait,
typename... Params>
44 using type = Trait<Params...>;
48 static_cast<bool>( std::declval<T>( ) ) );
52 template<
typename Constructor,
typename... Args>
53 struct constructor_cannot_be_invoked;
55 template<
typename Constructor,
typename... Args>
56 struct construction_result
58 std::is_invocable_v<Constructor, Args...>,
59 std::invoke_result<Constructor, Args...>,
60 daw::traits::identity<
61 constructor_cannot_be_invoked<Constructor, Args...>>> {};
64 namespace json_details {
65 template<
typename JsonMember>
66 using without_name =
typename JsonMember::without_name;
68 template<
typename JsonMember, JSONNAMETYPE NewName,
bool Cond>
69 using copy_name_when = daw::conditional_t<
70 Cond,
typename JsonMember::template with_name<NewName>, JsonMember>;
72 template<
typename JsonMember, JSONNAMETYPE NewName>
73 using copy_name_when_noname =
74 copy_name_when<JsonMember, NewName, is_no_name_v<JsonMember>>;
77 namespace json_details {
85 force_aggregate_construction_test1,
89 T::force_aggregate_construction );
101 json_details::force_aggregate_construction_test1<T> or
102 json_details::force_aggregate_construction_test2<T>;
104 namespace json_details {
105 template<
typename,
typename =
void>
106 struct json_constructor;
109 struct json_constructor<T,
std::void_t<typename T::constructor_t>> {
110 using type =
typename T::constructor_t;
114 using json_constructor_t =
typename json_constructor<T>::type;
116 template<
typename,
typename =
void>
120 struct json_result<T,
std::void_t<typename T::parse_to_t>> {
121 using type =
typename T::parse_to_t;
125 using json_result_t =
typename json_result<T>::type;
127 template<
typename,
typename =
void>
128 struct json_base_type;
131 struct json_base_type<T,
std::void_t<json_result_t<T>>> {
132 using type = json_result_t<T>;
136 using json_base_type_t =
typename json_base_type<T>::type;
139 is_default_default_constructor_type_v,
140 T::i_am_the_default_default_constructor_type );
143 T::has_stateless_allocator );
149 inline constexpr
bool must_be_class_member_v =
false;
152 template<
typename Constructor,
typename T,
typename ParseState>
154 not json_details::has_data_contract_constructor_v<T> and
155 ( force_aggregate_construction_v<T> or
156 json_details::is_default_default_constructor_type_v<Constructor> or
157 not json_details::has_stateless_allocator_v<ParseState> );
159 template<
typename... Ts>
171 template<
typename Char,
typename CharTrait,
typename Allocator>
173 std::basic_string<Char, CharTrait, Allocator>> =
true;
177 std::bool_constant<can_single_allocation_string_v<T>>;
179 namespace json_details {
181 T::i_am_a_json_type );
183 template<
typename... Ts>
184 inline constexpr
bool are_json_types_v = ( is_a_json_type_v<Ts> and ... );
187 T::i_am_an_ordered_member );
190 using is_an_ordered_member =
191 std::bool_constant<is_an_ordered_member_v<T>>;
194 T::i_am_a_json_tagged_variant );
197 using json_class_constructor_t_impl =
201 using data_contract_constructor_t =
204 template<
typename T,
typename Default>
205 using json_class_constructor_t = daw::detected_or_t<
206 typename daw::conditional_t<
207 std::is_same_v<use_default, Default>,
208 daw::conditional_t<has_data_contract_constructor_v<T>,
209 ident_trait<data_contract_constructor_t, T>,
210 ident_trait<default_constructor, T>>,
211 daw::traits::identity<Default>>::type,
212 json_class_constructor_t_impl, T>;
215 ( (
void)( std::data( std::declval<T>( ) ) ),
216 (
void)( std::size( std::declval<T>( ) ) ) ) );
218 static_assert( is_string_view_like_v<std::string_view> );
229 template<
typename CharT,
typename Traits,
typename Alloc>
230 inline constexpr
bool
231 is_zero_terminated_string_v<std::basic_string<CharT, Traits, Alloc>> =
236 std::bool_constant<is_zero_terminated_string_v<T>>;
238 namespace json_details {
239 template<
typename ParsePolicy, auto Option>
240 using apply_policy_option_t =
241 typename ParsePolicy::template SetPolicyOptions<Option>;
243 template<
typename ParsePolicy,
typename String, auto Option>
244 using apply_zstring_policy_option_t = daw::conditional_t<
245 is_zero_terminated_string_v<daw::remove_cvref_t<String>>,
246 apply_policy_option_t<ParsePolicy, Option>, ParsePolicy>;
248 template<
typename String>
249 inline constexpr
bool is_mutable_string_v =
250 not std::is_const_v<std::remove_pointer_t<std::remove_reference_t<
251 decltype( std::data( std::declval<String &&>( ) ) )>>>;
253 template<
typename String>
254 constexpr
bool is_mutable_string =
255 json_details::is_mutable_string_v<String>;
257 template<
typename String>
258 constexpr
bool is_rvalue_string = std::is_rvalue_reference_v<String>;
260 template<
typename String>
261 constexpr
bool is_ref_string =
262 not is_rvalue_string<String> and
263 std::is_const_v<std::remove_reference_t<String>>;
298 namespace json_details {
299 template<
typename T,
typename ParseState>
300 inline constexpr
bool all_json_members_must_exist_v =
301 not ignore_unknown_members_v<T> and
302 ( is_exact_class_mapping_v<T> or
303 ParseState::use_exact_mappings_by_default );
307 template<
template<
typename...>
typename T,
typename... Params>
308 struct identity_parts {
309 using type = T<Params...>;
320 std::is_pointer_v<T> or json_details::has_element_type<T>;
324 template<
typename Tuple,
typename =
void>
327 template<
typename... Ts>
329 using type = std::tuple<Ts...>;
331 static constexpr std::size_t size =
sizeof...( Ts );
333 template<std::
size_t Idx>
336 template<std::
size_t Idx,
typename Tuple>
337 static constexpr decltype(
auto )
get( Tuple &&tp ) {
338 return std::get<Idx>( DAW_FWD( tp ) );
342 template<
typename... Ts>
344 using type = daw::fwd_pack<Ts...>;
346 static constexpr std::size_t size =
sizeof...( Ts );
348 template<std::
size_t Idx>
350 daw::remove_cvref_t<typename daw::tuple_element<Idx, type>::type>;
352 template<std::
size_t Idx,
typename Tuple>
353 static constexpr decltype(
auto )
get( Tuple &&tp ) {
354 return DAW_FWD( tp ).template get<Idx>( );
365 (std::is_copy_constructible_v<T> and std::is_copy_assignable_v<T>) or
366 ( std::is_move_constructible_v<T> and std::is_move_assignable_v<T> ) );
368 namespace json_details {
369 template<
typename,
typename =
void>
370 inline constexpr
bool is_tuple_v =
false;
372 template<
typename... Ts>
373 inline constexpr
bool is_tuple_v<std::tuple<Ts...>> =
true;
376 inline constexpr
bool
377 is_tuple_v<T, typename tuple_elements_pack<T>::type> =
true;
380 using unwrapped_t = concepts::nullable_value_type_t<T>;
383 using mapped_type_t =
typename T::mapped_type;
386 using key_type_t =
typename T::key_type;
389 #if true or defined( DAW_JSON_DISABLE_RANDOM )
391 inline constexpr
bool can_be_random_iterator_v =
false;
393 template<
bool IsKnown>
394 inline constexpr
bool can_be_random_iterator_v = IsKnown;
400 template<
typename JsonMember>
401 using literal_json_type_as_string =
typename JsonMember::as_string;
403 template<
typename,
typename =
void>
404 inline constexpr
bool is_deduced_empty_class_v =
false;
#define DAW_JSON_MAKE_REQ_TRAIT(Name,...)
Disable concepts on gcc < 13.3. See https://github.com/beached/daw_json_link/issues/454.
typename json_data_contract< T >::type json_data_contract_trait_t
This trait gets us the mapping type from the contract.
constexpr bool can_single_allocation_string_v
Can use the fast, pseudo random string iterators. They are InputIterators with an operator- that allo...
constexpr bool is_zero_terminated_string_v
constexpr bool force_aggregate_construction_v
constexpr bool is_pinned_type_v
Is the type pinned in memory and unable to be copied/moved after construction(e.g....
constexpr bool is_pointer_like_v
DAW_JSON_MAKE_REQ_TYPE_ALIAS_TRAIT(ignore_unknown_members_v, json_data_contract< T >::ignore_unknown_members)
constexpr bool is_empty_pack_v
constexpr bool should_construct_explicitly_v
std::bool_constant< is_zero_terminated_string_v< T > > is_zero_terminated_string
std::bool_constant< can_single_allocation_string_v< T > > can_single_allocation_string
constexpr decltype(auto) get(basic_json_pair< PolicyFlags, Allocator > const &parse_state)
Customization point traits.
Mapping class for JSON data structures to C++. It must be specialized in order to parse to a user cla...
daw::fwd_pack< Ts... > type
daw::remove_cvref_t< typename daw::tuple_element< Idx, type >::type > element_t
std::tuple_element_t< Idx, type > element_t
Allow tuple like types to be used in json_tuple.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.