@@ -23,7 +23,7 @@ SOFTWARE.
23
23
*/
24
24
25
25
// Important note: the types in this file are only intended for compile-time construction
26
- // but consteval doesn't exist in C++17
26
+ // but consteval doesn't exist in C++17, and we're targeting C++17
27
27
28
28
#ifndef CONSTEXPR_JSON_HPP_INCLUDED
29
29
#define CONSTEXPR_JSON_HPP_INCLUDED
@@ -34,13 +34,15 @@ SOFTWARE.
34
34
#include < stdexcept>
35
35
#include < string_view>
36
36
37
+ // simple pair to speed up compilation a bit compared to std::pair
37
38
namespace json2cpp {
38
39
template <typename First, typename Second> struct pair
39
40
{
40
41
First first;
41
42
Second second;
42
43
};
43
44
45
+ // simple span because std::span is not in C++17
44
46
template <typename T> struct span
45
47
{
46
48
template <std::size_t Size >
@@ -388,6 +390,8 @@ template<typename CharType> struct basic_json
388
390
389
391
template <typename Type>[[nodiscard]] constexpr auto get () const
390
392
{
393
+ // I don't like this level of implicit conversions in the `get()` function,
394
+ // but it's necessary for API compatibility with nlohmann::json
391
395
if constexpr (std::is_same_v<Type, std::uint64_t > || std::is_same_v<Type, std::int64_t > || std::is_same_v<Type, double >) {
392
396
if (const auto *uint_value = data.get_if_uinteger (); uint_value != nullptr ) {
393
397
return Type (*uint_value);
@@ -396,8 +400,6 @@ template<typename CharType> struct basic_json
396
400
} else if (const auto *fpvalue = data.get_if_floating_point (); fpvalue != nullptr ) {
397
401
return Type (*fpvalue);
398
402
} else {
399
- // std::stringstream ss;
400
- // ss << is_string() << is_object() << is_array() << is_string() << is_boolean() << is_structured() << is_number() << is_null() << is_binary() << is_primitive();
401
403
throw std::runtime_error (" Unexpected type: number requested" );// + ss.str() );
402
404
}
403
405
} else if constexpr (std::is_same_v<Type,
0 commit comments