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 != 2
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 2
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
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>
296template<
template<
class...>
class Op,
class... Args>
299template<
template<
class...>
class Op,
class... Args>
302template<
class Default,
template<
class...>
class Op,
class... 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#ifdef JSON_HAS_CPP_17
2489 #define JSON_INLINE_VARIABLE inline
2491 #define JSON_INLINE_VARIABLE
2494#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address)
2495 #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]]
2497 #define JSON_NO_UNIQUE_ADDRESS
2501#if defined(__clang__)
2502 #pragma clang diagnostic push
2503 #pragma clang diagnostic ignored "-Wdocumentation"
2504 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2508#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2509 #define JSON_THROW(exception) throw exception
2510 #define JSON_TRY try
2511 #define JSON_CATCH(exception) catch(exception)
2512 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2515 #define JSON_THROW(exception) std::abort()
2516 #define JSON_TRY if(true)
2517 #define JSON_CATCH(exception) if(false)
2518 #define JSON_INTERNAL_CATCH(exception) if(false)
2522#if defined(JSON_THROW_USER)
2524 #define JSON_THROW JSON_THROW_USER
2526#if defined(JSON_TRY_USER)
2528 #define JSON_TRY JSON_TRY_USER
2530#if defined(JSON_CATCH_USER)
2532 #define JSON_CATCH JSON_CATCH_USER
2533 #undef JSON_INTERNAL_CATCH
2534 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2536#if defined(JSON_INTERNAL_CATCH_USER)
2537 #undef JSON_INTERNAL_CATCH
2538 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2542#if !defined(JSON_ASSERT)
2544 #define JSON_ASSERT(x) assert(x)
2548#if defined(JSON_TESTS_PRIVATE)
2549 #define JSON_PRIVATE_UNLESS_TESTED public
2551 #define JSON_PRIVATE_UNLESS_TESTED private
2559#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2560 template<typename BasicJsonType> \
2561 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2563 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2564 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2565 auto it = std::find_if(std::begin(m), std::end(m), \
2566 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2568 return ej_pair.first == e; \
2570 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2572 template<typename BasicJsonType> \
2573 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2575 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2576 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2577 auto it = std::find_if(std::begin(m), std::end(m), \
2578 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2580 return ej_pair.second == j; \
2582 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2588#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2589 template<template<typename, typename, typename...> class ObjectType, \
2590 template<typename, typename...> class ArrayType, \
2591 class StringType, class BooleanType, class NumberIntegerType, \
2592 class NumberUnsignedType, class NumberFloatType, \
2593 template<typename> class AllocatorType, \
2594 template<typename, typename = void> class JSONSerializer, \
2596 class CustomBaseClass>
2598#define NLOHMANN_BASIC_JSON_TPL \
2599 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2600 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2601 AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>
2605#define NLOHMANN_JSON_EXPAND( x ) x
2606#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
2607#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2608 NLOHMANN_JSON_PASTE64, \
2609 NLOHMANN_JSON_PASTE63, \
2610 NLOHMANN_JSON_PASTE62, \
2611 NLOHMANN_JSON_PASTE61, \
2612 NLOHMANN_JSON_PASTE60, \
2613 NLOHMANN_JSON_PASTE59, \
2614 NLOHMANN_JSON_PASTE58, \
2615 NLOHMANN_JSON_PASTE57, \
2616 NLOHMANN_JSON_PASTE56, \
2617 NLOHMANN_JSON_PASTE55, \
2618 NLOHMANN_JSON_PASTE54, \
2619 NLOHMANN_JSON_PASTE53, \
2620 NLOHMANN_JSON_PASTE52, \
2621 NLOHMANN_JSON_PASTE51, \
2622 NLOHMANN_JSON_PASTE50, \
2623 NLOHMANN_JSON_PASTE49, \
2624 NLOHMANN_JSON_PASTE48, \
2625 NLOHMANN_JSON_PASTE47, \
2626 NLOHMANN_JSON_PASTE46, \
2627 NLOHMANN_JSON_PASTE45, \
2628 NLOHMANN_JSON_PASTE44, \
2629 NLOHMANN_JSON_PASTE43, \
2630 NLOHMANN_JSON_PASTE42, \
2631 NLOHMANN_JSON_PASTE41, \
2632 NLOHMANN_JSON_PASTE40, \
2633 NLOHMANN_JSON_PASTE39, \
2634 NLOHMANN_JSON_PASTE38, \
2635 NLOHMANN_JSON_PASTE37, \
2636 NLOHMANN_JSON_PASTE36, \
2637 NLOHMANN_JSON_PASTE35, \
2638 NLOHMANN_JSON_PASTE34, \
2639 NLOHMANN_JSON_PASTE33, \
2640 NLOHMANN_JSON_PASTE32, \
2641 NLOHMANN_JSON_PASTE31, \
2642 NLOHMANN_JSON_PASTE30, \
2643 NLOHMANN_JSON_PASTE29, \
2644 NLOHMANN_JSON_PASTE28, \
2645 NLOHMANN_JSON_PASTE27, \
2646 NLOHMANN_JSON_PASTE26, \
2647 NLOHMANN_JSON_PASTE25, \
2648 NLOHMANN_JSON_PASTE24, \
2649 NLOHMANN_JSON_PASTE23, \
2650 NLOHMANN_JSON_PASTE22, \
2651 NLOHMANN_JSON_PASTE21, \
2652 NLOHMANN_JSON_PASTE20, \
2653 NLOHMANN_JSON_PASTE19, \
2654 NLOHMANN_JSON_PASTE18, \
2655 NLOHMANN_JSON_PASTE17, \
2656 NLOHMANN_JSON_PASTE16, \
2657 NLOHMANN_JSON_PASTE15, \
2658 NLOHMANN_JSON_PASTE14, \
2659 NLOHMANN_JSON_PASTE13, \
2660 NLOHMANN_JSON_PASTE12, \
2661 NLOHMANN_JSON_PASTE11, \
2662 NLOHMANN_JSON_PASTE10, \
2663 NLOHMANN_JSON_PASTE9, \
2664 NLOHMANN_JSON_PASTE8, \
2665 NLOHMANN_JSON_PASTE7, \
2666 NLOHMANN_JSON_PASTE6, \
2667 NLOHMANN_JSON_PASTE5, \
2668 NLOHMANN_JSON_PASTE4, \
2669 NLOHMANN_JSON_PASTE3, \
2670 NLOHMANN_JSON_PASTE2, \
2671 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2672#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2673#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2674#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2675#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2676#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2677#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)
2678#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)
2679#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)
2680#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)
2681#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)
2682#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)
2683#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)
2684#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)
2685#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)
2686#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)
2687#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)
2688#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)
2689#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)
2690#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)
2691#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)
2692#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)
2693#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)
2694#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)
2695#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)
2696#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)
2697#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)
2698#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)
2699#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)
2700#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)
2701#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)
2702#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)
2703#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)
2704#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)
2705#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)
2706#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)
2707#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)
2708#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)
2709#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)
2710#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)
2711#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)
2712#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)
2713#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)
2714#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)
2715#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)
2716#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)
2717#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)
2718#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)
2719#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)
2720#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)
2721#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)
2722#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)
2723#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)
2724#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)
2725#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)
2726#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)
2727#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)
2728#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)
2729#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)
2730#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)
2731#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)
2732#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)
2733#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)
2734#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)
2736#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2737#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2738#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1);
2745#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2746 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__)) } \
2747 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__)) }
2749#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2750 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__)) } \
2751 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__)) }
2758#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2759 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__)) } \
2760 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__)) }
2762#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
2763 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__)) } \
2764 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__)) }
2773#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2774 namespace detail { \
2775 using std::std_name; \
2777 template<typename... T> \
2778 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2781 namespace detail2 { \
2782 struct std_name##_tag \
2786 template<typename... T> \
2787 std_name##_tag std_name(T&&...); \
2789 template<typename... T> \
2790 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2792 template<typename... T> \
2793 struct would_call_std_##std_name \
2795 static constexpr auto const value = ::nlohmann::detail:: \
2796 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2800 template<typename... T> \
2801 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2805#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2806 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2809#if JSON_USE_IMPLICIT_CONVERSIONS
2810 #define JSON_EXPLICIT
2812 #define JSON_EXPLICIT explicit
2815#ifndef JSON_DISABLE_ENUM_SERIALIZATION
2816 #define JSON_DISABLE_ENUM_SERIALIZATION 0
2819#ifndef JSON_USE_GLOBAL_UDLS
2820 #define JSON_USE_GLOBAL_UDLS 1
2823#if JSON_HAS_THREE_WAY_COMPARISON
2827NLOHMANN_JSON_NAMESPACE_BEGIN
2886#if JSON_HAS_THREE_WAY_COMPARISON
2887 inline std::partial_ordering operator<=>(
const value_t lhs,
const value_t rhs)
noexcept
2892 static constexpr std::array<std::uint8_t, 9> order = {{
2899 const auto l_index =
static_cast<std::size_t
>(lhs);
2900 const auto r_index =
static_cast<std::size_t
>(rhs);
2901#if JSON_HAS_THREE_WAY_COMPARISON
2902 if (l_index < order.size() && r_index < order.size())
2904 return order[l_index] <=> order[r_index];
2906 return std::partial_ordering::unordered;
2908 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
2916#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__)
2919 return std::is_lt(lhs <=> rhs);
2924NLOHMANN_JSON_NAMESPACE_END
2940NLOHMANN_JSON_NAMESPACE_BEGIN
2957template<
typename StringType>
2959 const StringType& t)
2961 JSON_ASSERT(!f.empty());
2962 for (
auto pos = s.find(f);
2963 pos != StringType::npos;
2964 s.replace(pos, f.size(), t),
2965 pos = s.find(f, pos + t.size()))
2976template<
typename StringType>
2991template<
typename StringType>
2992static void unescape(StringType& s)
2999NLOHMANN_JSON_NAMESPACE_END
3017NLOHMANN_JSON_NAMESPACE_BEGIN
3032 constexpr operator size_t()
const
3039NLOHMANN_JSON_NAMESPACE_END
3057#include <type_traits>
3063NLOHMANN_JSON_NAMESPACE_BEGIN
3068using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3070#ifdef JSON_HAS_CPP_14
3073using std::enable_if_t;
3074using std::index_sequence;
3075using std::make_index_sequence;
3076using std::index_sequence_for;
3081template<
bool B,
typename T =
void>
3082using enable_if_t =
typename std::enable_if<B, T>::type;
3108template <
typename T, T... Ints>
3111 using value_type = T;
3112 static constexpr std::size_t size()
noexcept
3114 return sizeof...(Ints);
3123template <
size_t... Ints>
3126namespace utility_internal
3129template <
typename Seq,
size_t SeqSize,
size_t Rem>
3133template <
typename T, T... Ints,
size_t SeqSize>
3139template <
typename T, T... Ints,
size_t SeqSize>
3147template <
typename T,
size_t N>
3151 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3154template <
typename T>
3169template <
typename T, T N>
3170using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3178using make_index_sequence = make_integer_sequence<size_t, N>;
3185template <
typename... Ts>
3186using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3200 static JSON_INLINE_VARIABLE
constexpr T value{};
3203#ifndef JSON_HAS_CPP_17
3204 template<
typename T>
3208template<
typename T,
typename... Args>
3209inline constexpr std::array<T,
sizeof...(Args)> make_array(Args&& ... args)
3211 return std::array<T,
sizeof...(Args)> {{
static_cast<T
>(std::forward<Args>(args))...}};
3215NLOHMANN_JSON_NAMESPACE_END
3229#include <type_traits>
3253NLOHMANN_JSON_NAMESPACE_BEGIN
3257template<
typename It,
typename =
void>
3260template<
typename It>
3263 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3264 typename It::reference, typename It::iterator_category >>
3266 using difference_type =
typename It::difference_type;
3267 using value_type =
typename It::value_type;
3268 using pointer =
typename It::pointer;
3269 using reference =
typename It::reference;
3270 using iterator_category =
typename It::iterator_category;
3275template<
typename T,
typename =
void>
3289 using iterator_category = std::random_access_iterator_tag;
3290 using value_type = T;
3291 using difference_type = ptrdiff_t;
3293 using reference = T&;
3297NLOHMANN_JSON_NAMESPACE_END
3315NLOHMANN_JSON_NAMESPACE_BEGIN
3317NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin);
3319NLOHMANN_JSON_NAMESPACE_END
3335NLOHMANN_JSON_NAMESPACE_BEGIN
3337NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end);
3339NLOHMANN_JSON_NAMESPACE_END
3354#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3355 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3371 NLOHMANN_JSON_NAMESPACE_BEGIN
3380 template<
typename T =
void,
typename SFINAE =
void>
3385 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3387 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3388 class StringType = std::string,
class BooleanType = bool,
3389 class NumberIntegerType = std::int64_t,
3390 class NumberUnsignedType = std::uint64_t,
3391 class NumberFloatType = double,
3392 template<
typename U>
class AllocatorType = std::allocator,
3393 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3395 class BinaryType = std::vector<std::uint8_t>,
3396 class CustomBaseClass =
void>
3401 template<
typename RefStringType>
3412 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3419 NLOHMANN_JSON_NAMESPACE_END
3424NLOHMANN_JSON_NAMESPACE_BEGIN
3451NLOHMANN_BASIC_JSON_TPL_DECLARATION
3457template<
typename BasicJsonContext>
3459 std::integral_constant < bool,
3460 is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
3461 || std::is_same<BasicJsonContext, std::nullptr_t>::value >
3482using mapped_type_t =
typename T::mapped_type;
3485using key_type_t =
typename T::key_type;
3488using value_type_t =
typename T::value_type;
3491using difference_type_t =
typename T::difference_type;
3494using pointer_t =
typename T::pointer;
3497using reference_t =
typename T::reference;
3500using iterator_category_t =
typename T::iterator_category;
3502template<
typename T,
typename... Args>
3503using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3505template<
typename T,
typename... Args>
3506using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3508template<
typename T,
typename U>
3509using get_template_function =
decltype(std::declval<T>().template get<U>());
3512template<
typename BasicJsonType,
typename T,
typename =
void>
3519template <
typename BasicJsonType,
typename T>
3522 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3525template<
typename BasicJsonType,
typename T>
3528 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3530 static constexpr bool value =
3531 is_detected_exact<void, from_json_function, serializer,
3532 const BasicJsonType&, T&>::value;
3537template<
typename BasicJsonType,
typename T,
typename =
void>
3540template<
typename BasicJsonType,
typename T>
3543 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3545 static constexpr bool value =
3546 is_detected_exact<T, from_json_function, serializer,
3547 const BasicJsonType&>::value;
3552template<
typename BasicJsonType,
typename T,
typename =
void>
3555template<
typename BasicJsonType,
typename T>
3558 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3560 static constexpr bool value =
3561 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3566using detect_key_compare =
typename T::key_compare;
3569struct has_key_compare : std::integral_constant<bool, is_detected<detect_key_compare, T>::value> {};
3572template<
typename BasicJsonType>
3575 using object_t =
typename BasicJsonType::object_t;
3576 using object_comparator_t =
typename BasicJsonType::default_object_comparator_t;
3577 using type =
typename std::conditional < has_key_compare<object_t>::value,
3578 typename object_t::key_compare, object_comparator_t>::type;
3581template<
typename BasicJsonType>
3582using actual_object_comparator_t =
typename actual_object_comparator<BasicJsonType>::type;
3591template<
class B,
class... Bn>
3593: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
3596template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3601template <
typename T>
3604template <
typename T1,
typename T2>
3606 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3608template <
typename T1,
typename T2>
3610 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3612template <
typename... Ts>
3614 :
conjunction<is_default_constructible<Ts>...> {};
3616template <
typename... Ts>
3618 :
conjunction<is_default_constructible<Ts>...> {};
3621template <
typename T,
typename... Args>
3624template <
typename T1,
typename T2>
3627template <
typename T1,
typename T2>
3630template <
typename... Ts>
3633template <
typename... Ts>
3637template<
typename T,
typename =
void>
3647 static constexpr auto value =
3648 is_detected<value_type_t, traits>::value &&
3649 is_detected<difference_type_t, traits>::value &&
3650 is_detected<pointer_t, traits>::value &&
3651 is_detected<iterator_category_t, traits>::value &&
3652 is_detected<reference_t, traits>::value;
3659 using t_ref =
typename std::add_lvalue_reference<T>::type;
3661 using iterator = detected_t<result_of_begin, t_ref>;
3662 using sentinel = detected_t<result_of_end, t_ref>;
3667 static constexpr auto is_iterator_begin =
3671 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3675using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3678using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3684template<
typename T,
typename =
void>
3690template<
typename BasicJsonType,
typename CompatibleObjectType,
3694template<
typename BasicJsonType,
typename CompatibleObjectType>
3696 BasicJsonType, CompatibleObjectType,
3697 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3698 is_detected<key_type_t, CompatibleObjectType>::value >>
3700 using object_t =
typename BasicJsonType::object_t;
3703 static constexpr bool value =
3705 typename CompatibleObjectType::key_type>::value &&
3707 typename CompatibleObjectType::mapped_type>::value;
3710template<
typename BasicJsonType,
typename CompatibleObjectType>
3714template<
typename BasicJsonType,
typename ConstructibleObjectType,
3718template<
typename BasicJsonType,
typename ConstructibleObjectType>
3720 BasicJsonType, ConstructibleObjectType,
3721 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3722 is_detected<key_type_t, ConstructibleObjectType>::value >>
3724 using object_t =
typename BasicJsonType::object_t;
3726 static constexpr bool value =
3728 (std::is_move_assignable<ConstructibleObjectType>::value ||
3729 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3731 typename object_t::key_type>::value &&
3733 typename object_t::mapped_type,
3734 typename ConstructibleObjectType::mapped_type >::value)) ||
3736 typename ConstructibleObjectType::mapped_type>::value ||
3739 typename ConstructibleObjectType::mapped_type >::value);
3742template<
typename BasicJsonType,
typename ConstructibleObjectType>
3745 ConstructibleObjectType> {};
3747template<
typename BasicJsonType,
typename CompatibleStringType>
3750 static constexpr auto value =
3754template<
typename BasicJsonType,
typename ConstructibleStringType>
3758#ifdef __INTEL_COMPILER
3759 using laundered_type =
decltype(std::declval<ConstructibleStringType>());
3761 using laundered_type = ConstructibleStringType;
3764 static constexpr auto value =
3767 is_detected_exact<
typename BasicJsonType::string_t::value_type,
3768 value_type_t, laundered_type >>::value;
3771template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3774template<
typename BasicJsonType,
typename CompatibleArrayType>
3776 BasicJsonType, CompatibleArrayType,
3778 is_detected<iterator_t, CompatibleArrayType>::value&&
3779 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value&&
3782 !std::is_same<CompatibleArrayType, detected_t<range_value_t, CompatibleArrayType>>::value >>
3784 static constexpr bool value =
3786 range_value_t<CompatibleArrayType>>::value;
3789template<
typename BasicJsonType,
typename CompatibleArrayType>
3793template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3796template<
typename BasicJsonType,
typename ConstructibleArrayType>
3798 BasicJsonType, ConstructibleArrayType,
3799 enable_if_t<
std::is_same<ConstructibleArrayType,
3800 typename BasicJsonType::value_type>::value >>
3801 : std::true_type {};
3803template<
typename BasicJsonType,
typename ConstructibleArrayType>
3805 BasicJsonType, ConstructibleArrayType,
3806 enable_if_t < !
std::is_same<ConstructibleArrayType,
3807 typename BasicJsonType::value_type>::value&&
3810(std::is_move_assignable<ConstructibleArrayType>::value ||
3811 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3812is_detected<iterator_t, ConstructibleArrayType>::value&&
3813is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
3814is_detected<range_value_t, ConstructibleArrayType>::value&&
3817!std::is_same<ConstructibleArrayType, detected_t<range_value_t, ConstructibleArrayType>>::value&&
3819 detected_t<range_value_t, ConstructibleArrayType >>::value >>
3821 using value_type = range_value_t<ConstructibleArrayType>;
3823 static constexpr bool value =
3824 std::is_same<value_type,
3825 typename BasicJsonType::array_t::value_type>::value ||
3827 value_type>::value ||
3830 value_type >::value;
3833template<
typename BasicJsonType,
typename ConstructibleArrayType>
3837template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3841template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3843 RealIntegerType, CompatibleNumberIntegerType,
3844 enable_if_t <
std::is_integral<RealIntegerType>::value&&
3845 std::is_integral<CompatibleNumberIntegerType>::value&&
3846 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3849 using RealLimits = std::numeric_limits<RealIntegerType>;
3850 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3852 static constexpr auto value =
3854 CompatibleNumberIntegerType>::value &&
3855 CompatibleLimits::is_integer &&
3856 RealLimits::is_signed == CompatibleLimits::is_signed;
3859template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3862 CompatibleNumberIntegerType> {};
3864template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3867template<
typename BasicJsonType,
typename CompatibleType>
3869 BasicJsonType, CompatibleType,
3872 static constexpr bool value =
3876template<
typename BasicJsonType,
typename CompatibleType>
3880template<
typename T1,
typename T2>
3883template<
typename T1,
typename... Args>
3886template<
typename BasicJsonType,
typename T>
3889template<
typename BasicJsonType>
3892template<
typename BasicJsonType>
3897template<
template <
typename...>
class Primary,
typename T>
3900template<
template <
typename...>
class Primary,
typename... Args>
3907template<
typename Compare,
typename A,
typename B,
typename =
void>
3910template<
typename Compare,
typename A,
typename B>
3912decltype(
std::declval<Compare>()(std::declval<A>(), std::declval<B>())),
3913decltype(std::declval<Compare>()(std::declval<B>(), std::declval<A>()))
3914>> : std::true_type {};
3917using detect_is_transparent =
typename T::is_transparent;
3921template<
typename Comparator,
typename ObjectKeyType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
3922 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
3923using is_usable_as_key_type =
typename std::conditional <
3925 && !(ExcludeObjectKeyType && std::is_same<KeyType,
3926 ObjectKeyType>::value)
3927 && (!RequireTransparentComparator
3928 || is_detected <detect_is_transparent, Comparator>::value)
3931 std::false_type >::type;
3939template<
typename BasicJsonType,
typename KeyTypeCVRef,
bool RequireTransparentComparator =
true,
3940 bool ExcludeObjectKeyType = RequireTransparentComparator,
typename KeyType = uncvref_t<KeyTypeCVRef>>
3941using is_usable_as_basic_json_key_type =
typename std::conditional <
3942 is_usable_as_key_type<
typename BasicJsonType::object_comparator_t,
3943 typename BasicJsonType::object_t::key_type, KeyTypeCVRef,
3944 RequireTransparentComparator, ExcludeObjectKeyType>::value
3947 std::false_type >::type;
3949template<
typename ObjectType,
typename KeyType>
3950using detect_erase_with_key_type =
decltype(std::declval<ObjectType&>().erase(std::declval<KeyType>()));
3953template<
typename BasicJsonType,
typename KeyType>
3954using has_erase_with_key_type =
typename std::conditional <
3956 detect_erase_with_key_type,
3957 typename BasicJsonType::object_t, KeyType >::value,
3959 std::false_type >::type;
3963template <
typename T>
3973 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
3974 template <
typename C>
static two test(...);
3976 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
3980template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
3981T conditional_static_cast(U value)
3983 return static_cast<T
>(value);
3986template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
3987T conditional_static_cast(U value)
3992template<
typename... Types>
3993using all_integral = conjunction<std::is_integral<Types>...>;
3995template<
typename... Types>
3996using all_signed = conjunction<std::is_signed<Types>...>;
3998template<
typename... Types>
3999using all_unsigned = conjunction<std::is_unsigned<Types>...>;
4002template<
typename... Types>
4003using same_sign = std::integral_constant < bool,
4004 all_signed<Types...>::value || all_unsigned<Types...>::value >;
4006template<
typename OfType,
typename T>
4007using never_out_of_range = std::integral_constant < bool,
4008 (std::is_signed<OfType>::value && (
sizeof(T) <
sizeof(OfType)))
4009 || (same_sign<OfType, T>::value &&
sizeof(OfType) ==
sizeof(T)) >;
4011template<
typename OfType,
typename T,
4012 bool OfTypeSigned = std::is_signed<OfType>::value,
4013 bool TSigned = std::is_signed<T>::value>
4016template<
typename OfType,
typename T>
4019 static constexpr bool test(T val)
4021 using CommonType =
typename std::common_type<OfType, T>::type;
4022 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4026template<
typename OfType,
typename T>
4029 static constexpr bool test(T val)
4031 using CommonType =
typename std::common_type<OfType, T>::type;
4032 return static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4036template<
typename OfType,
typename T>
4039 static constexpr bool test(T val)
4041 using CommonType =
typename std::common_type<OfType, T>::type;
4042 return val >= 0 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4047template<
typename OfType,
typename T>
4050 static constexpr bool test(T val)
4052 using CommonType =
typename std::common_type<OfType, T>::type;
4053 return static_cast<CommonType
>(val) >=
static_cast<CommonType
>((std::numeric_limits<OfType>::min)())
4054 &&
static_cast<CommonType
>(val) <=
static_cast<CommonType
>((std::numeric_limits<OfType>::max)());
4058template<
typename OfType,
typename T,
4059 bool NeverOutOfRange = never_out_of_range<OfType, T>::value,
4060 typename = detail::enable_if_t<all_integral<OfType, T>::value>>
4063template<
typename OfType,
typename T>
4066 static constexpr bool test(T val)
4072template<
typename OfType,
typename T>
4075 static constexpr bool test(T )
4081template<
typename OfType,
typename T>
4082inline constexpr bool value_in_range_of(T val)
4088using bool_constant = std::integral_constant<bool, Value>;
4098inline constexpr bool is_c_string()
4100 using TUnExt =
typename std::remove_extent<T>::type;
4101 using TUnCVExt =
typename std::remove_cv<TUnExt>::type;
4102 using TUnPtr =
typename std::remove_pointer<T>::type;
4103 using TUnCVPtr =
typename std::remove_cv<TUnPtr>::type;
4105 (std::is_array<T>::value && std::is_same<TUnCVExt, char>::value)
4106 || (std::is_pointer<T>::value && std::is_same<TUnCVPtr, char>::value);
4128 return is_detected<detect_is_transparent, T>::value;
4140NLOHMANN_JSON_NAMESPACE_END
4162NLOHMANN_JSON_NAMESPACE_BEGIN
4166inline std::size_t concat_length()
4171template<
typename... Args>
4172inline std::size_t concat_length(
const char* cstr,
const Args& ... rest);
4174template<
typename StringType,
typename... Args>
4175inline std::size_t concat_length(
const StringType& str,
const Args& ... rest);
4177template<
typename... Args>
4178inline std::size_t concat_length(
const char ,
const Args& ... rest)
4180 return 1 + concat_length(rest...);
4183template<
typename... Args>
4184inline std::size_t concat_length(
const char* cstr,
const Args& ... rest)
4187 return ::strlen(cstr) + concat_length(rest...);
4190template<
typename StringType,
typename... Args>
4191inline std::size_t concat_length(
const StringType& str,
const Args& ... rest)
4193 return str.size() + concat_length(rest...);
4196template<
typename OutStringType>
4197inline void concat_into(OutStringType& )
4200template<
typename StringType,
typename Arg>
4201using string_can_append =
decltype(std::declval<StringType&>().append(std::declval < Arg && > ()));
4203template<
typename StringType,
typename Arg>
4204using detect_string_can_append = is_detected<string_can_append, StringType, Arg>;
4206template<
typename StringType,
typename Arg>
4207using string_can_append_op =
decltype(std::declval<StringType&>() += std::declval < Arg && > ());
4209template<
typename StringType,
typename Arg>
4210using detect_string_can_append_op = is_detected<string_can_append_op, StringType, Arg>;
4212template<
typename StringType,
typename Arg>
4213using string_can_append_iter =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().begin(), std::declval<const Arg&>().end()));
4215template<
typename StringType,
typename Arg>
4216using detect_string_can_append_iter = is_detected<string_can_append_iter, StringType, Arg>;
4218template<
typename StringType,
typename Arg>
4219using string_can_append_data =
decltype(std::declval<StringType&>().append(std::declval<const Arg&>().data(), std::declval<const Arg&>().size()));
4221template<
typename StringType,
typename Arg>
4222using detect_string_can_append_data = is_detected<string_can_append_data, StringType, Arg>;
4224template <
typename OutStringType,
typename Arg,
typename... Args,
4225 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4226 && detect_string_can_append_op<OutStringType, Arg>::value,
int > = 0 >
4227inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest);
4229template <
typename OutStringType,
typename Arg,
typename... Args,
4230 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4231 && !detect_string_can_append_op<OutStringType, Arg>::value
4232 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > = 0 >
4233inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4235template <
typename OutStringType,
typename Arg,
typename... Args,
4236 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4237 && !detect_string_can_append_op<OutStringType, Arg>::value
4238 && !detect_string_can_append_iter<OutStringType, Arg>::value
4239 && detect_string_can_append_data<OutStringType, Arg>::value,
int > = 0 >
4240inline void concat_into(OutStringType& out,
const Arg& arg, Args && ... rest);
4242template<
typename OutStringType,
typename Arg,
typename... Args,
4243 enable_if_t<detect_string_can_append<OutStringType, Arg>::value,
int> = 0>
4244inline void concat_into(OutStringType& out, Arg && arg, Args && ... rest)
4246 out.append(std::forward<Arg>(arg));
4247 concat_into(out, std::forward<Args>(rest)...);
4250template <
typename OutStringType,
typename Arg,
typename... Args,
4251 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4252 && detect_string_can_append_op<OutStringType, Arg>::value,
int > >
4253inline void concat_into(OutStringType& out, Arg&& arg, Args&& ... rest)
4255 out += std::forward<Arg>(arg);
4256 concat_into(out, std::forward<Args>(rest)...);
4259template <
typename OutStringType,
typename Arg,
typename... Args,
4260 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4261 && !detect_string_can_append_op<OutStringType, Arg>::value
4262 && detect_string_can_append_iter<OutStringType, Arg>::value,
int > >
4263inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4265 out.append(arg.begin(), arg.end());
4266 concat_into(out, std::forward<Args>(rest)...);
4269template <
typename OutStringType,
typename Arg,
typename... Args,
4270 enable_if_t < !detect_string_can_append<OutStringType, Arg>::value
4271 && !detect_string_can_append_op<OutStringType, Arg>::value
4272 && !detect_string_can_append_iter<OutStringType, Arg>::value
4273 && detect_string_can_append_data<OutStringType, Arg>::value,
int > >
4274inline void concat_into(OutStringType& out,
const Arg& arg, Args&& ... rest)
4276 out.append(arg.data(), arg.size());
4277 concat_into(out, std::forward<Args>(rest)...);
4280template<
typename OutStringType = std::string,
typename... Args>
4281inline OutStringType concat(Args && ... args)
4284 str.reserve(concat_length(args...));
4285 concat_into(str, std::forward<Args>(args)...);
4290NLOHMANN_JSON_NAMESPACE_END
4294NLOHMANN_JSON_NAMESPACE_BEGIN
4308 const char*
what() const noexcept
override
4317 JSON_HEDLEY_NON_NULL(3)
4318 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
4320 static std::string name(
const std::string& ename,
int id_)
4322 return concat(
"[json.exception.", ename,
'.', std::to_string(id_),
"] ");
4325 static std::string diagnostics(std::nullptr_t )
4330 template<
typename BasicJsonType>
4331 static std::string diagnostics(
const BasicJsonType* leaf_element)
4334 std::vector<std::string> tokens;
4335 for (
const auto* current = leaf_element; current !=
nullptr && current->m_parent !=
nullptr; current = current->m_parent)
4337 switch (current->m_parent->type())
4341 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
4343 if (¤t->m_parent->m_value.array->operator[](i) == current)
4345 tokens.emplace_back(std::to_string(i));
4354 for (
const auto& element : *current->m_parent->m_value.
object)
4356 if (&element.second == current)
4358 tokens.emplace_back(element.first.c_str());
4383 auto str = std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
4384 [](
const std::string & a,
const std::string & b)
4386 return concat(a,
'/', detail::escape(b));
4388 return concat(
'(', str,
") ");
4390 static_cast<void>(leaf_element);
4397 std::runtime_error m;
4414 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4417 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4418 position_string(pos),
": ", exception::diagnostics(context), what_arg);
4422 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4423 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg, BasicJsonContext context)
4425 const std::string w = concat(exception::name(
"parse_error", id_),
"parse error",
4426 (byte_ != 0 ? (concat(
" at byte ", std::to_string(byte_))) :
""),
4427 ": ",
exception::diagnostics(context), what_arg);
4428 return {id_, byte_, w.c_str()};
4443 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
4446 static std::string position_string(
const position_t& pos)
4448 return concat(
" at line ", std::to_string(pos.
lines_read + 1),
4458 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4459 static invalid_iterator create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4461 const std::string w = concat(exception::name(
"invalid_iterator", id_), exception::diagnostics(context), what_arg);
4462 return {id_, w.c_str()};
4466 JSON_HEDLEY_NON_NULL(3)
4476 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4477 static type_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4479 const std::string w = concat(exception::name(
"type_error", id_), exception::diagnostics(context), what_arg);
4480 return {id_, w.c_str()};
4484 JSON_HEDLEY_NON_NULL(3)
4493 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4494 static out_of_range create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4496 const std::string w = concat(exception::name(
"out_of_range", id_), exception::diagnostics(context), what_arg);
4497 return {id_, w.c_str()};
4501 JSON_HEDLEY_NON_NULL(3)
4510 template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value,
int> = 0>
4511 static other_error create(
int id_,
const std::string& what_arg, BasicJsonContext context)
4513 const std::string w = concat(exception::name(
"other_error", id_), exception::diagnostics(context), what_arg);
4514 return {id_, w.c_str()};
4518 JSON_HEDLEY_NON_NULL(3)
4523NLOHMANN_JSON_NAMESPACE_END
4543NLOHMANN_JSON_NAMESPACE_BEGIN
4548template <
class T>
struct identity_tag {};
4551NLOHMANN_JSON_NAMESPACE_END
4567#if JSON_HAS_EXPERIMENTAL_FILESYSTEM
4568#include <experimental/filesystem>
4569NLOHMANN_JSON_NAMESPACE_BEGIN
4572namespace std_fs = std::experimental::filesystem;
4574NLOHMANN_JSON_NAMESPACE_END
4575#elif JSON_HAS_FILESYSTEM
4576#include <filesystem>
4577NLOHMANN_JSON_NAMESPACE_BEGIN
4580namespace std_fs = std::filesystem;
4582NLOHMANN_JSON_NAMESPACE_END
4592NLOHMANN_JSON_NAMESPACE_BEGIN
4596template<
typename BasicJsonType>
4597inline void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
4599 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
4601 JSON_THROW(type_error::create(302, concat(
"type must be null, but is ", j.type_name()), &j));
4607template <
typename BasicJsonType,
typename ArithmeticType,
4608 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
4609 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4611void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
4613 switch (
static_cast<value_t>(j))
4617 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4622 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4627 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4639 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4643template<
typename BasicJsonType>
4644inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4646 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4648 JSON_THROW(type_error::create(302, concat(
"type must be boolean, but is ", j.type_name()), &j));
4650 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4653template<
typename BasicJsonType>
4654inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4656 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4658 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4660 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4664 typename BasicJsonType,
typename StringType,
4666 std::is_assignable<StringType&, const typename BasicJsonType::string_t>::value
4667 && is_detected_exact<typename BasicJsonType::string_t::value_type, value_type_t, StringType>::value
4668 && !std::is_same<typename BasicJsonType::string_t, StringType>::value
4669 && !is_json_ref<StringType>::value,
int > = 0 >
4670inline void from_json(
const BasicJsonType& j, StringType& s)
4672 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4674 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
4677 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4680template<
typename BasicJsonType>
4681inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4683 get_arithmetic_value(j, val);
4686template<
typename BasicJsonType>
4687inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4689 get_arithmetic_value(j, val);
4692template<
typename BasicJsonType>
4693inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4695 get_arithmetic_value(j, val);
4698#if !JSON_DISABLE_ENUM_SERIALIZATION
4699template<
typename BasicJsonType,
typename EnumType,
4700 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4701inline void from_json(
const BasicJsonType& j, EnumType& e)
4703 typename std::underlying_type<EnumType>::type val;
4704 get_arithmetic_value(j, val);
4705 e =
static_cast<EnumType
>(val);
4710template<
typename BasicJsonType,
typename T,
typename Allocator,
4711 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4712inline void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4714 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4716 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4719 std::transform(j.rbegin(), j.rend(),
4720 std::front_inserter(l), [](
const BasicJsonType & i)
4722 return i.template get<T>();
4727template<
typename BasicJsonType,
typename T,
4728 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4729inline void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4731 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4733 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4736 std::transform(j.begin(), j.end(), std::begin(l),
4737 [](
const BasicJsonType & elem)
4739 return elem.template get<T>();
4743template<
typename BasicJsonType,
typename T, std::
size_t N>
4744auto from_json(
const BasicJsonType& j, T (&arr)[N])
4745->
decltype(j.template get<T>(), void())
4747 for (std::size_t i = 0; i <
N; ++i)
4749 arr[i] = j.at(i).template get<T>();
4753template<
typename BasicJsonType>
4754inline void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4756 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4759template<
typename BasicJsonType,
typename T, std::
size_t N>
4760auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4762->
decltype(j.template get<T>(), void())
4764 for (std::size_t i = 0; i <
N; ++i)
4766 arr[i] = j.at(i).template get<T>();
4770template<
typename BasicJsonType,
typename ConstructibleArrayType,
4772 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4774auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4776 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4777 j.template get<typename ConstructibleArrayType::value_type>(),
4782 ConstructibleArrayType ret;
4783 ret.reserve(j.size());
4784 std::transform(j.begin(), j.end(),
4785 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4789 return i.template get<typename ConstructibleArrayType::value_type>();
4791 arr = std::move(ret);
4794template<
typename BasicJsonType,
typename ConstructibleArrayType,
4796 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4798inline void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4803 ConstructibleArrayType ret;
4805 j.begin(), j.end(), std::inserter(ret, end(ret)),
4806 [](
const BasicJsonType & i)
4810 return i.template get<typename ConstructibleArrayType::value_type>();
4812 arr = std::move(ret);
4815template <
typename BasicJsonType,
typename ConstructibleArrayType,
4817 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4818 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4819 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4820 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4821 !is_basic_json<ConstructibleArrayType>::value,
4823auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4824->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4825j.template get<typename ConstructibleArrayType::value_type>(),
4828 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4830 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4833 from_json_array_impl(j, arr, priority_tag<3> {});
4836template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4837std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4838 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4840 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4843template <
typename BasicJsonType,
typename T, std::
size_t N >
4844auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4845->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4847 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4849 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4852 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4855template<
typename BasicJsonType>
4856inline void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4858 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4860 JSON_THROW(type_error::create(302, concat(
"type must be binary, but is ", j.type_name()), &j));
4863 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4866template<
typename BasicJsonType,
typename ConstructibleObjectType,
4867 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4868inline void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4870 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4872 JSON_THROW(type_error::create(302, concat(
"type must be object, but is ", j.type_name()), &j));
4875 ConstructibleObjectType ret;
4876 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4877 using value_type =
typename ConstructibleObjectType::value_type;
4879 inner_object->begin(), inner_object->end(),
4880 std::inserter(ret, ret.begin()),
4881 [](
typename BasicJsonType::object_t::value_type
const & p)
4883 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4885 obj = std::move(ret);
4892template <
typename BasicJsonType,
typename ArithmeticType,
4894 std::is_arithmetic<ArithmeticType>::value&&
4895 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4896 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4897 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4898 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4900inline void from_json(
const BasicJsonType& j, ArithmeticType& val)
4902 switch (
static_cast<value_t>(j))
4906 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4911 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4916 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4921 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4932 JSON_THROW(type_error::create(302, concat(
"type must be number, but is ", j.type_name()), &j));
4936template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4937std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
4939 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4942template <
typename BasicJsonType,
class A1,
class A2 >
4943std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4945 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4946 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4949template<
typename BasicJsonType,
typename A1,
typename A2>
4950inline void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
4952 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4955template<
typename BasicJsonType,
typename... Args>
4956std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4958 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4961template<
typename BasicJsonType,
typename... Args>
4962inline void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
4964 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4967template<
typename BasicJsonType,
typename TupleRelated>
4968auto from_json(BasicJsonType&& j, TupleRelated&& t)
4969->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4971 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4973 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4976 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4979template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4980 typename = enable_if_t < !std::is_constructible <
4981 typename BasicJsonType::string_t, Key >::value >>
4982inline void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4984 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4986 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
4989 for (
const auto& p : j)
4991 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4993 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
4995 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4999template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
5000 typename = enable_if_t < !std::is_constructible <
5001 typename BasicJsonType::string_t, Key >::value >>
5002inline void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
5004 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
5006 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", j.type_name()), &j));
5009 for (
const auto& p : j)
5011 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
5013 JSON_THROW(type_error::create(302, concat(
"type must be array, but is ", p.type_name()), &j));
5015 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
5019#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5020template<
typename BasicJsonType>
5021inline void from_json(
const BasicJsonType& j, std_fs::path& p)
5023 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
5025 JSON_THROW(type_error::create(302, concat(
"type must be string, but is ", j.type_name()), &j));
5027 p = *j.template get_ptr<const typename BasicJsonType::string_t*>();
5033 template<
typename BasicJsonType,
typename T>
5034 auto operator()(
const BasicJsonType& j, T&& val)
const
5035 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
5036 ->
decltype(from_json(j, std::forward<T>(val)))
5038 return from_json(j, std::forward<T>(val));
5044#ifndef JSON_HAS_CPP_17
5051JSON_INLINE_VARIABLE
constexpr const auto& from_json =
5053#ifndef JSON_HAS_CPP_17
5057NLOHMANN_JSON_NAMESPACE_END
5074#include <type_traits>
5107NLOHMANN_JSON_NAMESPACE_BEGIN
5111template<
typename string_type>
5112void int_to_string( string_type& target, std::size_t value )
5115 using std::to_string;
5116 target = to_string(value);
5121 using difference_type = std::ptrdiff_t;
5125 using iterator_category = std::input_iterator_tag;
5126 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().
key() ) >::type >::type;
5130 IteratorType anchor{};
5132 std::size_t array_index = 0;
5134 mutable std::size_t array_index_last = 0;
5136 mutable string_type array_index_str =
"0";
5138 string_type empty_str{};
5143 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5144 && std::is_nothrow_default_constructible<string_type>::value)
5145 : anchor(std::move(it))
5146 , array_index(array_index_)
5153 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
5154 && std::is_nothrow_move_constructible<string_type>::value) =
default;
5156 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
5157 && std::is_nothrow_move_assignable<string_type>::value) =
default;
5186 return anchor == o.anchor;
5192 return anchor != o.anchor;
5196 const string_type&
key()
const
5198 JSON_ASSERT(anchor.m_object !=
nullptr);
5200 switch (anchor.m_object->type())
5205 if (array_index != array_index_last)
5207 int_to_string( array_index_str, array_index );
5208 array_index_last = array_index;
5210 return array_index_str;
5215 return anchor.key();
5232 typename IteratorType::reference
value()
const
5234 return anchor.value();
5243 typename IteratorType::pointer container =
nullptr;
5250 : container(&cont) {}
5274template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
5275auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
5282template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
5283auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
5289NLOHMANN_JSON_NAMESPACE_END
5298#if defined(__clang__)
5300 #pragma clang diagnostic push
5301 #pragma clang diagnostic ignored "-Wmismatched-tags"
5303template<
typename IteratorType>
5304class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
5305 :
public std::integral_constant<std::size_t, 2> {};
5307template<std::
size_t N,
typename IteratorType>
5308class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
5311 using type =
decltype(
5312 get<N>(std::declval <
5313 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
5315#if defined(__clang__)
5316 #pragma clang diagnostic pop
5322 template <
typename IteratorType>
5323 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
5337NLOHMANN_JSON_NAMESPACE_BEGIN
5357 template<
typename BasicJsonType>
5358 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
5360 j.m_value.destroy(j.m_type);
5363 j.assert_invariant();
5370 template<
typename BasicJsonType>
5371 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
5373 j.m_value.destroy(j.m_type);
5376 j.assert_invariant();
5379 template<
typename BasicJsonType>
5380 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5382 j.m_value.destroy(j.m_type);
5384 j.m_value = std::move(s);
5385 j.assert_invariant();
5388 template <
typename BasicJsonType,
typename CompatibleStringType,
5389 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
5391 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
5393 j.m_value.destroy(j.m_type);
5395 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
5396 j.assert_invariant();
5403 template<
typename BasicJsonType>
5404 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
5406 j.m_value.destroy(j.m_type);
5408 j.m_value =
typename BasicJsonType::binary_t(b);
5409 j.assert_invariant();
5412 template<
typename BasicJsonType>
5413 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
5415 j.m_value.destroy(j.m_type);
5417 j.m_value =
typename BasicJsonType::binary_t(std::move(b));
5418 j.assert_invariant();
5425 template<
typename BasicJsonType>
5426 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
5428 j.m_value.destroy(j.m_type);
5431 j.assert_invariant();
5438 template<
typename BasicJsonType>
5439 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
5441 j.m_value.destroy(j.m_type);
5444 j.assert_invariant();
5451 template<
typename BasicJsonType>
5452 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
5454 j.m_value.destroy(j.m_type);
5457 j.assert_invariant();
5464 template<
typename BasicJsonType>
5465 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
5467 j.m_value.destroy(j.m_type);
5471 j.assert_invariant();
5474 template<
typename BasicJsonType>
5475 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5477 j.m_value.destroy(j.m_type);
5479 j.m_value = std::move(arr);
5481 j.assert_invariant();
5484 template <
typename BasicJsonType,
typename CompatibleArrayType,
5485 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
5487 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
5492 j.m_value.destroy(j.m_type);
5494 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
5496 j.assert_invariant();
5499 template<
typename BasicJsonType>
5500 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
5502 j.m_value.destroy(j.m_type);
5505 j.m_value.array->reserve(arr.size());
5506 for (
const bool x : arr)
5508 j.m_value.array->push_back(x);
5509 j.set_parent(j.m_value.array->back());
5511 j.assert_invariant();
5514 template<
typename BasicJsonType,
typename T,
5515 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5516 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
5518 j.m_value.destroy(j.m_type);
5521 j.m_value.array->resize(arr.size());
5524 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
5527 j.assert_invariant();
5534 template<
typename BasicJsonType>
5535 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
5537 j.m_value.destroy(j.m_type);
5541 j.assert_invariant();
5544 template<
typename BasicJsonType>
5545 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5547 j.m_value.destroy(j.m_type);
5549 j.m_value = std::move(obj);
5551 j.assert_invariant();
5554 template <
typename BasicJsonType,
typename CompatibleObjectType,
5555 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
5556 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
5561 j.m_value.destroy(j.m_type);
5563 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
5565 j.assert_invariant();
5573template<
typename BasicJsonType,
typename T,
5574 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
5575inline void to_json(BasicJsonType& j, T b)
noexcept
5580template <
typename BasicJsonType,
typename BoolRef,
5582 ((std::is_same<std::vector<bool>::reference, BoolRef>::value
5583 && !std::is_same <std::vector<bool>::reference,
typename BasicJsonType::boolean_t&>::value)
5584 || (std::is_same<std::vector<bool>::const_reference, BoolRef>::value
5585 && !std::is_same <detail::uncvref_t<std::vector<bool>::const_reference>,
5586 typename BasicJsonType::boolean_t >::value))
5587 && std::is_convertible<const BoolRef&, typename BasicJsonType::boolean_t>::value,
int > = 0 >
5588inline void to_json(BasicJsonType& j,
const BoolRef& b)
noexcept
5590 external_constructor<value_t::boolean>::construct(j,
static_cast<typename BasicJsonType::boolean_t
>(b));
5593template<
typename BasicJsonType,
typename CompatibleString,
5594 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
5595inline void to_json(BasicJsonType& j,
const CompatibleString& s)
5597 external_constructor<value_t::string>::construct(j, s);
5600template<
typename BasicJsonType>
5601inline void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
5603 external_constructor<value_t::string>::construct(j, std::move(s));
5606template<
typename BasicJsonType,
typename FloatType,
5607 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
5608inline void to_json(BasicJsonType& j, FloatType val)
noexcept
5610 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
5613template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
5614 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
5615inline void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
5617 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
5620template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
5621 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
5622inline void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
5624 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
5627#if !JSON_DISABLE_ENUM_SERIALIZATION
5628template<
typename BasicJsonType,
typename EnumType,
5629 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
5630inline void to_json(BasicJsonType& j, EnumType e)
noexcept
5632 using underlying_type =
typename std::underlying_type<EnumType>::type;
5633 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
5637template<
typename BasicJsonType>
5638inline void to_json(BasicJsonType& j,
const std::vector<bool>& e)
5640 external_constructor<value_t::array>::construct(j, e);
5643template <
typename BasicJsonType,
typename CompatibleArrayType,
5644 enable_if_t < is_compatible_array_type<BasicJsonType,
5645 CompatibleArrayType>::value&&
5646 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
5647 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
5648 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
5649 !is_basic_json<CompatibleArrayType>::value,
5651inline void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
5653 external_constructor<value_t::array>::construct(j, arr);
5656template<
typename BasicJsonType>
5657inline void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
5659 external_constructor<value_t::binary>::construct(j, bin);
5662template<
typename BasicJsonType,
typename T,
5663 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
5664inline void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
5666 external_constructor<value_t::array>::construct(j, std::move(arr));
5669template<
typename BasicJsonType>
5670inline void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
5672 external_constructor<value_t::array>::construct(j, std::move(arr));
5675template <
typename BasicJsonType,
typename CompatibleObjectType,
5676 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
5677inline void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
5679 external_constructor<value_t::object>::construct(j, obj);
5682template<
typename BasicJsonType>
5683inline void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
5685 external_constructor<value_t::object>::construct(j, std::move(obj));
5689 typename BasicJsonType,
typename T, std::size_t
N,
5690 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
5691 const T(&)[
N]>::value,
5693inline void to_json(BasicJsonType& j,
const T(&arr)[N])
5695 external_constructor<value_t::array>::construct(j, arr);
5698template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
5699inline void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
5701 j = { p.first, p.second };
5705template<
typename BasicJsonType,
typename T,
5706 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
5707inline void to_json(BasicJsonType& j,
const T& b)
5709 j = { {b.key(), b.value()} };
5712template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
5713inline void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
5715 j = { std::get<Idx>(t)... };
5718template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
5719inline void to_json(BasicJsonType& j,
const T& t)
5721 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
5724#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM
5725template<
typename BasicJsonType>
5726inline void to_json(BasicJsonType& j,
const std_fs::path& p)
5734 template<
typename BasicJsonType,
typename T>
5735 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
5736 ->
decltype(to_json(j, std::forward<T>(val)), void())
5738 return to_json(j, std::forward<T>(val));
5743#ifndef JSON_HAS_CPP_17
5750JSON_INLINE_VARIABLE
constexpr const auto& to_json =
5752#ifndef JSON_HAS_CPP_17
5756NLOHMANN_JSON_NAMESPACE_END
5761NLOHMANN_JSON_NAMESPACE_BEGIN
5764template<
typename ValueType,
typename>
5769 template<
typename BasicJsonType,
typename TargetType = ValueType>
5770 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
5771 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5772 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
5774 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5779 template<
typename BasicJsonType,
typename TargetType = ValueType>
5781 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
5782 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
5784 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
5789 template<
typename BasicJsonType,
typename TargetType = ValueType>
5790 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
5791 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5792 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
5794 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5798NLOHMANN_JSON_NAMESPACE_END
5818NLOHMANN_JSON_NAMESPACE_BEGIN
5822template<
typename BinaryType>
5826 using container_type = BinaryType;
5827 using subtype_type = std::uint64_t;
5841 : container_type(std::move(b))
5847 , m_subtype(subtype_)
5848 , m_has_subtype(
true)
5853 : container_type(std::move(b))
5854 , m_subtype(subtype_)
5855 , m_has_subtype(
true)
5860 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5861 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5866 return !(rhs == *
this);
5873 m_subtype = subtype_;
5874 m_has_subtype =
true;
5881 return m_has_subtype ? m_subtype :
static_cast<subtype_type
>(-1);
5888 return m_has_subtype;
5896 m_has_subtype =
false;
5900 subtype_type m_subtype = 0;
5901 bool m_has_subtype =
false;
5904NLOHMANN_JSON_NAMESPACE_END
5925#include <functional>
5932NLOHMANN_JSON_NAMESPACE_BEGIN
5937inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
5939 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5954template<
typename BasicJsonType>
5955std::size_t hash(
const BasicJsonType& j)
5957 using string_t =
typename BasicJsonType::string_t;
5958 using number_integer_t =
typename BasicJsonType::number_integer_t;
5959 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5960 using number_float_t =
typename BasicJsonType::number_float_t;
5962 const auto type =
static_cast<std::size_t
>(j.type());
5965 case BasicJsonType::value_t::null:
5966 case BasicJsonType::value_t::discarded:
5968 return combine(type, 0);
5971 case BasicJsonType::value_t::object:
5973 auto seed = combine(type, j.size());
5974 for (
const auto& element : j.items())
5976 const auto h = std::hash<string_t> {}(element.key());
5977 seed = combine(seed, h);
5978 seed = combine(seed, hash(element.value()));
5983 case BasicJsonType::value_t::array:
5985 auto seed = combine(type, j.size());
5986 for (
const auto& element : j)
5988 seed = combine(seed, hash(element));
5993 case BasicJsonType::value_t::string:
5995 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5996 return combine(type, h);
5999 case BasicJsonType::value_t::boolean:
6001 const auto h = std::hash<bool> {}(j.template get<bool>());
6002 return combine(type, h);
6005 case BasicJsonType::value_t::number_integer:
6007 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
6008 return combine(type, h);
6011 case BasicJsonType::value_t::number_unsigned:
6013 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
6014 return combine(type, h);
6017 case BasicJsonType::value_t::number_float:
6019 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
6020 return combine(type, h);
6023 case BasicJsonType::value_t::binary:
6025 auto seed = combine(type, j.get_binary().size());
6026 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
6027 seed = combine(seed, h);
6028 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
6029 for (
const auto byte : j.get_binary())
6031 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
6043NLOHMANN_JSON_NAMESPACE_END
6089#include <type_traits>
6102NLOHMANN_JSON_NAMESPACE_BEGIN
6107enum class input_format_t { json, cbor, msgpack, ubjson, bson, bjdata };
6118class file_input_adapter
6121 using char_type = char;
6123 JSON_HEDLEY_NON_NULL(2)
6124 explicit file_input_adapter(
std::FILE* f) noexcept
6127 JSON_ASSERT(m_file !=
nullptr);
6131 file_input_adapter(
const file_input_adapter&) =
delete;
6132 file_input_adapter(file_input_adapter&&) noexcept = default;
6133 file_input_adapter& operator=(const file_input_adapter&) = delete;
6134 file_input_adapter& operator=(file_input_adapter&&) = delete;
6135 ~file_input_adapter() = default;
6137 std::char_traits<
char>::int_type get_character() noexcept
6139 return std::fgetc(m_file);
6157class input_stream_adapter
6160 using char_type = char;
6162 ~input_stream_adapter()
6168 is->clear(is->rdstate() & std::ios::eofbit);
6172 explicit input_stream_adapter(std::istream& i)
6173 : is(&i), sb(i.rdbuf())
6177 input_stream_adapter(
const input_stream_adapter&) =
delete;
6178 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
6179 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
6181 input_stream_adapter(input_stream_adapter&& rhs) noexcept
6182 : is(rhs.is), sb(rhs.sb)
6191 std::char_traits<char>::int_type get_character()
6193 auto res = sb->sbumpc();
6195 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
6197 is->clear(is->rdstate() | std::ios::eofbit);
6204 std::istream* is =
nullptr;
6205 std::streambuf* sb =
nullptr;
6211template<
typename IteratorType>
6212class iterator_input_adapter
6215 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
6217 iterator_input_adapter(IteratorType first, IteratorType last)
6218 : current(
std::move(first)), end(
std::move(last))
6221 typename std::char_traits<char_type>::int_type get_character()
6223 if (JSON_HEDLEY_LIKELY(current != end))
6225 auto result = std::char_traits<char_type>::to_int_type(*current);
6226 std::advance(current, 1);
6230 return std::char_traits<char_type>::eof();
6234 IteratorType current;
6237 template<
typename BaseInputAdapter,
size_t T>
6238 friend struct wide_string_input_helper;
6242 return current == end;
6247template<
typename BaseInputAdapter,
size_t T>
6248struct wide_string_input_helper;
6250template<
typename BaseInputAdapter>
6251struct wide_string_input_helper<BaseInputAdapter, 4>
6254 static void fill_buffer(BaseInputAdapter& input,
6255 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6256 size_t& utf8_bytes_index,
6257 size_t& utf8_bytes_filled)
6259 utf8_bytes_index = 0;
6261 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6263 utf8_bytes[0] = std::char_traits<char>::eof();
6264 utf8_bytes_filled = 1;
6269 const auto wc = input.get_character();
6274 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6275 utf8_bytes_filled = 1;
6277 else if (wc <= 0x7FF)
6279 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
6280 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6281 utf8_bytes_filled = 2;
6283 else if (wc <= 0xFFFF)
6285 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
6286 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6287 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6288 utf8_bytes_filled = 3;
6290 else if (wc <= 0x10FFFF)
6292 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
6293 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
6294 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6295 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6296 utf8_bytes_filled = 4;
6301 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6302 utf8_bytes_filled = 1;
6308template<
typename BaseInputAdapter>
6309struct wide_string_input_helper<BaseInputAdapter, 2>
6312 static void fill_buffer(BaseInputAdapter& input,
6313 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
6314 size_t& utf8_bytes_index,
6315 size_t& utf8_bytes_filled)
6317 utf8_bytes_index = 0;
6319 if (JSON_HEDLEY_UNLIKELY(input.empty()))
6321 utf8_bytes[0] = std::char_traits<char>::eof();
6322 utf8_bytes_filled = 1;
6327 const auto wc = input.get_character();
6332 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6333 utf8_bytes_filled = 1;
6335 else if (wc <= 0x7FF)
6337 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
6338 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6339 utf8_bytes_filled = 2;
6341 else if (0xD800 > wc || wc >= 0xE000)
6343 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
6344 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
6345 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
6346 utf8_bytes_filled = 3;
6350 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
6352 const auto wc2 =
static_cast<unsigned int>(input.get_character());
6353 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
6354 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
6355 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
6356 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
6357 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
6358 utf8_bytes_filled = 4;
6362 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
6363 utf8_bytes_filled = 1;
6371template<
typename BaseInputAdapter,
typename W
ideCharType>
6372class wide_string_input_adapter
6375 using char_type = char;
6377 wide_string_input_adapter(BaseInputAdapter base)
6378 : base_adapter(base) {}
6380 typename std::char_traits<char>::int_type get_character() noexcept
6383 if (utf8_bytes_index == utf8_bytes_filled)
6385 fill_buffer<sizeof(WideCharType)>();
6387 JSON_ASSERT(utf8_bytes_filled > 0);
6388 JSON_ASSERT(utf8_bytes_index == 0);
6392 JSON_ASSERT(utf8_bytes_filled > 0);
6393 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
6394 return utf8_bytes[utf8_bytes_index++];
6398 BaseInputAdapter base_adapter;
6403 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
6407 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
6410 std::size_t utf8_bytes_index = 0;
6412 std::size_t utf8_bytes_filled = 0;
6416template<
typename IteratorType,
typename Enable =
void>
6417struct iterator_input_adapter_factory
6419 using iterator_type = IteratorType;
6420 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6421 using adapter_type = iterator_input_adapter<iterator_type>;
6423 static adapter_type create(IteratorType first, IteratorType last)
6425 return adapter_type(std::move(first), std::move(last));
6430struct is_iterator_of_multibyte
6432 using value_type =
typename std::iterator_traits<T>::value_type;
6435 value =
sizeof(value_type) > 1
6439template<
typename IteratorType>
6440struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
6442 using iterator_type = IteratorType;
6443 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
6444 using base_adapter_type = iterator_input_adapter<iterator_type>;
6445 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
6447 static adapter_type create(IteratorType first, IteratorType last)
6449 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
6454template<
typename IteratorType>
6455typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
6457 using factory_type = iterator_input_adapter_factory<IteratorType>;
6458 return factory_type::create(first, last);
6465namespace container_input_adapter_factory_impl
6471template<
typename ContainerType,
typename Enable =
void>
6474template<
typename ContainerType>
6476 void_t<decltype(begin(
std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
6478 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
6480 static adapter_type create(
const ContainerType& container)
6482 return input_adapter(begin(container), end(container));
6488template<
typename ContainerType>
6496inline file_input_adapter input_adapter(std::FILE* file)
6498 return file_input_adapter(file);
6501inline input_stream_adapter input_adapter(std::istream& stream)
6503 return input_stream_adapter(stream);
6506inline input_stream_adapter input_adapter(std::istream&& stream)
6508 return input_stream_adapter(stream);
6512using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
6515template <
typename CharT,
6516 typename std::enable_if <
6517 std::is_pointer<CharT>::value&&
6518 !std::is_array<CharT>::value&&
6519 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6520 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6522contiguous_bytes_input_adapter input_adapter(CharT b)
6524 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
6525 const auto* ptr =
reinterpret_cast<const char*
>(b);
6526 return input_adapter(ptr, ptr + length);
6529template<
typename T, std::
size_t N>
6530auto input_adapter(T (&
array)[N]) ->
decltype(input_adapter(
array,
array + N))
6538class span_input_adapter
6541 template <
typename CharT,
6542 typename std::enable_if <
6543 std::is_pointer<CharT>::value&&
6544 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
6545 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
6547 span_input_adapter(CharT b, std::size_t l)
6548 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
6550 template<
class IteratorType,
6551 typename std::enable_if<
6552 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
6554 span_input_adapter(IteratorType first, IteratorType last)
6555 : ia(input_adapter(first, last)) {}
6557 contiguous_bytes_input_adapter&& get()
6559 return std::move(ia);
6563 contiguous_bytes_input_adapter ia;
6567NLOHMANN_JSON_NAMESPACE_END
6592NLOHMANN_JSON_NAMESPACE_BEGIN
6602template<
typename BasicJsonType>
6605 using number_integer_t =
typename BasicJsonType::number_integer_t;
6606 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6607 using number_float_t =
typename BasicJsonType::number_float_t;
6608 using string_t =
typename BasicJsonType::string_t;
6609 using binary_t =
typename BasicJsonType::binary_t;
6676 virtual bool key(string_t& val) = 0;
6706 const std::string& last_token,
6733template<
typename BasicJsonType>
6737 using number_integer_t =
typename BasicJsonType::number_integer_t;
6738 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6739 using number_float_t =
typename BasicJsonType::number_float_t;
6740 using string_t =
typename BasicJsonType::string_t;
6741 using binary_t =
typename BasicJsonType::binary_t;
6749 : root(r), allow_exceptions(allow_exceptions_)
6761 handle_value(
nullptr);
6765 bool boolean(
bool val)
6783 bool number_float(number_float_t val,
const string_t& )
6789 bool string(string_t& val)
6795 bool binary(binary_t& val)
6797 handle_value(std::move(val));
6801 bool start_object(std::size_t len)
6803 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6805 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6807 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
6813 bool key(string_t& val)
6815 JSON_ASSERT(!ref_stack.empty());
6816 JSON_ASSERT(ref_stack.back()->is_object());
6819 object_element = &(ref_stack.back()->m_value.object->operator[](val));
6825 JSON_ASSERT(!ref_stack.empty());
6826 JSON_ASSERT(ref_stack.back()->is_object());
6828 ref_stack.back()->set_parents();
6829 ref_stack.pop_back();
6833 bool start_array(std::size_t len)
6835 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6837 if (JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6839 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
6847 JSON_ASSERT(!ref_stack.empty());
6848 JSON_ASSERT(ref_stack.back()->is_array());
6850 ref_stack.back()->set_parents();
6851 ref_stack.pop_back();
6855 template<
class Exception>
6856 bool parse_error(std::size_t ,
const std::string& ,
6857 const Exception& ex)
6860 static_cast<void>(ex);
6861 if (allow_exceptions)
6868 constexpr bool is_errored()
const
6880 template<
typename Value>
6881 JSON_HEDLEY_RETURNS_NON_NULL
6882 BasicJsonType* handle_value(Value&& v)
6884 if (ref_stack.empty())
6886 root = BasicJsonType(std::forward<Value>(v));
6890 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6892 if (ref_stack.back()->is_array())
6894 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6895 return &(ref_stack.back()->m_value.array->back());
6898 JSON_ASSERT(ref_stack.back()->is_object());
6899 JSON_ASSERT(object_element);
6900 *object_element = BasicJsonType(std::forward<Value>(v));
6901 return object_element;
6905 BasicJsonType& root;
6907 std::vector<BasicJsonType*> ref_stack {};
6909 BasicJsonType* object_element =
nullptr;
6911 bool errored =
false;
6913 const bool allow_exceptions =
true;
6916template<
typename BasicJsonType>
6920 using number_integer_t =
typename BasicJsonType::number_integer_t;
6921 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6922 using number_float_t =
typename BasicJsonType::number_float_t;
6923 using string_t =
typename BasicJsonType::string_t;
6924 using binary_t =
typename BasicJsonType::binary_t;
6925 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6926 using parse_event_t =
typename BasicJsonType::parse_event_t;
6929 const parser_callback_t cb,
6930 const bool allow_exceptions_ =
true)
6931 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6933 keep_stack.push_back(
true);
6945 handle_value(
nullptr);
6967 bool number_float(number_float_t val,
const string_t& )
6973 bool string(string_t& val)
6979 bool binary(binary_t& val)
6981 handle_value(std::move(val));
6985 bool start_object(std::size_t len)
6988 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
6989 keep_stack.push_back(keep);
6991 auto val = handle_value(BasicJsonType::value_t::object,
true);
6992 ref_stack.push_back(val.second);
6995 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
6997 JSON_THROW(out_of_range::create(408, concat(
"excessive object size: ", std::to_string(len)), ref_stack.back()));
7003 bool key(string_t& val)
7005 BasicJsonType k = BasicJsonType(val);
7008 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
7009 key_keep_stack.push_back(keep);
7012 if (keep && ref_stack.back())
7014 object_element = &(ref_stack.back()->m_value.object->operator[](val) =
discarded);
7022 if (ref_stack.back())
7024 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
7031 ref_stack.back()->set_parents();
7035 JSON_ASSERT(!ref_stack.empty());
7036 JSON_ASSERT(!keep_stack.empty());
7037 ref_stack.pop_back();
7038 keep_stack.pop_back();
7040 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
7043 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
7045 if (it->is_discarded())
7047 ref_stack.back()->erase(it);
7056 bool start_array(std::size_t len)
7058 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
7059 keep_stack.push_back(keep);
7061 auto val = handle_value(BasicJsonType::value_t::array,
true);
7062 ref_stack.push_back(val.second);
7065 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len !=
static_cast<std::size_t
>(-1) && len > ref_stack.back()->max_size()))
7067 JSON_THROW(out_of_range::create(408, concat(
"excessive array size: ", std::to_string(len)), ref_stack.back()));
7077 if (ref_stack.back())
7079 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
7082 ref_stack.back()->set_parents();
7091 JSON_ASSERT(!ref_stack.empty());
7092 JSON_ASSERT(!keep_stack.empty());
7093 ref_stack.pop_back();
7094 keep_stack.pop_back();
7097 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
7099 ref_stack.back()->m_value.array->pop_back();
7105 template<
class Exception>
7106 bool parse_error(std::size_t ,
const std::string& ,
7107 const Exception& ex)
7110 static_cast<void>(ex);
7111 if (allow_exceptions)
7118 constexpr bool is_errored()
const
7139 template<
typename Value>
7140 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
7142 JSON_ASSERT(!keep_stack.empty());
7146 if (!keep_stack.back())
7148 return {
false,
nullptr};
7152 auto value = BasicJsonType(std::forward<Value>(v));
7155 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
7160 return {
false,
nullptr};
7163 if (ref_stack.empty())
7165 root = std::move(value);
7166 return {
true, &root};
7171 if (!ref_stack.back())
7173 return {
false,
nullptr};
7177 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
7180 if (ref_stack.back()->is_array())
7182 ref_stack.back()->m_value.array->emplace_back(std::move(value));
7183 return {
true, &(ref_stack.back()->m_value.array->back())};
7187 JSON_ASSERT(ref_stack.back()->is_object());
7189 JSON_ASSERT(!key_keep_stack.empty());
7190 const bool store_element = key_keep_stack.back();
7191 key_keep_stack.pop_back();
7195 return {
false,
nullptr};
7198 JSON_ASSERT(object_element);
7199 *object_element = std::move(value);
7200 return {
true, object_element};
7204 BasicJsonType& root;
7206 std::vector<BasicJsonType*> ref_stack {};
7208 std::vector<bool> keep_stack {};
7210 std::vector<bool> key_keep_stack {};
7212 BasicJsonType* object_element =
nullptr;
7214 bool errored =
false;
7216 const parser_callback_t callback =
nullptr;
7218 const bool allow_exceptions =
true;
7220 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
7223template<
typename BasicJsonType>
7227 using number_integer_t =
typename BasicJsonType::number_integer_t;
7228 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7229 using number_float_t =
typename BasicJsonType::number_float_t;
7230 using string_t =
typename BasicJsonType::string_t;
7231 using binary_t =
typename BasicJsonType::binary_t;
7268 bool start_object(std::size_t =
static_cast<std::size_t
>(-1))
7273 bool key(string_t& )
7283 bool start_array(std::size_t =
static_cast<std::size_t
>(-1))
7300NLOHMANN_JSON_NAMESPACE_END
7318#include <initializer_list>
7330NLOHMANN_JSON_NAMESPACE_BEGIN
7338template<
typename BasicJsonType>
7365 JSON_HEDLEY_RETURNS_NON_NULL
7371 case token_type::uninitialized:
7372 return "<uninitialized>";
7373 case token_type::literal_true:
7374 return "true literal";
7375 case token_type::literal_false:
7376 return "false literal";
7377 case token_type::literal_null:
7378 return "null literal";
7379 case token_type::value_string:
7380 return "string literal";
7381 case token_type::value_unsigned:
7382 case token_type::value_integer:
7383 case token_type::value_float:
7384 return "number literal";
7385 case token_type::begin_array:
7387 case token_type::begin_object:
7389 case token_type::end_array:
7391 case token_type::end_object:
7393 case token_type::name_separator:
7395 case token_type::value_separator:
7397 case token_type::parse_error:
7398 return "<parse error>";
7399 case token_type::end_of_input:
7400 return "end of input";
7401 case token_type::literal_or_value:
7402 return "'[', '{', or a literal";
7405 return "unknown token";
7415template<
typename BasicJsonType,
typename InputAdapterType>
7418 using number_integer_t =
typename BasicJsonType::number_integer_t;
7419 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
7420 using number_float_t =
typename BasicJsonType::number_float_t;
7421 using string_t =
typename BasicJsonType::string_t;
7422 using char_type =
typename InputAdapterType::char_type;
7423 using char_int_type =
typename std::char_traits<char_type>::int_type;
7428 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
7429 : ia(std::move(adapter))
7430 , ignore_comments(ignore_comments_)
7431 , decimal_point_char(
static_cast<char_int_type
>(get_decimal_point()))
7448 static char get_decimal_point()
noexcept
7450 const auto* loc = localeconv();
7451 JSON_ASSERT(loc !=
nullptr);
7452 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
7477 JSON_ASSERT(current ==
'u');
7480 const auto factors = { 12u, 8u, 4u, 0u };
7481 for (
const auto factor : factors)
7485 if (current >=
'0' && current <=
'9')
7487 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
7489 else if (current >=
'A' && current <=
'F')
7491 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
7493 else if (current >=
'a' && current <=
'f')
7495 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
7503 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
7522 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
7524 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
7527 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
7530 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
7536 error_message =
"invalid string: ill-formed UTF-8 byte";
7559 token_type scan_string()
7565 JSON_ASSERT(current ==
'\"');
7573 case std::char_traits<char_type>::eof():
7575 error_message =
"invalid string: missing closing quote";
7576 return token_type::parse_error;
7582 return token_type::value_string;
7626 const int codepoint1 = get_codepoint();
7627 int codepoint = codepoint1;
7629 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
7631 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7632 return token_type::parse_error;
7636 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
7639 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
7641 const int codepoint2 = get_codepoint();
7643 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
7645 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
7646 return token_type::parse_error;
7650 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
7653 codepoint =
static_cast<int>(
7655 (
static_cast<unsigned int>(codepoint1) << 10u)
7657 +
static_cast<unsigned int>(codepoint2)
7665 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7666 return token_type::parse_error;
7671 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
7672 return token_type::parse_error;
7677 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
7679 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
7680 return token_type::parse_error;
7685 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
7688 if (codepoint < 0x80)
7691 add(
static_cast<char_int_type
>(codepoint));
7693 else if (codepoint <= 0x7FF)
7696 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
7697 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7699 else if (codepoint <= 0xFFFF)
7702 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7703 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7704 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7709 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7710 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7711 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7712 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7720 error_message =
"invalid string: forbidden character after backslash";
7721 return token_type::parse_error;
7730 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7731 return token_type::parse_error;
7736 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7737 return token_type::parse_error;
7742 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7743 return token_type::parse_error;
7748 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7749 return token_type::parse_error;
7754 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7755 return token_type::parse_error;
7760 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7761 return token_type::parse_error;
7766 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7767 return token_type::parse_error;
7772 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7773 return token_type::parse_error;
7778 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7779 return token_type::parse_error;
7784 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7785 return token_type::parse_error;
7790 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7791 return token_type::parse_error;
7796 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7797 return token_type::parse_error;
7802 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7803 return token_type::parse_error;
7808 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7809 return token_type::parse_error;
7814 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7815 return token_type::parse_error;
7820 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7821 return token_type::parse_error;
7826 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7827 return token_type::parse_error;
7832 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7833 return token_type::parse_error;
7838 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7839 return token_type::parse_error;
7844 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7845 return token_type::parse_error;
7850 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7851 return token_type::parse_error;
7856 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7857 return token_type::parse_error;
7862 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7863 return token_type::parse_error;
7868 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7869 return token_type::parse_error;
7874 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7875 return token_type::parse_error;
7880 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7881 return token_type::parse_error;
7886 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7887 return token_type::parse_error;
7892 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7893 return token_type::parse_error;
7898 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7899 return token_type::parse_error;
7904 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7905 return token_type::parse_error;
7910 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7911 return token_type::parse_error;
7916 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7917 return token_type::parse_error;
8052 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
8054 return token_type::parse_error;
8062 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
8064 return token_type::parse_error;
8086 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
8088 return token_type::parse_error;
8096 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
8098 return token_type::parse_error;
8106 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8108 return token_type::parse_error;
8118 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
8120 return token_type::parse_error;
8128 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
8130 return token_type::parse_error;
8138 error_message =
"invalid string: ill-formed UTF-8 byte";
8139 return token_type::parse_error;
8162 case std::char_traits<char_type>::eof():
8179 case std::char_traits<char_type>::eof():
8182 error_message =
"invalid comment; missing closing '*/'";
8210 error_message =
"invalid comment; expecting '/' or '*' after '/'";
8216 JSON_HEDLEY_NON_NULL(2)
8217 static void strtof(
float& f,
const char* str,
char** endptr)
noexcept
8219 f = std::strtof(str, endptr);
8222 JSON_HEDLEY_NON_NULL(2)
8223 static void strtof(
double& f,
const char* str,
char** endptr)
noexcept
8225 f = std::strtod(str, endptr);
8228 JSON_HEDLEY_NON_NULL(2)
8229 static void strtof(
long double& f,
const char* str,
char** endptr)
noexcept
8231 f = std::strtold(str, endptr);
8274 token_type scan_number()
8281 token_type number_type = token_type::value_unsigned;
8289 goto scan_number_minus;
8295 goto scan_number_zero;
8309 goto scan_number_any1;
8319 number_type = token_type::value_integer;
8325 goto scan_number_zero;
8339 goto scan_number_any1;
8344 error_message =
"invalid number; expected digit after '-'";
8345 return token_type::parse_error;
8355 add(decimal_point_char);
8356 goto scan_number_decimal1;
8363 goto scan_number_exponent;
8367 goto scan_number_done;
8386 goto scan_number_any1;
8391 add(decimal_point_char);
8392 goto scan_number_decimal1;
8399 goto scan_number_exponent;
8403 goto scan_number_done;
8406scan_number_decimal1:
8408 number_type = token_type::value_float;
8423 goto scan_number_decimal2;
8428 error_message =
"invalid number; expected digit after '.'";
8429 return token_type::parse_error;
8433scan_number_decimal2:
8449 goto scan_number_decimal2;
8456 goto scan_number_exponent;
8460 goto scan_number_done;
8463scan_number_exponent:
8465 number_type = token_type::value_float;
8472 goto scan_number_sign;
8487 goto scan_number_any2;
8493 "invalid number; expected '+', '-', or digit after exponent";
8494 return token_type::parse_error;
8514 goto scan_number_any2;
8519 error_message =
"invalid number; expected digit after exponent sign";
8520 return token_type::parse_error;
8540 goto scan_number_any2;
8544 goto scan_number_done;
8552 char* endptr =
nullptr;
8556 if (number_type == token_type::value_unsigned)
8558 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
8561 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8565 value_unsigned =
static_cast<number_unsigned_t
>(x);
8566 if (value_unsigned == x)
8568 return token_type::value_unsigned;
8572 else if (number_type == token_type::value_integer)
8574 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
8577 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8581 value_integer =
static_cast<number_integer_t
>(x);
8582 if (value_integer == x)
8584 return token_type::value_integer;
8591 strtof(value_float, token_buffer.data(), &endptr);
8594 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
8596 return token_type::value_float;
8604 JSON_HEDLEY_NON_NULL(2)
8605 token_type scan_literal(
const char_type* literal_text,
const std::size_t length,
8606 token_type return_type)
8608 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
8609 for (std::size_t i = 1; i < length; ++i)
8611 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
8613 error_message =
"invalid literal";
8614 return token_type::parse_error;
8625 void reset()
noexcept
8627 token_buffer.clear();
8628 token_string.clear();
8629 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
8644 ++position.chars_read_total;
8645 ++position.chars_read_current_line;
8654 current = ia.get_character();
8657 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
8659 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
8662 if (current ==
'\n')
8664 ++position.lines_read;
8665 position.chars_read_current_line = 0;
8683 --position.chars_read_total;
8686 if (position.chars_read_current_line == 0)
8688 if (position.lines_read > 0)
8690 --position.lines_read;
8695 --position.chars_read_current_line;
8698 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
8700 JSON_ASSERT(!token_string.empty());
8701 token_string.pop_back();
8706 void add(char_int_type c)
8708 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8719 return value_integer;
8725 return value_unsigned;
8737 return token_buffer;
8757 for (
const auto c : token_string)
8759 if (
static_cast<unsigned char>(c) <=
'\x1F')
8762 std::array<char, 9> cs{{}};
8763 static_cast<void>((std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c)));
8764 result += cs.data();
8769 result.push_back(
static_cast<std::string::value_type
>(c));
8777 JSON_HEDLEY_RETURNS_NON_NULL
8780 return error_message;
8796 return get() == 0xBB && get() == 0xBF;
8805 void skip_whitespace()
8811 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8817 if (position.chars_read_total == 0 && !skip_bom())
8819 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8820 return token_type::parse_error;
8827 while (ignore_comments && current ==
'/')
8829 if (!scan_comment())
8831 return token_type::parse_error;
8842 return token_type::begin_array;
8844 return token_type::end_array;
8846 return token_type::begin_object;
8848 return token_type::end_object;
8850 return token_type::name_separator;
8852 return token_type::value_separator;
8857 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')}};
8858 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8862 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')}};
8863 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8867 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')}};
8868 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8873 return scan_string();
8887 return scan_number();
8892 case std::char_traits<char_type>::eof():
8893 return token_type::end_of_input;
8897 error_message =
"invalid literal";
8898 return token_type::parse_error;
8904 InputAdapterType ia;
8907 const bool ignore_comments =
false;
8910 char_int_type current = std::char_traits<char_type>::eof();
8913 bool next_unget =
false;
8919 std::vector<char_type> token_string {};
8922 string_t token_buffer {};
8925 const char* error_message =
"";
8928 number_integer_t value_integer = 0;
8929 number_unsigned_t value_unsigned = 0;
8930 number_float_t value_float = 0;
8933 const char_int_type decimal_point_char =
'.';
8937NLOHMANN_JSON_NAMESPACE_END
8963NLOHMANN_JSON_NAMESPACE_BEGIN
8968using null_function_t =
decltype(std::declval<T&>().null());
8971using boolean_function_t =
8972 decltype(std::declval<T&>().boolean(std::declval<bool>()));
8974template<
typename T,
typename Integer>
8975using number_integer_function_t =
8976 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8978template<
typename T,
typename Un
signed>
8979using number_unsigned_function_t =
8980 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8982template<
typename T,
typename Float,
typename String>
8983using number_float_function_t =
decltype(std::declval<T&>().number_float(
8984 std::declval<Float>(), std::declval<const String&>()));
8986template<
typename T,
typename String>
8987using string_function_t =
8988 decltype(std::declval<T&>().string(std::declval<String&>()));
8990template<
typename T,
typename Binary>
8991using binary_function_t =
8992 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8995using start_object_function_t =
8996 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8998template<
typename T,
typename String>
8999using key_function_t =
9000 decltype(std::declval<T&>().key(std::declval<String&>()));
9003using end_object_function_t =
decltype(std::declval<T&>().end_object());
9006using start_array_function_t =
9007 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
9010using end_array_function_t =
decltype(std::declval<T&>().end_array());
9012template<
typename T,
typename Exception>
9013using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
9014 std::declval<std::size_t>(), std::declval<const std::string&>(),
9015 std::declval<const Exception&>()));
9017template<
typename SAX,
typename BasicJsonType>
9021 static_assert(is_basic_json<BasicJsonType>::value,
9022 "BasicJsonType must be of type basic_json<...>");
9024 using number_integer_t =
typename BasicJsonType::number_integer_t;
9025 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9026 using number_float_t =
typename BasicJsonType::number_float_t;
9027 using string_t =
typename BasicJsonType::string_t;
9028 using binary_t =
typename BasicJsonType::binary_t;
9029 using exception_t =
typename BasicJsonType::exception;
9032 static constexpr bool value =
9033 is_detected_exact<bool, null_function_t, SAX>::value &&
9034 is_detected_exact<bool, boolean_function_t, SAX>::value &&
9035 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
9036 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
9037 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
9038 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
9039 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
9040 is_detected_exact<bool, start_object_function_t, SAX>::value &&
9041 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
9042 is_detected_exact<bool, end_object_function_t, SAX>::value &&
9043 is_detected_exact<bool, start_array_function_t, SAX>::value &&
9044 is_detected_exact<bool, end_array_function_t, SAX>::value &&
9045 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
9048template<
typename SAX,
typename BasicJsonType>
9049struct is_sax_static_asserts
9052 static_assert(is_basic_json<BasicJsonType>::value,
9053 "BasicJsonType must be of type basic_json<...>");
9055 using number_integer_t =
typename BasicJsonType::number_integer_t;
9056 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9057 using number_float_t =
typename BasicJsonType::number_float_t;
9058 using string_t =
typename BasicJsonType::string_t;
9059 using binary_t =
typename BasicJsonType::binary_t;
9060 using exception_t =
typename BasicJsonType::exception;
9063 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
9064 "Missing/invalid function: bool null()");
9065 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9066 "Missing/invalid function: bool boolean(bool)");
9067 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
9068 "Missing/invalid function: bool boolean(bool)");
9070 is_detected_exact<bool, number_integer_function_t, SAX,
9071 number_integer_t>::value,
9072 "Missing/invalid function: bool number_integer(number_integer_t)");
9074 is_detected_exact<bool, number_unsigned_function_t, SAX,
9075 number_unsigned_t>::value,
9076 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
9077 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
9078 number_float_t, string_t>::value,
9079 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
9081 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
9082 "Missing/invalid function: bool string(string_t&)");
9084 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
9085 "Missing/invalid function: bool binary(binary_t&)");
9086 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
9087 "Missing/invalid function: bool start_object(std::size_t)");
9088 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
9089 "Missing/invalid function: bool key(string_t&)");
9090 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
9091 "Missing/invalid function: bool end_object()");
9092 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
9093 "Missing/invalid function: bool start_array(std::size_t)");
9094 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
9095 "Missing/invalid function: bool end_array()");
9097 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
9098 "Missing/invalid function: bool parse_error(std::size_t, const "
9099 "std::string&, const exception&)");
9103NLOHMANN_JSON_NAMESPACE_END
9112NLOHMANN_JSON_NAMESPACE_BEGIN
9131static inline bool little_endianness(
int num = 1) noexcept
9133 return *
reinterpret_cast<char*
>(&num) == 1;
9144template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
9147 using number_integer_t =
typename BasicJsonType::number_integer_t;
9148 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
9149 using number_float_t =
typename BasicJsonType::number_float_t;
9150 using string_t =
typename BasicJsonType::string_t;
9151 using binary_t =
typename BasicJsonType::binary_t;
9152 using json_sax_t = SAX;
9153 using char_type =
typename InputAdapterType::char_type;
9154 using char_int_type =
typename std::char_traits<char_type>::int_type;
9162 explicit binary_reader(InputAdapterType&& adapter,
const input_format_t format = input_format_t::json) noexcept : ia(std::move(adapter)), input_format(format)
9164 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
9182 JSON_HEDLEY_NON_NULL(3)
9183 bool sax_parse(const input_format_t format,
9185 const
bool strict = true,
9189 bool result =
false;
9193 case input_format_t::bson:
9194 result = parse_bson_internal();
9197 case input_format_t::cbor:
9198 result = parse_cbor_internal(
true, tag_handler);
9201 case input_format_t::msgpack:
9202 result = parse_msgpack_internal();
9205 case input_format_t::ubjson:
9206 case input_format_t::bjdata:
9207 result = parse_ubjson_internal();
9210 case input_format_t::json:
9218 if (input_format == input_format_t::ubjson || input_format == input_format_t::bjdata)
9227 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
9229 return sax->parse_error(chars_read, get_token_string(), parse_error::create(110, chars_read,
9230 exception_message(input_format, concat(
"expected end of input; last byte: 0x", get_token_string()),
"value"),
nullptr));
9246 bool parse_bson_internal()
9248 std::int32_t document_size{};
9249 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9251 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
9256 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
9261 return sax->end_object();
9271 bool get_bson_cstr(string_t& result)
9273 auto out = std::back_inserter(result);
9277 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
9281 if (current == 0x00)
9285 *out++ =
static_cast<typename string_t::value_type
>(current);
9300 template<
typename NumberType>
9301 bool get_bson_string(
const NumberType len, string_t& result)
9303 if (JSON_HEDLEY_UNLIKELY(len < 1))
9305 auto last_token = get_token_string();
9306 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9307 exception_message(input_format_t::bson, concat(
"string length must be at least 1, is ", std::to_string(len)),
"string"),
nullptr));
9310 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
9322 template<
typename NumberType>
9323 bool get_bson_binary(
const NumberType len, binary_t& result)
9325 if (JSON_HEDLEY_UNLIKELY(len < 0))
9327 auto last_token = get_token_string();
9328 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9329 exception_message(input_format_t::bson, concat(
"byte array length cannot be negative, is ", std::to_string(len)),
"binary"),
nullptr));
9333 std::uint8_t subtype{};
9334 get_number<std::uint8_t>(input_format_t::bson, subtype);
9335 result.set_subtype(subtype);
9337 return get_binary(input_format_t::bson, len, result);
9350 bool parse_bson_element_internal(
const char_int_type element_type,
9351 const std::size_t element_type_parse_position)
9353 switch (element_type)
9358 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9365 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
9370 return parse_bson_internal();
9375 return parse_bson_array();
9382 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
9387 return sax->boolean(get() != 0);
9397 std::int32_t value{};
9398 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9403 std::int64_t value{};
9404 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
9409 std::array<char, 3> cr{{}};
9410 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type)));
9411 const std::string cr_str{cr.data()};
9412 return sax->parse_error(element_type_parse_position, cr_str,
9413 parse_error::create(114, element_type_parse_position, concat(
"Unsupported BSON record type 0x", cr_str),
nullptr));
9430 bool parse_bson_element_list(
const bool is_array)
9434 while (
auto element_type = get())
9436 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
9441 const std::size_t element_type_parse_position = chars_read;
9442 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
9447 if (!is_array && !sax->key(key))
9452 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
9468 bool parse_bson_array()
9470 std::int32_t document_size{};
9471 get_number<std::int32_t, true>(input_format_t::bson, document_size);
9473 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
9478 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
9483 return sax->end_array();
9498 bool parse_cbor_internal(
const bool get_char,
9499 const cbor_tag_handler_t tag_handler)
9501 switch (get_char ? get() : current)
9504 case std::char_traits<char_type>::eof():
9505 return unexpect_eof(input_format_t::cbor,
"value");
9532 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9536 std::uint8_t number{};
9537 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9542 std::uint16_t number{};
9543 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9548 std::uint32_t number{};
9549 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9554 std::uint64_t number{};
9555 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
9583 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
9587 std::uint8_t number{};
9588 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9593 std::uint16_t number{};
9594 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9599 std::uint32_t number{};
9600 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
9605 std::uint64_t number{};
9606 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
9607 -
static_cast<number_integer_t
>(number));
9642 return get_cbor_binary(b) && sax->binary(b);
9677 return get_cbor_string(s) && sax->string(s);
9705 return get_cbor_array(
9706 conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9711 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9716 std::uint16_t len{};
9717 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9722 std::uint32_t len{};
9723 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9728 std::uint64_t len{};
9729 return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast<std::size_t>(len), tag_handler);
9733 return get_cbor_array(
static_cast<std::size_t
>(-1), tag_handler);
9760 return get_cbor_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9765 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9770 std::uint16_t len{};
9771 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9776 std::uint32_t len{};
9777 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9782 std::uint64_t len{};
9783 return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast<std::size_t>(len), tag_handler);
9787 return get_cbor_object(
static_cast<std::size_t
>(-1), tag_handler);
9809 switch (tag_handler)
9811 case cbor_tag_handler_t::error:
9813 auto last_token = get_token_string();
9814 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9815 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9818 case cbor_tag_handler_t::ignore:
9825 std::uint8_t subtype_to_ignore{};
9826 get_number(input_format_t::cbor, subtype_to_ignore);
9831 std::uint16_t subtype_to_ignore{};
9832 get_number(input_format_t::cbor, subtype_to_ignore);
9837 std::uint32_t subtype_to_ignore{};
9838 get_number(input_format_t::cbor, subtype_to_ignore);
9843 std::uint64_t subtype_to_ignore{};
9844 get_number(input_format_t::cbor, subtype_to_ignore);
9850 return parse_cbor_internal(
true, tag_handler);
9853 case cbor_tag_handler_t::store:
9861 std::uint8_t subtype{};
9862 get_number(input_format_t::cbor, subtype);
9863 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9868 std::uint16_t subtype{};
9869 get_number(input_format_t::cbor, subtype);
9870 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9875 std::uint32_t subtype{};
9876 get_number(input_format_t::cbor, subtype);
9877 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9882 std::uint64_t subtype{};
9883 get_number(input_format_t::cbor, subtype);
9884 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9888 return parse_cbor_internal(
true, tag_handler);
9891 return get_cbor_binary(b) && sax->binary(b);
9901 return sax->boolean(
false);
9904 return sax->boolean(
true);
9911 const auto byte1_raw = get();
9912 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9916 const auto byte2_raw = get();
9917 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9922 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9923 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9933 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9934 const double val = [&half]
9936 const int exp = (half >> 10u) & 0x1Fu;
9937 const unsigned int mant = half & 0x3FFu;
9938 JSON_ASSERT(0 <= exp&& exp <= 32);
9939 JSON_ASSERT(mant <= 1024);
9943 return std::ldexp(mant, -24);
9946 ? std::numeric_limits<double>::infinity()
9947 :
std::numeric_limits<double>::quiet_NaN();
9949 return std::ldexp(mant + 1024, exp - 25);
9952 return sax->number_float((half & 0x8000u) != 0
9953 ?
static_cast<number_float_t
>(-val)
9954 : static_cast<number_float_t>(val),
"");
9960 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9966 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9971 auto last_token = get_token_string();
9972 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
9973 exception_message(input_format_t::cbor, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
9989 bool get_cbor_string(string_t& result)
9991 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
10024 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10029 std::uint8_t len{};
10030 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10035 std::uint16_t len{};
10036 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10041 std::uint32_t len{};
10042 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10047 std::uint64_t len{};
10048 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
10053 while (get() != 0xFF)
10056 if (!get_cbor_string(chunk))
10060 result.append(chunk);
10067 auto last_token = get_token_string();
10068 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10069 exception_message(input_format_t::cbor, concat(
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x", last_token),
"string"),
nullptr));
10085 bool get_cbor_binary(binary_t& result)
10087 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
10120 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
10125 std::uint8_t len{};
10126 return get_number(input_format_t::cbor, len) &&
10127 get_binary(input_format_t::cbor, len, result);
10132 std::uint16_t len{};
10133 return get_number(input_format_t::cbor, len) &&
10134 get_binary(input_format_t::cbor, len, result);
10139 std::uint32_t len{};
10140 return get_number(input_format_t::cbor, len) &&
10141 get_binary(input_format_t::cbor, len, result);
10146 std::uint64_t len{};
10147 return get_number(input_format_t::cbor, len) &&
10148 get_binary(input_format_t::cbor, len, result);
10153 while (get() != 0xFF)
10156 if (!get_cbor_binary(chunk))
10160 result.insert(result.end(), chunk.begin(), chunk.end());
10167 auto last_token = get_token_string();
10168 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10169 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));
10180 bool get_cbor_array(
const std::size_t len,
10181 const cbor_tag_handler_t tag_handler)
10183 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10188 if (len !=
static_cast<std::size_t
>(-1))
10190 for (std::size_t i = 0; i < len; ++i)
10192 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10200 while (get() != 0xFF)
10202 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
10209 return sax->end_array();
10218 bool get_cbor_object(
const std::size_t len,
10219 const cbor_tag_handler_t tag_handler)
10221 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10229 if (len !=
static_cast<std::size_t
>(-1))
10231 for (std::size_t i = 0; i < len; ++i)
10234 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10239 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10248 while (get() != 0xFF)
10250 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
10255 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
10264 return sax->end_object();
10274 bool parse_msgpack_internal()
10279 case std::char_traits<char_type>::eof():
10280 return unexpect_eof(input_format_t::msgpack,
"value");
10411 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
10430 return get_msgpack_object(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10449 return get_msgpack_array(conditional_static_cast<std::size_t>(
static_cast<unsigned int>(current) & 0x0Fu));
10489 return get_msgpack_string(s) && sax->string(s);
10493 return sax->null();
10496 return sax->boolean(
false);
10499 return sax->boolean(
true);
10514 return get_msgpack_binary(b) && sax->binary(b);
10520 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10526 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10531 std::uint8_t number{};
10532 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10537 std::uint16_t number{};
10538 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10543 std::uint32_t number{};
10544 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10549 std::uint64_t number{};
10550 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
10555 std::int8_t number{};
10556 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10561 std::int16_t number{};
10562 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10567 std::int32_t number{};
10568 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10573 std::int64_t number{};
10574 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
10579 std::uint16_t len{};
10580 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
10585 std::uint32_t len{};
10586 return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast<std::size_t>(len));
10591 std::uint16_t len{};
10592 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
10597 std::uint32_t len{};
10598 return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast<std::size_t>(len));
10634 return sax->number_integer(
static_cast<std::int8_t
>(current));
10638 auto last_token = get_token_string();
10639 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
10640 exception_message(input_format_t::msgpack, concat(
"invalid byte: 0x", last_token),
"value"),
nullptr));
10655 bool get_msgpack_string(string_t& result)
10657 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
10698 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
10703 std::uint8_t len{};
10704 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10709 std::uint16_t len{};
10710 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10715 std::uint32_t len{};
10716 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
10721 auto last_token = get_token_string();
10722 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
10723 exception_message(input_format_t::msgpack, concat(
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x", last_token),
"string"),
nullptr));
10738 bool get_msgpack_binary(binary_t& result)
10741 auto assign_and_return_true = [&result](std::int8_t subtype)
10743 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10751 std::uint8_t len{};
10752 return get_number(input_format_t::msgpack, len) &&
10753 get_binary(input_format_t::msgpack, len, result);
10758 std::uint16_t len{};
10759 return get_number(input_format_t::msgpack, len) &&
10760 get_binary(input_format_t::msgpack, len, result);
10765 std::uint32_t len{};
10766 return get_number(input_format_t::msgpack, len) &&
10767 get_binary(input_format_t::msgpack, len, result);
10772 std::uint8_t len{};
10773 std::int8_t subtype{};
10774 return get_number(input_format_t::msgpack, len) &&
10775 get_number(input_format_t::msgpack, subtype) &&
10776 get_binary(input_format_t::msgpack, len, result) &&
10777 assign_and_return_true(subtype);
10782 std::uint16_t len{};
10783 std::int8_t subtype{};
10784 return get_number(input_format_t::msgpack, len) &&
10785 get_number(input_format_t::msgpack, subtype) &&
10786 get_binary(input_format_t::msgpack, len, result) &&
10787 assign_and_return_true(subtype);
10792 std::uint32_t len{};
10793 std::int8_t subtype{};
10794 return get_number(input_format_t::msgpack, len) &&
10795 get_number(input_format_t::msgpack, subtype) &&
10796 get_binary(input_format_t::msgpack, len, result) &&
10797 assign_and_return_true(subtype);
10802 std::int8_t subtype{};
10803 return get_number(input_format_t::msgpack, subtype) &&
10804 get_binary(input_format_t::msgpack, 1, result) &&
10805 assign_and_return_true(subtype);
10810 std::int8_t subtype{};
10811 return get_number(input_format_t::msgpack, subtype) &&
10812 get_binary(input_format_t::msgpack, 2, result) &&
10813 assign_and_return_true(subtype);
10818 std::int8_t subtype{};
10819 return get_number(input_format_t::msgpack, subtype) &&
10820 get_binary(input_format_t::msgpack, 4, result) &&
10821 assign_and_return_true(subtype);
10826 std::int8_t subtype{};
10827 return get_number(input_format_t::msgpack, subtype) &&
10828 get_binary(input_format_t::msgpack, 8, result) &&
10829 assign_and_return_true(subtype);
10834 std::int8_t subtype{};
10835 return get_number(input_format_t::msgpack, subtype) &&
10836 get_binary(input_format_t::msgpack, 16, result) &&
10837 assign_and_return_true(subtype);
10849 bool get_msgpack_array(
const std::size_t len)
10851 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10856 for (std::size_t i = 0; i < len; ++i)
10858 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10864 return sax->end_array();
10871 bool get_msgpack_object(
const std::size_t len)
10873 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10879 for (std::size_t i = 0; i < len; ++i)
10882 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
10887 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10894 return sax->end_object();
10908 bool parse_ubjson_internal(
const bool get_char =
true)
10910 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10927 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
10934 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
10943 std::uint8_t len{};
10944 return get_number(input_format, len) && get_string(input_format, len, result);
10950 return get_number(input_format, len) && get_string(input_format, len, result);
10955 std::int16_t len{};
10956 return get_number(input_format, len) && get_string(input_format, len, result);
10961 std::int32_t len{};
10962 return get_number(input_format, len) && get_string(input_format, len, result);
10967 std::int64_t len{};
10968 return get_number(input_format, len) && get_string(input_format, len, result);
10973 if (input_format != input_format_t::bjdata)
10977 std::uint16_t len{};
10978 return get_number(input_format, len) && get_string(input_format, len, result);
10983 if (input_format != input_format_t::bjdata)
10987 std::uint32_t len{};
10988 return get_number(input_format, len) && get_string(input_format, len, result);
10993 if (input_format != input_format_t::bjdata)
10997 std::uint64_t len{};
10998 return get_number(input_format, len) && get_string(input_format, len, result);
11004 auto last_token = get_token_string();
11005 std::string message;
11007 if (input_format != input_format_t::bjdata)
11009 message =
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token;
11013 message =
"expected length type specification (U, i, u, I, m, l, M, L); last byte: 0x" + last_token;
11015 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"string"),
nullptr));
11022 bool get_ubjson_ndarray_size(std::vector<size_t>& dim)
11024 std::pair<std::size_t, char_int_type> size_and_type;
11026 bool no_ndarray =
true;
11028 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type, no_ndarray)))
11033 if (size_and_type.first != npos)
11035 if (size_and_type.second != 0)
11037 if (size_and_type.second !=
'N')
11039 for (std::size_t i = 0; i < size_and_type.first; ++i)
11041 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, size_and_type.second)))
11045 dim.push_back(dimlen);
11051 for (std::size_t i = 0; i < size_and_type.first; ++i)
11053 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray)))
11057 dim.push_back(dimlen);
11063 while (current !=
']')
11065 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_value(dimlen, no_ndarray, current)))
11069 dim.push_back(dimlen);
11087 bool get_ubjson_size_value(std::size_t& result,
bool& is_ndarray, char_int_type prefix = 0)
11091 prefix = get_ignore_noop();
11098 std::uint8_t number{};
11099 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11103 result =
static_cast<std::size_t
>(number);
11109 std::int8_t number{};
11110 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11116 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11117 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11119 result =
static_cast<std::size_t
>(number);
11125 std::int16_t number{};
11126 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11132 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11133 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11135 result =
static_cast<std::size_t
>(number);
11141 std::int32_t number{};
11142 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11148 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11149 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11151 result =
static_cast<std::size_t
>(number);
11157 std::int64_t number{};
11158 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11164 return sax->parse_error(chars_read, get_token_string(), parse_error::create(113, chars_read,
11165 exception_message(input_format,
"count in an optimized container must be positive",
"size"),
nullptr));
11167 if (!value_in_range_of<std::size_t>(number))
11169 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11170 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11172 result =
static_cast<std::size_t
>(number);
11178 if (input_format != input_format_t::bjdata)
11182 std::uint16_t number{};
11183 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11187 result =
static_cast<std::size_t
>(number);
11193 if (input_format != input_format_t::bjdata)
11197 std::uint32_t number{};
11198 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11202 result = conditional_static_cast<std::size_t>(number);
11208 if (input_format != input_format_t::bjdata)
11212 std::uint64_t number{};
11213 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
11217 if (!value_in_range_of<std::size_t>(number))
11219 return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408,
11220 exception_message(input_format,
"integer value overflow",
"size"),
nullptr));
11222 result = detail::conditional_static_cast<std::size_t>(number);
11228 if (input_format != input_format_t::bjdata)
11234 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));
11236 std::vector<size_t> dim;
11237 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_ndarray_size(dim)))
11241 if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1))
11243 result = dim.at(dim.size() - 1);
11257 string_t key =
"_ArraySize_";
11258 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))
11266 if (result == 0 || result == npos)
11268 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));
11270 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(
static_cast<number_unsigned_t
>(i))))
11276 return sax->end_array();
11285 auto last_token = get_token_string();
11286 std::string message;
11288 if (input_format != input_format_t::bjdata)
11290 message =
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token;
11294 message =
"expected length type specification (U, i, u, I, m, l, M, L) after '#'; last byte: 0x" + last_token;
11296 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format, message,
"size"),
nullptr));
11310 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result,
bool inside_ndarray =
false)
11312 result.first = npos;
11314 bool is_ndarray =
false;
11318 if (current ==
'$')
11320 result.second = get();
11321 if (input_format == input_format_t::bjdata
11322 && JSON_HEDLEY_UNLIKELY(std::binary_search(bjd_optimized_type_markers.begin(), bjd_optimized_type_markers.end(), result.second)))
11324 auto last_token = get_token_string();
11325 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11326 exception_message(input_format, concat(
"marker 0x", last_token,
" is not a permitted optimized array type"),
"type"),
nullptr));
11329 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"type")))
11335 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
11337 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"value")))
11341 auto last_token = get_token_string();
11342 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11343 exception_message(input_format, concat(
"expected '#' after type information; last byte: 0x", last_token),
"size"),
nullptr));
11346 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11347 if (input_format == input_format_t::bjdata && is_ndarray)
11349 if (inside_ndarray)
11351 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
11352 exception_message(input_format,
"ndarray can not be recursive",
"size"),
nullptr));
11354 result.second |= (1 << 8);
11359 if (current ==
'#')
11361 const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
11362 if (input_format == input_format_t::bjdata && is_ndarray)
11364 return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,
11365 exception_message(input_format,
"ndarray requires both type and size",
"size"),
nullptr));
11377 bool get_ubjson_value(
const char_int_type prefix)
11381 case std::char_traits<char_type>::eof():
11382 return unexpect_eof(input_format,
"value");
11385 return sax->boolean(
true);
11387 return sax->boolean(
false);
11390 return sax->null();
11394 std::uint8_t number{};
11395 return get_number(input_format, number) && sax->number_unsigned(number);
11400 std::int8_t number{};
11401 return get_number(input_format, number) && sax->number_integer(number);
11406 std::int16_t number{};
11407 return get_number(input_format, number) && sax->number_integer(number);
11412 std::int32_t number{};
11413 return get_number(input_format, number) && sax->number_integer(number);
11418 std::int64_t number{};
11419 return get_number(input_format, number) && sax->number_integer(number);
11424 if (input_format != input_format_t::bjdata)
11428 std::uint16_t number{};
11429 return get_number(input_format, number) && sax->number_unsigned(number);
11434 if (input_format != input_format_t::bjdata)
11438 std::uint32_t number{};
11439 return get_number(input_format, number) && sax->number_unsigned(number);
11444 if (input_format != input_format_t::bjdata)
11448 std::uint64_t number{};
11449 return get_number(input_format, number) && sax->number_unsigned(number);
11454 if (input_format != input_format_t::bjdata)
11458 const auto byte1_raw = get();
11459 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11463 const auto byte2_raw = get();
11464 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11469 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
11470 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
11480 const auto half =
static_cast<unsigned int>((byte2 << 8u) + byte1);
11481 const double val = [&half]
11483 const int exp = (half >> 10u) & 0x1Fu;
11484 const unsigned int mant = half & 0x3FFu;
11485 JSON_ASSERT(0 <= exp&& exp <= 32);
11486 JSON_ASSERT(mant <= 1024);
11490 return std::ldexp(mant, -24);
11493 ? std::numeric_limits<double>::infinity()
11494 :
std::numeric_limits<double>::quiet_NaN();
11496 return std::ldexp(mant + 1024, exp - 25);
11499 return sax->number_float((half & 0x8000u) != 0
11500 ?
static_cast<number_float_t
>(-val)
11501 : static_cast<number_float_t>(val),
"");
11507 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11513 return get_number(input_format, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
11518 return get_ubjson_high_precision_number();
11524 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"char")))
11528 if (JSON_HEDLEY_UNLIKELY(current > 127))
11530 auto last_token = get_token_string();
11531 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read,
11532 exception_message(input_format, concat(
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x", last_token),
"char"),
nullptr));
11534 string_t s(1,
static_cast<typename string_t::value_type
>(current));
11535 return sax->string(s);
11541 return get_ubjson_string(s) && sax->string(s);
11545 return get_ubjson_array();
11548 return get_ubjson_object();
11553 auto last_token = get_token_string();
11554 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));
11560 bool get_ubjson_array()
11562 std::pair<std::size_t, char_int_type> size_and_type;
11563 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11571 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11573 size_and_type.second &= ~(
static_cast<char_int_type
>(1) << 8);
11574 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)
11576 return p.first < t;
11578 string_t key =
"_ArrayType_";
11579 if (JSON_HEDLEY_UNLIKELY(it == bjd_types_map.end() || it->first != size_and_type.second))
11581 auto last_token = get_token_string();
11582 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11583 exception_message(input_format,
"invalid byte: 0x" + last_token,
"type"),
nullptr));
11586 string_t type = it->second;
11587 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->string(type)))
11592 if (size_and_type.second ==
'C')
11594 size_and_type.second =
'U';
11597 key =
"_ArrayData_";
11598 if (JSON_HEDLEY_UNLIKELY(!sax->key(key) || !sax->start_array(size_and_type.first) ))
11603 for (std::size_t i = 0; i < size_and_type.first; ++i)
11605 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11611 return (sax->end_array() && sax->end_object());
11614 if (size_and_type.first != npos)
11616 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
11621 if (size_and_type.second != 0)
11623 if (size_and_type.second !=
'N')
11625 for (std::size_t i = 0; i < size_and_type.first; ++i)
11627 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11636 for (std::size_t i = 0; i < size_and_type.first; ++i)
11638 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11647 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
11652 while (current !=
']')
11654 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
11662 return sax->end_array();
11668 bool get_ubjson_object()
11670 std::pair<std::size_t, char_int_type> size_and_type;
11671 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
11677 if (input_format == input_format_t::bjdata && size_and_type.first != npos && (size_and_type.second & (1 << 8)) != 0)
11679 auto last_token = get_token_string();
11680 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read,
11681 exception_message(input_format,
"BJData object does not support ND-array size in optimized format",
"object"),
nullptr));
11685 if (size_and_type.first != npos)
11687 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
11692 if (size_and_type.second != 0)
11694 for (std::size_t i = 0; i < size_and_type.first; ++i)
11696 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
11700 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
11709 for (std::size_t i = 0; i < size_and_type.first; ++i)
11711 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
11715 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11725 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
11730 while (current !=
'}')
11732 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
11736 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
11745 return sax->end_object();
11751 bool get_ubjson_high_precision_number()
11754 std::size_t size{};
11755 bool no_ndarray =
true;
11756 auto res = get_ubjson_size_value(size, no_ndarray);
11757 if (JSON_HEDLEY_UNLIKELY(!res))
11763 std::vector<char> number_vector;
11764 for (std::size_t i = 0; i < size; ++i)
11767 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format,
"number")))
11771 number_vector.push_back(
static_cast<char>(current));
11775 using ia_type =
decltype(detail::input_adapter(number_vector));
11777 const auto result_number = number_lexer.scan();
11778 const auto number_string = number_lexer.get_token_string();
11779 const auto result_remainder = number_lexer.scan();
11783 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
11785 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
11786 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11789 switch (result_number)
11791 case token_type::value_integer:
11792 return sax->number_integer(number_lexer.get_number_integer());
11793 case token_type::value_unsigned:
11794 return sax->number_unsigned(number_lexer.get_number_unsigned());
11795 case token_type::value_float:
11796 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
11797 case token_type::uninitialized:
11798 case token_type::literal_true:
11799 case token_type::literal_false:
11800 case token_type::literal_null:
11801 case token_type::value_string:
11802 case token_type::begin_array:
11803 case token_type::begin_object:
11804 case token_type::end_array:
11805 case token_type::end_object:
11806 case token_type::name_separator:
11807 case token_type::value_separator:
11808 case token_type::parse_error:
11809 case token_type::end_of_input:
11810 case token_type::literal_or_value:
11812 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read,
11813 exception_message(input_format, concat(
"invalid number text: ", number_lexer.get_token_string()),
"high-precision number"),
nullptr));
11830 char_int_type get()
11833 return current = ia.get_character();
11839 char_int_type get_ignore_noop()
11845 while (current ==
'N');
11865 template<
typename NumberType,
bool InputIsLittleEndian = false>
11866 bool get_number(
const input_format_t format, NumberType& result)
11869 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
11870 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
11873 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
11879 if (is_little_endian != (InputIsLittleEndian || format == input_format_t::bjdata))
11881 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
11885 vec[i] =
static_cast<std::uint8_t
>(current);
11890 std::memcpy(&result, vec.data(),
sizeof(NumberType));
11908 template<
typename NumberType>
11909 bool get_string(
const input_format_t format,
11910 const NumberType len,
11913 bool success =
true;
11914 for (NumberType i = 0; i < len; i++)
11917 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
11922 result.push_back(
static_cast<typename string_t::value_type
>(current));
11941 template<
typename NumberType>
11942 bool get_binary(
const input_format_t format,
11943 const NumberType len,
11946 bool success =
true;
11947 for (NumberType i = 0; i < len; i++)
11950 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
11955 result.push_back(
static_cast<std::uint8_t
>(current));
11965 JSON_HEDLEY_NON_NULL(3)
11966 bool unexpect_eof(const input_format_t format, const
char* context)
const
11968 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
11970 return sax->parse_error(chars_read,
"<end of file>",
11971 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context),
nullptr));
11979 std::string get_token_string()
const
11981 std::array<char, 3> cr{{}};
11982 static_cast<void>((std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current)));
11983 return std::string{cr.data()};
11992 std::string exception_message(
const input_format_t format,
11993 const std::string&
detail,
11994 const std::string& context)
const
11996 std::string error_msg =
"syntax error while parsing ";
12000 case input_format_t::cbor:
12001 error_msg +=
"CBOR";
12004 case input_format_t::msgpack:
12005 error_msg +=
"MessagePack";
12008 case input_format_t::ubjson:
12009 error_msg +=
"UBJSON";
12012 case input_format_t::bson:
12013 error_msg +=
"BSON";
12016 case input_format_t::bjdata:
12017 error_msg +=
"BJData";
12020 case input_format_t::json:
12022 JSON_ASSERT(
false);
12025 return concat(error_msg,
' ', context,
": ",
detail);
12029 static JSON_INLINE_VARIABLE
constexpr std::size_t npos =
static_cast<std::size_t
>(-1);
12032 InputAdapterType ia;
12035 char_int_type current = std::char_traits<char_type>::eof();
12038 std::size_t chars_read = 0;
12041 const bool is_little_endian = little_endianness();
12044 const input_format_t input_format = input_format_t::json;
12047 json_sax_t* sax =
nullptr;
12050#define JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_ \
12051 make_array<char_int_type>('F', 'H', 'N', 'S', 'T', 'Z', '[', '{')
12053#define JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_ \
12054 make_array<bjd_type>( \
12055 bjd_type{'C', "char"}, \
12056 bjd_type{'D', "double"}, \
12057 bjd_type{'I', "int16"}, \
12058 bjd_type{'L', "int64"}, \
12059 bjd_type{'M', "uint64"}, \
12060 bjd_type{'U', "uint8"}, \
12061 bjd_type{'d', "single"}, \
12062 bjd_type{'i', "int8"}, \
12063 bjd_type{'l', "int32"}, \
12064 bjd_type{'m', "uint32"}, \
12065 bjd_type{'u', "uint16"})
12067 JSON_PRIVATE_UNLESS_TESTED:
12070 const decltype(JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_) bjd_optimized_type_markers =
12071 JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_;
12073 using bjd_type = std::pair<char_int_type, string_t>;
12075 const decltype(JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_) bjd_types_map =
12076 JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_;
12078#undef JSON_BINARY_READER_MAKE_BJD_OPTIMIZED_TYPE_MARKERS_
12079#undef JSON_BINARY_READER_MAKE_BJD_TYPES_MAP_
12082#ifndef JSON_HAS_CPP_17
12083 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX>
12084 constexpr std::size_t binary_reader<BasicJsonType, InputAdapterType, SAX>::npos;
12088NLOHMANN_JSON_NAMESPACE_END
12107#include <functional>
12129NLOHMANN_JSON_NAMESPACE_BEGIN
12136enum class parse_event_t : std::uint8_t
12152template<
typename BasicJsonType>
12153using parser_callback_t =
12154 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
12161template<
typename BasicJsonType,
typename InputAdapterType>
12164 using number_integer_t =
typename BasicJsonType::number_integer_t;
12165 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
12166 using number_float_t =
typename BasicJsonType::number_float_t;
12167 using string_t =
typename BasicJsonType::string_t;
12168 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
12169 using token_type =
typename lexer_t::token_type;
12173 explicit parser(InputAdapterType&& adapter,
12174 const parser_callback_t<BasicJsonType> cb =
nullptr,
12175 const bool allow_exceptions_ =
true,
12176 const bool skip_comments =
false)
12178 , m_lexer(
std::move(adapter), skip_comments)
12179 , allow_exceptions(allow_exceptions_)
12195 void parse(
const bool strict, BasicJsonType& result)
12199 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
12200 sax_parse_internal(&sdp);
12203 if (strict && (get_token() != token_type::end_of_input))
12205 sdp.parse_error(m_lexer.get_position(),
12206 m_lexer.get_token_string(),
12207 parse_error::create(101, m_lexer.get_position(),
12208 exception_message(token_type::end_of_input,
"value"),
nullptr));
12212 if (sdp.is_errored())
12214 result = value_t::discarded;
12220 if (result.is_discarded())
12227 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
12228 sax_parse_internal(&sdp);
12231 if (strict && (get_token() != token_type::end_of_input))
12233 sdp.parse_error(m_lexer.get_position(),
12234 m_lexer.get_token_string(),
12235 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12239 if (sdp.is_errored())
12241 result = value_t::discarded;
12246 result.assert_invariant();
12255 bool accept(
const bool strict =
true)
12257 json_sax_acceptor<BasicJsonType> sax_acceptor;
12258 return sax_parse(&sax_acceptor, strict);
12261 template<
typename SAX>
12262 JSON_HEDLEY_NON_NULL(2)
12263 bool sax_parse(SAX* sax, const
bool strict = true)
12265 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
12266 const bool result = sax_parse_internal(sax);
12269 if (result && strict && (get_token() != token_type::end_of_input))
12271 return sax->parse_error(m_lexer.get_position(),
12272 m_lexer.get_token_string(),
12273 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"),
nullptr));
12280 template<
typename SAX>
12281 JSON_HEDLEY_NON_NULL(2)
12282 bool sax_parse_internal(SAX* sax)
12286 std::vector<bool> states;
12288 bool skip_to_state_evaluation =
false;
12292 if (!skip_to_state_evaluation)
12295 switch (last_token)
12297 case token_type::begin_object:
12299 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(
static_cast<std::size_t
>(-1))))
12305 if (get_token() == token_type::end_object)
12307 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12315 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
12317 return sax->parse_error(m_lexer.get_position(),
12318 m_lexer.get_token_string(),
12319 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12321 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12327 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12329 return sax->parse_error(m_lexer.get_position(),
12330 m_lexer.get_token_string(),
12331 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12335 states.push_back(
false);
12342 case token_type::begin_array:
12344 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(
static_cast<std::size_t
>(-1))))
12350 if (get_token() == token_type::end_array)
12352 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12360 states.push_back(
true);
12366 case token_type::value_float:
12368 const auto res = m_lexer.get_number_float();
12370 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
12372 return sax->parse_error(m_lexer.get_position(),
12373 m_lexer.get_token_string(),
12374 out_of_range::create(406, concat(
"number overflow parsing '", m_lexer.get_token_string(),
'\''),
nullptr));
12377 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
12385 case token_type::literal_false:
12387 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
12394 case token_type::literal_null:
12396 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
12403 case token_type::literal_true:
12405 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
12412 case token_type::value_integer:
12414 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
12421 case token_type::value_string:
12423 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
12430 case token_type::value_unsigned:
12432 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
12439 case token_type::parse_error:
12442 return sax->parse_error(m_lexer.get_position(),
12443 m_lexer.get_token_string(),
12444 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"),
nullptr));
12447 case token_type::uninitialized:
12448 case token_type::end_array:
12449 case token_type::end_object:
12450 case token_type::name_separator:
12451 case token_type::value_separator:
12452 case token_type::end_of_input:
12453 case token_type::literal_or_value:
12456 return sax->parse_error(m_lexer.get_position(),
12457 m_lexer.get_token_string(),
12458 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"),
nullptr));
12464 skip_to_state_evaluation =
false;
12468 if (states.empty())
12477 if (get_token() == token_type::value_separator)
12485 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
12487 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
12496 JSON_ASSERT(!states.empty());
12498 skip_to_state_evaluation =
true;
12502 return sax->parse_error(m_lexer.get_position(),
12503 m_lexer.get_token_string(),
12504 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"),
nullptr));
12510 if (get_token() == token_type::value_separator)
12513 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
12515 return sax->parse_error(m_lexer.get_position(),
12516 m_lexer.get_token_string(),
12517 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"),
nullptr));
12520 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
12526 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
12528 return sax->parse_error(m_lexer.get_position(),
12529 m_lexer.get_token_string(),
12530 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"),
nullptr));
12539 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
12541 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
12550 JSON_ASSERT(!states.empty());
12552 skip_to_state_evaluation =
true;
12556 return sax->parse_error(m_lexer.get_position(),
12557 m_lexer.get_token_string(),
12558 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"),
nullptr));
12563 token_type get_token()
12565 return last_token = m_lexer.scan();
12568 std::string exception_message(
const token_type expected,
const std::string& context)
12570 std::string error_msg =
"syntax error ";
12572 if (!context.empty())
12574 error_msg += concat(
"while parsing ", context,
' ');
12579 if (last_token == token_type::parse_error)
12581 error_msg += concat(m_lexer.get_error_message(),
"; last read: '",
12582 m_lexer.get_token_string(),
'\'');
12586 error_msg += concat(
"unexpected ", lexer_t::token_type_name(last_token));
12589 if (expected != token_type::uninitialized)
12591 error_msg += concat(
"; expected ", lexer_t::token_type_name(expected));
12599 const parser_callback_t<BasicJsonType> callback =
nullptr;
12601 token_type last_token = token_type::uninitialized;
12605 const bool allow_exceptions =
true;
12609NLOHMANN_JSON_NAMESPACE_END
12641NLOHMANN_JSON_NAMESPACE_BEGIN
12654class primitive_iterator_t
12657 using difference_type = std::ptrdiff_t;
12658 static constexpr difference_type begin_value = 0;
12659 static constexpr difference_type end_value = begin_value + 1;
12661 JSON_PRIVATE_UNLESS_TESTED:
12663 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
12666 constexpr difference_type get_value() const noexcept
12672 void set_begin() noexcept
12674 m_it = begin_value;
12678 void set_end() noexcept
12684 constexpr bool is_begin() const noexcept
12686 return m_it == begin_value;
12690 constexpr bool is_end() const noexcept
12692 return m_it == end_value;
12695 friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12697 return lhs.m_it == rhs.m_it;
12700 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12702 return lhs.m_it < rhs.m_it;
12705 primitive_iterator_t operator+(difference_type n)
noexcept
12707 auto result = *
this;
12712 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
12714 return lhs.m_it - rhs.m_it;
12717 primitive_iterator_t& operator++() noexcept
12723 primitive_iterator_t operator++(
int)&
noexcept
12725 auto result = *
this;
12730 primitive_iterator_t& operator--() noexcept
12736 primitive_iterator_t operator--(
int)&
noexcept
12738 auto result = *
this;
12743 primitive_iterator_t& operator+=(difference_type n)
noexcept
12749 primitive_iterator_t& operator-=(difference_type n)
noexcept
12757NLOHMANN_JSON_NAMESPACE_END
12760NLOHMANN_JSON_NAMESPACE_BEGIN
12773 typename BasicJsonType::object_t::iterator object_iterator {};
12775 typename BasicJsonType::array_t::iterator array_iterator {};
12777 primitive_iterator_t primitive_iterator {};
12781NLOHMANN_JSON_NAMESPACE_END
12795#include <type_traits>
12812NLOHMANN_JSON_NAMESPACE_BEGIN
12817template<
typename IteratorType>
class iteration_proxy;
12818template<
typename IteratorType>
class iteration_proxy_value;
12836template<
typename BasicJsonType>
12843 friend BasicJsonType;
12847 using object_t =
typename BasicJsonType::object_t;
12848 using array_t =
typename BasicJsonType::array_t;
12851 "iter_impl only accepts (const) basic_json");
12853 static_assert(std::is_base_of<std::bidirectional_iterator_tag, std::bidirectional_iterator_tag>::value
12854 && std::is_base_of<std::bidirectional_iterator_tag, typename std::iterator_traits<typename array_t::iterator>::iterator_category>::value,
12855 "basic_json iterator assumes array and object type iterators satisfy the LegacyBidirectionalIterator named requirement.");
12870 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
12871 typename BasicJsonType::const_pointer,
12872 typename BasicJsonType::pointer>::type;
12875 typename std::conditional<std::is_const<BasicJsonType>::value,
12876 typename BasicJsonType::const_reference,
12877 typename BasicJsonType::reference>::type;
12892 JSON_ASSERT(m_object !=
nullptr);
12894 switch (m_object->m_type)
12896 case value_t::object:
12898 m_it.object_iterator =
typename object_t::iterator();
12902 case value_t::array:
12904 m_it.array_iterator =
typename array_t::iterator();
12908 case value_t::null:
12909 case value_t::string:
12910 case value_t::boolean:
12911 case value_t::number_integer:
12912 case value_t::number_unsigned:
12913 case value_t::number_float:
12914 case value_t::binary:
12915 case value_t::discarded:
12918 m_it.primitive_iterator = primitive_iterator_t();
12941 : m_object(other.m_object), m_it(other.m_it)
12952 if (&other !=
this)
12954 m_object = other.m_object;
12966 : m_object(other.m_object), m_it(other.m_it)
12977 m_object = other.m_object;
12982 JSON_PRIVATE_UNLESS_TESTED:
12987 void set_begin() noexcept
12989 JSON_ASSERT(m_object !=
nullptr);
12991 switch (m_object->m_type)
12993 case value_t::object:
12995 m_it.object_iterator = m_object->m_value.object->begin();
12999 case value_t::array:
13001 m_it.array_iterator = m_object->m_value.array->begin();
13005 case value_t::null:
13008 m_it.primitive_iterator.set_end();
13012 case value_t::string:
13013 case value_t::boolean:
13014 case value_t::number_integer:
13015 case value_t::number_unsigned:
13016 case value_t::number_float:
13017 case value_t::binary:
13018 case value_t::discarded:
13021 m_it.primitive_iterator.set_begin();
13033 JSON_ASSERT(m_object !=
nullptr);
13035 switch (m_object->m_type)
13037 case value_t::object:
13039 m_it.object_iterator = m_object->m_value.object->end();
13043 case value_t::array:
13045 m_it.array_iterator = m_object->m_value.array->end();
13049 case value_t::null:
13050 case value_t::string:
13051 case value_t::boolean:
13052 case value_t::number_integer:
13053 case value_t::number_unsigned:
13054 case value_t::number_float:
13055 case value_t::binary:
13056 case value_t::discarded:
13059 m_it.primitive_iterator.set_end();
13072 JSON_ASSERT(m_object !=
nullptr);
13074 switch (m_object->m_type)
13076 case value_t::object:
13078 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
13079 return m_it.object_iterator->second;
13082 case value_t::array:
13084 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
13085 return *m_it.array_iterator;
13088 case value_t::null:
13089 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13091 case value_t::string:
13092 case value_t::boolean:
13093 case value_t::number_integer:
13094 case value_t::number_unsigned:
13095 case value_t::number_float:
13096 case value_t::binary:
13097 case value_t::discarded:
13100 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13105 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13116 JSON_ASSERT(m_object !=
nullptr);
13118 switch (m_object->m_type)
13120 case value_t::object:
13122 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
13123 return &(m_it.object_iterator->second);
13126 case value_t::array:
13128 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
13129 return &*m_it.array_iterator;
13132 case value_t::null:
13133 case value_t::string:
13134 case value_t::boolean:
13135 case value_t::number_integer:
13136 case value_t::number_unsigned:
13137 case value_t::number_float:
13138 case value_t::binary:
13139 case value_t::discarded:
13142 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
13147 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13158 auto result = *
this;
13169 JSON_ASSERT(m_object !=
nullptr);
13171 switch (m_object->m_type)
13173 case value_t::object:
13175 std::advance(m_it.object_iterator, 1);
13179 case value_t::array:
13181 std::advance(m_it.array_iterator, 1);
13185 case value_t::null:
13186 case value_t::string:
13187 case value_t::boolean:
13188 case value_t::number_integer:
13189 case value_t::number_unsigned:
13190 case value_t::number_float:
13191 case value_t::binary:
13192 case value_t::discarded:
13195 ++m_it.primitive_iterator;
13209 auto result = *
this;
13220 JSON_ASSERT(m_object !=
nullptr);
13222 switch (m_object->m_type)
13224 case value_t::object:
13226 std::advance(m_it.object_iterator, -1);
13230 case value_t::array:
13232 std::advance(m_it.array_iterator, -1);
13236 case value_t::null:
13237 case value_t::string:
13238 case value_t::boolean:
13239 case value_t::number_integer:
13240 case value_t::number_unsigned:
13241 case value_t::number_float:
13242 case value_t::binary:
13243 case value_t::discarded:
13246 --m_it.primitive_iterator;
13258 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 >
13262 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13264 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13267 JSON_ASSERT(m_object !=
nullptr);
13269 switch (m_object->m_type)
13271 case value_t::object:
13272 return (m_it.object_iterator == other.m_it.object_iterator);
13274 case value_t::array:
13275 return (m_it.array_iterator == other.m_it.array_iterator);
13277 case value_t::null:
13278 case value_t::string:
13279 case value_t::boolean:
13280 case value_t::number_integer:
13281 case value_t::number_unsigned:
13282 case value_t::number_float:
13283 case value_t::binary:
13284 case value_t::discarded:
13286 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
13294 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 >
13297 return !operator==(other);
13307 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
13309 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", m_object));
13312 JSON_ASSERT(m_object !=
nullptr);
13314 switch (m_object->m_type)
13316 case value_t::object:
13317 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", m_object));
13319 case value_t::array:
13322 case value_t::null:
13323 case value_t::string:
13324 case value_t::boolean:
13325 case value_t::number_integer:
13326 case value_t::number_unsigned:
13327 case value_t::number_float:
13328 case value_t::binary:
13329 case value_t::discarded:
13341 return !other.operator < (*this);
13350 return !operator<=(other);
13368 JSON_ASSERT(m_object !=
nullptr);
13370 switch (m_object->m_type)
13372 case value_t::object:
13373 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13375 case value_t::array:
13377 std::advance(m_it.array_iterator, i);
13381 case value_t::null:
13382 case value_t::string:
13383 case value_t::boolean:
13384 case value_t::number_integer:
13385 case value_t::number_unsigned:
13386 case value_t::number_float:
13387 case value_t::binary:
13388 case value_t::discarded:
13391 m_it.primitive_iterator += i;
13405 return operator+=(-i);
13414 auto result = *
this;
13436 auto result = *
this;
13447 JSON_ASSERT(m_object !=
nullptr);
13449 switch (m_object->m_type)
13451 case value_t::object:
13452 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", m_object));
13454 case value_t::array:
13457 case value_t::null:
13458 case value_t::string:
13459 case value_t::boolean:
13460 case value_t::number_integer:
13461 case value_t::number_unsigned:
13462 case value_t::number_float:
13463 case value_t::binary:
13464 case value_t::discarded:
13476 JSON_ASSERT(m_object !=
nullptr);
13478 switch (m_object->m_type)
13480 case value_t::object:
13481 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", m_object));
13483 case value_t::array:
13484 return *std::next(m_it.array_iterator, n);
13486 case value_t::null:
13487 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13489 case value_t::string:
13490 case value_t::boolean:
13491 case value_t::number_integer:
13492 case value_t::number_unsigned:
13493 case value_t::number_float:
13494 case value_t::binary:
13495 case value_t::discarded:
13498 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
13503 JSON_THROW(invalid_iterator::create(214,
"cannot get value", m_object));
13512 const typename object_t::key_type&
key()
const
13514 JSON_ASSERT(m_object !=
nullptr);
13516 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
13518 return m_it.object_iterator->first;
13521 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", m_object));
13530 return operator*();
13533 JSON_PRIVATE_UNLESS_TESTED:
13535 pointer m_object =
nullptr;
13541NLOHMANN_JSON_NAMESPACE_END
13563NLOHMANN_JSON_NAMESPACE_BEGIN
13589template<
typename Base>
13593 using difference_type = std::ptrdiff_t;
13657 return *(this->operator+(n));
13661 auto key() const -> decltype(
std::declval<Base>().key())
13663 auto it = --this->base();
13670 auto it = --this->base();
13671 return it.operator * ();
13676NLOHMANN_JSON_NAMESPACE_END
13683#include <type_traits>
13688NLOHMANN_JSON_NAMESPACE_BEGIN
13705using json_base_class =
typename std::conditional <
13706 std::is_same<T, void>::value,
13712NLOHMANN_JSON_NAMESPACE_END
13725#include <algorithm>
13749NLOHMANN_JSON_NAMESPACE_BEGIN
13753template<
typename RefStringType>
13757 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13763 template<
typename T>
13764 struct string_t_helper
13769 NLOHMANN_BASIC_JSON_TPL_DECLARATION
13770 struct string_t_helper<NLOHMANN_BASIC_JSON_TPL>
13772 using type = StringType;
13777 using string_t =
typename string_t_helper<RefStringType>::type;
13782 : reference_tokens(split(s))
13789 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
13791 [](
const string_t& a,
const string_t& b)
13793 return detail::concat(a,
'/', detail::escape(b));
13799 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, to_string())
13800 operator string_t()
const
13802 return to_string();
13819 reference_tokens.insert(reference_tokens.end(),
13820 ptr.reference_tokens.begin(),
13821 ptr.reference_tokens.end());
13829 push_back(std::move(token));
13837 return *
this /= std::to_string(array_idx);
13880 if (JSON_HEDLEY_UNLIKELY(empty()))
13882 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13885 reference_tokens.pop_back();
13892 if (JSON_HEDLEY_UNLIKELY(empty()))
13894 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13897 return reference_tokens.back();
13904 reference_tokens.push_back(token);
13911 reference_tokens.push_back(std::move(token));
13918 return reference_tokens.empty();
13932 template<
typename BasicJsonType>
13933 static typename BasicJsonType::size_type array_index(
const string_t& s)
13935 using size_type =
typename BasicJsonType::size_type;
13938 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
13944 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
13949 const char* p = s.c_str();
13950 char* p_end =
nullptr;
13952 const unsigned long long res = std::strtoull(p, &p_end, 10);
13955 || JSON_HEDLEY_UNLIKELY(
static_cast<std::size_t
>(p_end - p) != s.size()))
13957 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", s,
"'"),
nullptr));
13962 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
13964 JSON_THROW(detail::out_of_range::create(410, detail::concat(
"array index ", s,
" exceeds size_type"),
nullptr));
13967 return static_cast<size_type
>(res);
13970 JSON_PRIVATE_UNLESS_TESTED:
13973 if (JSON_HEDLEY_UNLIKELY(empty()))
13975 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent",
nullptr));
13979 result.reference_tokens = {reference_tokens[0]};
13992 template<
typename BasicJsonType>
13993 BasicJsonType& get_and_create(BasicJsonType& j)
const
13999 for (
const auto& reference_token : reference_tokens)
14001 switch (result->type())
14005 if (reference_token ==
"0")
14008 result = &result->operator[](0);
14013 result = &result->operator[](reference_token);
14021 result = &result->operator[](reference_token);
14028 result = &result->operator[](array_index<BasicJsonType>(reference_token));
14046 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", &j));
14072 template<
typename BasicJsonType>
14073 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
14075 for (
const auto& reference_token : reference_tokens)
14078 if (ptr->is_null())
14082 std::all_of(reference_token.begin(), reference_token.end(),
14083 [](
const unsigned char x)
14085 return std::isdigit(x);
14089 *ptr = (nums || reference_token ==
"-")
14094 switch (ptr->type())
14099 ptr = &ptr->operator[](reference_token);
14105 if (reference_token ==
"-")
14108 ptr = &ptr->operator[](ptr->m_value.array->size());
14113 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14127 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14140 template<
typename BasicJsonType>
14141 BasicJsonType& get_checked(BasicJsonType* ptr)
const
14143 for (
const auto& reference_token : reference_tokens)
14145 switch (ptr->type())
14150 ptr = &ptr->at(reference_token);
14156 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14159 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14160 "array index '-' (", std::to_string(ptr->m_value.array->size()),
14161 ") is out of range"), ptr));
14165 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14178 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14198 template<
typename BasicJsonType>
14199 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
14201 for (
const auto& reference_token : reference_tokens)
14203 switch (ptr->type())
14208 ptr = &ptr->operator[](reference_token);
14214 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14217 JSON_THROW(detail::out_of_range::create(402, detail::concat(
"array index '-' (", std::to_string(ptr->m_value.array->size()),
") is out of range"), ptr));
14221 ptr = &ptr->operator[](array_index<BasicJsonType>(reference_token));
14234 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14247 template<
typename BasicJsonType>
14248 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
14250 for (
const auto& reference_token : reference_tokens)
14252 switch (ptr->type())
14257 ptr = &ptr->at(reference_token);
14263 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14266 JSON_THROW(detail::out_of_range::create(402, detail::concat(
14267 "array index '-' (", std::to_string(ptr->m_value.array->size()),
14268 ") is out of range"), ptr));
14272 ptr = &ptr->at(array_index<BasicJsonType>(reference_token));
14285 JSON_THROW(detail::out_of_range::create(404, detail::concat(
"unresolved reference token '", reference_token,
"'"), ptr));
14296 template<
typename BasicJsonType>
14297 bool contains(
const BasicJsonType* ptr)
const
14299 for (
const auto& reference_token : reference_tokens)
14301 switch (ptr->type())
14305 if (!ptr->contains(reference_token))
14311 ptr = &ptr->operator[](reference_token);
14317 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
14322 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
14327 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
14329 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
14334 for (std::size_t i = 1; i < reference_token.size(); i++)
14336 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
14344 const auto idx = array_index<BasicJsonType>(reference_token);
14345 if (idx >= ptr->size())
14351 ptr = &ptr->operator[](idx);
14385 static std::vector<string_t> split(
const string_t& reference_string)
14387 std::vector<string_t> result;
14390 if (reference_string.empty())
14396 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
14398 JSON_THROW(
detail::parse_error::create(107, 1, detail::concat(
"JSON pointer must be empty or begin with '/' - was: '", reference_string,
"'"),
nullptr));
14406 std::size_t slash = reference_string.find_first_of(
'/', 1),
14413 start = (slash == string_t::npos) ? 0 : slash + 1,
14415 slash = reference_string.find_first_of(
'/', start))
14419 auto reference_token = reference_string.substr(start, slash - start);
14422 for (std::size_t pos = reference_token.find_first_of(
'~');
14423 pos != string_t::npos;
14424 pos = reference_token.find_first_of(
'~', pos + 1))
14426 JSON_ASSERT(reference_token[pos] ==
'~');
14429 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
14430 (reference_token[pos + 1] !=
'0' &&
14431 reference_token[pos + 1] !=
'1')))
14438 detail::unescape(reference_token);
14439 result.push_back(reference_token);
14453 template<
typename BasicJsonType>
14454 static void flatten(
const string_t& reference_string,
14455 const BasicJsonType& value,
14456 BasicJsonType& result)
14458 switch (value.type())
14462 if (value.m_value.array->empty())
14465 result[reference_string] =
nullptr;
14470 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
14472 flatten(detail::concat(reference_string,
'/', std::to_string(i)),
14473 value.m_value.array->operator[](i), result);
14481 if (value.m_value.object->empty())
14484 result[reference_string] =
nullptr;
14489 for (
const auto& element : *value.m_value.
object)
14491 flatten(detail::concat(reference_string,
'/',
detail::escape(element.first)), element.second, result);
14508 result[reference_string] = value;
14524 template<
typename BasicJsonType>
14525 static BasicJsonType
14526 unflatten(
const BasicJsonType& value)
14528 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
14530 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", &value));
14533 BasicJsonType result;
14536 for (
const auto& element : *value.m_value.
object)
14538 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
14540 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", &element.second));
14547 json_pointer(element.first).get_and_create(result) = element.second;
14557 result.reference_tokens = reference_tokens;
14564 result.reference_tokens = std::move(reference_tokens);
14569#if JSON_HAS_THREE_WAY_COMPARISON
14572 template<
typename RefStringTypeRhs>
14575 return reference_tokens == rhs.reference_tokens;
14580 JSON_HEDLEY_DEPRECATED_FOR(3.11.2,
operator==(
json_pointer))
14581 bool operator==(
const string_t& rhs)
const
14587 template<
typename RefStringTypeRhs>
14590 return reference_tokens <=> rhs.reference_tokens;
14595 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14602 template<
typename RefStringTypeLhs,
typename StringType>
14605 const StringType& rhs);
14609 template<
typename RefStringTypeRhs,
typename StringType>
14611 friend bool operator==(
const StringType& lhs,
14616 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14623 template<
typename RefStringTypeLhs,
typename StringType>
14626 const StringType& rhs);
14630 template<
typename RefStringTypeRhs,
typename StringType>
14632 friend bool operator!=(
const StringType& lhs,
14636 template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14644 std::vector<string_t> reference_tokens;
14647#if !JSON_HAS_THREE_WAY_COMPARISON
14649template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14653 return lhs.reference_tokens == rhs.reference_tokens;
14656template<
typename RefStringTypeLhs,
14657 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14660 const StringType& rhs)
14665template<
typename RefStringTypeRhs,
14666 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14668inline
bool operator==(const StringType& lhs,
14674template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14678 return !(lhs == rhs);
14681template<
typename RefStringTypeLhs,
14682 typename StringType =
typename json_pointer<RefStringTypeLhs>::string_t>
14685 const StringType& rhs)
14687 return !(lhs == rhs);
14690template<
typename RefStringTypeRhs,
14691 typename StringType =
typename json_pointer<RefStringTypeRhs>::string_t>
14693inline
bool operator!=(const StringType& lhs,
14696 return !(lhs == rhs);
14699template<
typename RefStringTypeLhs,
typename RefStringTypeRhs>
14703 return lhs.reference_tokens < rhs.reference_tokens;
14707NLOHMANN_JSON_NAMESPACE_END
14720#include <initializer_list>
14728NLOHMANN_JSON_NAMESPACE_BEGIN
14732template<
typename BasicJsonType>
14736 using value_type = BasicJsonType;
14739 : owned_value(std::move(value))
14743 : value_ref(&value)
14746 json_ref(std::initializer_list<json_ref> init)
14747 : owned_value(init)
14752 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
14754 : owned_value(std::forward<Args>(args)...)
14764 value_type moved_or_copied()
const
14766 if (value_ref ==
nullptr)
14768 return std::move(owned_value);
14773 value_type
const& operator*()
const
14775 return value_ref ? *value_ref : owned_value;
14778 value_type
const* operator->()
const
14784 mutable value_type owned_value =
nullptr;
14785 value_type
const* value_ref =
nullptr;
14789NLOHMANN_JSON_NAMESPACE_END
14812#include <algorithm>
14838#include <algorithm>
14853NLOHMANN_JSON_NAMESPACE_BEGIN
14858template<
typename CharType>
struct output_adapter_protocol
14860 virtual void write_character(CharType c) = 0;
14861 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
14862 virtual ~output_adapter_protocol() =
default;
14864 output_adapter_protocol() =
default;
14865 output_adapter_protocol(
const output_adapter_protocol&) =
default;
14866 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
14867 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
14868 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
14872template<typename CharType>
14873using output_adapter_t =
std::shared_ptr<output_adapter_protocol<CharType>>;
14876template<typename CharType, typename AllocatorType =
std::allocator<CharType>>
14877class output_vector_adapter : public output_adapter_protocol<CharType>
14880 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
14884 void write_character(CharType c)
override
14889 JSON_HEDLEY_NON_NULL(2)
14890 void write_characters(const CharType* s,
std::
size_t length)
override
14892 v.insert(v.end(), s, s + length);
14896 std::vector<CharType, AllocatorType>& v;
14901template<
typename CharType>
14902class output_stream_adapter :
public output_adapter_protocol<CharType>
14905 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
14909 void write_character(CharType c)
override
14914 JSON_HEDLEY_NON_NULL(2)
14915 void write_characters(const CharType* s,
std::
size_t length)
override
14917 stream.write(s,
static_cast<std::streamsize
>(length));
14921 std::basic_ostream<CharType>& stream;
14926template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
14927class output_string_adapter :
public output_adapter_protocol<CharType>
14930 explicit output_string_adapter(StringType& s) noexcept
14934 void write_character(CharType c)
override
14939 JSON_HEDLEY_NON_NULL(2)
14940 void write_characters(const CharType* s,
std::
size_t length)
override
14942 str.append(s, length);
14949template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
14950class output_adapter
14953 template<
typename AllocatorType = std::allocator<CharType>>
14954 output_adapter(std::vector<CharType, AllocatorType>& vec)
14955 : oa(
std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
14958 output_adapter(std::basic_ostream<CharType>& s)
14959 : oa(
std::make_shared<output_stream_adapter<CharType>>(s)) {}
14962 output_adapter(StringType& s)
14963 : oa(
std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
14965 operator output_adapter_t<CharType>()
14971 output_adapter_t<CharType> oa =
nullptr;
14975NLOHMANN_JSON_NAMESPACE_END
14980NLOHMANN_JSON_NAMESPACE_BEGIN
14991template<
typename BasicJsonType,
typename CharType>
14994 using string_t =
typename BasicJsonType::string_t;
14995 using binary_t =
typename BasicJsonType::binary_t;
14996 using number_float_t =
typename BasicJsonType::number_float_t;
15004 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(
std::move(adapter))
15013 void write_bson(
const BasicJsonType& j)
15017 case value_t::object:
15019 write_bson_object(*j.m_value.object);
15023 case value_t::null:
15024 case value_t::array:
15025 case value_t::string:
15026 case value_t::boolean:
15027 case value_t::number_integer:
15028 case value_t::number_unsigned:
15029 case value_t::number_float:
15030 case value_t::binary:
15031 case value_t::discarded:
15034 JSON_THROW(type_error::create(317, concat(
"to serialize to BSON, top-level type must be object, but is ", j.type_name()), &j));
15042 void write_cbor(
const BasicJsonType& j)
15046 case value_t::null:
15048 oa->write_character(to_char_type(0xF6));
15052 case value_t::boolean:
15054 oa->write_character(j.m_value.boolean
15055 ? to_char_type(0xF5)
15056 : to_char_type(0xF4));
15060 case value_t::number_integer:
15062 if (j.m_value.number_integer >= 0)
15067 if (j.m_value.number_integer <= 0x17)
15069 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15071 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
15073 oa->write_character(to_char_type(0x18));
15074 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15076 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
15078 oa->write_character(to_char_type(0x19));
15079 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
15081 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
15083 oa->write_character(to_char_type(0x1A));
15084 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
15088 oa->write_character(to_char_type(0x1B));
15089 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
15096 const auto positive_number = -1 - j.m_value.number_integer;
15097 if (j.m_value.number_integer >= -24)
15099 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
15101 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
15103 oa->write_character(to_char_type(0x38));
15104 write_number(
static_cast<std::uint8_t
>(positive_number));
15106 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
15108 oa->write_character(to_char_type(0x39));
15109 write_number(
static_cast<std::uint16_t
>(positive_number));
15111 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
15113 oa->write_character(to_char_type(0x3A));
15114 write_number(
static_cast<std::uint32_t
>(positive_number));
15118 oa->write_character(to_char_type(0x3B));
15119 write_number(
static_cast<std::uint64_t
>(positive_number));
15125 case value_t::number_unsigned:
15127 if (j.m_value.number_unsigned <= 0x17)
15129 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
15131 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15133 oa->write_character(to_char_type(0x18));
15134 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
15136 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15138 oa->write_character(to_char_type(0x19));
15139 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
15141 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15143 oa->write_character(to_char_type(0x1A));
15144 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
15148 oa->write_character(to_char_type(0x1B));
15149 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
15154 case value_t::number_float:
15156 if (std::isnan(j.m_value.number_float))
15159 oa->write_character(to_char_type(0xF9));
15160 oa->write_character(to_char_type(0x7E));
15161 oa->write_character(to_char_type(0x00));
15163 else if (std::isinf(j.m_value.number_float))
15166 oa->write_character(to_char_type(0xf9));
15167 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
15168 oa->write_character(to_char_type(0x00));
15172 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
15177 case value_t::string:
15180 const auto N = j.m_value.string->size();
15183 write_number(
static_cast<std::uint8_t
>(0x60 + N));
15185 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15187 oa->write_character(to_char_type(0x78));
15188 write_number(
static_cast<std::uint8_t
>(N));
15190 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15192 oa->write_character(to_char_type(0x79));
15193 write_number(
static_cast<std::uint16_t
>(N));
15195 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15197 oa->write_character(to_char_type(0x7A));
15198 write_number(
static_cast<std::uint32_t
>(N));
15201 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15203 oa->write_character(to_char_type(0x7B));
15204 write_number(
static_cast<std::uint64_t
>(N));
15209 oa->write_characters(
15210 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
15211 j.m_value.string->size());
15215 case value_t::array:
15218 const auto N = j.m_value.array->size();
15221 write_number(
static_cast<std::uint8_t
>(0x80 + N));
15223 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15225 oa->write_character(to_char_type(0x98));
15226 write_number(
static_cast<std::uint8_t
>(N));
15228 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15230 oa->write_character(to_char_type(0x99));
15231 write_number(
static_cast<std::uint16_t
>(N));
15233 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15235 oa->write_character(to_char_type(0x9A));
15236 write_number(
static_cast<std::uint32_t
>(N));
15239 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15241 oa->write_character(to_char_type(0x9B));
15242 write_number(
static_cast<std::uint64_t
>(N));
15247 for (
const auto& el : *j.m_value.
array)
15254 case value_t::binary:
15256 if (j.m_value.binary->has_subtype())
15258 if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
15260 write_number(
static_cast<std::uint8_t
>(0xd8));
15261 write_number(
static_cast<std::uint8_t
>(j.m_value.binary->subtype()));
15263 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
15265 write_number(
static_cast<std::uint8_t
>(0xd9));
15266 write_number(
static_cast<std::uint16_t
>(j.m_value.binary->subtype()));
15268 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
15270 write_number(
static_cast<std::uint8_t
>(0xda));
15271 write_number(
static_cast<std::uint32_t
>(j.m_value.binary->subtype()));
15273 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
15275 write_number(
static_cast<std::uint8_t
>(0xdb));
15276 write_number(
static_cast<std::uint64_t
>(j.m_value.binary->subtype()));
15281 const auto N = j.m_value.binary->size();
15284 write_number(
static_cast<std::uint8_t
>(0x40 + N));
15286 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15288 oa->write_character(to_char_type(0x58));
15289 write_number(
static_cast<std::uint8_t
>(N));
15291 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15293 oa->write_character(to_char_type(0x59));
15294 write_number(
static_cast<std::uint16_t
>(N));
15296 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15298 oa->write_character(to_char_type(0x5A));
15299 write_number(
static_cast<std::uint32_t
>(N));
15302 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15304 oa->write_character(to_char_type(0x5B));
15305 write_number(
static_cast<std::uint64_t
>(N));
15310 oa->write_characters(
15311 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
15317 case value_t::object:
15320 const auto N = j.m_value.object->size();
15323 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
15325 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15327 oa->write_character(to_char_type(0xB8));
15328 write_number(
static_cast<std::uint8_t
>(N));
15330 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15332 oa->write_character(to_char_type(0xB9));
15333 write_number(
static_cast<std::uint16_t
>(N));
15335 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15337 oa->write_character(to_char_type(0xBA));
15338 write_number(
static_cast<std::uint32_t
>(N));
15341 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
15343 oa->write_character(to_char_type(0xBB));
15344 write_number(
static_cast<std::uint64_t
>(N));
15349 for (
const auto& el : *j.m_value.
object)
15351 write_cbor(el.first);
15352 write_cbor(el.second);
15357 case value_t::discarded:
15366 void write_msgpack(
const BasicJsonType& j)
15370 case value_t::null:
15372 oa->write_character(to_char_type(0xC0));
15376 case value_t::boolean:
15378 oa->write_character(j.m_value.boolean
15379 ? to_char_type(0xC3)
15380 : to_char_type(0xC2));
15384 case value_t::number_integer:
15386 if (j.m_value.number_integer >= 0)
15391 if (j.m_value.number_unsigned < 128)
15394 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15396 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15399 oa->write_character(to_char_type(0xCC));
15400 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15402 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15405 oa->write_character(to_char_type(0xCD));
15406 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
15408 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15411 oa->write_character(to_char_type(0xCE));
15412 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
15414 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15417 oa->write_character(to_char_type(0xCF));
15418 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
15423 if (j.m_value.number_integer >= -32)
15426 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
15428 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
15429 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
15432 oa->write_character(to_char_type(0xD0));
15433 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
15435 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
15436 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
15439 oa->write_character(to_char_type(0xD1));
15440 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
15442 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
15443 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
15446 oa->write_character(to_char_type(0xD2));
15447 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
15449 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
15450 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
15453 oa->write_character(to_char_type(0xD3));
15454 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
15460 case value_t::number_unsigned:
15462 if (j.m_value.number_unsigned < 128)
15465 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15467 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
15470 oa->write_character(to_char_type(0xCC));
15471 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
15473 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
15476 oa->write_character(to_char_type(0xCD));
15477 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
15479 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
15482 oa->write_character(to_char_type(0xCE));
15483 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
15485 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
15488 oa->write_character(to_char_type(0xCF));
15489 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
15494 case value_t::number_float:
15496 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
15500 case value_t::string:
15503 const auto N = j.m_value.string->size();
15507 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
15509 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
15512 oa->write_character(to_char_type(0xD9));
15513 write_number(
static_cast<std::uint8_t
>(N));
15515 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15518 oa->write_character(to_char_type(0xDA));
15519 write_number(
static_cast<std::uint16_t
>(N));
15521 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15524 oa->write_character(to_char_type(0xDB));
15525 write_number(
static_cast<std::uint32_t
>(N));
15529 oa->write_characters(
15530 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
15531 j.m_value.string->size());
15535 case value_t::array:
15538 const auto N = j.m_value.array->size();
15542 write_number(
static_cast<std::uint8_t
>(0x90 | N));
15544 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15547 oa->write_character(to_char_type(0xDC));
15548 write_number(
static_cast<std::uint16_t
>(N));
15550 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15553 oa->write_character(to_char_type(0xDD));
15554 write_number(
static_cast<std::uint32_t
>(N));
15558 for (
const auto& el : *j.m_value.
array)
15565 case value_t::binary:
15569 const bool use_ext = j.m_value.binary->has_subtype();
15572 const auto N = j.m_value.binary->size();
15573 if (N <= (std::numeric_limits<std::uint8_t>::max)())
15575 std::uint8_t output_type{};
15582 output_type = 0xD4;
15585 output_type = 0xD5;
15588 output_type = 0xD6;
15591 output_type = 0xD7;
15594 output_type = 0xD8;
15597 output_type = 0xC7;
15605 output_type = 0xC4;
15609 oa->write_character(to_char_type(output_type));
15612 write_number(
static_cast<std::uint8_t
>(N));
15615 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15617 const std::uint8_t output_type = use_ext
15621 oa->write_character(to_char_type(output_type));
15622 write_number(
static_cast<std::uint16_t
>(N));
15624 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15626 const std::uint8_t output_type = use_ext
15630 oa->write_character(to_char_type(output_type));
15631 write_number(
static_cast<std::uint32_t
>(N));
15637 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
15641 oa->write_characters(
15642 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
15648 case value_t::object:
15651 const auto N = j.m_value.object->size();
15655 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
15657 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
15660 oa->write_character(to_char_type(0xDE));
15661 write_number(
static_cast<std::uint16_t
>(N));
15663 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
15666 oa->write_character(to_char_type(0xDF));
15667 write_number(
static_cast<std::uint32_t
>(N));
15671 for (
const auto& el : *j.m_value.
object)
15673 write_msgpack(el.first);
15674 write_msgpack(el.second);
15679 case value_t::discarded:
15692 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
15693 const bool use_type,
const bool add_prefix =
true,
15694 const bool use_bjdata =
false)
15698 case value_t::null:
15702 oa->write_character(to_char_type(
'Z'));
15707 case value_t::boolean:
15711 oa->write_character(j.m_value.boolean
15712 ? to_char_type(
'T')
15713 : to_char_type(
'F'));
15718 case value_t::number_integer:
15720 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix, use_bjdata);
15724 case value_t::number_unsigned:
15726 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix, use_bjdata);
15730 case value_t::number_float:
15732 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix, use_bjdata);
15736 case value_t::string:
15740 oa->write_character(to_char_type(
'S'));
15742 write_number_with_ubjson_prefix(j.m_value.string->size(),
true, use_bjdata);
15743 oa->write_characters(
15744 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
15745 j.m_value.string->size());
15749 case value_t::array:
15753 oa->write_character(to_char_type(
'['));
15756 bool prefix_required =
true;
15757 if (use_type && !j.m_value.array->empty())
15759 JSON_ASSERT(use_count);
15760 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15761 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
15762 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15764 return ubjson_prefix(v, use_bjdata) == first_prefix;
15767 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15769 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15771 prefix_required =
false;
15772 oa->write_character(to_char_type(
'$'));
15773 oa->write_character(first_prefix);
15779 oa->write_character(to_char_type(
'#'));
15780 write_number_with_ubjson_prefix(j.m_value.array->size(),
true, use_bjdata);
15783 for (
const auto& el : *j.m_value.
array)
15785 write_ubjson(el, use_count, use_type, prefix_required, use_bjdata);
15790 oa->write_character(to_char_type(
']'));
15796 case value_t::binary:
15800 oa->write_character(to_char_type(
'['));
15803 if (use_type && !j.m_value.binary->empty())
15805 JSON_ASSERT(use_count);
15806 oa->write_character(to_char_type(
'$'));
15807 oa->write_character(
'U');
15812 oa->write_character(to_char_type(
'#'));
15813 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true, use_bjdata);
15818 oa->write_characters(
15819 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
15820 j.m_value.binary->size());
15824 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
15826 oa->write_character(to_char_type(
'U'));
15827 oa->write_character(j.m_value.binary->data()[i]);
15833 oa->write_character(to_char_type(
']'));
15839 case value_t::object:
15841 if (use_bjdata && j.m_value.object->size() == 3 && j.m_value.object->find(
"_ArrayType_") != j.m_value.object->end() && j.m_value.object->find(
"_ArraySize_") != j.m_value.object->end() && j.m_value.object->find(
"_ArrayData_") != j.m_value.object->end())
15843 if (!write_bjdata_ndarray(*j.m_value.object, use_count, use_type))
15851 oa->write_character(to_char_type(
'{'));
15854 bool prefix_required =
true;
15855 if (use_type && !j.m_value.object->empty())
15857 JSON_ASSERT(use_count);
15858 const CharType first_prefix = ubjson_prefix(j.front(), use_bjdata);
15859 const bool same_prefix = std::all_of(j.begin(), j.end(),
15860 [
this, first_prefix, use_bjdata](
const BasicJsonType & v)
15862 return ubjson_prefix(v, use_bjdata) == first_prefix;
15865 std::vector<CharType> bjdx = {
'[',
'{',
'S',
'H',
'T',
'F',
'N',
'Z'};
15867 if (same_prefix && !(use_bjdata && std::find(bjdx.begin(), bjdx.end(), first_prefix) != bjdx.end()))
15869 prefix_required =
false;
15870 oa->write_character(to_char_type(
'$'));
15871 oa->write_character(first_prefix);
15877 oa->write_character(to_char_type(
'#'));
15878 write_number_with_ubjson_prefix(j.m_value.object->size(),
true, use_bjdata);
15881 for (
const auto& el : *j.m_value.
object)
15883 write_number_with_ubjson_prefix(el.first.size(),
true, use_bjdata);
15884 oa->write_characters(
15885 reinterpret_cast<const CharType*
>(el.first.c_str()),
15887 write_ubjson(el.second, use_count, use_type, prefix_required, use_bjdata);
15892 oa->write_character(to_char_type(
'}'));
15898 case value_t::discarded:
15913 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
15915 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
15916 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
15918 JSON_THROW(out_of_range::create(409, concat(
"BSON key cannot contain code point U+0000 (at byte ", std::to_string(it),
")"), &j));
15919 static_cast<void>(j);
15922 return 1ul + name.size() + 1u;
15928 void write_bson_entry_header(
const string_t& name,
15929 const std::uint8_t element_type)
15931 oa->write_character(to_char_type(element_type));
15932 oa->write_characters(
15933 reinterpret_cast<const CharType*
>(name.c_str()),
15940 void write_bson_boolean(
const string_t& name,
15943 write_bson_entry_header(name, 0x08);
15944 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
15950 void write_bson_double(
const string_t& name,
15951 const double value)
15953 write_bson_entry_header(name, 0x01);
15954 write_number<double>(value,
true);
15960 static std::size_t calc_bson_string_size(
const string_t& value)
15962 return sizeof(std::int32_t) + value.size() + 1ul;
15968 void write_bson_string(
const string_t& name,
15969 const string_t& value)
15971 write_bson_entry_header(name, 0x02);
15973 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size() + 1ul),
true);
15974 oa->write_characters(
15975 reinterpret_cast<const CharType*
>(value.c_str()),
15982 void write_bson_null(
const string_t& name)
15984 write_bson_entry_header(name, 0x0A);
15990 static std::size_t calc_bson_integer_size(
const std::int64_t value)
15992 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
15993 ?
sizeof(std::int32_t)
15994 :
sizeof(std::int64_t);
16000 void write_bson_integer(
const string_t& name,
16001 const std::int64_t value)
16003 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
16005 write_bson_entry_header(name, 0x10);
16006 write_number<std::int32_t>(
static_cast<std::int32_t
>(value),
true);
16010 write_bson_entry_header(name, 0x12);
16011 write_number<std::int64_t>(
static_cast<std::int64_t
>(value),
true);
16018 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
16020 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16021 ?
sizeof(std::int32_t)
16022 : sizeof(
std::int64_t);
16028 void write_bson_unsigned(
const string_t& name,
16029 const BasicJsonType& j)
16031 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16033 write_bson_entry_header(name, 0x10 );
16034 write_number<std::int32_t>(
static_cast<std::int32_t
>(j.m_value.number_unsigned),
true);
16036 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16038 write_bson_entry_header(name, 0x12 );
16039 write_number<std::int64_t>(
static_cast<std::int64_t
>(j.m_value.number_unsigned),
true);
16043 JSON_THROW(out_of_range::create(407, concat(
"integer number ", std::to_string(j.m_value.number_unsigned),
" cannot be represented by BSON as it does not fit int64"), &j));
16050 void write_bson_object_entry(
const string_t& name,
16051 const typename BasicJsonType::object_t& value)
16053 write_bson_entry_header(name, 0x03);
16054 write_bson_object(value);
16060 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
16062 std::size_t array_index = 0ul;
16064 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)
16066 return result + calc_bson_element_size(std::to_string(array_index++), el);
16069 return sizeof(std::int32_t) + embedded_document_size + 1ul;
16075 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
16077 return sizeof(std::int32_t) + value.size() + 1ul;
16083 void write_bson_array(
const string_t& name,
16084 const typename BasicJsonType::array_t& value)
16086 write_bson_entry_header(name, 0x04);
16087 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_array_size(value)),
true);
16089 std::size_t array_index = 0ul;
16091 for (
const auto& el : value)
16093 write_bson_element(std::to_string(array_index++), el);
16096 oa->write_character(to_char_type(0x00));
16102 void write_bson_binary(
const string_t& name,
16103 const binary_t& value)
16105 write_bson_entry_header(name, 0x05);
16107 write_number<std::int32_t>(
static_cast<std::int32_t
>(value.size()),
true);
16108 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) : static_cast<
std::uint8_t>(0x00));
16110 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
16117 static std::size_t calc_bson_element_size(
const string_t& name,
16118 const BasicJsonType& j)
16120 const auto header_size = calc_bson_entry_header_size(name, j);
16123 case value_t::object:
16124 return header_size + calc_bson_object_size(*j.m_value.object);
16126 case value_t::array:
16127 return header_size + calc_bson_array_size(*j.m_value.array);
16129 case value_t::binary:
16130 return header_size + calc_bson_binary_size(*j.m_value.binary);
16132 case value_t::boolean:
16133 return header_size + 1ul;
16135 case value_t::number_float:
16136 return header_size + 8ul;
16138 case value_t::number_integer:
16139 return header_size + calc_bson_integer_size(j.m_value.number_integer);
16141 case value_t::number_unsigned:
16142 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
16144 case value_t::string:
16145 return header_size + calc_bson_string_size(*j.m_value.string);
16147 case value_t::null:
16148 return header_size + 0ul;
16151 case value_t::discarded:
16153 JSON_ASSERT(
false);
16165 void write_bson_element(
const string_t& name,
16166 const BasicJsonType& j)
16170 case value_t::object:
16171 return write_bson_object_entry(name, *j.m_value.object);
16173 case value_t::array:
16174 return write_bson_array(name, *j.m_value.array);
16176 case value_t::binary:
16177 return write_bson_binary(name, *j.m_value.binary);
16179 case value_t::boolean:
16180 return write_bson_boolean(name, j.m_value.boolean);
16182 case value_t::number_float:
16183 return write_bson_double(name, j.m_value.number_float);
16185 case value_t::number_integer:
16186 return write_bson_integer(name, j.m_value.number_integer);
16188 case value_t::number_unsigned:
16189 return write_bson_unsigned(name, j);
16191 case value_t::string:
16192 return write_bson_string(name, *j.m_value.string);
16194 case value_t::null:
16195 return write_bson_null(name);
16198 case value_t::discarded:
16200 JSON_ASSERT(
false);
16212 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
16214 const std::size_t document_size = std::accumulate(value.begin(), value.end(),
static_cast<std::size_t
>(0),
16215 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
16217 return result += calc_bson_element_size(el.first, el.second);
16220 return sizeof(std::int32_t) + document_size + 1ul;
16227 void write_bson_object(
const typename BasicJsonType::object_t& value)
16229 write_number<std::int32_t>(
static_cast<std::int32_t
>(calc_bson_object_size(value)),
true);
16231 for (
const auto& el : value)
16233 write_bson_element(el.first, el.second);
16236 oa->write_character(to_char_type(0x00));
16243 static constexpr CharType get_cbor_float_prefix(
float )
16245 return to_char_type(0xFA);
16248 static constexpr CharType get_cbor_float_prefix(
double )
16250 return to_char_type(0xFB);
16257 static constexpr CharType get_msgpack_float_prefix(
float )
16259 return to_char_type(0xCA);
16262 static constexpr CharType get_msgpack_float_prefix(
double )
16264 return to_char_type(0xCB);
16272 template<
typename NumberType,
typename std::enable_if<
16273 std::is_floating_point<NumberType>::value,
int>::type = 0>
16274 void write_number_with_ubjson_prefix(
const NumberType n,
16275 const bool add_prefix,
16276 const bool use_bjdata)
16280 oa->write_character(get_ubjson_float_prefix(n));
16282 write_number(n, use_bjdata);
16286 template<
typename NumberType,
typename std::enable_if<
16287 std::is_unsigned<NumberType>::value,
int>::type = 0>
16288 void write_number_with_ubjson_prefix(
const NumberType n,
16289 const bool add_prefix,
16290 const bool use_bjdata)
16292 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16296 oa->write_character(to_char_type(
'i'));
16298 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16300 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
16304 oa->write_character(to_char_type(
'U'));
16306 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16308 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16312 oa->write_character(to_char_type(
'I'));
16314 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16316 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint16_t>::max)()))
16320 oa->write_character(to_char_type(
'u'));
16322 write_number(
static_cast<std::uint16_t
>(n), use_bjdata);
16324 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16328 oa->write_character(to_char_type(
'l'));
16330 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16332 else if (use_bjdata && n <=
static_cast<uint64_t
>((std::numeric_limits<uint32_t>::max)()))
16336 oa->write_character(to_char_type(
'm'));
16338 write_number(
static_cast<std::uint32_t
>(n), use_bjdata);
16340 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16344 oa->write_character(to_char_type(
'L'));
16346 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16348 else if (use_bjdata && n <= (std::numeric_limits<uint64_t>::max)())
16352 oa->write_character(to_char_type(
'M'));
16354 write_number(
static_cast<std::uint64_t
>(n), use_bjdata);
16360 oa->write_character(to_char_type(
'H'));
16363 const auto number = BasicJsonType(n).dump();
16364 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16365 for (std::size_t i = 0; i < number.size(); ++i)
16367 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16373 template <
typename NumberType,
typename std::enable_if <
16374 std::is_signed<NumberType>::value&&
16375 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
16376 void write_number_with_ubjson_prefix(
const NumberType n,
16377 const bool add_prefix,
16378 const bool use_bjdata)
16380 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
16384 oa->write_character(to_char_type(
'i'));
16386 write_number(
static_cast<std::int8_t
>(n), use_bjdata);
16388 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)()))
16392 oa->write_character(to_char_type(
'U'));
16394 write_number(
static_cast<std::uint8_t
>(n), use_bjdata);
16396 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
16400 oa->write_character(to_char_type(
'I'));
16402 write_number(
static_cast<std::int16_t
>(n), use_bjdata);
16404 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)())))
16408 oa->write_character(to_char_type(
'u'));
16410 write_number(
static_cast<uint16_t
>(n), use_bjdata);
16412 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
16416 oa->write_character(to_char_type(
'l'));
16418 write_number(
static_cast<std::int32_t
>(n), use_bjdata);
16420 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)())))
16424 oa->write_character(to_char_type(
'm'));
16426 write_number(
static_cast<uint32_t
>(n), use_bjdata);
16428 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
16432 oa->write_character(to_char_type(
'L'));
16434 write_number(
static_cast<std::int64_t
>(n), use_bjdata);
16441 oa->write_character(to_char_type(
'H'));
16444 const auto number = BasicJsonType(n).dump();
16445 write_number_with_ubjson_prefix(number.size(),
true, use_bjdata);
16446 for (std::size_t i = 0; i < number.size(); ++i)
16448 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
16457 CharType ubjson_prefix(
const BasicJsonType& j,
const bool use_bjdata)
const noexcept
16461 case value_t::null:
16464 case value_t::boolean:
16465 return j.m_value.boolean ?
'T' :
'F';
16467 case value_t::number_integer:
16469 if ((std::numeric_limits<std::int8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
16473 if ((std::numeric_limits<std::uint8_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
16477 if ((std::numeric_limits<std::int16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
16481 if (use_bjdata && ((std::numeric_limits<std::uint16_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)()))
16485 if ((std::numeric_limits<std::int32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
16489 if (use_bjdata && ((std::numeric_limits<std::uint32_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)()))
16493 if ((std::numeric_limits<std::int64_t>::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
16501 case value_t::number_unsigned:
16503 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
16507 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
16511 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
16515 if (use_bjdata && j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint16_t>::max)()))
16519 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
16523 if (use_bjdata && j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint32_t>::max)()))
16527 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
16531 if (use_bjdata && j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
16539 case value_t::number_float:
16540 return get_ubjson_float_prefix(j.m_value.number_float);
16542 case value_t::string:
16545 case value_t::array:
16546 case value_t::binary:
16549 case value_t::object:
16552 case value_t::discarded:
16558 static constexpr CharType get_ubjson_float_prefix(
float )
16563 static constexpr CharType get_ubjson_float_prefix(
double )
16571 bool write_bjdata_ndarray(
const typename BasicJsonType::object_t& value,
const bool use_count,
const bool use_type)
16573 std::map<string_t, CharType> bjdtype = {{
"uint8",
'U'}, {
"int8",
'i'}, {
"uint16",
'u'}, {
"int16",
'I'},
16574 {
"uint32",
'm'}, {
"int32",
'l'}, {
"uint64",
'M'}, {
"int64",
'L'}, {
"single",
'd'}, {
"double",
'D'}, {
"char",
'C'}
16577 string_t key =
"_ArrayType_";
16578 auto it = bjdtype.find(
static_cast<string_t
>(value.at(key)));
16579 if (it == bjdtype.end())
16583 CharType dtype = it->second;
16585 key =
"_ArraySize_";
16586 std::size_t len = (value.at(key).empty() ? 0 : 1);
16587 for (
const auto& el : value.at(key))
16589 len *=
static_cast<std::size_t
>(el.m_value.number_unsigned);
16592 key =
"_ArrayData_";
16593 if (value.at(key).size() != len)
16598 oa->write_character(
'[');
16599 oa->write_character(
'$');
16600 oa->write_character(dtype);
16601 oa->write_character(
'#');
16603 key =
"_ArraySize_";
16604 write_ubjson(value.at(key), use_count, use_type,
true,
true);
16606 key =
"_ArrayData_";
16607 if (dtype ==
'U' || dtype ==
'C')
16609 for (
const auto& el : value.at(key))
16611 write_number(
static_cast<std::uint8_t
>(el.m_value.number_unsigned),
true);
16614 else if (dtype ==
'i')
16616 for (
const auto& el : value.at(key))
16618 write_number(
static_cast<std::int8_t
>(el.m_value.number_integer),
true);
16621 else if (dtype ==
'u')
16623 for (
const auto& el : value.at(key))
16625 write_number(
static_cast<std::uint16_t
>(el.m_value.number_unsigned),
true);
16628 else if (dtype ==
'I')
16630 for (
const auto& el : value.at(key))
16632 write_number(
static_cast<std::int16_t
>(el.m_value.number_integer),
true);
16635 else if (dtype ==
'm')
16637 for (
const auto& el : value.at(key))
16639 write_number(
static_cast<std::uint32_t
>(el.m_value.number_unsigned),
true);
16642 else if (dtype ==
'l')
16644 for (
const auto& el : value.at(key))
16646 write_number(
static_cast<std::int32_t
>(el.m_value.number_integer),
true);
16649 else if (dtype ==
'M')
16651 for (
const auto& el : value.at(key))
16653 write_number(
static_cast<std::uint64_t
>(el.m_value.number_unsigned),
true);
16656 else if (dtype ==
'L')
16658 for (
const auto& el : value.at(key))
16660 write_number(
static_cast<std::int64_t
>(el.m_value.number_integer),
true);
16663 else if (dtype ==
'd')
16665 for (
const auto& el : value.at(key))
16667 write_number(
static_cast<float>(el.m_value.number_float),
true);
16670 else if (dtype ==
'D')
16672 for (
const auto& el : value.at(key))
16674 write_number(
static_cast<double>(el.m_value.number_float),
true);
16697 template<
typename NumberType>
16698 void write_number(
const NumberType n,
const bool OutputIsLittleEndian =
false)
16701 std::array<CharType,
sizeof(NumberType)> vec{};
16702 std::memcpy(vec.data(), &n,
sizeof(NumberType));
16705 if (is_little_endian != OutputIsLittleEndian)
16708 std::reverse(vec.begin(), vec.end());
16711 oa->write_characters(vec.data(),
sizeof(NumberType));
16714 void write_compact_float(
const number_float_t n, detail::input_format_t format)
16717#pragma GCC diagnostic push
16718#pragma GCC diagnostic ignored "-Wfloat-equal"
16720 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
16721 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
16722 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
16724 oa->write_character(format == detail::input_format_t::cbor
16725 ? get_cbor_float_prefix(
static_cast<float>(n))
16726 : get_msgpack_float_prefix(static_cast<float>(n)));
16727 write_number(
static_cast<float>(n));
16731 oa->write_character(format == detail::input_format_t::cbor
16732 ? get_cbor_float_prefix(n)
16733 : get_msgpack_float_prefix(n));
16737#pragma GCC diagnostic pop
16746 template <
typename C = CharType,
16747 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
16748 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16750 return *
reinterpret_cast<char*
>(&x);
16753 template <
typename C = CharType,
16754 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
16755 static CharType to_char_type(std::uint8_t x)
noexcept
16757 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
16758 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
16760 std::memcpy(&result, &x,
sizeof(x));
16764 template<
typename C = CharType,
16765 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
16766 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
16771 template <
typename InputCharType,
typename C = CharType,
16773 std::is_signed<C>::value &&
16774 std::is_signed<char>::value &&
16775 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
16777 static constexpr CharType to_char_type(InputCharType x)
noexcept
16784 const bool is_little_endian = little_endianness();
16787 output_adapter_t<CharType> oa =
nullptr;
16791NLOHMANN_JSON_NAMESPACE_END
16807#include <algorithm>
16817#include <type_traits>
16837#include <type_traits>
16842NLOHMANN_JSON_NAMESPACE_BEGIN
16868template<
typename Target,
typename Source>
16869Target reinterpret_bits(
const Source source)
16871 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
16874 std::memcpy(&target, &source,
sizeof(Source));
16880 static constexpr int kPrecision = 64;
16882 std::uint64_t f = 0;
16885 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
16891 static diyfp sub(
const diyfp& x,
const diyfp& y)
noexcept
16893 JSON_ASSERT(x.e == y.e);
16894 JSON_ASSERT(x.f >= y.f);
16896 return {x.f - y.f, x.e};
16903 static diyfp mul(
const diyfp& x,
const diyfp& y)
noexcept
16905 static_assert(kPrecision == 64,
"internal error");
16930 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
16931 const std::uint64_t u_hi = x.f >> 32u;
16932 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
16933 const std::uint64_t v_hi = y.f >> 32u;
16935 const std::uint64_t p0 = u_lo * v_lo;
16936 const std::uint64_t p1 = u_lo * v_hi;
16937 const std::uint64_t p2 = u_hi * v_lo;
16938 const std::uint64_t p3 = u_hi * v_hi;
16940 const std::uint64_t p0_hi = p0 >> 32u;
16941 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
16942 const std::uint64_t p1_hi = p1 >> 32u;
16943 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
16944 const std::uint64_t p2_hi = p2 >> 32u;
16946 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
16957 Q += std::uint64_t{1} << (64u - 32u - 1u);
16959 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
16961 return {h, x.e + y.e + 64};
16968 static diyfp normalize(diyfp x)
noexcept
16970 JSON_ASSERT(x.f != 0);
16972 while ((x.f >> 63u) == 0)
16985 static diyfp normalize_to(
const diyfp& x,
const int target_exponent)
noexcept
16987 const int delta = x.e - target_exponent;
16989 JSON_ASSERT(delta >= 0);
16990 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
16992 return {x.f << delta, target_exponent};
17009template<
typename FloatType>
17010boundaries compute_boundaries(FloatType value)
17012 JSON_ASSERT(std::isfinite(value));
17013 JSON_ASSERT(value > 0);
17022 static_assert(std::numeric_limits<FloatType>::is_iec559,
17023 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
17025 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
17026 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
17027 constexpr int kMinExp = 1 - kBias;
17028 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
17030 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
17032 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
17033 const std::uint64_t E = bits >> (kPrecision - 1);
17034 const std::uint64_t F = bits & (kHiddenBit - 1);
17036 const bool is_denormal = E == 0;
17037 const diyfp v = is_denormal
17038 ? diyfp(F, kMinExp)
17039 : diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
17062 const bool lower_boundary_is_closer = F == 0 && E > 1;
17063 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
17064 const diyfp m_minus = lower_boundary_is_closer
17065 ? diyfp(4 * v.f - 1, v.e - 2)
17066 : diyfp(2 * v.f - 1, v.e - 1);
17069 const diyfp w_plus = diyfp::normalize(m_plus);
17072 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
17074 return {diyfp::normalize(v), w_minus, w_plus};
17132constexpr int kAlpha = -60;
17133constexpr int kGamma = -32;
17149inline cached_power get_cached_power_for_binary_exponent(
int e)
17201 constexpr int kCachedPowersMinDecExp = -300;
17202 constexpr int kCachedPowersDecStep = 8;
17204 static constexpr std::array<cached_power, 79> kCachedPowers =
17207 { 0xAB70FE17C79AC6CA, -1060, -300 },
17208 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
17209 { 0xBE5691EF416BD60C, -1007, -284 },
17210 { 0x8DD01FAD907FFC3C, -980, -276 },
17211 { 0xD3515C2831559A83, -954, -268 },
17212 { 0x9D71AC8FADA6C9B5, -927, -260 },
17213 { 0xEA9C227723EE8BCB, -901, -252 },
17214 { 0xAECC49914078536D, -874, -244 },
17215 { 0x823C12795DB6CE57, -847, -236 },
17216 { 0xC21094364DFB5637, -821, -228 },
17217 { 0x9096EA6F3848984F, -794, -220 },
17218 { 0xD77485CB25823AC7, -768, -212 },
17219 { 0xA086CFCD97BF97F4, -741, -204 },
17220 { 0xEF340A98172AACE5, -715, -196 },
17221 { 0xB23867FB2A35B28E, -688, -188 },
17222 { 0x84C8D4DFD2C63F3B, -661, -180 },
17223 { 0xC5DD44271AD3CDBA, -635, -172 },
17224 { 0x936B9FCEBB25C996, -608, -164 },
17225 { 0xDBAC6C247D62A584, -582, -156 },
17226 { 0xA3AB66580D5FDAF6, -555, -148 },
17227 { 0xF3E2F893DEC3F126, -529, -140 },
17228 { 0xB5B5ADA8AAFF80B8, -502, -132 },
17229 { 0x87625F056C7C4A8B, -475, -124 },
17230 { 0xC9BCFF6034C13053, -449, -116 },
17231 { 0x964E858C91BA2655, -422, -108 },
17232 { 0xDFF9772470297EBD, -396, -100 },
17233 { 0xA6DFBD9FB8E5B88F, -369, -92 },
17234 { 0xF8A95FCF88747D94, -343, -84 },
17235 { 0xB94470938FA89BCF, -316, -76 },
17236 { 0x8A08F0F8BF0F156B, -289, -68 },
17237 { 0xCDB02555653131B6, -263, -60 },
17238 { 0x993FE2C6D07B7FAC, -236, -52 },
17239 { 0xE45C10C42A2B3B06, -210, -44 },
17240 { 0xAA242499697392D3, -183, -36 },
17241 { 0xFD87B5F28300CA0E, -157, -28 },
17242 { 0xBCE5086492111AEB, -130, -20 },
17243 { 0x8CBCCC096F5088CC, -103, -12 },
17244 { 0xD1B71758E219652C, -77, -4 },
17245 { 0x9C40000000000000, -50, 4 },
17246 { 0xE8D4A51000000000, -24, 12 },
17247 { 0xAD78EBC5AC620000, 3, 20 },
17248 { 0x813F3978F8940984, 30, 28 },
17249 { 0xC097CE7BC90715B3, 56, 36 },
17250 { 0x8F7E32CE7BEA5C70, 83, 44 },
17251 { 0xD5D238A4ABE98068, 109, 52 },
17252 { 0x9F4F2726179A2245, 136, 60 },
17253 { 0xED63A231D4C4FB27, 162, 68 },
17254 { 0xB0DE65388CC8ADA8, 189, 76 },
17255 { 0x83C7088E1AAB65DB, 216, 84 },
17256 { 0xC45D1DF942711D9A, 242, 92 },
17257 { 0x924D692CA61BE758, 269, 100 },
17258 { 0xDA01EE641A708DEA, 295, 108 },
17259 { 0xA26DA3999AEF774A, 322, 116 },
17260 { 0xF209787BB47D6B85, 348, 124 },
17261 { 0xB454E4A179DD1877, 375, 132 },
17262 { 0x865B86925B9BC5C2, 402, 140 },
17263 { 0xC83553C5C8965D3D, 428, 148 },
17264 { 0x952AB45CFA97A0B3, 455, 156 },
17265 { 0xDE469FBD99A05FE3, 481, 164 },
17266 { 0xA59BC234DB398C25, 508, 172 },
17267 { 0xF6C69A72A3989F5C, 534, 180 },
17268 { 0xB7DCBF5354E9BECE, 561, 188 },
17269 { 0x88FCF317F22241E2, 588, 196 },
17270 { 0xCC20CE9BD35C78A5, 614, 204 },
17271 { 0x98165AF37B2153DF, 641, 212 },
17272 { 0xE2A0B5DC971F303A, 667, 220 },
17273 { 0xA8D9D1535CE3B396, 694, 228 },
17274 { 0xFB9B7CD9A4A7443C, 720, 236 },
17275 { 0xBB764C4CA7A44410, 747, 244 },
17276 { 0x8BAB8EEFB6409C1A, 774, 252 },
17277 { 0xD01FEF10A657842C, 800, 260 },
17278 { 0x9B10A4E5E9913129, 827, 268 },
17279 { 0xE7109BFBA19C0C9D, 853, 276 },
17280 { 0xAC2820D9623BF429, 880, 284 },
17281 { 0x80444B5E7AA7CF85, 907, 292 },
17282 { 0xBF21E44003ACDD2D, 933, 300 },
17283 { 0x8E679C2F5E44FF8F, 960, 308 },
17284 { 0xD433179D9C8CB841, 986, 316 },
17285 { 0x9E19DB92B4E31BA9, 1013, 324 },
17293 JSON_ASSERT(e >= -1500);
17294 JSON_ASSERT(e <= 1500);
17295 const int f = kAlpha - e - 1;
17296 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
17298 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
17299 JSON_ASSERT(index >= 0);
17300 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
17302 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
17303 JSON_ASSERT(kAlpha <= cached.e + e + 64);
17304 JSON_ASSERT(kGamma >= cached.e + e + 64);
17313inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
17316 if (n >= 1000000000)
17318 pow10 = 1000000000;
17322 if (n >= 100000000)
17367inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
17368 std::uint64_t rest, std::uint64_t ten_k)
17370 JSON_ASSERT(len >= 1);
17371 JSON_ASSERT(dist <= delta);
17372 JSON_ASSERT(rest <= delta);
17373 JSON_ASSERT(ten_k > 0);
17395 && delta - rest >= ten_k
17396 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
17398 JSON_ASSERT(buf[len - 1] !=
'0');
17408inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
17409 diyfp M_minus, diyfp w, diyfp M_plus)
17411 static_assert(kAlpha >= -60,
"internal error");
17412 static_assert(kGamma <= -32,
"internal error");
17426 JSON_ASSERT(M_plus.e >= kAlpha);
17427 JSON_ASSERT(M_plus.e <= kGamma);
17429 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
17430 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
17439 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
17441 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
17442 std::uint64_t p2 = M_plus.f & (one.f - 1);
17448 JSON_ASSERT(p1 > 0);
17450 std::uint32_t pow10{};
17451 const int k = find_largest_pow10(p1, pow10);
17478 const std::uint32_t d = p1 / pow10;
17479 const std::uint32_t r = p1 % pow10;
17484 JSON_ASSERT(d <= 9);
17485 buffer[length++] =
static_cast<char>(
'0' + d);
17504 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
17509 decimal_exponent += n;
17520 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
17521 grisu2_round(buffer, length, dist, delta, rest, ten_n);
17571 JSON_ASSERT(p2 > delta);
17582 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
17584 const std::uint64_t d = p2 >> -one.e;
17585 const std::uint64_t r = p2 & (one.f - 1);
17591 JSON_ASSERT(d <= 9);
17592 buffer[length++] =
static_cast<char>(
'0' + d);
17617 decimal_exponent -= m;
17625 const std::uint64_t ten_m = one.f;
17626 grisu2_round(buffer, length, dist, delta, p2, ten_m);
17648JSON_HEDLEY_NON_NULL(1)
17649inline void grisu2(
char* buf,
int& len,
int& decimal_exponent,
17650 diyfp m_minus, diyfp v, diyfp m_plus)
17652 JSON_ASSERT(m_plus.e == m_minus.e);
17653 JSON_ASSERT(m_plus.e == v.e);
17664 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
17666 const diyfp c_minus_k(cached.f, cached.e);
17669 const diyfp w = diyfp::mul(v, c_minus_k);
17670 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
17671 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
17694 const diyfp M_minus(w_minus.f + 1, w_minus.e);
17695 const diyfp M_plus (w_plus.f - 1, w_plus.e );
17697 decimal_exponent = -cached.k;
17699 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
17707template<
typename FloatType>
17708JSON_HEDLEY_NON_NULL(1)
17709void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
17711 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
17712 "internal error: not enough precision");
17714 JSON_ASSERT(std::isfinite(value));
17715 JSON_ASSERT(value > 0);
17734 const boundaries w = compute_boundaries(
static_cast<double>(value));
17736 const boundaries w = compute_boundaries(value);
17739 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
17747JSON_HEDLEY_NON_NULL(1)
17748JSON_HEDLEY_RETURNS_NON_NULL
17749inline char* append_exponent(
char* buf,
int e)
17751 JSON_ASSERT(e > -1000);
17752 JSON_ASSERT(e < 1000);
17764 auto k =
static_cast<std::uint32_t
>(e);
17770 *buf++ =
static_cast<char>(
'0' + k);
17774 *buf++ =
static_cast<char>(
'0' + k / 10);
17776 *buf++ =
static_cast<char>(
'0' + k);
17780 *buf++ =
static_cast<char>(
'0' + k / 100);
17782 *buf++ =
static_cast<char>(
'0' + k / 10);
17784 *buf++ =
static_cast<char>(
'0' + k);
17799JSON_HEDLEY_NON_NULL(1)
17800JSON_HEDLEY_RETURNS_NON_NULL
17801inline char* format_buffer(
char* buf,
int len,
int decimal_exponent,
17802 int min_exp,
int max_exp)
17804 JSON_ASSERT(min_exp < 0);
17805 JSON_ASSERT(max_exp > 0);
17808 const int n = len + decimal_exponent;
17814 if (k <= n && n <= max_exp)
17819 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
17823 return buf + (
static_cast<size_t>(n) + 2);
17826 if (0 < n && n <= max_exp)
17831 JSON_ASSERT(k > n);
17833 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
17835 return buf + (
static_cast<size_t>(k) + 1U);
17838 if (min_exp < n && n <= 0)
17843 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
17846 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
17847 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
17862 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
17864 buf += 1 +
static_cast<size_t>(k);
17868 return append_exponent(buf, n - 1);
17883template<
typename FloatType>
17884JSON_HEDLEY_NON_NULL(1, 2)
17885JSON_HEDLEY_RETURNS_NON_NULL
17886char* to_chars(
char* first, const
char* last, FloatType value)
17888 static_cast<void>(last);
17889 JSON_ASSERT(std::isfinite(value));
17892 if (std::signbit(value))
17899#pragma GCC diagnostic push
17900#pragma GCC diagnostic ignored "-Wfloat-equal"
17911#pragma GCC diagnostic pop
17914 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
17921 int decimal_exponent = 0;
17922 dtoa_impl::grisu2(first, len, decimal_exponent, value);
17924 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
17927 constexpr int kMinExp = -4;
17929 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
17931 JSON_ASSERT(last - first >= kMaxExp + 2);
17932 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
17933 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
17935 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
17939NLOHMANN_JSON_NAMESPACE_END
17956NLOHMANN_JSON_NAMESPACE_BEGIN
17972template<
typename BasicJsonType>
17975 using string_t =
typename BasicJsonType::string_t;
17976 using number_float_t =
typename BasicJsonType::number_float_t;
17977 using number_integer_t =
typename BasicJsonType::number_integer_t;
17978 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
17979 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
17980 static constexpr std::uint8_t UTF8_ACCEPT = 0;
17981 static constexpr std::uint8_t UTF8_REJECT = 1;
17992 , loc(
std::localeconv())
17993 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' :
std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
17994 , decimal_point(loc->decimal_point == nullptr ?
'\0' :
std::char_traits<char>::to_char_type(* (loc->decimal_point)))
17995 , indent_char(ichar)
17996 , indent_string(512, indent_char)
17997 , error_handler(error_handler_)
18030 const bool pretty_print,
18031 const bool ensure_ascii,
18032 const unsigned int indent_step,
18033 const unsigned int current_indent = 0)
18035 switch (val.m_type)
18037 case value_t::object:
18039 if (val.m_value.object->empty())
18041 o->write_characters(
"{}", 2);
18047 o->write_characters(
"{\n", 2);
18050 const auto new_indent = current_indent + indent_step;
18051 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18053 indent_string.resize(indent_string.size() * 2,
' ');
18057 auto i = val.m_value.object->cbegin();
18058 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
18060 o->write_characters(indent_string.c_str(), new_indent);
18061 o->write_character(
'\"');
18062 dump_escaped(i->first, ensure_ascii);
18063 o->write_characters(
"\": ", 3);
18064 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18065 o->write_characters(
",\n", 2);
18069 JSON_ASSERT(i != val.m_value.object->cend());
18070 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
18071 o->write_characters(indent_string.c_str(), new_indent);
18072 o->write_character(
'\"');
18073 dump_escaped(i->first, ensure_ascii);
18074 o->write_characters(
"\": ", 3);
18075 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
18077 o->write_character(
'\n');
18078 o->write_characters(indent_string.c_str(), current_indent);
18079 o->write_character(
'}');
18083 o->write_character(
'{');
18086 auto i = val.m_value.object->cbegin();
18087 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
18089 o->write_character(
'\"');
18090 dump_escaped(i->first, ensure_ascii);
18091 o->write_characters(
"\":", 2);
18092 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18093 o->write_character(
',');
18097 JSON_ASSERT(i != val.m_value.object->cend());
18098 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
18099 o->write_character(
'\"');
18100 dump_escaped(i->first, ensure_ascii);
18101 o->write_characters(
"\":", 2);
18102 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
18104 o->write_character(
'}');
18110 case value_t::array:
18112 if (val.m_value.array->empty())
18114 o->write_characters(
"[]", 2);
18120 o->write_characters(
"[\n", 2);
18123 const auto new_indent = current_indent + indent_step;
18124 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18126 indent_string.resize(indent_string.size() * 2,
' ');
18130 for (
auto i = val.m_value.array->cbegin();
18131 i != val.m_value.array->cend() - 1; ++i)
18133 o->write_characters(indent_string.c_str(), new_indent);
18134 dump(*i,
true, ensure_ascii, indent_step, new_indent);
18135 o->write_characters(
",\n", 2);
18139 JSON_ASSERT(!val.m_value.array->empty());
18140 o->write_characters(indent_string.c_str(), new_indent);
18141 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
18143 o->write_character(
'\n');
18144 o->write_characters(indent_string.c_str(), current_indent);
18145 o->write_character(
']');
18149 o->write_character(
'[');
18152 for (
auto i = val.m_value.array->cbegin();
18153 i != val.m_value.array->cend() - 1; ++i)
18155 dump(*i,
false, ensure_ascii, indent_step, current_indent);
18156 o->write_character(
',');
18160 JSON_ASSERT(!val.m_value.array->empty());
18161 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
18163 o->write_character(
']');
18169 case value_t::string:
18171 o->write_character(
'\"');
18172 dump_escaped(*val.m_value.string, ensure_ascii);
18173 o->write_character(
'\"');
18177 case value_t::binary:
18181 o->write_characters(
"{\n", 2);
18184 const auto new_indent = current_indent + indent_step;
18185 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
18187 indent_string.resize(indent_string.size() * 2,
' ');
18190 o->write_characters(indent_string.c_str(), new_indent);
18192 o->write_characters(
"\"bytes\": [", 10);
18194 if (!val.m_value.binary->empty())
18196 for (
auto i = val.m_value.binary->cbegin();
18197 i != val.m_value.binary->cend() - 1; ++i)
18200 o->write_characters(
", ", 2);
18202 dump_integer(val.m_value.binary->back());
18205 o->write_characters(
"],\n", 3);
18206 o->write_characters(indent_string.c_str(), new_indent);
18208 o->write_characters(
"\"subtype\": ", 11);
18209 if (val.m_value.binary->has_subtype())
18211 dump_integer(val.m_value.binary->subtype());
18215 o->write_characters(
"null", 4);
18217 o->write_character(
'\n');
18218 o->write_characters(indent_string.c_str(), current_indent);
18219 o->write_character(
'}');
18223 o->write_characters(
"{\"bytes\":[", 10);
18225 if (!val.m_value.binary->empty())
18227 for (
auto i = val.m_value.binary->cbegin();
18228 i != val.m_value.binary->cend() - 1; ++i)
18231 o->write_character(
',');
18233 dump_integer(val.m_value.binary->back());
18236 o->write_characters(
"],\"subtype\":", 12);
18237 if (val.m_value.binary->has_subtype())
18239 dump_integer(val.m_value.binary->subtype());
18240 o->write_character(
'}');
18244 o->write_characters(
"null}", 5);
18250 case value_t::boolean:
18252 if (val.m_value.boolean)
18254 o->write_characters(
"true", 4);
18258 o->write_characters(
"false", 5);
18263 case value_t::number_integer:
18265 dump_integer(val.m_value.number_integer);
18269 case value_t::number_unsigned:
18271 dump_integer(val.m_value.number_unsigned);
18275 case value_t::number_float:
18277 dump_float(val.m_value.number_float);
18281 case value_t::discarded:
18283 o->write_characters(
"<discarded>", 11);
18287 case value_t::null:
18289 o->write_characters(
"null", 4);
18294 JSON_ASSERT(
false);
18298 JSON_PRIVATE_UNLESS_TESTED:
18313 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
18315 std::uint32_t codepoint{};
18316 std::uint8_t state = UTF8_ACCEPT;
18317 std::size_t bytes = 0;
18320 std::size_t bytes_after_last_accept = 0;
18321 std::size_t undumped_chars = 0;
18323 for (std::size_t i = 0; i < s.size(); ++i)
18325 const auto byte =
static_cast<std::uint8_t
>(s[i]);
18327 switch (decode(state, codepoint,
byte))
18335 string_buffer[bytes++] =
'\\';
18336 string_buffer[bytes++] =
'b';
18342 string_buffer[bytes++] =
'\\';
18343 string_buffer[bytes++] =
't';
18349 string_buffer[bytes++] =
'\\';
18350 string_buffer[bytes++] =
'n';
18356 string_buffer[bytes++] =
'\\';
18357 string_buffer[bytes++] =
'f';
18363 string_buffer[bytes++] =
'\\';
18364 string_buffer[bytes++] =
'r';
18370 string_buffer[bytes++] =
'\\';
18371 string_buffer[bytes++] =
'\"';
18377 string_buffer[bytes++] =
'\\';
18378 string_buffer[bytes++] =
'\\';
18386 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
18388 if (codepoint <= 0xFFFF)
18391 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
18392 static_cast<std::uint16_t
>(codepoint)));
18398 static_cast<void>((std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
18399 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
18400 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu))));
18408 string_buffer[bytes++] = s[i];
18417 if (string_buffer.size() - bytes < 13)
18419 o->write_characters(string_buffer.data(), bytes);
18424 bytes_after_last_accept = bytes;
18425 undumped_chars = 0;
18431 switch (error_handler)
18433 case error_handler_t::strict:
18435 JSON_THROW(type_error::create(316, concat(
"invalid UTF-8 byte at index ", std::to_string(i),
": 0x", hex_bytes(
byte | 0)),
nullptr));
18438 case error_handler_t::ignore:
18439 case error_handler_t::replace:
18445 if (undumped_chars > 0)
18452 bytes = bytes_after_last_accept;
18454 if (error_handler == error_handler_t::replace)
18459 string_buffer[bytes++] =
'\\';
18460 string_buffer[bytes++] =
'u';
18461 string_buffer[bytes++] =
'f';
18462 string_buffer[bytes++] =
'f';
18463 string_buffer[bytes++] =
'f';
18464 string_buffer[bytes++] =
'd';
18468 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
18469 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
18470 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
18476 if (string_buffer.size() - bytes < 13)
18478 o->write_characters(string_buffer.data(), bytes);
18482 bytes_after_last_accept = bytes;
18485 undumped_chars = 0;
18488 state = UTF8_ACCEPT;
18493 JSON_ASSERT(
false);
18503 string_buffer[bytes++] = s[i];
18512 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
18517 o->write_characters(string_buffer.data(), bytes);
18523 switch (error_handler)
18525 case error_handler_t::strict:
18527 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));
18530 case error_handler_t::ignore:
18533 o->write_characters(string_buffer.data(), bytes_after_last_accept);
18537 case error_handler_t::replace:
18540 o->write_characters(string_buffer.data(), bytes_after_last_accept);
18544 o->write_characters(
"\\ufffd", 6);
18548 o->write_characters(
"\xEF\xBF\xBD", 3);
18554 JSON_ASSERT(
false);
18568 inline unsigned int count_digits(number_unsigned_t x)
noexcept
18570 unsigned int n_digits = 1;
18579 return n_digits + 1;
18583 return n_digits + 2;
18587 return n_digits + 3;
18599 static std::string hex_bytes(std::uint8_t
byte)
18601 std::string result =
"FF";
18602 constexpr const char* nibble_to_hex =
"0123456789ABCDEF";
18603 result[0] = nibble_to_hex[
byte / 16];
18604 result[1] = nibble_to_hex[
byte % 16];
18609 template <typename NumberType, enable_if_t<std::is_signed<NumberType>::value,
int> = 0>
18610 bool is_negative_number(NumberType x)
18615 template < typename NumberType, enable_if_t <std::is_unsigned<NumberType>::value,
int > = 0 >
18616 bool is_negative_number(NumberType )
18630 template <
typename NumberType, detail::enable_if_t <
18631 std::is_integral<NumberType>::value ||
18632 std::is_same<NumberType, number_unsigned_t>::value ||
18633 std::is_same<NumberType, number_integer_t>::value ||
18634 std::is_same<NumberType, binary_char_t>::value,
18636 void dump_integer(NumberType x)
18638 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
18641 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
18642 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
18643 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
18644 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
18645 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
18646 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
18647 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
18648 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
18649 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
18650 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
18657 o->write_character(
'0');
18662 auto buffer_ptr = number_buffer.begin();
18664 number_unsigned_t abs_value;
18666 unsigned int n_chars{};
18668 if (is_negative_number(x))
18671 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
18674 n_chars = 1 + count_digits(abs_value);
18678 abs_value =
static_cast<number_unsigned_t
>(x);
18679 n_chars = count_digits(abs_value);
18683 JSON_ASSERT(n_chars < number_buffer.size() - 1);
18687 buffer_ptr += n_chars;
18691 while (abs_value >= 100)
18693 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
18695 *(--buffer_ptr) = digits_to_99[digits_index][1];
18696 *(--buffer_ptr) = digits_to_99[digits_index][0];
18699 if (abs_value >= 10)
18701 const auto digits_index =
static_cast<unsigned>(abs_value);
18702 *(--buffer_ptr) = digits_to_99[digits_index][1];
18703 *(--buffer_ptr) = digits_to_99[digits_index][0];
18707 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
18710 o->write_characters(number_buffer.data(), n_chars);
18721 void dump_float(number_float_t x)
18724 if (!std::isfinite(x))
18726 o->write_characters(
"null", 4);
18735 static constexpr bool is_ieee_single_or_double
18736 = (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) ||
18737 (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);
18739 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
18742 void dump_float(number_float_t x, std::true_type )
18744 auto* begin = number_buffer.data();
18745 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
18747 o->write_characters(begin,
static_cast<size_t>(end - begin));
18750 void dump_float(number_float_t x, std::false_type )
18753 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
18757 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
18760 JSON_ASSERT(len > 0);
18762 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
18765 if (thousands_sep !=
'\0')
18768 const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep);
18769 std::fill(end, number_buffer.end(),
'\0');
18770 JSON_ASSERT((end - number_buffer.begin()) <= len);
18771 len = (end - number_buffer.begin());
18775 if (decimal_point !=
'\0' && decimal_point !=
'.')
18778 const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
18779 if (dec_pos != number_buffer.end())
18785 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
18788 const bool value_is_int_like =
18789 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
18792 return c ==
'.' || c ==
'e';
18795 if (value_is_int_like)
18797 o->write_characters(
".0", 2);
18822 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
18824 static const std::array<std::uint8_t, 400> utf8d =
18827 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,
18828 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,
18829 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,
18830 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,
18831 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,
18832 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,
18833 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,
18834 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
18835 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
18836 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
18837 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,
18838 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,
18839 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,
18840 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
18844 JSON_ASSERT(
byte < utf8d.size());
18845 const std::uint8_t type = utf8d[byte];
18847 codep = (state != UTF8_ACCEPT)
18848 ? (
byte & 0x3fu) | (codep << 6u)
18849 : (0xFFu >> type) & (byte);
18851 const std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
18852 JSON_ASSERT(index < utf8d.size());
18853 state = utf8d[index];
18862 number_unsigned_t remove_sign(number_unsigned_t x)
18864 JSON_ASSERT(
false);
18877 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
18879 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
18880 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
18885 output_adapter_t<char> o =
nullptr;
18888 std::array<char, 64> number_buffer{{}};
18891 const std::lconv* loc =
nullptr;
18893 const char thousands_sep =
'\0';
18895 const char decimal_point =
'\0';
18898 std::array<char, 512> string_buffer{{}};
18910NLOHMANN_JSON_NAMESPACE_END
18927#include <functional>
18928#include <initializer_list>
18931#include <stdexcept>
18932#include <type_traits>
18941NLOHMANN_JSON_NAMESPACE_BEGIN
18945template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
18946 class Allocator = std::allocator<std::pair<const Key, T>>>
18949 using key_type = Key;
18950 using mapped_type = T;
18951 using Container = std::vector<std::pair<const Key, T>, Allocator>;
18952 using iterator =
typename Container::iterator;
18953 using const_iterator =
typename Container::const_iterator;
18954 using size_type =
typename Container::size_type;
18955 using value_type =
typename Container::value_type;
18956#ifdef JSON_HAS_CPP_14
18957 using key_compare = std::equal_to<>;
18959 using key_compare = std::equal_to<Key>;
18964 ordered_map()
noexcept(
noexcept(Container())) : Container{} {}
18965 explicit ordered_map(
const Allocator& alloc)
noexcept(
noexcept(Container(alloc))) : Container{alloc} {}
18966 template <
class It>
18967 ordered_map(It first, It last,
const Allocator& alloc = Allocator())
18968 : Container{first, last, alloc} {}
18969 ordered_map(std::initializer_list<value_type> init,
const Allocator& alloc = Allocator() )
18970 : Container{init, alloc} {}
18972 std::pair<iterator, bool> emplace(
const key_type& key, T&& t)
18974 for (
auto it = this->begin(); it != this->end(); ++it)
18976 if (m_compare(it->first, key))
18978 return {it,
false};
18981 Container::emplace_back(key, std::forward<T>(t));
18982 return {std::prev(this->end()),
true};
18985 template<
class KeyType, detail::enable_if_t<
18986 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
18987 std::pair<iterator, bool> emplace(KeyType && key, T && t)
18989 for (
auto it = this->begin(); it != this->end(); ++it)
18991 if (m_compare(it->first, key))
18993 return {it,
false};
18996 Container::emplace_back(std::forward<KeyType>(key), std::forward<T>(t));
18997 return {std::prev(this->end()),
true};
19000 T& operator[](
const key_type& key)
19002 return emplace(key, T{}).first->second;
19005 template<
class KeyType, detail::enable_if_t<
19006 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19007 T & operator[](KeyType && key)
19009 return emplace(std::forward<KeyType>(key), T{}).first->second;
19012 const T& operator[](
const key_type& key)
const
19017 template<
class KeyType, detail::enable_if_t<
19018 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19019 const T & operator[](KeyType && key)
const
19021 return at(std::forward<KeyType>(key));
19024 T& at(
const key_type& key)
19026 for (
auto it = this->begin(); it != this->end(); ++it)
19028 if (m_compare(it->first, key))
19034 JSON_THROW(std::out_of_range(
"key not found"));
19037 template<
class KeyType, detail::enable_if_t<
19038 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19039 T & at(KeyType && key)
19041 for (
auto it = this->begin(); it != this->end(); ++it)
19043 if (m_compare(it->first, key))
19049 JSON_THROW(std::out_of_range(
"key not found"));
19052 const T& at(
const key_type& key)
const
19054 for (
auto it = this->begin(); it != this->end(); ++it)
19056 if (m_compare(it->first, key))
19062 JSON_THROW(std::out_of_range(
"key not found"));
19065 template<
class KeyType, detail::enable_if_t<
19066 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19067 const T & at(KeyType && key)
const
19069 for (
auto it = this->begin(); it != this->end(); ++it)
19071 if (m_compare(it->first, key))
19077 JSON_THROW(std::out_of_range(
"key not found"));
19080 size_type erase(
const key_type& key)
19082 for (
auto it = this->begin(); it != this->end(); ++it)
19084 if (m_compare(it->first, key))
19087 for (
auto next = it; ++next != this->end(); ++it)
19090 new (&*it) value_type{std::move(*next)};
19092 Container::pop_back();
19099 template<
class KeyType, detail::enable_if_t<
19100 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19101 size_type erase(KeyType && key)
19103 for (
auto it = this->begin(); it != this->end(); ++it)
19105 if (m_compare(it->first, key))
19108 for (
auto next = it; ++next != this->end(); ++it)
19111 new (&*it) value_type{std::move(*next)};
19113 Container::pop_back();
19120 iterator erase(iterator pos)
19122 return erase(pos, std::next(pos));
19125 iterator erase(iterator first, iterator last)
19132 const auto elements_affected = std::distance(first, last);
19133 const auto offset = std::distance(Container::begin(), first);
19155 for (
auto it = first; std::next(it, elements_affected) != Container::end(); ++it)
19158 new (&*it) value_type{std::move(*std::next(it, elements_affected))};
19166 Container::resize(this->size() -
static_cast<size_type
>(elements_affected));
19175 return Container::begin() + offset;
19178 size_type count(
const key_type& key)
const
19180 for (
auto it = this->begin(); it != this->end(); ++it)
19182 if (m_compare(it->first, key))
19190 template<
class KeyType, detail::enable_if_t<
19191 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19192 size_type count(KeyType && key)
const
19194 for (
auto it = this->begin(); it != this->end(); ++it)
19196 if (m_compare(it->first, key))
19204 iterator find(
const key_type& key)
19206 for (
auto it = this->begin(); it != this->end(); ++it)
19208 if (m_compare(it->first, key))
19213 return Container::end();
19216 template<
class KeyType, detail::enable_if_t<
19217 detail::is_usable_as_key_type<key_compare, key_type, KeyType>::value,
int> = 0>
19218 iterator find(KeyType && key)
19220 for (
auto it = this->begin(); it != this->end(); ++it)
19222 if (m_compare(it->first, key))
19227 return Container::end();
19230 const_iterator find(
const key_type& key)
const
19232 for (
auto it = this->begin(); it != this->end(); ++it)
19234 if (m_compare(it->first, key))
19239 return Container::end();
19242 std::pair<iterator, bool> insert( value_type&& value )
19244 return emplace(value.first, std::move(value.second));
19247 std::pair<iterator, bool> insert(
const value_type& value )
19249 for (
auto it = this->begin(); it != this->end(); ++it)
19251 if (m_compare(it->first, value.first))
19253 return {it,
false};
19256 Container::push_back(value);
19257 return {--this->end(),
true};
19260 template<
typename InputIt>
19261 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
19262 std::input_iterator_tag>::value>::type;
19264 template<
typename InputIt,
typename = require_input_iter<InputIt>>
19265 void insert(InputIt first, InputIt last)
19267 for (
auto it = first; it != last; ++it)
19274 JSON_NO_UNIQUE_ADDRESS key_compare m_compare = key_compare();
19277NLOHMANN_JSON_NAMESPACE_END
19280#if defined(JSON_HAS_CPP_17)
19282 #include <string_view>
19290NLOHMANN_JSON_NAMESPACE_BEGIN
19310NLOHMANN_BASIC_JSON_TPL_DECLARATION
19312 :
public ::nlohmann::detail::json_base_class<CustomBaseClass>
19318 friend class ::nlohmann::json_pointer;
19322 template<
typename BasicJsonType,
typename InputType>
19323 friend class ::nlohmann::detail::parser;
19324 friend ::nlohmann::detail::serializer<basic_json>;
19325 template<
typename BasicJsonType>
19326 friend class ::nlohmann::detail::iter_impl;
19327 template<
typename BasicJsonType,
typename CharType>
19328 friend class ::nlohmann::detail::binary_writer;
19329 template<
typename BasicJsonType,
typename InputType,
typename SAX>
19330 friend class ::nlohmann::detail::binary_reader;
19331 template<
typename BasicJsonType>
19332 friend class ::nlohmann::detail::json_sax_dom_parser;
19333 template<
typename BasicJsonType>
19334 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
19335 friend class ::nlohmann::detail::exception;
19338 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
19339 using json_base_class_t = ::nlohmann::detail::json_base_class<CustomBaseClass>;
19341 JSON_PRIVATE_UNLESS_TESTED:
19343 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
19345 template<
typename InputAdapterType>
19346 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
19347 InputAdapterType adapter,
19348 detail::parser_callback_t<basic_json>cb =
nullptr,
19349 const bool allow_exceptions =
true,
19350 const bool ignore_comments =
false
19353 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
19354 std::move(cb), allow_exceptions, ignore_comments);
19358 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
19359 template<
typename BasicJsonType>
19360 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
19361 template<
typename BasicJsonType>
19362 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
19363 template<
typename Iterator>
19364 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
19365 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
19367 template<
typename CharType>
19368 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
19370 template<
typename InputType>
19371 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
19372 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
19374 JSON_PRIVATE_UNLESS_TESTED:
19375 using serializer = ::nlohmann::detail::serializer<basic_json>;
19381 template<
typename T,
typename SFINAE>
19382 using json_serializer = JSONSerializer<T, SFINAE>;
19390 using input_format_t = detail::input_format_t;
19438 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
19440 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
19463 JSON_HEDLEY_WARN_UNUSED_RESULT
19468 result[
"copyright"] =
"(C) 2013-2022 Niels Lohmann";
19469 result[
"name"] =
"JSON for Modern C++";
19470 result[
"url"] =
"https://github.com/nlohmann/json";
19471 result[
"version"][
"string"] =
19472 detail::concat(std::to_string(NLOHMANN_JSON_VERSION_MAJOR),
'.',
19473 std::to_string(NLOHMANN_JSON_VERSION_MINOR),
'.',
19474 std::to_string(NLOHMANN_JSON_VERSION_PATCH));
19475 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
19476 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
19477 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
19480 result[
"platform"] =
"win32";
19481#elif defined __linux__
19482 result[
"platform"] =
"linux";
19483#elif defined __APPLE__
19484 result[
"platform"] =
"apple";
19485#elif defined __unix__
19486 result[
"platform"] =
"unix";
19488 result[
"platform"] =
"unknown";
19491#if defined(__ICC) || defined(__INTEL_COMPILER)
19492 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
19493#elif defined(__clang__)
19494 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
19495#elif defined(__GNUC__) || defined(__GNUG__)
19496 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", detail::concat(
19497 std::to_string(__GNUC__),
'.',
19498 std::to_string(__GNUC_MINOR__),
'.',
19499 std::to_string(__GNUC_PATCHLEVEL__))
19502#elif defined(__HP_cc) || defined(__HP_aCC)
19503 result[
"compiler"] =
"hp"
19504#elif defined(__IBMCPP__)
19505 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
19506#elif defined(_MSC_VER)
19507 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
19508#elif defined(__PGI)
19509 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
19510#elif defined(__SUNPRO_CC)
19511 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
19513 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
19517#if defined(_MSVC_LANG)
19518 result[
"compiler"][
"c++"] = std::to_string(_MSVC_LANG);
19519#elif defined(__cplusplus)
19520 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
19522 result[
"compiler"][
"c++"] =
"unknown";
19541#if defined(JSON_HAS_CPP_14)
19544 using default_object_comparator_t = std::less<>;
19554 AllocatorType<std::pair<
const StringType,
19559 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
19583 using binary_t = nlohmann::byte_container_with_subtype<BinaryType>;
19594 template<
typename T,
typename... Args>
19595 JSON_HEDLEY_RETURNS_NON_NULL
19596 static T* create(Args&& ... args)
19598 AllocatorType<T> alloc;
19599 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
19601 auto deleter = [&](T * obj)
19603 AllocatorTraits::deallocate(alloc, obj, 1);
19605 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
19606 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
19607 JSON_ASSERT(obj !=
nullptr);
19608 return obj.release();
19615 JSON_PRIVATE_UNLESS_TESTED:
19654 number_integer_t number_integer;
19656 number_unsigned_t number_unsigned;
19658 number_float_t number_float;
19661 json_value() =
default;
19663 json_value(boolean_t v) noexcept : boolean(v) {}
19669 json_value(number_float_t v) noexcept :
number_float(v) {}
19671 json_value(value_t t)
19675 case value_t::object:
19677 object = create<object_t>();
19681 case value_t::array:
19683 array = create<array_t>();
19687 case value_t::string:
19689 string = create<string_t>(
"");
19693 case value_t::binary:
19695 binary = create<binary_t>();
19699 case value_t::boolean:
19701 boolean =
static_cast<boolean_t
>(
false);
19705 case value_t::number_integer:
19711 case value_t::number_unsigned:
19717 case value_t::number_float:
19723 case value_t::null:
19729 case value_t::discarded:
19733 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
19735 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.11.2",
nullptr));
19743 json_value(
const string_t& value) :
string(create<string_t>(value)) {}
19746 json_value(string_t&& value) :
string(create<string_t>(
std::move(value))) {}
19749 json_value(
const object_t& value) :
object(create<object_t>(value)) {}
19752 json_value(object_t&& value) :
object(create<object_t>(
std::move(value))) {}
19755 json_value(
const array_t& value) :
array(create<array_t>(value)) {}
19758 json_value(array_t&& value) :
array(create<array_t>(
std::move(value))) {}
19761 json_value(
const typename binary_t::container_type& value) :
binary(create<binary_t>(value)) {}
19764 json_value(
typename binary_t::container_type&& value) :
binary(create<binary_t>(
std::move(value))) {}
19767 json_value(
const binary_t& value) :
binary(create<binary_t>(value)) {}
19770 json_value(binary_t&& value) :
binary(create<binary_t>(
std::move(value))) {}
19772 void destroy(value_t t)
19774 if (t == value_t::array || t == value_t::object)
19777 std::vector<basic_json> stack;
19780 if (t == value_t::array)
19782 stack.reserve(
array->size());
19783 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
19787 stack.reserve(
object->size());
19788 for (
auto&& it : *
object)
19790 stack.push_back(std::move(it.second));
19794 while (!stack.empty())
19797 basic_json current_item(std::move(stack.back()));
19802 if (current_item.is_array())
19804 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
19806 current_item.m_value.array->clear();
19808 else if (current_item.is_object())
19810 for (
auto&& it : *current_item.m_value.
object)
19812 stack.push_back(std::move(it.second));
19815 current_item.m_value.object->clear();
19825 case value_t::object:
19827 AllocatorType<object_t> alloc;
19828 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
19829 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
19833 case value_t::array:
19835 AllocatorType<array_t> alloc;
19836 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
19837 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
19841 case value_t::string:
19843 AllocatorType<string_t> alloc;
19844 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
19845 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
19849 case value_t::binary:
19851 AllocatorType<binary_t> alloc;
19852 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
19853 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
19857 case value_t::null:
19858 case value_t::boolean:
19859 case value_t::number_integer:
19860 case value_t::number_unsigned:
19861 case value_t::number_float:
19862 case value_t::discarded:
19890 void assert_invariant(
bool check_parents =
true) const noexcept
19892 JSON_ASSERT(m_type != value_t::object || m_value.object !=
nullptr);
19893 JSON_ASSERT(m_type != value_t::array || m_value.array !=
nullptr);
19894 JSON_ASSERT(m_type != value_t::string || m_value.string !=
nullptr);
19895 JSON_ASSERT(m_type != value_t::binary || m_value.binary !=
nullptr);
19897#if JSON_DIAGNOSTICS
19901 JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [
this](
const basic_json & j)
19903 return j.m_parent ==
this;
19908 static_cast<void>(check_parents);
19913#if JSON_DIAGNOSTICS
19916 case value_t::array:
19918 for (
auto& element : *m_value.
array)
19920 element.m_parent =
this;
19925 case value_t::object:
19927 for (
auto& element : *m_value.
object)
19929 element.second.m_parent =
this;
19934 case value_t::null:
19935 case value_t::string:
19936 case value_t::boolean:
19937 case value_t::number_integer:
19938 case value_t::number_unsigned:
19939 case value_t::number_float:
19940 case value_t::binary:
19941 case value_t::discarded:
19948 iterator set_parents(iterator it,
typename iterator::difference_type count_set_parents)
19950#if JSON_DIAGNOSTICS
19951 for (
typename iterator::difference_type i = 0; i < count_set_parents; ++i)
19953 (it + i)->m_parent =
this;
19956 static_cast<void>(count_set_parents);
19961 reference set_parent(reference j, std::size_t old_capacity =
static_cast<std::size_t
>(-1))
19963#if JSON_DIAGNOSTICS
19964 if (old_capacity !=
static_cast<std::size_t
>(-1))
19967 JSON_ASSERT(type() == value_t::array);
19968 if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
19978#ifdef JSON_HEDLEY_MSVC_VERSION
19979#pragma warning(push )
19980#pragma warning(disable : 4127)
19987#ifdef JSON_HEDLEY_MSVC_VERSION
19988#pragma warning( pop )
19993 static_cast<void>(j);
19994 static_cast<void>(old_capacity);
20006 using parse_event_t = detail::parse_event_t;
20024 : m_type(v), m_value(v)
20026 assert_invariant();
20034 assert_invariant();
20039 template <
typename CompatibleType,
20040 typename U = detail::uncvref_t<CompatibleType>,
20041 detail::enable_if_t <
20044 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
20045 std::forward<CompatibleType>(val))))
20047 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
20049 assert_invariant();
20054 template <
typename BasicJsonType,
20055 detail::enable_if_t <
20059 using other_boolean_t =
typename BasicJsonType::boolean_t;
20060 using other_number_float_t =
typename BasicJsonType::number_float_t;
20061 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
20062 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
20063 using other_string_t =
typename BasicJsonType::string_t;
20064 using other_object_t =
typename BasicJsonType::object_t;
20065 using other_array_t =
typename BasicJsonType::array_t;
20066 using other_binary_t =
typename BasicJsonType::binary_t;
20068 switch (val.type())
20070 case value_t::boolean:
20071 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
20073 case value_t::number_float:
20074 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
20076 case value_t::number_integer:
20077 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
20079 case value_t::number_unsigned:
20080 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
20082 case value_t::string:
20083 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
20085 case value_t::object:
20086 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
20088 case value_t::array:
20089 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
20091 case value_t::binary:
20092 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
20094 case value_t::null:
20097 case value_t::discarded:
20098 m_type = value_t::discarded;
20101 JSON_ASSERT(
false);
20103 JSON_ASSERT(m_type == val.type());
20105 assert_invariant();
20111 bool type_deduction =
true,
20112 value_t manual_type = value_t::array)
20116 bool is_an_object = std::all_of(init.begin(), init.end(),
20119 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
20123 if (!type_deduction)
20126 if (manual_type == value_t::array)
20128 is_an_object =
false;
20132 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
20134 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
nullptr));
20141 m_type = value_t::object;
20142 m_value = value_t::object;
20144 for (
auto& element_ref : init)
20146 auto element = element_ref.moved_or_copied();
20147 m_value.object->emplace(
20148 std::move(*((*element.m_value.array)[0].m_value.string)),
20149 std::move((*element.m_value.array)[1]));
20155 m_type = value_t::array;
20156 m_value.array = create<array_t>(init.begin(), init.end());
20160 assert_invariant();
20165 JSON_HEDLEY_WARN_UNUSED_RESULT
20169 res.m_type = value_t::binary;
20170 res.m_value = init;
20176 JSON_HEDLEY_WARN_UNUSED_RESULT
20177 static basic_json binary(
const typename binary_t::container_type& init,
typename binary_t::subtype_type subtype)
20180 res.m_type = value_t::binary;
20181 res.m_value =
binary_t(init, subtype);
20187 JSON_HEDLEY_WARN_UNUSED_RESULT
20191 res.m_type = value_t::binary;
20192 res.m_value = std::move(init);
20198 JSON_HEDLEY_WARN_UNUSED_RESULT
20199 static basic_json binary(
typename binary_t::container_type&& init,
typename binary_t::subtype_type subtype)
20202 res.m_type = value_t::binary;
20203 res.m_value =
binary_t(std::move(init), subtype);
20209 JSON_HEDLEY_WARN_UNUSED_RESULT
20212 return basic_json(init,
false, value_t::array);
20217 JSON_HEDLEY_WARN_UNUSED_RESULT
20220 return basic_json(init,
false, value_t::object);
20228 m_value.array = create<array_t>(cnt, val);
20230 assert_invariant();
20235 template <
class InputIT,
typename std::enable_if <
20236 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
20237 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >::type = 0 >
20240 JSON_ASSERT(first.m_object !=
nullptr);
20241 JSON_ASSERT(last.m_object !=
nullptr);
20244 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
20246 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
nullptr));
20250 m_type = first.m_object->m_type;
20255 case value_t::boolean:
20256 case value_t::number_float:
20257 case value_t::number_integer:
20258 case value_t::number_unsigned:
20259 case value_t::string:
20261 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
20262 || !last.m_it.primitive_iterator.is_end()))
20264 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", first.m_object));
20269 case value_t::null:
20270 case value_t::object:
20271 case value_t::array:
20272 case value_t::binary:
20273 case value_t::discarded:
20280 case value_t::number_integer:
20282 m_value.number_integer = first.m_object->m_value.number_integer;
20286 case value_t::number_unsigned:
20288 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
20292 case value_t::number_float:
20294 m_value.number_float = first.m_object->m_value.number_float;
20298 case value_t::boolean:
20300 m_value.boolean = first.m_object->m_value.boolean;
20304 case value_t::string:
20306 m_value = *first.m_object->m_value.string;
20310 case value_t::object:
20312 m_value.object = create<object_t>(first.m_it.object_iterator,
20313 last.m_it.object_iterator);
20317 case value_t::array:
20319 m_value.array = create<array_t>(first.m_it.array_iterator,
20320 last.m_it.array_iterator);
20324 case value_t::binary:
20326 m_value = *first.m_object->m_value.binary;
20330 case value_t::null:
20331 case value_t::discarded:
20333 JSON_THROW(invalid_iterator::create(206, detail::concat(
"cannot construct with iterators from ", first.m_object->type_name()), first.m_object));
20337 assert_invariant();
20345 template<
typename JsonRef,
20346 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
20347 std::is_same<typename JsonRef::value_type, basic_json>>::value,
int> = 0 >
20353 : json_base_class_t(other),
20354 m_type(other.m_type)
20357 other.assert_invariant();
20361 case value_t::object:
20363 m_value = *other.
m_value.object;
20367 case value_t::array:
20369 m_value = *other.
m_value.array;
20373 case value_t::string:
20375 m_value = *other.
m_value.string;
20379 case value_t::boolean:
20381 m_value = other.
m_value.boolean;
20385 case value_t::number_integer:
20387 m_value = other.
m_value.number_integer;
20391 case value_t::number_unsigned:
20393 m_value = other.
m_value.number_unsigned;
20397 case value_t::number_float:
20399 m_value = other.
m_value.number_float;
20403 case value_t::binary:
20405 m_value = *other.
m_value.binary;
20409 case value_t::null:
20410 case value_t::discarded:
20416 assert_invariant();
20422 : json_base_class_t(std::move(other)),
20423 m_type(std::move(other.m_type)),
20424 m_value(std::move(other.m_value))
20427 other.assert_invariant(
false);
20430 other.m_type = value_t::null;
20431 other.m_value = {};
20434 assert_invariant();
20440 std::is_nothrow_move_constructible<value_t>::value&&
20441 std::is_nothrow_move_assignable<value_t>::value&&
20442 std::is_nothrow_move_constructible<json_value>::value&&
20443 std::is_nothrow_move_assignable<json_value>::value&&
20444 std::is_nothrow_move_assignable<json_base_class_t>::value
20448 other.assert_invariant();
20451 swap(m_type, other.m_type);
20452 swap(m_value, other.m_value);
20453 json_base_class_t::operator=(std::move(other));
20456 assert_invariant();
20464 assert_invariant(
false);
20465 m_value.destroy(m_type);
20482 const char indent_char =
' ',
20483 const bool ensure_ascii =
false,
20487 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
20491 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
20495 s.dump(*
this,
false, ensure_ascii, 0);
20512 return is_null() || is_string() || is_boolean() || is_number() || is_binary();
20519 return is_array() || is_object();
20526 return m_type == value_t::null;
20533 return m_type == value_t::boolean;
20540 return is_number_integer() || is_number_float();
20547 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
20554 return m_type == value_t::number_unsigned;
20561 return m_type == value_t::number_float;
20568 return m_type == value_t::object;
20575 return m_type == value_t::array;
20582 return m_type == value_t::string;
20589 return m_type == value_t::binary;
20596 return m_type == value_t::discarded;
20614 boolean_t get_impl(boolean_t* )
const
20616 if (JSON_HEDLEY_LIKELY(is_boolean()))
20618 return m_value.boolean;
20621 JSON_THROW(type_error::create(302, detail::concat(
"type must be boolean, but is ",
type_name()),
this));
20625 object_t* get_impl_ptr(object_t* )
noexcept
20627 return is_object() ? m_value.object :
nullptr;
20631 constexpr const object_t* get_impl_ptr(
const object_t* )
const noexcept
20633 return is_object() ? m_value.object :
nullptr;
20637 array_t* get_impl_ptr(array_t* )
noexcept
20639 return is_array() ? m_value.array :
nullptr;
20643 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
20645 return is_array() ? m_value.array :
nullptr;
20649 string_t* get_impl_ptr(string_t* )
noexcept
20651 return is_string() ? m_value.string :
nullptr;
20655 constexpr const string_t* get_impl_ptr(
const string_t* )
const noexcept
20657 return is_string() ? m_value.string :
nullptr;
20661 boolean_t* get_impl_ptr(boolean_t* )
noexcept
20663 return is_boolean() ? &m_value.boolean :
nullptr;
20667 constexpr const boolean_t* get_impl_ptr(
const boolean_t* )
const noexcept
20669 return is_boolean() ? &m_value.boolean :
nullptr;
20673 number_integer_t* get_impl_ptr(number_integer_t* )
noexcept
20675 return is_number_integer() ? &m_value.number_integer :
nullptr;
20679 constexpr const number_integer_t* get_impl_ptr(
const number_integer_t* )
const noexcept
20681 return is_number_integer() ? &m_value.number_integer :
nullptr;
20685 number_unsigned_t* get_impl_ptr(number_unsigned_t* )
noexcept
20687 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
20691 constexpr const number_unsigned_t* get_impl_ptr(
const number_unsigned_t* )
const noexcept
20693 return is_number_unsigned() ? &m_value.number_unsigned :
nullptr;
20697 number_float_t* get_impl_ptr(number_float_t* )
noexcept
20699 return is_number_float() ? &m_value.number_float :
nullptr;
20703 constexpr const number_float_t* get_impl_ptr(
const number_float_t* )
const noexcept
20705 return is_number_float() ? &m_value.number_float :
nullptr;
20709 binary_t* get_impl_ptr(binary_t* )
noexcept
20711 return is_binary() ? m_value.binary :
nullptr;
20715 constexpr const binary_t* get_impl_ptr(
const binary_t* )
const noexcept
20717 return is_binary() ? m_value.binary :
nullptr;
20731 template<
typename ReferenceType,
typename ThisType>
20732 static ReferenceType get_ref_impl(ThisType& obj)
20735 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20737 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20742 JSON_THROW(type_error::create(303, detail::concat(
"incompatible ReferenceType for get_ref, actual type is ", obj.type_name()), &obj));
20752 template<
typename PointerType,
typename std::enable_if<
20753 std::is_pointer<PointerType>::value,
int>::type = 0>
20754 auto get_ptr() noexcept -> decltype(
std::declval<basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20757 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20762 template <
typename PointerType,
typename std::enable_if <
20763 std::is_pointer<PointerType>::value&&
20764 std::is_const<typename std::remove_pointer<PointerType>::type>::value,
int >::type = 0 >
20765 constexpr auto get_ptr() const noexcept -> decltype(
std::declval<const basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20768 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20810 template <
typename ValueType,
20811 detail::enable_if_t <
20816 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20818 auto ret = ValueType();
20819 JSONSerializer<ValueType>::from_json(*
this, ret);
20853 template <
typename ValueType,
20854 detail::enable_if_t <
20858 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20860 return JSONSerializer<ValueType>::from_json(*
this);
20878 template <
typename BasicJsonType,
20879 detail::enable_if_t <
20901 template<
typename BasicJsonType,
20902 detail::enable_if_t<
20903 std::is_same<BasicJsonType, basic_json_t>::value,
20914 template<
typename PointerType,
20915 detail::enable_if_t<
20916 std::is_pointer<PointerType>::value,
20919 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
20922 return get_ptr<PointerType>();
20949 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20950#if defined(JSON_HAS_CPP_14)
20954 noexcept(
std::declval<const basic_json_t&>().template get_impl<ValueType>(
detail::priority_tag<4> {})))
20960 static_assert(!std::is_reference<ValueTypeCV>::value,
20961 "get() cannot be used with reference types, you might want to use get_ref()");
20992 template<
typename PointerType,
typename std::enable_if<
20993 std::is_pointer<PointerType>::value,
int>::type = 0>
20994 auto get() noexcept -> decltype(
std::declval<basic_json_t&>().template get_ptr<PointerType>())
20997 return get_ptr<PointerType>();
21002 template <
typename ValueType,
21003 detail::enable_if_t <
21007 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
21008 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
21010 JSONSerializer<ValueType>::from_json(*
this, v);
21016 template<
typename ValueType,
21017 detail::enable_if_t <
21020 ValueType & get_to(ValueType& v)
const
21027 typename T, std::size_t
N,
21028 typename Array = T (&)[
N],
21029 detail::enable_if_t <
21031 Array get_to(T (&v)[N])
const
21032 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21033 std::declval<const basic_json_t&>(), v)))
21035 JSONSerializer<Array>::from_json(*
this, v);
21041 template<
typename ReferenceType,
typename std::enable_if<
21042 std::is_reference<ReferenceType>::value,
int>::type = 0>
21046 return get_ref_impl<ReferenceType>(*
this);
21051 template <
typename ReferenceType,
typename std::enable_if <
21052 std::is_reference<ReferenceType>::value&&
21053 std::is_const<typename std::remove_reference<ReferenceType>::type>::value,
int >::type = 0 >
21057 return get_ref_impl<ReferenceType>(*
this);
21089 template <
typename ValueType,
typename std::enable_if <
21097#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21100#if defined(JSON_HAS_CPP_17)
21104 >::value,
int >::type = 0 >
21105 JSON_EXPLICIT
operator ValueType()
const
21108 return get<ValueType>();
21117 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21120 return *get_ptr<binary_t*>();
21129 JSON_THROW(type_error::create(302, detail::concat(
"type must be binary, but is ", type_name()),
this));
21132 return *get_ptr<const binary_t*>();
21151 if (JSON_HEDLEY_LIKELY(is_array()))
21155 return set_parent(m_value.array->at(idx));
21157 JSON_CATCH (std::out_of_range&)
21160 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21165 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21174 if (JSON_HEDLEY_LIKELY(is_array()))
21178 return m_value.array->at(idx);
21180 JSON_CATCH (std::out_of_range&)
21183 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21188 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21197 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21199 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21202 auto it = m_value.object->find(key);
21203 if (it == m_value.object->end())
21205 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
21207 return set_parent(it->second);
21212 template<
class KeyType, detail::enable_if_t<
21213 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21217 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21219 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21222 auto it = m_value.object->find(std::forward<KeyType>(key));
21223 if (it == m_value.object->end())
21225 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
21227 return set_parent(it->second);
21235 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21237 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21240 auto it = m_value.object->find(key);
21241 if (it == m_value.object->end())
21243 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", key,
"' not found"),
this));
21250 template<
class KeyType, detail::enable_if_t<
21251 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21255 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21257 JSON_THROW(type_error::create(304, detail::concat(
"cannot use at() with ", type_name()),
this));
21260 auto it = m_value.object->find(std::forward<KeyType>(key));
21261 if (it == m_value.object->end())
21263 JSON_THROW(out_of_range::create(403, detail::concat(
"key '",
string_t(std::forward<KeyType>(key)),
"' not found"),
this));
21275 m_type = value_t::array;
21276 m_value.array = create<array_t>();
21277 assert_invariant();
21281 if (JSON_HEDLEY_LIKELY(is_array()))
21284 if (idx >= m_value.array->size())
21286#if JSON_DIAGNOSTICS
21288 const auto old_size = m_value.array->size();
21289 const auto old_capacity = m_value.array->capacity();
21291 m_value.array->resize(idx + 1);
21293#if JSON_DIAGNOSTICS
21294 if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
21302 set_parents(begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
21305 assert_invariant();
21308 return m_value.array->operator[](idx);
21311 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21319 if (JSON_HEDLEY_LIKELY(is_array()))
21321 return m_value.array->operator[](idx);
21324 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a numeric argument with ", type_name()),
this));
21334 m_type = value_t::object;
21335 m_value.
object = create<object_t>();
21336 assert_invariant();
21340 if (JSON_HEDLEY_LIKELY(is_object()))
21342 auto result = m_value.object->emplace(std::move(key),
nullptr);
21343 return set_parent(result.first->second);
21346 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21354 if (JSON_HEDLEY_LIKELY(is_object()))
21357 JSON_ASSERT(it != m_value.object->end());
21361 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21366 template<
typename T>
21367 reference operator[](T* key)
21369 return operator[](
typename object_t::key_type(key));
21372 template<
typename T>
21373 const_reference operator[](T* key)
const
21375 return operator[](
typename object_t::key_type(key));
21380 template<
class KeyType, detail::enable_if_t<
21381 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21387 m_type = value_t::object;
21388 m_value.
object = create<object_t>();
21389 assert_invariant();
21393 if (JSON_HEDLEY_LIKELY(is_object()))
21395 auto result = m_value.object->emplace(std::forward<KeyType>(key),
nullptr);
21396 return set_parent(result.first->second);
21399 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21404 template<
class KeyType, detail::enable_if_t<
21405 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21409 if (JSON_HEDLEY_LIKELY(is_object()))
21411 auto it = m_value.
object->
find(std::forward<KeyType>(key));
21412 JSON_ASSERT(it != m_value.object->end());
21416 JSON_THROW(type_error::create(305, detail::concat(
"cannot use operator[] with a string argument with ", type_name()),
this));
21420 template<
typename KeyType>
21422 object_comparator_t,
const typename object_t::key_type&, KeyType >;
21424 template<
typename ValueType>
21425 using value_return_type = std::conditional <
21427 string_t,
typename std::decay<ValueType>::type >;
21432 template <
class ValueType, detail::enable_if_t <
21435 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21436 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
21439 if (JSON_HEDLEY_LIKELY(is_object()))
21442 const auto it = find(key);
21445 return it->template get<ValueType>();
21448 return default_value;
21451 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21456 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21457 detail::enable_if_t <
21460 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21461 ReturnType
value(
const typename object_t::key_type& key, ValueType && default_value)
const
21464 if (JSON_HEDLEY_LIKELY(is_object()))
21467 const auto it = find(key);
21470 return it->template get<ReturnType>();
21473 return std::forward<ValueType>(default_value);
21476 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21481 template <
class ValueType,
class KeyType, detail::enable_if_t <
21484 && is_comparable_with_object_key<KeyType>::value
21486 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21487 ValueType
value(KeyType && key,
const ValueType& default_value)
const
21490 if (JSON_HEDLEY_LIKELY(is_object()))
21493 const auto it = find(std::forward<KeyType>(key));
21496 return it->template get<ValueType>();
21499 return default_value;
21502 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21507 template < class ValueType, class KeyType, class ReturnType = typename value_return_type<ValueType>::type,
21508 detail::enable_if_t <
21511 && is_comparable_with_object_key<KeyType>::value
21513 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21514 ReturnType
value(KeyType && key, ValueType && default_value)
const
21517 if (JSON_HEDLEY_LIKELY(is_object()))
21520 const auto it = find(std::forward<KeyType>(key));
21523 return it->template get<ReturnType>();
21526 return std::forward<ValueType>(default_value);
21529 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21534 template <
class ValueType, detail::enable_if_t <
21536 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21540 if (JSON_HEDLEY_LIKELY(is_object()))
21545 return ptr.get_checked(
this).template get<ValueType>();
21549 return default_value;
21553 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21558 template < class ValueType, class ReturnType = typename value_return_type<ValueType>::type,
21559 detail::enable_if_t <
21561 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21565 if (JSON_HEDLEY_LIKELY(is_object()))
21570 return ptr.get_checked(
this).template get<ReturnType>();
21574 return std::forward<ValueType>(default_value);
21578 JSON_THROW(type_error::create(306, detail::concat(
"cannot use value() with ", type_name()),
this));
21581 template <
class ValueType,
class BasicJsonType, detail::enable_if_t <
21584 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21586 ValueType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr,
const ValueType& default_value)
const
21588 return value(ptr.convert(), default_value);
21591 template < class ValueType, class BasicJsonType, class ReturnType = typename value_return_type<ValueType>::type,
21592 detail::enable_if_t <
21595 && !std::is_same<value_t, detail::uncvref_t<ValueType>>::value,
int > = 0 >
21597 ReturnType value(const ::nlohmann::json_pointer<BasicJsonType>& ptr, ValueType && default_value)
const
21599 return value(ptr.convert(), std::forward<ValueType>(default_value));
21636 template <
class IteratorType, detail::enable_if_t <
21637 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21638 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21642 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21644 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
21647 IteratorType result = end();
21651 case value_t::boolean:
21652 case value_t::number_float:
21653 case value_t::number_integer:
21654 case value_t::number_unsigned:
21655 case value_t::string:
21656 case value_t::binary:
21658 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21660 JSON_THROW(invalid_iterator::create(205,
"iterator out of range",
this));
21665 AllocatorType<string_t> alloc;
21666 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.string);
21667 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21668 m_value.string =
nullptr;
21670 else if (is_binary())
21672 AllocatorType<binary_t> alloc;
21673 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.binary);
21674 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21675 m_value.binary =
nullptr;
21678 m_type = value_t::null;
21679 assert_invariant();
21683 case value_t::object:
21685 result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
21689 case value_t::array:
21691 result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
21695 case value_t::null:
21696 case value_t::discarded:
21698 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21706 template <
class IteratorType, detail::enable_if_t <
21707 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21708 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int > = 0 >
21709 IteratorType
erase(IteratorType first, IteratorType last)
21712 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21714 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value",
this));
21717 IteratorType result = end();
21721 case value_t::boolean:
21722 case value_t::number_float:
21723 case value_t::number_integer:
21724 case value_t::number_unsigned:
21725 case value_t::string:
21726 case value_t::binary:
21728 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21729 || !last.m_it.primitive_iterator.is_end()))
21731 JSON_THROW(invalid_iterator::create(204,
"iterators out of range",
this));
21736 AllocatorType<string_t> alloc;
21737 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.string);
21738 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.string, 1);
21739 m_value.string =
nullptr;
21741 else if (is_binary())
21743 AllocatorType<binary_t> alloc;
21744 std::allocator_traits<
decltype(alloc)>::destroy(alloc, m_value.binary);
21745 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, m_value.binary, 1);
21746 m_value.binary =
nullptr;
21749 m_type = value_t::null;
21750 assert_invariant();
21754 case value_t::object:
21756 result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
21757 last.m_it.object_iterator);
21761 case value_t::array:
21763 result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
21764 last.m_it.array_iterator);
21768 case value_t::null:
21769 case value_t::discarded:
21771 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21778 template <
typename KeyType, detail::enable_if_t <
21779 detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21780 size_type erase_internal(KeyType && key)
21783 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21785 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21788 return m_value.object->erase(std::forward<KeyType>(key));
21791 template <
typename KeyType, detail::enable_if_t <
21792 !detail::has_erase_with_key_type<basic_json_t, KeyType>::value,
int > = 0 >
21793 size_type erase_internal(KeyType && key)
21796 if (JSON_HEDLEY_UNLIKELY(!is_object()))
21798 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ",
type_name()),
this));
21801 const auto it = m_value.object->find(std::forward<KeyType>(key));
21802 if (it != m_value.object->end())
21804 m_value.object->erase(it);
21818 return erase_internal(key);
21823 template<
class KeyType, detail::enable_if_t<
21824 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21827 return erase_internal(std::forward<KeyType>(key));
21835 if (JSON_HEDLEY_LIKELY(is_array()))
21837 if (JSON_HEDLEY_UNLIKELY(idx >= size()))
21839 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"),
this));
21842 m_value.array->erase(m_value.array->begin() +
static_cast<difference_type>(idx));
21846 JSON_THROW(type_error::create(307, detail::concat(
"cannot use erase() with ", type_name()),
this));
21864 auto result = end();
21868 result.m_it.object_iterator = m_value.object->find(key);
21878 auto result = cend();
21882 result.m_it.object_iterator = m_value.object->find(key);
21890 template<
class KeyType, detail::enable_if_t<
21891 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21894 auto result = end();
21898 result.m_it.object_iterator = m_value.object->find(std::forward<KeyType>(key));
21906 template<
class KeyType, detail::enable_if_t<
21907 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21910 auto result = cend();
21914 result.m_it.object_iterator = m_value.object->find(std::forward<KeyType>(key));
21925 return is_object() ? m_value.object->count(key) : 0;
21930 template<
class KeyType, detail::enable_if_t<
21931 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21935 return is_object() ? m_value.object->count(std::forward<KeyType>(key)) : 0;
21940 bool contains(
const typename object_t::key_type& key)
const
21942 return is_object() && m_value.object->find(key) != m_value.object->end();
21947 template<
class KeyType, detail::enable_if_t<
21948 detail::is_usable_as_basic_json_key_type<basic_json_t, KeyType>::value,
int> = 0>
21951 return is_object() && m_value.object->find(std::forward<KeyType>(key)) != m_value.object->end();
21958 return ptr.contains(
this);
21961 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
21963 bool contains(
const typename ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
21965 return ptr.contains(
this);
21983 result.set_begin();
21999 result.set_begin();
22076 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22079 return ref.items();
22087 JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items())
22090 return ref.items();
22097 return iteration_proxy<iterator>(*
this);
22102 iteration_proxy<const_iterator>
items() const noexcept
22104 return iteration_proxy<const_iterator>(*
this);
22123 case value_t::null:
22129 case value_t::array:
22132 return m_value.array->empty();
22135 case value_t::object:
22138 return m_value.object->empty();
22141 case value_t::string:
22142 case value_t::boolean:
22143 case value_t::number_integer:
22144 case value_t::number_unsigned:
22145 case value_t::number_float:
22146 case value_t::binary:
22147 case value_t::discarded:
22162 case value_t::null:
22168 case value_t::array:
22171 return m_value.array->size();
22174 case value_t::object:
22177 return m_value.object->size();
22180 case value_t::string:
22181 case value_t::boolean:
22182 case value_t::number_integer:
22183 case value_t::number_unsigned:
22184 case value_t::number_float:
22185 case value_t::binary:
22186 case value_t::discarded:
22201 case value_t::array:
22204 return m_value.array->max_size();
22207 case value_t::object:
22210 return m_value.object->max_size();
22213 case value_t::null:
22214 case value_t::string:
22215 case value_t::boolean:
22216 case value_t::number_integer:
22217 case value_t::number_unsigned:
22218 case value_t::number_float:
22219 case value_t::binary:
22220 case value_t::discarded:
22245 case value_t::number_integer:
22247 m_value.number_integer = 0;
22251 case value_t::number_unsigned:
22253 m_value.number_unsigned = 0;
22257 case value_t::number_float:
22259 m_value.number_float = 0.0;
22263 case value_t::boolean:
22265 m_value.boolean =
false;
22269 case value_t::string:
22271 m_value.string->clear();
22275 case value_t::binary:
22277 m_value.binary->clear();
22281 case value_t::array:
22283 m_value.array->clear();
22287 case value_t::object:
22289 m_value.object->clear();
22293 case value_t::null:
22294 case value_t::discarded:
22305 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22307 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22313 m_type = value_t::array;
22314 m_value = value_t::array;
22315 assert_invariant();
22319 const auto old_capacity = m_value.array->capacity();
22320 m_value.array->push_back(std::move(val));
22321 set_parent(m_value.array->back(), old_capacity);
22329 push_back(std::move(val));
22338 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22340 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22346 m_type = value_t::array;
22347 m_value = value_t::array;
22348 assert_invariant();
22352 const auto old_capacity = m_value.array->capacity();
22353 m_value.array->push_back(val);
22354 set_parent(m_value.array->back(), old_capacity);
22370 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22372 JSON_THROW(type_error::create(308, detail::concat(
"cannot use push_back() with ", type_name()),
this));
22378 m_type = value_t::object;
22379 m_value = value_t::object;
22380 assert_invariant();
22384 auto res = m_value.object->insert(val);
22385 set_parent(res.first->second);
22400 if (is_object() && init.size() == 2 && (*init.begin())->is_string())
22402 basic_json&& key = init.begin()->moved_or_copied();
22403 push_back(
typename object_t::value_type(
22404 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22422 template<
class... Args>
22426 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array())))
22428 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace_back() with ", type_name()),
this));
22434 m_type = value_t::array;
22435 m_value = value_t::array;
22436 assert_invariant();
22440 const auto old_capacity = m_value.array->capacity();
22441 m_value.array->emplace_back(std::forward<Args>(args)...);
22442 return set_parent(m_value.array->back(), old_capacity);
22447 template<
class... Args>
22451 if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object())))
22453 JSON_THROW(type_error::create(311, detail::concat(
"cannot use emplace() with ", type_name()),
this));
22459 m_type = value_t::object;
22460 m_value = value_t::object;
22461 assert_invariant();
22465 auto res = m_value.object->emplace(std::forward<Args>(args)...);
22466 set_parent(res.first->second);
22470 it.m_it.object_iterator = res.first;
22473 return {it, res.second};
22479 template<
typename... Args>
22483 JSON_ASSERT(m_value.array !=
nullptr);
22485 auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator);
22486 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22487 result.m_it.array_iterator = m_value.array->begin() + insert_pos;
22502 if (JSON_HEDLEY_LIKELY(is_array()))
22505 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22507 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22511 return insert_iterator(pos, val);
22514 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22521 return insert(pos, val);
22529 if (JSON_HEDLEY_LIKELY(is_array()))
22532 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22534 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22538 return insert_iterator(pos, cnt, val);
22541 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22549 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22551 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22555 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22557 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22561 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22563 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22566 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22568 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container",
this));
22572 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
22580 if (JSON_HEDLEY_UNLIKELY(!is_array()))
22582 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22586 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22588 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value",
this));
22592 return insert_iterator(pos, ilist.begin(), ilist.end());
22600 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22602 JSON_THROW(type_error::create(309, detail::concat(
"cannot use insert() with ", type_name()),
this));
22606 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22608 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22612 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22614 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects",
this));
22617 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22624 update(j.
begin(), j.
end(), merge_objects);
22634 m_type = value_t::object;
22635 m_value.object = create<object_t>();
22636 assert_invariant();
22639 if (JSON_HEDLEY_UNLIKELY(!is_object()))
22641 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", type_name()),
this));
22645 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22647 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit",
this));
22651 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22653 JSON_THROW(type_error::create(312, detail::concat(
"cannot use update() with ", first.m_object->type_name()), first.m_object));
22656 for (
auto it = first; it != last; ++it)
22658 if (merge_objects && it.value().is_object())
22660 auto it2 = m_value.object->find(it.key());
22661 if (it2 != m_value.object->end())
22663 it2->second.update(it.value(),
true);
22667 m_value.object->operator[](it.key()) = it.value();
22668#if JSON_DIAGNOSTICS
22669 m_value.object->operator[](it.key()).m_parent =
this;
22677 std::is_nothrow_move_constructible<value_t>::value&&
22678 std::is_nothrow_move_assignable<value_t>::value&&
22679 std::is_nothrow_move_constructible<json_value>::value&&
22680 std::is_nothrow_move_assignable<json_value>::value
22687 other.set_parents();
22688 assert_invariant();
22694 std::is_nothrow_move_constructible<value_t>::value&&
22695 std::is_nothrow_move_assignable<value_t>::value&&
22696 std::is_nothrow_move_constructible<json_value>::value&&
22697 std::is_nothrow_move_assignable<json_value>::value
22708 if (JSON_HEDLEY_LIKELY(is_array()))
22711 swap(*(m_value.array), other);
22715 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(array_t&) with ", type_name()),
this));
22724 if (JSON_HEDLEY_LIKELY(is_object()))
22727 swap(*(m_value.object), other);
22731 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(object_t&) with ", type_name()),
this));
22740 if (JSON_HEDLEY_LIKELY(is_string()))
22743 swap(*(m_value.string), other);
22747 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(string_t&) with ", type_name()),
this));
22756 if (JSON_HEDLEY_LIKELY(is_binary()))
22759 swap(*(m_value.binary), other);
22763 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t&) with ", type_name()),
this));
22769 void swap(
typename binary_t::container_type& other)
22772 if (JSON_HEDLEY_LIKELY(is_binary()))
22775 swap(*(m_value.binary), other);
22779 JSON_THROW(type_error::create(310, detail::concat(
"cannot use swap(binary_t::container_type&) with ", type_name()),
this));
22794#define JSON_IMPLEMENT_OPERATOR(op, null_result, unordered_result, default_result) \
22795 const auto lhs_type = lhs.type(); \
22796 const auto rhs_type = rhs.type(); \
22798 if (lhs_type == rhs_type) \
22800 switch (lhs_type) \
22802 case value_t::array: \
22803 return (*lhs.m_value.array) op (*rhs.m_value.array); \
22805 case value_t::object: \
22806 return (*lhs.m_value.object) op (*rhs.m_value.object); \
22808 case value_t::null: \
22809 return (null_result); \
22811 case value_t::string: \
22812 return (*lhs.m_value.string) op (*rhs.m_value.string); \
22814 case value_t::boolean: \
22815 return (lhs.m_value.boolean) op (rhs.m_value.boolean); \
22817 case value_t::number_integer: \
22818 return (lhs.m_value.number_integer) op (rhs.m_value.number_integer); \
22820 case value_t::number_unsigned: \
22821 return (lhs.m_value.number_unsigned) op (rhs.m_value.number_unsigned); \
22823 case value_t::number_float: \
22824 return (lhs.m_value.number_float) op (rhs.m_value.number_float); \
22826 case value_t::binary: \
22827 return (*lhs.m_value.binary) op (*rhs.m_value.binary); \
22829 case value_t::discarded: \
22831 return (unordered_result); \
22834 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) \
22836 return static_cast<number_float_t>(lhs.m_value.number_integer) op rhs.m_value.number_float; \
22838 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) \
22840 return lhs.m_value.number_float op static_cast<number_float_t>(rhs.m_value.number_integer); \
22842 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) \
22844 return static_cast<number_float_t>(lhs.m_value.number_unsigned) op rhs.m_value.number_float; \
22846 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) \
22848 return lhs.m_value.number_float op static_cast<number_float_t>(rhs.m_value.number_unsigned); \
22850 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) \
22852 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) op rhs.m_value.number_integer; \
22854 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) \
22856 return lhs.m_value.number_integer op static_cast<number_integer_t>(rhs.m_value.number_unsigned); \
22858 else if(compares_unordered(lhs, rhs))\
22860 return (unordered_result);\
22863 return (default_result);
22865 JSON_PRIVATE_UNLESS_TESTED:
22871 static bool compares_unordered(const_reference lhs, const_reference rhs,
bool inverse =
false) noexcept
22873 if ((lhs.is_number_float() && std::isnan(lhs.m_value.number_float) && rhs.is_number())
22874 || (rhs.is_number_float() && std::isnan(rhs.m_value.number_float) && lhs.is_number()))
22878#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22879 return (lhs.is_discarded() || rhs.is_discarded()) && !inverse;
22881 static_cast<void>(inverse);
22882 return lhs.is_discarded() || rhs.is_discarded();
22887 bool compares_unordered(const_reference rhs,
bool inverse =
false) const noexcept
22889 return compares_unordered(*
this, rhs, inverse);
22893#if JSON_HAS_THREE_WAY_COMPARISON
22896 bool operator==(const_reference rhs)
const noexcept
22899#pragma GCC diagnostic push
22900#pragma GCC diagnostic ignored "-Wfloat-equal"
22902 const_reference lhs = *
this;
22903 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
22905#pragma GCC diagnostic pop
22911 template<
typename ScalarType>
22912 requires std::is_scalar_v<ScalarType>
22913 bool operator==(ScalarType rhs)
const noexcept
22920 bool operator!=(const_reference rhs)
const noexcept
22922 if (compares_unordered(rhs,
true))
22926 return !operator==(rhs);
22931 std::partial_ordering operator<=>(const_reference rhs)
const noexcept
22933 const_reference lhs = *
this;
22936 JSON_IMPLEMENT_OPERATOR(<=>,
22937 std::partial_ordering::equivalent,
22938 std::partial_ordering::unordered,
22939 lhs_type <=> rhs_type)
22944 template<
typename ScalarType>
22945 requires std::is_scalar_v<ScalarType>
22946 std::partial_ordering operator<=>(ScalarType rhs)
const noexcept
22951#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
22957 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
22958 bool operator<=(const_reference rhs)
const noexcept
22960 if (compares_unordered(rhs,
true))
22964 return !(rhs < *
this);
22969 template<
typename ScalarType>
22970 requires std::is_scalar_v<ScalarType>
22971 bool operator<=(ScalarType rhs)
const noexcept
22978 JSON_HEDLEY_DEPRECATED_FOR(3.11.0, undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON)
22979 bool operator>=(const_reference rhs)
const noexcept
22981 if (compares_unordered(rhs,
true))
22985 return !(*
this < rhs);
22990 template<
typename ScalarType>
22991 requires std::is_scalar_v<ScalarType>
22992 bool operator>=(ScalarType rhs)
const noexcept
23000 friend bool operator==(const_reference lhs, const_reference rhs)
noexcept
23003#pragma GCC diagnostic push
23004#pragma GCC diagnostic ignored "-Wfloat-equal"
23006 JSON_IMPLEMENT_OPERATOR( ==,
true,
false,
false)
23008#pragma GCC diagnostic pop
23014 template<
typename ScalarType,
typename std::enable_if<
23015 std::is_scalar<ScalarType>::value,
int>::type = 0>
23016 friend bool operator==(const_reference lhs, ScalarType rhs)
noexcept
23023 template<
typename ScalarType,
typename std::enable_if<
23024 std::is_scalar<ScalarType>::value,
int>::type = 0>
23025 friend bool operator==(ScalarType lhs, const_reference rhs)
noexcept
23032 friend bool operator!=(const_reference lhs, const_reference rhs)
noexcept
23034 if (compares_unordered(lhs, rhs,
true))
23038 return !(lhs == rhs);
23043 template<
typename ScalarType,
typename std::enable_if<
23044 std::is_scalar<ScalarType>::value,
int>::type = 0>
23045 friend bool operator!=(const_reference lhs, ScalarType rhs)
noexcept
23052 template<
typename ScalarType,
typename std::enable_if<
23053 std::is_scalar<ScalarType>::value,
int>::type = 0>
23054 friend bool operator!=(ScalarType lhs, const_reference rhs)
noexcept
23061 friend bool operator<(const_reference lhs, const_reference rhs)
noexcept
23066 JSON_IMPLEMENT_OPERATOR( <,
false,
false,
operator<(lhs_type, rhs_type))
23071 template<
typename ScalarType,
typename std::enable_if<
23072 std::is_scalar<ScalarType>::value,
int>::type = 0>
23073 friend bool operator<(const_reference lhs, ScalarType rhs)
noexcept
23080 template<
typename ScalarType,
typename std::enable_if<
23081 std::is_scalar<ScalarType>::value,
int>::type = 0>
23082 friend bool operator<(ScalarType lhs, const_reference rhs)
noexcept
23089 friend bool operator<=(const_reference lhs, const_reference rhs)
noexcept
23091 if (compares_unordered(lhs, rhs,
true))
23095 return !(rhs < lhs);
23100 template<
typename ScalarType,
typename std::enable_if<
23101 std::is_scalar<ScalarType>::value,
int>::type = 0>
23102 friend bool operator<=(const_reference lhs, ScalarType rhs)
noexcept
23109 template<
typename ScalarType,
typename std::enable_if<
23110 std::is_scalar<ScalarType>::value,
int>::type = 0>
23111 friend bool operator<=(ScalarType lhs, const_reference rhs)
noexcept
23118 friend bool operator>(const_reference lhs, const_reference rhs)
noexcept
23121 if (compares_unordered(lhs, rhs))
23125 return !(lhs <= rhs);
23130 template<
typename ScalarType,
typename std::enable_if<
23131 std::is_scalar<ScalarType>::value,
int>::type = 0>
23132 friend bool operator>(const_reference lhs, ScalarType rhs)
noexcept
23139 template<
typename ScalarType,
typename std::enable_if<
23140 std::is_scalar<ScalarType>::value,
int>::type = 0>
23141 friend bool operator>(ScalarType lhs, const_reference rhs)
noexcept
23148 friend bool operator>=(const_reference lhs, const_reference rhs)
noexcept
23150 if (compares_unordered(lhs, rhs,
true))
23154 return !(lhs < rhs);
23159 template<
typename ScalarType,
typename std::enable_if<
23160 std::is_scalar<ScalarType>::value,
int>::type = 0>
23161 friend bool operator>=(const_reference lhs, ScalarType rhs)
noexcept
23168 template<
typename ScalarType,
typename std::enable_if<
23169 std::is_scalar<ScalarType>::value,
int>::type = 0>
23170 friend bool operator>=(ScalarType lhs, const_reference rhs)
noexcept
23176#undef JSON_IMPLEMENT_OPERATOR
23189 friend std::ostream& operator<<(std::ostream& o,
const basic_json& j)
23192 const bool pretty_print = o.width() > 0;
23193 const auto indentation = pretty_print ? o.width() : 0;
23199 serializer s(detail::output_adapter<char>(o), o.fill());
23200 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23210 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23228 template<
typename InputType>
23229 JSON_HEDLEY_WARN_UNUSED_RESULT
23231 const parser_callback_t cb =
nullptr,
23232 const bool allow_exceptions =
true,
23233 const bool ignore_comments =
false)
23236 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23242 template<
typename IteratorType>
23243 JSON_HEDLEY_WARN_UNUSED_RESULT
23246 const parser_callback_t cb =
nullptr,
23247 const bool allow_exceptions =
true,
23248 const bool ignore_comments =
false)
23251 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23255 JSON_HEDLEY_WARN_UNUSED_RESULT
23256 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len))
23257 static basic_json parse(detail::span_input_adapter&& i,
23258 const parser_callback_t cb =
nullptr,
23259 const bool allow_exceptions =
true,
23260 const bool ignore_comments =
false)
23263 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23269 template<
typename InputType>
23270 static bool accept(InputType&& i,
23271 const bool ignore_comments =
false)
23273 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23278 template<
typename IteratorType>
23279 static bool accept(IteratorType first, IteratorType last,
23280 const bool ignore_comments =
false)
23282 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23285 JSON_HEDLEY_WARN_UNUSED_RESULT
23286 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len))
23287 static bool accept(detail::span_input_adapter&& i,
23288 const bool ignore_comments =
false)
23290 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23295 template <
typename InputType,
typename SAX>
23296 JSON_HEDLEY_NON_NULL(2)
23297 static
bool sax_parse(InputType&& i, SAX* sax,
23298 input_format_t format = input_format_t::json,
23299 const
bool strict = true,
23300 const
bool ignore_comments = false)
23302 auto ia = detail::input_adapter(std::forward<InputType>(i));
23303 return format == input_format_t::json
23304 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23310 template<
class IteratorType,
class SAX>
23311 JSON_HEDLEY_NON_NULL(3)
23312 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23313 input_format_t format = input_format_t::
json,
23314 const
bool strict = true,
23315 const
bool ignore_comments = false)
23317 auto ia = detail::input_adapter(std::move(first), std::move(last));
23318 return format == input_format_t::json
23319 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23328 template <
typename SAX>
23329 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...))
23330 JSON_HEDLEY_NON_NULL(2)
23331 static
bool sax_parse(
detail::span_input_adapter&& i, SAX* sax,
23332 input_format_t format = input_format_t::
json,
23333 const
bool strict = true,
23334 const
bool ignore_comments = false)
23337 return format == input_format_t::json
23339 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23350 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
23353 return operator>>(i, j);
23360 parser(detail::input_adapter(i)).parse(
false, j);
23372 JSON_HEDLEY_RETURNS_NON_NULL
23377 case value_t::null:
23379 case value_t::object:
23381 case value_t::array:
23383 case value_t::string:
23385 case value_t::boolean:
23387 case value_t::binary:
23389 case value_t::discarded:
23390 return "discarded";
23391 case value_t::number_integer:
23392 case value_t::number_unsigned:
23393 case value_t::number_float:
23400 JSON_PRIVATE_UNLESS_TESTED:
23406 value_t m_type = value_t::null;
23409 json_value m_value = {};
23411#if JSON_DIAGNOSTICS
23428 std::vector<std::uint8_t> result;
23429 to_cbor(j, result);
23437 binary_writer<std::uint8_t>(o).write_cbor(j);
23444 binary_writer<char>(o).write_cbor(j);
23451 std::vector<std::uint8_t> result;
23452 to_msgpack(j, result);
23460 binary_writer<std::uint8_t>(o).write_msgpack(j);
23467 binary_writer<char>(o).write_msgpack(j);
23473 const bool use_size =
false,
23474 const bool use_type =
false)
23476 std::vector<std::uint8_t> result;
23477 to_ubjson(j, result, use_size, use_type);
23484 const bool use_size =
false,
const bool use_type =
false)
23486 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
23492 const bool use_size =
false,
const bool use_type =
false)
23494 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
23500 const bool use_size =
false,
23501 const bool use_type =
false)
23503 std::vector<std::uint8_t> result;
23504 to_bjdata(j, result, use_size, use_type);
23511 const bool use_size =
false,
const bool use_type =
false)
23513 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type,
true,
true);
23519 const bool use_size =
false,
const bool use_type =
false)
23521 binary_writer<char>(o).write_ubjson(j, use_size, use_type,
true,
true);
23528 std::vector<std::uint8_t> result;
23529 to_bson(j, result);
23537 binary_writer<std::uint8_t>(o).write_bson(j);
23544 binary_writer<char>(o).write_bson(j);
23549 template<
typename InputType>
23550 JSON_HEDLEY_WARN_UNUSED_RESULT
23552 const bool strict =
true,
23553 const bool allow_exceptions =
true,
23558 auto ia = detail::input_adapter(std::forward<InputType>(i));
23559 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23560 return res ? result :
basic_json(value_t::discarded);
23565 template<
typename IteratorType>
23566 JSON_HEDLEY_WARN_UNUSED_RESULT
23568 const bool strict =
true,
23569 const bool allow_exceptions =
true,
23574 auto ia = detail::input_adapter(std::move(first), std::move(last));
23575 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23576 return res ? result :
basic_json(value_t::discarded);
23579 template<
typename T>
23580 JSON_HEDLEY_WARN_UNUSED_RESULT
23581 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23582 static basic_json from_cbor(
const T* ptr, std::size_t len,
23583 const bool strict =
true,
23584 const bool allow_exceptions =
true,
23585 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23587 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
23591 JSON_HEDLEY_WARN_UNUSED_RESULT
23592 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len))
23593 static basic_json from_cbor(detail::span_input_adapter&& i,
23594 const bool strict =
true,
23595 const bool allow_exceptions =
true,
23596 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
23602 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
23603 return res ? result :
basic_json(value_t::discarded);
23608 template<
typename InputType>
23609 JSON_HEDLEY_WARN_UNUSED_RESULT
23611 const bool strict =
true,
23612 const bool allow_exceptions =
true)
23616 auto ia = detail::input_adapter(std::forward<InputType>(i));
23617 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23618 return res ? result :
basic_json(value_t::discarded);
23623 template<
typename IteratorType>
23624 JSON_HEDLEY_WARN_UNUSED_RESULT
23626 const bool strict =
true,
23627 const bool allow_exceptions =
true)
23631 auto ia = detail::input_adapter(std::move(first), std::move(last));
23632 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23633 return res ? result :
basic_json(value_t::discarded);
23636 template<
typename T>
23637 JSON_HEDLEY_WARN_UNUSED_RESULT
23638 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23639 static basic_json from_msgpack(
const T* ptr, std::size_t len,
23640 const bool strict =
true,
23641 const bool allow_exceptions =
true)
23643 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
23646 JSON_HEDLEY_WARN_UNUSED_RESULT
23647 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len))
23648 static basic_json from_msgpack(detail::span_input_adapter&& i,
23649 const bool strict =
true,
23650 const bool allow_exceptions =
true)
23656 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
23657 return res ? result :
basic_json(value_t::discarded);
23662 template<
typename InputType>
23663 JSON_HEDLEY_WARN_UNUSED_RESULT
23665 const bool strict =
true,
23666 const bool allow_exceptions =
true)
23670 auto ia = detail::input_adapter(std::forward<InputType>(i));
23671 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23672 return res ? result :
basic_json(value_t::discarded);
23677 template<
typename IteratorType>
23678 JSON_HEDLEY_WARN_UNUSED_RESULT
23680 const bool strict =
true,
23681 const bool allow_exceptions =
true)
23685 auto ia = detail::input_adapter(std::move(first), std::move(last));
23686 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23687 return res ? result :
basic_json(value_t::discarded);
23690 template<
typename T>
23691 JSON_HEDLEY_WARN_UNUSED_RESULT
23692 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23693 static basic_json from_ubjson(
const T* ptr, std::size_t len,
23694 const bool strict =
true,
23695 const bool allow_exceptions =
true)
23697 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
23700 JSON_HEDLEY_WARN_UNUSED_RESULT
23701 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len))
23702 static basic_json from_ubjson(detail::span_input_adapter&& i,
23703 const bool strict =
true,
23704 const bool allow_exceptions =
true)
23710 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
23711 return res ? result :
basic_json(value_t::discarded);
23717 template<
typename InputType>
23718 JSON_HEDLEY_WARN_UNUSED_RESULT
23720 const bool strict =
true,
23721 const bool allow_exceptions =
true)
23725 auto ia = detail::input_adapter(std::forward<InputType>(i));
23726 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23727 return res ? result :
basic_json(value_t::discarded);
23732 template<
typename IteratorType>
23733 JSON_HEDLEY_WARN_UNUSED_RESULT
23735 const bool strict =
true,
23736 const bool allow_exceptions =
true)
23740 auto ia = detail::input_adapter(std::move(first), std::move(last));
23741 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
23742 return res ? result :
basic_json(value_t::discarded);
23747 template<
typename InputType>
23748 JSON_HEDLEY_WARN_UNUSED_RESULT
23750 const bool strict =
true,
23751 const bool allow_exceptions =
true)
23755 auto ia = detail::input_adapter(std::forward<InputType>(i));
23756 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23757 return res ? result :
basic_json(value_t::discarded);
23762 template<
typename IteratorType>
23763 JSON_HEDLEY_WARN_UNUSED_RESULT
23765 const bool strict =
true,
23766 const bool allow_exceptions =
true)
23770 auto ia = detail::input_adapter(std::move(first), std::move(last));
23771 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23772 return res ? result :
basic_json(value_t::discarded);
23775 template<
typename T>
23776 JSON_HEDLEY_WARN_UNUSED_RESULT
23777 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23778 static basic_json from_bson(
const T* ptr, std::size_t len,
23779 const bool strict =
true,
23780 const bool allow_exceptions =
true)
23782 return from_bson(ptr, ptr + len, strict, allow_exceptions);
23785 JSON_HEDLEY_WARN_UNUSED_RESULT
23786 JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len))
23787 static basic_json from_bson(detail::span_input_adapter&& i,
23788 const bool strict =
true,
23789 const bool allow_exceptions =
true)
23795 const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
23796 return res ? result :
basic_json(value_t::discarded);
23811 return ptr.get_unchecked(
this);
23814 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23816 reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23818 return ptr.get_unchecked(
this);
23825 return ptr.get_unchecked(
this);
23828 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23830 const_reference operator[](const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23832 return ptr.get_unchecked(
this);
23839 return ptr.get_checked(
this);
23842 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23844 reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
23846 return ptr.get_checked(
this);
23853 return ptr.get_checked(
this);
23856 template<typename BasicJsonType, detail::enable_if_t<detail::is_basic_json<BasicJsonType>::value,
int> = 0>
23858 const_reference at(const ::nlohmann::json_pointer<BasicJsonType>& ptr)
const
23860 return ptr.get_checked(
this);
23868 json_pointer::flatten(
"", *
this, result);
23876 return json_pointer::unflatten(*
this);
23894 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
23896 const auto get_op = [](
const std::string & op)
23900 return patch_operations::add;
23902 if (op ==
"remove")
23904 return patch_operations::remove;
23906 if (op ==
"replace")
23908 return patch_operations::replace;
23912 return patch_operations::move;
23916 return patch_operations::copy;
23920 return patch_operations::test;
23923 return patch_operations::invalid;
23938 if (top_pointer != ptr)
23940 result.
at(top_pointer);
23944 const auto last_path = ptr.
back();
23949 switch (parent.m_type)
23951 case value_t::null:
23952 case value_t::object:
23955 parent[last_path] = val;
23959 case value_t::array:
23961 if (last_path ==
"-")
23968 const auto idx = json_pointer::template array_index<basic_json_t>(last_path);
23969 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
23972 JSON_THROW(out_of_range::create(401, detail::concat(
"array index ", std::to_string(idx),
" is out of range"), &parent));
23982 case value_t::string:
23983 case value_t::boolean:
23984 case value_t::number_integer:
23985 case value_t::number_unsigned:
23986 case value_t::number_float:
23987 case value_t::binary:
23988 case value_t::discarded:
23990 JSON_ASSERT(
false);
23995 const auto operation_remove = [
this, &result](
json_pointer & ptr)
23998 const auto last_path = ptr.
back();
24006 auto it = parent.
find(last_path);
24007 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
24013 JSON_THROW(out_of_range::create(403, detail::concat(
"key '", last_path,
"' not found"),
this));
24019 parent.
erase(json_pointer::template array_index<basic_json_t>(last_path));
24024 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
24026 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &json_patch));
24030 for (
const auto& val : json_patch)
24033 const auto get_value = [&val](
const std::string & op,
24034 const std::string & member,
24038 auto it = val.
m_value.object->find(member);
24041 const auto error_msg = (op ==
"op") ?
"operation" : detail::concat(
"operation '", op,
'\'');
24044 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
24047 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have member '", member,
"'"), &val));
24051 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
24054 JSON_THROW(parse_error::create(105, 0, detail::concat(error_msg,
" must have string member '", member,
"'"), &val));
24062 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
24064 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", &val));
24068 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
24069 const auto path = get_value(op,
"path",
true).template get<std::string>();
24072 switch (get_op(op))
24074 case patch_operations::add:
24076 operation_add(ptr, get_value(
"add",
"value",
false));
24080 case patch_operations::remove:
24082 operation_remove(ptr);
24086 case patch_operations::replace:
24089 result.
at(ptr) = get_value(
"replace",
"value",
false);
24093 case patch_operations::move:
24095 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
24105 operation_remove(from_ptr);
24106 operation_add(ptr, v);
24110 case patch_operations::copy:
24112 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
24121 operation_add(ptr, v);
24125 case patch_operations::test:
24127 bool success =
false;
24132 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
24140 if (JSON_HEDLEY_UNLIKELY(!success))
24142 JSON_THROW(other_error::create(501, detail::concat(
"unsuccessful: ", val.dump()), &val));
24148 case patch_operations::invalid:
24153 JSON_THROW(parse_error::create(105, 0, detail::concat(
"operation value '", op,
"' is invalid"), &val));
24170 JSON_HEDLEY_WARN_UNUSED_RESULT
24172 const std::string& path =
"")
24178 if (source == target)
24183 if (source.
type() != target.
type())
24188 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24193 switch (source.
type())
24195 case value_t::array:
24199 while (i < source.
size() && i < target.
size())
24202 auto temp_diff = diff(source[i], target[i], detail::concat(path,
'/', std::to_string(i)));
24203 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24212 while (i < source.
size())
24216 result.
insert(result.
begin() + end_index, object(
24219 {
"path", detail::concat(path,
'/', std::to_string(i))}
24225 while (i < target.
size())
24230 {
"path", detail::concat(path,
"/-")},
24231 {
"value", target[i]}
24239 case value_t::object:
24242 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
24245 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24247 if (target.
find(it.key()) != target.
end())
24250 auto temp_diff = diff(it.value(), target[it.key()], path_key);
24251 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
24258 {
"op",
"remove"}, {
"path", path_key}
24264 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
24266 if (source.
find(it.key()) == source.
end())
24269 const auto path_key = detail::concat(path,
'/',
detail::escape(it.key()));
24272 {
"op",
"add"}, {
"path", path_key},
24273 {
"value", it.value()}
24281 case value_t::null:
24282 case value_t::string:
24283 case value_t::boolean:
24284 case value_t::number_integer:
24285 case value_t::number_unsigned:
24286 case value_t::number_float:
24287 case value_t::binary:
24288 case value_t::discarded:
24294 {
"op",
"replace"}, {
"path", path}, {
"value", target}
24321 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
24323 if (it.value().is_null())
24329 operator[](it.key()).merge_patch(it.value());
24335 *
this = apply_patch;
24344NLOHMANN_BASIC_JSON_TPL_DECLARATION
24345std::string to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
24350inline namespace literals
24352inline namespace json_literals
24357JSON_HEDLEY_NON_NULL(1)
24358inline nlohmann::json operator "" _json(const
char* s,
std::
size_t n)
24360 return nlohmann::json::parse(s, s + n);
24365JSON_HEDLEY_NON_NULL(1)
24366inline nlohmann::json::
json_pointer operator "" _json_pointer(const
char* s,
std::
size_t n)
24368 return nlohmann::json::json_pointer(std::string(s, n));
24373NLOHMANN_JSON_NAMESPACE_END
24384NLOHMANN_BASIC_JSON_TPL_DECLARATION
24385struct hash<nlohmann::NLOHMANN_BASIC_JSON_TPL>
24387 std::size_t operator()(
const nlohmann::NLOHMANN_BASIC_JSON_TPL& j)
const
24389 return nlohmann::detail::hash(j);
24395struct less< ::nlohmann::detail::value_t>
24402 ::nlohmann::detail::value_t rhs)
const noexcept
24404#if JSON_HAS_THREE_WAY_COMPARISON
24405 return std::is_lt(lhs <=> rhs);
24407 return ::nlohmann::detail::operator<(lhs, rhs);
24413#ifndef JSON_HAS_CPP_20
24417NLOHMANN_BASIC_JSON_TPL_DECLARATION
24418inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2)
noexcept(
24419 is_nothrow_move_constructible<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value&&
24420 is_nothrow_move_assignable<nlohmann::NLOHMANN_BASIC_JSON_TPL>::value)
24429#if JSON_USE_GLOBAL_UDLS
24430 using nlohmann::literals::json_literals::operator
"" _json;
24431 using nlohmann::literals::json_literals::operator
"" _json_pointer;
24446#if defined(__clang__)
24447 #pragma clang diagnostic pop
24452#undef JSON_INTERNAL_CATCH
24454#undef JSON_PRIVATE_UNLESS_TESTED
24455#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
24456#undef NLOHMANN_BASIC_JSON_TPL
24457#undef JSON_EXPLICIT
24458#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
24459#undef JSON_INLINE_VARIABLE
24460#undef JSON_NO_UNIQUE_ADDRESS
24461#undef JSON_DISABLE_ENUM_SERIALIZATION
24462#undef JSON_USE_GLOBAL_UDLS
24464#ifndef JSON_TEST_KEEP_MACROS
24467 #undef JSON_HAS_CPP_11
24468 #undef JSON_HAS_CPP_14
24469 #undef JSON_HAS_CPP_17
24470 #undef JSON_HAS_CPP_20
24471 #undef JSON_HAS_FILESYSTEM
24472 #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM
24473 #undef JSON_HAS_THREE_WAY_COMPARISON
24474 #undef JSON_HAS_RANGES
24475 #undef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON
24489#undef JSON_HEDLEY_ALWAYS_INLINE
24490#undef JSON_HEDLEY_ARM_VERSION
24491#undef JSON_HEDLEY_ARM_VERSION_CHECK
24492#undef JSON_HEDLEY_ARRAY_PARAM
24493#undef JSON_HEDLEY_ASSUME
24494#undef JSON_HEDLEY_BEGIN_C_DECLS
24495#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
24496#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
24497#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
24498#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
24499#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
24500#undef JSON_HEDLEY_CLANG_HAS_FEATURE
24501#undef JSON_HEDLEY_CLANG_HAS_WARNING
24502#undef JSON_HEDLEY_COMPCERT_VERSION
24503#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
24504#undef JSON_HEDLEY_CONCAT
24505#undef JSON_HEDLEY_CONCAT3
24506#undef JSON_HEDLEY_CONCAT3_EX
24507#undef JSON_HEDLEY_CONCAT_EX
24508#undef JSON_HEDLEY_CONST
24509#undef JSON_HEDLEY_CONSTEXPR
24510#undef JSON_HEDLEY_CONST_CAST
24511#undef JSON_HEDLEY_CPP_CAST
24512#undef JSON_HEDLEY_CRAY_VERSION
24513#undef JSON_HEDLEY_CRAY_VERSION_CHECK
24514#undef JSON_HEDLEY_C_DECL
24515#undef JSON_HEDLEY_DEPRECATED
24516#undef JSON_HEDLEY_DEPRECATED_FOR
24517#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
24518#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
24519#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
24520#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
24521#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
24522#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
24523#undef JSON_HEDLEY_DIAGNOSTIC_POP
24524#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
24525#undef JSON_HEDLEY_DMC_VERSION
24526#undef JSON_HEDLEY_DMC_VERSION_CHECK
24527#undef JSON_HEDLEY_EMPTY_BASES
24528#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
24529#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
24530#undef JSON_HEDLEY_END_C_DECLS
24531#undef JSON_HEDLEY_FLAGS
24532#undef JSON_HEDLEY_FLAGS_CAST
24533#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
24534#undef JSON_HEDLEY_GCC_HAS_BUILTIN
24535#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
24536#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
24537#undef JSON_HEDLEY_GCC_HAS_EXTENSION
24538#undef JSON_HEDLEY_GCC_HAS_FEATURE
24539#undef JSON_HEDLEY_GCC_HAS_WARNING
24540#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
24541#undef JSON_HEDLEY_GCC_VERSION
24542#undef JSON_HEDLEY_GCC_VERSION_CHECK
24543#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
24544#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
24545#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
24546#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
24547#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
24548#undef JSON_HEDLEY_GNUC_HAS_FEATURE
24549#undef JSON_HEDLEY_GNUC_HAS_WARNING
24550#undef JSON_HEDLEY_GNUC_VERSION
24551#undef JSON_HEDLEY_GNUC_VERSION_CHECK
24552#undef JSON_HEDLEY_HAS_ATTRIBUTE
24553#undef JSON_HEDLEY_HAS_BUILTIN
24554#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
24555#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
24556#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
24557#undef JSON_HEDLEY_HAS_EXTENSION
24558#undef JSON_HEDLEY_HAS_FEATURE
24559#undef JSON_HEDLEY_HAS_WARNING
24560#undef JSON_HEDLEY_IAR_VERSION
24561#undef JSON_HEDLEY_IAR_VERSION_CHECK
24562#undef JSON_HEDLEY_IBM_VERSION
24563#undef JSON_HEDLEY_IBM_VERSION_CHECK
24564#undef JSON_HEDLEY_IMPORT
24565#undef JSON_HEDLEY_INLINE
24566#undef JSON_HEDLEY_INTEL_CL_VERSION
24567#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
24568#undef JSON_HEDLEY_INTEL_VERSION
24569#undef JSON_HEDLEY_INTEL_VERSION_CHECK
24570#undef JSON_HEDLEY_IS_CONSTANT
24571#undef JSON_HEDLEY_IS_CONSTEXPR_
24572#undef JSON_HEDLEY_LIKELY
24573#undef JSON_HEDLEY_MALLOC
24574#undef JSON_HEDLEY_MCST_LCC_VERSION
24575#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
24576#undef JSON_HEDLEY_MESSAGE
24577#undef JSON_HEDLEY_MSVC_VERSION
24578#undef JSON_HEDLEY_MSVC_VERSION_CHECK
24579#undef JSON_HEDLEY_NEVER_INLINE
24580#undef JSON_HEDLEY_NON_NULL
24581#undef JSON_HEDLEY_NO_ESCAPE
24582#undef JSON_HEDLEY_NO_RETURN
24583#undef JSON_HEDLEY_NO_THROW
24584#undef JSON_HEDLEY_NULL
24585#undef JSON_HEDLEY_PELLES_VERSION
24586#undef JSON_HEDLEY_PELLES_VERSION_CHECK
24587#undef JSON_HEDLEY_PGI_VERSION
24588#undef JSON_HEDLEY_PGI_VERSION_CHECK
24589#undef JSON_HEDLEY_PREDICT
24590#undef JSON_HEDLEY_PRINTF_FORMAT
24591#undef JSON_HEDLEY_PRIVATE
24592#undef JSON_HEDLEY_PUBLIC
24593#undef JSON_HEDLEY_PURE
24594#undef JSON_HEDLEY_REINTERPRET_CAST
24595#undef JSON_HEDLEY_REQUIRE
24596#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
24597#undef JSON_HEDLEY_REQUIRE_MSG
24598#undef JSON_HEDLEY_RESTRICT
24599#undef JSON_HEDLEY_RETURNS_NON_NULL
24600#undef JSON_HEDLEY_SENTINEL
24601#undef JSON_HEDLEY_STATIC_ASSERT
24602#undef JSON_HEDLEY_STATIC_CAST
24603#undef JSON_HEDLEY_STRINGIFY
24604#undef JSON_HEDLEY_STRINGIFY_EX
24605#undef JSON_HEDLEY_SUNPRO_VERSION
24606#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
24607#undef JSON_HEDLEY_TINYC_VERSION
24608#undef JSON_HEDLEY_TINYC_VERSION_CHECK
24609#undef JSON_HEDLEY_TI_ARMCL_VERSION
24610#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
24611#undef JSON_HEDLEY_TI_CL2000_VERSION
24612#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
24613#undef JSON_HEDLEY_TI_CL430_VERSION
24614#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
24615#undef JSON_HEDLEY_TI_CL6X_VERSION
24616#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
24617#undef JSON_HEDLEY_TI_CL7X_VERSION
24618#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
24619#undef JSON_HEDLEY_TI_CLPRU_VERSION
24620#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
24621#undef JSON_HEDLEY_TI_VERSION
24622#undef JSON_HEDLEY_TI_VERSION_CHECK
24623#undef JSON_HEDLEY_UNAVAILABLE
24624#undef JSON_HEDLEY_UNLIKELY
24625#undef JSON_HEDLEY_UNPREDICTABLE
24626#undef JSON_HEDLEY_UNREACHABLE
24627#undef JSON_HEDLEY_UNREACHABLE_RETURN
24628#undef JSON_HEDLEY_VERSION
24629#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
24630#undef JSON_HEDLEY_VERSION_DECODE_MINOR
24631#undef JSON_HEDLEY_VERSION_DECODE_REVISION
24632#undef JSON_HEDLEY_VERSION_ENCODE
24633#undef JSON_HEDLEY_WARNING
24634#undef JSON_HEDLEY_WARN_UNUSED_RESULT
24635#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
24636#undef JSON_HEDLEY_FALL_THROUGH
a class to store JSON values
Definition json.hpp:19313
constexpr bool is_string() const noexcept
return whether value is a string
Definition json.hpp:20580
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
Definition json.hpp:21814
reference operator[](KeyType &&key)
access specified object element
Definition json.hpp:21382
size_type size() const noexcept
returns the number of elements
Definition json.hpp:22158
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.hpp:23567
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.hpp:23499
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.hpp:20953
const_iterator end() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22014
reference back()
access the last element
Definition json.hpp:21618
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.hpp:20043
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22030
basic_json patch(const basic_json &json_patch) const
applies a JSON patch to a copy of the current object
Definition json.hpp:24161
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition json.hpp:23373
const_reference front() const
access the first element
Definition json.hpp:21611
constexpr bool is_array() const noexcept
return whether value is an array
Definition json.hpp:20573
ReturnType value(const json_pointer &ptr, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21562
size_type count(KeyType &&key) const
returns the number of occurrences of a key in a JSON object
Definition json.hpp:21932
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
Definition json.hpp:19445
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.hpp:23518
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
Definition json.hpp:19388
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
Definition json.hpp:20545
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
Definition json.hpp:19449
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.hpp:23764
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.hpp:23510
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:23809
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
Definition json.hpp:19440
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 &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:22676
std::size_t size_type
a type to represent container sizes
Definition json.hpp:19432
constexpr bool is_structured() const noexcept
return whether type is structured
Definition json.hpp:20517
const_reference operator[](KeyType &&key) const
access specified object element
Definition json.hpp:21406
void swap(binary_t &other)
exchanges the values
Definition json.hpp:22753
ReferenceType get_ref()
get a reference value (implicit)
Definition json.hpp:21043
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition json.hpp:22197
void update(const_reference j, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:22622
ReferenceType get_ref() const
get a reference value (implicit)
Definition json.hpp:21054
constexpr bool is_discarded() const noexcept
return whether value is discarded
Definition json.hpp:20594
reference operator+=(initializer_list_t init)
add an object to an object
Definition json.hpp:22414
void push_back(basic_json &&val)
add an object to an array
Definition json.hpp:22302
const_reference operator[](const typename object_t::key_type &key) const
access specified object element
Definition json.hpp:21351
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22102
const_reference back() const
access the last element
Definition json.hpp:21627
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
Definition json.hpp:21709
reference operator+=(const basic_json &val)
add an object to an array
Definition json.hpp:22359
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.hpp:23664
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.hpp:20177
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts copies of element into array
Definition json.hpp:22526
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.hpp:23749
static allocator_type get_allocator()
returns the allocator associated with the container
Definition json.hpp:19456
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
Definition json.hpp:19583
reference at(KeyType &&key)
access specified object element with bounds checking
Definition json.hpp:21214
iterator end() noexcept
returns an iterator to one past the last element
Definition json.hpp:22005
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
Definition json.hpp:20552
void update(const_iterator first, const_iterator last, bool merge_objects=false)
updates a JSON object from another object, overwriting existing keys
Definition json.hpp:22629
static std::vector< std::uint8_t > to_bson(const basic_json &j)
create a BSON serialization of a given JSON value
Definition json.hpp:23526
const_reverse_iterator rbegin() const noexcept
returns an iterator to the reverse-beginning
Definition json.hpp:22037
void push_back(initializer_list_t init)
add an object to an object
Definition json.hpp:22398
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
Definition json.hpp:20010
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition json.hpp:20218
static void to_msgpack(const basic_json &j, detail::output_adapter< char > o)
create a MessagePack serialization of a given JSON value
Definition json.hpp:23465
iterator begin() noexcept
returns an iterator to the first element
Definition json.hpp:21980
ReturnType value(const typename object_t::key_type &key, ValueType &&default_value) const
access specified object element with default value
Definition json.hpp:21461
const_iterator cend() const noexcept
returns an iterator to one past the last element
Definition json.hpp:22021
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.hpp:23719
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:23851
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array
Definition json.hpp:20188
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
Definition json.hpp:20031
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.hpp:23551
basic_json flatten() const
return flattened JSON value
Definition json.hpp:23865
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.hpp:23679
size_type erase(KeyType &&key)
remove element from a JSON object given a key
Definition json.hpp:21825
const binary_t & get_binary() const
get a binary value
Definition json.hpp:21125
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts range of elements into array
Definition json.hpp:22546
void patch_inplace(const basic_json &json_patch)
applies a JSON patch in-place without copying the object
Definition json.hpp:23890
ReturnType value(KeyType &&key, ValueType &&default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21514
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.hpp:24171
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
Definition json.hpp:23823
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Definition json.hpp:19559
bool contains(KeyType &&key) const
check the existence of an element in a JSON object
Definition json.hpp:21949
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.hpp:23435
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
create a BSON serialization of a given JSON value
Definition json.hpp:23542
iterator find(const typename object_t::key_type &key)
find an element in a JSON object
Definition json.hpp:21862
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.hpp:20166
const_reference at(KeyType &&key) const
access specified object element with bounds checking
Definition json.hpp:21252
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
Definition json.hpp:19464
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
Definition json.hpp:20225
const_iterator find(const typename object_t::key_type &key) const
find an element in a JSON object
Definition json.hpp:21876
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:23426
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition json.hpp:21639
iterator insert(const_iterator pos, const basic_json &val)
inserts element into array
Definition json.hpp:22499
NumberFloatType number_float_t
a type for a number (floating-point)
Definition json.hpp:19579
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:21436
AllocatorType< basic_json > allocator_type
the allocator type
Definition json.hpp:19435
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
Definition json.hpp:19438
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.hpp:20481
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition json.hpp:24313
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.hpp:21007
reference at(size_type idx)
access specified array element with bounds checking
Definition json.hpp:21148
iterator find(KeyType &&key)
find an element in a JSON object
Definition json.hpp:21892
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
Definition json.hpp:20559
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
Definition json.hpp:22044
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.hpp:23472
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
Definition json.hpp:23837
BooleanType boolean_t
a type for a boolean
Definition json.hpp:19567
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.hpp:19546
reference operator+=(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:22390
const_iterator cbegin() const noexcept
returns a const iterator to the first element
Definition json.hpp:21996
reference operator[](typename object_t::key_type key)
access specified object element
Definition json.hpp:21329
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.hpp:20765
~basic_json() noexcept
destructor
Definition json.hpp:20462
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
Definition json.hpp:22065
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.hpp:20110
void swap(typename binary_t::container_type &other)
exchanges the values
Definition json.hpp:22769
binary_t & get_binary()
get a binary value
Definition json.hpp:21113
const_iterator begin() const noexcept
returns an iterator to the first element
Definition json.hpp:21989
constexpr bool is_number() const noexcept
return whether value is a number
Definition json.hpp:20538
void insert(const_iterator first, const_iterator last)
inserts range of elements into object
Definition json.hpp:22597
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.hpp:23610
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
Definition json.hpp:20994
reference operator[](size_type idx)
access specified array element
Definition json.hpp:21270
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.hpp:20439
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.hpp:23491
NumberIntegerType number_integer_t
a type for a number (integer)
Definition json.hpp:19571
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
Definition json.hpp:20754
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
Definition json.hpp:21232
constexpr bool is_binary() const noexcept
return whether value is a binary array
Definition json.hpp:20587
void swap(object_t &other)
exchanges the values
Definition json.hpp:22721
basic_json unflatten() const
unflatten a previously flattened JSON value
Definition json.hpp:23874
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements from initializer list into array
Definition json.hpp:22577
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.hpp:20199
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition json.hpp:22095
bool empty() const noexcept
checks whether the container is empty.
Definition json.hpp:22119
void swap(array_t &other)
exchanges the values
Definition json.hpp:22705
void erase(const size_type idx)
remove element from a JSON array given an index
Definition json.hpp:21832
reference operator+=(basic_json &&val)
add an object to an array
Definition json.hpp:22327
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
Definition json.hpp:21956
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition json.hpp:20503
reference emplace_back(Args &&... args)
add an object to an array
Definition json.hpp:22423
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
Definition json.hpp:21537
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
Definition json.hpp:20210
StringType string_t
a type for a string
Definition json.hpp:19563
ObjectType< StringType, basic_json, default_object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
Definition json.hpp:19555
void push_back(const basic_json &val)
add an object to an array
Definition json.hpp:22335
ValueType value(KeyType &&key, const ValueType &default_value) const
access specified object element with default value
Definition json.hpp:21487
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
Definition json.hpp:21194
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.hpp:23734
json_value m_value
the value of the current element
Definition json.hpp:23409
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
Definition json.hpp:22058
constexpr bool is_boolean() const noexcept
return whether value is a boolean
Definition json.hpp:20531
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.hpp:21922
reference front()
access the first element
Definition json.hpp:21604
constexpr bool is_primitive() const noexcept
return whether type is primitive
Definition json.hpp:20510
constexpr bool is_null() const noexcept
return whether value is null
Definition json.hpp:20524
void clear() noexcept
clears the contents
Definition json.hpp:22241
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.hpp:23483
basic_json(basic_json &&other) noexcept
move constructor
Definition json.hpp:20421
iter_impl< basic_json > iterator
an iterator for a basic_json container
Definition json.hpp:19443
basic_json(const value_t v)
create an empty value with a given type
Definition json.hpp:20023
const_reference operator[](size_type idx) const
access specified array element
Definition json.hpp:21316
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition json.hpp:19430
iterator insert(const_iterator pos, basic_json &&val)
inserts element into array
Definition json.hpp:22519
const_reverse_iterator rend() const noexcept
returns an iterator to the reverse-end
Definition json.hpp:22051
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
Definition json.hpp:19575
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
Definition json.hpp:23358
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
Definition json.hpp:23449
void swap(string_t &other)
exchanges the values
Definition json.hpp:22737
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
Definition json.hpp:20057
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
Definition json.hpp:19447
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 &&std::is_nothrow_move_assignable< json_value >::value)
exchanges the values
Definition json.hpp:22693
const_reference at(size_type idx) const
access specified array element with bounds checking
Definition json.hpp:21171
detail::actual_object_comparator_t< basic_json > object_comparator_t
object key comparator type
Definition json.hpp:19587
basic_json(const basic_json &other)
copy constructor
Definition json.hpp:20352
void push_back(const typename object_t::value_type &val)
add an object to an object
Definition json.hpp:22367
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
Definition json.hpp:22448
static void to_cbor(const basic_json &j, detail::output_adapter< char > o)
create a CBOR serialization of a given JSON value
Definition json.hpp:23442
constexpr bool is_object() const noexcept
return whether value is an object
Definition json.hpp:20566
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.hpp:23458
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.hpp:23625
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
Definition json.hpp:22480
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
Definition json.hpp:20238
bool contains(const typename object_t::key_type &key) const
check the existence of an element in a JSON object
Definition json.hpp:21940
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.hpp:23535
const_iterator find(KeyType &&key) const
find an element in a JSON object
Definition json.hpp:21908
::nlohmann::json_pointer< StringType > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition json.hpp:19380
an internal type for a backed binary type
Definition json.hpp:5824
byte_container_with_subtype() noexcept(noexcept(container_type()))
Definition json.hpp:5830
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5852
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
Definition json.hpp:5840
constexpr subtype_type subtype() const noexcept
return the binary subtype
Definition json.hpp:5879
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
Definition json.hpp:5845
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
Definition json.hpp:5886
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
Definition json.hpp:5835
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
Definition json.hpp:5871
void clear_subtype() noexcept
clears the binary subtype
Definition json.hpp:5893
deserialization of CBOR, MessagePack, and UBJSON values
Definition json.hpp:9146
binary_reader(InputAdapterType &&adapter, const input_format_t format=input_format_t::json) noexcept
create a binary reader
Definition json.hpp:9162
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.hpp:9183
general exception of the basic_json class
Definition json.hpp:4305
const int id
the id of the exception
Definition json.hpp:4314
const char * what() const noexcept override
returns the explanatory string
Definition json.hpp:4308
exception indicating errors with iterators
Definition json.hpp:4456
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
Definition json.hpp:12838
iter_impl operator+(difference_type i) const
add to iterator
Definition json.hpp:13412
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
Definition json.hpp:12975
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
Definition json.hpp:13357
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
Definition json.hpp:12965
bool operator<(const iter_impl &other) const
comparison: smaller
Definition json.hpp:13304
bool operator<=(const iter_impl &other) const
comparison: less than or equal
Definition json.hpp:13339
iter_impl & operator-=(difference_type i)
subtract from iterator
Definition json.hpp:13403
iter_impl & operator--()
pre-decrement (–it)
Definition json.hpp:13218
const object_t::key_type & key() const
return the key of an object iterator
Definition json.hpp:13512
bool operator==(const IterImpl &other) const
comparison: equal
Definition json.hpp:13259
iter_impl operator++(int) &
post-increment (it++)
Definition json.hpp:13156
iter_impl & operator+=(difference_type i)
add to iterator
Definition json.hpp:13366
reference operator[](difference_type n) const
access to successor
Definition json.hpp:13474
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
Definition json.hpp:12868
pointer operator->() const
dereference the iterator
Definition json.hpp:13114
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
Definition json.hpp:13537
difference_type operator-(const iter_impl &other) const
return difference
Definition json.hpp:13445
std::bidirectional_iterator_tag iterator_category
The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
Definition json.hpp:12863
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
Definition json.hpp:13423
reference value() const
return the value of an iterator
Definition json.hpp:13528
bool operator>(const iter_impl &other) const
comparison: greater than
Definition json.hpp:13348
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.hpp:12872
iter_impl & operator++()
pre-increment (++it)
Definition json.hpp:13167
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
Definition json.hpp:12866
reference operator*() const
return a reference to the value pointed to by the iterator
Definition json.hpp:13070
iter_impl operator-(difference_type i) const
subtract from iterator
Definition json.hpp:13434
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
Definition json.hpp:12950
bool operator!=(const IterImpl &other) const
comparison: not equal
Definition json.hpp:13295
iter_impl operator--(int) &
post-decrement (it–)
Definition json.hpp:13207
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.hpp:12877
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
Definition json.hpp:12940
void set_end() noexcept
set the iterator past the last value
Definition json.hpp:13031
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
Definition json.hpp:5184
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
Definition json.hpp:5190
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
Definition json.hpp:5167
const iteration_proxy_value & operator*() const
dereference operator (needed for range-based for)
Definition json.hpp:5161
IteratorType::reference value() const
return value of the iterator
Definition json.hpp:5232
const string_type & key() const
return key of the iterator
Definition json.hpp:5196
proxy class for the items() function
Definition json.hpp:5240
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
Definition json.hpp:5265
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
Definition json.hpp:5259
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
Definition json.hpp:5249
Definition json.hpp:14734
a template for a reverse iterator class
Definition json.hpp:13591
json_reverse_iterator operator++(int) &
post-increment (it++)
Definition json.hpp:13607
json_reverse_iterator operator--(int) &
post-decrement (it–)
Definition json.hpp:13619
json_reverse_iterator & operator++()
pre-increment (++it)
Definition json.hpp:13613
json_reverse_iterator & operator+=(difference_type i)
add to iterator
Definition json.hpp:13631
reference operator[](difference_type n) const
access to successor
Definition json.hpp:13655
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
Definition json.hpp:13661
difference_type operator-(const json_reverse_iterator &other) const
return difference
Definition json.hpp:13649
typename Base::reference reference
the reference type for the pointed-to element
Definition json.hpp:13597
reference value() const
return the value of an iterator
Definition json.hpp:13668
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
Definition json.hpp:13604
json_reverse_iterator & operator--()
pre-decrement (–it)
Definition json.hpp:13625
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
Definition json.hpp:13595
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
Definition json.hpp:13643
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
Definition json.hpp:13600
json_reverse_iterator operator+(difference_type i) const
add to iterator
Definition json.hpp:13637
SAX implementation to create a JSON value from SAX events.
Definition json.hpp:6735
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
Definition json.hpp:6748
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.hpp:7367
token_type
token types for the parser
Definition json.hpp:7344
lexical analysis
Definition json.hpp:7417
bool skip_bom()
skip the UTF-8 byte order mark
Definition json.hpp:8791
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
Definition json.hpp:8778
std::string get_token_string() const
return the last read token (for errors only).
Definition json.hpp:8753
constexpr number_integer_t get_number_integer() const noexcept
return integer value
Definition json.hpp:8717
constexpr position_t get_position() const noexcept
return position of last read token
Definition json.hpp:8745
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
Definition json.hpp:8723
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
Definition json.hpp:8735
constexpr number_float_t get_number_float() const noexcept
return floating-point value
Definition json.hpp:8729
exception indicating other library errors
Definition json.hpp:4508
exception indicating access out of the defined range
Definition json.hpp:4491
exception indicating a parse error
Definition json.hpp:4403
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, BasicJsonContext context)
create a parse error exception
Definition json.hpp:4415
const std::size_t byte
byte index of the parse error
Definition json.hpp:4440
Definition json.hpp:17974
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
Definition json.hpp:17989
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition json.hpp:18906
string_t indent_string
the indentation string
Definition json.hpp:18903
const char indent_char
the indentation character
Definition json.hpp:18901
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.hpp:18029
exception indicating executing a member function with a wrong type
Definition json.hpp:4474
JSON Pointer defines a string syntax for identifying a specific value within a JSON document.
Definition json.hpp:13755
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.hpp:13850
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.hpp:13857
json_pointer(const string_t &s="")
create JSON pointer
Definition json.hpp:13781
bool empty() const noexcept
return whether pointer points to the root document
Definition json.hpp:13916
void pop_back()
remove last reference token
Definition json.hpp:13878
string_t to_string() const
return a string representation of the JSON pointer
Definition json.hpp:13787
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
Definition json.hpp:13835
void push_back(string_t &&token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:13909
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
Definition json.hpp:13817
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.hpp:13842
json_pointer parent_pointer() const
returns the parent of this JSON pointer
Definition json.hpp:13864
json_pointer & operator/=(string_t token)
append an unescaped reference token at the end of this JSON pointer
Definition json.hpp:13827
const string_t & back() const
return last reference token
Definition json.hpp:13890
friend std::ostream & operator<<(std::ostream &o, const json_pointer &ptr)
write string representation of the JSON pointer to stream
Definition json.hpp:13808
void push_back(const string_t &token)
append an unescaped token at the end of the reference pointer
Definition json.hpp:13902
detail namespace with internal helper functions
Definition json.hpp:249
void replace_substring(StringType &s, const StringType &f, const StringType &t)
replace all occurrences of a substring by another string
Definition json.hpp:2958
cbor_tag_handler_t
how to treat CBOR tags
Definition json.hpp:9118
@ 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.hpp:2860
@ 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)
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
Definition json.hpp:2889
error_handler_t
how to treat decoding errors
Definition json.hpp:17966
@ strict
throw a type_error exception in case of invalid UTF-8
StringType escape(StringType s)
string escaping as described in RFC 6901 (Sect. 4)
Definition json.hpp:2977
std::string type_name()
the string representation of type name
Definition type_traits.h:101
std::istream & operator>>(std::istream &is, optional< T > &t)
parse a string object into optional<T>
Definition optional.h:323
int N
Simulate some binary data with a single categorical and single continuous predictor.
Definition logistic_regression.py:26
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:24418
std::uint32_t position_t
top-k position
Definition ranking_utils.h:34
namespace for Niels Lohmann
Definition json.hpp:5766
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.hpp:5790
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.hpp:5780
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.hpp:5770
an iterator value
Definition json.hpp:12771
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
Definition json.hpp:12775
primitive_iterator_t primitive_iterator
generic iterator for all other types
Definition json.hpp:12777
Default base class of the basic_json class.
Definition json.hpp:13702
struct to capture the start position of the current token
Definition json.hpp:3023
std::size_t chars_read_current_line
the number of characters read in the current line
Definition json.hpp:3027
std::size_t lines_read
the number of lines read
Definition json.hpp:3029
std::size_t chars_read_total
the total number of characters read
Definition json.hpp:3025
SAX interface.
Definition json.hpp:6604
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:18948
bool operator()(::nlohmann::detail::value_t lhs, ::nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values
Definition json.hpp:24401