24 namespace json_details {
25#if defined( DAW_HAS_CPP20_CONCEPTS )
27 concept has_call_operator = std::is_function_v<T> or
requires {
28 &std::remove_reference_t<T>::operator( );
31 template<
typename T,
typename =
void>
32 inline constexpr bool has_call_operator = std::is_function_v<T>;
35 inline constexpr bool has_call_operator<
36 T, std::void_t<
decltype( &std::remove_reference_t<T>::operator( ) )>> =
39 template<
typename Signature,
typename Callable,
40 typename... FromJsonParams>
41 DAW_ATTRIB_INLINE
constexpr auto
42 json_apply_impl( Callable &&callable, FromJsonParams &&...params ) {
43 using func_t =
typename std::conditional_t<
44 std::is_same_v<use_default, Signature>,
45 daw::traits::identity<daw::func::function_traits<Callable>>,
46 daw::traits::identity<daw::func::function_traits<Signature>>>::type;
48 if constexpr( func_t::arity == 1 ) {
49 return DAW_FWD( callable )(
51 typename func_t::template argument<0>::plain_type>(
52 DAW_FWD( params )... ) );
56 daw::json::from_json<typename func_t::plain_params_t>(
57 DAW_FWD( params )... ) );
73 template<
typename Signature = use_default,
typename String,
74 typename Callable DAW_ENABLEIF(
75 json_details::has_call_operator<Callable> )>
76 DAW_REQUIRES( json_details::has_call_operator<Callable> )
77 constexpr auto json_apply( String &&json_doc, Callable &&callable ) {
78 return json_details::json_apply_impl<Signature>( DAW_FWD( callable ),
79 DAW_FWD( json_doc ) );
94 template<
typename Signature = use_default,
typename String,
95 typename Callable DAW_ENABLEIF(
96 json_details::has_call_operator<Callable> )>
97 DAW_REQUIRES( json_details::has_call_operator<Callable> )
98 constexpr auto json_apply( String &&json_doc,
std::string_view json_path,
99 Callable &&callable ) {
100 return json_details::json_apply_impl<Signature>(
101 DAW_FWD( callable ), DAW_FWD( json_doc ), json_path );
118 template<
typename Signature = use_default,
typename String,
120 typename Callable DAW_ENABLEIF(
121 json_details::has_call_operator<Callable> )>
122 DAW_REQUIRES( json_details::has_call_operator<Callable> )
123 constexpr auto json_apply(
124 String &&json_doc,
std::string_view json_path,
125 daw::json::options::parse_flags_t<PolicyFlags...> flags,
126 Callable &&callable ) {
127 return json_details::json_apply_impl<Signature>(
128 DAW_FWD( callable ), DAW_FWD( json_doc ), json_path, flags );
144 template<
typename Signature = use_default,
typename String,
146 typename Callable DAW_ENABLEIF(
147 json_details::has_call_operator<Callable> )>
148 DAW_REQUIRES( json_details::has_call_operator<Callable> )
149 constexpr auto json_apply(
151 daw::json::options::parse_flags_t<PolicyFlags...> flags,
152 Callable &&callable ) {
153 return json_details::json_apply_impl<Signature>(
154 DAW_FWD( callable ), DAW_FWD( json_doc ), flags );