@@ -287,10 +287,7 @@ template<typename CharType> struct basic_json
287
287
288
288
[[nodiscard]] constexpr iterator cend () const noexcept { return end (); }
289
289
290
- [[nodiscard]] constexpr std::size_t size () const noexcept
291
- {
292
- return size_;
293
- }
290
+ [[nodiscard]] constexpr std::size_t size () const noexcept { return size_; }
294
291
295
292
[[nodiscard]] static constexpr std::size_t size (const basic_json &obj) noexcept
296
293
{
@@ -367,26 +364,28 @@ template<typename CharType> struct basic_json
367
364
constexpr static basic_json object () { return basic_json{ data_t { basic_object_t <CharType>{} } }; }
368
365
constexpr static basic_json array () { return basic_json{ data_t { basic_array_t <CharType>{} } }; }
369
366
370
- template <typename Type> [[nodiscard]] constexpr Type get () const
367
+ template <typename Type>[[nodiscard]] constexpr Type get () const
371
368
{
372
369
if constexpr (std::is_same_v<Type, std::uint64_t > || std::is_same_v<Type, std::int64_t >) {
373
370
if (const auto *uint_value = data.get_if_uinteger (); uint_value != nullptr ) {
374
371
return Type (*uint_value);
375
372
} else if (const auto *value = data.get_if_integer (); value != nullptr ) {
376
373
return Type (*value);
377
374
}
375
+ throw std::runtime_error (" Incorrect type for get(), integer requested" );
378
376
} else if constexpr (std::is_same_v<Type, double >) {
379
377
if (const auto *value = data.get_if_floating_point (); value != nullptr ) { return *value; }
378
+ throw std::runtime_error (" Incorrect type for get(), double requested" );
380
379
} else if constexpr (std::is_same_v<Type,
381
380
std::basic_string_view<CharType>> || std::is_same_v<Type, std::basic_string<CharType>>) {
382
381
if (const auto *value = data.get_if_string (); value != nullptr ) { return *value; }
382
+ throw std::runtime_error (" Incorrect type for get(), string requested" );
383
383
} else if constexpr (std::is_same_v<Type, bool >) {
384
384
if (const auto *value = data.get_if_boolean (); value != nullptr ) { return *value; }
385
+ throw std::runtime_error (" Incorrect type for get(), boolean requested" );
385
386
} else {
386
387
throw std::runtime_error (" Unexpected type for get()" );
387
388
}
388
-
389
- throw std::runtime_error (" Incorrect type for get()" );
390
389
}
391
390
392
391
[[nodiscard]] constexpr bool is_object () const noexcept { return data.selected == data_t ::selected_type::object; }
@@ -421,13 +420,13 @@ template<typename CharType> struct basic_json
421
420
422
421
423
422
data_t data;
424
- std::size_t size_{size (*this )};
423
+ std::size_t size_{ size (*this ) };
425
424
};
426
425
427
426
using json = basic_json<char >;
428
427
using object_t = basic_object_t <char >;
429
428
using value_pair_t = basic_value_pair_t <char >;
430
429
using array_t = basic_array_t <char >;
431
- }// namespace constexpr_json
430
+ }// namespace json2cpp
432
431
433
432
#endif
0 commit comments