33 namespace json_details {
35 inline constexpr bool is_std_allocator_v =
false;
38 inline constexpr bool is_std_allocator_v<std::allocator<T>> =
true;
43 template<
typename T, std::
size_t Sz>
45 template<
typename Iterator, std::size_t... Is>
46 DAW_ATTRIB_INLINE
static constexpr std::array<T, Sz>
48 std::index_sequence<Is...> ) {
49 auto const get_result = [&]( std::size_t ) {
51 if constexpr( std::is_move_constructible_v<T> or
52 std::is_copy_constructible_v<T> ) {
58 auto const run_after_parse = on_exit_success( [&] {
61 (void)run_after_parse;
67 return std::array<T, Sz>{ get_result( Is )... };
72 operator( )( std::array<T, Sz> &&v )
74 return std::move( v );
77 template<
typename Iterator,
typename Last>
80 operator( )( Iterator first,
82 return construct_array( std::move( first ),
84 std::make_index_sequence<Sz>{ } );
89#if defined( DAW_JSON_HAS_CPP23_RANGE_CTOR )
90 namespace json_details {
91 template<
typename F,
typename L>
96 explicit iter_range_t( ) =
default;
97 explicit constexpr iter_range_t( F f, L l ) noexcept
101 [[nodiscard]]
constexpr F begin( ) const noexcept {
105 [[nodiscard]]
constexpr L end( ) const noexcept {
109 template<
typename F,
typename L>
110 iter_range_t( F, L ) -> iter_range_t<F, L>;
115 template<
typename T,
typename Alloc>
116 struct default_constructor<
std::vector<T, Alloc>> {
120 operator( )( std::vector<T, Alloc> &&v )
122 noexcept(
noexcept( std::vector<T, Alloc>( v ) ) ) {
123 return std::move( v );
126 template<
typename Iterator,
typename Last>
129 operator( )( Iterator first, Last last, Alloc
const &alloc = Alloc{ } )
131 if constexpr(
requires { last - first; } or
132 not json_details::is_std_allocator_v<Alloc> ) {
133 return std::vector<T, Alloc>(
135 json_details::iter_range_t{ std::move( first ), std::move( last ) },
138 using reserve_amount = daw::constant<
139 ( 4096U /
sizeof( T ) ) == 0 ? 1 : ( 4096U /
sizeof( T ) )>;
140 auto result = std::vector<T, Alloc>( alloc );
142 result.reserve( reserve_amount::value );
143 result.assign_range( json_details::iter_range_t{
144 std::move( first ), std::move( last ) } );
154 template<
typename T,
typename Alloc>
159 operator( )( std::vector<T, Alloc> &&v )
161 noexcept(
noexcept( std::vector<T, Alloc>( v ) ) ) {
162 return std::move( v );
165 template<
typename Iterator,
typename Last>
168 operator( )( Iterator first, Last last, Alloc
const &alloc = Alloc{ } )
170 if constexpr( std::is_same_v<std::random_access_iterator_tag,
171 typename std::iterator_traits<
172 Iterator>::iterator_category> or
173 not json_details::is_std_allocator_v<Alloc> ) {
174 return std::vector<T, Alloc>(
175 std::move( first ), std::move( last ), alloc );
177 using reserve_amount = daw::constant<4096U / (
sizeof( T ) * 8U )>;
178 auto result = std::vector<T, Alloc>( alloc );
180 result.reserve( reserve_amount::value );
181 result.assign( std::move( first ), std::move( last ) );
194 template<
typename Key,
typename T,
typename Hash,
typename CompareEqual,
197 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>> {
201 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>
202 operator( )( std::unordered_map<Key, T, Hash, CompareEqual, Alloc> &&v )
204 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>( v ) ) ) {
205 return std::move( v );
208 static constexpr std::size_t count = 1;
209 template<
typename Iterator>
211 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>
212 operator( )( Iterator first, Iterator last,
213 Alloc
const &alloc = Alloc{ } )
215 return std::unordered_map<Key, T, Hash, CompareEqual, Alloc>(
216 first, last, count, Hash{ }, CompareEqual{ }, alloc );
225 T DAW_ENABLEIF_S( concepts::is_nullable_value_v<T> )> {
230 [[nodiscard]] DAW_ATTRIB_INLINE
232 operator( )( concepts::construct_nullable_with_empty_t )
234 noexcept( concepts::is_nullable_empty_nothrow_constructible_v<T> ) {
235 static_assert( concepts::is_nullable_empty_constructible_v<T> );
236 return rtraits_t{ }( concepts::construct_nullable_with_empty );
239 template<
typename... Args DAW_ENABLEIF(
240 concepts::is_nullable_value_constructible_v<T, Args...> )>
241 DAW_REQUIRES( concepts::is_nullable_value_constructible_v<T, Args...> )
246 concepts::is_nullable_value_nothrow_constructible_v<T, Args...> ) {
247 return rtraits_t{ }( concepts::construct_nullable_with_value,
248 DAW_FWD( args )... );
251 template<
typename Pointer DAW_ENABLEIF(
252 concepts::is_nullable_pointer_constructible_v<T, Pointer *> )>
254 concepts::is_nullable_pointer_constructible_v<T, Pointer *> )
257 operator( )( concepts::construct_nullable_with_pointer_t,
260 concepts::is_nullable_value_nothrow_constructible_v<T, Pointer> ) {
261 return rtraits_t{ }( concepts::construct_nullable_with_pointer, ptr );