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<4096U / (
sizeof( T ) * 8U )>;
139 auto result = std::vector<T, Alloc>( alloc );
141 result.reserve( reserve_amount::value );
142 result.assign_range( json_details::iter_range_t{
143 std::move( first ), std::move( last ) } );
153 template<
typename T,
typename Alloc>
158 operator( )( std::vector<T, Alloc> &&v )
160 noexcept(
noexcept( std::vector<T, Alloc>( v ) ) ) {
161 return std::move( v );
164 template<
typename Iterator,
typename Last>
167 operator( )( Iterator first, Last last, Alloc
const &alloc = Alloc{ } )
169 if constexpr( std::is_same_v<std::random_access_iterator_tag,
170 typename std::iterator_traits<
171 Iterator>::iterator_category> or
172 not json_details::is_std_allocator_v<Alloc> ) {
173 return std::vector<T, Alloc>(
174 std::move( first ), std::move( last ), alloc );
176 using reserve_amount = daw::constant<4096U / (
sizeof( T ) * 8U )>;
177 auto result = std::vector<T, Alloc>( alloc );
179 result.reserve( reserve_amount::value );
180 result.assign( std::move( first ), std::move( last ) );
193 template<
typename Key,
typename T,
typename Hash,
typename CompareEqual,
196 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>> {
200 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>
201 operator( )( std::unordered_map<Key, T, Hash, CompareEqual, Alloc> &&v )
203 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>( v ) ) ) {
204 return std::move( v );
207 static constexpr std::size_t count = 1;
208 template<
typename Iterator>
210 std::unordered_map<Key, T, Hash, CompareEqual, Alloc>
211 operator( )( Iterator first, Iterator last,
212 Alloc
const &alloc = Alloc{ } )
214 return std::unordered_map<Key, T, Hash, CompareEqual, Alloc>(
215 first, last, count, Hash{ }, CompareEqual{ }, alloc );
224 T DAW_ENABLEIF_S( concepts::is_nullable_value_v<T> )> {
229 [[nodiscard]] DAW_ATTRIB_INLINE
231 operator( )( concepts::construct_nullable_with_empty_t )
233 noexcept( concepts::is_nullable_empty_nothrow_constructible_v<T> ) {
234 static_assert( concepts::is_nullable_empty_constructible_v<T> );
235 return rtraits_t{ }( concepts::construct_nullable_with_empty );
238 template<
typename... Args DAW_ENABLEIF(
239 concepts::is_nullable_value_constructible_v<T, Args...> )>
240 DAW_REQUIRES( concepts::is_nullable_value_constructible_v<T, Args...> )
245 concepts::is_nullable_value_nothrow_constructible_v<T, Args...> ) {
246 return rtraits_t{ }( concepts::construct_nullable_with_value,
247 DAW_FWD( args )... );
250 template<
typename Pointer DAW_ENABLEIF(
251 concepts::is_nullable_pointer_constructible_v<T, Pointer *> )>
253 concepts::is_nullable_pointer_constructible_v<T, Pointer *> )
256 operator( )( concepts::construct_nullable_with_pointer_t,
259 concepts::is_nullable_value_nothrow_constructible_v<T, Pointer> ) {
260 return rtraits_t{ }( concepts::construct_nullable_with_pointer, ptr );