24 namespace json_details {
25 template<
typename Value,
typename Constructor,
typename ParseState,
27 DAW_ATTRIB_INLINE
static constexpr auto
28 construct_value( ParseState &parse_state, Args &&...args ) {
31 if constexpr( ParseState::has_allocator ) {
32 auto alloc = parse_state.template get_allocator_for<Value>( );
33 return daw::try_alloc_construct<Value, Constructor>(
34 std::move( alloc ), DAW_FWD( args )... );
37 daw::is_callable_v<Constructor, Args...>,
38 "Unable to construct value with the supplied arguments" );
39 return Constructor{ }( DAW_FWD( args )... );
43#if not defined( DAW_JSON_USE_GENERIC_LAMBDAS )
44 template<
typename Constructor>
45 struct construct_value_tp_invoke_t {
46 template<
typename... TArgs, std::size_t... Is>
47 DAW_ATTRIB_INLINE
constexpr auto
48 operator( )( fwd_pack<TArgs...> &&tp,
49 std::index_sequence<Is...> )
const {
50 return Constructor{ }( get<Is>( std::move( tp ) )... );
53 template<
typename... TArgs,
typename Allocator, std::size_t... Is>
54 DAW_ATTRIB_INLINE
constexpr auto
55 operator( )( fwd_pack<TArgs...> &&tp, Allocator &alloc,
56 std::index_sequence<Is...> )
const {
57 return Constructor{ }( get<Is>( std::move( tp ) )...,
61 template<
typename Alloc,
typename... TArgs, std::size_t... Is>
62 DAW_ATTRIB_INLINE
constexpr auto
63 operator( )( std::allocator_arg_t, Alloc &&alloc,
64 fwd_pack<TArgs...> &&tp,
65 std::index_sequence<Is...> )
const {
67 return Constructor{ }( std::allocator_arg,
69 get<Is>( std::move( tp ) )... );
72 template<
typename Constructor>
73 inline constexpr auto construct_value_tp_invoke =
74 construct_value_tp_invoke_t<Constructor>{ };
77 template<
typename Value,
typename Constructor,
typename ParseState,
79 DAW_ATTRIB_FLATINLINE
static constexpr auto
80 construct_value_tp( ParseState &parse_state,
81 fwd_pack<Args...> &&tp_args ) {
83#if defined( DAW_JSON_USE_GENERIC_LAMBDAS )
84 if constexpr( ParseState::has_allocator ) {
88 typename ParseState::template allocator_type_as<Value>;
89 auto alloc = parse_state.template get_allocator_for<Value>( );
91 if constexpr( daw::is_callable_v<Constructor, Args..., alloc_t> ) {
92 return [&]<std::size_t... Is>( std::index_sequence<Is...> ) {
94 return Constructor{ }( get<Is>( std::move( tp_args ) )...,
96 }( std::make_index_sequence<
sizeof...( Args )>{ } );
97 }
else if constexpr( daw::is_callable_v<Constructor,
102 return [&]<std::size_t... Is>( std::index_sequence<Is...> ) {
103 return Constructor{ }( std::allocator_arg,
105 get<Is>( std::move( tp_args ) )... );
106 }( std::make_index_sequence<
sizeof...( Args )>{ } );
112 daw::is_callable_v<Constructor, Args...>,
113 "Unable to construct value with the supplied arguments" );
114 return [&]<std::size_t... Is>( std::index_sequence<Is...> ) {
115 return Constructor{ }( get<Is>( std::move( tp_args ) )... );
116 }( std::make_index_sequence<
sizeof...( Args )>{ } );
124 daw::is_callable_v<Constructor, Args...>,
125 "Unable to construct value with the supplied arguments" );
126 return [&]<std::size_t... Is>( std::index_sequence<Is...> ) {
127 return Constructor{ }( get<Is>( std::move( tp_args ) )... );
128 }( std::make_index_sequence<
sizeof...( Args )>{ } );
131 if constexpr( ParseState::has_allocator ) {
135 typename ParseState::template allocator_type_as<Value>;
136 auto alloc = parse_state.template get_allocator_for<Value>( );
137 if constexpr( daw::is_callable_v<Constructor, Args..., alloc_t> ) {
139 return construct_value_tp_invoke<Constructor>(
140 std::move( tp_args ),
142 std::index_sequence_for<Args...>{ } );
143 }
else if constexpr( daw::is_callable_v<Constructor,
144 std::allocator_arg_t,
148 return construct_value_tp_invoke<Constructor>(
151 std::move( tp_args ),
152 std::index_sequence_for<Args...>{ } );
158 daw::is_callable_v<Constructor, Args...>,
159 "Unable to construct value with the supplied arguments" );
160 return construct_value_tp_invoke<Constructor>(
161 std::move( tp_args ), std::index_sequence_for<Args...>{ } );
169 daw::is_callable_v<Constructor, Args...>,
170 "Unable to construct value with the supplied arguments" );
171 return construct_value_tp_invoke<Constructor>(
172 std::move( tp_args ), std::index_sequence_for<Args...>{ } );