18#ifndef INCLUDE_NLOHMANN_JSON_HPP_
19#define INCLUDE_NLOHMANN_JSON_HPP_
24#include <initializer_list>
60#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK
61 #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH)
62 #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 3
63 #warning "Already included a different version of the library!"
68#define NLOHMANN_JSON_VERSION_MAJOR 3
69#define NLOHMANN_JSON_VERSION_MINOR 11
70#define NLOHMANN_JSON_VERSION_PATCH 3
72#ifndef JSON_DIAGNOSTICS
73 #define JSON_DIAGNOSTICS 0
76#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
77 #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0
81 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag
83 #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS
86#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
87 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp
89 #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON
92#ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION
93 #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0
97#define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b
98#define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \
99 NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b)
101#define NLOHMANN_JSON_ABI_TAGS \
102 NLOHMANN_JSON_ABI_TAGS_CONCAT( \
103 NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \
104 NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON)
107#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \
108 _v ## major ## _ ## minor ## _ ## patch
109#define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \
110 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch)
112#if NLOHMANN_JSON_NAMESPACE_NO_VERSION
113#define NLOHMANN_JSON_NAMESPACE_VERSION
115#define NLOHMANN_JSON_NAMESPACE_VERSION \
116 NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \
117 NLOHMANN_JSON_VERSION_MINOR, \
118 NLOHMANN_JSON_VERSION_PATCH)
122#define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b
123#define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \
124 NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b)
126#ifndef NLOHMANN_JSON_NAMESPACE
127#define NLOHMANN_JSON_NAMESPACE \
128 nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \
129 NLOHMANN_JSON_ABI_TAGS, \
130 NLOHMANN_JSON_NAMESPACE_VERSION)
133#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN
134#define NLOHMANN_JSON_NAMESPACE_BEGIN \
137 inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \
138 NLOHMANN_JSON_ABI_TAGS, \
139 NLOHMANN_JSON_NAMESPACE_VERSION) \
143#ifndef NLOHMANN_JSON_NAMESPACE_END
144#define NLOHMANN_JSON_NAMESPACE_END \
162#include <forward_list>
167#include <type_traits>
168#include <unordered_map>
231#include <type_traits>
247NLOHMANN_JSON_NAMESPACE_BEGIN
255template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
258NLOHMANN_JSON_NAMESPACE_END
261NLOHMANN_JSON_NAMESPACE_BEGIN
269 ~nonesuch() =
delete;
270 nonesuch(nonesuch
const&) =
delete;
271 nonesuch(nonesuch
const&&) =
delete;
272 void operator=(nonesuch
const&) =
delete;
273 void operator=(nonesuch&&) =
delete;
276template<
class Default,
278 template<
class...>
class Op,
282 using value_t = std::false_type;
283 using type = Default;
286template<
class Default,
template<
class...>
class Op,
class... Args>
287struct detector<Default, void_t<Op<Args...>>, Op, Args...>
289 using value_t = std::true_type;
290 using type = Op<Args...>;
293template<
template<
class...>
class Op,
class... Args>
294using is_detected =
typename detector<nonesuch, void, Op, Args...>
::value_t;
296template<
template<
class...>
class Op,
class... Args>
297struct is_detected_lazy : is_detected<Op, Args...> { };
299template<
template<
class...>
class Op,
class... Args>
300using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
302template<
class Default,
template<
class...>
class Op,
class... Args>
303using detected_or = detector<Default, void, Op, Args...>;
305template<
class Default,
template<
class...>
class Op,
class... Args>
306using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
308template<
class Expected,
template<
class...>
class Op,
class... Args>
309using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
311template<
class To,
template<
class...>
class Op,
class... Args>
312using is_detected_convertible =
313 std::is_convertible<detected_t<Op, Args...>, To>;
316NLOHMANN_JSON_NAMESPACE_END
334#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
335#if defined(JSON_HEDLEY_VERSION)
336 #undef JSON_HEDLEY_VERSION
338#define JSON_HEDLEY_VERSION 15
340#if defined(JSON_HEDLEY_STRINGIFY_EX)
341 #undef JSON_HEDLEY_STRINGIFY_EX
343#define JSON_HEDLEY_STRINGIFY_EX(x) #x
345#if defined(JSON_HEDLEY_STRINGIFY)
346 #undef JSON_HEDLEY_STRINGIFY
348#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
350#if defined(JSON_HEDLEY_CONCAT_EX)
351 #undef JSON_HEDLEY_CONCAT_EX
353#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
355#if defined(JSON_HEDLEY_CONCAT)
356 #undef JSON_HEDLEY_CONCAT
358#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
360#if defined(JSON_HEDLEY_CONCAT3_EX)
361 #undef JSON_HEDLEY_CONCAT3_EX
363#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
365#if defined(JSON_HEDLEY_CONCAT3)
366 #undef JSON_HEDLEY_CONCAT3
368#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
370#if defined(JSON_HEDLEY_VERSION_ENCODE)
371 #undef JSON_HEDLEY_VERSION_ENCODE
373#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
375#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
376 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
378#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
380#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
381 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
383#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
385#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
386 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
388#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
390#if defined(JSON_HEDLEY_GNUC_VERSION)
391 #undef JSON_HEDLEY_GNUC_VERSION
393#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
394 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
395#elif defined(__GNUC__)
396 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
399#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
400 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
402#if defined(JSON_HEDLEY_GNUC_VERSION)
403 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
405 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
408#if defined(JSON_HEDLEY_MSVC_VERSION)
409 #undef JSON_HEDLEY_MSVC_VERSION
411#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
412 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
413#elif defined(_MSC_FULL_VER) && !defined(__ICL)
414 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
415#elif defined(_MSC_VER) && !defined(__ICL)
416 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
419#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
420 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
422#if !defined(JSON_HEDLEY_MSVC_VERSION)
423 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
424#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
425 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
426#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
427 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
429 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
432#if defined(JSON_HEDLEY_INTEL_VERSION)
433 #undef JSON_HEDLEY_INTEL_VERSION
435#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
436 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
437#elif defined(__INTEL_COMPILER) && !defined(__ICL)
438 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
441#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
442 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
444#if defined(JSON_HEDLEY_INTEL_VERSION)
445 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
447 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
450#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
451 #undef JSON_HEDLEY_INTEL_CL_VERSION
453#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
454 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
457#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
458 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
460#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
461 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
463 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
466#if defined(JSON_HEDLEY_PGI_VERSION)
467 #undef JSON_HEDLEY_PGI_VERSION
469#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
470 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
473#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
474 #undef JSON_HEDLEY_PGI_VERSION_CHECK
476#if defined(JSON_HEDLEY_PGI_VERSION)
477 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
479 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
482#if defined(JSON_HEDLEY_SUNPRO_VERSION)
483 #undef JSON_HEDLEY_SUNPRO_VERSION
485#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
486 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10)
487#elif defined(__SUNPRO_C)
488 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
489#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
490 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10)
491#elif defined(__SUNPRO_CC)
492 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
495#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
496 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
498#if defined(JSON_HEDLEY_SUNPRO_VERSION)
499 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
501 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
504#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
505 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
507#if defined(__EMSCRIPTEN__)
508 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
511#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
512 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
514#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
515 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
517 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
520#if defined(JSON_HEDLEY_ARM_VERSION)
521 #undef JSON_HEDLEY_ARM_VERSION
523#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
524 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
525#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
526 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
529#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
530 #undef JSON_HEDLEY_ARM_VERSION_CHECK
532#if defined(JSON_HEDLEY_ARM_VERSION)
533 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
535 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
538#if defined(JSON_HEDLEY_IBM_VERSION)
539 #undef JSON_HEDLEY_IBM_VERSION
541#if defined(__ibmxl__)
542 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
543#elif defined(__xlC__) && defined(__xlC_ver__)
544 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
545#elif defined(__xlC__)
546 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
549#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
550 #undef JSON_HEDLEY_IBM_VERSION_CHECK
552#if defined(JSON_HEDLEY_IBM_VERSION)
553 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
555 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
558#if defined(JSON_HEDLEY_TI_VERSION)
559 #undef JSON_HEDLEY_TI_VERSION
562 defined(__TI_COMPILER_VERSION__) && \
564 defined(__TMS470__) || defined(__TI_ARM__) || \
565 defined(__MSP430__) || \
566 defined(__TMS320C2000__) \
568#if (__TI_COMPILER_VERSION__ >= 16000000)
569 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
573#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
574 #undef JSON_HEDLEY_TI_VERSION_CHECK
576#if defined(JSON_HEDLEY_TI_VERSION)
577 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
579 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
582#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
583 #undef JSON_HEDLEY_TI_CL2000_VERSION
585#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
586 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
589#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
590 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
592#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
593 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
595 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
598#if defined(JSON_HEDLEY_TI_CL430_VERSION)
599 #undef JSON_HEDLEY_TI_CL430_VERSION
601#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
602 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
605#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
606 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
608#if defined(JSON_HEDLEY_TI_CL430_VERSION)
609 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
611 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
614#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
615 #undef JSON_HEDLEY_TI_ARMCL_VERSION
617#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
618 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
621#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
622 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
624#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
625 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
627 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
630#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
631 #undef JSON_HEDLEY_TI_CL6X_VERSION
633#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
634 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
637#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
638 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
640#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
641 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
643 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
646#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
647 #undef JSON_HEDLEY_TI_CL7X_VERSION
649#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
650 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
653#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
654 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
656#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
657 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
659 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
662#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
663 #undef JSON_HEDLEY_TI_CLPRU_VERSION
665#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
666 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
669#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
670 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
672#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
673 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
675 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
678#if defined(JSON_HEDLEY_CRAY_VERSION)
679 #undef JSON_HEDLEY_CRAY_VERSION
682 #if defined(_RELEASE_PATCHLEVEL)
683 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
685 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
689#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
690 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
692#if defined(JSON_HEDLEY_CRAY_VERSION)
693 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
695 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
698#if defined(JSON_HEDLEY_IAR_VERSION)
699 #undef JSON_HEDLEY_IAR_VERSION
701#if defined(__IAR_SYSTEMS_ICC__)
703 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
705 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
709#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
710 #undef JSON_HEDLEY_IAR_VERSION_CHECK
712#if defined(JSON_HEDLEY_IAR_VERSION)
713 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
715 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
718#if defined(JSON_HEDLEY_TINYC_VERSION)
719 #undef JSON_HEDLEY_TINYC_VERSION
721#if defined(__TINYC__)
722 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
725#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
726 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
728#if defined(JSON_HEDLEY_TINYC_VERSION)
729 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
731 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
734#if defined(JSON_HEDLEY_DMC_VERSION)
735 #undef JSON_HEDLEY_DMC_VERSION
738 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
741#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
742 #undef JSON_HEDLEY_DMC_VERSION_CHECK
744#if defined(JSON_HEDLEY_DMC_VERSION)
745 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
747 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
750#if defined(JSON_HEDLEY_COMPCERT_VERSION)
751 #undef JSON_HEDLEY_COMPCERT_VERSION
753#if defined(__COMPCERT_VERSION__)
754 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
757#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
758 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
760#if defined(JSON_HEDLEY_COMPCERT_VERSION)
761 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
763 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
766#if defined(JSON_HEDLEY_PELLES_VERSION)
767 #undef JSON_HEDLEY_PELLES_VERSION
770 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
773#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
774 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
776#if defined(JSON_HEDLEY_PELLES_VERSION)
777 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
779 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
782#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
783 #undef JSON_HEDLEY_MCST_LCC_VERSION
785#if defined(__LCC__) && defined(__LCC_MINOR__)
786 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
789#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
790 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
792#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
793 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
795 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
798#if defined(JSON_HEDLEY_GCC_VERSION)
799 #undef JSON_HEDLEY_GCC_VERSION
802 defined(JSON_HEDLEY_GNUC_VERSION) && \
803 !defined(__clang__) && \
804 !defined(JSON_HEDLEY_INTEL_VERSION) && \
805 !defined(JSON_HEDLEY_PGI_VERSION) && \
806 !defined(JSON_HEDLEY_ARM_VERSION) && \
807 !defined(JSON_HEDLEY_CRAY_VERSION) && \
808 !defined(JSON_HEDLEY_TI_VERSION) && \
809 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
810 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
811 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
812 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
813 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
814 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
815 !defined(__COMPCERT__) && \
816 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
817 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
820#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
821 #undef JSON_HEDLEY_GCC_VERSION_CHECK
823#if defined(JSON_HEDLEY_GCC_VERSION)
824 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
826 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
829#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
830 #undef JSON_HEDLEY_HAS_ATTRIBUTE
833 defined(__has_attribute) && \
835 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
837# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
839# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
842#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
843 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
845#if defined(__has_attribute)
846 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
848 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
851#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
852 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
854#if defined(__has_attribute)
855 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
857 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
860#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
861 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
864 defined(__has_cpp_attribute) && \
865 defined(__cplusplus) && \
866 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
867 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
869 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
872#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
873 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
875#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
876 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
878 !defined(JSON_HEDLEY_PGI_VERSION) && \
879 !defined(JSON_HEDLEY_IAR_VERSION) && \
880 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
881 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
882 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
884 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
887#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
888 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
890#if defined(__has_cpp_attribute) && defined(__cplusplus)
891 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
893 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
896#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
897 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
899#if defined(__has_cpp_attribute) && defined(__cplusplus)
900 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
902 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
905#if defined(JSON_HEDLEY_HAS_BUILTIN)
906 #undef JSON_HEDLEY_HAS_BUILTIN
908#if defined(__has_builtin)
909 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
911 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
914#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
915 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
917#if defined(__has_builtin)
918 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
920 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
923#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
924 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
926#if defined(__has_builtin)
927 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
929 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
932#if defined(JSON_HEDLEY_HAS_FEATURE)
933 #undef JSON_HEDLEY_HAS_FEATURE
935#if defined(__has_feature)
936 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
938 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
941#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
942 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
944#if defined(__has_feature)
945 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
947 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
950#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
951 #undef JSON_HEDLEY_GCC_HAS_FEATURE
953#if defined(__has_feature)
954 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
956 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
959#if defined(JSON_HEDLEY_HAS_EXTENSION)
960 #undef JSON_HEDLEY_HAS_EXTENSION
962#if defined(__has_extension)
963 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
965 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
968#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
969 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
971#if defined(__has_extension)
972 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
974 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
977#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
978 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
980#if defined(__has_extension)
981 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
983 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
986#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
987 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
989#if defined(__has_declspec_attribute)
990 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
992 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
995#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
996 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
998#if defined(__has_declspec_attribute)
999 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1001 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1004#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
1005 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
1007#if defined(__has_declspec_attribute)
1008 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
1010 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1013#if defined(JSON_HEDLEY_HAS_WARNING)
1014 #undef JSON_HEDLEY_HAS_WARNING
1016#if defined(__has_warning)
1017 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
1019 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
1022#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
1023 #undef JSON_HEDLEY_GNUC_HAS_WARNING
1025#if defined(__has_warning)
1026 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1028 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
1031#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
1032 #undef JSON_HEDLEY_GCC_HAS_WARNING
1034#if defined(__has_warning)
1035 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
1037 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
1041 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1042 defined(__clang__) || \
1043 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1044 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1045 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1046 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
1047 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1048 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1049 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1050 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1051 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1052 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
1053 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1054 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1055 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
1056 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
1057 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
1058 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
1059 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
1060#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1061 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
1063 #define JSON_HEDLEY_PRAGMA(value)
1066#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
1067 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
1069#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
1070 #undef JSON_HEDLEY_DIAGNOSTIC_POP
1072#if defined(__clang__)
1073 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
1074 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
1075#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1076 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1077 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1078#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1079 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
1080 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
1082 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
1083 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1084 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
1085 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
1086#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
1087 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
1088 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
1090 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1091 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1092 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
1093 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1094 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1095 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1096 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
1097 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
1098#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1099 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
1100 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
1102 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
1103 #define JSON_HEDLEY_DIAGNOSTIC_POP
1108#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1109 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
1111#if defined(__cplusplus)
1112# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
1113# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
1114# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
1115# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1116 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1117 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1118 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1119 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
1121 JSON_HEDLEY_DIAGNOSTIC_POP
1123# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1124 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1125 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1126 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
1128 JSON_HEDLEY_DIAGNOSTIC_POP
1131# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
1132 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1133 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
1135 JSON_HEDLEY_DIAGNOSTIC_POP
1139#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
1140 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
1143#if defined(JSON_HEDLEY_CONST_CAST)
1144 #undef JSON_HEDLEY_CONST_CAST
1146#if defined(__cplusplus)
1147# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1149 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1150 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1151 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1152# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1153 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1154 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1156 JSON_HEDLEY_DIAGNOSTIC_POP \
1159# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1162#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1163 #undef JSON_HEDLEY_REINTERPRET_CAST
1165#if defined(__cplusplus)
1166 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1168 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1171#if defined(JSON_HEDLEY_STATIC_CAST)
1172 #undef JSON_HEDLEY_STATIC_CAST
1174#if defined(__cplusplus)
1175 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1177 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1180#if defined(JSON_HEDLEY_CPP_CAST)
1181 #undef JSON_HEDLEY_CPP_CAST
1183#if defined(__cplusplus)
1184# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1185# define JSON_HEDLEY_CPP_CAST(T, expr) \
1186 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1187 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1189 JSON_HEDLEY_DIAGNOSTIC_POP
1190# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1191# define JSON_HEDLEY_CPP_CAST(T, expr) \
1192 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1193 _Pragma("diag_suppress=Pe137") \
1194 JSON_HEDLEY_DIAGNOSTIC_POP
1196# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1199# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1202#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1203 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1205#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1206 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1207#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1208 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1209#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1210 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1211#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1212 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1213#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1214 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1215#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1216 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1217#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1218 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1219#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1220 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1222 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1223 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1225 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1226 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1227 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1228 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1229 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1230 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1231 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1232 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1233 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1234#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1235 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1236#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1237 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1238#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1239 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1240#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1241 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1243 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1246#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1247 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1249#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1250 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1251#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1252 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1253#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1254 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1255#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1256 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1257#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1258 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1259#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1260 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1262 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1263 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1264 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1265 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1266 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1267#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1268 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1269#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1270 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1271#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1272 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1274 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1277#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1278 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1280#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1281 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1282#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1283 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1284#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1285 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1286#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1287 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1288#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1289 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1290#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1291 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1292#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1293 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1294#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1295 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1297 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1298 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1299 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1300 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1301#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1302 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1303#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1304 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1306 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1309#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1310 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1312#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1313 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1314#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1315 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1316#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1317 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1319 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1322#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1323 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1325#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1326 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1327#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1328 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1329#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1330 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1331#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1332 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1334 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1337#if defined(JSON_HEDLEY_DEPRECATED)
1338 #undef JSON_HEDLEY_DEPRECATED
1340#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1341 #undef JSON_HEDLEY_DEPRECATED_FOR
1344 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1345 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1346 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1347 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1349 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1350 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1351 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1352 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1353 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1354 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1355 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1356 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1357 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1358 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1359 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1360 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1361 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1362 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1363#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1364 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1365 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1367 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1368 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1369 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1370 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1371 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1372 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1373 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1374 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1375 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1376 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1377 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1378 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1379 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1380 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1381 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1382 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1383 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1384 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1386 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1387 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1388 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1389 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1390 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1391#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1392 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1393 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1395 #define JSON_HEDLEY_DEPRECATED(since)
1396 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1399#if defined(JSON_HEDLEY_UNAVAILABLE)
1400 #undef JSON_HEDLEY_UNAVAILABLE
1403 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1404 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1405 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1406 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1407 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1409 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1412#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1413 #undef JSON_HEDLEY_WARN_UNUSED_RESULT
1415#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1416 #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1419 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1420 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1421 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1422 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1423 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1424 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1425 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1426 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1427 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1428 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1429 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1430 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1431 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1432 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1433 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1434 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1435 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1436 #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1437 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1438#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1439 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1440 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1441#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1442 #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1443 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1444#elif defined(_Check_return_)
1445 #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1446 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1448 #define JSON_HEDLEY_WARN_UNUSED_RESULT
1449 #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1452#if defined(JSON_HEDLEY_SENTINEL)
1453 #undef JSON_HEDLEY_SENTINEL
1456 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1457 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1458 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1459 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1460 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1461 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1463 #define JSON_HEDLEY_SENTINEL(position)
1466#if defined(JSON_HEDLEY_NO_RETURN)
1467 #undef JSON_HEDLEY_NO_RETURN
1469#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1470 #define JSON_HEDLEY_NO_RETURN __noreturn
1472 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1473 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1474 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1475#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1476 #define JSON_HEDLEY_NO_RETURN _Noreturn
1477#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1478 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1480 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1481 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1482 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1483 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1484 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1485 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1486 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1487 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1488 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1489 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1490 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1491 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1492 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1493 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1494 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1495 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1496 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1497 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1498#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1499 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1501 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1502 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1503 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1504#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1505 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1506#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1507 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1508#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1509 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1511 #define JSON_HEDLEY_NO_RETURN
1514#if defined(JSON_HEDLEY_NO_ESCAPE)
1515 #undef JSON_HEDLEY_NO_ESCAPE
1517#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1518 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1520 #define JSON_HEDLEY_NO_ESCAPE
1523#if defined(JSON_HEDLEY_UNREACHABLE)
1524 #undef JSON_HEDLEY_UNREACHABLE
1526#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1527 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1529#if defined(JSON_HEDLEY_ASSUME)
1530 #undef JSON_HEDLEY_ASSUME
1533 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1534 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1535 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1536 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1537#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1538 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1540 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1541 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1542 #if defined(__cplusplus)
1543 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1545 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1549 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1550 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1551 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1552 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1553 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1554 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1555 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1556 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1557#elif defined(JSON_HEDLEY_ASSUME)
1558 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1560#if !defined(JSON_HEDLEY_ASSUME)
1561 #if defined(JSON_HEDLEY_UNREACHABLE)
1562 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1564 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1567#if defined(JSON_HEDLEY_UNREACHABLE)
1569 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1570 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1571 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1573 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1576 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1578#if !defined(JSON_HEDLEY_UNREACHABLE)
1579 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1582JSON_HEDLEY_DIAGNOSTIC_PUSH
1583#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1584 #pragma clang diagnostic ignored "-Wpedantic"
1586#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1587 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1589#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1590 #if defined(__clang__)
1591 #pragma clang diagnostic ignored "-Wvariadic-macros"
1592 #elif defined(JSON_HEDLEY_GCC_VERSION)
1593 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1596#if defined(JSON_HEDLEY_NON_NULL)
1597 #undef JSON_HEDLEY_NON_NULL
1600 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1601 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1602 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1603 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1604 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1606 #define JSON_HEDLEY_NON_NULL(...)
1608JSON_HEDLEY_DIAGNOSTIC_POP
1610#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1611 #undef JSON_HEDLEY_PRINTF_FORMAT
1613#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1614 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1615#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1616 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1618 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1619 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1620 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1621 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1622 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1623 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1624 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1625 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1626 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1627 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1628 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1629 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1630 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1631 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1632 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1633 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1634 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1635 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1636#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1637 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1639 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1642#if defined(JSON_HEDLEY_CONSTEXPR)
1643 #undef JSON_HEDLEY_CONSTEXPR
1645#if defined(__cplusplus)
1646 #if __cplusplus >= 201103L
1647 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1650#if !defined(JSON_HEDLEY_CONSTEXPR)
1651 #define JSON_HEDLEY_CONSTEXPR
1654#if defined(JSON_HEDLEY_PREDICT)
1655 #undef JSON_HEDLEY_PREDICT
1657#if defined(JSON_HEDLEY_LIKELY)
1658 #undef JSON_HEDLEY_LIKELY
1660#if defined(JSON_HEDLEY_UNLIKELY)
1661 #undef JSON_HEDLEY_UNLIKELY
1663#if defined(JSON_HEDLEY_UNPREDICTABLE)
1664 #undef JSON_HEDLEY_UNPREDICTABLE
1666#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1667 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1670 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1671 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1672 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1673# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1674# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1675# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1676# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1677# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1679 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1680 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1681 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1682 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1683 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1684 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1685 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1686 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1687 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1688 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1689 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1690 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1691 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1692 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1693 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1694 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1695# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1696 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1697# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1699 double hedley_probability_ = (probability); \
1700 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1702# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1704 double hedley_probability_ = (probability); \
1705 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1707# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1708# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1710# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1711# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1712# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1713# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1714# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1716#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1717 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1720#if defined(JSON_HEDLEY_MALLOC)
1721 #undef JSON_HEDLEY_MALLOC
1724 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1725 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1726 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1727 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1728 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1729 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1730 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1731 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1732 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1733 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1734 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1735 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1736 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1737 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1738 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1739 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1740 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1741 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1742 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1743#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1744 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1746 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1747 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1748 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1750 #define JSON_HEDLEY_MALLOC
1753#if defined(JSON_HEDLEY_PURE)
1754 #undef JSON_HEDLEY_PURE
1757 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1758 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1759 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1760 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1761 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1762 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1763 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1764 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1765 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1766 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1767 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1768 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1769 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1770 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1771 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1772 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1773 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1774 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1775 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1776# define JSON_HEDLEY_PURE __attribute__((__pure__))
1777#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1778# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1779#elif defined(__cplusplus) && \
1781 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1782 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1783 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1785# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1787# define JSON_HEDLEY_PURE
1790#if defined(JSON_HEDLEY_CONST)
1791 #undef JSON_HEDLEY_CONST
1794 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1795 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1796 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1797 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1798 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1799 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1800 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1801 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1802 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1803 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1804 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1805 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1806 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1807 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1808 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1809 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1810 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1811 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1812 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1813 #define JSON_HEDLEY_CONST __attribute__((__const__))
1815 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1816 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1818 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1821#if defined(JSON_HEDLEY_RESTRICT)
1822 #undef JSON_HEDLEY_RESTRICT
1824#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1825 #define JSON_HEDLEY_RESTRICT restrict
1827 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1828 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1829 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1830 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1831 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1832 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1833 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1834 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1835 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1836 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1837 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1838 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1839 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1840 defined(__clang__) || \
1841 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1842 #define JSON_HEDLEY_RESTRICT __restrict
1843#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1844 #define JSON_HEDLEY_RESTRICT _Restrict
1846 #define JSON_HEDLEY_RESTRICT
1849#if defined(JSON_HEDLEY_INLINE)
1850 #undef JSON_HEDLEY_INLINE
1853 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1854 (defined(__cplusplus) && (__cplusplus >= 199711L))
1855 #define JSON_HEDLEY_INLINE inline
1857 defined(JSON_HEDLEY_GCC_VERSION) || \
1858 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1859 #define JSON_HEDLEY_INLINE __inline__
1861 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1862 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1863 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1864 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1865 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1866 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1867 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1868 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1869 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1870 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1871 #define JSON_HEDLEY_INLINE __inline
1873 #define JSON_HEDLEY_INLINE
1876#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1877 #undef JSON_HEDLEY_ALWAYS_INLINE
1880 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1881 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1882 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1883 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1884 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1885 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1886 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1887 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1888 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1889 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1890 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1891 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1892 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1893 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1894 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1895 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1896 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1897 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1898 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1899# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1901 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1902 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1903# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1904#elif defined(__cplusplus) && \
1906 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1907 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1908 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1909 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1910 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1911 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1913# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1914#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1915# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1917# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1920#if defined(JSON_HEDLEY_NEVER_INLINE)
1921 #undef JSON_HEDLEY_NEVER_INLINE
1924 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1925 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1926 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1927 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1928 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1929 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1930 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1931 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1932 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1933 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1934 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1935 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1936 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1937 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1938 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1939 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1940 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1941 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1942 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1943 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1945 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1946 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1947 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1948#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1949 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1950#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1951 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1952#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1953 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1954#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1955 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1956#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1957 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1959 #define JSON_HEDLEY_NEVER_INLINE
1962#if defined(JSON_HEDLEY_PRIVATE)
1963 #undef JSON_HEDLEY_PRIVATE
1965#if defined(JSON_HEDLEY_PUBLIC)
1966 #undef JSON_HEDLEY_PUBLIC
1968#if defined(JSON_HEDLEY_IMPORT)
1969 #undef JSON_HEDLEY_IMPORT
1971#if defined(_WIN32) || defined(__CYGWIN__)
1972# define JSON_HEDLEY_PRIVATE
1973# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1974# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1977 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1978 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1979 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1980 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1981 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1982 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1984 defined(__TI_EABI__) && \
1986 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1987 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1990 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1991# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1992# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1994# define JSON_HEDLEY_PRIVATE
1995# define JSON_HEDLEY_PUBLIC
1997# define JSON_HEDLEY_IMPORT extern
2000#if defined(JSON_HEDLEY_NO_THROW)
2001 #undef JSON_HEDLEY_NO_THROW
2004 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
2005 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
2006 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2007 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2008 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
2010 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
2011 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
2012 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
2013 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
2015 #define JSON_HEDLEY_NO_THROW
2018#if defined(JSON_HEDLEY_FALL_THROUGH)
2019 #undef JSON_HEDLEY_FALL_THROUGH
2022 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
2023 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
2024 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2025 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
2026#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
2027 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
2028#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
2029 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
2030#elif defined(__fallthrough)
2031 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
2033 #define JSON_HEDLEY_FALL_THROUGH
2036#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
2037 #undef JSON_HEDLEY_RETURNS_NON_NULL
2040 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
2041 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2042 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2043 #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
2044#elif defined(_Ret_notnull_)
2045 #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
2047 #define JSON_HEDLEY_RETURNS_NON_NULL
2050#if defined(JSON_HEDLEY_ARRAY_PARAM)
2051 #undef JSON_HEDLEY_ARRAY_PARAM
2054 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
2055 !defined(__STDC_NO_VLA__) && \
2056 !defined(__cplusplus) && \
2057 !defined(JSON_HEDLEY_PGI_VERSION) && \
2058 !defined(JSON_HEDLEY_TINYC_VERSION)
2059 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
2061 #define JSON_HEDLEY_ARRAY_PARAM(name)
2064#if defined(JSON_HEDLEY_IS_CONSTANT)
2065 #undef JSON_HEDLEY_IS_CONSTANT
2067#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
2068 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
2072#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2073 #undef JSON_HEDLEY_IS_CONSTEXPR_
2076 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
2077 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2078 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2079 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
2080 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
2081 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2082 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
2083 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
2084 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2085 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
2086 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
2088#if !defined(__cplusplus)
2090 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
2091 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
2092 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2093 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
2094 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
2095 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
2096 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
2097#if defined(__INTPTR_TYPE__)
2098 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
2101 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
2105 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
2106 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
2107 !defined(JSON_HEDLEY_PGI_VERSION) && \
2108 !defined(JSON_HEDLEY_IAR_VERSION)) || \
2109 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
2110 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
2111 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
2112 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
2113 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
2114#if defined(__INTPTR_TYPE__)
2115 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
2118 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
2121 defined(JSON_HEDLEY_GCC_VERSION) || \
2122 defined(JSON_HEDLEY_INTEL_VERSION) || \
2123 defined(JSON_HEDLEY_TINYC_VERSION) || \
2124 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
2125 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
2126 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
2127 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
2128 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
2129 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
2131# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
2135 ((void*) ((expr) * 0L) ) : \
2136((struct { char v[sizeof(void) * 2]; } *) 1) \
2142#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
2143 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2144 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
2146 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2148 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2149 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2151 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2154#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2155 #undef JSON_HEDLEY_BEGIN_C_DECLS
2157#if defined(JSON_HEDLEY_END_C_DECLS)
2158 #undef JSON_HEDLEY_END_C_DECLS
2160#if defined(JSON_HEDLEY_C_DECL)
2161 #undef JSON_HEDLEY_C_DECL
2163#if defined(__cplusplus)
2164 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2165 #define JSON_HEDLEY_END_C_DECLS }
2166 #define JSON_HEDLEY_C_DECL extern "C"
2168 #define JSON_HEDLEY_BEGIN_C_DECLS
2169 #define JSON_HEDLEY_END_C_DECLS
2170 #define JSON_HEDLEY_C_DECL
2173#if defined(JSON_HEDLEY_STATIC_ASSERT)
2174 #undef JSON_HEDLEY_STATIC_ASSERT
2177 !defined(__cplusplus) && ( \
2178 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2179 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2180 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2181 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2182 defined(_Static_assert) \
2184# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2186 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2187 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2188 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2189# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2191# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2194#if defined(JSON_HEDLEY_NULL)
2195 #undef JSON_HEDLEY_NULL
2197#if defined(__cplusplus)
2198 #if __cplusplus >= 201103L
2199 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2201 #define JSON_HEDLEY_NULL NULL
2203 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2206 #define JSON_HEDLEY_NULL NULL
2208 #define JSON_HEDLEY_NULL ((void*) 0)
2211#if defined(JSON_HEDLEY_MESSAGE)
2212 #undef JSON_HEDLEY_MESSAGE
2214#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2215# define JSON_HEDLEY_MESSAGE(msg) \
2216 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2217 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2218 JSON_HEDLEY_PRAGMA(message msg) \
2219 JSON_HEDLEY_DIAGNOSTIC_POP
2221 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2222 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2223# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2224#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2225# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2226#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2227# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2228#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2229# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2231# define JSON_HEDLEY_MESSAGE(msg)
2234#if defined(JSON_HEDLEY_WARNING)
2235 #undef JSON_HEDLEY_WARNING
2237#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2238# define JSON_HEDLEY_WARNING(msg) \
2239 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2240 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2241 JSON_HEDLEY_PRAGMA(clang warning msg) \
2242 JSON_HEDLEY_DIAGNOSTIC_POP
2244 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2245 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2246 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2247# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2249 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2250 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2251# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2253# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2256#if defined(JSON_HEDLEY_REQUIRE)
2257 #undef JSON_HEDLEY_REQUIRE
2259#if defined(JSON_HEDLEY_REQUIRE_MSG)
2260 #undef JSON_HEDLEY_REQUIRE_MSG
2262#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2263# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2264# define JSON_HEDLEY_REQUIRE(expr) \
2265 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2266 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2267 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2268 JSON_HEDLEY_DIAGNOSTIC_POP
2269# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2270 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2271 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2272 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2273 JSON_HEDLEY_DIAGNOSTIC_POP
2275# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2276# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2279# define JSON_HEDLEY_REQUIRE(expr)
2280# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2283#if defined(JSON_HEDLEY_FLAGS)
2284 #undef JSON_HEDLEY_FLAGS
2286#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2287 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2289 #define JSON_HEDLEY_FLAGS
2292#if defined(JSON_HEDLEY_FLAGS_CAST)
2293 #undef JSON_HEDLEY_FLAGS_CAST
2295#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2296# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2297 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2298 _Pragma("warning(disable:188)") \
2300 JSON_HEDLEY_DIAGNOSTIC_POP \
2303# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2306#if defined(JSON_HEDLEY_EMPTY_BASES)
2307 #undef JSON_HEDLEY_EMPTY_BASES
2310 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2311 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2312 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2314 #define JSON_HEDLEY_EMPTY_BASES
2319#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2320 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2322#if defined(__clang__)
2323 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2325 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2328#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2329 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2331#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2333#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2334 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2336#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2338#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2339 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2341#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2343#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2344 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2346#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2348#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2349 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2351#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2353#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2354 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2356#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2358#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2359 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2361#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2373#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2374 #if defined(__clang__)
2375 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2376 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2378 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2379 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2380 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2387#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2388 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2389 #define JSON_HAS_CPP_20
2390 #define JSON_HAS_CPP_17
2391 #define JSON_HAS_CPP_14
2392 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2393 #define JSON_HAS_CPP_17
2394 #define JSON_HAS_CPP_14
2395 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2396 #define JSON_HAS_CPP_14
2399 #define JSON_HAS_CPP_11
2403 #if __has_include(<version>)
2408#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM)
2409 #ifdef JSON_HAS_CPP_17
2410 #if defined(__cpp_lib_filesystem)
2411 #define JSON_HAS_FILESYSTEM 1
2412 #elif defined(__cpp_lib_experimental_filesystem)
2413 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2414 #elif !defined(__has_include)
2415 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2416 #elif __has_include(<filesystem>)
2417 #define JSON_HAS_FILESYSTEM 1
2418 #elif __has_include(<experimental/filesystem>)
2419 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1
2423 #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8
2424 #undef JSON_HAS_FILESYSTEM
2425 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2429 #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8
2430 #undef JSON_HAS_FILESYSTEM
2431 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2435 #if defined(__clang_major__) && __clang_major__ < 7
2436 #undef JSON_HAS_FILESYSTEM
2437 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2441 #if defined(_MSC_VER) && _MSC_VER < 1914
2442 #undef JSON_HAS_FILESYSTEM
2443 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2447 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000
2448 #undef JSON_HAS_FILESYSTEM
2449 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2453 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
2454 #undef JSON_HAS_FILESYSTEM
2455 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2460#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM
2461 #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0
2464#ifndef JSON_HAS_FILESYSTEM
2465 #define JSON_HAS_FILESYSTEM 0
2468#ifndef JSON_HAS_THREE_WAY_COMPARISON
2469 #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \
2470 && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L
2471 #define JSON_HAS_THREE_WAY_COMPARISON 1
2473 #define JSON_HAS_THREE_WAY_COMPARISON 0
2477#ifndef JSON_HAS_RANGES
2479 #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
2480 #define JSON_HAS_RANGES 0
2481 #elif defined(__cpp_lib_ranges)
2482 #define JSON_HAS_RANGES 1
2484 #define JSON_HAS_RANGES 0
2488#ifndef JSON_HAS_STATIC_RTTI
2489 #if !defined(_HAS_STATIC_RTTI) || _HAS_STATIC_RTTI != 0
2490 #define JSON_HAS_STATIC_RTTI 1
2492 #define JSON_HAS_STATIC_RTTI 0
2496#ifdef JSON_HAS_CPP_17
2497 #define JSON_INLINE_VARIABLE inline
2499 #define JSON_INLINE_VARIABLE
2502#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2503 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2505 #define JSON_NO_UNIQUE_ADDRESS
2509#if defined(__clang__)
2510 #pragma clang diagnostic push
2511 #pragma clang diagnostic ignored "-Wdocumentation"
2512 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2516#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2517 #define JSON_THROW(exception) throw exception
2518 #define JSON_TRY try
2519 #define JSON_CATCH(exception) catch(exception)
2520 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2523 #define JSON_THROW(exception) std::abort()
2524 #define JSON_TRY if(true)
2525 #define JSON_CATCH(exception) if(false)
2526 #define JSON_INTERNAL_CATCH(exception) if(false)
2530#if defined(JSON_THROW_USER)
2532 #define JSON_THROW JSON_THROW_USER
2534#if defined(JSON_TRY_USER)
2536 #define JSON_TRY JSON_TRY_USER
2538#if defined(JSON_CATCH_USER)
2540 #define JSON_CATCH JSON_CATCH_USER
2541 #undef JSON_INTERNAL_CATCH
2542 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2544#if defined(JSON_INTERNAL_CATCH_USER)
2545 #undef JSON_INTERNAL_CATCH
2546 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2550#if !defined(JSON_ASSERT)
2552 #define JSON_ASSERT(x) assert(x)
2556#if defined(JSON_TESTS_PRIVATE)
2557 #define JSON_PRIVATE_UNLESS_TESTED public
2559 #define JSON_PRIVATE_UNLESS_TESTED private
2567#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2568 template<typename BasicJsonType> \
2569 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2571 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2572 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2573 auto it = std::find_if(std::begin(m), std::end(m), \
2574 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2576 return ej_pair.first == e; \
2578 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2580 template<typename BasicJsonType> \
2581 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2583 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2584 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2585 auto it = std::find_if(std::begin(m), std::end(m), \
2586 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2588 return ej_pair.second == j; \
2590 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2596#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2597 template<template<typename, typename, typename...> class ObjectType, \
2598 template<typename, typename...> class ArrayType, \
2599 class StringType, class BooleanType, class NumberIntegerType, \
2600 class NumberUnsignedType, class NumberFloatType, \
2601 template<typename> class AllocatorType, \
2602 template<typename, typename = void> class JSONSerializer, \
2604 class CustomBaseClass>
2606#define NLOHMANN_BASIC_JSON_TPL \
2607 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2608 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2609 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2613#define NLOHMANN_JSON_EXPAND( x ) x
2614#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME
2615#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2616 NLOHMANN_JSON_PASTE64, \
2617 NLOHMANN_JSON_PASTE63, \
2618 NLOHMANN_JSON_PASTE62, \
2619 NLOHMANN_JSON_PASTE61, \
2620 NLOHMANN_JSON_PASTE60, \
2621 NLOHMANN_JSON_PASTE59, \
2622 NLOHMANN_JSON_PASTE58, \
2623 NLOHMANN_JSON_PASTE57, \
2624 NLOHMANN_JSON_PASTE56, \
2625 NLOHMANN_JSON_PASTE55, \
2626 NLOHMANN_JSON_PASTE54, \
2627 NLOHMANN_JSON_PASTE53, \
2628 NLOHMANN_JSON_PASTE52, \
2629 NLOHMANN_JSON_PASTE51, \
2630 NLOHMANN_JSON_PASTE50, \
2631 NLOHMANN_JSON_PASTE49, \
2632 NLOHMANN_JSON_PASTE48, \
2633 NLOHMANN_JSON_PASTE47, \
2634 NLOHMANN_JSON_PASTE46, \
2635 NLOHMANN_JSON_PASTE45, \
2636 NLOHMANN_JSON_PASTE44, \
2637 NLOHMANN_JSON_PASTE43, \
2638 NLOHMANN_JSON_PASTE42, \
2639 NLOHMANN_JSON_PASTE41, \
2640 NLOHMANN_JSON_PASTE40, \
2641 NLOHMANN_JSON_PASTE39, \
2642 NLOHMANN_JSON_PASTE38, \
2643 NLOHMANN_JSON_PASTE37, \
2644 NLOHMANN_JSON_PASTE36, \
2645 NLOHMANN_JSON_PASTE35, \
2646 NLOHMANN_JSON_PASTE34, \
2647 NLOHMANN_JSON_PASTE33, \
2648 NLOHMANN_JSON_PASTE32, \
2649 NLOHMANN_JSON_PASTE31, \
2650 NLOHMANN_JSON_PASTE30, \
2651 NLOHMANN_JSON_PASTE29, \
2652 NLOHMANN_JSON_PASTE28, \
2653 NLOHMANN_JSON_PASTE27, \
2654 NLOHMANN_JSON_PASTE26, \
2655 NLOHMANN_JSON_PASTE25, \
2656 NLOHMANN_JSON_PASTE24, \
2657 NLOHMANN_JSON_PASTE23, \
2658 NLOHMANN_JSON_PASTE22, \
2659 NLOHMANN_JSON_PASTE21, \
2660 NLOHMANN_JSON_PASTE20, \
2661 NLOHMANN_JSON_PASTE19, \
2662 NLOHMANN_JSON_PASTE18, \
2663 NLOHMANN_JSON_PASTE17, \
2664 NLOHMANN_JSON_PASTE16, \
2665 NLOHMANN_JSON_PASTE15, \
2666 NLOHMANN_JSON_PASTE14, \
2667 NLOHMANN_JSON_PASTE13, \
2668 NLOHMANN_JSON_PASTE12, \
2669 NLOHMANN_JSON_PASTE11, \
2670 NLOHMANN_JSON_PASTE10, \
2671 NLOHMANN_JSON_PASTE9, \
2672 NLOHMANN_JSON_PASTE8, \
2673 NLOHMANN_JSON_PASTE7, \
2674 NLOHMANN_JSON_PASTE6, \
2675 NLOHMANN_JSON_PASTE5, \
2676 NLOHMANN_JSON_PASTE4, \
2677 NLOHMANN_JSON_PASTE3, \
2678 NLOHMANN_JSON_PASTE2, \
2679 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2680#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2681#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2682#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2683#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2684#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2685#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6)
2686#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7)
2687#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8)
2688#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9)
2689#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10)
2690#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11)
2691#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12)
2692#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13)
2693#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14)
2694#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15)
2695#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16)
2696#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17)
2697#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18)
2698#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19)
2699#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20)
2700#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21)
2701#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
2702#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23)
2703#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24)
2704#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25)
2705#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26)
2706#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27)
2707#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28)
2708#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29)
2709#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30)
2710#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31)
2711#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32)
2712#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33)
2713#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34)
2714#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35)
2715#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36)
2716#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37)
2717#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38)
2718#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39)
2719#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40)
2720#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41)
2721#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42)
2722#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43)
2723#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44)
2724#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45)
2725#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46)
2726#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47)
2727#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48)
2728#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49)
2729#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50)
2730#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51)
2731#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52)
2732#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53)
2733#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54)
2734#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55)
2735#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56)
2736#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57)
2737#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58)
2738#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59)
2739#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60)
2740#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61)
2741#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62)
2742#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63)
2744#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2745#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2746#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2753#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2754 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2755 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2757#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2758 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2759 friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2761#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2762 friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2769#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2770 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2771 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) }
2773#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ONLY_SERIALIZE(Type, ...) \
2774 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) }
2776#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2777 inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
2778 inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
2786#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2787 namespace detail { \
2788 using std::std_name; \
2790 template<typename... T> \
2791 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2794 namespace detail2 { \
2795 struct std_name##_tag \
2799 template<typename... T> \
2800 std_name##_tag std_name(T&&...); \
2802 template<typename... T> \
2803 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2805 template<typename... T> \
2806 struct would_call_std_##std_name \
2808 static constexpr auto const value = ::nlohmann::detail:: \
2809 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2813 template<typename... T> \
2814 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2818#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2819 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2822#if JSON_USE_IMPLICIT_CONVERSIONS
2823 #define JSON_EXPLICIT
2825 #define JSON_EXPLICIT explicit
2828#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2829 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2832#ifndef JSON_USE_GLOBAL_UDLS
2833 #define JSON_USE_GLOBAL_UDLS 1
2836#if JSON_HAS_THREE_WAY_COMPARISON
2840NLOHMANN_JSON_NAMESPACE_BEGIN
2899#if JSON_HAS_THREE_WAY_COMPARISON
2900 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
2905 static constexpr std::array<std::uint8_t, 9> order = {{
2912 const auto l_index =
static_cast<std::size_t
>(lhs);
2913 const auto r_index =
static_cast<std::size_t
>(rhs);
2914#if JSON_HAS_THREE_WAY_COMPARISON
2915 if (l_index < order.size() && r_index < order.size())
2917 return order[l_index] <=> order[r_index];
2919 return std::partial_ordering::unordered;
2921 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
2929#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
2932 return std::is_lt(lhs <=> rhs);
2937NLOHMANN_JSON_NAMESPACE_END
2953NLOHMANN_JSON_NAMESPACE_BEGIN
2970template<
typename StringType>
2972 const StringType& t)
2974 JSON_ASSERT(!f.empty());
2975 for (
auto pos = s.find(f);
2976 pos != StringType::npos;
2977 s.replace(pos, f.size(), t),
2978 pos = s.find(f, pos + t.size()))
2989template<
typename StringType>
3004template<
typename StringType>
3005static void unescape(StringType& s)
3012NLOHMANN_JSON_NAMESPACE_END
3030NLOHMANN_JSON_NAMESPACE_BEGIN
3045 constexpr operator size_t()
const
3052NLOHMANN_JSON_NAMESPACE_END
3070#include <type_traits>
3076NLOHMANN_JSON_NAMESPACE_BEGIN
3081using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3083#ifdef JSON_HAS_CPP_14
3086using std::enable_if_t;
3087using std::index_sequence;
3088using std::make_index_sequence;
3089using std::index_sequence_for;
3094template<
bool B,
typename T =
void>
3095using enable_if_t =
typename std::enable_if<B, T>::type;
3121template <
typename T, T... Ints>
3122struct integer_sequence
3124 using value_type = T;
3125 static constexpr std::size_t size() noexcept
3127 return sizeof...(Ints);
3136template <
size_t... Ints>
3137using index_sequence = integer_sequence<size_t, Ints...>;
3139namespace utility_internal
3142template <
typename Seq,
size_t SeqSize,
size_t Rem>
3146template <
typename T, T... Ints,
size_t SeqSize>
3147struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3149 using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3152template <
typename T, T... Ints,
size_t SeqSize>
3153struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3155 using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3160template <
typename T,
size_t N>
3164 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3167template <
typename T>
3170 using type = integer_sequence<T>;
3182template <
typename T, T N>
3183using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3191using make_index_sequence = make_integer_sequence<size_t, N>;
3198template <
typename... Ts>
3199using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3206template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
3207template<>
struct priority_tag<0> {};
3213 static JSON_INLINE_VARIABLE
constexpr T value{};
3216#ifndef JSON_HAS_CPP_17
3217 template<
typename T>
3218 constexpr T static_const<T>::value;
3221template<
typename T,
typename... Args>
3222inline constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3224 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3228NLOHMANN_JSON_NAMESPACE_END
3242#include <type_traits>
3267NLOHMANN_JSON_NAMESPACE_BEGIN
3271template<
typename It,
typename =
void>
3272struct iterator_types {};
3274template<
typename It>
3275struct iterator_types <
3277 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3278 typename It::reference, typename It::iterator_category >>
3280 using difference_type =
typename It::difference_type;
3281 using value_type =
typename It::value_type;
3282 using pointer =
typename It::pointer;
3283 using reference =
typename It::reference;
3284 using iterator_category =
typename It::iterator_category;
3289template<
typename T,
typename =
void>
3290struct iterator_traits
3295struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3301struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3303 using iterator_category = std::random_access_iterator_tag;
3304 using value_type = T;
3305 using difference_type = ptrdiff_t;
3307 using reference = T&;
3311NLOHMANN_JSON_NAMESPACE_END
3329NLOHMANN_JSON_NAMESPACE_BEGIN
3331NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3333NLOHMANN_JSON_NAMESPACE_END
3349NLOHMANN_JSON_NAMESPACE_BEGIN
3351NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3353NLOHMANN_JSON_NAMESPACE_END
3368#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3369 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3385 NLOHMANN_JSON_NAMESPACE_BEGIN
3394 template<
typename T =
void,
typename SFINAE =
void>
3399 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3401 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3402 class StringType = std::string,
class BooleanType = bool,
3403 class NumberIntegerType = std::int64_t,
3404 class NumberUnsignedType = std::uint64_t,
3405 class NumberFloatType = double,
3406 template<
typename U>
class AllocatorType = std::allocator,
3407 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3409 class BinaryType = std::vector<std::uint8_t>,
3410 class CustomBaseClass =
void>
3415 template<
typename RefStringType>
3426 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3433 NLOHMANN_JSON_NAMESPACE_END
3438NLOHMANN_JSON_NAMESPACE_BEGIN
3463template<
typename>
struct is_basic_json : std::false_type {};
3465NLOHMANN_BASIC_JSON_TPL_DECLARATION
3466struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3471template<
typename BasicJsonContext>
3472struct is_basic_json_context :
3473 std::integral_constant < bool,
3474 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3475 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3486struct is_json_ref : std::false_type {};
3489struct is_json_ref<json_ref<T>> : std::true_type {};
3496using mapped_type_t =
typename T::mapped_type;
3499using key_type_t =
typename T::key_type;
3502using value_type_t =
typename T::value_type;
3505using difference_type_t =
typename T::difference_type;
3508using pointer_t =
typename T::pointer;
3511using reference_t =
typename T::reference;
3514using iterator_category_t =
typename T::iterator_category;
3516template<
typename T,
typename... Args>
3517using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3519template<
typename T,
typename... Args>
3520using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3522template<
typename T,
typename U>
3523using get_template_function =
decltype(std::declval<T>().template get<U>());
3526template<
typename BasicJsonType,
typename T,
typename =
void>
3527struct has_from_json : std::false_type {};
3533template <
typename BasicJsonType,
typename T>
3536 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3539template<
typename BasicJsonType,
typename T>
3540struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3542 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3544 static constexpr bool value =
3545 is_detected_exact<void, from_json_function, serializer,
3546 const BasicJsonType&, T&>
::value;
3551template<
typename BasicJsonType,
typename T,
typename =
void>
3552struct has_non_default_from_json : std::false_type {};
3554template<
typename BasicJsonType,
typename T>
3555struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3557 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3559 static constexpr bool value =
3560 is_detected_exact<T, from_json_function, serializer,
3566template<
typename BasicJsonType,
typename T,
typename =
void>
3567struct has_to_json : std::false_type {};
3569template<
typename BasicJsonType,
typename T>
3570struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3572 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3574 static constexpr bool value =
3575 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3580using detect_key_compare =
typename T::key_compare;
3583struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3586template<
typename BasicJsonType>
3587struct actual_object_comparator
3589 using object_t =
typename BasicJsonType::object_t;
3590 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3591 using type =
typename std::conditional < has_key_compare<object_t>::value,
3592 typename object_t::key_compare, object_comparator_t>::type;
3595template<
typename BasicJsonType>
3596using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3604struct char_traits : std::char_traits<T>
3609struct char_traits<unsigned char> : std::char_traits<char>
3611 using char_type =
unsigned char;
3615 static int_type to_int_type(char_type c)
noexcept
3617 return static_cast<int_type
>(c);
3620 static char_type to_char_type(int_type i)
noexcept
3622 return static_cast<char_type
>(i);
3625 static constexpr int_type eof() noexcept
3627 return static_cast<int_type
>(EOF);
3633struct char_traits<signed char> : std::char_traits<char>
3635 using char_type =
signed char;
3639 static int_type to_int_type(char_type c)
noexcept
3641 return static_cast<int_type
>(c);
3644 static char_type to_char_type(int_type i)
noexcept
3646 return static_cast<char_type
>(i);
3649 static constexpr int_type eof() noexcept
3651 return static_cast<int_type
>(EOF);
3660template<
class...>
struct conjunction : std::true_type { };
3661template<
class B>
struct conjunction<B> : B { };
3662template<
class B,
class... Bn>
3663struct conjunction<B, Bn...>
3664: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3667template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3672template <
typename T>
3673struct is_default_constructible : std::is_default_constructible<T> {};
3675template <
typename T1,
typename T2>
3676struct is_default_constructible<std::pair<T1, T2>>
3677 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3679template <
typename T1,
typename T2>
3680struct is_default_constructible<const std::pair<T1, T2>>
3681 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3683template <
typename... Ts>
3684struct is_default_constructible<std::tuple<Ts...>>
3685 : conjunction<is_default_constructible<Ts>...> {};
3687template <
typename... Ts>
3688struct is_default_constructible<const std::tuple<Ts...>>
3689 : conjunction<is_default_constructible<Ts>...> {};
3691template <
typename T,
typename... Args>
3692struct is_constructible : std::is_constructible<T, Args...> {};
3694template <
typename T1,
typename T2>
3695struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
3697template <
typename T1,
typename T2>
3698struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
3700template <
typename... Ts>
3701struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
3703template <
typename... Ts>
3704struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
3706template<
typename T,
typename =
void>
3707struct is_iterator_traits : std::false_type {};
3710struct is_iterator_traits<iterator_traits<T>>
3713 using traits = iterator_traits<T>;
3716 static constexpr auto value =
3717 is_detected<value_type_t, traits>::value &&
3718 is_detected<difference_type_t, traits>::value &&
3719 is_detected<pointer_t, traits>::value &&
3720 is_detected<iterator_category_t, traits>::value &&
3721 is_detected<reference_t, traits>::value;
3728 using t_ref =
typename std::add_lvalue_reference<T>::type;
3730 using iterator = detected_t<result_of_begin, t_ref>;
3731 using sentinel = detected_t<result_of_end, t_ref>;
3736 static constexpr auto is_iterator_begin =
3737 is_iterator_traits<iterator_traits<iterator>>::value;
3740 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3744using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3747using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3753template<
typename T,
typename =
void>
3754struct is_complete_type : std::false_type {};
3757struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3759template<
typename BasicJsonType,
typename CompatibleObjectType,
3761struct is_compatible_object_type_impl : std::false_type {};
3763template<
typename BasicJsonType,
typename CompatibleObjectType>
3764struct is_compatible_object_type_impl <
3765 BasicJsonType, CompatibleObjectType,
3766 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3767 is_detected<key_type_t, CompatibleObjectType>::value >>
3769 using object_t =
typename BasicJsonType::object_t;
3772 static constexpr bool value =
3773 is_constructible<
typename object_t::key_type,
3774 typename CompatibleObjectType::key_type>::value &&
3775 is_constructible<
typename object_t::mapped_type,
3776 typename CompatibleObjectType::mapped_type>
::value;
3779template<
typename BasicJsonType,
typename CompatibleObjectType>
3780struct is_compatible_object_type
3781 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3783template<
typename BasicJsonType,
typename ConstructibleObjectType,
3785struct is_constructible_object_type_impl : std::false_type {};
3787template<
typename BasicJsonType,
typename ConstructibleObjectType>
3788struct is_constructible_object_type_impl <
3789 BasicJsonType, ConstructibleObjectType,
3790 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3791 is_detected<key_type_t, ConstructibleObjectType>::value >>
3793 using object_t =
typename BasicJsonType::object_t;
3795 static constexpr bool value =
3796 (is_default_constructible<ConstructibleObjectType>::value &&
3797 (std::is_move_assignable<ConstructibleObjectType>::value ||
3798 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3799 (is_constructible<
typename ConstructibleObjectType::key_type,
3800 typename object_t::key_type>::value &&
3802 typename object_t::mapped_type,
3803 typename ConstructibleObjectType::mapped_type >
::value)) ||
3804 (has_from_json<BasicJsonType,
3805 typename ConstructibleObjectType::mapped_type>::value ||
3806 has_non_default_from_json <
3808 typename ConstructibleObjectType::mapped_type >::value);
3811template<
typename BasicJsonType,
typename ConstructibleObjectType>
3812struct is_constructible_object_type
3813 : is_constructible_object_type_impl<BasicJsonType,
3814 ConstructibleObjectType> {};
3816template<
typename BasicJsonType,
typename CompatibleStringType>
3817struct is_compatible_string_type
3819 static constexpr auto value =
3820 is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3823template<
typename BasicJsonType,
typename ConstructibleStringType>
3824struct is_constructible_string_type
3827#ifdef __INTEL_COMPILER
3828 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3830 using laundered_type = ConstructibleStringType;
3833 static constexpr auto value =
3835 is_constructible<laundered_type, typename BasicJsonType::string_t>,
3836 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3837 value_type_t, laundered_type >>::value;
3840template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3841struct is_compatible_array_type_impl : std::false_type {};
3843template<
typename BasicJsonType,
typename CompatibleArrayType>
3844struct is_compatible_array_type_impl <
3845 BasicJsonType, CompatibleArrayType,
3847 is_detected<iterator_t, CompatibleArrayType>::value&&
3848 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
3851 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
3853 static constexpr bool value =
3854 is_constructible<BasicJsonType,
3855 range_value_t<CompatibleArrayType>>
::value;
3858template<
typename BasicJsonType,
typename CompatibleArrayType>
3859struct is_compatible_array_type
3860 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3862template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3863struct is_constructible_array_type_impl : std::false_type {};
3865template<
typename BasicJsonType,
typename ConstructibleArrayType>
3866struct is_constructible_array_type_impl <
3867 BasicJsonType, ConstructibleArrayType,
3868 enable_if_t<std::is_same<ConstructibleArrayType,
3869 typename BasicJsonType::value_type>::value >>
3870 : std::true_type {};
3872template<
typename BasicJsonType,
typename ConstructibleArrayType>
3873struct is_constructible_array_type_impl <
3874 BasicJsonType, ConstructibleArrayType,
3875 enable_if_t < !std::is_same<ConstructibleArrayType,
3876 typename BasicJsonType::value_type>::value&&
3877 !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
3878 is_default_constructible<ConstructibleArrayType>::value&&
3879(std::is_move_assignable<ConstructibleArrayType>::value ||
3880 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3881is_detected<iterator_t, ConstructibleArrayType>::value&&
3882is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
3883is_detected<range_value_t, ConstructibleArrayType>::value&&
3886!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
3888 detected_t<range_value_t, ConstructibleArrayType >>::value >>
3890 using value_type = range_value_t<ConstructibleArrayType>;
3892 static constexpr bool value =
3893 std::is_same<value_type,
3894 typename BasicJsonType::array_t::value_type>::value ||
3895 has_from_json<BasicJsonType,
3896 value_type>::value ||
3897 has_non_default_from_json <
3902template<
typename BasicJsonType,
typename ConstructibleArrayType>
3903struct is_constructible_array_type
3904 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3906template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3908struct is_compatible_integer_type_impl : std::false_type {};
3910template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3911struct is_compatible_integer_type_impl <
3912 RealIntegerType, CompatibleNumberIntegerType,
3913 enable_if_t < std::is_integral<RealIntegerType>::value&&
3914 std::is_integral<CompatibleNumberIntegerType>::value&&
3915 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3918 using RealLimits = std::numeric_limits<RealIntegerType>;
3919 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3921 static constexpr auto value =
3922 is_constructible<RealIntegerType,
3923 CompatibleNumberIntegerType>::value &&
3924 CompatibleLimits::is_integer &&
3925 RealLimits::is_signed == CompatibleLimits::is_signed;
3928template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3929struct is_compatible_integer_type
3930 : is_compatible_integer_type_impl<RealIntegerType,
3931 CompatibleNumberIntegerType> {};
3933template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3934struct is_compatible_type_impl: std::false_type {};
3936template<
typename BasicJsonType,
typename CompatibleType>
3937struct is_compatible_type_impl <
3938 BasicJsonType, CompatibleType,
3939 enable_if_t<is_complete_type<CompatibleType>::value >>
3941 static constexpr bool value =
3942 has_to_json<BasicJsonType, CompatibleType>::value;
3945template<
typename BasicJsonType,
typename CompatibleType>
3946struct is_compatible_type
3947 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3949template<
typename T1,
typename T2>
3950struct is_constructible_tuple : std::false_type {};
3952template<
typename T1,
typename... Args>
3953struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
3955template<
typename BasicJsonType,
typename T>
3956struct is_json_iterator_of : std::false_type {};
3958template<
typename BasicJsonType>
3959struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : std::true_type {};
3961template<
typename BasicJsonType>
3962struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
3966template<
template <
typename...>
class Primary,
typename T>
3967struct is_specialization_of : std::false_type {};
3969template<
template <
typename...>
class Primary,
typename... Args>
3970struct is_specialization_of<Primary, Primary<Args...>> : std::true_type {};
3973using is_json_pointer = is_specialization_of<::nlohmann::json_pointer, uncvref_t<T>>;
3976template<
typename Compare,
typename A,
typename B,
typename =
void>
3977struct is_comparable : std::false_type {};
3979template<
typename Compare,
typename A,
typename B>
3980struct is_comparable<Compare, A, B, void_t<
3981decltype(std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
3982decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
3983>> : std::true_type {};
3986using detect_is_transparent =
typename T::is_transparent;
3990template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
3991 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
3992using is_usable_as_key_type =
typename std::conditional <
3993 is_comparable<Comparator, ObjectKeyType, KeyTypeCVRef>::value
3994 && !(ExcludeObjectKeyType && std::is_same<KeyType,
3996 && (!RequireTransparentComparator
3997 || is_detected <detect_is_transparent, Comparator>::value)
3998 && !is_json_pointer<KeyType>::value,
4000 std::false_type >::type;
4008template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
4009 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
4010using is_usable_as_basic_json_key_type =
typename std::conditional <
4011 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
4012 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
4013 RequireTransparentComparator, ExcludeObjectKeyType>::value
4014 && !is_json_iterator_of<BasicJsonType, KeyType>::value,
4016 std::false_type >::type;
4018template<
typename ObjectType,
typename KeyType>
4019using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
4022template<
typename BasicJsonType,
typename KeyType>
4023using has_erase_with_key_type =
typename std::conditional <
4025 detect_erase_with_key_type,
4026 typename BasicJsonType::object_t, KeyType >
::value,
4028 std::false_type >::type;
4032template <
typename T>
4033struct is_ordered_map
4042 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
4043 template <
typename C>
static two test(...);
4045 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
4049template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
4050T conditional_static_cast(U value)
4052 return static_cast<T
>(
value);
4055template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
4056T conditional_static_cast(U value)
4061template<
typename... Types>
4062using all_integral = conjunction<std::is_integral<Types>...>;
4064template<
typename... Types>
4065using all_signed = conjunction<std::is_signed<Types>...>;
4067template<
typename... Types>
4068using all_unsigned = conjunction<std::is_unsigned<Types>...>;
4071template<
typename... Types>
4072using same_sign = std::integral_constant < bool,
4073 all_signed<Types...>::value || all_unsigned<Types...>::value >;
4075template<
typename OfType,
typename T>
4076using never_out_of_range = std::integral_constant < bool,
4077 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4078 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4080template<
typename OfType,
typename T,
4081 bool OfTypeSigned = std::is_signed<OfType>::value,
4082 bool TSigned = std::is_signed<T>::value>
4083struct value_in_range_of_impl2;
4085template<
typename OfType,
typename T>
4086struct value_in_range_of_impl2<OfType, T, false, false>
4088 static constexpr bool test(T val)
4090 using CommonType =
typename std::common_type<OfType, T>::type;
4091 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4095template<
typename OfType,
typename T>
4096struct value_in_range_of_impl2<OfType, T, true, false>
4098 static constexpr bool test(T val)
4100 using CommonType =
typename std::common_type<OfType, T>::type;
4101 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4105template<
typename OfType,
typename T>
4106struct value_in_range_of_impl2<OfType, T, false, true>
4108 static constexpr bool test(T val)
4110 using CommonType =
typename std::common_type<OfType, T>::type;
4111 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4115template<
typename OfType,
typename T>
4116struct value_in_range_of_impl2<OfType, T, true, true>
4118 static constexpr bool test(T val)
4120 using CommonType =
typename std::common_type<OfType, T>::type;
4121 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4122 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4126template<
typename OfType,
typename T,
4127 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4128 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4129struct value_in_range_of_impl1;
4131template<
typename OfType,
typename T>
4132struct value_in_range_of_impl1<OfType, T, false>
4134 static constexpr bool test(T val)
4136 return value_in_range_of_impl2<OfType, T>::test(val);
4140template<
typename OfType,
typename T>
4141struct value_in_range_of_impl1<OfType, T, true>
4143 static constexpr bool test(T )
4149template<
typename OfType,
typename T>
4150inline constexpr bool value_in_range_of(T val)
4152 return value_in_range_of_impl1<OfType, T>::test(val);
4156using bool_constant = std::integral_constant<bool, Value>;
4166inline constexpr bool is_c_string()
4168 using TUnExt =
typename std::remove_extent<T>::type;
4169 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4170 using TUnPtr =
typename std::remove_pointer<T>::type;
4171 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4173 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4174 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4181struct is_c_string : bool_constant<impl::is_c_string<T>()> {};
4184using is_c_string_uncvref = is_c_string<uncvref_t<T>>;
4194inline constexpr bool is_transparent()
4196 return is_detected<detect_is_transparent, T>::value;
4203struct is_transparent : bool_constant<impl::is_transparent<T>()> {};
4208NLOHMANN_JSON_NAMESPACE_END
4230NLOHMANN_JSON_NAMESPACE_BEGIN
4234inline std::size_t concat_length()
4239template<
typename... Args>
4240inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4242template<
typename StringType,
typename... Args>
4243inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4245template<
typename... Args>
4246inline std::size_t concat_length(
const char ,
const Args& ... rest)
4248 return 1 + concat_length(rest...);
4251template<
typename... Args>
4252inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4255 return ::strlen(cstr) + concat_length(rest...);
4258template<
typename StringType,
typename... Args>
4259inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4261 return str.size() + concat_length(rest...);
4264template<
typename OutStringType>
4265inline void concat_into(OutStringType& )
4268template<
typename StringType,
typename Arg>
4269using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4271template<
typename StringType,
typename Arg>
4272using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4274template<
typename StringType,
typename Arg>
4275using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4277template<
typename StringType,
typename Arg>
4278using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4280template<
typename StringType,
typename Arg>
4281using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4283template<
typename StringType,
typename Arg>
4284using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4286template<
typename StringType,
typename Arg>
4287using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4289template<
typename StringType,
typename Arg>
4290using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4292template <
typename OutStringType,
typename Arg,
typename... Args,
4293 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4294 && detect_string_can_append_op<OutStringType, Arg>::value,
int > = 0 >
4295inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4297template <
typename OutStringType,
typename Arg,
typename... Args,
4298 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4299 && !detect_string_can_append_op<OutStringType, Arg>::value
4300 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4301inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4303template <
typename OutStringType,
typename Arg,
typename... Args,
4304 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4305 && !detect_string_can_append_op<OutStringType, Arg>::value
4306 && !detect_string_can_append_iter<OutStringType, Arg>::value
4307 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4308inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4310template<
typename OutStringType,
typename Arg,
typename... Args,
4311 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4312inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4314 out.append(std::forward<Arg>(arg));
4315 concat_into(out, std::forward<Args>(rest)...);
4318template <
typename OutStringType,
typename Arg,
typename... Args,
4319 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4320 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4321inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4323 out += std::forward<Arg>(arg);
4324 concat_into(out, std::forward<Args>(rest)...);
4327template <
typename OutStringType,
typename Arg,
typename... Args,
4328 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4329 && !detect_string_can_append_op<OutStringType, Arg>::value
4330 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4331inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4333 out.append(arg.begin(), arg.end());
4334 concat_into(out, std::forward<Args>(rest)...);
4337template <
typename OutStringType,
typename Arg,
typename... Args,
4338 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4339 && !detect_string_can_append_op<OutStringType, Arg>::value
4340 && !detect_string_can_append_iter<OutStringType, Arg>::value
4341 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4342inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4344 out.append(arg.data(), arg.size());
4345 concat_into(out, std::forward<Args>(rest)...);
4348template<
typename OutStringType = std::string,
typename... Args>
4349inline OutStringType concat(Args && ... args)
4352 str.reserve(concat_length(args...));
4353 concat_into(str, std::forward<Args>(args)...);
4358NLOHMANN_JSON_NAMESPACE_END
4361NLOHMANN_JSON_NAMESPACE_BEGIN
4371class exception :
public std::exception
4375 const char*
what() const noexcept
override
4384 JSON_HEDLEY_NON_NULL(3)
4385 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4387 static std::string name(
const std::string& ename,
int id_)
4389 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4392 static std::string diagnostics(std::nullptr_t )
4397 template<
typename BasicJsonType>
4398 static std::string diagnostics(
const BasicJsonType* leaf_element)
4401 std::vector<std::string> tokens;
4402 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4404 switch (current->m_parent->type())
4408 for (std::size_t i = 0; i < current->m_parent->m_data.m_value.array->size(); ++i)
4410 if (¤t->m_parent->m_data.m_value.array->operator[](i) == current)
4412 tokens.emplace_back(std::to_string(i));
4421 for (
const auto& element : *current->m_parent->m_data.m_value.object)
4423 if (&element.second == current)
4425 tokens.emplace_back(element.first.c_str());
4450 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4451 [](
const std::string & a,
const std::string & b)
4453 return concat(a,
'/', detail::escape(b));
4455 return concat(
'(', str,
") ");
4457 static_cast<void>(leaf_element);
4464 std::runtime_error m;
4469class parse_error :
public exception
4481 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4484 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4485 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4486 return {id_, pos.chars_read_total, w.c_str()};
4489 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4490 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4492 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4493 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4494 ": ", exception::diagnostics(context), what_arg);
4495 return {id_, byte_, w.c_str()};
4510 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4513 static std::string position_string(
const position_t& pos)
4515 return concat(
" at line ", std::to_string(pos.lines_read + 1),
4516 ", column ", std::to_string(pos.chars_read_current_line));
4522class invalid_iterator :
public exception
4525 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4526 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4528 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4529 return {id_, w.c_str()};
4533 JSON_HEDLEY_NON_NULL(3)
4534 invalid_iterator(
int id_, const
char* what_arg)
4535 : exception(id_, what_arg) {}
4540class type_error :
public exception
4543 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4544 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4546 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4547 return {id_, w.c_str()};
4551 JSON_HEDLEY_NON_NULL(3)
4552 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
4557class out_of_range :
public exception
4560 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4561 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4563 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4564 return {id_, w.c_str()};
4568 JSON_HEDLEY_NON_NULL(3)
4569 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
4574class other_error :
public exception
4577 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4578 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4580 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4581 return {id_, w.c_str()};
4585 JSON_HEDLEY_NON_NULL(3)
4586 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
4590NLOHMANN_JSON_NAMESPACE_END
4610NLOHMANN_JSON_NAMESPACE_BEGIN
4615template <
class T>
struct identity_tag {};
4618NLOHMANN_JSON_NAMESPACE_END
4634#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4635#include <experimental/filesystem>
4636NLOHMANN_JSON_NAMESPACE_BEGIN
4639namespace std_fs = std::experimental::filesystem;
4641NLOHMANN_JSON_NAMESPACE_END
4642#elif JSON_HAS_FILESYSTEM
4643#include <filesystem>
4644NLOHMANN_JSON_NAMESPACE_BEGIN
4647namespace std_fs = std::filesystem;
4649NLOHMANN_JSON_NAMESPACE_END
4659NLOHMANN_JSON_NAMESPACE_BEGIN
4663template<
typename BasicJsonType>
4664inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4666 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4668 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4674template <
typename BasicJsonType,
typename ArithmeticType,
4675 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4676 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4678void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4680 switch (
static_cast<value_t>(j))
4684 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4689 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4694 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4706 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4710template<
typename BasicJsonType>
4711inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4713 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4715 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4717 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4720template<
typename BasicJsonType>
4721inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4723 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4725 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4727 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4731 typename BasicJsonType,
typename StringType,
4733 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4734 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4735 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4736 && !is_json_ref<StringType>::value,
int > = 0 >
4737inline void from_json(
const BasicJsonType& j, StringType& s)
4739 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4741 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4744 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4747template<
typename BasicJsonType>
4748inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4750 get_arithmetic_value(j, val);
4753template<
typename BasicJsonType>
4754inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4756 get_arithmetic_value(j, val);
4759template<
typename BasicJsonType>
4760inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4762 get_arithmetic_value(j, val);
4765#if !JSON_DISABLE_ENUM_SERIALIZATION
4766template<
typename BasicJsonType,
typename EnumType,
4767 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4768inline void from_json(
const BasicJsonType& j, EnumType& e)
4770 typename std::underlying_type<EnumType>::type val;
4771 get_arithmetic_value(j, val);
4772 e =
static_cast<EnumType
>(val);
4777template<
typename BasicJsonType,
typename T,
typename Allocator,
4778 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4779inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4781 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4783 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4786 std::transform(j.rbegin(), j.rend(),
4787 std::front_inserter(l), [](
const BasicJsonType & i)
4789 return i.template get<T>();
4794template<
typename BasicJsonType,
typename T,
4795 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4796inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4798 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4800 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4803 std::transform(j.begin(), j.end(), std::begin(l),
4804 [](
const BasicJsonType & elem)
4806 return elem.template get<T>();
4810template<
typename BasicJsonType,
typename T, std::
size_t N>
4811auto from_json(
const BasicJsonType& j, T (&arr)[N])
4812->
decltype(j.template get<T>(), void())
4814 for (std::size_t i = 0; i < N; ++i)
4816 arr[i] = j.at(i).template get<T>();
4820template<
typename BasicJsonType>
4821inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4823 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4826template<
typename BasicJsonType,
typename T, std::
size_t N>
4827auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4829->
decltype(j.template get<T>(), void())
4831 for (std::size_t i = 0; i < N; ++i)
4833 arr[i] = j.at(i).template get<T>();
4837template<
typename BasicJsonType,
typename ConstructibleArrayType,
4839 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4841auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4843 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4844 j.template get<typename ConstructibleArrayType::value_type>(),
4849 ConstructibleArrayType ret;
4850 ret.reserve(j.size());
4851 std::transform(j.begin(), j.end(),
4852 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4856 return i.template get<typename ConstructibleArrayType::value_type>();
4858 arr = std::move(ret);
4861template<
typename BasicJsonType,
typename ConstructibleArrayType,
4863 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4865inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4870 ConstructibleArrayType ret;
4872 j.begin(), j.end(), std::inserter(ret, end(ret)),
4873 [](
const BasicJsonType & i)
4877 return i.template get<typename ConstructibleArrayType::value_type>();
4879 arr = std::move(ret);
4882template <
typename BasicJsonType,
typename ConstructibleArrayType,
4884 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4885 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4886 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4887 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4888 !is_basic_json<ConstructibleArrayType>::value,
4890auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4891->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4892j.template get<typename ConstructibleArrayType::value_type>(),
4895 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4897 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4900 from_json_array_impl(j, arr, priority_tag<3> {});
4903template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4904std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4905 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4907 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4910template <
typename BasicJsonType,
typename T, std::
size_t N >
4911auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4912->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4914 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4916 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4919 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4922template<
typename BasicJsonType>
4923inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4925 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4927 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
4930 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4933template<
typename BasicJsonType,
typename ConstructibleObjectType,
4934 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4935inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4937 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4939 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
4942 ConstructibleObjectType ret;
4943 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4944 using value_type =
typename ConstructibleObjectType::value_type;
4946 inner_object->begin(), inner_object->end(),
4947 std::inserter(ret, ret.begin()),
4948 [](
typename BasicJsonType::object_t::value_type
const & p)
4950 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4952 obj = std::move(ret);
4959template <
typename BasicJsonType,
typename ArithmeticType,
4961 std::is_arithmetic<ArithmeticType>::value&&
4962 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4963 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4964 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4965 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4967inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
4969 switch (
static_cast<value_t>(j))
4973 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4978 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4983 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4988 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4999 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
5003template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
5004std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
5006 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
5009template <
typename BasicJsonType,
class A1,
class A2 >
5010std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
5012 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
5013 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
5016template<
typename BasicJsonType,
typename A1,
typename A2>
5017inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
5019 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
5022template<
typename BasicJsonType,
typename... Args>
5023std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
5025 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5028template<
typename BasicJsonType,
typename... Args>
5029inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
5031 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
5034template<
typename BasicJsonType,
typename TupleRelated>
5035auto from_json(BasicJsonType&& j, TupleRelated&& t)
5036->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
5038 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5040 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5043 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
5046template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
5047 typename = enable_if_t < !std::is_constructible <
5048 typename BasicJsonType::string_t, Key >::value >>
5049inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
5051 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5053 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5056 for (
const auto& p : j)
5058 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5060 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5062 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5066template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5067 typename = enable_if_t < !std::is_constructible <
5068 typename BasicJsonType::string_t, Key >::value >>
5069inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5071 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5073 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5076 for (
const auto& p : j)
5078 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5080 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5082 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5086#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5087template<
typename BasicJsonType>
5088inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5090 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5092 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5094 p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5100 template<
typename BasicJsonType,
typename T>
5101 auto operator()(
const BasicJsonType& j, T&& val)
const
5102 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5103 ->
decltype(from_json(j, std::forward<T>(val)))
5105 return from_json(j, std::forward<T>(val));
5111#ifndef JSON_HAS_CPP_17
5118JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5120#ifndef JSON_HAS_CPP_17
5124NLOHMANN_JSON_NAMESPACE_END
5141#include <type_traits>
5174NLOHMANN_JSON_NAMESPACE_BEGIN
5178template<
typename string_type>
5179void int_to_string( string_type& target, std::size_t value )
5182 using std::to_string;
5185template<
typename IteratorType>
class iteration_proxy_value
5188 using difference_type = std::ptrdiff_t;
5189 using value_type = iteration_proxy_value;
5190 using pointer = value_type *;
5191 using reference = value_type &;
5192 using iterator_category = std::input_iterator_tag;
5193 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
5197 IteratorType anchor{};
5199 std::size_t array_index = 0;
5201 mutable std::size_t array_index_last = 0;
5203 mutable string_type array_index_str =
"0";
5205 string_type empty_str{};
5208 explicit iteration_proxy_value() =
default;
5209 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
5210 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5211 && std::is_nothrow_default_constructible<string_type>::value)
5212 : anchor(std::move(it))
5213 , array_index(array_index_)
5216 iteration_proxy_value(iteration_proxy_value
const&) =
default;
5217 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
5219 iteration_proxy_value(iteration_proxy_value&&)
5220 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5221 && std::is_nothrow_move_constructible<string_type>::value) = default;
5222 iteration_proxy_value& operator=(iteration_proxy_value&&)
5223 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
5224 && std::is_nothrow_move_assignable<string_type>::value) = default;
5225 ~iteration_proxy_value() = default;
5253 return anchor == o.anchor;
5259 return anchor != o.anchor;
5263 const string_type&
key()
const
5265 JSON_ASSERT(anchor.m_object !=
nullptr);
5267 switch (anchor.m_object->type())
5272 if (array_index != array_index_last)
5274 int_to_string( array_index_str, array_index );
5275 array_index_last = array_index;
5277 return array_index_str;
5282 return anchor.key();
5299 typename IteratorType::reference
value()
const
5301 return anchor.value();
5306template<
typename IteratorType>
class iteration_proxy
5310 typename IteratorType::pointer container =
nullptr;
5313 explicit iteration_proxy() =
default;
5317 : container(&cont) {}
5341template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5342auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5349template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5350auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5356NLOHMANN_JSON_NAMESPACE_END
5365#if defined(__clang__)
5367 #pragma clang diagnostic push
5368 #pragma clang diagnostic ignored "-Wmismatched-tags"
5370template<
typename IteratorType>
5371class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5372 :
public std::integral_constant<std::size_t, 2> {};
5374template<std::
size_t N,
typename IteratorType>
5375class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5378 using type =
decltype(
5379 get<N>(std::declval <
5380 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5382#if defined(__clang__)
5383 #pragma clang diagnostic pop
5389 template <
typename IteratorType>
5390 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5404NLOHMANN_JSON_NAMESPACE_BEGIN
5419template<value_t>
struct external_constructor;
5424 template<
typename BasicJsonType>
5425 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5427 j.m_data.m_value.destroy(j.m_data.m_type);
5429 j.m_data.m_value = b;
5430 j.assert_invariant();
5435struct external_constructor<
value_t::string>
5437 template<
typename BasicJsonType>
5438 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5440 j.m_data.m_value.destroy(j.m_data.m_type);
5442 j.m_data.m_value = s;
5443 j.assert_invariant();
5446 template<
typename BasicJsonType>
5447 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5449 j.m_data.m_value.destroy(j.m_data.m_type);
5451 j.m_data.m_value = std::move(s);
5452 j.assert_invariant();
5455 template <
typename BasicJsonType,
typename CompatibleStringType,
5456 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5458 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5460 j.m_data.m_value.destroy(j.m_data.m_type);
5462 j.m_data.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5463 j.assert_invariant();
5468struct external_constructor<
value_t::binary>
5470 template<
typename BasicJsonType>
5471 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5473 j.m_data.m_value.destroy(j.m_data.m_type);
5475 j.m_data.m_value =
typename BasicJsonType::binary_t(b);
5476 j.assert_invariant();
5479 template<
typename BasicJsonType>
5480 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5482 j.m_data.m_value.destroy(j.m_data.m_type);
5484 j.m_data.m_value =
typename BasicJsonType::binary_t(std::move(b));
5485 j.assert_invariant();
5492 template<
typename BasicJsonType>
5493 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5495 j.m_data.m_value.destroy(j.m_data.m_type);
5497 j.m_data.m_value = val;
5498 j.assert_invariant();
5505 template<
typename BasicJsonType>
5506 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5508 j.m_data.m_value.destroy(j.m_data.m_type);
5510 j.m_data.m_value = val;
5511 j.assert_invariant();
5518 template<
typename BasicJsonType>
5519 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5521 j.m_data.m_value.destroy(j.m_data.m_type);
5523 j.m_data.m_value = val;
5524 j.assert_invariant();
5529struct external_constructor<
value_t::array>
5531 template<
typename BasicJsonType>
5532 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5534 j.m_data.m_value.destroy(j.m_data.m_type);
5536 j.m_data.m_value = arr;
5538 j.assert_invariant();
5541 template<
typename BasicJsonType>
5542 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5544 j.m_data.m_value.destroy(j.m_data.m_type);
5546 j.m_data.m_value = std::move(arr);
5548 j.assert_invariant();
5551 template <
typename BasicJsonType,
typename CompatibleArrayType,
5552 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5554 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5559 j.m_data.m_value.destroy(j.m_data.m_type);
5561 j.m_data.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5563 j.assert_invariant();
5566 template<
typename BasicJsonType>
5567 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5569 j.m_data.m_value.destroy(j.m_data.m_type);
5572 j.m_data.m_value.array->reserve(arr.size());
5573 for (
const bool x : arr)
5575 j.m_data.m_value.array->push_back(x);
5576 j.set_parent(j.m_data.m_value.array->back());
5578 j.assert_invariant();
5581 template<
typename BasicJsonType,
typename T,
5582 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5583 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5585 j.m_data.m_value.destroy(j.m_data.m_type);
5588 j.m_data.m_value.array->resize(arr.size());
5591 std::copy(std::begin(arr), std::end(arr), j.m_data.m_value.array->begin());
5594 j.assert_invariant();
5601 template<
typename BasicJsonType>
5602 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5604 j.m_data.m_value.destroy(j.m_data.m_type);
5606 j.m_data.m_value = obj;
5608 j.assert_invariant();
5611 template<
typename BasicJsonType>
5612 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5614 j.m_data.m_value.destroy(j.m_data.m_type);
5616 j.m_data.m_value = std::move(obj);
5618 j.assert_invariant();
5621 template <
typename BasicJsonType,
typename CompatibleObjectType,
5622 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5623 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5628 j.m_data.m_value.destroy(j.m_data.m_type);
5630 j.m_data.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5632 j.assert_invariant();
5640template<
typename BasicJsonType,
typename T,
5641 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5642inline void to_json(BasicJsonType& j, T b)
noexcept
5644 external_constructor<value_t::boolean>::construct(j, b);
5647template <
typename BasicJsonType,
typename BoolRef,
5649 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5650 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>
::value)
5651 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5652 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5653 typename BasicJsonType::boolean_t >
::value))
5654 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5655inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5657 external_constructor<value_t::boolean>::construct(j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5660template<
typename BasicJsonType,
typename CompatibleString,
5661 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5662inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5664 external_constructor<value_t::string>::construct(j, s);
5667template<
typename BasicJsonType>
5668inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5670 external_constructor<value_t::string>::construct(j, std::move(s));
5673template<
typename BasicJsonType,
typename FloatType,
5674 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5675inline void to_json(BasicJsonType& j, FloatType val)
noexcept
5677 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
5680template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5681 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
5682inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
5684 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
5687template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5688 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
5689inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
5691 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
5694#if !JSON_DISABLE_ENUM_SERIALIZATION
5695template<
typename BasicJsonType,
typename EnumType,
5696 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5697inline void to_json(BasicJsonType& j, EnumType e)
noexcept
5699 using underlying_type =
typename std::underlying_type<EnumType>::type;
5701 external_constructor<integral_value_t>::construct(j,
static_cast<underlying_type
>(e));
5705template<
typename BasicJsonType>
5706inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
5708 external_constructor<value_t::array>::construct(j, e);
5711template <
typename BasicJsonType,
typename CompatibleArrayType,
5712 enable_if_t < is_compatible_array_type<BasicJsonType,
5713 CompatibleArrayType>::value&&
5714 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
5715 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
5716 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
5717 !is_basic_json<CompatibleArrayType>::value,
5719inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
5721 external_constructor<value_t::array>::construct(j, arr);
5724template<
typename BasicJsonType>
5725inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
5727 external_constructor<value_t::binary>::construct(j, bin);
5730template<
typename BasicJsonType,
typename T,
5731 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5732inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
5734 external_constructor<value_t::array>::construct(j, std::move(arr));
5737template<
typename BasicJsonType>
5738inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5740 external_constructor<value_t::array>::construct(j, std::move(arr));
5743template <
typename BasicJsonType,
typename CompatibleObjectType,
5744 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
5745inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
5747 external_constructor<value_t::object>::construct(j, obj);
5750template<
typename BasicJsonType>
5751inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5753 external_constructor<value_t::object>::construct(j, std::move(obj));
5757 typename BasicJsonType,
typename T, std::size_t N,
5758 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
5761inline void to_json(BasicJsonType& j,
const T(&arr)[N])
5763 external_constructor<value_t::array>::construct(j, arr);
5766template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
5767inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
5769 j = { p.first, p.second };
5773template<
typename BasicJsonType,
typename T,
5774 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>
::value,
int> = 0>
5775inline void to_json(BasicJsonType& j,
const T& b)
5777 j = { {b.key(), b.value()} };
5780template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
5781inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
5783 j = { std::get<Idx>(t)... };
5786template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
5787inline void to_json(BasicJsonType& j,
const T& t)
5789 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
5792#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5793template<
typename BasicJsonType>
5794inline void to_json(BasicJsonType& j,
const std_fs::path& p)
5802 template<
typename BasicJsonType,
typename T>
5803 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
5804 ->
decltype(to_json(j, std::forward<T>(val)),
void())
5806 return to_json(j, std::forward<T>(val));
5811#ifndef JSON_HAS_CPP_17
5818JSON_INLINE_VARIABLE
constexpr const auto& to_json =
5820#ifndef JSON_HAS_CPP_17
5824NLOHMANN_JSON_NAMESPACE_END
5829NLOHMANN_JSON_NAMESPACE_BEGIN
5832template<
typename ValueType,
typename>
5837 template<
typename BasicJsonType,
typename TargetType = ValueType>
5838 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
5839 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5840 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
5842 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5847 template<
typename BasicJsonType,
typename TargetType = ValueType>
5857 template<
typename BasicJsonType,
typename TargetType = ValueType>
5858 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
5859 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5860 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
5862 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5866NLOHMANN_JSON_NAMESPACE_END
5886NLOHMANN_JSON_NAMESPACE_BEGIN
5890template<
typename BinaryType>
5894 using container_type = BinaryType;
5895 using subtype_type = std::uint64_t;
5909 : container_type(std::move(b))
5915 , m_subtype(subtype_)
5916 , m_has_subtype(true)
5921 : container_type(std::move(b))
5922 , m_subtype(subtype_)
5923 , m_has_subtype(true)
5928 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5929 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5934 return !(rhs == *
this);
5941 m_subtype = subtype_;
5942 m_has_subtype =
true;
5949 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
5956 return m_has_subtype;
5964 m_has_subtype =
false;
5968 subtype_type m_subtype = 0;
5969 bool m_has_subtype =
false;
5972NLOHMANN_JSON_NAMESPACE_END
5993#include <functional>
6000NLOHMANN_JSON_NAMESPACE_BEGIN
6005inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
6007 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
6022template<
typename BasicJsonType>
6023std::size_t
hash(
const BasicJsonType& j)
6025 using string_t =
typename BasicJsonType::string_t;
6026 using number_integer_t =
typename BasicJsonType::number_integer_t;
6027 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6028 using number_float_t =
typename BasicJsonType::number_float_t;
6030 const auto type =
static_cast<std::size_t
>(j.type());
6033 case BasicJsonType::value_t::null:
6034 case BasicJsonType::value_t::discarded:
6036 return combine(type, 0);
6039 case BasicJsonType::value_t::object:
6041 auto seed = combine(type, j.size());
6042 for (
const auto& element : j.items())
6044 const auto h = std::hash<string_t> {}(element.key());
6045 seed = combine(seed, h);
6046 seed = combine(seed,
hash(element.value()));
6051 case BasicJsonType::value_t::array:
6053 auto seed = combine(type, j.size());
6054 for (
const auto& element : j)
6056 seed = combine(seed,
hash(element));
6061 case BasicJsonType::value_t::string:
6063 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
6064 return combine(type, h);
6067 case BasicJsonType::value_t::boolean:
6069 const auto h = std::hash<bool> {}(j.template get<bool>());
6070 return combine(type, h);
6073 case BasicJsonType::value_t::number_integer:
6075 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6076 return combine(type, h);
6079 case BasicJsonType::value_t::number_unsigned:
6081 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6082 return combine(type, h);
6085 case BasicJsonType::value_t::number_float:
6087 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6088 return combine(type, h);
6091 case BasicJsonType::value_t::binary:
6093 auto seed = combine(type, j.get_binary().size());
6094 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6095 seed = combine(seed, h);
6096 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6097 for (
const auto byte : j.get_binary())
6099 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6111NLOHMANN_JSON_NAMESPACE_END
6157#include <type_traits>
6172NLOHMANN_JSON_NAMESPACE_BEGIN
6188class file_input_adapter
6191 using char_type = char;
6193 JSON_HEDLEY_NON_NULL(2)
6194 explicit file_input_adapter(std::FILE* f) noexcept
6197 JSON_ASSERT(m_file !=
nullptr);
6201 file_input_adapter(
const file_input_adapter&) =
delete;
6202 file_input_adapter(file_input_adapter&&) noexcept = default;
6203 file_input_adapter& operator=(const file_input_adapter&) = delete;
6204 file_input_adapter& operator=(file_input_adapter&&) = delete;
6205 ~file_input_adapter() = default;
6207 std::char_traits<
char>::int_type get_character() noexcept
6209 return std::fgetc(m_file);
6226class input_stream_adapter
6229 using char_type = char;
6231 ~input_stream_adapter()
6237 is->clear(is->rdstate() & std::ios::eofbit);
6241 explicit input_stream_adapter(std::istream& i)
6242 : is(&i), sb(i.rdbuf())
6246 input_stream_adapter(
const input_stream_adapter&) =
delete;
6247 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6248 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6250 input_stream_adapter(input_stream_adapter&& rhs) noexcept
6251 : is(rhs.is), sb(rhs.sb)
6260 std::char_traits<char>::int_type get_character()
6262 auto res = sb->sbumpc();
6264 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6266 is->clear(is->rdstate() | std::ios::eofbit);
6273 std::istream* is =
nullptr;
6274 std::streambuf* sb =
nullptr;
6280template<
typename IteratorType>
6281class iterator_input_adapter
6284 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6286 iterator_input_adapter(IteratorType first, IteratorType last)
6287 : current(std::move(first)), end(std::move(last))
6290 typename char_traits<char_type>::int_type get_character()
6292 if (JSON_HEDLEY_LIKELY(current != end))
6294 auto result = char_traits<char_type>::to_int_type(*current);
6295 std::advance(current, 1);
6299 return char_traits<char_type>::eof();
6303 IteratorType current;
6306 template<
typename BaseInputAdapter,
size_t T>
6307 friend struct wide_string_input_helper;
6311 return current == end;
6315template<
typename BaseInputAdapter,
size_t T>
6316struct wide_string_input_helper;
6318template<
typename BaseInputAdapter>
6319struct wide_string_input_helper<BaseInputAdapter, 4>
6322 static void fill_buffer(BaseInputAdapter& input,
6323 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6324 size_t& utf8_bytes_index,
6325 size_t& utf8_bytes_filled)
6327 utf8_bytes_index = 0;
6329 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6331 utf8_bytes[0] = std::char_traits<char>::eof();
6332 utf8_bytes_filled = 1;
6337 const auto wc = input.get_character();
6342 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6343 utf8_bytes_filled = 1;
6345 else if (wc <= 0x7FF)
6347 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6348 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6349 utf8_bytes_filled = 2;
6351 else if (wc <= 0xFFFF)
6353 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6354 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6355 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6356 utf8_bytes_filled = 3;
6358 else if (wc <= 0x10FFFF)
6360 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6361 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6362 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6363 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6364 utf8_bytes_filled = 4;
6369 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6370 utf8_bytes_filled = 1;
6376template<
typename BaseInputAdapter>
6377struct wide_string_input_helper<BaseInputAdapter, 2>
6380 static void fill_buffer(BaseInputAdapter& input,
6381 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6382 size_t& utf8_bytes_index,
6383 size_t& utf8_bytes_filled)
6385 utf8_bytes_index = 0;
6387 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6389 utf8_bytes[0] = std::char_traits<char>::eof();
6390 utf8_bytes_filled = 1;
6395 const auto wc = input.get_character();
6400 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6401 utf8_bytes_filled = 1;
6403 else if (wc <= 0x7FF)
6405 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6406 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6407 utf8_bytes_filled = 2;
6409 else if (0xD800 > wc || wc >= 0xE000)
6411 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6412 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6413 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6414 utf8_bytes_filled = 3;
6418 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6420 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6421 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6422 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6423 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6424 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6425 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6426 utf8_bytes_filled = 4;
6430 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6431 utf8_bytes_filled = 1;
6439template<
typename BaseInputAdapter,
typename W
ideCharType>
6440class wide_string_input_adapter
6443 using char_type = char;
6445 wide_string_input_adapter(BaseInputAdapter base)
6446 : base_adapter(base) {}
6448 typename std::char_traits<char>::int_type get_character() noexcept
6451 if (utf8_bytes_index == utf8_bytes_filled)
6453 fill_buffer<sizeof(WideCharType)>();
6455 JSON_ASSERT(utf8_bytes_filled > 0);
6456 JSON_ASSERT(utf8_bytes_index == 0);
6460 JSON_ASSERT(utf8_bytes_filled > 0);
6461 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6462 return utf8_bytes[utf8_bytes_index++];
6466 BaseInputAdapter base_adapter;
6471 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
6475 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6478 std::size_t utf8_bytes_index = 0;
6480 std::size_t utf8_bytes_filled = 0;
6483template<
typename IteratorType,
typename Enable =
void>
6484struct iterator_input_adapter_factory
6486 using iterator_type = IteratorType;
6487 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6488 using adapter_type = iterator_input_adapter<iterator_type>;
6490 static adapter_type create(IteratorType first, IteratorType last)
6492 return adapter_type(std::move(first), std::move(last));
6497struct is_iterator_of_multibyte
6499 using value_type =
typename std::iterator_traits<T>::value_type;
6502 value =
sizeof(value_type) > 1
6506template<
typename IteratorType>
6507struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
6509 using iterator_type = IteratorType;
6510 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6511 using base_adapter_type = iterator_input_adapter<iterator_type>;
6512 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
6514 static adapter_type create(IteratorType first, IteratorType last)
6516 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6521template<
typename IteratorType>
6522typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
6524 using factory_type = iterator_input_adapter_factory<IteratorType>;
6525 return factory_type::create(first, last);
6532namespace container_input_adapter_factory_impl
6538template<
typename ContainerType,
typename Enable =
void>
6539struct container_input_adapter_factory {};
6541template<
typename ContainerType>
6542struct container_input_adapter_factory< ContainerType,
6543 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6545 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6547 static adapter_type create(
const ContainerType& container)
6549 return input_adapter(begin(container), end(container));
6555template<
typename ContainerType>
6556typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
6558 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
6563inline file_input_adapter input_adapter(std::FILE* file)
6565 return file_input_adapter(file);
6568inline input_stream_adapter input_adapter(std::istream& stream)
6570 return input_stream_adapter(stream);
6573inline input_stream_adapter input_adapter(std::istream&& stream)
6575 return input_stream_adapter(stream);
6579using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6582template <
typename CharT,
6583 typename std::enable_if <
6584 std::is_pointer<CharT>::value&&
6585 !std::is_array<CharT>::value&&
6586 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6587 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6589contiguous_bytes_input_adapter input_adapter(CharT b)
6591 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6592 const auto* ptr =
reinterpret_cast<const char*
>(b);
6593 return input_adapter(ptr, ptr + length);
6596template<
typename T, std::
size_t N>
6597auto input_adapter(T (&array)[N]) ->
decltype(input_adapter(array, array + N))
6599 return input_adapter(array, array + N);
6605class span_input_adapter
6608 template <
typename CharT,
6609 typename std::enable_if <
6610 std::is_pointer<CharT>::value&&
6611 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6612 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6614 span_input_adapter(CharT b, std::size_t l)
6615 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
6617 template<
class IteratorType,
6618 typename std::enable_if<
6619 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
6621 span_input_adapter(IteratorType first, IteratorType last)
6622 : ia(input_adapter(first, last)) {}
6624 contiguous_bytes_input_adapter&& get()
6626 return std::move(ia);
6630 contiguous_bytes_input_adapter ia;
6634NLOHMANN_JSON_NAMESPACE_END
6659NLOHMANN_JSON_NAMESPACE_BEGIN
6669template<
typename BasicJsonType>
6672 using number_integer_t =
typename BasicJsonType::number_integer_t;
6673 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6674 using number_float_t =
typename BasicJsonType::number_float_t;
6675 using string_t =
typename BasicJsonType::string_t;
6676 using binary_t =
typename BasicJsonType::binary_t;
6743 virtual bool key(string_t& val) = 0;
6773 const std::string& last_token,
6799template<
typename BasicJsonType>
6800class json_sax_dom_parser
6803 using number_integer_t =
typename BasicJsonType::number_integer_t;
6804 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6805 using number_float_t =
typename BasicJsonType::number_float_t;
6806 using string_t =
typename BasicJsonType::string_t;
6807 using binary_t =
typename BasicJsonType::binary_t;
6815 : root(r), allow_exceptions(allow_exceptions_)
6827 handle_value(
nullptr);
6831 bool boolean(
bool val)
6849 bool number_float(number_float_t val,
const string_t& )
6855 bool string(string_t& val)
6861 bool binary(binary_t& val)
6863 handle_value(std::move(val));
6867 bool start_object(std::size_t len)
6869 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6871 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6873 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6879 bool key(string_t& val)
6881 JSON_ASSERT(!ref_stack.empty());
6882 JSON_ASSERT(ref_stack.back()->is_object());
6885 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val));
6891 JSON_ASSERT(!ref_stack.empty());
6892 JSON_ASSERT(ref_stack.back()->is_object());
6894 ref_stack.back()->set_parents();
6895 ref_stack.pop_back();
6899 bool start_array(std::size_t len)
6901 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6903 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6905 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6913 JSON_ASSERT(!ref_stack.empty());
6914 JSON_ASSERT(ref_stack.back()->is_array());
6916 ref_stack.back()->set_parents();
6917 ref_stack.pop_back();
6921 template<
class Exception>
6922 bool parse_error(std::size_t ,
const std::string& ,
6923 const Exception& ex)
6926 static_cast<void>(ex);
6927 if (allow_exceptions)
6934 constexpr bool is_errored()
const
6946 template<
typename Value>
6947 JSON_HEDLEY_RETURNS_NON_NULL
6948 BasicJsonType* handle_value(Value&& v)
6950 if (ref_stack.empty())
6952 root = BasicJsonType(std::forward<Value>(v));
6956 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6958 if (ref_stack.back()->is_array())
6960 ref_stack.back()->m_data.m_value.array->emplace_back(std::forward<Value>(v));
6961 return &(ref_stack.back()->m_data.m_value.array->back());
6964 JSON_ASSERT(ref_stack.back()->is_object());
6965 JSON_ASSERT(object_element);
6966 *object_element = BasicJsonType(std::forward<Value>(v));
6967 return object_element;
6971 BasicJsonType& root;
6973 std::vector<BasicJsonType*> ref_stack {};
6975 BasicJsonType* object_element =
nullptr;
6977 bool errored =
false;
6979 const bool allow_exceptions =
true;
6982template<
typename BasicJsonType>
6983class json_sax_dom_callback_parser
6986 using number_integer_t =
typename BasicJsonType::number_integer_t;
6987 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6988 using number_float_t =
typename BasicJsonType::number_float_t;
6989 using string_t =
typename BasicJsonType::string_t;
6990 using binary_t =
typename BasicJsonType::binary_t;
6991 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6992 using parse_event_t =
typename BasicJsonType::parse_event_t;
6994 json_sax_dom_callback_parser(BasicJsonType& r,
6995 const parser_callback_t cb,
6996 const bool allow_exceptions_ =
true)
6997 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6999 keep_stack.push_back(
true);
7003 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
7004 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
7005 json_sax_dom_callback_parser& operator=(
const json_sax_dom_callback_parser&) =
delete;
7006 json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) =
default;
7007 ~json_sax_dom_callback_parser() =
default;
7011 handle_value(
nullptr);
7033 bool number_float(number_float_t val,
const string_t& )
7039 bool string(string_t& val)
7045 bool binary(binary_t& val)
7047 handle_value(std::move(val));
7051 bool start_object(std::size_t len)
7054 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
7055 keep_stack.push_back(keep);
7057 auto val = handle_value(BasicJsonType::value_t::object,
true);
7058 ref_stack.push_back(val.second);
7061 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7063 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
7069 bool key(string_t& val)
7071 BasicJsonType k = BasicJsonType(val);
7074 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
7075 key_keep_stack.push_back(keep);
7078 if (keep && ref_stack.back())
7080 object_element = &(ref_stack.back()->m_data.m_value.object->operator[](val) = discarded);
7088 if (ref_stack.back())
7090 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
7097 ref_stack.back()->set_parents();
7101 JSON_ASSERT(!ref_stack.empty());
7102 JSON_ASSERT(!keep_stack.empty());
7103 ref_stack.pop_back();
7104 keep_stack.pop_back();
7106 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
7109 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
7111 if (it->is_discarded())
7113 ref_stack.back()->erase(it);
7122 bool start_array(std::size_t len)
7124 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
7125 keep_stack.push_back(keep);
7127 auto val = handle_value(BasicJsonType::value_t::array,
true);
7128 ref_stack.push_back(val.second);
7131 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7133 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
7143 if (ref_stack.back())
7145 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
7148 ref_stack.back()->set_parents();
7157 JSON_ASSERT(!ref_stack.empty());
7158 JSON_ASSERT(!keep_stack.empty());
7159 ref_stack.pop_back();
7160 keep_stack.pop_back();
7163 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
7165 ref_stack.back()->m_data.m_value.array->pop_back();
7171 template<
class Exception>
7172 bool parse_error(std::size_t ,
const std::string& ,
7173 const Exception& ex)
7176 static_cast<void>(ex);
7177 if (allow_exceptions)
7184 constexpr bool is_errored()
const
7205 template<
typename Value>
7206 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
7208 JSON_ASSERT(!keep_stack.empty());
7212 if (!keep_stack.back())
7214 return {
false,
nullptr};
7218 auto value = BasicJsonType(std::forward<Value>(v));
7221 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
7226 return {
false,
nullptr};
7229 if (ref_stack.empty())
7231 root = std::move(value);
7232 return {
true, & root};
7237 if (!ref_stack.back())
7239 return {
false,
nullptr};
7243 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
7246 if (ref_stack.back()->is_array())
7248 ref_stack.back()->m_data.m_value.array->emplace_back(std::move(value));
7249 return {
true, & (ref_stack.back()->m_data.m_value.array->back())};
7253 JSON_ASSERT(ref_stack.back()->is_object());
7255 JSON_ASSERT(!key_keep_stack.empty());
7256 const bool store_element = key_keep_stack.back();
7257 key_keep_stack.pop_back();
7261 return {
false,
nullptr};
7264 JSON_ASSERT(object_element);
7265 *object_element = std::move(value);
7266 return {
true, object_element};
7270 BasicJsonType& root;
7272 std::vector<BasicJsonType*> ref_stack {};
7274 std::vector<bool> keep_stack {};
7276 std::vector<bool> key_keep_stack {};
7278 BasicJsonType* object_element =
nullptr;
7280 bool errored =
false;
7282 const parser_callback_t callback =
nullptr;
7284 const bool allow_exceptions =
true;
7286 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
7289template<
typename BasicJsonType>
7290class json_sax_acceptor
7293 using number_integer_t =
typename BasicJsonType::number_integer_t;
7294 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7295 using number_float_t =
typename BasicJsonType::number_float_t;
7296 using string_t =
typename BasicJsonType::string_t;
7297 using binary_t =
typename BasicJsonType::binary_t;
7324 bool string(string_t& )
7329 bool binary(binary_t& )
7334 bool start_object(std::size_t =
static_cast<std::size_t
>(-1))
7339 bool key(string_t& )
7349 bool start_array(std::size_t =
static_cast<std::size_t
>(-1))
7366NLOHMANN_JSON_NAMESPACE_END
7384#include <initializer_list>
7398NLOHMANN_JSON_NAMESPACE_BEGIN
7406template<
typename BasicJsonType>
7433 JSON_HEDLEY_RETURNS_NON_NULL
7439 case token_type::uninitialized:
7440 return "<uninitialized>";
7441 case token_type::literal_true:
7442 return "true literal";
7443 case token_type::literal_false:
7444 return "false literal";
7445 case token_type::literal_null:
7446 return "null literal";
7447 case token_type::value_string:
7448 return "string literal";
7449 case token_type::value_unsigned:
7450 case token_type::value_integer:
7451 case token_type::value_float:
7452 return "number literal";
7453 case token_type::begin_array:
7455 case token_type::begin_object:
7457 case token_type::end_array:
7459 case token_type::end_object:
7461 case token_type::name_separator:
7463 case token_type::value_separator:
7465 case token_type::parse_error:
7466 return "<parse error>";
7467 case token_type::end_of_input:
7468 return "end of input";
7469 case token_type::literal_or_value:
7470 return "'[', '{', or a literal";
7473 return "unknown token";
7483template<
typename BasicJsonType,
typename InputAdapterType>
7484class lexer :
public lexer_base<BasicJsonType>
7486 using number_integer_t =
typename BasicJsonType::number_integer_t;
7487 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7488 using number_float_t =
typename BasicJsonType::number_float_t;
7489 using string_t =
typename BasicJsonType::string_t;
7490 using char_type =
typename InputAdapterType::char_type;
7491 using char_int_type =
typename char_traits<char_type>::int_type;
7494 using token_type =
typename lexer_base<BasicJsonType>::token_type;
7496 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7497 : ia(std::move(adapter))
7498 , ignore_comments(ignore_comments_)
7499 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
7503 lexer(
const lexer&) =
delete;
7504 lexer(lexer&&) =
default;
7505 lexer& operator=(lexer&) =
delete;
7506 lexer& operator=(lexer&&) =
default;
7516 static char get_decimal_point() noexcept
7518 const auto* loc = localeconv();
7519 JSON_ASSERT(loc !=
nullptr);
7520 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7545 JSON_ASSERT(current ==
'u');
7548 const auto factors = { 12u, 8u, 4u, 0u };
7549 for (
const auto factor : factors)
7553 if (current >=
'0' && current <=
'9')
7555 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7557 else if (current >=
'A' && current <=
'F')
7559 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7561 else if (current >=
'a' && current <=
'f')
7563 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7571 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7590 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7592 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7595 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7598 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7604 error_message =
"invalid string: ill-formed UTF-8 byte";
7627 token_type scan_string()
7633 JSON_ASSERT(current ==
'\"');
7641 case char_traits<char_type>::eof():
7643 error_message =
"invalid string: missing closing quote";
7650 return token_type::value_string;
7694 const int codepoint1 = get_codepoint();
7695 int codepoint = codepoint1;
7697 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7699 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7700 return token_type::parse_error;
7704 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7707 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7709 const int codepoint2 = get_codepoint();
7711 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7713 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7714 return token_type::parse_error;
7718 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7721 codepoint =
static_cast<int>(
7723 (
static_cast<unsigned int>(codepoint1) << 10u)
7725 +
static_cast<unsigned int>(codepoint2)
7733 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7734 return token_type::parse_error;
7739 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7740 return token_type::parse_error;
7745 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7747 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7748 return token_type::parse_error;
7753 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7756 if (codepoint < 0x80)
7759 add(
static_cast<char_int_type
>(codepoint));
7761 else if (codepoint <= 0x7FF)
7764 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7765 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7767 else if (codepoint <= 0xFFFF)
7770 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7771 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7772 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7777 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7778 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7779 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7780 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7788 error_message =
"invalid string: forbidden character after backslash";
7789 return token_type::parse_error;
7798 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7799 return token_type::parse_error;
7804 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7805 return token_type::parse_error;
7810 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7811 return token_type::parse_error;
7816 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7817 return token_type::parse_error;
7822 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7823 return token_type::parse_error;
7828 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7829 return token_type::parse_error;
7834 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7835 return token_type::parse_error;
7840 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7841 return token_type::parse_error;
7846 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7847 return token_type::parse_error;
7852 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7853 return token_type::parse_error;
7858 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7859 return token_type::parse_error;
7864 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7865 return token_type::parse_error;
7870 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7871 return token_type::parse_error;
7876 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7877 return token_type::parse_error;
7882 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7883 return token_type::parse_error;
7888 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7889 return token_type::parse_error;
7894 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7895 return token_type::parse_error;
7900 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7901 return token_type::parse_error;
7906 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7907 return token_type::parse_error;
7912 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7913 return token_type::parse_error;
7918 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7919 return token_type::parse_error;
7924 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7925 return token_type::parse_error;
7930 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7931 return token_type::parse_error;
7936 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7937 return token_type::parse_error;
7942 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7943 return token_type::parse_error;
7948 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7949 return token_type::parse_error;
7954 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7955 return token_type::parse_error;
7960 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7961 return token_type::parse_error;
7966 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7967 return token_type::parse_error;
7972 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7973 return token_type::parse_error;
7978 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7979 return token_type::parse_error;
7984 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7985 return token_type::parse_error;
8120 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
8122 return token_type::parse_error;
8130 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
8132 return token_type::parse_error;
8154 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
8156 return token_type::parse_error;
8164 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
8166 return token_type::parse_error;
8174 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8176 return token_type::parse_error;
8186 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8188 return token_type::parse_error;
8196 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
8198 return token_type::parse_error;
8206 error_message =
"invalid string: ill-formed UTF-8 byte";
8207 return token_type::parse_error;
8230 case char_traits<char_type>::eof():
8247 case char_traits<char_type>::eof():
8250 error_message =
"invalid comment; missing closing '*/'";
8278 error_message =
"invalid comment; expecting '/' or '*' after '/'";
8284 JSON_HEDLEY_NON_NULL(2)
8285 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
8287 f = std::strtof(str, endptr);
8290 JSON_HEDLEY_NON_NULL(2)
8291 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
8293 f = std::strtod(str, endptr);
8296 JSON_HEDLEY_NON_NULL(2)
8297 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
8299 f = std::strtold(str, endptr);
8342 token_type scan_number()
8349 token_type number_type = token_type::value_unsigned;
8357 goto scan_number_minus;
8363 goto scan_number_zero;
8377 goto scan_number_any1;
8387 number_type = token_type::value_integer;
8393 goto scan_number_zero;
8407 goto scan_number_any1;
8412 error_message =
"invalid number; expected digit after '-'";
8413 return token_type::parse_error;
8423 add(decimal_point_char);
8424 goto scan_number_decimal1;
8431 goto scan_number_exponent;
8435 goto scan_number_done;
8454 goto scan_number_any1;
8459 add(decimal_point_char);
8460 goto scan_number_decimal1;
8467 goto scan_number_exponent;
8471 goto scan_number_done;
8474scan_number_decimal1:
8476 number_type = token_type::value_float;
8491 goto scan_number_decimal2;
8496 error_message =
"invalid number; expected digit after '.'";
8497 return token_type::parse_error;
8501scan_number_decimal2:
8517 goto scan_number_decimal2;
8524 goto scan_number_exponent;
8528 goto scan_number_done;
8531scan_number_exponent:
8533 number_type = token_type::value_float;
8540 goto scan_number_sign;
8555 goto scan_number_any2;
8561 "invalid number; expected '+', '-', or digit after exponent";
8562 return token_type::parse_error;
8582 goto scan_number_any2;
8587 error_message =
"invalid number; expected digit after exponent sign";
8588 return token_type::parse_error;
8608 goto scan_number_any2;
8612 goto scan_number_done;
8620 char* endptr =
nullptr;
8624 if (number_type == token_type::value_unsigned)
8626 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8629 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8633 value_unsigned =
static_cast<number_unsigned_t
>(x);
8634 if (value_unsigned == x)
8636 return token_type::value_unsigned;
8640 else if (number_type == token_type::value_integer)
8642 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8645 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8649 value_integer =
static_cast<number_integer_t
>(x);
8650 if (value_integer == x)
8652 return token_type::value_integer;
8659 strtof(value_float, token_buffer.data(), &endptr);
8662 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8664 return token_type::value_float;
8672 JSON_HEDLEY_NON_NULL(2)
8673 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
8674 token_type return_type)
8676 JSON_ASSERT(char_traits<char_type>::to_char_type(current) == literal_text[0]);
8677 for (std::size_t i = 1; i < length; ++i)
8679 if (JSON_HEDLEY_UNLIKELY(char_traits<char_type>::to_char_type(get()) != literal_text[i]))
8681 error_message =
"invalid literal";
8682 return token_type::parse_error;
8693 void reset() noexcept
8695 token_buffer.clear();
8696 token_string.clear();
8697 token_string.push_back(char_traits<char_type>::to_char_type(current));
8712 ++position.chars_read_total;
8713 ++position.chars_read_current_line;
8722 current = ia.get_character();
8725 if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))
8727 token_string.push_back(char_traits<char_type>::to_char_type(current));
8730 if (current ==
'\n')
8732 ++position.lines_read;
8733 position.chars_read_current_line = 0;
8751 --position.chars_read_total;
8754 if (position.chars_read_current_line == 0)
8756 if (position.lines_read > 0)
8758 --position.lines_read;
8763 --position.chars_read_current_line;
8766 if (JSON_HEDLEY_LIKELY(current != char_traits<char_type>::eof()))
8768 JSON_ASSERT(!token_string.empty());
8769 token_string.pop_back();
8774 void add(char_int_type c)
8776 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8787 return value_integer;
8793 return value_unsigned;
8805 return token_buffer;
8825 for (
const auto c : token_string)
8827 if (
static_cast<unsigned char>(c) <=
'\x1F')
8830 std::array<char, 9> cs{{}};
8831 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8832 result += cs.data();
8837 result.push_back(
static_cast<std::string::value_type
>(c));
8845 JSON_HEDLEY_RETURNS_NON_NULL
8848 return error_message;
8864 return get() == 0xBB && get() == 0xBF;
8873 void skip_whitespace()
8879 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8885 if (position.chars_read_total == 0 && !skip_bom())
8887 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8888 return token_type::parse_error;
8895 while (ignore_comments && current ==
'/')
8897 if (!scan_comment())
8899 return token_type::parse_error;
8910 return token_type::begin_array;
8912 return token_type::end_array;
8914 return token_type::begin_object;
8916 return token_type::end_object;
8918 return token_type::name_separator;
8920 return token_type::value_separator;
8925 std::array<char_type, 4> true_literal = {{
static_cast<char_type
>(
't'),
static_cast<char_type
>(
'r'),
static_cast<char_type
>(
'u'),
static_cast<char_type
>(
'e')}};
8926 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8930 std::array<char_type, 5> false_literal = {{
static_cast<char_type
>(
'f'),
static_cast<char_type
>(
'a'),
static_cast<char_type
>(
'l'),
static_cast<char_type
>(
's'),
static_cast<char_type
>(
'e')}};
8931 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8935 std::array<char_type, 4> null_literal = {{
static_cast<char_type
>(
'n'),
static_cast<char_type
>(
'u'),
static_cast<char_type
>(
'l'),
static_cast<char_type
>(
'l')}};
8936 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8941 return scan_string();
8955 return scan_number();
8960 case char_traits<char_type>::eof():
8961 return token_type::end_of_input;
8965 error_message =
"invalid literal";
8966 return token_type::parse_error;
8972 InputAdapterType ia;
8975 const bool ignore_comments =
false;
8978 char_int_type current = char_traits<char_type>::eof();
8981 bool next_unget =
false;
8984 position_t position {};
8987 std::vector<char_type> token_string {};
8990 string_t token_buffer {};
8993 const char* error_message =
"";
8996 number_integer_t value_integer = 0;
8997 number_unsigned_t value_unsigned = 0;
8998 number_float_t value_float = 0;
9001 const char_int_type decimal_point_char =
'.';
9005NLOHMANN_JSON_NAMESPACE_END
9031NLOHMANN_JSON_NAMESPACE_BEGIN
9036using null_function_t =
decltype(std::declval<T&>().null());
9039using boolean_function_t =
9040 decltype(std::declval<T&>().boolean(std::declval<bool>()));
9042template<
typename T,
typename Integer>
9043using number_integer_function_t =
9044 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
9046template<
typename T,
typename Un
signed>
9047using number_unsigned_function_t =
9048 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
9050template<
typename T,
typename Float,
typename String>
9051using number_float_function_t =
decltype(std::declval<T&>().number_float(
9052 std::declval<Float>(), std::declval<const String&>()));
9054template<
typename T,
typename String>
9055using string_function_t =
9056 decltype(std::declval<T&>().string(std::declval<String&>()));
9058template<
typename T,
typename Binary>
9059using binary_function_t =
9060 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
9063using start_object_function_t =
9064 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
9066template<
typename T,
typename String>
9067using key_function_t =
9068 decltype(std::declval<T&>().key(std::declval<String&>()));
9071using end_object_function_t =
decltype(std::declval<T&>().end_object());
9074using start_array_function_t =
9075 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9078using end_array_function_t =
decltype(std::declval<T&>().end_array());
9080template<
typename T,
typename Exception>
9081using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9082 std::declval<std::size_t>(), std::declval<const std::string&>(),
9083 std::declval<const Exception&>()));
9085template<
typename SAX,
typename BasicJsonType>
9089 static_assert(is_basic_json<BasicJsonType>::value,
9090 "BasicJsonType must be of type basic_json<...>");
9092 using number_integer_t =
typename BasicJsonType::number_integer_t;
9093 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9094 using number_float_t =
typename BasicJsonType::number_float_t;
9095 using string_t =
typename BasicJsonType::string_t;
9096 using binary_t =
typename BasicJsonType::binary_t;
9097 using exception_t =
typename BasicJsonType::exception;
9100 static constexpr bool value =
9101 is_detected_exact<bool, null_function_t, SAX>::value &&
9102 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9103 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9104 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9105 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9106 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9107 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9108 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9109 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9110 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9111 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9112 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9113 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9116template<
typename SAX,
typename BasicJsonType>
9117struct is_sax_static_asserts
9120 static_assert(is_basic_json<BasicJsonType>::value,
9121 "BasicJsonType must be of type basic_json<...>");
9123 using number_integer_t =
typename BasicJsonType::number_integer_t;
9124 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9125 using number_float_t =
typename BasicJsonType::number_float_t;
9126 using string_t =
typename BasicJsonType::string_t;
9127 using binary_t =
typename BasicJsonType::binary_t;
9128 using exception_t =
typename BasicJsonType::exception;
9131 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9132 "Missing/invalid function: bool null()");
9133 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9134 "Missing/invalid function: bool boolean(bool)");
9135 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9136 "Missing/invalid function: bool boolean(bool)");
9138 is_detected_exact<bool, number_integer_function_t, SAX,
9140 "Missing/invalid function: bool number_integer(number_integer_t)");
9142 is_detected_exact<bool, number_unsigned_function_t, SAX,
9144 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9145 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9146 number_float_t, string_t>
::value,
9147 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9149 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9150 "Missing/invalid function: bool string(string_t&)");
9152 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9153 "Missing/invalid function: bool binary(binary_t&)");
9154 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9155 "Missing/invalid function: bool start_object(std::size_t)");
9156 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9157 "Missing/invalid function: bool key(string_t&)");
9158 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9159 "Missing/invalid function: bool end_object()");
9160 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9161 "Missing/invalid function: bool start_array(std::size_t)");
9162 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9163 "Missing/invalid function: bool end_array()");
9165 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9166 "Missing/invalid function: bool parse_error(std::size_t, const "
9167 "std::string&, const exception&)");
9171NLOHMANN_JSON_NAMESPACE_END
9180NLOHMANN_JSON_NAMESPACE_BEGIN
9199static inline bool little_endianness(
int num = 1) noexcept
9201 return *
reinterpret_cast<char*
>(&num) == 1;
9211template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
9214 using number_integer_t =
typename BasicJsonType::number_integer_t;
9215 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9216 using number_float_t =
typename BasicJsonType::number_float_t;
9217 using string_t =
typename BasicJsonType::string_t;
9218 using binary_t =
typename BasicJsonType::binary_t;
9219 using json_sax_t = SAX;
9220 using char_type =
typename InputAdapterType::char_type;
9221 using char_int_type =
typename char_traits<char_type>::int_type;
9229 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9249 JSON_HEDLEY_NON_NULL(3)
9252 const
bool strict = true,
9256 bool result =
false;
9260 case input_format_t::bson:
9261 result = parse_bson_internal();
9264 case input_format_t::cbor:
9265 result = parse_cbor_internal(
true, tag_handler);
9268 case input_format_t::msgpack:
9269 result = parse_msgpack_internal();
9272 case input_format_t::ubjson:
9273 case input_format_t::bjdata:
9274 result = parse_ubjson_internal();
9277 case input_format_t::json:
9285 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9296 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(110, chars_read,
9297 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9313 bool parse_bson_internal()
9315 std::int32_t document_size{};
9316 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9318 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
9323 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
9328 return sax->end_object();
9338 bool get_bson_cstr(string_t& result)
9340 auto out = std::back_inserter(result);
9344 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
9348 if (current == 0x00)
9352 *out++ =
static_cast<typename string_t::value_type
>(current);
9367 template<
typename NumberType>
9368 bool get_bson_string(
const NumberType len, string_t& result)
9370 if (JSON_HEDLEY_UNLIKELY(len < 1))
9372 auto last_token = get_token_string();
9374 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
9377 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != char_traits<char_type>::eof();
9389 template<
typename NumberType>
9390 bool get_bson_binary(
const NumberType len, binary_t& result)
9392 if (JSON_HEDLEY_UNLIKELY(len < 0))
9394 auto last_token = get_token_string();
9396 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
9400 std::uint8_t subtype{};
9401 get_number<std::uint8_t>(input_format_t::bson, subtype);
9402 result.set_subtype(subtype);
9404 return get_binary(input_format_t::bson, len, result);
9417 bool parse_bson_element_internal(
const char_int_type element_type,
9418 const std::size_t element_type_parse_position)
9420 switch (element_type)
9425 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9432 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
9437 return parse_bson_internal();
9442 return parse_bson_array();
9449 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
9454 return sax->boolean(get() != 0);
9464 std::int32_t value{};
9465 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9470 std::int64_t value{};
9471 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9476 std::array<char, 3> cr{{}};
9477 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
9478 const std::string cr_str{cr.data()};
9479 return sax->parse_error(element_type_parse_position, cr_str,
9480 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
9497 bool parse_bson_element_list(
const bool is_array)
9501 while (
auto element_type = get())
9503 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
9508 const std::size_t element_type_parse_position = chars_read;
9509 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(
key)))
9514 if (!is_array && !sax->key(
key))
9519 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
9535 bool parse_bson_array()
9537 std::int32_t document_size{};
9538 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9540 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
9545 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
9550 return sax->end_array();
9565 bool parse_cbor_internal(
const bool get_char,
9568 switch (get_char ? get() : current)
9571 case char_traits<char_type>::eof():
9599 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9603 std::uint8_t number{};
9604 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9609 std::uint16_t number{};
9610 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9615 std::uint32_t number{};
9616 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9621 std::uint64_t number{};
9622 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9650 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
9654 std::uint8_t number{};
9655 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9660 std::uint16_t number{};
9661 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9666 std::uint32_t number{};
9667 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9672 std::uint64_t number{};
9673 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
9674 -
static_cast<number_integer_t
>(number));
9709 return get_cbor_binary(b) && sax->binary(b);
9744 return get_cbor_string(s) && sax->string(s);
9772 return get_cbor_array(
9773 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9778 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9783 std::uint16_t len{};
9784 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9789 std::uint32_t len{};
9790 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9795 std::uint64_t len{};
9796 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9800 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
9827 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9832 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9837 std::uint16_t len{};
9838 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9843 std::uint32_t len{};
9844 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9849 std::uint64_t len{};
9850 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9854 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
9876 switch (tag_handler)
9880 auto last_token = get_token_string();
9882 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9892 std::uint8_t subtype_to_ignore{};
9893 get_number(input_format_t::cbor, subtype_to_ignore);
9898 std::uint16_t subtype_to_ignore{};
9899 get_number(input_format_t::cbor, subtype_to_ignore);
9904 std::uint32_t subtype_to_ignore{};
9905 get_number(input_format_t::cbor, subtype_to_ignore);
9910 std::uint64_t subtype_to_ignore{};
9911 get_number(input_format_t::cbor, subtype_to_ignore);
9917 return parse_cbor_internal(
true, tag_handler);
9928 std::uint8_t subtype{};
9929 get_number(input_format_t::cbor, subtype);
9930 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9935 std::uint16_t subtype{};
9936 get_number(input_format_t::cbor, subtype);
9937 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9942 std::uint32_t subtype{};
9943 get_number(input_format_t::cbor, subtype);
9944 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9949 std::uint64_t subtype{};
9950 get_number(input_format_t::cbor, subtype);
9951 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9955 return parse_cbor_internal(
true, tag_handler);
9958 return get_cbor_binary(b) && sax->binary(b);
9968 return sax->boolean(
false);
9971 return sax->boolean(
true);
9978 const auto byte1_raw = get();
9979 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9983 const auto byte2_raw = get();
9984 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9989 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9990 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
10000 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
10001 const double val = [&half]
10003 const int exp = (half >> 10u) & 0x1Fu;
10004 const unsigned int mant = half & 0x3FFu;
10005 JSON_ASSERT(0 <= exp&& exp <= 32);
10006 JSON_ASSERT(mant <= 1024);
10010 return std::ldexp(mant, -24);
10013 ? std::numeric_limits<double>::infinity()
10014 : std::numeric_limits<double>::quiet_NaN();
10016 return std::ldexp(mant + 1024, exp - 25);
10019 return sax->number_float((half & 0x8000u) != 0
10020 ?
static_cast<number_float_t
>(-val)
10021 :
static_cast<number_float_t
>(val),
"");
10027 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10033 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10038 auto last_token = get_token_string();
10040 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10056 bool get_cbor_string(string_t& result)
10058 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10091 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10096 std::uint8_t len{};
10097 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10102 std::uint16_t len{};
10103 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10108 std::uint32_t len{};
10109 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10114 std::uint64_t len{};
10115 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10120 while (get() != 0xFF)
10123 if (!get_cbor_string(chunk))
10127 result.append(chunk);
10134 auto last_token = get_token_string();
10136 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10152 bool get_cbor_binary(binary_t& result)
10154 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10187 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10192 std::uint8_t len{};
10193 return get_number(input_format_t::cbor, len) &&
10194 get_binary(input_format_t::cbor, len, result);
10199 std::uint16_t len{};
10200 return get_number(input_format_t::cbor, len) &&
10201 get_binary(input_format_t::cbor, len, result);
10206 std::uint32_t len{};
10207 return get_number(input_format_t::cbor, len) &&
10208 get_binary(input_format_t::cbor, len, result);
10213 std::uint64_t len{};
10214 return get_number(input_format_t::cbor, len) &&
10215 get_binary(input_format_t::cbor, len, result);
10220 while (get() != 0xFF)
10223 if (!get_cbor_binary(chunk))
10227 result.insert(result.end(), chunk.begin(), chunk.end());
10234 auto last_token = get_token_string();
10236 exception_message(input_format_t::cbor, concat(
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x", last_token),
"binary"),
nullptr));
10247 bool get_cbor_array(
const std::size_t len,
10250 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10255 if (len !=
static_cast<std::size_t
>(-1))
10257 for (std::size_t i = 0; i < len; ++i)
10259 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10267 while (get() != 0xFF)
10269 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10276 return sax->end_array();
10285 bool get_cbor_object(
const std::size_t len,
10288 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10296 if (len !=
static_cast<std::size_t
>(-1))
10298 for (std::size_t i = 0; i < len; ++i)
10301 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(
key) || !sax->key(
key)))
10306 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10315 while (get() != 0xFF)
10317 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(
key) || !sax->key(
key)))
10322 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10331 return sax->end_object();
10341 bool parse_msgpack_internal()
10346 case char_traits<char_type>::eof():
10478 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10497 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10516 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10556 return get_msgpack_string(s) && sax->string(s);
10560 return sax->null();
10563 return sax->boolean(
false);
10566 return sax->boolean(
true);
10581 return get_msgpack_binary(b) && sax->binary(b);
10587 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10593 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10598 std::uint8_t number{};
10599 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10604 std::uint16_t number{};
10605 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10610 std::uint32_t number{};
10611 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10616 std::uint64_t number{};
10617 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10622 std::int8_t number{};
10623 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10628 std::int16_t number{};
10629 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10634 std::int32_t number{};
10635 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10640 std::int64_t number{};
10641 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10646 std::uint16_t len{};
10647 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
10652 std::uint32_t len{};
10653 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
10658 std::uint16_t len{};
10659 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
10664 std::uint32_t len{};
10665 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
10701 return sax->number_integer(
static_cast<std::int8_t
>(current));
10705 auto last_token = get_token_string();
10707 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10722 bool get_msgpack_string(string_t& result)
10724 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
10765 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
10770 std::uint8_t len{};
10771 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10776 std::uint16_t len{};
10777 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10782 std::uint32_t len{};
10783 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10788 auto last_token = get_token_string();
10790 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
10805 bool get_msgpack_binary(binary_t& result)
10808 auto assign_and_return_true = [&result](std::int8_t subtype)
10810 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10818 std::uint8_t len{};
10819 return get_number(input_format_t::msgpack, len) &&
10820 get_binary(input_format_t::msgpack, len, result);
10825 std::uint16_t len{};
10826 return get_number(input_format_t::msgpack, len) &&
10827 get_binary(input_format_t::msgpack, len, result);
10832 std::uint32_t len{};
10833 return get_number(input_format_t::msgpack, len) &&
10834 get_binary(input_format_t::msgpack, len, result);
10839 std::uint8_t len{};
10840 std::int8_t subtype{};
10841 return get_number(input_format_t::msgpack, len) &&
10842 get_number(input_format_t::msgpack, subtype) &&
10843 get_binary(input_format_t::msgpack, len, result) &&
10844 assign_and_return_true(subtype);
10849 std::uint16_t len{};
10850 std::int8_t subtype{};
10851 return get_number(input_format_t::msgpack, len) &&
10852 get_number(input_format_t::msgpack, subtype) &&
10853 get_binary(input_format_t::msgpack, len, result) &&
10854 assign_and_return_true(subtype);
10859 std::uint32_t len{};
10860 std::int8_t subtype{};
10861 return get_number(input_format_t::msgpack, len) &&
10862 get_number(input_format_t::msgpack, subtype) &&
10863 get_binary(input_format_t::msgpack, len, result) &&
10864 assign_and_return_true(subtype);
10869 std::int8_t subtype{};
10870 return get_number(input_format_t::msgpack, subtype) &&
10871 get_binary(input_format_t::msgpack, 1, result) &&
10872 assign_and_return_true(subtype);
10877 std::int8_t subtype{};
10878 return get_number(input_format_t::msgpack, subtype) &&
10879 get_binary(input_format_t::msgpack, 2, result) &&
10880 assign_and_return_true(subtype);
10885 std::int8_t subtype{};
10886 return get_number(input_format_t::msgpack, subtype) &&
10887 get_binary(input_format_t::msgpack, 4, result) &&
10888 assign_and_return_true(subtype);
10893 std::int8_t subtype{};
10894 return get_number(input_format_t::msgpack, subtype) &&
10895 get_binary(input_format_t::msgpack, 8, result) &&
10896 assign_and_return_true(subtype);
10901 std::int8_t subtype{};
10902 return get_number(input_format_t::msgpack, subtype) &&
10903 get_binary(input_format_t::msgpack, 16, result) &&
10904 assign_and_return_true(subtype);
10916 bool get_msgpack_array(
const std::size_t len)
10918 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10923 for (std::size_t i = 0; i < len; ++i)
10925 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10931 return sax->end_array();
10938 bool get_msgpack_object(
const std::size_t len)
10940 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10946 for (std::size_t i = 0; i < len; ++i)
10949 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(
key) || !sax->key(
key)))
10954 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10961 return sax->end_object();
10975 bool parse_ubjson_internal(
const bool get_char =
true)
10977 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10994 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
11001 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11010 std::uint8_t len{};
11011 return get_number(input_format, len) && get_string(input_format, len, result);
11017 return get_number(input_format, len) && get_string(input_format, len, result);
11022 std::int16_t len{};
11023 return get_number(input_format, len) && get_string(input_format, len, result);
11028 std::int32_t len{};
11029 return get_number(input_format, len) && get_string(input_format, len, result);
11034 std::int64_t len{};
11035 return get_number(input_format, len) && get_string(input_format, len, result);
11040 if (input_format != input_format_t::bjdata)
11044 std::uint16_t len{};
11045 return get_number(input_format, len) && get_string(input_format, len, result);
11050 if (input_format != input_format_t::bjdata)
11054 std::uint32_t len{};
11055 return get_number(input_format, len) && get_string(input_format, len, result);
11060 if (input_format != input_format_t::bjdata)
11064 std::uint64_t len{};
11065 return get_number(input_format, len) && get_string(input_format, len, result);
11071 auto last_token = get_token_string();
11072 std::string message;
11074 if (input_format != input_format_t::bjdata)
11076 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11080 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11082 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11089 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11091 std::pair<std::size_t, char_int_type> size_and_type;
11093 bool no_ndarray =
true;
11095 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11100 if (size_and_type.first != npos)
11102 if (size_and_type.second != 0)
11104 if (size_and_type.second !=
'N')
11106 for (std::size_t i = 0; i < size_and_type.first; ++i)
11108 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11112 dim.push_back(dimlen);
11118 for (std::size_t i = 0; i < size_and_type.first; ++i)
11120 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11124 dim.push_back(dimlen);
11130 while (current !=
']')
11132 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11136 dim.push_back(dimlen);
11154 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11158 prefix = get_ignore_noop();
11165 std::uint8_t number{};
11166 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11170 result =
static_cast<std::size_t
>(number);
11176 std::int8_t number{};
11177 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11183 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11184 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11186 result =
static_cast<std::size_t
>(number);
11192 std::int16_t number{};
11193 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11199 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11200 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11202 result =
static_cast<std::size_t
>(number);
11208 std::int32_t number{};
11209 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11215 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11216 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11218 result =
static_cast<std::size_t
>(number);
11224 std::int64_t number{};
11225 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11231 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read,
11232 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11234 if (!value_in_range_of<std::size_t>(number))
11236 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11237 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11239 result =
static_cast<std::size_t
>(number);
11245 if (input_format != input_format_t::bjdata)
11249 std::uint16_t number{};
11250 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11254 result =
static_cast<std::size_t
>(number);
11260 if (input_format != input_format_t::bjdata)
11264 std::uint32_t number{};
11265 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11269 result = conditional_static_cast<std::size_t>(number);
11275 if (input_format != input_format_t::bjdata)
11279 std::uint64_t number{};
11280 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11284 if (!value_in_range_of<std::size_t>(number))
11286 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11287 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11289 result = detail::conditional_static_cast<std::size_t>(number);
11295 if (input_format != input_format_t::bjdata)
11301 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(113, chars_read, exception_message(input_format,
"ndarray dimensional vector is not allowed",
"size"),
nullptr));
11303 std::vector<size_t> dim;
11304 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
11308 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
11310 result = dim.at(dim.size() - 1);
11324 string_t
key =
"_ArraySize_";
11325 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(
key) || !sax->start_array(dim.size())))
11333 if (result == 0 || result == npos)
11335 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format,
"excessive ndarray size caused overflow",
"size"),
nullptr));
11337 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
11343 return sax->end_array();
11352 auto last_token = get_token_string();
11353 std::string message;
11355 if (input_format != input_format_t::bjdata)
11357 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
11361 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
11363 return sax->parse_error(chars_read, last_token,
parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
11377 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
11379 result.first = npos;
11381 bool is_ndarray =
false;
11385 if (current ==
'$')
11387 result.second = get();
11388 if (input_format == input_format_t::bjdata
11389 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
11391 auto last_token = get_token_string();
11393 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
11396 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
11402 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
11404 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11408 auto last_token = get_token_string();
11410 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
11413 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11414 if (input_format == input_format_t::bjdata && is_ndarray)
11416 if (inside_ndarray)
11418 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
11419 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
11421 result.second |= (1 << 8);
11426 if (current ==
'#')
11428 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11429 if (input_format == input_format_t::bjdata && is_ndarray)
11431 return sax->parse_error(chars_read, get_token_string(),
parse_error::create(112, chars_read,
11432 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
11444 bool get_ubjson_value(
const char_int_type prefix)
11448 case char_traits<char_type>::eof():
11449 return unexpect_eof(input_format,
"value");
11452 return sax->boolean(
true);
11454 return sax->boolean(
false);
11457 return sax->null();
11461 std::uint8_t number{};
11462 return get_number(input_format, number) && sax->number_unsigned(number);
11467 std::int8_t number{};
11468 return get_number(input_format, number) && sax->number_integer(number);
11473 std::int16_t number{};
11474 return get_number(input_format, number) && sax->number_integer(number);
11479 std::int32_t number{};
11480 return get_number(input_format, number) && sax->number_integer(number);
11485 std::int64_t number{};
11486 return get_number(input_format, number) && sax->number_integer(number);
11491 if (input_format != input_format_t::bjdata)
11495 std::uint16_t number{};
11496 return get_number(input_format, number) && sax->number_unsigned(number);
11501 if (input_format != input_format_t::bjdata)
11505 std::uint32_t number{};
11506 return get_number(input_format, number) && sax->number_unsigned(number);
11511 if (input_format != input_format_t::bjdata)
11515 std::uint64_t number{};
11516 return get_number(input_format, number) && sax->number_unsigned(number);
11521 if (input_format != input_format_t::bjdata)
11525 const auto byte1_raw = get();
11526 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11530 const auto byte2_raw = get();
11531 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11536 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
11537 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
11547 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
11548 const double val = [&half]
11550 const int exp = (half >> 10u) & 0x1Fu;
11551 const unsigned int mant = half & 0x3FFu;
11552 JSON_ASSERT(0 <= exp&& exp <= 32);
11553 JSON_ASSERT(mant <= 1024);
11557 return std::ldexp(mant, -24);
11560 ? std::numeric_limits<double>::infinity()
11561 : std::numeric_limits<double>::quiet_NaN();
11563 return std::ldexp(mant + 1024, exp - 25);
11566 return sax->number_float((half & 0x8000u) != 0
11567 ?
static_cast<number_float_t
>(-val)
11568 :
static_cast<number_float_t
>(val),
"");
11574 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11580 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11585 return get_ubjson_high_precision_number();
11591 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
11595 if (JSON_HEDLEY_UNLIKELY(current > 127))
11597 auto last_token = get_token_string();
11599 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
11601 string_t s(1,
static_cast<typename string_t::value_type
>(current));
11602 return sax->string(s);
11608 return get_ubjson_string(s) && sax->string(s);
11612 return get_ubjson_array();
11615 return get_ubjson_object();
11620 auto last_token = get_token_string();
11621 return sax->parse_error(chars_read, last_token,
parse_error::create(112, chars_read, exception_message(input_format,
"invalid byte: 0x" + last_token,
"value"),
nullptr));
11627 bool get_ubjson_array()
11629 std::pair<std::size_t, char_int_type> size_and_type;
11630 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11638 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11640 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
11641 auto it = std::lower_bound(bjd_types_map.begin(), bjd_types_map.end(), size_and_type.second, [](
const bjd_type & p, char_int_type t)
11643 return p.first < t;
11645 string_t
key =
"_ArrayType_";
11646 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
11648 auto last_token = get_token_string();
11650 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
11653 string_t type = it->second;
11654 if (JSON_HEDLEY_UNLIKELY(!sax->key(
key) || !sax->string(type)))
11659 if (size_and_type.second ==
'C')
11661 size_and_type.second =
'U';
11664 key =
"_ArrayData_";
11665 if (JSON_HEDLEY_UNLIKELY(!sax->key(
key) || !sax->start_array(size_and_type.first) ))
11670 for (std::size_t i = 0; i < size_and_type.first; ++i)
11672 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11678 return (sax->end_array() && sax->end_object());
11681 if (size_and_type.first != npos)
11683 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
11688 if (size_and_type.second != 0)
11690 if (size_and_type.second !=
'N')
11692 for (std::size_t i = 0; i < size_and_type.first; ++i)
11694 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11703 for (std::size_t i = 0; i < size_and_type.first; ++i)
11705 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11714 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
11719 while (current !=
']')
11721 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
11729 return sax->end_array();
11735 bool get_ubjson_object()
11737 std::pair<std::size_t, char_int_type> size_and_type;
11738 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11744 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11746 auto last_token = get_token_string();
11748 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
11752 if (size_and_type.first != npos)
11754 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
11759 if (size_and_type.second != 0)
11761 for (std::size_t i = 0; i < size_and_type.first; ++i)
11763 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(
key) || !sax->key(
key)))
11767 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11776 for (std::size_t i = 0; i < size_and_type.first; ++i)
11778 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(
key) || !sax->key(
key)))
11782 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11792 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
11797 while (current !=
'}')
11799 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(
key,
false) || !sax->key(
key)))
11803 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11812 return sax->end_object();
11818 bool get_ubjson_high_precision_number()
11821 std::size_t size{};
11822 bool no_ndarray =
true;
11823 auto res = get_ubjson_size_value(size, no_ndarray);
11824 if (JSON_HEDLEY_UNLIKELY(!res))
11830 std::vector<char> number_vector;
11831 for (std::size_t i = 0; i < size; ++i)
11834 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11838 number_vector.push_back(
static_cast<char>(current));
11842 using ia_type =
decltype(detail::input_adapter(number_vector));
11844 const auto result_number = number_lexer.scan();
11845 const auto number_string = number_lexer.get_token_string();
11846 const auto result_remainder = number_lexer.scan();
11850 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
11853 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11856 switch (result_number)
11858 case token_type::value_integer:
11859 return sax->number_integer(number_lexer.get_number_integer());
11860 case token_type::value_unsigned:
11861 return sax->number_unsigned(number_lexer.get_number_unsigned());
11862 case token_type::value_float:
11863 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
11864 case token_type::uninitialized:
11865 case token_type::literal_true:
11866 case token_type::literal_false:
11867 case token_type::literal_null:
11868 case token_type::value_string:
11869 case token_type::begin_array:
11870 case token_type::begin_object:
11871 case token_type::end_array:
11872 case token_type::end_object:
11873 case token_type::name_separator:
11874 case token_type::value_separator:
11875 case token_type::parse_error:
11876 case token_type::end_of_input:
11877 case token_type::literal_or_value:
11880 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11897 char_int_type get()
11900 return current = ia.get_character();
11906 char_int_type get_ignore_noop()
11912 while (current ==
'N');
11932 template<
typename NumberType,
bool InputIsLittleEndian = false>
11933 bool get_number(
const input_format_t format, NumberType& result)
11936 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
11937 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
11940 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
11946 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
11948 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
11952 vec[i] =
static_cast<std::uint8_t
>(current);
11957 std::memcpy(&result, vec.data(),
sizeof(NumberType));
11975 template<
typename NumberType>
11977 const NumberType len,
11980 bool success =
true;
11981 for (NumberType i = 0; i < len; i++)
11984 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
11989 result.push_back(
static_cast<typename string_t::value_type
>(current));
12008 template<
typename NumberType>
12010 const NumberType len,
12013 bool success =
true;
12014 for (NumberType i = 0; i < len; i++)
12017 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
12022 result.push_back(
static_cast<std::uint8_t
>(current));
12032 JSON_HEDLEY_NON_NULL(3)
12033 bool unexpect_eof(const
input_format_t format, const
char* context)
const
12035 if (JSON_HEDLEY_UNLIKELY(current == char_traits<char_type>::eof()))
12037 return sax->parse_error(chars_read,
"<end of file>",
12038 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
12046 std::string get_token_string()
const
12048 std::array<char, 3> cr{{}};
12049 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
12050 return std::string{cr.data()};
12060 const std::string&
detail,
12061 const std::string& context)
const
12063 std::string error_msg =
"syntax error while parsing ";
12067 case input_format_t::cbor:
12068 error_msg +=
"CBOR";
12071 case input_format_t::msgpack:
12072 error_msg +=
"MessagePack";
12075 case input_format_t::ubjson:
12076 error_msg +=
"UBJSON";
12079 case input_format_t::bson:
12080 error_msg +=
"BSON";
12083 case input_format_t::bjdata:
12084 error_msg +=
"BJData";
12087 case input_format_t::json:
12089 JSON_ASSERT(
false);
12092 return concat(error_msg,
' ', context,
": ",
detail);
12096 static JSON_INLINE_VARIABLE
constexpr std::size_t npos =
static_cast<std::size_t
>(-1);
12099 InputAdapterType ia;
12102 char_int_type current = char_traits<char_type>::eof();
12105 std::size_t chars_read = 0;
12108 const bool is_little_endian = little_endianness();
12114 json_sax_t* sax =
nullptr;
12117#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12118 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12120#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12121 make_array<bjd_type>( \
12122 bjd_type{'C', "char"}, \
12123 bjd_type{'D', "double"}, \
12124 bjd_type{'I', "int16"}, \
12125 bjd_type{'L', "int64"}, \
12126 bjd_type{'M', "uint64"}, \
12127 bjd_type{'U', "uint8"}, \
12128 bjd_type{'d', "single"}, \
12129 bjd_type{'i', "int8"}, \
12130 bjd_type{'l', "int32"}, \
12131 bjd_type{'m', "uint32"}, \
12132 bjd_type{'u', "uint16"})
12134 JSON_PRIVATE_UNLESS_TESTED:
12137 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12138 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12140 using bjd_type = std::pair<char_int_type, string_t>;
12142 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12143 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12145#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12146#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12149#ifndef JSON_HAS_CPP_17
12150 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12151 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12155NLOHMANN_JSON_NAMESPACE_END
12174#include <functional>
12196NLOHMANN_JSON_NAMESPACE_BEGIN
12219template<
typename BasicJsonType>
12220using parser_callback_t =
12221 std::function<bool(
int ,
parse_event_t , BasicJsonType& )>;
12228template<
typename BasicJsonType,
typename InputAdapterType>
12231 using number_integer_t =
typename BasicJsonType::number_integer_t;
12232 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12233 using number_float_t =
typename BasicJsonType::number_float_t;
12234 using string_t =
typename BasicJsonType::string_t;
12235 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
12236 using token_type =
typename lexer_t::token_type;
12241 const parser_callback_t<BasicJsonType> cb =
nullptr,
12242 const bool allow_exceptions_ =
true,
12243 const bool skip_comments =
false)
12245 , m_lexer(std::move(adapter), skip_comments)
12246 , allow_exceptions(allow_exceptions_)
12267 sax_parse_internal(&sdp);
12270 if (
strict && (get_token() != token_type::end_of_input))
12275 exception_message(token_type::end_of_input,
"value"),
nullptr));
12279 if (sdp.is_errored())
12287 if (result.is_discarded())
12295 sax_parse_internal(&sdp);
12298 if (
strict && (get_token() != token_type::end_of_input))
12306 if (sdp.is_errored())
12313 result.assert_invariant();
12325 return sax_parse(&sax_acceptor,
strict);
12328 template<
typename SAX>
12329 JSON_HEDLEY_NON_NULL(2)
12330 bool sax_parse(SAX* sax, const
bool strict = true)
12333 const bool result = sax_parse_internal(sax);
12336 if (result &&
strict && (get_token() != token_type::end_of_input))
12347 template<
typename SAX>
12348 JSON_HEDLEY_NON_NULL(2)
12349 bool sax_parse_internal(SAX* sax)
12353 std::vector<bool> states;
12355 bool skip_to_state_evaluation =
false;
12359 if (!skip_to_state_evaluation)
12362 switch (last_token)
12364 case token_type::begin_object:
12366 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
12372 if (get_token() == token_type::end_object)
12374 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12382 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
12388 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.
get_string())))
12394 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12402 states.push_back(
false);
12409 case token_type::begin_array:
12411 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
12417 if (get_token() == token_type::end_array)
12419 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12427 states.push_back(
true);
12433 case token_type::value_float:
12437 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
12441 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.
get_token_string(),
'\''),
nullptr));
12444 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.
get_string())))
12452 case token_type::literal_false:
12454 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
12461 case token_type::literal_null:
12463 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
12470 case token_type::literal_true:
12472 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
12479 case token_type::value_integer:
12488 case token_type::value_string:
12490 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.
get_string())))
12497 case token_type::value_unsigned:
12506 case token_type::parse_error:
12513 case token_type::end_of_input:
12520 "attempting to parse an empty input; check that your input string or stream contains the expected JSON",
nullptr));
12527 case token_type::uninitialized:
12528 case token_type::end_array:
12529 case token_type::end_object:
12530 case token_type::name_separator:
12531 case token_type::value_separator:
12532 case token_type::literal_or_value:
12543 skip_to_state_evaluation =
false;
12547 if (states.empty())
12556 if (get_token() == token_type::value_separator)
12564 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
12566 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12575 JSON_ASSERT(!states.empty());
12577 skip_to_state_evaluation =
true;
12589 if (get_token() == token_type::value_separator)
12592 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
12599 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.
get_string())))
12605 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12618 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
12620 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12629 JSON_ASSERT(!states.empty());
12631 skip_to_state_evaluation =
true;
12642 token_type get_token()
12644 return last_token = m_lexer.scan();
12647 std::string exception_message(
const token_type expected,
const std::string& context)
12649 std::string error_msg =
"syntax error ";
12651 if (!context.empty())
12653 error_msg += concat(
"while parsing ", context,
' ');
12658 if (last_token == token_type::parse_error)
12668 if (expected != token_type::uninitialized)
12678 const parser_callback_t<BasicJsonType> callback =
nullptr;
12680 token_type last_token = token_type::uninitialized;
12684 const bool allow_exceptions =
true;
12688NLOHMANN_JSON_NAMESPACE_END
12720NLOHMANN_JSON_NAMESPACE_BEGIN
12733class primitive_iterator_t
12736 using difference_type = std::ptrdiff_t;
12737 static constexpr difference_type begin_value = 0;
12738 static constexpr difference_type end_value = begin_value + 1;
12740 JSON_PRIVATE_UNLESS_TESTED:
12742 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
12745 constexpr difference_type get_value() const noexcept
12753 m_it = begin_value;
12765 return m_it == begin_value;
12771 return m_it == end_value;
12776 return lhs.m_it == rhs.m_it;
12779 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12781 return lhs.m_it < rhs.m_it;
12784 primitive_iterator_t operator+(difference_type n)
noexcept
12786 auto result = *
this;
12791 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12793 return lhs.m_it - rhs.m_it;
12796 primitive_iterator_t& operator++() noexcept
12802 primitive_iterator_t operator++(
int)&
noexcept
12804 auto result = *
this;
12809 primitive_iterator_t& operator--() noexcept
12815 primitive_iterator_t operator--(
int)&
noexcept
12817 auto result = *
this;
12822 primitive_iterator_t& operator+=(difference_type n)
noexcept
12828 primitive_iterator_t& operator-=(difference_type n)
noexcept
12836NLOHMANN_JSON_NAMESPACE_END
12839NLOHMANN_JSON_NAMESPACE_BEGIN
12849template<
typename BasicJsonType>
struct internal_iterator
12860NLOHMANN_JSON_NAMESPACE_END
12874#include <type_traits>
12891NLOHMANN_JSON_NAMESPACE_BEGIN
12896template<
typename IteratorType>
class iteration_proxy;
12897template<
typename IteratorType>
class iteration_proxy_value;
12915template<
typename BasicJsonType>
12919 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
12921 friend other_iter_impl;
12922 friend BasicJsonType;
12923 friend iteration_proxy<iter_impl>;
12924 friend iteration_proxy_value<iter_impl>;
12926 using object_t =
typename BasicJsonType::object_t;
12927 using array_t =
typename BasicJsonType::array_t;
12929 static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>
::value,
12930 "iter_impl only accepts (const) basic_json");
12932 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
12933 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>
::value,
12934 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
12949 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
12950 typename BasicJsonType::const_pointer,
12951 typename BasicJsonType::pointer>::type;
12954 typename std::conditional<std::is_const<BasicJsonType>::value,
12955 typename BasicJsonType::const_reference,
12956 typename BasicJsonType::reference>::type;
12971 JSON_ASSERT(m_object !=
nullptr);
12973 switch (m_object->m_data.m_type)
12977 m_it.object_iterator =
typename object_t::iterator();
12983 m_it.array_iterator =
typename array_t::iterator();
13020 : m_object(other.m_object),
m_it(other.m_it)
13031 if (&other !=
this)
13033 m_object = other.m_object;
13045 : m_object(other.m_object),
m_it(other.m_it)
13056 m_object = other.m_object;
13061 JSON_PRIVATE_UNLESS_TESTED:
13066 void set_begin() noexcept
13068 JSON_ASSERT(m_object !=
nullptr);
13070 switch (m_object->m_data.m_type)
13074 m_it.object_iterator = m_object->m_data.m_value.object->begin();
13080 m_it.array_iterator = m_object->m_data.m_value.array->begin();
13087 m_it.primitive_iterator.set_end();
13100 m_it.primitive_iterator.set_begin();
13112 JSON_ASSERT(m_object !=
nullptr);
13114 switch (m_object->m_data.m_type)
13118 m_it.object_iterator = m_object->m_data.m_value.object->end();
13124 m_it.array_iterator = m_object->m_data.m_value.array->end();
13138 m_it.primitive_iterator.set_end();
13151 JSON_ASSERT(m_object !=
nullptr);
13153 switch (m_object->m_data.m_type)
13157 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
13158 return m_it.object_iterator->second;
13163 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
13164 return *
m_it.array_iterator;
13168 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13179 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin()))
13184 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13195 JSON_ASSERT(m_object !=
nullptr);
13197 switch (m_object->m_data.m_type)
13201 JSON_ASSERT(
m_it.object_iterator != m_object->m_data.m_value.object->end());
13202 return &(
m_it.object_iterator->second);
13207 JSON_ASSERT(
m_it.array_iterator != m_object->m_data.m_value.array->end());
13208 return &*
m_it.array_iterator;
13221 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.is_begin()))
13226 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13237 auto result = *
this;
13248 JSON_ASSERT(m_object !=
nullptr);
13250 switch (m_object->m_data.m_type)
13254 std::advance(
m_it.object_iterator, 1);
13260 std::advance(
m_it.array_iterator, 1);
13274 ++
m_it.primitive_iterator;
13288 auto result = *
this;
13299 JSON_ASSERT(m_object !=
nullptr);
13301 switch (m_object->m_data.m_type)
13305 std::advance(
m_it.object_iterator, -1);
13311 std::advance(
m_it.array_iterator, -1);
13325 --
m_it.primitive_iterator;
13337 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
13341 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13343 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13346 JSON_ASSERT(m_object !=
nullptr);
13348 switch (m_object->m_data.m_type)
13351 return (
m_it.object_iterator == other.m_it.object_iterator);
13354 return (
m_it.array_iterator == other.m_it.array_iterator);
13365 return (
m_it.primitive_iterator == other.m_it.primitive_iterator);
13373 template <
typename IterImpl, detail::enable_if_t < (std::is_same<IterImpl, iter_impl>::value || std::is_same<IterImpl, other_iter_impl>::value), std::
nullptr_t > =
nullptr >
13386 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13388 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13391 JSON_ASSERT(m_object !=
nullptr);
13393 switch (m_object->m_data.m_type)
13396 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
13399 return (
m_it.array_iterator < other.m_it.array_iterator);
13410 return (
m_it.primitive_iterator < other.m_it.primitive_iterator);
13420 return !other.operator < (*this);
13447 JSON_ASSERT(m_object !=
nullptr);
13449 switch (m_object->m_data.m_type)
13452 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13456 std::advance(
m_it.array_iterator, i);
13470 m_it.primitive_iterator += i;
13493 auto result = *
this;
13515 auto result = *
this;
13526 JSON_ASSERT(m_object !=
nullptr);
13528 switch (m_object->m_data.m_type)
13531 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13534 return m_it.array_iterator - other.m_it.array_iterator;
13545 return m_it.primitive_iterator - other.m_it.primitive_iterator;
13555 JSON_ASSERT(m_object !=
nullptr);
13557 switch (m_object->m_data.m_type)
13560 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
13563 return *std::next(
m_it.array_iterator, n);
13566 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13577 if (JSON_HEDLEY_LIKELY(
m_it.primitive_iterator.get_value() == -n))
13582 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13591 const typename object_t::key_type&
key()
const
13593 JSON_ASSERT(m_object !=
nullptr);
13595 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
13597 return m_it.object_iterator->first;
13600 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
13612 JSON_PRIVATE_UNLESS_TESTED:
13614 pointer m_object =
nullptr;
13620NLOHMANN_JSON_NAMESPACE_END
13642NLOHMANN_JSON_NAMESPACE_BEGIN
13668template<
typename Base>
13669class json_reverse_iterator :
public std::reverse_iterator<Base>
13672 using difference_type = std::ptrdiff_t;
13740 auto key() const -> decltype(std::declval<Base>().
key())
13742 auto it = --this->base();
13749 auto it = --this->base();
13750 return it.operator * ();
13755NLOHMANN_JSON_NAMESPACE_END
13770#include <type_traits>
13775NLOHMANN_JSON_NAMESPACE_BEGIN
13789struct json_default_base {};
13792using json_base_class =
typename std::conditional <
13793 std::is_same<T, void>::value,
13799NLOHMANN_JSON_NAMESPACE_END
13812#include <algorithm>
13836NLOHMANN_JSON_NAMESPACE_BEGIN
13840template<
typename RefStringType>
13844 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13850 template<
typename T>
13851 struct string_t_helper
13856 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13857 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
13859 using type = StringType;
13864 using string_t =
typename string_t_helper<RefStringType>::type;
13869 : reference_tokens(split(s))
13876 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
13878 [](
const string_t& a,
const string_t& b)
13880 return detail::concat(a,
'/', detail::escape(b));
13886 JSON_HEDLEY_DEPRECATED_FOR(3.11.0,
to_string())
13887 operator string_t()
const
13906 reference_tokens.insert(reference_tokens.end(),
13907 ptr.reference_tokens.begin(),
13908 ptr.reference_tokens.end());
13924 return *
this /= std::to_string(array_idx);
13967 if (JSON_HEDLEY_UNLIKELY(
empty()))
13969 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13972 reference_tokens.pop_back();
13979 if (JSON_HEDLEY_UNLIKELY(
empty()))
13981 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13984 return reference_tokens.back();
13991 reference_tokens.push_back(token);
13998 reference_tokens.push_back(std::move(token));
14005 return reference_tokens.empty();
14019 template<
typename BasicJsonType>
14020 static typename BasicJsonType::size_type array_index(
const string_t& s)
14022 using size_type =
typename BasicJsonType::size_type;
14025 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
14031 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
14036 const char* p = s.c_str();
14037 char* p_end =
nullptr;
14039 const unsigned long long res = std::strtoull(p, &p_end, 10);
14042 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
14044 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
14049 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
14051 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
14054 return static_cast<size_type
>(res);
14057 JSON_PRIVATE_UNLESS_TESTED:
14060 if (JSON_HEDLEY_UNLIKELY(
empty()))
14062 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
14066 result.reference_tokens = {reference_tokens[0]};
14079 template<
typename BasicJsonType>
14080 BasicJsonType& get_and_create(BasicJsonType& j)
const
14086 for (
const auto& reference_token : reference_tokens)
14088 switch (result->type())
14092 if (reference_token ==
"0")
14095 result = &result->operator[](0);
14100 result = &result->operator[](reference_token);
14108 result = &result->operator[](reference_token);
14115 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14133 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14159 template<
typename BasicJsonType>
14160 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14162 for (
const auto& reference_token : reference_tokens)
14165 if (ptr->is_null())
14169 std::all_of(reference_token.begin(), reference_token.end(),
14170 [](
const unsigned char x)
14172 return std::isdigit(x);
14176 *ptr = (nums || reference_token ==
"-")
14181 switch (ptr->type())
14186 ptr = &ptr->operator[](reference_token);
14192 if (reference_token ==
"-")
14195 ptr = &ptr->operator[](ptr->m_data.m_value.array->size());
14200 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14214 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14227 template<
typename BasicJsonType>
14228 BasicJsonType& get_checked(BasicJsonType* ptr)
const
14230 for (
const auto& reference_token : reference_tokens)
14232 switch (ptr->type())
14237 ptr = &ptr->at(reference_token);
14243 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14246 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14247 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14248 ") is out of range"), ptr));
14252 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14265 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14285 template<
typename BasicJsonType>
14286 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
14288 for (
const auto& reference_token : reference_tokens)
14290 switch (ptr->type())
14295 ptr = &ptr->operator[](reference_token);
14301 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14304 JSON_THROW(detail::out_of_range::create(402, detail::concat(
"array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
") is out of range"), ptr));
14308 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14321 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14334 template<
typename BasicJsonType>
14335 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
14337 for (
const auto& reference_token : reference_tokens)
14339 switch (ptr->type())
14344 ptr = &ptr->at(reference_token);
14350 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14353 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14354 "array index '-' (", std::to_string(ptr->m_data.m_value.array->size()),
14355 ") is out of range"), ptr));
14359 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14372 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14383 template<
typename BasicJsonType>
14384 bool contains(
const BasicJsonType* ptr)
const
14386 for (
const auto& reference_token : reference_tokens)
14388 switch (ptr->type())
14392 if (!ptr->contains(reference_token))
14398 ptr = &ptr->operator[](reference_token);
14404 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14409 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
14414 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
14416 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
14421 for (std::size_t i = 1; i < reference_token.size(); i++)
14423 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
14431 const auto idx = array_index<BasicJsonType>(reference_token);
14432 if (idx >= ptr->size())
14438 ptr = &ptr->operator[](idx);
14472 static std::vector<string_t> split(
const string_t& reference_string)
14474 std::vector<string_t> result;
14477 if (reference_string.empty())
14483 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
14485 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
14493 std::size_t slash = reference_string.find_first_of(
'/', 1),
14500 start = (slash == string_t::npos) ? 0 : slash + 1,
14502 slash = reference_string.find_first_of(
'/', start))
14506 auto reference_token = reference_string.substr(start, slash - start);
14509 for (std::size_t pos = reference_token.find_first_of(
'~');
14510 pos != string_t::npos;
14511 pos = reference_token.find_first_of(
'~', pos + 1))
14513 JSON_ASSERT(reference_token[pos] ==
'~');
14516 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
14517 (reference_token[pos + 1] !=
'0' &&
14518 reference_token[pos + 1] !=
'1')))
14525 detail::unescape(reference_token);
14526 result.push_back(reference_token);
14540 template<
typename BasicJsonType>
14541 static void flatten(
const string_t& reference_string,
14542 const BasicJsonType& value,
14543 BasicJsonType& result)
14545 switch (value.type())
14549 if (value.m_data.m_value.array->empty())
14552 result[reference_string] =
nullptr;
14557 for (std::size_t i = 0; i < value.m_data.m_value.array->size(); ++i)
14559 flatten(detail::concat(reference_string,
'/', std::to_string(i)),
14560 value.m_data.m_value.array->operator[](i), result);
14568 if (value.m_data.m_value.object->empty())
14571 result[reference_string] =
nullptr;
14576 for (
const auto& element : *value.m_data.m_value.object)
14578 flatten(detail::concat(reference_string,
'/',
detail::escape(element.first)), element.second, result);
14595 result[reference_string] = value;
14611 template<
typename BasicJsonType>
14612 static BasicJsonType
14613 unflatten(
const BasicJsonType& value)
14615 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
14617 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
14620 BasicJsonType result;
14623 for (
const auto& element : *value.m_data.m_value.object)
14625 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
14627 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
14634 json_pointer(element.first).get_and_create(result) = element.second;
14644 result.reference_tokens = reference_tokens;
14651 result.reference_tokens = std::move(reference_tokens);
14656#if JSON_HAS_THREE_WAY_COMPARISON
14659 template<
typename RefStringTypeRhs>
14662 return reference_tokens == rhs.reference_tokens;
14667 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(
json_pointer))
14674 template<
typename RefStringTypeRhs>
14677 return reference_tokens <=> rhs.reference_tokens;
14682 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14689 template<
typename RefStringTypeLhs,
typename StringType>
14692 const StringType& rhs);
14696 template<
typename RefStringTypeRhs,
typename StringType>
14698 friend bool operator==(
const StringType& lhs,
14703 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14710 template<
typename RefStringTypeLhs,
typename StringType>
14713 const StringType& rhs);
14717 template<
typename RefStringTypeRhs,
typename StringType>
14719 friend bool operator!=(
const StringType& lhs,
14723 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14731 std::vector<string_t> reference_tokens;
14734#if !JSON_HAS_THREE_WAY_COMPARISON
14736template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14740 return lhs.reference_tokens == rhs.reference_tokens;
14743template<
typename RefStringTypeLhs,
14744 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14747 const StringType& rhs)
14752template<
typename RefStringTypeRhs,
14753 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14755inline
bool operator==(const StringType& lhs,
14761template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14765 return !(lhs == rhs);
14768template<
typename RefStringTypeLhs,
14769 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14772 const StringType& rhs)
14774 return !(lhs == rhs);
14777template<
typename RefStringTypeRhs,
14778 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14780inline
bool operator!=(const StringType& lhs,
14783 return !(lhs == rhs);
14786template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14790 return lhs.reference_tokens < rhs.reference_tokens;
14794NLOHMANN_JSON_NAMESPACE_END
14807#include <initializer_list>
14815NLOHMANN_JSON_NAMESPACE_BEGIN
14819template<
typename BasicJsonType>
14823 using value_type = BasicJsonType;
14825 json_ref(value_type&& value)
14826 : owned_value(std::move(value))
14829 json_ref(
const value_type& value)
14830 : value_ref(&value)
14833 json_ref(std::initializer_list<json_ref> init)
14834 : owned_value(init)
14839 enable_if_t<std::is_constructible<value_type, Args...>
::value,
int> = 0 >
14840 json_ref(Args && ... args)
14841 : owned_value(std::forward<Args>(args)...)
14845 json_ref(json_ref&&) noexcept = default;
14846 json_ref(const json_ref&) = delete;
14847 json_ref& operator=(const json_ref&) = delete;
14848 json_ref& operator=(json_ref&&) = delete;
14849 ~json_ref() = default;
14851 value_type moved_or_copied()
const
14853 if (value_ref ==
nullptr)
14855 return std::move(owned_value);
14860 value_type
const& operator*()
const
14862 return value_ref ? *value_ref : owned_value;
14865 value_type
const* operator->()
const
14871 mutable value_type owned_value =
nullptr;
14872 value_type
const* value_ref =
nullptr;
14876NLOHMANN_JSON_NAMESPACE_END
14899#include <algorithm>
14925#include <algorithm>
14940NLOHMANN_JSON_NAMESPACE_BEGIN
14945template<
typename CharType>
struct output_adapter_protocol
14947 virtual void write_character(CharType c) = 0;
14948 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
14949 virtual ~output_adapter_protocol() =
default;
14951 output_adapter_protocol() =
default;
14952 output_adapter_protocol(
const output_adapter_protocol&) =
default;
14953 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
14954 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
14955 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
14959template<typename CharType>
14963template<typename CharType, typename AllocatorType = std::allocator<CharType>>
14971 void write_character(CharType c)
override
14976 JSON_HEDLEY_NON_NULL(2)
14977 void write_characters(
const CharType* s, std::size_t length)
override
14979 v.insert(v.end(), s, s + length);
14983 std::vector<CharType, AllocatorType>& v;
14988template<
typename CharType>
14989class output_stream_adapter :
public output_adapter_protocol<CharType>
14992 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
14996 void write_character(CharType c)
override
15001 JSON_HEDLEY_NON_NULL(2)
15002 void write_characters(const CharType* s, std::
size_t length)
override
15004 stream.write(s,
static_cast<std::streamsize
>(length));
15008 std::basic_ostream<CharType>& stream;
15013template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15014class output_string_adapter :
public output_adapter_protocol<CharType>
15017 explicit output_string_adapter(StringType& s) noexcept
15021 void write_character(CharType c)
override
15026 JSON_HEDLEY_NON_NULL(2)
15027 void write_characters(const CharType* s, std::
size_t length)
override
15029 str.append(s, length);
15036template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
15037class output_adapter
15040 template<
typename AllocatorType = std::allocator<CharType>>
15041 output_adapter(std::vector<CharType, AllocatorType>& vec)
15042 : oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
15045 output_adapter(std::basic_ostream<CharType>& s)
15046 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
15049 output_adapter(StringType& s)
15050 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
15052 operator output_adapter_t<CharType>()
15058 output_adapter_t<CharType> oa =
nullptr;
15062NLOHMANN_JSON_NAMESPACE_END
15067NLOHMANN_JSON_NAMESPACE_BEGIN
15078template<
typename BasicJsonType,
typename CharType>
15081 using string_t =
typename BasicJsonType::string_t;
15082 using binary_t =
typename BasicJsonType::binary_t;
15083 using number_float_t =
typename BasicJsonType::number_float_t;
15104 case value_t::object:
15106 write_bson_object(*j.m_data.m_value.object);
15110 case value_t::null:
15111 case value_t::array:
15112 case value_t::string:
15113 case value_t::boolean:
15114 case value_t::number_integer:
15115 case value_t::number_unsigned:
15116 case value_t::number_float:
15117 case value_t::binary:
15118 case value_t::discarded:
15121 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15133 case value_t::null:
15135 oa->write_character(to_char_type(0xF6));
15139 case value_t::boolean:
15141 oa->write_character(j.m_data.m_value.boolean
15142 ? to_char_type(0xF5)
15143 : to_char_type(0xF4));
15147 case value_t::number_integer:
15149 if (j.m_data.m_value.number_integer >= 0)
15154 if (j.m_data.m_value.number_integer <= 0x17)
15156 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15158 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15160 oa->write_character(to_char_type(0x18));
15161 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15163 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15165 oa->write_character(to_char_type(0x19));
15166 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15168 else if (j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15170 oa->write_character(to_char_type(0x1A));
15171 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15175 oa->write_character(to_char_type(0x1B));
15176 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15183 const auto positive_number = -1 - j.m_data.m_value.number_integer;
15184 if (j.m_data.m_value.number_integer >= -24)
15186 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15188 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15190 oa->write_character(to_char_type(0x38));
15191 write_number(
static_cast<std::uint8_t
>(positive_number));
15193 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15195 oa->write_character(to_char_type(0x39));
15196 write_number(
static_cast<std::uint16_t
>(positive_number));
15198 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15200 oa->write_character(to_char_type(0x3A));
15201 write_number(
static_cast<std::uint32_t
>(positive_number));
15205 oa->write_character(to_char_type(0x3B));
15206 write_number(
static_cast<std::uint64_t
>(positive_number));
15212 case value_t::number_unsigned:
15214 if (j.m_data.m_value.number_unsigned <= 0x17)
15216 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15218 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15220 oa->write_character(to_char_type(0x18));
15221 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_unsigned));
15223 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15225 oa->write_character(to_char_type(0x19));
15226 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_unsigned));
15228 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15230 oa->write_character(to_char_type(0x1A));
15231 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_unsigned));
15235 oa->write_character(to_char_type(0x1B));
15236 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_unsigned));
15241 case value_t::number_float:
15243 if (std::isnan(j.m_data.m_value.number_float))
15246 oa->write_character(to_char_type(0xF9));
15247 oa->write_character(to_char_type(0x7E));
15248 oa->write_character(to_char_type(0x00));
15250 else if (std::isinf(j.m_data.m_value.number_float))
15253 oa->write_character(to_char_type(0xf9));
15254 oa->write_character(j.m_data.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
15255 oa->write_character(to_char_type(0x00));
15259 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::cbor);
15264 case value_t::string:
15267 const auto N = j.m_data.m_value.string->size();
15270 write_number(
static_cast<std::uint8_t
>(0x60 + N));
15272 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15274 oa->write_character(to_char_type(0x78));
15275 write_number(
static_cast<std::uint8_t
>(N));
15277 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15279 oa->write_character(to_char_type(0x79));
15280 write_number(
static_cast<std::uint16_t
>(N));
15282 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15284 oa->write_character(to_char_type(0x7A));
15285 write_number(
static_cast<std::uint32_t
>(N));
15288 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15290 oa->write_character(to_char_type(0x7B));
15291 write_number(
static_cast<std::uint64_t
>(N));
15296 oa->write_characters(
15297 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15298 j.m_data.m_value.string->size());
15302 case value_t::array:
15305 const auto N = j.m_data.m_value.array->size();
15308 write_number(
static_cast<std::uint8_t
>(0x80 + N));
15310 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15312 oa->write_character(to_char_type(0x98));
15313 write_number(
static_cast<std::uint8_t
>(N));
15315 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15317 oa->write_character(to_char_type(0x99));
15318 write_number(
static_cast<std::uint16_t
>(N));
15320 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15322 oa->write_character(to_char_type(0x9A));
15323 write_number(
static_cast<std::uint32_t
>(N));
15326 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15328 oa->write_character(to_char_type(0x9B));
15329 write_number(
static_cast<std::uint64_t
>(N));
15334 for (
const auto& el : *j.m_data.m_value.array)
15341 case value_t::binary:
15343 if (j.m_data.m_value.binary->has_subtype())
15345 if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
15347 write_number(
static_cast<std::uint8_t
>(0xd8));
15348 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.binary->subtype()));
15350 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
15352 write_number(
static_cast<std::uint8_t
>(0xd9));
15353 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.binary->subtype()));
15355 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
15357 write_number(
static_cast<std::uint8_t
>(0xda));
15358 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.binary->subtype()));
15360 else if (j.m_data.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
15362 write_number(
static_cast<std::uint8_t
>(0xdb));
15363 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.binary->subtype()));
15368 const auto N = j.m_data.m_value.binary->size();
15371 write_number(
static_cast<std::uint8_t
>(0x40 + N));
15373 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15375 oa->write_character(to_char_type(0x58));
15376 write_number(
static_cast<std::uint8_t
>(N));
15378 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15380 oa->write_character(to_char_type(0x59));
15381 write_number(
static_cast<std::uint16_t
>(N));
15383 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15385 oa->write_character(to_char_type(0x5A));
15386 write_number(
static_cast<std::uint32_t
>(N));
15389 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15391 oa->write_character(to_char_type(0x5B));
15392 write_number(
static_cast<std::uint64_t
>(N));
15397 oa->write_characters(
15398 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15404 case value_t::object:
15407 const auto N = j.m_data.m_value.object->size();
15410 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
15412 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15414 oa->write_character(to_char_type(0xB8));
15415 write_number(
static_cast<std::uint8_t
>(N));
15417 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15419 oa->write_character(to_char_type(0xB9));
15420 write_number(
static_cast<std::uint16_t
>(N));
15422 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15424 oa->write_character(to_char_type(0xBA));
15425 write_number(
static_cast<std::uint32_t
>(N));
15428 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15430 oa->write_character(to_char_type(0xBB));
15431 write_number(
static_cast<std::uint64_t
>(N));
15436 for (
const auto& el : *j.m_data.m_value.object)
15438 write_cbor(el.first);
15439 write_cbor(el.second);
15444 case value_t::discarded:
15457 case value_t::null:
15459 oa->write_character(to_char_type(0xC0));
15463 case value_t::boolean:
15465 oa->write_character(j.m_data.m_value.boolean
15466 ? to_char_type(0xC3)
15467 : to_char_type(0xC2));
15471 case value_t::number_integer:
15473 if (j.m_data.m_value.number_integer >= 0)
15478 if (j.m_data.m_value.number_unsigned < 128)
15481 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15483 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15486 oa->write_character(to_char_type(0xCC));
15487 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15489 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15492 oa->write_character(to_char_type(0xCD));
15493 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15495 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15498 oa->write_character(to_char_type(0xCE));
15499 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15501 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15504 oa->write_character(to_char_type(0xCF));
15505 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15510 if (j.m_data.m_value.number_integer >= -32)
15513 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15515 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
15516 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
15519 oa->write_character(to_char_type(0xD0));
15520 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.number_integer));
15522 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
15523 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
15526 oa->write_character(to_char_type(0xD1));
15527 write_number(
static_cast<std::int16_t
>(j.m_data.m_value.number_integer));
15529 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
15530 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
15533 oa->write_character(to_char_type(0xD2));
15534 write_number(
static_cast<std::int32_t
>(j.m_data.m_value.number_integer));
15536 else if (j.m_data.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
15537 j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
15540 oa->write_character(to_char_type(0xD3));
15541 write_number(
static_cast<std::int64_t
>(j.m_data.m_value.number_integer));
15547 case value_t::number_unsigned:
15549 if (j.m_data.m_value.number_unsigned < 128)
15552 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15554 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15557 oa->write_character(to_char_type(0xCC));
15558 write_number(
static_cast<std::uint8_t
>(j.m_data.m_value.number_integer));
15560 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15563 oa->write_character(to_char_type(0xCD));
15564 write_number(
static_cast<std::uint16_t
>(j.m_data.m_value.number_integer));
15566 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15569 oa->write_character(to_char_type(0xCE));
15570 write_number(
static_cast<std::uint32_t
>(j.m_data.m_value.number_integer));
15572 else if (j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15575 oa->write_character(to_char_type(0xCF));
15576 write_number(
static_cast<std::uint64_t
>(j.m_data.m_value.number_integer));
15581 case value_t::number_float:
15583 write_compact_float(j.m_data.m_value.number_float, detail::input_format_t::msgpack);
15587 case value_t::string:
15590 const auto N = j.m_data.m_value.string->size();
15594 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
15596 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15599 oa->write_character(to_char_type(0xD9));
15600 write_number(
static_cast<std::uint8_t
>(N));
15602 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15605 oa->write_character(to_char_type(0xDA));
15606 write_number(
static_cast<std::uint16_t
>(N));
15608 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15611 oa->write_character(to_char_type(0xDB));
15612 write_number(
static_cast<std::uint32_t
>(N));
15616 oa->write_characters(
15617 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15618 j.m_data.m_value.string->size());
15622 case value_t::array:
15625 const auto N = j.m_data.m_value.array->size();
15629 write_number(
static_cast<std::uint8_t
>(0x90 | N));
15631 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15634 oa->write_character(to_char_type(0xDC));
15635 write_number(
static_cast<std::uint16_t
>(N));
15637 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15640 oa->write_character(to_char_type(0xDD));
15641 write_number(
static_cast<std::uint32_t
>(N));
15645 for (
const auto& el : *j.m_data.m_value.array)
15652 case value_t::binary:
15656 const bool use_ext = j.m_data.m_value.binary->has_subtype();
15659 const auto N = j.m_data.m_value.binary->size();
15660 if (N <= (std::numeric_limits<std::uint8_t>::max)())
15662 std::uint8_t output_type{};
15669 output_type = 0xD4;
15672 output_type = 0xD5;
15675 output_type = 0xD6;
15678 output_type = 0xD7;
15681 output_type = 0xD8;
15684 output_type = 0xC7;
15692 output_type = 0xC4;
15696 oa->write_character(to_char_type(output_type));
15699 write_number(
static_cast<std::uint8_t
>(N));
15702 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15704 const std::uint8_t output_type = use_ext
15708 oa->write_character(to_char_type(output_type));
15709 write_number(
static_cast<std::uint16_t
>(N));
15711 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15713 const std::uint8_t output_type = use_ext
15717 oa->write_character(to_char_type(output_type));
15718 write_number(
static_cast<std::uint32_t
>(N));
15724 write_number(
static_cast<std::int8_t
>(j.m_data.m_value.binary->subtype()));
15728 oa->write_characters(
15729 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15735 case value_t::object:
15738 const auto N = j.m_data.m_value.object->size();
15742 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
15744 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15747 oa->write_character(to_char_type(0xDE));
15748 write_number(
static_cast<std::uint16_t
>(N));
15750 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15753 oa->write_character(to_char_type(0xDF));
15754 write_number(
static_cast<std::uint32_t
>(N));
15758 for (
const auto& el : *j.m_data.m_value.object)
15760 write_msgpack(el.first);
15761 write_msgpack(el.second);
15766 case value_t::discarded:
15780 const bool use_type,
const bool add_prefix =
true,
15781 const bool use_bjdata =
false)
15785 case value_t::null:
15789 oa->write_character(to_char_type(
'Z'));
15794 case value_t::boolean:
15798 oa->write_character(j.m_data.m_value.boolean
15799 ? to_char_type(
'T')
15800 : to_char_type(
'F'));
15805 case value_t::number_integer:
15807 write_number_with_ubjson_prefix(j.m_data.m_value.number_integer, add_prefix, use_bjdata);
15811 case value_t::number_unsigned:
15813 write_number_with_ubjson_prefix(j.m_data.m_value.number_unsigned, add_prefix, use_bjdata);
15817 case value_t::number_float:
15819 write_number_with_ubjson_prefix(j.m_data.m_value.number_float, add_prefix, use_bjdata);
15823 case value_t::string:
15827 oa->write_character(to_char_type(
'S'));
15829 write_number_with_ubjson_prefix(j.m_data.m_value.string->size(),
true, use_bjdata);
15830 oa->write_characters(
15831 reinterpret_cast<const CharType*
>(j.m_data.m_value.string->c_str()),
15832 j.m_data.m_value.string->size());
15836 case value_t::array:
15840 oa->write_character(to_char_type(
'['));
15843 bool prefix_required =
true;
15844 if (use_type && !j.m_data.m_value.array->empty())
15846 JSON_ASSERT(use_count);
15847 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15848 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
15849 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15851 return ubjson_prefix(v, use_bjdata) == first_prefix;
15854 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15856 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15858 prefix_required =
false;
15859 oa->write_character(to_char_type(
'$'));
15860 oa->write_character(first_prefix);
15866 oa->write_character(to_char_type(
'#'));
15867 write_number_with_ubjson_prefix(j.m_data.m_value.array->size(),
true, use_bjdata);
15870 for (
const auto& el : *j.m_data.m_value.array)
15872 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
15877 oa->write_character(to_char_type(
']'));
15883 case value_t::binary:
15887 oa->write_character(to_char_type(
'['));
15890 if (use_type && !j.m_data.m_value.binary->empty())
15892 JSON_ASSERT(use_count);
15893 oa->write_character(to_char_type(
'$'));
15894 oa->write_character(
'U');
15899 oa->write_character(to_char_type(
'#'));
15900 write_number_with_ubjson_prefix(j.m_data.m_value.binary->size(),
true, use_bjdata);
15905 oa->write_characters(
15906 reinterpret_cast<const CharType*
>(j.m_data.m_value.binary->data()),
15907 j.m_data.m_value.binary->size());
15911 for (
size_t i = 0; i < j.m_data.m_value.binary->size(); ++i)
15913 oa->write_character(to_char_type(
'U'));
15914 oa->write_character(j.m_data.m_value.binary->data()[i]);
15920 oa->write_character(to_char_type(
']'));
15926 case value_t::object:
15928 if (use_bjdata && j.m_data.m_value.object->size() == 3 && j.m_data.m_value.object->find(
"_ArrayType_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(
"_ArraySize_") != j.m_data.m_value.object->end() && j.m_data.m_value.object->find(
"_ArrayData_") != j.m_data.m_value.object->end())
15930 if (!write_bjdata_ndarray(*j.m_data.m_value.object, use_count, use_type))
15938 oa->write_character(to_char_type(
'{'));
15941 bool prefix_required =
true;
15942 if (use_type && !j.m_data.m_value.object->empty())
15944 JSON_ASSERT(use_count);
15945 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15946 const bool same_prefix = std::all_of(j.begin(), j.end(),
15947 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15949 return ubjson_prefix(v, use_bjdata) == first_prefix;
15952 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15954 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15956 prefix_required =
false;
15957 oa->write_character(to_char_type(
'$'));
15958 oa->write_character(first_prefix);
15964 oa->write_character(to_char_type(
'#'));
15965 write_number_with_ubjson_prefix(j.m_data.m_value.object->size(),
true, use_bjdata);
15968 for (
const auto& el : *j.m_data.m_value.object)
15970 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
15971 oa->write_characters(
15972 reinterpret_cast<const CharType*
>(el.first.c_str()),
15974 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
15979 oa->write_character(to_char_type(
'}'));
15985 case value_t::discarded:
16000 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
16002 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
16003 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
16005 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
16006 static_cast<void>(j);
16009 return 1ul + name.size() + 1u;
16015 void write_bson_entry_header(
const string_t& name,
16016 const std::uint8_t element_type)
16018 oa->write_character(to_char_type(element_type));
16019 oa->write_characters(
16020 reinterpret_cast<const CharType*
>(name.c_str()),
16027 void write_bson_boolean(
const string_t& name,
16030 write_bson_entry_header(name, 0x08);
16031 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
16037 void write_bson_double(
const string_t& name,
16038 const double value)
16040 write_bson_entry_header(name, 0x01);
16041 write_number<double>(value,
true);
16047 static std::size_t calc_bson_string_size(
const string_t& value)
16049 return sizeof(std::int32_t) + value.size() + 1ul;
16055 void write_bson_string(
const string_t& name,
16056 const string_t& value)
16058 write_bson_entry_header(name, 0x02);
16060 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
16061 oa->write_characters(
16062 reinterpret_cast<const CharType*
>(value.c_str()),
16069 void write_bson_null(
const string_t& name)
16071 write_bson_entry_header(name, 0x0A);
16077 static std::size_t calc_bson_integer_size(
const std::int64_t value)
16079 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
16080 ?
sizeof(std::int32_t)
16081 :
sizeof(std::int64_t);
16087 void write_bson_integer(
const string_t& name,
16088 const std::int64_t value)
16090 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16092 write_bson_entry_header(name, 0x10);
16093 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16097 write_bson_entry_header(name, 0x12);
16098 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16105 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16107 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16108 ?
sizeof(std::int32_t)
16115 void write_bson_unsigned(
const string_t& name,
16116 const BasicJsonType& j)
16118 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16120 write_bson_entry_header(name, 0x10 );
16121 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_data.m_value.number_unsigned),
true);
16123 else if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16125 write_bson_entry_header(name, 0x12 );
16126 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_data.m_value.number_unsigned),
true);
16130 JSON_THROW(out_of_range::create(407, concat(
"integer number ", std::to_string(j.m_data.m_value.number_unsigned),
" cannot be represented by BSON as it does not fit int64"), &j));
16137 void write_bson_object_entry(
const string_t& name,
16138 const typename BasicJsonType::object_t& value)
16140 write_bson_entry_header(name, 0x03);
16141 write_bson_object(value);
16147 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16149 std::size_t array_index = 0ul;
16151 const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value),
static_cast<std::size_t
>(0), [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
16153 return result + calc_bson_element_size(std::to_string(array_index++), el);
16156 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16162 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16164 return sizeof(std::int32_t) + value.size() + 1ul;
16170 void write_bson_array(
const string_t& name,
16171 const typename BasicJsonType::array_t& value)
16173 write_bson_entry_header(name, 0x04);
16174 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16176 std::size_t array_index = 0ul;
16178 for (
const auto& el : value)
16180 write_bson_element(std::to_string(array_index++), el);
16183 oa->write_character(to_char_type(0x00));
16189 void write_bson_binary(
const string_t& name,
16190 const binary_t& value)
16192 write_bson_entry_header(name, 0x05);
16194 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16195 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) :
static_cast<std::uint8_t
>(0x00));
16197 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
16204 static std::size_t calc_bson_element_size(
const string_t& name,
16205 const BasicJsonType& j)
16207 const auto header_size = calc_bson_entry_header_size(name, j);
16210 case value_t::object:
16211 return header_size + calc_bson_object_size(*j.m_data.m_value.object);
16213 case value_t::array:
16214 return header_size + calc_bson_array_size(*j.m_data.m_value.array);
16216 case value_t::binary:
16217 return header_size + calc_bson_binary_size(*j.m_data.m_value.binary);
16219 case value_t::boolean:
16220 return header_size + 1ul;
16222 case value_t::number_float:
16223 return header_size + 8ul;
16225 case value_t::number_integer:
16226 return header_size + calc_bson_integer_size(j.m_data.m_value.number_integer);
16228 case value_t::number_unsigned:
16229 return header_size + calc_bson_unsigned_size(j.m_data.m_value.number_unsigned);
16231 case value_t::string:
16232 return header_size + calc_bson_string_size(*j.m_data.m_value.string);
16234 case value_t::null:
16235 return header_size + 0ul;
16238 case value_t::discarded:
16240 JSON_ASSERT(
false);
16252 void write_bson_element(
const string_t& name,
16253 const BasicJsonType& j)
16257 case value_t::object:
16258 return write_bson_object_entry(name, *j.m_data.m_value.object);
16260 case value_t::array:
16261 return write_bson_array(name, *j.m_data.m_value.array);
16263 case value_t::binary:
16264 return write_bson_binary(name, *j.m_data.m_value.binary);
16266 case value_t::boolean:
16267 return write_bson_boolean(name, j.m_data.m_value.boolean);
16269 case value_t::number_float:
16270 return write_bson_double(name, j.m_data.m_value.number_float);
16272 case value_t::number_integer:
16273 return write_bson_integer(name, j.m_data.m_value.number_integer);
16275 case value_t::number_unsigned:
16276 return write_bson_unsigned(name, j);
16278 case value_t::string:
16279 return write_bson_string(name, *j.m_data.m_value.string);
16281 case value_t::null:
16282 return write_bson_null(name);
16285 case value_t::discarded:
16287 JSON_ASSERT(
false);
16299 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
16301 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
16302 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
16304 return result += calc_bson_element_size(el.first, el.second);
16307 return sizeof(std::int32_t) + document_size + 1ul;
16314 void write_bson_object(
const typename BasicJsonType::object_t& value)
16316 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
16318 for (
const auto& el : value)
16320 write_bson_element(el.first, el.second);
16323 oa->write_character(to_char_type(0x00));
16330 static constexpr CharType get_cbor_float_prefix(
float )
16332 return to_char_type(0xFA);
16335 static constexpr CharType get_cbor_float_prefix(
double )
16337 return to_char_type(0xFB);
16344 static constexpr CharType get_msgpack_float_prefix(
float )
16346 return to_char_type(0xCA);
16349 static constexpr CharType get_msgpack_float_prefix(
double )
16351 return to_char_type(0xCB);
16359 template<
typename NumberType,
typename std::enable_if<
16360 std::is_floating_point<NumberType>::value,
int>::type = 0>
16361 void write_number_with_ubjson_prefix(
const NumberType n,
16362 const bool add_prefix,
16363 const bool use_bjdata)
16367 oa->write_character(get_ubjson_float_prefix(n));
16369 write_number(n, use_bjdata);
16373 template<
typename NumberType,
typename std::enable_if<
16374 std::is_unsigned<NumberType>::value,
int>::type = 0>
16375 void write_number_with_ubjson_prefix(
const NumberType n,
16376 const bool add_prefix,
16377 const bool use_bjdata)
16379 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16383 oa->write_character(to_char_type(
'i'));
16385 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16387 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
16391 oa->write_character(to_char_type(
'U'));
16393 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16395 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16399 oa->write_character(to_char_type(
'I'));
16401 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16403 else if (use_bjdata && n <=
static_cast<uint64_t>((std::numeric_limits<uint16_t>::max)()))
16407 oa->write_character(to_char_type(
'u'));
16409 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
16411 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16415 oa->write_character(to_char_type(
'l'));
16417 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16419 else if (use_bjdata && n <=
static_cast<uint64_t>((std::numeric_limits<uint32_t>::max)()))
16423 oa->write_character(to_char_type(
'm'));
16425 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
16427 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16431 oa->write_character(to_char_type(
'L'));
16433 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16435 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
16439 oa->write_character(to_char_type(
'M'));
16441 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
16447 oa->write_character(to_char_type(
'H'));
16450 const auto number = BasicJsonType(n).dump();
16451 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16452 for (std::size_t i = 0; i < number.size(); ++i)
16454 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16460 template <
typename NumberType,
typename std::enable_if <
16461 std::is_signed<NumberType>::value&&
16462 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
16463 void write_number_with_ubjson_prefix(
const NumberType n,
16464 const bool add_prefix,
16465 const bool use_bjdata)
16467 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
16471 oa->write_character(to_char_type(
'i'));
16473 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
16475 else if (
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16479 oa->write_character(to_char_type(
'U'));
16481 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16483 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
16487 oa->write_character(to_char_type(
'I'));
16489 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16491 else if (use_bjdata && (
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint16_t>::max)())))
16495 oa->write_character(to_char_type(
'u'));
16497 write_number(
static_cast<uint16_t>(n), use_bjdata);
16499 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
16503 oa->write_character(to_char_type(
'l'));
16505 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16507 else if (use_bjdata && (
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::min)()) <= n && n <=
static_cast<std::int64_t
>((std::numeric_limits<std::uint32_t>::max)())))
16511 oa->write_character(to_char_type(
'm'));
16513 write_number(
static_cast<uint32_t>(n), use_bjdata);
16515 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
16519 oa->write_character(to_char_type(
'L'));
16521 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16528 oa->write_character(to_char_type(
'H'));
16531 const auto number = BasicJsonType(n).dump();
16532 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16533 for (std::size_t i = 0; i < number.size(); ++i)
16535 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16544 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
16548 case value_t::null:
16551 case value_t::boolean:
16552 return j.m_data.m_value.boolean ?
'T' :
'F';
16554 case value_t::number_integer:
16556 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16560 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
16564 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16568 if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
16572 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16576 if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
16580 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_data.m_value.number_integer && j.m_data.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16588 case value_t::number_unsigned:
16590 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16594 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16598 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16602 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
16606 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16610 if (use_bjdata && j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
16614 if (j.m_data.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16618 if (use_bjdata && j.m_data.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16626 case value_t::number_float:
16627 return get_ubjson_float_prefix(j.m_data.m_value.number_float);
16629 case value_t::string:
16632 case value_t::array:
16633 case value_t::binary:
16636 case value_t::object:
16639 case value_t::discarded:
16645 static constexpr CharType get_ubjson_float_prefix(
float )
16650 static constexpr CharType get_ubjson_float_prefix(
double )
16658 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type)
16660 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
16661 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'}, {
"char",
'C'}
16664 string_t
key =
"_ArrayType_";
16665 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
16666 if (it == bjdtype.end())
16670 CharType dtype = it->second;
16672 key =
"_ArraySize_";
16673 std::size_t len = (value.at(key).empty() ? 0 : 1);
16674 for (
const auto& el : value.at(key))
16676 len *=
static_cast<std::size_t
>(el.m_data.m_value.number_unsigned);
16679 key =
"_ArrayData_";
16680 if (value.at(key).size() != len)
16685 oa->write_character(
'[');
16686 oa->write_character(
'$');
16687 oa->write_character(dtype);
16688 oa->write_character(
'#');
16690 key =
"_ArraySize_";
16691 write_ubjson(value.at(key), use_count, use_type,
true,
true);
16693 key =
"_ArrayData_";
16694 if (dtype ==
'U' || dtype ==
'C')
16696 for (
const auto& el : value.at(key))
16698 write_number(
static_cast<std::uint8_t
>(el.m_data.m_value.number_unsigned),
true);
16701 else if (dtype ==
'i')
16703 for (
const auto& el : value.at(key))
16705 write_number(
static_cast<std::int8_t
>(el.m_data.m_value.number_integer),
true);
16708 else if (dtype ==
'u')
16710 for (
const auto& el : value.at(key))
16712 write_number(
static_cast<std::uint16_t
>(el.m_data.m_value.number_unsigned),
true);
16715 else if (dtype ==
'I')
16717 for (
const auto& el : value.at(key))
16719 write_number(
static_cast<std::int16_t
>(el.m_data.m_value.number_integer),
true);
16722 else if (dtype ==
'm')
16724 for (
const auto& el : value.at(key))
16726 write_number(
static_cast<std::uint32_t
>(el.m_data.m_value.number_unsigned),
true);
16729 else if (dtype ==
'l')
16731 for (
const auto& el : value.at(key))
16733 write_number(
static_cast<std::int32_t
>(el.m_data.m_value.number_integer),
true);
16736 else if (dtype ==
'M')
16738 for (
const auto& el : value.at(key))
16740 write_number(
static_cast<std::uint64_t
>(el.m_data.m_value.number_unsigned),
true);
16743 else if (dtype ==
'L')
16745 for (
const auto& el : value.at(key))
16747 write_number(
static_cast<std::int64_t
>(el.m_data.m_value.number_integer),
true);
16750 else if (dtype ==
'd')
16752 for (
const auto& el : value.at(key))
16754 write_number(
static_cast<float>(el.m_data.m_value.number_float),
true);
16757 else if (dtype ==
'D')
16759 for (
const auto& el : value.at(key))
16761 write_number(
static_cast<double>(el.m_data.m_value.number_float),
true);
16784 template<
typename NumberType>
16785 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
16788 std::array<CharType,
sizeof(NumberType)> vec{};
16789 std::memcpy(vec.data(), &n,
sizeof(NumberType));
16792 if (is_little_endian != OutputIsLittleEndian)
16795 std::reverse(vec.begin(), vec.end());
16798 oa->write_characters(vec.data(),
sizeof(NumberType));
16804#pragma GCC diagnostic push
16805#pragma GCC diagnostic ignored "-Wfloat-equal"
16807 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
16808 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
16809 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
16811 oa->write_character(format == detail::input_format_t::cbor
16812 ? get_cbor_float_prefix(
static_cast<float>(n))
16813 : get_msgpack_float_prefix(
static_cast<float>(n)));
16814 write_number(
static_cast<float>(n));
16818 oa->write_character(format == detail::input_format_t::cbor
16819 ? get_cbor_float_prefix(n)
16820 : get_msgpack_float_prefix(n));
16824#pragma GCC diagnostic pop
16833 template <
typename C = CharType,
16834 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
16835 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16837 return *
reinterpret_cast<char*
>(&x);
16840 template <
typename C = CharType,
16841 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
16842 static CharType to_char_type(std::uint8_t x)
noexcept
16844 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
16845 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
16847 std::memcpy(&result, &x,
sizeof(x));
16851 template<
typename C = CharType,
16852 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
16853 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16858 template <
typename InputCharType,
typename C = CharType,
16860 std::is_signed<C>::value &&
16861 std::is_signed<char>::value &&
16862 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
16864 static constexpr CharType to_char_type(InputCharType x)
noexcept
16871 const bool is_little_endian = little_endianness();
16874 output_adapter_t<CharType> oa =
nullptr;
16878NLOHMANN_JSON_NAMESPACE_END
16894#include <algorithm>
16904#include <type_traits>
16924#include <type_traits>
16929NLOHMANN_JSON_NAMESPACE_BEGIN
16955template<
typename Target,
typename Source>
16956Target reinterpret_bits(
const Source source)
16958 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
16961 std::memcpy(&target, &source,
sizeof(Source));
16967 static constexpr int kPrecision = 64;
16969 std::uint64_t f = 0;
16972 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
16980 JSON_ASSERT(x.e == y.e);
16981 JSON_ASSERT(x.f >= y.f);
16983 return {x.f - y.f, x.e};
16992 static_assert(kPrecision == 64,
"internal error");
17017 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
17018 const std::uint64_t u_hi = x.f >> 32u;
17019 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
17020 const std::uint64_t v_hi = y.f >> 32u;
17022 const std::uint64_t p0 = u_lo * v_lo;
17023 const std::uint64_t p1 = u_lo * v_hi;
17024 const std::uint64_t p2 = u_hi * v_lo;
17025 const std::uint64_t p3 = u_hi * v_hi;
17027 const std::uint64_t p0_hi = p0 >> 32u;
17028 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
17029 const std::uint64_t p1_hi = p1 >> 32u;
17030 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
17031 const std::uint64_t p2_hi = p2 >> 32u;
17033 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
17044 Q += std::uint64_t{1} << (64u - 32u - 1u);
17046 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
17048 return {h, x.e + y.e + 64};
17057 JSON_ASSERT(x.f != 0);
17059 while ((x.f >> 63u) == 0)
17074 const int delta = x.e - target_exponent;
17076 JSON_ASSERT(delta >= 0);
17077 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
17079 return {x.f << delta, target_exponent};
17096template<
typename FloatType>
17099 JSON_ASSERT(std::isfinite(value));
17100 JSON_ASSERT(value > 0);
17109 static_assert(std::numeric_limits<FloatType>::is_iec559,
17110 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17112 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17113 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17114 constexpr int kMinExp = 1 - kBias;
17115 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17117 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17119 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17120 const std::uint64_t E = bits >> (kPrecision - 1);
17121 const std::uint64_t F = bits & (kHiddenBit - 1);
17123 const bool is_denormal = E == 0;
17124 const diyfp v = is_denormal
17125 ?
diyfp(F, kMinExp)
17126 :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17149 const bool lower_boundary_is_closer = F == 0 && E > 1;
17150 const diyfp m_plus =
diyfp(2 * v.f + 1, v.e - 1);
17151 const diyfp m_minus = lower_boundary_is_closer
17152 ?
diyfp(4 * v.f - 1, v.e - 2)
17153 :
diyfp(2 * v.f - 1, v.e - 1);
17219constexpr int kAlpha = -60;
17220constexpr int kGamma = -32;
17288 constexpr int kCachedPowersMinDecExp = -300;
17289 constexpr int kCachedPowersDecStep = 8;
17291 static constexpr std::array<cached_power, 79> kCachedPowers =
17294 { 0xAB70FE17C79AC6CA, -1060, -300 },
17295 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
17296 { 0xBE5691EF416BD60C, -1007, -284 },
17297 { 0x8DD01FAD907FFC3C, -980, -276 },
17298 { 0xD3515C2831559A83, -954, -268 },
17299 { 0x9D71AC8FADA6C9B5, -927, -260 },
17300 { 0xEA9C227723EE8BCB, -901, -252 },
17301 { 0xAECC49914078536D, -874, -244 },
17302 { 0x823C12795DB6CE57, -847, -236 },
17303 { 0xC21094364DFB5637, -821, -228 },
17304 { 0x9096EA6F3848984F, -794, -220 },
17305 { 0xD77485CB25823AC7, -768, -212 },
17306 { 0xA086CFCD97BF97F4, -741, -204 },
17307 { 0xEF340A98172AACE5, -715, -196 },
17308 { 0xB23867FB2A35B28E, -688, -188 },
17309 { 0x84C8D4DFD2C63F3B, -661, -180 },
17310 { 0xC5DD44271AD3CDBA, -635, -172 },
17311 { 0x936B9FCEBB25C996, -608, -164 },
17312 { 0xDBAC6C247D62A584, -582, -156 },
17313 { 0xA3AB66580D5FDAF6, -555, -148 },
17314 { 0xF3E2F893DEC3F126, -529, -140 },
17315 { 0xB5B5ADA8AAFF80B8, -502, -132 },
17316 { 0x87625F056C7C4A8B, -475, -124 },
17317 { 0xC9BCFF6034C13053, -449, -116 },
17318 { 0x964E858C91BA2655, -422, -108 },
17319 { 0xDFF9772470297EBD, -396, -100 },
17320 { 0xA6DFBD9FB8E5B88F, -369, -92 },
17321 { 0xF8A95FCF88747D94, -343, -84 },
17322 { 0xB94470938FA89BCF, -316, -76 },
17323 { 0x8A08F0F8BF0F156B, -289, -68 },
17324 { 0xCDB02555653131B6, -263, -60 },
17325 { 0x993FE2C6D07B7FAC, -236, -52 },
17326 { 0xE45C10C42A2B3B06, -210, -44 },
17327 { 0xAA242499697392D3, -183, -36 },
17328 { 0xFD87B5F28300CA0E, -157, -28 },
17329 { 0xBCE5086492111AEB, -130, -20 },
17330 { 0x8CBCCC096F5088CC, -103, -12 },
17331 { 0xD1B71758E219652C, -77, -4 },
17332 { 0x9C40000000000000, -50, 4 },
17333 { 0xE8D4A51000000000, -24, 12 },
17334 { 0xAD78EBC5AC620000, 3, 20 },
17335 { 0x813F3978F8940984, 30, 28 },
17336 { 0xC097CE7BC90715B3, 56, 36 },
17337 { 0x8F7E32CE7BEA5C70, 83, 44 },
17338 { 0xD5D238A4ABE98068, 109, 52 },
17339 { 0x9F4F2726179A2245, 136, 60 },
17340 { 0xED63A231D4C4FB27, 162, 68 },
17341 { 0xB0DE65388CC8ADA8, 189, 76 },
17342 { 0x83C7088E1AAB65DB, 216, 84 },
17343 { 0xC45D1DF942711D9A, 242, 92 },
17344 { 0x924D692CA61BE758, 269, 100 },
17345 { 0xDA01EE641A708DEA, 295, 108 },
17346 { 0xA26DA3999AEF774A, 322, 116 },
17347 { 0xF209787BB47D6B85, 348, 124 },
17348 { 0xB454E4A179DD1877, 375, 132 },
17349 { 0x865B86925B9BC5C2, 402, 140 },
17350 { 0xC83553C5C8965D3D, 428, 148 },
17351 { 0x952AB45CFA97A0B3, 455, 156 },
17352 { 0xDE469FBD99A05FE3, 481, 164 },
17353 { 0xA59BC234DB398C25, 508, 172 },
17354 { 0xF6C69A72A3989F5C, 534, 180 },
17355 { 0xB7DCBF5354E9BECE, 561, 188 },
17356 { 0x88FCF317F22241E2, 588, 196 },
17357 { 0xCC20CE9BD35C78A5, 614, 204 },
17358 { 0x98165AF37B2153DF, 641, 212 },
17359 { 0xE2A0B5DC971F303A, 667, 220 },
17360 { 0xA8D9D1535CE3B396, 694, 228 },
17361 { 0xFB9B7CD9A4A7443C, 720, 236 },
17362 { 0xBB764C4CA7A44410, 747, 244 },
17363 { 0x8BAB8EEFB6409C1A, 774, 252 },
17364 { 0xD01FEF10A657842C, 800, 260 },
17365 { 0x9B10A4E5E9913129, 827, 268 },
17366 { 0xE7109BFBA19C0C9D, 853, 276 },
17367 { 0xAC2820D9623BF429, 880, 284 },
17368 { 0x80444B5E7AA7CF85, 907, 292 },
17369 { 0xBF21E44003ACDD2D, 933, 300 },
17370 { 0x8E679C2F5E44FF8F, 960, 308 },
17371 { 0xD433179D9C8CB841, 986, 316 },
17372 { 0x9E19DB92B4E31BA9, 1013, 324 },
17380 JSON_ASSERT(e >= -1500);
17381 JSON_ASSERT(e <= 1500);
17382 const int f = kAlpha - e - 1;
17383 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
17385 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
17386 JSON_ASSERT(index >= 0);
17387 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
17389 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
17390 JSON_ASSERT(kAlpha <= cached.e + e + 64);
17391 JSON_ASSERT(kGamma >= cached.e + e + 64);
17403 if (n >= 1000000000)
17405 pow10 = 1000000000;
17409 if (n >= 100000000)
17454inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
17455 std::uint64_t rest, std::uint64_t ten_k)
17457 JSON_ASSERT(len >= 1);
17458 JSON_ASSERT(dist <= delta);
17459 JSON_ASSERT(rest <= delta);
17460 JSON_ASSERT(ten_k > 0);
17482 && delta - rest >= ten_k
17483 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
17485 JSON_ASSERT(buf[len - 1] !=
'0');
17498 static_assert(kAlpha >= -60,
"internal error");
17499 static_assert(kGamma <= -32,
"internal error");
17513 JSON_ASSERT(M_plus.e >= kAlpha);
17514 JSON_ASSERT(M_plus.e <= kGamma);
17516 std::uint64_t delta =
diyfp::sub(M_plus, M_minus).f;
17517 std::uint64_t dist =
diyfp::sub(M_plus, w ).f;
17526 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
17528 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
17529 std::uint64_t p2 = M_plus.f & (one.f - 1);
17535 JSON_ASSERT(p1 > 0);
17537 std::uint32_t pow10{};
17565 const std::uint32_t d = p1 / pow10;
17566 const std::uint32_t r = p1 % pow10;
17571 JSON_ASSERT(d <= 9);
17572 buffer[length++] =
static_cast<char>(
'0' + d);
17591 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
17596 decimal_exponent += n;
17607 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
17608 grisu2_round(buffer, length, dist, delta, rest, ten_n);
17658 JSON_ASSERT(p2 > delta);
17669 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
17671 const std::uint64_t d = p2 >> -one.e;
17672 const std::uint64_t r = p2 & (one.f - 1);
17678 JSON_ASSERT(d <= 9);
17679 buffer[length++] =
static_cast<char>(
'0' + d);
17704 decimal_exponent -= m;
17712 const std::uint64_t ten_m = one.f;
17713 grisu2_round(buffer, length, dist, delta, p2, ten_m);
17735JSON_HEDLEY_NON_NULL(1)
17736inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
17739 JSON_ASSERT(m_plus.e == m_minus.e);
17740 JSON_ASSERT(m_plus.e == v.e);
17753 const diyfp c_minus_k(cached.f, cached.e);
17781 const diyfp M_minus(w_minus.f + 1, w_minus.e);
17782 const diyfp M_plus (w_plus.f - 1, w_plus.e );
17784 decimal_exponent = -cached.k;
17794template<
typename FloatType>
17795JSON_HEDLEY_NON_NULL(1)
17796void
grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
17798 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
17799 "internal error: not enough precision");
17801 JSON_ASSERT(std::isfinite(value));
17802 JSON_ASSERT(value > 0);
17826 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
17834JSON_HEDLEY_NON_NULL(1)
17835JSON_HEDLEY_RETURNS_NON_NULL
17838 JSON_ASSERT(e > -1000);
17839 JSON_ASSERT(e < 1000);
17851 auto k =
static_cast<std::uint32_t
>(e);
17857 *buf++ =
static_cast<char>(
'0' + k);
17861 *buf++ =
static_cast<char>(
'0' + k / 10);
17863 *buf++ =
static_cast<char>(
'0' + k);
17867 *buf++ =
static_cast<char>(
'0' + k / 100);
17869 *buf++ =
static_cast<char>(
'0' + k / 10);
17871 *buf++ =
static_cast<char>(
'0' + k);
17886JSON_HEDLEY_NON_NULL(1)
17887JSON_HEDLEY_RETURNS_NON_NULL
17889 int min_exp,
int max_exp)
17891 JSON_ASSERT(min_exp < 0);
17892 JSON_ASSERT(max_exp > 0);
17895 const int n = len + decimal_exponent;
17901 if (k <= n && n <= max_exp)
17906 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
17910 return buf + (
static_cast<size_t>(n) + 2);
17913 if (0 < n && n <= max_exp)
17918 JSON_ASSERT(k > n);
17920 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
17922 return buf + (
static_cast<size_t>(k) + 1U);
17925 if (min_exp < n && n <= 0)
17930 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
17933 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
17934 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
17949 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
17951 buf += 1 +
static_cast<size_t>(k);
17970template<
typename FloatType>
17971JSON_HEDLEY_NON_NULL(1, 2)
17972JSON_HEDLEY_RETURNS_NON_NULL
17973char*
to_chars(
char* first, const
char* last, FloatType value)
17975 static_cast<void>(last);
17976 JSON_ASSERT(std::isfinite(value));
17979 if (std::signbit(value))
17986#pragma GCC diagnostic push
17987#pragma GCC diagnostic ignored "-Wfloat-equal"
17998#pragma GCC diagnostic pop
18001 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
18008 int decimal_exponent = 0;
18011 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
18014 constexpr int kMinExp = -4;
18016 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
18018 JSON_ASSERT(last - first >= kMaxExp + 2);
18019 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
18020 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
18026NLOHMANN_JSON_NAMESPACE_END
18043NLOHMANN_JSON_NAMESPACE_BEGIN
18059template<
typename BasicJsonType>
18062 using string_t =
typename BasicJsonType::string_t;
18063 using number_float_t =
typename BasicJsonType::number_float_t;
18064 using number_integer_t =
typename BasicJsonType::number_integer_t;
18065 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18066 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
18067 static constexpr std::uint8_t UTF8_ACCEPT = 0;
18068 static constexpr std::uint8_t UTF8_REJECT = 1;
18079 ,
loc(std::localeconv())
18117 const bool pretty_print,
18118 const bool ensure_ascii,
18119 const unsigned int indent_step,
18120 const unsigned int current_indent = 0)
18122 switch (val.m_data.m_type)
18126 if (val.m_data.m_value.object->empty())
18128 o->write_characters(
"{}", 2);
18134 o->write_characters(
"{\n", 2);
18137 const auto new_indent = current_indent + indent_step;
18138 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
18144 auto i = val.m_data.m_value.object->cbegin();
18145 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18148 o->write_character(
'\"');
18149 dump_escaped(i->first, ensure_ascii);
18150 o->write_characters(
"\": ", 3);
18151 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18152 o->write_characters(
",\n", 2);
18156 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18157 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18159 o->write_character(
'\"');
18160 dump_escaped(i->first, ensure_ascii);
18161 o->write_characters(
"\": ", 3);
18162 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18164 o->write_character(
'\n');
18165 o->write_characters(
indent_string.c_str(), current_indent);
18166 o->write_character(
'}');
18170 o->write_character(
'{');
18173 auto i = val.m_data.m_value.object->cbegin();
18174 for (std::size_t cnt = 0; cnt < val.m_data.m_value.object->size() - 1; ++cnt, ++i)
18176 o->write_character(
'\"');
18177 dump_escaped(i->first, ensure_ascii);
18178 o->write_characters(
"\":", 2);
18179 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18180 o->write_character(
',');
18184 JSON_ASSERT(i != val.m_data.m_value.object->cend());
18185 JSON_ASSERT(std::next(i) == val.m_data.m_value.object->cend());
18186 o->write_character(
'\"');
18187 dump_escaped(i->first, ensure_ascii);
18188 o->write_characters(
"\":", 2);
18189 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18191 o->write_character(
'}');
18199 if (val.m_data.m_value.array->empty())
18201 o->write_characters(
"[]", 2);
18207 o->write_characters(
"[\n", 2);
18210 const auto new_indent = current_indent + indent_step;
18211 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
18217 for (
auto i = val.m_data.m_value.array->cbegin();
18218 i != val.m_data.m_value.array->cend() - 1; ++i)
18221 dump(*i,
true, ensure_ascii, indent_step, new_indent);
18222 o->write_characters(
",\n", 2);
18226 JSON_ASSERT(!val.m_data.m_value.array->empty());
18228 dump(val.m_data.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
18230 o->write_character(
'\n');
18231 o->write_characters(
indent_string.c_str(), current_indent);
18232 o->write_character(
']');
18236 o->write_character(
'[');
18239 for (
auto i = val.m_data.m_value.array->cbegin();
18240 i != val.m_data.m_value.array->cend() - 1; ++i)
18242 dump(*i,
false, ensure_ascii, indent_step, current_indent);
18243 o->write_character(
',');
18247 JSON_ASSERT(!val.m_data.m_value.array->empty());
18248 dump(val.m_data.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
18250 o->write_character(
']');
18258 o->write_character(
'\"');
18259 dump_escaped(*val.m_data.m_value.string, ensure_ascii);
18260 o->write_character(
'\"');
18268 o->write_characters(
"{\n", 2);
18271 const auto new_indent = current_indent + indent_step;
18272 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
18279 o->write_characters(
"\"bytes\": [", 10);
18281 if (!val.m_data.m_value.binary->empty())
18283 for (
auto i = val.m_data.m_value.binary->cbegin();
18284 i != val.m_data.m_value.binary->cend() - 1; ++i)
18287 o->write_characters(
", ", 2);
18289 dump_integer(val.m_data.m_value.binary->back());
18292 o->write_characters(
"],\n", 3);
18295 o->write_characters(
"\"subtype\": ", 11);
18296 if (val.m_data.m_value.binary->has_subtype())
18298 dump_integer(val.m_data.m_value.binary->subtype());
18302 o->write_characters(
"null", 4);
18304 o->write_character(
'\n');
18305 o->write_characters(
indent_string.c_str(), current_indent);
18306 o->write_character(
'}');
18310 o->write_characters(
"{\"bytes\":[", 10);
18312 if (!val.m_data.m_value.binary->empty())
18314 for (
auto i = val.m_data.m_value.binary->cbegin();
18315 i != val.m_data.m_value.binary->cend() - 1; ++i)
18318 o->write_character(
',');
18320 dump_integer(val.m_data.m_value.binary->back());
18323 o->write_characters(
"],\"subtype\":", 12);
18324 if (val.m_data.m_value.binary->has_subtype())
18326 dump_integer(val.m_data.m_value.binary->subtype());
18327 o->write_character(
'}');
18331 o->write_characters(
"null}", 5);
18339 if (val.m_data.m_value.boolean)
18341 o->write_characters(
"true", 4);
18345 o->write_characters(
"false", 5);
18352 dump_integer(val.m_data.m_value.number_integer);
18358 dump_integer(val.m_data.m_value.number_unsigned);
18364 dump_float(val.m_data.m_value.number_float);
18370 o->write_characters(
"<discarded>", 11);
18376 o->write_characters(
"null", 4);
18381 JSON_ASSERT(
false);
18385 JSON_PRIVATE_UNLESS_TESTED:
18400 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
18402 std::uint32_t codepoint{};
18403 std::uint8_t state = UTF8_ACCEPT;
18404 std::size_t bytes = 0;
18407 std::size_t bytes_after_last_accept = 0;
18408 std::size_t undumped_chars = 0;
18410 for (std::size_t i = 0; i < s.size(); ++i)
18412 const auto byte =
static_cast<std::uint8_t
>(s[i]);
18414 switch (decode(state, codepoint,
byte))
18473 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
18475 if (codepoint <= 0xFFFF)
18478 static_cast<void>((std::snprintf)(
string_buffer.data() + bytes, 7,
"\\u%04x",
18479 static_cast<std::uint16_t
>(codepoint)));
18485 static_cast<void>((std::snprintf)(
string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
18486 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
18487 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
18511 bytes_after_last_accept = bytes;
18512 undumped_chars = 0;
18522 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
18532 if (undumped_chars > 0)
18539 bytes = bytes_after_last_accept;
18569 bytes_after_last_accept = bytes;
18572 undumped_chars = 0;
18575 state = UTF8_ACCEPT;
18580 JSON_ASSERT(
false);
18599 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
18614 JSON_THROW(type_error::create(316, concat(
"incomplete UTF-8 string; last byte: 0x", hex_bytes(
static_cast<std::uint8_t
>(s.back() | 0))),
nullptr));
18620 o->write_characters(
string_buffer.data(), bytes_after_last_accept);
18627 o->write_characters(
string_buffer.data(), bytes_after_last_accept);
18631 o->write_characters(
"\\ufffd", 6);
18635 o->write_characters(
"\xEF\xBF\xBD", 3);
18641 JSON_ASSERT(
false);
18655 inline unsigned int count_digits(number_unsigned_t x)
noexcept
18657 unsigned int n_digits = 1;
18666 return n_digits + 1;
18670 return n_digits + 2;
18674 return n_digits + 3;
18686 static std::string hex_bytes(std::uint8_t
byte)
18688 std::string result =
"FF";
18689 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
18690 result[0] = nibble_to_hex[
byte / 16];
18691 result[1] = nibble_to_hex[
byte % 16];
18696 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
18697 bool is_negative_number(NumberType x)
18702 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
18703 bool is_negative_number(NumberType )
18717 template <
typename NumberType, detail::enable_if_t <
18718 std::is_integral<NumberType>::value ||
18719 std::is_same<NumberType, number_unsigned_t>::value ||
18720 std::is_same<NumberType, number_integer_t>::value ||
18721 std::is_same<NumberType, binary_char_t>::value,
18723 void dump_integer(NumberType x)
18725 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
18728 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
18729 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
18730 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
18731 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
18732 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
18733 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
18734 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
18735 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
18736 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
18737 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
18744 o->write_character(
'0');
18751 number_unsigned_t abs_value;
18753 unsigned int n_chars{};
18755 if (is_negative_number(x))
18758 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
18761 n_chars = 1 + count_digits(abs_value);
18765 abs_value =
static_cast<number_unsigned_t
>(x);
18766 n_chars = count_digits(abs_value);
18774 buffer_ptr += n_chars;
18778 while (abs_value >= 100)
18780 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
18782 *(--buffer_ptr) = digits_to_99[digits_index][1];
18783 *(--buffer_ptr) = digits_to_99[digits_index][0];
18786 if (abs_value >= 10)
18788 const auto digits_index =
static_cast<unsigned>(abs_value);
18789 *(--buffer_ptr) = digits_to_99[digits_index][1];
18790 *(--buffer_ptr) = digits_to_99[digits_index][0];
18794 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
18808 void dump_float(number_float_t x)
18811 if (!std::isfinite(x))
18813 o->write_characters(
"null", 4);
18822 static constexpr bool is_ieee_single_or_double
18823 = (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 24 && std::numeric_limits<number_float_t>::max_exponent == 128) ||
18824 (std::numeric_limits<number_float_t>::is_iec559 && std::numeric_limits<number_float_t>::digits == 53 && std::numeric_limits<number_float_t>::max_exponent == 1024);
18826 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
18829 void dump_float(number_float_t x, std::true_type )
18832 auto* end = ::nlohmann::detail::to_chars(begin, begin +
number_buffer.size(), x);
18834 o->write_characters(begin,
static_cast<size_t>(end - begin));
18837 void dump_float(number_float_t x, std::false_type )
18840 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
18847 JSON_ASSERT(len > 0);
18849 JSON_ASSERT(
static_cast<std::size_t
>(len) <
number_buffer.size());
18872 o->write_characters(
number_buffer.data(),
static_cast<std::size_t
>(len));
18875 const bool value_is_int_like =
18879 return c ==
'.' || c ==
'e';
18882 if (value_is_int_like)
18884 o->write_characters(
".0", 2);
18909 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
18911 static const std::array<std::uint8_t, 400> utf8d =
18914 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18915 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18916 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18917 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
18918 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
18919 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
18920 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
18921 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
18922 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
18923 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
18924 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1,
18925 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
18926 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1,
18927 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
18931 JSON_ASSERT(
byte < utf8d.size());
18932 const std::uint8_t type = utf8d[
byte];
18934 codep = (state != UTF8_ACCEPT)
18935 ? (
byte & 0x3fu) | (codep << 6u)
18936 : (0xFFu >> type) & (
byte);
18938 const std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
18939 JSON_ASSERT(index < utf8d.size());
18940 state = utf8d[index];
18949 number_unsigned_t remove_sign(number_unsigned_t x)
18951 JSON_ASSERT(
false);
18964 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
18966 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
18967 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
18997NLOHMANN_JSON_NAMESPACE_END
19014#include <functional>
19015#include <initializer_list>
19018#include <stdexcept>
19019#include <type_traits>
19028NLOHMANN_JSON_NAMESPACE_BEGIN
19032template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
19033 class Allocator = std::allocator<std::pair<const Key, T>>>
19034 struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>
19036 using key_type = Key;
19037 using mapped_type = T;
19038 using Container = std::vector<std::pair<const Key, T>, Allocator>;
19039 using iterator =
typename Container::iterator;
19040 using const_iterator =
typename Container::const_iterator;
19041 using size_type =
typename Container::size_type;
19042 using value_type =
typename Container::value_type;
19043#ifdef JSON_HAS_CPP_14
19044 using key_compare = std::equal_to<>;
19046 using key_compare = std::equal_to<Key>;
19051 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
19052 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
19053 template <
class It>
19054 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
19055 : Container{first, last, alloc} {}
19056 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
19057 : Container{init, alloc} {}
19059 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
19061 for (
auto it = this->begin(); it != this->end(); ++it)
19063 if (m_compare(it->first, key))
19065 return {it,
false};
19068 Container::emplace_back(key, std::forward<T>(t));
19069 return {std::prev(this->end()),
true};
19072 template<
class KeyType, detail::enable_if_t<
19073 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19074 std::pair<iterator, bool> emplace(KeyType && key, T && t)
19076 for (
auto it = this->begin(); it != this->end(); ++it)
19078 if (m_compare(it->first, key))
19080 return {it,
false};
19083 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
19084 return {std::prev(this->end()),
true};
19087 T& operator[](
const key_type& key)
19089 return emplace(key, T{}).first->second;
19092 template<
class KeyType, detail::enable_if_t<
19093 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19094 T & operator[](KeyType && key)
19096 return emplace(std::forward<KeyType>(key), T{}).first->second;
19099 const T& operator[](
const key_type& key)
const
19104 template<
class KeyType, detail::enable_if_t<
19105 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19106 const T & operator[](KeyType && key)
const
19108 return at(std::forward<KeyType>(key));
19111 T& at(
const key_type& key)
19113 for (
auto it = this->begin(); it != this->end(); ++it)
19115 if (m_compare(it->first, key))
19121 JSON_THROW(std::out_of_range(
"key not found"));
19124 template<
class KeyType, detail::enable_if_t<
19125 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19126 T & at(KeyType && key)
19128 for (
auto it = this->begin(); it != this->end(); ++it)
19130 if (m_compare(it->first, key))
19136 JSON_THROW(std::out_of_range(
"key not found"));
19139 const T& at(
const key_type& key)
const
19141 for (
auto it = this->begin(); it != this->end(); ++it)
19143 if (m_compare(it->first, key))
19149 JSON_THROW(std::out_of_range(
"key not found"));
19152 template<
class KeyType, detail::enable_if_t<
19153 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19154 const T & at(KeyType && key)
const
19156 for (
auto it = this->begin(); it != this->end(); ++it)
19158 if (m_compare(it->first, key))
19164 JSON_THROW(std::out_of_range(
"key not found"));
19167 size_type erase(
const key_type& key)
19169 for (
auto it = this->begin(); it != this->end(); ++it)
19171 if (m_compare(it->first, key))
19174 for (
auto next = it; ++next != this->end(); ++it)
19177 new (&*it) value_type{std::move(*next)};
19179 Container::pop_back();
19186 template<
class KeyType, detail::enable_if_t<
19187 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19188 size_type erase(KeyType && key)
19190 for (
auto it = this->begin(); it != this->end(); ++it)
19192 if (m_compare(it->first, key))
19195 for (
auto next = it; ++next != this->end(); ++it)
19198 new (&*it) value_type{std::move(*next)};
19200 Container::pop_back();
19207 iterator erase(iterator pos)
19209 return erase(pos, std::next(pos));
19212 iterator erase(iterator first, iterator last)
19219 const auto elements_affected = std::distance(first, last);
19220 const auto offset = std::distance(Container::begin(), first);
19242 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
19245 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
19253 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
19262 return Container::begin() + offset;
19265 size_type count(
const key_type& key)
const
19267 for (
auto it = this->begin(); it != this->end(); ++it)
19269 if (m_compare(it->first, key))
19277 template<
class KeyType, detail::enable_if_t<
19278 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19279 size_type count(KeyType && key)
const
19281 for (
auto it = this->begin(); it != this->end(); ++it)
19283 if (m_compare(it->first, key))
19291 iterator find(
const key_type& key)
19293 for (
auto it = this->begin(); it != this->end(); ++it)
19295 if (m_compare(it->first, key))
19300 return Container::end();
19303 template<
class KeyType, detail::enable_if_t<
19304 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19305 iterator find(KeyType && key)
19307 for (
auto it = this->begin(); it != this->end(); ++it)
19309 if (m_compare(it->first, key))
19314 return Container::end();
19317 const_iterator find(
const key_type& key)
const
19319 for (
auto it = this->begin(); it != this->end(); ++it)
19321 if (m_compare(it->first, key))
19326 return Container::end();
19329 std::pair<iterator, bool> insert( value_type&& value )
19331 return emplace(value.first, std::move(value.second));
19334 std::pair<iterator, bool> insert(
const value_type& value )
19336 for (
auto it = this->begin(); it != this->end(); ++it)
19338 if (m_compare(it->first, value.first))
19340 return {it,
false};
19343 Container::push_back(value);
19344 return {--this->end(),
true};
19347 template<
typename InputIt>
19348 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
19349 std::input_iterator_tag>::value>::type;
19351 template<
typename InputIt,
typename = require_input_iter<InputIt>>
19352 void insert(InputIt first, InputIt last)
19354 for (
auto it = first; it != last; ++it)
19361 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
19364NLOHMANN_JSON_NAMESPACE_END
19367#if defined(JSON_HAS_CPP_17)
19368 #if JSON_HAS_STATIC_RTTI
19371 #include <string_view>
19379NLOHMANN_JSON_NAMESPACE_BEGIN
19399NLOHMANN_BASIC_JSON_TPL_DECLARATION
19401 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
19407 friend class ::nlohmann::json_pointer;
19411 template<
typename BasicJsonType,
typename InputType>
19412 friend class ::nlohmann::detail::parser;
19413 friend ::nlohmann::detail::serializer<basic_json>;
19414 template<
typename BasicJsonType>
19415 friend class ::nlohmann::detail::iter_impl;
19416 template<
typename BasicJsonType,
typename CharType>
19417 friend class ::nlohmann::detail::binary_writer;
19418 template<
typename BasicJsonType,
typename InputType,
typename SAX>
19419 friend class ::nlohmann::detail::binary_reader;
19420 template<
typename BasicJsonType>
19421 friend class ::nlohmann::detail::json_sax_dom_parser;
19422 template<
typename BasicJsonType>
19423 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
19424 friend class ::nlohmann::detail::exception;
19427 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
19428 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
19430 JSON_PRIVATE_UNLESS_TESTED:
19432 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
19434 template<
typename InputAdapterType>
19435 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
19436 InputAdapterType adapter,
19437 detail::parser_callback_t<basic_json>cb =
nullptr,
19438 const bool allow_exceptions =
true,
19439 const bool ignore_comments =
false
19442 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
19443 std::move(cb), allow_exceptions, ignore_comments);
19447 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
19448 template<
typename BasicJsonType>
19449 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
19450 template<
typename BasicJsonType>
19451 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
19452 template<
typename Iterator>
19453 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
19454 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
19456 template<
typename CharType>
19457 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
19459 template<
typename InputType>
19460 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
19461 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
19463 JSON_PRIVATE_UNLESS_TESTED:
19464 using serializer = ::nlohmann::detail::serializer<basic_json>;
19470 template<
typename T,
typename SFINAE>
19471 using json_serializer = JSONSerializer<T, SFINAE>;
19526 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
19528 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
19550 JSON_HEDLEY_WARN_UNUSED_RESULT
19555 result[
"copyright"] =
"(C) 2013-2023 Niels Lohmann";
19556 result[
"name"] =
"JSON for Modern C++";
19557 result[
"url"] =
"https://github.com/nlohmann/json";
19558 result[
"version"][
"string"] =
19559 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
19560 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
19561 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
19562 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
19563 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
19564 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
19567 result[
"platform"] =
"win32";
19568#elif defined __linux__
19569 result[
"platform"] =
"linux";
19570#elif defined __APPLE__
19571 result[
"platform"] =
"apple";
19572#elif defined __unix__
19573 result[
"platform"] =
"unix";
19575 result[
"platform"] =
"unknown";
19578#if defined(__ICC) || defined(__INTEL_COMPILER)
19579 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
19580#elif defined(__clang__)
19581 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
19582#elif defined(__GNUC__) || defined(__GNUG__)
19583 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
19584 std::to_string(__GNUC__),
'.',
19585 std::to_string(__GNUC_MINOR__),
'.',
19586 std::to_string(__GNUC_PATCHLEVEL__))
19589#elif defined(__HP_cc) || defined(__HP_aCC)
19590 result[
"compiler"] =
"hp"
19591#elif defined(__IBMCPP__)
19592 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
19593#elif defined(_MSC_VER)
19594 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
19595#elif defined(__PGI)
19596 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
19597#elif defined(__SUNPRO_CC)
19598 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
19600 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
19603#if defined(_MSVC_LANG)
19604 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
19605#elif defined(__cplusplus)
19606 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
19608 result[
"compiler"][
"c++"] =
"unknown";
19626#if defined(JSON_HAS_CPP_14)
19639 AllocatorType<std::pair<
const StringType,
19644 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
19668 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
19679 template<
typename T,
typename... Args>
19680 JSON_HEDLEY_RETURNS_NON_NULL
19681 static T* create(Args&& ... args)
19683 AllocatorType<T> alloc;
19684 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
19686 auto deleter = [&](T * obj)
19688 AllocatorTraits::deallocate(alloc, obj, 1);
19690 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
19691 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
19692 JSON_ASSERT(obj !=
nullptr);
19693 return obj.release();
19700 JSON_PRIVATE_UNLESS_TESTED:
19746 json_value() =
default;
19748 json_value(
boolean_t v) noexcept : boolean(v) {}
19756 json_value(value_t t)
19760 case value_t::object:
19762 object = create<object_t>();
19766 case value_t::array:
19768 array = create<array_t>();
19772 case value_t::string:
19774 string = create<string_t>(
"");
19778 case value_t::binary:
19780 binary = create<binary_t>();
19784 case value_t::boolean:
19786 boolean =
static_cast<boolean_t>(
false);
19790 case value_t::number_integer:
19796 case value_t::number_unsigned:
19802 case value_t::number_float:
19808 case value_t::null:
19814 case value_t::discarded:
19818 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
19820 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.3",
nullptr));
19831 json_value(
string_t&& value) : string(create<
string_t>(std::move(value))) {}
19840 json_value(
const array_t& value) : array(create<
array_t>(value)) {}
19843 json_value(
array_t&& value) : array(create<
array_t>(std::move(value))) {}
19846 json_value(
const typename binary_t::container_type& value) : binary(create<
binary_t>(value)) {}
19849 json_value(
typename binary_t::container_type&& value) : binary(create<
binary_t>(std::move(value))) {}
19855 json_value(
binary_t&& value) : binary(create<
binary_t>(std::move(value))) {}
19857 void destroy(value_t t)
19860 (t == value_t::object &&
object ==
nullptr) ||
19861 (t == value_t::array && array ==
nullptr) ||
19862 (t == value_t::string &&
string ==
nullptr) ||
19863 (t == value_t::binary && binary ==
nullptr)
19869 if (t == value_t::array || t == value_t::object)
19872 std::vector<basic_json> stack;
19875 if (t == value_t::array)
19877 stack.reserve(array->size());
19878 std::move(array->begin(), array->end(), std::back_inserter(stack));
19883 for (
auto&& it : *
object)
19885 stack.push_back(std::move(it.second));
19889 while (!stack.empty())
19892 basic_json current_item(std::move(stack.back()));
19897 if (current_item.is_array())
19899 std::move(current_item.m_data.m_value.array->begin(), current_item.m_data.m_value.array->end(), std::back_inserter(stack));
19901 current_item.m_data.m_value.array->clear();
19903 else if (current_item.is_object())
19905 for (
auto&& it : *current_item.m_data.m_value.object)
19907 stack.push_back(std::move(it.second));
19910 current_item.m_data.m_value.object->clear();
19920 case value_t::object:
19922 AllocatorType<object_t> alloc;
19923 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
19924 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
19928 case value_t::array:
19930 AllocatorType<array_t> alloc;
19931 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
19932 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
19936 case value_t::string:
19938 AllocatorType<string_t> alloc;
19939 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
19940 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
19944 case value_t::binary:
19946 AllocatorType<binary_t> alloc;
19947 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
19948 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
19952 case value_t::null:
19953 case value_t::boolean:
19954 case value_t::number_integer:
19955 case value_t::number_unsigned:
19956 case value_t::number_float:
19957 case value_t::discarded:
19985 void assert_invariant(
bool check_parents =
true) const noexcept
19987 JSON_ASSERT(m_data.m_type != value_t::object || m_data.m_value.object !=
nullptr);
19988 JSON_ASSERT(m_data.m_type != value_t::array || m_data.m_value.array !=
nullptr);
19989 JSON_ASSERT(m_data.m_type != value_t::string || m_data.m_value.string !=
nullptr);
19990 JSON_ASSERT(m_data.m_type != value_t::binary || m_data.m_value.binary !=
nullptr);
19992#if JSON_DIAGNOSTICS
19998 return j.m_parent ==
this;
20003 static_cast<void>(check_parents);
20008#if JSON_DIAGNOSTICS
20009 switch (m_data.m_type)
20011 case value_t::array:
20013 for (
auto& element : *m_data.m_value.array)
20015 element.m_parent =
this;
20020 case value_t::object:
20022 for (
auto& element : *m_data.m_value.object)
20024 element.second.m_parent =
this;
20029 case value_t::null:
20030 case value_t::string:
20031 case value_t::boolean:
20032 case value_t::number_integer:
20033 case value_t::number_unsigned:
20034 case value_t::number_float:
20035 case value_t::binary:
20036 case value_t::discarded:
20043 iterator set_parents(
iterator it,
typename iterator::difference_type count_set_parents)
20045#if JSON_DIAGNOSTICS
20046 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
20048 (it + i)->m_parent =
this;
20051 static_cast<void>(count_set_parents);
20056 reference set_parent(
reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1))
20058#if JSON_DIAGNOSTICS
20059 if (old_capacity !=
static_cast<std::size_t
>(-1))
20062 JSON_ASSERT(
type() == value_t::array);
20063 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
20073#ifdef JSON_HEDLEY_MSVC_VERSION
20074#pragma warning(push )
20075#pragma warning(disable : 4127)
20082#ifdef JSON_HEDLEY_MSVC_VERSION
20083#pragma warning( pop )
20088 static_cast<void>(j);
20089 static_cast<void>(old_capacity);
20121 assert_invariant();
20129 assert_invariant();
20134 template <
typename CompatibleType,
20135 typename U = detail::uncvref_t<CompatibleType>,
20136 detail::enable_if_t <
20139 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20140 std::forward<CompatibleType>(val))))
20142 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20144 assert_invariant();
20149 template <
typename BasicJsonType,
20150 detail::enable_if_t <
20154 using other_boolean_t =
typename BasicJsonType::boolean_t;
20155 using other_number_float_t =
typename BasicJsonType::number_float_t;
20156 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20157 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20158 using other_string_t =
typename BasicJsonType::string_t;
20159 using other_object_t =
typename BasicJsonType::object_t;
20160 using other_array_t =
typename BasicJsonType::array_t;
20161 using other_binary_t =
typename BasicJsonType::binary_t;
20163 switch (val.type())
20165 case value_t::boolean:
20168 case value_t::number_float:
20171 case value_t::number_integer:
20174 case value_t::number_unsigned:
20177 case value_t::string:
20180 case value_t::object:
20183 case value_t::array:
20186 case value_t::binary:
20189 case value_t::null:
20192 case value_t::discarded:
20193 m_data.m_type = value_t::discarded;
20196 JSON_ASSERT(
false);
20198 JSON_ASSERT(m_data.m_type == val.type());
20200 assert_invariant();
20206 bool type_deduction =
true,
20207 value_t manual_type = value_t::array)
20211 bool is_an_object = std::all_of(init.begin(), init.end(),
20217 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[static_cast<size_type>(0)].is_string();
20221 if (!type_deduction)
20224 if (manual_type == value_t::array)
20226 is_an_object =
false;
20230 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
20232 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
20239 m_data.m_type = value_t::object;
20240 m_data.m_value = value_t::object;
20242 for (
auto& element_ref : init)
20244 auto element = element_ref.moved_or_copied();
20245 m_data.m_value.object->emplace(
20246 std::move(*((*element.m_data.m_value.array)[0].m_data.m_value.string)),
20247 std::move((*element.m_data.m_value.array)[1]));
20253 m_data.m_type = value_t::array;
20254 m_data.m_value.array = create<array_t>(init.begin(), init.end());
20258 assert_invariant();
20263 JSON_HEDLEY_WARN_UNUSED_RESULT
20267 res.m_data.m_type = value_t::binary;
20268 res.m_data.m_value = init;
20274 JSON_HEDLEY_WARN_UNUSED_RESULT
20275 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
20278 res.m_data.m_type = value_t::binary;
20279 res.m_data.m_value =
binary_t(init, subtype);
20285 JSON_HEDLEY_WARN_UNUSED_RESULT
20289 res.m_data.m_type = value_t::binary;
20290 res.m_data.m_value = std::move(init);
20296 JSON_HEDLEY_WARN_UNUSED_RESULT
20297 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
20300 res.m_data.m_type = value_t::binary;
20301 res.m_data.m_value =
binary_t(std::move(init), subtype);
20307 JSON_HEDLEY_WARN_UNUSED_RESULT
20310 return basic_json(init,
false, value_t::array);
20315 JSON_HEDLEY_WARN_UNUSED_RESULT
20318 return basic_json(init,
false, value_t::object);
20327 assert_invariant();
20332 template <
class InputIT,
typename std::enable_if <
20333 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
20334 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
20337 JSON_ASSERT(first.m_object !=
nullptr);
20338 JSON_ASSERT(last.m_object !=
nullptr);
20341 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
20343 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
20347 m_data.m_type = first.m_object->m_data.m_type;
20350 switch (m_data.m_type)
20352 case value_t::boolean:
20353 case value_t::number_float:
20354 case value_t::number_integer:
20355 case value_t::number_unsigned:
20356 case value_t::string:
20358 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
20359 || !last.m_it.primitive_iterator.is_end()))
20361 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
20366 case value_t::null:
20367 case value_t::object:
20368 case value_t::array:
20369 case value_t::binary:
20370 case value_t::discarded:
20375 switch (m_data.m_type)
20377 case value_t::number_integer:
20379 m_data.m_value.number_integer = first.m_object->m_data.m_value.number_integer;
20383 case value_t::number_unsigned:
20385 m_data.m_value.number_unsigned = first.m_object->m_data.m_value.number_unsigned;
20389 case value_t::number_float:
20391 m_data.m_value.number_float = first.m_object->m_data.m_value.number_float;
20395 case value_t::boolean:
20397 m_data.m_value.boolean = first.m_object->m_data.m_value.boolean;
20401 case value_t::string:
20403 m_data.m_value = *first.m_object->m_data.m_value.string;
20407 case value_t::object:
20409 m_data.m_value.object = create<object_t>(first.m_it.object_iterator,
20410 last.m_it.object_iterator);
20414 case value_t::array:
20416 m_data.m_value.array = create<array_t>(first.m_it.array_iterator,
20417 last.m_it.array_iterator);
20421 case value_t::binary:
20423 m_data.m_value = *first.m_object->m_data.m_value.binary;
20427 case value_t::null:
20428 case value_t::discarded:
20430 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
20434 assert_invariant();
20441 template<
typename JsonRef,
20442 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
20443 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
20449 : json_base_class_t(other)
20451 m_data.m_type = other.m_data.m_type;
20453 other.assert_invariant();
20455 switch (m_data.m_type)
20457 case value_t::object:
20459 m_data.m_value = *other.m_data.m_value.object;
20463 case value_t::array:
20465 m_data.m_value = *other.m_data.m_value.array;
20469 case value_t::string:
20471 m_data.m_value = *other.m_data.m_value.string;
20475 case value_t::boolean:
20477 m_data.m_value = other.m_data.m_value.boolean;
20481 case value_t::number_integer:
20483 m_data.m_value = other.m_data.m_value.number_integer;
20487 case value_t::number_unsigned:
20489 m_data.m_value = other.m_data.m_value.number_unsigned;
20493 case value_t::number_float:
20495 m_data.m_value = other.m_data.m_value.number_float;
20499 case value_t::binary:
20501 m_data.m_value = *other.m_data.m_value.binary;
20505 case value_t::null:
20506 case value_t::discarded:
20512 assert_invariant();
20518 : json_base_class_t(std::forward<json_base_class_t>(other)),
20519 m_data(std::move(other.m_data))
20522 other.assert_invariant(
false);
20525 other.m_data.m_type = value_t::null;
20526 other.m_data.m_value = {};
20529 assert_invariant();
20535 std::is_nothrow_move_constructible<value_t>::value&&
20536 std::is_nothrow_move_assignable<value_t>::value&&
20537 std::is_nothrow_move_constructible<json_value>::value&&
20538 std::is_nothrow_move_assignable<json_value>::value&&
20539 std::is_nothrow_move_assignable<json_base_class_t>::value
20543 other.assert_invariant();
20546 swap(m_data.m_type, other.m_data.m_type);
20547 swap(m_data.m_value, other.m_data.m_value);
20548 json_base_class_t::operator=(std::move(other));
20551 assert_invariant();
20559 assert_invariant(
false);
20576 const char indent_char =
' ',
20577 const bool ensure_ascii =
false,
20585 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
20589 s.dump(*
this,
false, ensure_ascii, 0);
20599 return m_data.m_type;
20606 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
20613 return is_array() || is_object();
20620 return m_data.m_type == value_t::null;
20627 return m_data.m_type == value_t::boolean;
20634 return is_number_integer() || is_number_float();
20641 return m_data.m_type == value_t::number_integer || m_data.m_type == value_t::number_unsigned;
20648 return m_data.m_type == value_t::number_unsigned;
20655 return m_data.m_type == value_t::number_float;
20662 return m_data.m_type == value_t::object;
20669 return m_data.m_type == value_t::array;
20676 return m_data.m_type == value_t::string;
20683 return m_data.m_type == value_t::binary;
20690 return m_data.m_type == value_t::discarded;
20697 return m_data.m_type;
20708 boolean_t get_impl(boolean_t* )
const
20710 if (JSON_HEDLEY_LIKELY(is_boolean()))
20712 return m_data.m_value.boolean;
20715 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ", type_name()),
this));
20719 object_t* get_impl_ptr(object_t* )
noexcept
20721 return is_object() ? m_data.m_value.object :
nullptr;
20725 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
20727 return is_object() ? m_data.m_value.object :
nullptr;
20731 array_t* get_impl_ptr(array_t* )
noexcept
20733 return is_array() ? m_data.m_value.array :
nullptr;
20737 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
20739 return is_array() ? m_data.m_value.array :
nullptr;
20743 string_t* get_impl_ptr(string_t* )
noexcept
20745 return is_string() ? m_data.m_value.string :
nullptr;
20749 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
20751 return is_string() ? m_data.m_value.string :
nullptr;
20755 boolean_t* get_impl_ptr(boolean_t* )
noexcept
20757 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
20761 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
20763 return is_boolean() ? &m_data.m_value.boolean :
nullptr;
20767 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
20769 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
20773 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
20775 return is_number_integer() ? &m_data.m_value.number_integer :
nullptr;
20779 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
20781 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
20785 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
20787 return is_number_unsigned() ? &m_data.m_value.number_unsigned :
nullptr;
20791 number_float_t* get_impl_ptr(number_float_t* )
noexcept
20793 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
20797 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
20799 return is_number_float() ? &m_data.m_value.number_float :
nullptr;
20803 binary_t* get_impl_ptr(binary_t* )
noexcept
20805 return is_binary() ? m_data.m_value.binary :
nullptr;
20809 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
20811 return is_binary() ? m_data.m_value.binary :
nullptr;
20825 template<
typename ReferenceType,
typename ThisType>
20826 static ReferenceType get_ref_impl(ThisType& obj)
20829 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20831 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20836 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
20846 template<
typename PointerType,
typename std::enable_if<
20847 std::is_pointer<PointerType>::value,
int>::type = 0>
20848 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20851 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20856 template <
typename PointerType,
typename std::enable_if <
20857 std::is_pointer<PointerType>::value&&
20858 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
20859 constexpr auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20862 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20904 template <
typename ValueType,
20905 detail::enable_if_t <
20910 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20912 auto ret = ValueType();
20913 JSONSerializer<ValueType>::from_json(*
this, ret);
20947 template <
typename ValueType,
20948 detail::enable_if_t <
20952 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20954 return JSONSerializer<ValueType>::from_json(*
this);
20972 template <
typename BasicJsonType,
20973 detail::enable_if_t <
20995 template<
typename BasicJsonType,
20996 detail::enable_if_t<
20997 std::is_same<BasicJsonType, basic_json_t>::value,
21008 template<
typename PointerType,
21009 detail::enable_if_t<
21010 std::is_pointer<PointerType>::value,
21013 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
21016 return get_ptr<PointerType>();
21043 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
21044#if defined(JSON_HAS_CPP_14)
21048 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
21054 static_assert(!std::is_reference<ValueTypeCV>::value,
21055 "get() cannot be used with reference types, you might want to use get_ref()");
21086 template<
typename PointerType,
typename std::enable_if<
21087 std::is_pointer<PointerType>::value,
int>::type = 0>
21088 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
21091 return get_ptr<PointerType>();
21096 template <
typename ValueType,
21097 detail::enable_if_t <
21101 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21102 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21104 JSONSerializer<ValueType>::from_json(*
this, v);
21110 template<
typename ValueType,
21111 detail::enable_if_t <
21114 ValueType & get_to(ValueType& v)
const
21121 typename T, std::size_t N,
21122 typename Array = T (&)[N],
21123 detail::enable_if_t <
21125 Array get_to(T (&v)[N])
const
21126 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21127 std::declval<const basic_json_t&>(), v)))
21129 JSONSerializer<Array>::from_json(*
this, v);
21135 template<
typename ReferenceType,
typename std::enable_if<
21136 std::is_reference<ReferenceType>::value,
int>::type = 0>
21140 return get_ref_impl<ReferenceType>(*
this);
21145 template <
typename ReferenceType,
typename std::enable_if <
21146 std::is_reference<ReferenceType>::value&&
21147 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21151 return get_ref_impl<ReferenceType>(*
this);
21183 template <
typename ValueType,
typename std::enable_if <
21191#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21194#if defined(JSON_HAS_CPP_17) && JSON_HAS_STATIC_RTTI
21198 >::value,
int >::type = 0 >
21199 JSON_EXPLICIT
operator ValueType()
const
21202 return get<ValueType>();
21211 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21214 return *get_ptr<binary_t*>();
21223 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21226 return *get_ptr<const binary_t*>();
21244 if (JSON_HEDLEY_LIKELY(is_array()))
21248 return set_parent(m_data.m_value.array->at(idx));
21250 JSON_CATCH (std::out_of_range&)
21253 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21258 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21267 if (JSON_HEDLEY_LIKELY(is_array()))
21271 return m_data.m_value.array->at(idx);
21273 JSON_CATCH (std::out_of_range&)
21276 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21281 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21290 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21292 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21295 auto it = m_data.
m_value.object->find(key);
21296 if (it == m_data.m_value.object->end())
21298 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
21300 return set_parent(it->second);
21305 template<
class KeyType, detail::enable_if_t<
21306 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21310 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21312 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21315 auto it = m_data.
m_value.object->find(std::forward<KeyType>(key));
21316 if (it == m_data.m_value.object->end())
21318 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
21320 return set_parent(it->second);
21328 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21330 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21333 auto it = m_data.
m_value.object->find(key);
21334 if (it == m_data.m_value.object->end())
21336 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
21343 template<
class KeyType, detail::enable_if_t<
21344 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21348 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21350 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21353 auto it = m_data.
m_value.object->find(std::forward<KeyType>(key));
21354 if (it == m_data.m_value.object->end())
21356 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
21368 m_data.m_type = value_t::array;
21369 m_data.m_value.array = create<array_t>();
21370 assert_invariant();
21374 if (JSON_HEDLEY_LIKELY(is_array()))
21377 if (idx >= m_data.m_value.array->size())
21379#if JSON_DIAGNOSTICS
21381 const auto old_size = m_data.m_value.array->size();
21382 const auto old_capacity = m_data.m_value.array->capacity();
21384 m_data.m_value.array->resize(idx + 1);
21386#if JSON_DIAGNOSTICS
21387 if (JSON_HEDLEY_UNLIKELY(m_data.m_value.array->capacity() != old_capacity))
21395 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
21398 assert_invariant();
21401 return m_data.m_value.array->operator[](idx);
21404 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21412 if (JSON_HEDLEY_LIKELY(is_array()))
21414 return m_data.m_value.array->operator[](idx);
21417 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21427 m_data.m_type = value_t::object;
21428 m_data.m_value.object = create<object_t>();
21429 assert_invariant();
21433 if (JSON_HEDLEY_LIKELY(is_object()))
21435 auto result = m_data.m_value.object->emplace(std::move(key),
nullptr);
21436 return set_parent(result.first->second);
21439 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21447 if (JSON_HEDLEY_LIKELY(is_object()))
21449 auto it = m_data.m_value.object->find(key);
21450 JSON_ASSERT(it != m_data.m_value.object->end());
21454 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21459 template<
typename T>
21460 reference operator[](T* key)
21462 return operator[](
typename object_t::key_type(key));
21465 template<
typename T>
21466 const_reference operator[](T* key)
const
21468 return operator[](
typename object_t::key_type(key));
21473 template<
class KeyType, detail::enable_if_t<
21474 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21480 m_data.m_type = value_t::object;
21481 m_data.m_value.object = create<object_t>();
21482 assert_invariant();
21486 if (JSON_HEDLEY_LIKELY(is_object()))
21488 auto result = m_data.m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
21489 return set_parent(result.first->second);
21492 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21497 template<
class KeyType, detail::enable_if_t<
21498 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21502 if (JSON_HEDLEY_LIKELY(is_object()))
21504 auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
21505 JSON_ASSERT(it != m_data.m_value.object->end());
21509 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21513 template<
typename KeyType>
21515 object_comparator_t,
const typename object_t::key_type&, KeyType >;
21517 template<
typename ValueType>
21518 using value_return_type = std::conditional <
21520 string_t,
typename std::decay<ValueType>::type >;
21525 template <
class ValueType, detail::enable_if_t <
21528 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21529 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
21532 if (JSON_HEDLEY_LIKELY(is_object()))
21535 const auto it = find(key);
21538 return it->template get<ValueType>();
21541 return default_value;
21544 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21549 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21550 detail::enable_if_t <
21553 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21554 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
21557 if (JSON_HEDLEY_LIKELY(is_object()))
21560 const auto it = find(key);
21563 return it->template get<ReturnType>();
21566 return std::forward<ValueType>(default_value);
21569 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21574 template <
class ValueType,
class KeyType, detail::enable_if_t <
21577 && is_comparable_with_object_key<KeyType>::value
21579 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21580 ValueType
value(KeyType && key,
const ValueType& default_value)
const
21583 if (JSON_HEDLEY_LIKELY(is_object()))
21586 const auto it = find(std::forward<KeyType>(key));
21589 return it->template get<ValueType>();
21592 return default_value;
21595 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21600 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
21601 detail::enable_if_t <
21604 && is_comparable_with_object_key<KeyType>::value
21606 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21607 ReturnType
value(KeyType && key, ValueType && default_value)
const
21610 if (JSON_HEDLEY_LIKELY(is_object()))
21613 const auto it = find(std::forward<KeyType>(key));
21616 return it->template get<ReturnType>();
21619 return std::forward<ValueType>(default_value);
21622 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21627 template <
class ValueType, detail::enable_if_t <
21629 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21633 if (JSON_HEDLEY_LIKELY(is_object()))
21638 return ptr.get_checked(
this).template get<ValueType>();
21642 return default_value;
21646 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21651 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21652 detail::enable_if_t <
21654 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21658 if (JSON_HEDLEY_LIKELY(is_object()))
21663 return ptr.get_checked(
this).template get<ReturnType>();
21667 return std::forward<ValueType>(default_value);
21671 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21674 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
21677 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21679 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
21681 return value(ptr.convert(), default_value);
21684 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
21685 detail::enable_if_t <
21688 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21690 ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
21692 return value(ptr.convert(), std::forward<ValueType>(default_value));
21729 template <
class IteratorType, detail::enable_if_t <
21730 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21731 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21735 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21737 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
21740 IteratorType result = end();
21742 switch (m_data.m_type)
21744 case value_t::boolean:
21745 case value_t::number_float:
21746 case value_t::number_integer:
21747 case value_t::number_unsigned:
21748 case value_t::string:
21749 case value_t::binary:
21751 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21753 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
21758 AllocatorType<string_t> alloc;
21759 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
21760 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
21761 m_data.m_value.string =
nullptr;
21763 else if (is_binary())
21765 AllocatorType<binary_t> alloc;
21766 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
21767 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
21768 m_data.m_value.binary =
nullptr;
21771 m_data.m_type = value_t::null;
21772 assert_invariant();
21776 case value_t::object:
21778 result.m_it.object_iterator = m_data.m_value.object->erase(pos.m_it.object_iterator);
21782 case value_t::array:
21784 result.m_it.array_iterator = m_data.m_value.array->erase(pos.m_it.array_iterator);
21788 case value_t::null:
21789 case value_t::discarded:
21791 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21799 template <
class IteratorType, detail::enable_if_t <
21800 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21801 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21802 IteratorType
erase(IteratorType first, IteratorType last)
21805 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21807 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
21810 IteratorType result = end();
21812 switch (m_data.m_type)
21814 case value_t::boolean:
21815 case value_t::number_float:
21816 case value_t::number_integer:
21817 case value_t::number_unsigned:
21818 case value_t::string:
21819 case value_t::binary:
21821 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21822 || !last.m_it.primitive_iterator.is_end()))
21824 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
21829 AllocatorType<string_t> alloc;
21830 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.string);
21831 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.string, 1);
21832 m_data.m_value.string =
nullptr;
21834 else if (is_binary())
21836 AllocatorType<binary_t> alloc;
21837 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_data.m_value.binary);
21838 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_data.m_value.binary, 1);
21839 m_data.m_value.binary =
nullptr;
21842 m_data.m_type = value_t::null;
21843 assert_invariant();
21847 case value_t::object:
21849 result.m_it.object_iterator = m_data.m_value.object->erase(first.m_it.object_iterator,
21850 last.m_it.object_iterator);
21854 case value_t::array:
21856 result.m_it.array_iterator = m_data.m_value.array->erase(first.m_it.array_iterator,
21857 last.m_it.array_iterator);
21861 case value_t::null:
21862 case value_t::discarded:
21864 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21871 template <
typename KeyType, detail::enable_if_t <
21872 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21873 size_type erase_internal(KeyType && key)
21876 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21878 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21881 return m_data.m_value.object->erase(std::forward<KeyType>(key));
21884 template <
typename KeyType, detail::enable_if_t <
21885 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21886 size_type erase_internal(KeyType && key)
21889 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21891 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21894 const auto it = m_data.m_value.object->find(std::forward<KeyType>(key));
21895 if (it != m_data.m_value.object->end())
21897 m_data.m_value.object->erase(it);
21911 return erase_internal(key);
21916 template<
class KeyType, detail::enable_if_t<
21917 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21920 return erase_internal(std::forward<KeyType>(key));
21928 if (JSON_HEDLEY_LIKELY(is_array()))
21930 if (JSON_HEDLEY_UNLIKELY(idx >= size()))
21932 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21935 m_data.m_value.array->erase(m_data.m_value.array->begin() +
static_cast<difference_type>(idx));
21939 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21956 auto result = end();
21960 result.m_it.object_iterator = m_data.m_value.object->find(key);
21970 auto result = cend();
21974 result.m_it.object_iterator = m_data.m_value.object->find(key);
21982 template<
class KeyType, detail::enable_if_t<
21983 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21986 auto result = end();
21990 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
21998 template<
class KeyType, detail::enable_if_t<
21999 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22002 auto result = cend();
22006 result.m_it.object_iterator = m_data.m_value.object->find(std::forward<KeyType>(key));
22017 return is_object() ? m_data.m_value.object->count(key) : 0;
22022 template<
class KeyType, detail::enable_if_t<
22023 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22027 return is_object() ? m_data.m_value.object->count(std::forward<KeyType>(key)) : 0;
22032 bool contains(
const typename object_t::key_type& key)
const
22034 return is_object() && m_data.m_value.object->find(key) != m_data.m_value.object->end();
22039 template<
class KeyType, detail::enable_if_t<
22040 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
22043 return is_object() && m_data.m_value.object->find(std::forward<KeyType>(key)) != m_data.m_value.object->end();
22050 return ptr.contains(
this);
22053 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
22055 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
22057 return ptr.contains(
this);
22074 result.set_begin();
22090 result.set_begin();
22167 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22170 return ref.items();
22178 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22181 return ref.items();
22188 return iteration_proxy<iterator>(*
this);
22193 iteration_proxy<const_iterator>
items() const noexcept
22195 return iteration_proxy<const_iterator>(*
this);
22211 switch (m_data.m_type)
22213 case value_t::null:
22219 case value_t::array:
22222 return m_data.m_value.array->empty();
22225 case value_t::object:
22228 return m_data.m_value.object->empty();
22231 case value_t::string:
22232 case value_t::boolean:
22233 case value_t::number_integer:
22234 case value_t::number_unsigned:
22235 case value_t::number_float:
22236 case value_t::binary:
22237 case value_t::discarded:
22250 switch (m_data.m_type)
22252 case value_t::null:
22258 case value_t::array:
22261 return m_data.m_value.array->size();
22264 case value_t::object:
22267 return m_data.m_value.object->size();
22270 case value_t::string:
22271 case value_t::boolean:
22272 case value_t::number_integer:
22273 case value_t::number_unsigned:
22274 case value_t::number_float:
22275 case value_t::binary:
22276 case value_t::discarded:
22289 switch (m_data.m_type)
22291 case value_t::array:
22294 return m_data.m_value.array->max_size();
22297 case value_t::object:
22300 return m_data.m_value.object->max_size();
22303 case value_t::null:
22304 case value_t::string:
22305 case value_t::boolean:
22306 case value_t::number_integer:
22307 case value_t::number_unsigned:
22308 case value_t::number_float:
22309 case value_t::binary:
22310 case value_t::discarded:
22332 switch (m_data.m_type)
22334 case value_t::number_integer:
22336 m_data.m_value.number_integer = 0;
22340 case value_t::number_unsigned:
22342 m_data.m_value.number_unsigned = 0;
22346 case value_t::number_float:
22348 m_data.m_value.number_float = 0.0;
22352 case value_t::boolean:
22354 m_data.m_value.boolean =
false;
22358 case value_t::string:
22360 m_data.m_value.string->clear();
22364 case value_t::binary:
22366 m_data.m_value.binary->clear();
22370 case value_t::array:
22372 m_data.m_value.array->clear();
22376 case value_t::object:
22378 m_data.m_value.object->clear();
22382 case value_t::null:
22383 case value_t::discarded:
22394 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22396 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22402 m_data.m_type = value_t::array;
22403 m_data.m_value = value_t::array;
22404 assert_invariant();
22408 const auto old_capacity = m_data.m_value.array->capacity();
22409 m_data.m_value.array->push_back(std::move(val));
22410 set_parent(m_data.m_value.array->back(), old_capacity);
22418 push_back(std::move(val));
22427 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22429 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22435 m_data.m_type = value_t::array;
22436 m_data.m_value = value_t::array;
22437 assert_invariant();
22441 const auto old_capacity = m_data.m_value.array->capacity();
22442 m_data.m_value.array->push_back(val);
22443 set_parent(m_data.m_value.array->back(), old_capacity);
22459 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22461 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22467 m_data.m_type = value_t::object;
22468 m_data.m_value = value_t::object;
22469 assert_invariant();
22473 auto res = m_data.m_value.object->insert(val);
22474 set_parent(res.first->second);
22489 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
22491 basic_json&& key = init.begin()->moved_or_copied();
22492 push_back(
typename object_t::value_type(
22493 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22511 template<
class... Args>
22515 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22517 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
22523 m_data.m_type = value_t::array;
22524 m_data.m_value = value_t::array;
22525 assert_invariant();
22529 const auto old_capacity = m_data.
m_value.array->capacity();
22530 m_data.m_value.array->emplace_back(std::forward<Args>(args)...);
22531 return set_parent(m_data.m_value.array->back(), old_capacity);
22536 template<
class... Args>
22540 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22542 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
22548 m_data.m_type = value_t::object;
22549 m_data.m_value = value_t::object;
22550 assert_invariant();
22554 auto res = m_data.m_value.object->emplace(std::forward<Args>(args)...);
22555 set_parent(res.first->second);
22559 it.m_it.object_iterator = res.first;
22562 return {it, res.second};
22568 template<
typename... Args>
22572 JSON_ASSERT(m_data.m_value.array !=
nullptr);
22574 auto insert_pos = std::distance(m_data.m_value.array->begin(), pos.m_it.array_iterator);
22575 m_data.m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22576 result.m_it.array_iterator = m_data.m_value.array->begin() + insert_pos;
22591 if (JSON_HEDLEY_LIKELY(is_array()))
22594 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22596 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22600 return insert_iterator(pos, val);
22603 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22610 return insert(pos, val);
22618 if (JSON_HEDLEY_LIKELY(is_array()))
22621 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22623 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22627 return insert_iterator(pos, cnt, val);
22630 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22638 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22640 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22644 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22646 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22650 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22652 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22655 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22657 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
22661 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22669 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22671 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22675 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22677 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22681 return insert_iterator(pos, ilist.begin(), ilist.end());
22689 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22691 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22695 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22697 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22701 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22703 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
22706 m_data.m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22713 update(j.
begin(), j.
end(), merge_objects);
22723 m_data.m_type = value_t::object;
22724 m_data.m_value.object = create<object_t>();
22725 assert_invariant();
22728 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22730 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
22734 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22736 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22740 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22742 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
22745 for (
auto it = first; it != last; ++it)
22747 if (merge_objects && it.value().is_object())
22749 auto it2 = m_data.m_value.object->find(it.key());
22750 if (it2 != m_data.m_value.object->end())
22752 it2->second.update(it.value(),
true);
22756 m_data.m_value.object->operator[](it.key()) = it.value();
22757#if JSON_DIAGNOSTICS
22758 m_data.m_value.object->operator[](it.key()).m_parent =
this;
22766 std::is_nothrow_move_constructible<value_t>::value&&
22767 std::is_nothrow_move_assignable<value_t>::value&&
22768 std::is_nothrow_move_constructible<json_value>::value&&
22769 std::is_nothrow_move_assignable<json_value>::value
22772 std::swap(m_data.m_type, other.m_data.m_type);
22773 std::swap(m_data.m_value, other.m_data.m_value);
22776 other.set_parents();
22777 assert_invariant();
22783 std::is_nothrow_move_constructible<value_t>::value&&
22784 std::is_nothrow_move_assignable<value_t>::value&&
22785 std::is_nothrow_move_constructible<json_value>::value&&
22786 std::is_nothrow_move_assignable<json_value>::value
22797 if (JSON_HEDLEY_LIKELY(is_array()))
22800 swap(*(m_data.m_value.array), other);
22804 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
22813 if (JSON_HEDLEY_LIKELY(is_object()))
22816 swap(*(m_data.m_value.object), other);
22820 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
22829 if (JSON_HEDLEY_LIKELY(is_string()))
22832 swap(*(m_data.m_value.string), other);
22836 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
22845 if (JSON_HEDLEY_LIKELY(is_binary()))
22848 swap(*(m_data.m_value.binary), other);
22852 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
22858 void swap(
typename binary_t::container_type& other)
22861 if (JSON_HEDLEY_LIKELY(is_binary()))
22864 swap(*(m_data.m_value.binary), other);
22868 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
22883#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
22884 const auto lhs_type = lhs.type(); \
22885 const auto rhs_type = rhs.type(); \
22887 if (lhs_type == rhs_type) \
22889 switch (lhs_type) \
22891 case value_t::array: \
22892 return (*lhs.m_data.m_value.array) op (*rhs.m_data.m_value.array); \
22894 case value_t::object: \
22895 return (*lhs.m_data.m_value.object) op (*rhs.m_data.m_value.object); \
22897 case value_t::null: \
22898 return (null_result); \
22900 case value_t::string: \
22901 return (*lhs.m_data.m_value.string) op (*rhs.m_data.m_value.string); \
22903 case value_t::boolean: \
22904 return (lhs.m_data.m_value.boolean) op (rhs.m_data.m_value.boolean); \
22906 case value_t::number_integer: \
22907 return (lhs.m_data.m_value.number_integer) op (rhs.m_data.m_value.number_integer); \
22909 case value_t::number_unsigned: \
22910 return (lhs.m_data.m_value.number_unsigned) op (rhs.m_data.m_value.number_unsigned); \
22912 case value_t::number_float: \
22913 return (lhs.m_data.m_value.number_float) op (rhs.m_data.m_value.number_float); \
22915 case value_t::binary: \
22916 return (*lhs.m_data.m_value.binary) op (*rhs.m_data.m_value.binary); \
22918 case value_t::discarded: \
22920 return (unordered_result); \
22923 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
22925 return static_cast<number_float_t>(lhs.m_data.m_value.number_integer) op rhs.m_data.m_value.number_float; \
22927 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
22929 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_integer); \
22931 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
22933 return static_cast<number_float_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_float; \
22935 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
22937 return lhs.m_data.m_value.number_float op static_cast<number_float_t>(rhs.m_data.m_value.number_unsigned); \
22939 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
22941 return static_cast<number_integer_t>(lhs.m_data.m_value.number_unsigned) op rhs.m_data.m_value.number_integer; \
22943 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
22945 return lhs.m_data.m_value.number_integer op static_cast<number_integer_t>(rhs.m_data.m_value.number_unsigned); \
22947 else if(compares_unordered(lhs, rhs))\
22949 return (unordered_result);\
22952 return (default_result);
22954 JSON_PRIVATE_UNLESS_TESTED:
22960 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
22962 if ((lhs.is_number_float() && std::isnan(lhs.m_data.m_value.number_float) && rhs.is_number())
22963 || (rhs.is_number_float() && std::isnan(rhs.m_data.m_value.number_float) && lhs.is_number()))
22967#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22968 return (lhs.is_discarded() || rhs.is_discarded()) && !
inverse;
22971 return lhs.is_discarded() || rhs.is_discarded();
22976 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
22978 return compares_unordered(*
this, rhs, inverse);
22982#if JSON_HAS_THREE_WAY_COMPARISON
22985 bool operator==(const_reference rhs)
const noexcept
22988#pragma GCC diagnostic push
22989#pragma GCC diagnostic ignored "-Wfloat-equal"
22991 const_reference lhs = *
this;
22992 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
22994#pragma GCC diagnostic pop
23000 template<
typename ScalarType>
23001 requires std::is_scalar_v<ScalarType>
23002 bool operator==(ScalarType rhs)
const noexcept
23009 bool operator!=(const_reference rhs)
const noexcept
23011 if (compares_unordered(rhs,
true))
23015 return !operator==(rhs);
23020 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
23022 const_reference lhs = *
this;
23025 JSON_IMPLEMENT_OPERATOR(<=>,
23026 std::partial_ordering::equivalent,
23027 std::partial_ordering::unordered,
23028 lhs_type <=> rhs_type)
23033 template<
typename ScalarType>
23034 requires std::is_scalar_v<ScalarType>
23035 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
23040#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
23046 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23047 bool operator<=(const_reference rhs)
const noexcept
23049 if (compares_unordered(rhs,
true))
23053 return !(rhs < *
this);
23058 template<
typename ScalarType>
23059 requires std::is_scalar_v<ScalarType>
23060 bool operator<=(ScalarType rhs)
const noexcept
23067 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
23068 bool operator>=(const_reference rhs)
const noexcept
23070 if (compares_unordered(rhs,
true))
23074 return !(*
this < rhs);
23079 template<
typename ScalarType>
23080 requires std::is_scalar_v<ScalarType>
23081 bool operator>=(ScalarType rhs)
const noexcept
23089 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23092#pragma GCC diagnostic push
23093#pragma GCC diagnostic ignored "-Wfloat-equal"
23095 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23097#pragma GCC diagnostic pop
23103 template<
typename ScalarType,
typename std::enable_if<
23104 std::is_scalar<ScalarType>::value,
int>::type = 0>
23105 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23112 template<
typename ScalarType,
typename std::enable_if<
23113 std::is_scalar<ScalarType>::value,
int>::type = 0>
23114 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23121 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23123 if (compares_unordered(lhs, rhs,
true))
23127 return !(lhs == rhs);
23132 template<
typename ScalarType,
typename std::enable_if<
23133 std::is_scalar<ScalarType>::value,
int>::type = 0>
23134 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23141 template<
typename ScalarType,
typename std::enable_if<
23142 std::is_scalar<ScalarType>::value,
int>::type = 0>
23143 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23150 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
23155 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
23160 template<
typename ScalarType,
typename std::enable_if<
23161 std::is_scalar<ScalarType>::value,
int>::type = 0>
23162 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
23169 template<
typename ScalarType,
typename std::enable_if<
23170 std::is_scalar<ScalarType>::value,
int>::type = 0>
23171 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
23178 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
23180 if (compares_unordered(lhs, rhs,
true))
23184 return !(rhs < lhs);
23189 template<
typename ScalarType,
typename std::enable_if<
23190 std::is_scalar<ScalarType>::value,
int>::type = 0>
23191 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
23198 template<
typename ScalarType,
typename std::enable_if<
23199 std::is_scalar<ScalarType>::value,
int>::type = 0>
23200 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
23207 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
23210 if (compares_unordered(lhs, rhs))
23214 return !(lhs <= rhs);
23219 template<
typename ScalarType,
typename std::enable_if<
23220 std::is_scalar<ScalarType>::value,
int>::type = 0>
23221 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
23228 template<
typename ScalarType,
typename std::enable_if<
23229 std::is_scalar<ScalarType>::value,
int>::type = 0>
23230 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
23237 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
23239 if (compares_unordered(lhs, rhs,
true))
23243 return !(lhs < rhs);
23248 template<
typename ScalarType,
typename std::enable_if<
23249 std::is_scalar<ScalarType>::value,
int>::type = 0>
23250 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
23257 template<
typename ScalarType,
typename std::enable_if<
23258 std::is_scalar<ScalarType>::value,
int>::type = 0>
23259 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
23265#undef JSON_IMPLEMENT_OPERATOR
23278 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
23281 const bool pretty_print = o.width() > 0;
23282 const auto indentation = pretty_print ? o.width() : 0;
23289 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23299 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23300 friend std::ostream& operator>>(
const basic_json& j, std::ostream& o)
23316 template<
typename InputType>
23317 JSON_HEDLEY_WARN_UNUSED_RESULT
23319 const parser_callback_t cb =
nullptr,
23320 const bool allow_exceptions =
true,
23321 const bool ignore_comments =
false)
23324 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23330 template<
typename IteratorType>
23331 JSON_HEDLEY_WARN_UNUSED_RESULT
23334 const parser_callback_t cb =
nullptr,
23335 const bool allow_exceptions =
true,
23336 const bool ignore_comments =
false)
23339 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23343 JSON_HEDLEY_WARN_UNUSED_RESULT
23344 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
23346 const parser_callback_t cb =
nullptr,
23347 const bool allow_exceptions =
true,
23348 const bool ignore_comments =
false)
23351 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23357 template<
typename InputType>
23358 static bool accept(InputType&& i,
23359 const bool ignore_comments =
false)
23361 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23366 template<
typename IteratorType>
23367 static bool accept(IteratorType first, IteratorType last,
23368 const bool ignore_comments =
false)
23370 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23373 JSON_HEDLEY_WARN_UNUSED_RESULT
23374 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
23376 const bool ignore_comments =
false)
23378 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23383 template <
typename InputType,
typename SAX>
23384 JSON_HEDLEY_NON_NULL(2)
23385 static
bool sax_parse(InputType&& i, SAX* sax,
23386 input_format_t format = input_format_t::json,
23387 const
bool strict = true,
23388 const
bool ignore_comments = false)
23390 auto ia = detail::input_adapter(std::forward<InputType>(i));
23391 return format == input_format_t::json
23392 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23398 template<
class IteratorType,
class SAX>
23399 JSON_HEDLEY_NON_NULL(3)
23400 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23402 const
bool strict = true,
23403 const
bool ignore_comments = false)
23405 auto ia = detail::input_adapter(std::move(first), std::move(last));
23406 return format == input_format_t::json
23407 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23416 template <
typename SAX>
23417 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
23418 JSON_HEDLEY_NON_NULL(2)
23419 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
23421 const
bool strict = true,
23422 const
bool ignore_comments = false)
23425 return format == input_format_t::json
23427 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23438 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
23441 return operator>>(i, j);
23448 parser(detail::input_adapter(i)).parse(
false, j);
23460 JSON_HEDLEY_RETURNS_NON_NULL
23463 switch (m_data.m_type)
23465 case value_t::null:
23467 case value_t::object:
23469 case value_t::array:
23471 case value_t::string:
23473 case value_t::boolean:
23475 case value_t::binary:
23477 case value_t::discarded:
23478 return "discarded";
23479 case value_t::number_integer:
23480 case value_t::number_unsigned:
23481 case value_t::number_float:
23487 JSON_PRIVATE_UNLESS_TESTED:
23495 value_t m_type = value_t::null;
23498 json_value m_value = {};
23500 data(
const value_t v)
23501 : m_type(v), m_value(v)
23508 m_value.array = create<array_t>(cnt, val);
23511 data() noexcept = default;
23512 data(data&&) noexcept = default;
23513 data(const data&) noexcept = delete;
23514 data& operator=(data&&) noexcept = delete;
23515 data& operator=(const data&) noexcept = delete;
23519 m_value.destroy(m_type);
23525#if JSON_DIAGNOSTICS
23542 std::vector<std::uint8_t> result;
23543 to_cbor(j, result);
23551 binary_writer<std::uint8_t>(o).write_cbor(j);
23558 binary_writer<char>(o).write_cbor(j);
23565 std::vector<std::uint8_t> result;
23566 to_msgpack(j, result);
23574 binary_writer<std::uint8_t>(o).write_msgpack(j);
23581 binary_writer<char>(o).write_msgpack(j);
23587 const bool use_size =
false,
23588 const bool use_type =
false)
23590 std::vector<std::uint8_t> result;
23591 to_ubjson(j, result, use_size, use_type);
23598 const bool use_size =
false,
const bool use_type =
false)
23600 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
23606 const bool use_size =
false,
const bool use_type =
false)
23608 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
23614 const bool use_size =
false,
23615 const bool use_type =
false)
23617 std::vector<std::uint8_t> result;
23618 to_bjdata(j, result, use_size, use_type);
23625 const bool use_size =
false,
const bool use_type =
false)
23627 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
23633 const bool use_size =
false,
const bool use_type =
false)
23635 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
23642 std::vector<std::uint8_t> result;
23643 to_bson(j, result);
23651 binary_writer<std::uint8_t>(o).write_bson(j);
23658 binary_writer<char>(o).write_bson(j);
23663 template<
typename InputType>
23664 JSON_HEDLEY_WARN_UNUSED_RESULT
23666 const bool strict =
true,
23667 const bool allow_exceptions =
true,
23672 auto ia = detail::input_adapter(std::forward<InputType>(i));
23673 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23674 return res ? result :
basic_json(value_t::discarded);
23679 template<
typename IteratorType>
23680 JSON_HEDLEY_WARN_UNUSED_RESULT
23682 const bool strict =
true,
23683 const bool allow_exceptions =
true,
23688 auto ia = detail::input_adapter(std::move(first), std::move(last));
23689 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23690 return res ? result :
basic_json(value_t::discarded);
23693 template<
typename T>
23694 JSON_HEDLEY_WARN_UNUSED_RESULT
23695 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23696 static basic_json from_cbor(
const T* ptr, std::size_t len,
23697 const bool strict =
true,
23698 const bool allow_exceptions =
true,
23699 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23701 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
23704 JSON_HEDLEY_WARN_UNUSED_RESULT
23705 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23707 const bool strict =
true,
23708 const bool allow_exceptions =
true,
23709 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23715 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23716 return res ? result :
basic_json(value_t::discarded);
23721 template<
typename InputType>
23722 JSON_HEDLEY_WARN_UNUSED_RESULT
23724 const bool strict =
true,
23725 const bool allow_exceptions =
true)
23729 auto ia = detail::input_adapter(std::forward<InputType>(i));
23730 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23731 return res ? result :
basic_json(value_t::discarded);
23736 template<
typename IteratorType>
23737 JSON_HEDLEY_WARN_UNUSED_RESULT
23739 const bool strict =
true,
23740 const bool allow_exceptions =
true)
23744 auto ia = detail::input_adapter(std::move(first), std::move(last));
23745 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23746 return res ? result :
basic_json(value_t::discarded);
23749 template<
typename T>
23750 JSON_HEDLEY_WARN_UNUSED_RESULT
23751 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23752 static basic_json from_msgpack(
const T* ptr, std::size_t len,
23753 const bool strict =
true,
23754 const bool allow_exceptions =
true)
23756 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
23759 JSON_HEDLEY_WARN_UNUSED_RESULT
23760 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23762 const bool strict =
true,
23763 const bool allow_exceptions =
true)
23769 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23770 return res ? result :
basic_json(value_t::discarded);
23775 template<
typename InputType>
23776 JSON_HEDLEY_WARN_UNUSED_RESULT
23778 const bool strict =
true,
23779 const bool allow_exceptions =
true)
23783 auto ia = detail::input_adapter(std::forward<InputType>(i));
23784 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23785 return res ? result :
basic_json(value_t::discarded);
23790 template<
typename IteratorType>
23791 JSON_HEDLEY_WARN_UNUSED_RESULT
23793 const bool strict =
true,
23794 const bool allow_exceptions =
true)
23798 auto ia = detail::input_adapter(std::move(first), std::move(last));
23799 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23800 return res ? result :
basic_json(value_t::discarded);
23803 template<
typename T>
23804 JSON_HEDLEY_WARN_UNUSED_RESULT
23805 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23806 static basic_json from_ubjson(
const T* ptr, std::size_t len,
23807 const bool strict =
true,
23808 const bool allow_exceptions =
true)
23810 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
23813 JSON_HEDLEY_WARN_UNUSED_RESULT
23814 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23816 const bool strict =
true,
23817 const bool allow_exceptions =
true)
23823 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23824 return res ? result :
basic_json(value_t::discarded);
23829 template<
typename InputType>
23830 JSON_HEDLEY_WARN_UNUSED_RESULT
23832 const bool strict =
true,
23833 const bool allow_exceptions =
true)
23837 auto ia = detail::input_adapter(std::forward<InputType>(i));
23838 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23839 return res ? result :
basic_json(value_t::discarded);
23844 template<
typename IteratorType>
23845 JSON_HEDLEY_WARN_UNUSED_RESULT
23847 const bool strict =
true,
23848 const bool allow_exceptions =
true)
23852 auto ia = detail::input_adapter(std::move(first), std::move(last));
23853 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23854 return res ? result :
basic_json(value_t::discarded);
23859 template<
typename InputType>
23860 JSON_HEDLEY_WARN_UNUSED_RESULT
23862 const bool strict =
true,
23863 const bool allow_exceptions =
true)
23867 auto ia = detail::input_adapter(std::forward<InputType>(i));
23868 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23869 return res ? result :
basic_json(value_t::discarded);
23874 template<
typename IteratorType>
23875 JSON_HEDLEY_WARN_UNUSED_RESULT
23877 const bool strict =
true,
23878 const bool allow_exceptions =
true)
23882 auto ia = detail::input_adapter(std::move(first), std::move(last));
23883 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23884 return res ? result :
basic_json(value_t::discarded);
23887 template<
typename T>
23888 JSON_HEDLEY_WARN_UNUSED_RESULT
23889 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23890 static basic_json from_bson(
const T* ptr, std::size_t len,
23891 const bool strict =
true,
23892 const bool allow_exceptions =
true)
23894 return from_bson(ptr, ptr + len, strict, allow_exceptions);
23897 JSON_HEDLEY_WARN_UNUSED_RESULT
23898 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23900 const bool strict =
true,
23901 const bool allow_exceptions =
true)
23907 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23908 return res ? result :
basic_json(value_t::discarded);
23923 return ptr.get_unchecked(
this);
23926 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23928 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23930 return ptr.get_unchecked(
this);
23937 return ptr.get_unchecked(
this);
23940 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23942 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23944 return ptr.get_unchecked(
this);
23951 return ptr.get_checked(
this);
23954 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23956 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23958 return ptr.get_checked(
this);
23965 return ptr.get_checked(
this);
23968 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23970 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23972 return ptr.get_checked(
this);
23980 json_pointer::flatten(
"", *
this, result);
23988 return json_pointer::unflatten(*
this);
24006 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
24008 const auto get_op = [](
const std::string & op)
24012 return patch_operations::add;
24014 if (op ==
"remove")
24016 return patch_operations::remove;
24018 if (op ==
"replace")
24020 return patch_operations::replace;
24024 return patch_operations::move;
24028 return patch_operations::copy;
24032 return patch_operations::test;
24035 return patch_operations::invalid;
24050 if (top_pointer != ptr)
24052 result.
at(top_pointer);
24056 const auto last_path = ptr.
back();
24061 switch (parent.m_data.m_type)
24063 case value_t::null:
24064 case value_t::object:
24067 parent[last_path] = val;
24071 case value_t::array:
24073 if (last_path ==
"-")
24080 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
24081 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
24084 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
24094 case value_t::string:
24095 case value_t::boolean:
24096 case value_t::number_integer:
24097 case value_t::number_unsigned:
24098 case value_t::number_float:
24099 case value_t::binary:
24100 case value_t::discarded:
24102 JSON_ASSERT(
false);
24107 const auto operation_remove = [
this, & result](
json_pointer & ptr)
24110 const auto last_path = ptr.
back();
24118 auto it = parent.
find(last_path);
24119 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
24125 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
24131 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
24136 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
24138 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
24142 for (
const auto& val : json_patch)
24145 const auto get_value = [&val](
const std::string & op,
24146 const std::string & member,
24150 auto it = val.m_data.m_value.object->find(member);
24153 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
24156 if (JSON_HEDLEY_UNLIKELY(it == val.m_data.m_value.object->end()))
24159 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
24163 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
24166 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
24174 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
24176 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
24180 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
24181 const auto path = get_value(op,
"path",
true).template get<std::string>();
24184 switch (get_op(op))
24186 case patch_operations::add:
24188 operation_add(ptr, get_value(
"add",
"value",
false));
24192 case patch_operations::remove:
24194 operation_remove(ptr);
24198 case patch_operations::replace:
24201 result.
at(ptr) = get_value(
"replace",
"value",
false);
24205 case patch_operations::move:
24207 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
24217 operation_remove(from_ptr);
24218 operation_add(ptr, v);
24222 case patch_operations::copy:
24224 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
24233 operation_add(ptr, v);
24237 case patch_operations::test:
24239 bool success =
false;
24244 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
24252 if (JSON_HEDLEY_UNLIKELY(!success))
24254 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
24260 case patch_operations::invalid:
24265 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
24282 JSON_HEDLEY_WARN_UNUSED_RESULT
24284 const std::string& path =
"")
24290 if (source == target)
24295 if (source.type() != target.type())
24300 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24305 switch (source.type())
24307 case value_t::array:
24311 while (i < source.size() && i < target.size())
24314 auto temp_diff = diff(source[i], target[i], detail::concat(path,
'/', std::to_string(i)));
24315 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24324 while (i < source.size())
24328 result.
insert(result.
begin() + end_index,
object(
24331 {
"path", detail::concat(path,
'/', std::to_string(i))}
24337 while (i < target.size())
24342 {
"path", detail::concat(path,
"/-")},
24343 {
"value", target[i]}
24351 case value_t::object:
24354 for (
auto it = source.cbegin(); it != source.cend(); ++it)
24357 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24359 if (target.find(it.key()) != target.end())
24362 auto temp_diff = diff(it.value(), target[it.key()], path_key);
24363 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24370 {
"op",
"remove"}, {
"path", path_key}
24376 for (
auto it = target.cbegin(); it != target.cend(); ++it)
24378 if (source.find(it.key()) == source.end())
24381 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24384 {
"op",
"add"}, {
"path", path_key},
24385 {
"value", it.value()}
24393 case value_t::null:
24394 case value_t::string:
24395 case value_t::boolean:
24396 case value_t::number_integer:
24397 case value_t::number_unsigned:
24398 case value_t::number_float:
24399 case value_t::binary:
24400 case value_t::discarded:
24406 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24433 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
24435 if (it.value().is_null())
24441 operator[](it.key()).merge_patch(it.value());
24447 *
this = apply_patch;
24456NLOHMANN_BASIC_JSON_TPL_DECLARATION
24457std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
24462inline namespace literals
24464inline namespace json_literals
24469JSON_HEDLEY_NON_NULL(1)
24470#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24471 inline nlohmann::json
operator ""_json(
const char* s, std::size_t n)
24473 inline nlohmann::json
operator "" _json(
const char* s, std::size_t n)
24476 return nlohmann::json::parse(s, s + n);
24481JSON_HEDLEY_NON_NULL(1)
24482#if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24483 inline nlohmann::json::json_pointer
operator ""_json_pointer(
const char* s, std::size_t n)
24485 inline nlohmann::json::json_pointer
operator "" _json_pointer(
const char* s, std::size_t n)
24488 return nlohmann::json::json_pointer(std::string(s, n));
24493NLOHMANN_JSON_NAMESPACE_END
24504NLOHMANN_BASIC_JSON_TPL_DECLARATION
24505struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
24507 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
24509 return nlohmann::detail::hash(j);
24515struct less< ::nlohmann::detail::value_t>
24522 ::nlohmann::detail::value_t rhs)
const noexcept
24524#if JSON_HAS_THREE_WAY_COMPARISON
24525 return std::is_lt(lhs <=> rhs);
24527 return ::nlohmann::detail::operator<(lhs, rhs);
24533#ifndef JSON_HAS_CPP_20
24537NLOHMANN_BASIC_JSON_TPL_DECLARATION
24538inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
24539 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
24540 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
24549#if JSON_USE_GLOBAL_UDLS
24550 #if !defined(JSON_HEDLEY_GCC_VERSION) || JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0)
24551 using nlohmann::literals::json_literals::operator
""_json;
24552 using nlohmann::literals::json_literals::operator
""_json_pointer;
24554 using nlohmann::literals::json_literals::operator
"" _json;
24555 using nlohmann::literals::json_literals::operator
"" _json_pointer;
24571#if defined(__clang__)
24572 #pragma clang diagnostic pop
24577#undef JSON_INTERNAL_CATCH
24579#undef JSON_PRIVATE_UNLESS_TESTED
24580#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
24581#undef NLOHMANN_BASIC_JSON_TPL
24582#undef JSON_EXPLICIT
24583#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
24584#undef JSON_INLINE_VARIABLE
24585#undef JSON_NO_UNIQUE_ADDRESS
24586#undef JSON_DISABLE_ENUM_SERIALIZATION
24587#undef JSON_USE_GLOBAL_UDLS
24589#ifndef JSON_TEST_KEEP_MACROS
24592 #undef JSON_HAS_CPP_11
24593 #undef JSON_HAS_CPP_14
24594 #undef JSON_HAS_CPP_17
24595 #undef JSON_HAS_CPP_20
24596 #undef JSON_HAS_FILESYSTEM
24597 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
24598 #undef JSON_HAS_THREE_WAY_COMPARISON
24599 #undef JSON_HAS_RANGES
24600 #undef JSON_HAS_STATIC_RTTI
24601 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
24615#undef JSON_HEDLEY_ALWAYS_INLINE
24616#undef JSON_HEDLEY_ARM_VERSION
24617#undef JSON_HEDLEY_ARM_VERSION_CHECK
24618#undef JSON_HEDLEY_ARRAY_PARAM
24619#undef JSON_HEDLEY_ASSUME
24620#undef JSON_HEDLEY_BEGIN_C_DECLS
24621#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
24622#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
24623#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
24624#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
24625#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
24626#undef JSON_HEDLEY_CLANG_HAS_FEATURE
24627#undef JSON_HEDLEY_CLANG_HAS_WARNING
24628#undef JSON_HEDLEY_COMPCERT_VERSION
24629#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
24630#undef JSON_HEDLEY_CONCAT
24631#undef JSON_HEDLEY_CONCAT3
24632#undef JSON_HEDLEY_CONCAT3_EX
24633#undef JSON_HEDLEY_CONCAT_EX
24634#undef JSON_HEDLEY_CONST
24635#undef JSON_HEDLEY_CONSTEXPR
24636#undef JSON_HEDLEY_CONST_CAST
24637#undef JSON_HEDLEY_CPP_CAST
24638#undef JSON_HEDLEY_CRAY_VERSION
24639#undef JSON_HEDLEY_CRAY_VERSION_CHECK
24640#undef JSON_HEDLEY_C_DECL
24641#undef JSON_HEDLEY_DEPRECATED
24642#undef JSON_HEDLEY_DEPRECATED_FOR
24643#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
24644#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
24645#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
24646#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
24647#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
24648#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
24649#undef JSON_HEDLEY_DIAGNOSTIC_POP
24650#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
24651#undef JSON_HEDLEY_DMC_VERSION
24652#undef JSON_HEDLEY_DMC_VERSION_CHECK
24653#undef JSON_HEDLEY_EMPTY_BASES
24654#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
24655#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
24656#undef JSON_HEDLEY_END_C_DECLS
24657#undef JSON_HEDLEY_FLAGS
24658#undef JSON_HEDLEY_FLAGS_CAST
24659#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
24660#undef JSON_HEDLEY_GCC_HAS_BUILTIN
24661#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
24662#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
24663#undef JSON_HEDLEY_GCC_HAS_EXTENSION
24664#undef JSON_HEDLEY_GCC_HAS_FEATURE
24665#undef JSON_HEDLEY_GCC_HAS_WARNING
24666#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
24667#undef JSON_HEDLEY_GCC_VERSION
24668#undef JSON_HEDLEY_GCC_VERSION_CHECK
24669#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
24670#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
24671#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
24672#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
24673#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
24674#undef JSON_HEDLEY_GNUC_HAS_FEATURE
24675#undef JSON_HEDLEY_GNUC_HAS_WARNING
24676#undef JSON_HEDLEY_GNUC_VERSION
24677#undef JSON_HEDLEY_GNUC_VERSION_CHECK
24678#undef JSON_HEDLEY_HAS_ATTRIBUTE
24679#undef JSON_HEDLEY_HAS_BUILTIN
24680#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
24681#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
24682#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
24683#undef JSON_HEDLEY_HAS_EXTENSION
24684#undef JSON_HEDLEY_HAS_FEATURE
24685#undef JSON_HEDLEY_HAS_WARNING
24686#undef JSON_HEDLEY_IAR_VERSION
24687#undef JSON_HEDLEY_IAR_VERSION_CHECK
24688#undef JSON_HEDLEY_IBM_VERSION
24689#undef JSON_HEDLEY_IBM_VERSION_CHECK
24690#undef JSON_HEDLEY_IMPORT
24691#undef JSON_HEDLEY_INLINE
24692#undef JSON_HEDLEY_INTEL_CL_VERSION
24693#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
24694#undef JSON_HEDLEY_INTEL_VERSION
24695#undef JSON_HEDLEY_INTEL_VERSION_CHECK
24696#undef JSON_HEDLEY_IS_CONSTANT
24697#undef JSON_HEDLEY_IS_CONSTEXPR_
24698#undef JSON_HEDLEY_LIKELY
24699#undef JSON_HEDLEY_MALLOC
24700#undef JSON_HEDLEY_MCST_LCC_VERSION
24701#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
24702#undef JSON_HEDLEY_MESSAGE
24703#undef JSON_HEDLEY_MSVC_VERSION
24704#undef JSON_HEDLEY_MSVC_VERSION_CHECK
24705#undef JSON_HEDLEY_NEVER_INLINE
24706#undef JSON_HEDLEY_NON_NULL
24707#undef JSON_HEDLEY_NO_ESCAPE
24708#undef JSON_HEDLEY_NO_RETURN
24709#undef JSON_HEDLEY_NO_THROW
24710#undef JSON_HEDLEY_NULL
24711#undef JSON_HEDLEY_PELLES_VERSION
24712#undef JSON_HEDLEY_PELLES_VERSION_CHECK
24713#undef JSON_HEDLEY_PGI_VERSION
24714#undef JSON_HEDLEY_PGI_VERSION_CHECK
24715#undef JSON_HEDLEY_PREDICT
24716#undef JSON_HEDLEY_PRINTF_FORMAT
24717#undef JSON_HEDLEY_PRIVATE
24718#undef JSON_HEDLEY_PUBLIC
24719#undef JSON_HEDLEY_PURE
24720#undef JSON_HEDLEY_REINTERPRET_CAST
24721#undef JSON_HEDLEY_REQUIRE
24722#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
24723#undef JSON_HEDLEY_REQUIRE_MSG
24724#undef JSON_HEDLEY_RESTRICT
24725#undef JSON_HEDLEY_RETURNS_NON_NULL
24726#undef JSON_HEDLEY_SENTINEL
24727#undef JSON_HEDLEY_STATIC_ASSERT
24728#undef JSON_HEDLEY_STATIC_CAST
24729#undef JSON_HEDLEY_STRINGIFY
24730#undef JSON_HEDLEY_STRINGIFY_EX
24731#undef JSON_HEDLEY_SUNPRO_VERSION
24732#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
24733#undef JSON_HEDLEY_TINYC_VERSION
24734#undef JSON_HEDLEY_TINYC_VERSION_CHECK
24735#undef JSON_HEDLEY_TI_ARMCL_VERSION
24736#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
24737#undef JSON_HEDLEY_TI_CL2000_VERSION
24738#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
24739#undef JSON_HEDLEY_TI_CL430_VERSION
24740#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
24741#undef JSON_HEDLEY_TI_CL6X_VERSION
24742#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
24743#undef JSON_HEDLEY_TI_CL7X_VERSION
24744#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
24745#undef JSON_HEDLEY_TI_CLPRU_VERSION
24746#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
24747#undef JSON_HEDLEY_TI_VERSION
24748#undef JSON_HEDLEY_TI_VERSION_CHECK
24749#undef JSON_HEDLEY_UNAVAILABLE
24750#undef JSON_HEDLEY_UNLIKELY
24751#undef JSON_HEDLEY_UNPREDICTABLE
24752#undef JSON_HEDLEY_UNREACHABLE
24753#undef JSON_HEDLEY_UNREACHABLE_RETURN
24754#undef JSON_HEDLEY_VERSION
24755#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
24756#undef JSON_HEDLEY_VERSION_DECODE_MINOR
24757#undef JSON_HEDLEY_VERSION_DECODE_REVISION
24758#undef JSON_HEDLEY_VERSION_ENCODE
24759#undef JSON_HEDLEY_WARNING
24760#undef JSON_HEDLEY_WARN_UNUSED_RESULT
24761#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
24762#undef JSON_HEDLEY_FALL_THROUGH
namespace for Niels Lohmann
Definition json.hpp:20114
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.h:20674
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.h:21907
std::size_t size_type
a type to represent container sizes
Definition json.h:19520
reference operator[](KeyType &&key)
access specified object element
Definition json.h:21475
size_type size() const noexcept
returns the number of elements
Definition json.h:22248
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.h:23681
BooleanType boolean_t
a type for a boolean
Definition json.h:19652
static std::vector< std::uint8_t > to_bjdata(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:23613
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
Definition json.h:21047
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.h:22105
reference back()
access the last element
Definition json.h:21711
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value from compatible types
Definition json.h:20138
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.h:22121
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.h:24273
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.h:23461
const_reference front() const
access the first element
Definition json.h:21704
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.h:20667
void swap(reference other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.h:22765
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:21655
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.h:22024
static void to_bjdata(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:23632
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.h:20639
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
Definition json.h:23876
static void to_bjdata(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a BJData serialization of a given JSON value
Definition json.h:23624
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.h:23921
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.h:20611
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.h:21499
void swap(binary_t &other)
exchanges the values
Definition json.h:22842
ReferenceType get_ref()
get a reference value (implicit)
Definition json.h:21137
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.h:22287
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.h:22711
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.h:21148
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.h:20688
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.h:22503
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.h:19523
void push_back(basic_json &&val)
add an object to an array
Definition json.h:22391
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.h:21444
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.h:22193
const_reference back() const
access the last element
Definition json.h:21720
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.h:21802
reference operator+=(const basic_json &val)
add an object to an array
Definition json.h:22448
friend void swap(reference left, reference right) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&//NOLINT(cppcoreguidelines-noexcept-swap, performance-noexcept-swap) std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.h:22782
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.h:23777
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.h:20275
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.h:22615
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BSON format
Definition json.h:23861
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.h:19543
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.h:21307
iterator end() noexcept
returns an iterator to one past the last element
Definition json.h:22096
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.h:20646
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.h:22718
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.h:23640
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.h:22128
void push_back(initializer_list_t init)
add an object to an object
Definition json.h:22487
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.h:20316
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.h:23579
iterator begin() noexcept
returns an iterator to the first element
Definition json.h:22071
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.h:21554
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.h:22112
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
Definition json.h:23831
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.h:23963
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.h:20286
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.h:20126
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition json.h:23665
basic_json flatten() const
return flattened JSON value
Definition json.h:23977
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_ubjson(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in UBJSON format
Definition json.h:23792
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.h:21918
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.h:19644
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.h:19636
const binary_t & get_binary() const
get a binary value
Definition json.h:21219
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.h:22635
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.h:24002
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:21607
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
Definition json.h:24283
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.h:23935
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.h:19477
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.h:19535
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.h:22041
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
Definition json.h:19672
static void to_cbor(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a CBOR serialization of a given JSON value
Definition json.h:23549
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.h:23656
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.h:21954
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition json.h:19469
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
Definition json.h:20264
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.h:21345
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.h:19551
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.h:20323
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.h:21968
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.h:23540
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.h:21732
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.h:19528
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.h:22588
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.h:21529
string_t dump(const int indent=-1, const char indent_char=' ', const bool ensure_ascii=false, const error_handler_t error_handler=error_handler_t::strict) const
serialization
Definition json.h:20575
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.h:24425
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
Definition json.h:21101
reference at(size_type idx)
access specified array element with bounds checking
Definition json.h:21241
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.h:21984
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.h:20653
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.h:22135
static std::vector< std::uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:23586
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.h:23949
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.h:22479
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.h:22087
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.h:21422
std::less< StringType > default_object_comparator_t
default object key comparator type The actual object key comparator type (object_comparator_t) may be...
Definition json.h:19631
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.h:20859
~basic_json() noexcept
destructor
Definition json.h:20557
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.h:19526
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.h:22156
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.h:19660
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
Definition json.h:20205
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.h:22858
binary_t & get_binary()
get a binary value
Definition json.h:21207
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.h:19533
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.h:22080
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.h:20632
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.h:22686
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.h:23723
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.h:21088
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.h:19656
reference operator[](size_type idx)
access specified array element
Definition json.h:21363
basic_json & operator=(basic_json other) noexcept(std::is_nothrow_move_constructible< value_t >::value &&std::is_nothrow_move_assignable< value_t >::value &&std::is_nothrow_move_constructible< json_value >::value &&std::is_nothrow_move_assignable< json_value >::value &&std::is_nothrow_move_assignable< json_base_class_t >::value)
copy assignment
Definition json.h:20534
static void to_ubjson(const basic_json &j, detail::output_adapter< char > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:23605
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.h:20848
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.h:21325
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.h:20681
void swap(object_t &other)
exchanges the values
Definition json.h:22810
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.h:19668
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.h:23986
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.h:22666
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.h:19537
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init, typename binary_t::subtype_type subtype)
explicitly create a binary array (with subtype)
Definition json.h:20297
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.h:22186
bool empty() const noexcept
checks whether the container is empty.
Definition json.h:22209
void swap(array_t &other)
exchanges the values
Definition json.h:22794
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.h:21925
StringType string_t
a type for a string
Definition json.h:19648
reference operator+=(basic_json &&val)
add an object to an array
Definition json.h:22416
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.h:22048
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.h:20597
reference emplace_back(Args &&... args)
add an object to an array
Definition json.h:22512
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.h:21630
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.h:20308
void push_back(const basic_json &val)
add an object to an array
Definition json.h:22424
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.h:21580
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.h:21287
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bjdata(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in BJData format
Definition json.h:23846
json_value m_value
the value of the current element
Definition json.h:23498
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.h:22149
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.h:20625
size_type count(const typename object_t::key_type &key) const
returns the number of occurrences of a key in a JSON object
Definition json.h:22014
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.h:19531
reference front()
access the first element
Definition json.h:21697
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.h:20604
constexpr bool is_null() const noexcept
return whether value is null
Definition json.h:20618
void clear() noexcept
clears the contents
Definition json.h:22330
static void to_ubjson(const basic_json &j, detail::output_adapter< std::uint8_t > o, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
Definition json.h:23597
basic_json(basic_json &&other) noexcept
move constructor
Definition json.h:20517
basic_json(const value_t v)
create an empty value with a given type
Definition json.h:20118
const_reference operator[](size_type idx) const
access specified array element
Definition json.h:21409
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition json.h:20105
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.h:22608
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.h:22142
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.h:23446
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.h:23563
void swap(string_t &other)
exchanges the values
Definition json.h:22826
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.h:20152
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.h:21264
basic_json(const basic_json &other)
copy constructor
Definition json.h:20448
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.h:22456
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.h:22537
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.h:19518
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.h:19664
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.h:23556
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.h:20660
static void to_msgpack(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a MessagePack serialization of a given JSON value
Definition json.h:23572
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(IteratorType first, IteratorType last, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition json.h:23738
iterator insert_iterator(const_iterator pos, Args &&... args)
Definition json.h:22569
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.h:20335
value_type & reference
the type of an element reference
Definition json.h:19513
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.h:22032
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
create a BSON serialization of a given JSON value
Definition json.h:23649
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.h:22000
an internal type for a backed binary type
Definition json.h:5892
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.h:5898
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.h:5920
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.h:5908
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.h:5947
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.h:5913
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.h:5954
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.h:5903
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.h:5939
void clear_subtype() noexcept
clears the binary subtype
Definition json.h:5961
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9846
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.h:9229
bool sax_parse(const input_format_t format, json_sax_t *sax_, const bool strict=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
Definition json.h:9250
serialization to CBOR and MessagePack values
Definition json.hpp:15787
void write_bson(const BasicJsonType &j)
Definition json.h:15100
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
Definition json.h:15091
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true, const bool use_bjdata=false)
Definition json.h:15779
void write_msgpack(const BasicJsonType &j)
Definition json.h:15453
void write_cbor(const BasicJsonType &j)
Definition json.h:15129
general exception of the basic_json class
Definition json.hpp:4511
const int id
the id of the exception
Definition json.h:4381
const char * what() const noexcept override
returns the explanatory string
Definition json.h:4375
exception indicating errors with iterators
Definition json.hpp:4680
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:13606
iter_impl operator+(difference_type i) const
add to iterator
Definition json.h:13491
std::bidirectional_iterator_tag iterator_category
Definition json.h:12942
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference >::type reference
defines a reference to the type iterated over (value_type)
Definition json.h:12953
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.h:13054
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.h:13436
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.h:13044
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.h:12945
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.h:13383
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.h:13418
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.h:13482
iter_impl & operator--()
pre-decrement (–it)
Definition json.h:13297
const object_t::key_type & key() const
return the key of an object iterator
Definition json.h:13591
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.h:13338
iter_impl operator++(int) &
post-increment (it++)
Definition json.h:13235
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.h:13445
reference operator[](difference_type n) const
access to successor
Definition json.h:13553
pointer operator->() const
dereference the iterator
Definition json.h:13193
difference_type operator-(const iter_impl &other) const
return difference
Definition json.h:13524
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.h:13502
reference value() const
return the value of an iterator
Definition json.h:13607
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.h:13427
iter_impl & operator++()
pre-increment (++it)
Definition json.h:13246
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.h:13149
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.h:13513
typename std::conditional< std::is_const< BasicJsonType >::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer >::type pointer
defines a pointer to the type iterated over (value_type)
Definition json.h:12949
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.h:13029
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.h:13374
iter_impl operator--(int) &
post-decrement (it–)
Definition json.h:13286
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.h:12947
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.h:13019
void set_end() noexcept
set the iterator past the last value
Definition json.h:13110
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition json.h:13616
Definition json.hpp:13586
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.h:5251
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.h:5257
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.h:5234
IteratorType::reference value() const
return value of the iterator
Definition json.h:5299
const string_type & key() const
return key of the iterator
Definition json.h:5263
proxy class for the items() function
Definition json.hpp:13585
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.h:5332
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.h:5316
Definition json.hpp:15519
a template for a reverse iterator class
Definition json.hpp:14368
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.h:13686
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.h:13698
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.h:13674
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.h:13692
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.h:13710
reference operator[](difference_type n) const
access to successor
Definition json.h:13734
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.h:13740
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.h:13728
reference value() const
return the value of an iterator
Definition json.h:13747
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.h:13683
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.h:13704
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.h:13722
typename Base::reference reference
the reference type for the pointed-to element
Definition json.h:13676
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.h:13679
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.h:13716
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:8818
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition json.h:6814
JSON_HEDLEY_RETURNS_NON_NULL static JSON_HEDLEY_CONST const char * token_type_name(const token_type t) noexcept
return name of values of type token_type (only used for errors)
Definition json.h:7435
token_type
token types for the parser
Definition json.h:7412
@ parse_error
indicating a parse error
lexical analysis
Definition json.hpp:7135
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.h:8859
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.h:8846
std::string get_token_string() const
Definition json.h:8821
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.h:8785
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.h:8813
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.h:8791
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.h:8803
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.h:8797
exception indicating other library errors
Definition json.hpp:4732
exception indicating access out of the defined range
Definition json.hpp:4715
Definition json.hpp:15738
output adapter for byte vectors
Definition json.hpp:15665
exception indicating a parse error
Definition json.hpp:4627
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition json.h:4482
const std::size_t byte
byte index of the parse error
Definition json.h:4507
parser(InputAdapterType &&adapter, const parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
Definition json.h:12240
void parse(const bool strict, BasicJsonType &result)
public parser interface
Definition json.h:12262
bool accept(const bool strict=true)
public accept interface
Definition json.h:12322
Definition json.hpp:13423
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
Definition json.h:12763
void set_end() noexcept
set iterator to a defined past the end
Definition json.h:12757
constexpr bool is_end() const noexcept
return whether the iterator is at end
Definition json.h:12769
void set_begin() noexcept
set iterator to a defined beginning
Definition json.h:12751
Definition json.hpp:18773
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.h:18076
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition json.h:18975
const char thousands_sep
the locale's thousand separator character
Definition json.h:18980
const char decimal_point
the locale's decimal point character
Definition json.h:18982
const std::lconv * loc
the locale
Definition json.h:18978
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.h:18993
string_t indent_string
the indentation string
Definition json.h:18990
std::array< char, 512 > string_buffer
string buffer
Definition json.h:18985
const char indent_char
the indentation character
Definition json.h:18988
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition json.h:18116
exception indicating executing a member function with a wrong type
Definition json.hpp:4698
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:14540
friend json_pointer operator/(const json_pointer &lhs, string_t token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
Definition json.h:13937
friend json_pointer operator/(const json_pointer &lhs, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
Definition json.h:13944
friend bool operator==(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for equality
Definition json.h:14737
json_pointer(const string_t &s="")
create JSON pointer
Definition json.h:13868
bool empty() const noexcept
return whether pointer points to the root document
Definition json.h:14003
void pop_back()
remove last reference token
Definition json.h:13965
string_t to_string() const
return a string representation of the JSON pointer
Definition json.h:13874
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.h:13922
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.h:13996
friend bool operator<(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointer for less-than
Definition json.h:14787
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.h:13904
friend json_pointer operator/(const json_pointer &lhs, const json_pointer &rhs)
create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer
Definition json.h:13929
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.h:13951
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.h:13914
const string_t & back() const
return last reference token
Definition json.h:13977
friend bool operator!=(const json_pointer< RefStringTypeLhs > &lhs, const json_pointer< RefStringTypeRhs > &rhs) noexcept
compares two JSON pointers for inequality
Definition json.h:14762
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.h:13895
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.h:13989
GLM_FUNC_QUALIFIER mat< C, R, T, Q > inverse(mat< C, R, T, Q > const &m)
Definition func_matrix.inl:388
GLM_FUNC_DECL GLM_CONSTEXPR genType e()
Definition constants.inl:102
uint64 uint64_t
Definition fwd.hpp:143
int64 int64_t
Definition fwd.hpp:85
uint32 uint32_t
Definition fwd.hpp:129
uint16 uint16_t
Definition fwd.hpp:115
detail::uint8 byte
Definition raw_data.hpp:34
GLM_FUNC_DECL std::string to_string(genType const &x)
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
Definition json.h:17400
cached_power get_cached_power_for_binary_exponent(int e)
Definition json.h:17236
boundaries compute_boundaries(FloatType value)
Definition json.h:17097
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
Definition json.h:17736
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
Definition json.h:17495
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
Definition json.h:17836
JSON_HEDLEY_RETURNS_NON_NULL char * format_buffer(char *buf, int len, int decimal_exponent, int min_exp, int max_exp)
prettify v = buf * 10^decimal_exponent
Definition json.h:17888
detail namespace with internal helper functions
Definition json.h:249
input_format_t
the supported input formats
Definition json.h:6177
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition json.h:17973
parse_event_t
Definition json.h:12204
@ value
the parser finished reading a JSON value
@ key
the parser read a key of a value in an object
@ array_end
the parser read ] and finished processing a JSON array
@ array_start
the parser read [ and started to process a JSON array
@ object_start
the parser read { and started to process a JSON object
@ object_end
the parser read } and finished processing a JSON object
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
Definition json.h:14960
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.h:2971
cbor_tag_handler_t
how to treat CBOR tags
Definition json.h:9186
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
value_t
the JSON type enumeration
Definition json.h:2873
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition json.h:6023
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.h:2902
error_handler_t
how to treat decoding errors
Definition json.h:18053
@ strict
throw a type_error exception in case of invalid UTF-8
@ ignore
ignore invalid UTF-8 sequences
@ replace
replace invalid UTF-8 sequences with U+FFFD
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.h:2990
namespace for Niels Lohmann
Definition json.hpp:6136
static auto to_json(BasicJsonType &j, TargetType &&val) noexcept(noexcept(::nlohmann::to_json(j, std::forward< TargetType >(val)))) -> decltype(::nlohmann::to_json(j, std::forward< TargetType >(val)), void())
convert any value type to a JSON value
Definition json.h:5858
static auto from_json(BasicJsonType &&j) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), detail::identity_tag< TargetType > {}))
convert a JSON value to any value type
Definition json.h:5848
static auto from_json(BasicJsonType &&j, TargetType &val) noexcept(noexcept(::nlohmann::from_json(std::forward< BasicJsonType >(j), val))) -> decltype(::nlohmann::from_json(std::forward< BasicJsonType >(j), val), void())
convert a JSON value to any value type
Definition json.h:5838
Definition json.hpp:17796
Definition json.hpp:17935
Definition json.hpp:17678
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
Definition json.h:16990
static diyfp normalize_to(const diyfp &x, const int target_exponent) noexcept
normalize x such that the result has the exponent E
Definition json.h:17072
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
Definition json.h:17055
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
Definition json.h:16978
an iterator value
Definition json.hpp:13539
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.h:12854
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.h:12856
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
Definition json.h:12852
abstract output adapter interface
Definition json.hpp:15646
struct to capture the start position of the current token
Definition json.hpp:3163
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.h:3040
std::size_t lines_read
the number of lines read
Definition json.h:3042
std::size_t chars_read_total
the total number of characters read
Definition json.h:3038
SAX interface.
Definition json.h:6671
virtual bool binary(binary_t &val)=0
a binary value was read
virtual bool number_float(number_float_t val, const string_t &s)=0
a floating-point number was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
virtual bool key(string_t &val)=0
an object key was read
virtual bool string(string_t &val)=0
a string value was read
virtual bool number_integer(number_integer_t val)=0
an integer number was read
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool end_array()=0
the end of an array was read
virtual bool boolean(bool val)=0
a boolean value was read
virtual bool end_object()=0
the end of an object was read
virtual bool null()=0
a null value was read
virtual bool parse_error(std::size_t position, const std::string &last_token, const detail::exception &ex)=0
a parse error occurred
virtual bool start_array(std::size_t elements)=0
the beginning of an array was read
a minimal map-like container that preserves insertion order
Definition json.hpp:19747
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.h:24521