30#ifndef INCLUDE_NLOHMANN_JSON_HPP_
31#define INCLUDE_NLOHMANN_JSON_HPP_
33#define NLOHMANN_JSON_VERSION_MAJOR 3
34#define NLOHMANN_JSON_VERSION_MINOR 10
35#define NLOHMANN_JSON_VERSION_PATCH 2
40#include <initializer_list>
62#include <forward_list>
68#include <unordered_map>
149 static constexpr std::array<std::uint8_t, 9> order = {{
155 const auto l_index =
static_cast<std::size_t
>(lhs);
156 const auto r_index =
static_cast<std::size_t
>(rhs);
157 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
185#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
186#if defined(JSON_HEDLEY_VERSION)
187#undef JSON_HEDLEY_VERSION
189#define JSON_HEDLEY_VERSION 15
191#if defined(JSON_HEDLEY_STRINGIFY_EX)
192#undef JSON_HEDLEY_STRINGIFY_EX
194#define JSON_HEDLEY_STRINGIFY_EX(x) #x
196#if defined(JSON_HEDLEY_STRINGIFY)
197#undef JSON_HEDLEY_STRINGIFY
199#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
201#if defined(JSON_HEDLEY_CONCAT_EX)
202#undef JSON_HEDLEY_CONCAT_EX
204#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
206#if defined(JSON_HEDLEY_CONCAT)
207#undef JSON_HEDLEY_CONCAT
209#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
211#if defined(JSON_HEDLEY_CONCAT3_EX)
212#undef JSON_HEDLEY_CONCAT3_EX
214#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
216#if defined(JSON_HEDLEY_CONCAT3)
217#undef JSON_HEDLEY_CONCAT3
219#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
221#if defined(JSON_HEDLEY_VERSION_ENCODE)
222#undef JSON_HEDLEY_VERSION_ENCODE
224#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
226#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
227#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
229#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
231#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
232#undef JSON_HEDLEY_VERSION_DECODE_MINOR
234#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
236#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
237#undef JSON_HEDLEY_VERSION_DECODE_REVISION
239#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
241#if defined(JSON_HEDLEY_GNUC_VERSION)
242#undef JSON_HEDLEY_GNUC_VERSION
244#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
245#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
246#elif defined(__GNUC__)
247#define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
250#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
251#undef JSON_HEDLEY_GNUC_VERSION_CHECK
253#if defined(JSON_HEDLEY_GNUC_VERSION)
254#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
256#define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
259#if defined(JSON_HEDLEY_MSVC_VERSION)
260#undef JSON_HEDLEY_MSVC_VERSION
262#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
263#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
264#elif defined(_MSC_FULL_VER) && !defined(__ICL)
265#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
266#elif defined(_MSC_VER) && !defined(__ICL)
267#define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
270#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
271#undef JSON_HEDLEY_MSVC_VERSION_CHECK
273#if !defined(JSON_HEDLEY_MSVC_VERSION)
274#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
275#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
276#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
277#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
278#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
280#define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
283#if defined(JSON_HEDLEY_INTEL_VERSION)
284#undef JSON_HEDLEY_INTEL_VERSION
286#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
287#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
288#elif defined(__INTEL_COMPILER) && !defined(__ICL)
289#define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
292#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
293#undef JSON_HEDLEY_INTEL_VERSION_CHECK
295#if defined(JSON_HEDLEY_INTEL_VERSION)
296#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
298#define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
301#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
302#undef JSON_HEDLEY_INTEL_CL_VERSION
304#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
305#define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
308#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
309#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
311#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
312#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
314#define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
317#if defined(JSON_HEDLEY_PGI_VERSION)
318#undef JSON_HEDLEY_PGI_VERSION
320#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
321#define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
324#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
325#undef JSON_HEDLEY_PGI_VERSION_CHECK
327#if defined(JSON_HEDLEY_PGI_VERSION)
328#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
330#define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
333#if defined(JSON_HEDLEY_SUNPRO_VERSION)
334#undef JSON_HEDLEY_SUNPRO_VERSION
336#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
337#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)
338#elif defined(__SUNPRO_C)
339#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
340#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
341#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)
342#elif defined(__SUNPRO_CC)
343#define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
346#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
347#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
349#if defined(JSON_HEDLEY_SUNPRO_VERSION)
350#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
352#define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
355#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
356#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
358#if defined(__EMSCRIPTEN__)
359#define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
362#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
363#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
365#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
366#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
368#define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
371#if defined(JSON_HEDLEY_ARM_VERSION)
372#undef JSON_HEDLEY_ARM_VERSION
374#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
375#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
376#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
377#define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
380#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
381#undef JSON_HEDLEY_ARM_VERSION_CHECK
383#if defined(JSON_HEDLEY_ARM_VERSION)
384#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
386#define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
389#if defined(JSON_HEDLEY_IBM_VERSION)
390#undef JSON_HEDLEY_IBM_VERSION
392#if defined(__ibmxl__)
393#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
394#elif defined(__xlC__) && defined(__xlC_ver__)
395#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
396#elif defined(__xlC__)
397#define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
400#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
401#undef JSON_HEDLEY_IBM_VERSION_CHECK
403#if defined(JSON_HEDLEY_IBM_VERSION)
404#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
406#define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
409#if defined(JSON_HEDLEY_TI_VERSION)
410#undef JSON_HEDLEY_TI_VERSION
413 defined(__TI_COMPILER_VERSION__) && \
415 defined(__TMS470__) || defined(__TI_ARM__) || \
416 defined(__MSP430__) || \
417 defined(__TMS320C2000__) \
419#if (__TI_COMPILER_VERSION__ >= 16000000)
420#define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
424#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
425#undef JSON_HEDLEY_TI_VERSION_CHECK
427#if defined(JSON_HEDLEY_TI_VERSION)
428#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
430#define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
433#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
434#undef JSON_HEDLEY_TI_CL2000_VERSION
436#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
437#define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
440#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
441#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
443#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
444#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
446#define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
449#if defined(JSON_HEDLEY_TI_CL430_VERSION)
450#undef JSON_HEDLEY_TI_CL430_VERSION
452#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
453#define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
456#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
457#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
459#if defined(JSON_HEDLEY_TI_CL430_VERSION)
460#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
462#define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
465#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
466#undef JSON_HEDLEY_TI_ARMCL_VERSION
468#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
469#define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
472#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
473#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
475#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
476#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
478#define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
481#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
482#undef JSON_HEDLEY_TI_CL6X_VERSION
484#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
485#define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
488#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
489#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
491#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
492#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
494#define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
497#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
498#undef JSON_HEDLEY_TI_CL7X_VERSION
500#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
501#define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
504#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
505#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
507#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
508#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
510#define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
513#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
514#undef JSON_HEDLEY_TI_CLPRU_VERSION
516#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
517#define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
520#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
521#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
523#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
524#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
526#define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
529#if defined(JSON_HEDLEY_CRAY_VERSION)
530#undef JSON_HEDLEY_CRAY_VERSION
533#if defined(_RELEASE_PATCHLEVEL)
534#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
536#define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
540#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
541#undef JSON_HEDLEY_CRAY_VERSION_CHECK
543#if defined(JSON_HEDLEY_CRAY_VERSION)
544#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
546#define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
549#if defined(JSON_HEDLEY_IAR_VERSION)
550#undef JSON_HEDLEY_IAR_VERSION
552#if defined(__IAR_SYSTEMS_ICC__)
554#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
556#define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
560#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
561#undef JSON_HEDLEY_IAR_VERSION_CHECK
563#if defined(JSON_HEDLEY_IAR_VERSION)
564#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
566#define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
569#if defined(JSON_HEDLEY_TINYC_VERSION)
570#undef JSON_HEDLEY_TINYC_VERSION
572#if defined(__TINYC__)
573#define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
576#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
577#undef JSON_HEDLEY_TINYC_VERSION_CHECK
579#if defined(JSON_HEDLEY_TINYC_VERSION)
580#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
582#define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
585#if defined(JSON_HEDLEY_DMC_VERSION)
586#undef JSON_HEDLEY_DMC_VERSION
589#define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
592#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
593#undef JSON_HEDLEY_DMC_VERSION_CHECK
595#if defined(JSON_HEDLEY_DMC_VERSION)
596#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
598#define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
601#if defined(JSON_HEDLEY_COMPCERT_VERSION)
602#undef JSON_HEDLEY_COMPCERT_VERSION
604#if defined(__COMPCERT_VERSION__)
605#define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
608#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
609#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
611#if defined(JSON_HEDLEY_COMPCERT_VERSION)
612#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
614#define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
617#if defined(JSON_HEDLEY_PELLES_VERSION)
618#undef JSON_HEDLEY_PELLES_VERSION
621#define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
624#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
625#undef JSON_HEDLEY_PELLES_VERSION_CHECK
627#if defined(JSON_HEDLEY_PELLES_VERSION)
628#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
630#define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
633#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
634#undef JSON_HEDLEY_MCST_LCC_VERSION
636#if defined(__LCC__) && defined(__LCC_MINOR__)
637#define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
640#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
641#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
643#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
644#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
646#define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
649#if defined(JSON_HEDLEY_GCC_VERSION)
650#undef JSON_HEDLEY_GCC_VERSION
653 defined(JSON_HEDLEY_GNUC_VERSION) && \
654 !defined(__clang__) && \
655 !defined(JSON_HEDLEY_INTEL_VERSION) && \
656 !defined(JSON_HEDLEY_PGI_VERSION) && \
657 !defined(JSON_HEDLEY_ARM_VERSION) && \
658 !defined(JSON_HEDLEY_CRAY_VERSION) && \
659 !defined(JSON_HEDLEY_TI_VERSION) && \
660 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
661 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
662 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
663 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
664 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
665 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
666 !defined(__COMPCERT__) && \
667 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
668#define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
671#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
672#undef JSON_HEDLEY_GCC_VERSION_CHECK
674#if defined(JSON_HEDLEY_GCC_VERSION)
675#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
677#define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
680#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
681#undef JSON_HEDLEY_HAS_ATTRIBUTE
684 defined(__has_attribute) && \
686 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
688# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
690# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
693#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
694#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
696#if defined(__has_attribute)
697#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
699#define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
702#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
703#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
705#if defined(__has_attribute)
706#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
708#define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
711#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
712#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
715 defined(__has_cpp_attribute) && \
716 defined(__cplusplus) && \
717 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
718#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
720#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
723#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
724#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
726#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
727#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
729 !defined(JSON_HEDLEY_PGI_VERSION) && \
730 !defined(JSON_HEDLEY_IAR_VERSION) && \
731 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
732 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
733#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
735#define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
738#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
739#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
741#if defined(__has_cpp_attribute) && defined(__cplusplus)
742#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
744#define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
747#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
748#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
750#if defined(__has_cpp_attribute) && defined(__cplusplus)
751#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
753#define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
756#if defined(JSON_HEDLEY_HAS_BUILTIN)
757#undef JSON_HEDLEY_HAS_BUILTIN
759#if defined(__has_builtin)
760#define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
762#define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
765#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
766#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
768#if defined(__has_builtin)
769#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
771#define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
774#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
775#undef JSON_HEDLEY_GCC_HAS_BUILTIN
777#if defined(__has_builtin)
778#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
780#define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
783#if defined(JSON_HEDLEY_HAS_FEATURE)
784#undef JSON_HEDLEY_HAS_FEATURE
786#if defined(__has_feature)
787#define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
789#define JSON_HEDLEY_HAS_FEATURE(feature) (0)
792#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
793#undef JSON_HEDLEY_GNUC_HAS_FEATURE
795#if defined(__has_feature)
796#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
798#define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
801#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
802#undef JSON_HEDLEY_GCC_HAS_FEATURE
804#if defined(__has_feature)
805#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
807#define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
810#if defined(JSON_HEDLEY_HAS_EXTENSION)
811#undef JSON_HEDLEY_HAS_EXTENSION
813#if defined(__has_extension)
814#define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
816#define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
819#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
820#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
822#if defined(__has_extension)
823#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
825#define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
828#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
829#undef JSON_HEDLEY_GCC_HAS_EXTENSION
831#if defined(__has_extension)
832#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
834#define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
837#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
838#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
840#if defined(__has_declspec_attribute)
841#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
843#define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
846#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
847#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
849#if defined(__has_declspec_attribute)
850#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
852#define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
855#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
856#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
858#if defined(__has_declspec_attribute)
859#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
861#define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
864#if defined(JSON_HEDLEY_HAS_WARNING)
865#undef JSON_HEDLEY_HAS_WARNING
867#if defined(__has_warning)
868#define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
870#define JSON_HEDLEY_HAS_WARNING(warning) (0)
873#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
874#undef JSON_HEDLEY_GNUC_HAS_WARNING
876#if defined(__has_warning)
877#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
879#define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
882#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
883#undef JSON_HEDLEY_GCC_HAS_WARNING
885#if defined(__has_warning)
886#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
888#define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
892 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
893 defined(__clang__) || \
894 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
895 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
896 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
897 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
898 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
899 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
900 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
901 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
902 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
903 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
904 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
905 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
906 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
907 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
908 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
909 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
910#define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
911#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
912#define JSON_HEDLEY_PRAGMA(value) __pragma(value)
914#define JSON_HEDLEY_PRAGMA(value)
917#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
918#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
920#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
921#undef JSON_HEDLEY_DIAGNOSTIC_POP
923#if defined(__clang__)
924#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
925#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
926#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
927#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
928#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
929#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
930#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
931#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
933 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
934 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
935#define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
936#define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
937#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
938#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
939#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
941 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
942 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
943 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
944 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
945 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
946 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
947#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
948#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
949#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
950#define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
951#define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
953#define JSON_HEDLEY_DIAGNOSTIC_PUSH
954#define JSON_HEDLEY_DIAGNOSTIC_POP
959#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
960#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
962#if defined(__cplusplus)
963# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
964# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
965# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
966# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
967 JSON_HEDLEY_DIAGNOSTIC_PUSH \
968 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
969 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
970 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
972 JSON_HEDLEY_DIAGNOSTIC_POP
974# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
975 JSON_HEDLEY_DIAGNOSTIC_PUSH \
976 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
977 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
979 JSON_HEDLEY_DIAGNOSTIC_POP
982# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
983 JSON_HEDLEY_DIAGNOSTIC_PUSH \
984 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
986 JSON_HEDLEY_DIAGNOSTIC_POP
990#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
991#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
994#if defined(JSON_HEDLEY_CONST_CAST)
995#undef JSON_HEDLEY_CONST_CAST
997#if defined(__cplusplus)
998# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1000 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1001 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1002 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1003# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1004 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1005 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1007 JSON_HEDLEY_DIAGNOSTIC_POP \
1010# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1013#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1014#undef JSON_HEDLEY_REINTERPRET_CAST
1016#if defined(__cplusplus)
1017#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1019#define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1022#if defined(JSON_HEDLEY_STATIC_CAST)
1023#undef JSON_HEDLEY_STATIC_CAST
1025#if defined(__cplusplus)
1026#define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1028#define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1031#if defined(JSON_HEDLEY_CPP_CAST)
1032#undef JSON_HEDLEY_CPP_CAST
1034#if defined(__cplusplus)
1035# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1036# define JSON_HEDLEY_CPP_CAST(T, expr) \
1037 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1038 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1040 JSON_HEDLEY_DIAGNOSTIC_POP
1041# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1042# define JSON_HEDLEY_CPP_CAST(T, expr) \
1043 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1044 _Pragma("diag_suppress=Pe137") \
1045 JSON_HEDLEY_DIAGNOSTIC_POP
1047# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1050# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1053#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1054#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1056#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1057#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1058#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1059#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1060#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1061#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1062#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1063#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1064#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1065#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1066#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1067#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1068#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1069#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1070#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1071#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1073 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1074 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1075 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1076 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1077 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1078 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1079 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1080 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1081 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1082 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1083 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1084#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1085#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1086#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1087#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1088#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1089#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1090#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1091#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1092#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1094#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1097#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1098#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1100#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1101#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1102#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1103#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1104#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1105#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1106#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1107#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1108#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1109#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1110#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1111#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1113 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1114 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1115 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1116 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1117#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1118#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1119#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1120#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1121#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1122#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1123#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1125#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1128#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1129#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1131#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1132#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1133#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1134#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1135#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1136#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1137#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1138#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1139#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1140#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1141#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1142#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1143#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1144#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1145#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1146#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1148 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1149 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1150 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1151#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1152#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1153#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1154#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1155#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1157#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1160#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1161#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1163#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1164#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1165#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1166#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1167#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1168#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1170#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1173#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1174#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1176#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1177#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1178#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1179#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1180#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1181#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1182#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1183#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1185#define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1188#if defined(JSON_HEDLEY_DEPRECATED)
1189#undef JSON_HEDLEY_DEPRECATED
1191#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1192#undef JSON_HEDLEY_DEPRECATED_FOR
1195 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1196 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1197#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1198#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1200 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1201 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1202 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1203 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1204 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1205 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1206 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1207 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1208 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1209 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1210 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1211 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1212#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1213#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1214#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1215#define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1216#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1218 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1219 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1220 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1221 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1222 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1223 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1224 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1225 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1226 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1227 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1228 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1229 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1230 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1231 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1232 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1233 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1234#define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1235#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1237 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1238 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1239 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1240#define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1241#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1242#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1243#define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1244#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1246#define JSON_HEDLEY_DEPRECATED(since)
1247#define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1250#if defined(JSON_HEDLEY_UNAVAILABLE)
1251#undef JSON_HEDLEY_UNAVAILABLE
1254 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1255 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1256 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1257 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1258#define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1260#define JSON_HEDLEY_UNAVAILABLE(available_since)
1263#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT)
1264#undef JSON_HEDLEY_WARN_UNUSED_RESULT
1266#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG)
1267#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
1270 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1271 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1272 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1273 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1274 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1275 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1276 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1277 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1278 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1279 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1280 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1281 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1282 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1283 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1284 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1285 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1286 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1287#define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
1288#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__))
1289#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1290#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1291#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1292#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1293#define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1294#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1295#elif defined(_Check_return_)
1296#define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_
1297#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_
1299#define JSON_HEDLEY_WARN_UNUSED_RESULT
1300#define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg)
1303#if defined(JSON_HEDLEY_SENTINEL)
1304#undef JSON_HEDLEY_SENTINEL
1307 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1308 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1309 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1310 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1311 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1312#define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1314#define JSON_HEDLEY_SENTINEL(position)
1317#if defined(JSON_HEDLEY_NO_RETURN)
1318#undef JSON_HEDLEY_NO_RETURN
1320#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1321#define JSON_HEDLEY_NO_RETURN __noreturn
1323 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1324 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1325#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1326#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1327#define JSON_HEDLEY_NO_RETURN _Noreturn
1328#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1329#define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1331 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1332 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1333 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1334 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1335 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1336 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1337 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1338 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1339 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1340 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1341 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1342 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1343 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1344 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1345 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1346 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1347 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1348#define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1349#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1350#define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1352 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1353 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1354#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1355#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1356#define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1357#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1358#define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1359#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1360#define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1362#define JSON_HEDLEY_NO_RETURN
1365#if defined(JSON_HEDLEY_NO_ESCAPE)
1366#undef JSON_HEDLEY_NO_ESCAPE
1368#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1369#define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1371#define JSON_HEDLEY_NO_ESCAPE
1374#if defined(JSON_HEDLEY_UNREACHABLE)
1375#undef JSON_HEDLEY_UNREACHABLE
1377#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1378#undef JSON_HEDLEY_UNREACHABLE_RETURN
1380#if defined(JSON_HEDLEY_ASSUME)
1381#undef JSON_HEDLEY_ASSUME
1384 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1385 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1386 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1387#define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1388#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1389#define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1391 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1392 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1393#if defined(__cplusplus)
1394#define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1396#define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1400 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1401 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1402 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1403 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1404 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1405 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1406 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1407#define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1408#elif defined(JSON_HEDLEY_ASSUME)
1409#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1411#if !defined(JSON_HEDLEY_ASSUME)
1412#if defined(JSON_HEDLEY_UNREACHABLE)
1413#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1415#define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1418#if defined(JSON_HEDLEY_UNREACHABLE)
1420 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1421 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1422#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1424#define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1427#define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1429#if !defined(JSON_HEDLEY_UNREACHABLE)
1430#define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1433JSON_HEDLEY_DIAGNOSTIC_PUSH
1434#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1435#pragma clang diagnostic ignored "-Wpedantic"
1437#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1438#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1440#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1441#if defined(__clang__)
1442#pragma clang diagnostic ignored "-Wvariadic-macros"
1443#elif defined(JSON_HEDLEY_GCC_VERSION)
1444#pragma GCC diagnostic ignored "-Wvariadic-macros"
1447#if defined(JSON_HEDLEY_NON_NULL)
1448#undef JSON_HEDLEY_NON_NULL
1451 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1452 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1453 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1454 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1455#define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1457#define JSON_HEDLEY_NON_NULL(...)
1459JSON_HEDLEY_DIAGNOSTIC_POP
1461#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1462#undef JSON_HEDLEY_PRINTF_FORMAT
1464#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1465#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1466#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1467#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1469 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1470 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1471 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1472 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1473 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1474 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1475 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1476 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1477 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1478 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1479 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1480 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1481 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1482 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1483 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1484 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1485 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1486#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1487#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1488#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1490#define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1493#if defined(JSON_HEDLEY_CONSTEXPR)
1494#undef JSON_HEDLEY_CONSTEXPR
1496#if defined(__cplusplus)
1497#if __cplusplus >= 201103L
1498#define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1501#if !defined(JSON_HEDLEY_CONSTEXPR)
1502#define JSON_HEDLEY_CONSTEXPR
1505#if defined(JSON_HEDLEY_PREDICT)
1506#undef JSON_HEDLEY_PREDICT
1508#if defined(JSON_HEDLEY_LIKELY)
1509#undef JSON_HEDLEY_LIKELY
1511#if defined(JSON_HEDLEY_UNLIKELY)
1512#undef JSON_HEDLEY_UNLIKELY
1514#if defined(JSON_HEDLEY_UNPREDICTABLE)
1515#undef JSON_HEDLEY_UNPREDICTABLE
1517#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1518#define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1521 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1522 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1523 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1524# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1525# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1526# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1527# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1528# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1530 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1531 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1532 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1533 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1534 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1535 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1536 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1537 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1538 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1539 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1540 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1541 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1542 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1543 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1544 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1545 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1546# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1547 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1548# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1550 double hedley_probability_ = (probability); \
1551 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1553# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1555 double hedley_probability_ = (probability); \
1556 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1558# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1559# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1561# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1562# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1563# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1564# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1565# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1567#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1568#define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1571#if defined(JSON_HEDLEY_MALLOC)
1572#undef JSON_HEDLEY_MALLOC
1575 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1576 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1577 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1578 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1579 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1580 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1581 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1582 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1583 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1584 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1585 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1586 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1587 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1588 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1589 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1590 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1591 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1592 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1593#define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1594#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1595#define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1597 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1598 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1599#define JSON_HEDLEY_MALLOC __declspec(restrict)
1601#define JSON_HEDLEY_MALLOC
1604#if defined(JSON_HEDLEY_PURE)
1605#undef JSON_HEDLEY_PURE
1608 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1609 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1610 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1611 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1612 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1613 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1614 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1615 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1616 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1617 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1618 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1619 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1620 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1621 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1622 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1623 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1624 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1625 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1626 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1627# define JSON_HEDLEY_PURE __attribute__((__pure__))
1628#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1629# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1630#elif defined(__cplusplus) && \
1632 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1633 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1634 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1636# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1638# define JSON_HEDLEY_PURE
1641#if defined(JSON_HEDLEY_CONST)
1642#undef JSON_HEDLEY_CONST
1645 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1646 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1647 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1648 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1649 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1650 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1651 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1652 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1653 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1654 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1655 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1656 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1657 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1658 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1659 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1660 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1661 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1662 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1663 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1664#define JSON_HEDLEY_CONST __attribute__((__const__))
1666 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1667#define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1669#define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1672#if defined(JSON_HEDLEY_RESTRICT)
1673#undef JSON_HEDLEY_RESTRICT
1675#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1676#define JSON_HEDLEY_RESTRICT restrict
1678 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1679 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1680 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1681 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1682 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1683 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1684 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1685 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1686 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1687 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1688 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1689 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1690 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1691 defined(__clang__) || \
1692 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1693#define JSON_HEDLEY_RESTRICT __restrict
1694#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1695#define JSON_HEDLEY_RESTRICT _Restrict
1697#define JSON_HEDLEY_RESTRICT
1700#if defined(JSON_HEDLEY_INLINE)
1701#undef JSON_HEDLEY_INLINE
1704 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1705 (defined(__cplusplus) && (__cplusplus >= 199711L))
1706#define JSON_HEDLEY_INLINE inline
1708 defined(JSON_HEDLEY_GCC_VERSION) || \
1709 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1710#define JSON_HEDLEY_INLINE __inline__
1712 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1713 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1714 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1715 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1716 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1717 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1718 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1719 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1720 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1721 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1722#define JSON_HEDLEY_INLINE __inline
1724#define JSON_HEDLEY_INLINE
1727#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1728#undef JSON_HEDLEY_ALWAYS_INLINE
1731 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1732 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1733 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1734 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1735 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1736 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1737 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1738 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1739 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1740 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1741 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1742 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1743 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1744 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1745 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1746 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1747 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1748 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1749 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1750# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1752 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1753 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1754# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1755#elif defined(__cplusplus) && \
1757 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1758 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1759 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1760 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1761 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1762 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1764# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1765#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1766# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1768# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1771#if defined(JSON_HEDLEY_NEVER_INLINE)
1772#undef JSON_HEDLEY_NEVER_INLINE
1775 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1776 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1777 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1778 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1779 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1780 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1781 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1782 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1783 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1784 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1785 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1786 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1787 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1788 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1789 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1790 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1791 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1792 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1793 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1794#define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1796 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1797 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1798#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1799#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1800#define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1801#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1802#define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1803#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1804#define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1805#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1806#define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1807#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1808#define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1810#define JSON_HEDLEY_NEVER_INLINE
1813#if defined(JSON_HEDLEY_PRIVATE)
1814#undef JSON_HEDLEY_PRIVATE
1816#if defined(JSON_HEDLEY_PUBLIC)
1817#undef JSON_HEDLEY_PUBLIC
1819#if defined(JSON_HEDLEY_IMPORT)
1820#undef JSON_HEDLEY_IMPORT
1822#if defined(_WIN32) || defined(__CYGWIN__)
1823# define JSON_HEDLEY_PRIVATE
1824# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1825# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1828 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1829 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1830 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1831 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1832 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1833 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1835 defined(__TI_EABI__) && \
1837 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1838 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1841 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1842# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1843# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1845# define JSON_HEDLEY_PRIVATE
1846# define JSON_HEDLEY_PUBLIC
1848# define JSON_HEDLEY_IMPORT extern
1851#if defined(JSON_HEDLEY_NO_THROW)
1852#undef JSON_HEDLEY_NO_THROW
1855 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1856 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1857 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1858 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1859#define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1861 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1862 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1863 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1864#define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1866#define JSON_HEDLEY_NO_THROW
1869#if defined(JSON_HEDLEY_FALL_THROUGH)
1870#undef JSON_HEDLEY_FALL_THROUGH
1873 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1874 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1875 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1876#define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1877#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1878#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1879#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1880#define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1881#elif defined(__fallthrough)
1882#define JSON_HEDLEY_FALL_THROUGH __fallthrough
1884#define JSON_HEDLEY_FALL_THROUGH
1887#if defined(JSON_HEDLEY_RETURNS_NON_NULL)
1888#undef JSON_HEDLEY_RETURNS_NON_NULL
1891 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1892 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1893 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1894#define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__))
1895#elif defined(_Ret_notnull_)
1896#define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_
1898#define JSON_HEDLEY_RETURNS_NON_NULL
1901#if defined(JSON_HEDLEY_ARRAY_PARAM)
1902#undef JSON_HEDLEY_ARRAY_PARAM
1905 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1906 !defined(__STDC_NO_VLA__) && \
1907 !defined(__cplusplus) && \
1908 !defined(JSON_HEDLEY_PGI_VERSION) && \
1909 !defined(JSON_HEDLEY_TINYC_VERSION)
1910#define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1912#define JSON_HEDLEY_ARRAY_PARAM(name)
1915#if defined(JSON_HEDLEY_IS_CONSTANT)
1916#undef JSON_HEDLEY_IS_CONSTANT
1918#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1919#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1923#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1924#undef JSON_HEDLEY_IS_CONSTEXPR_
1927 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1928 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1929 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1930 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1931 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1932 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1933 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1934 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1935 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1936 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1937#define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1939#if !defined(__cplusplus)
1941 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1942 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1943 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1944 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1945 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1946 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1947 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1948#if defined(__INTPTR_TYPE__)
1949#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1952#define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1956 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1957 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1958 !defined(JSON_HEDLEY_PGI_VERSION) && \
1959 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1960 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1961 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1962 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1963 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1964 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1965#if defined(__INTPTR_TYPE__)
1966#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1969#define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1972 defined(JSON_HEDLEY_GCC_VERSION) || \
1973 defined(JSON_HEDLEY_INTEL_VERSION) || \
1974 defined(JSON_HEDLEY_TINYC_VERSION) || \
1975 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1976 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1977 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1978 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1979 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1980 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1982# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1986 ((void*) ((expr) * 0L) ) : \
1987((struct { char v[sizeof(void) * 2]; } *) 1) \
1993#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1994#if !defined(JSON_HEDLEY_IS_CONSTANT)
1995#define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1997#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1999#if !defined(JSON_HEDLEY_IS_CONSTANT)
2000#define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2002#define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2005#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2006#undef JSON_HEDLEY_BEGIN_C_DECLS
2008#if defined(JSON_HEDLEY_END_C_DECLS)
2009#undef JSON_HEDLEY_END_C_DECLS
2011#if defined(JSON_HEDLEY_C_DECL)
2012#undef JSON_HEDLEY_C_DECL
2014#if defined(__cplusplus)
2015#define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2016#define JSON_HEDLEY_END_C_DECLS }
2017#define JSON_HEDLEY_C_DECL extern "C"
2019#define JSON_HEDLEY_BEGIN_C_DECLS
2020#define JSON_HEDLEY_END_C_DECLS
2021#define JSON_HEDLEY_C_DECL
2024#if defined(JSON_HEDLEY_STATIC_ASSERT)
2025#undef JSON_HEDLEY_STATIC_ASSERT
2028 !defined(__cplusplus) && ( \
2029 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2030 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2031 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2032 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2033 defined(_Static_assert) \
2035# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2037 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2038 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2039 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2040# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2042# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2045#if defined(JSON_HEDLEY_NULL)
2046#undef JSON_HEDLEY_NULL
2048#if defined(__cplusplus)
2049#if __cplusplus >= 201103L
2050#define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2052#define JSON_HEDLEY_NULL NULL
2054#define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2057#define JSON_HEDLEY_NULL NULL
2059#define JSON_HEDLEY_NULL ((void*) 0)
2062#if defined(JSON_HEDLEY_MESSAGE)
2063#undef JSON_HEDLEY_MESSAGE
2065#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2066# define JSON_HEDLEY_MESSAGE(msg) \
2067 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2068 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2069 JSON_HEDLEY_PRAGMA(message msg) \
2070 JSON_HEDLEY_DIAGNOSTIC_POP
2072 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2073 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2074# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2075#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2076# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2077#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2078# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2079#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2080# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2082# define JSON_HEDLEY_MESSAGE(msg)
2085#if defined(JSON_HEDLEY_WARNING)
2086#undef JSON_HEDLEY_WARNING
2088#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2089# define JSON_HEDLEY_WARNING(msg) \
2090 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2091 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2092 JSON_HEDLEY_PRAGMA(clang warning msg) \
2093 JSON_HEDLEY_DIAGNOSTIC_POP
2095 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2096 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2097 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2098# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2100 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2101 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2102# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2104# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2107#if defined(JSON_HEDLEY_REQUIRE)
2108#undef JSON_HEDLEY_REQUIRE
2110#if defined(JSON_HEDLEY_REQUIRE_MSG)
2111#undef JSON_HEDLEY_REQUIRE_MSG
2113#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2114# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2115# define JSON_HEDLEY_REQUIRE(expr) \
2116 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2117 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2118 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2119 JSON_HEDLEY_DIAGNOSTIC_POP
2120# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2121 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2122 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2123 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2124 JSON_HEDLEY_DIAGNOSTIC_POP
2126# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2127# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2130# define JSON_HEDLEY_REQUIRE(expr)
2131# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2134#if defined(JSON_HEDLEY_FLAGS)
2135#undef JSON_HEDLEY_FLAGS
2137#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2138#define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2140#define JSON_HEDLEY_FLAGS
2143#if defined(JSON_HEDLEY_FLAGS_CAST)
2144#undef JSON_HEDLEY_FLAGS_CAST
2146#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2147# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2148 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2149 _Pragma("warning(disable:188)") \
2151 JSON_HEDLEY_DIAGNOSTIC_POP \
2154# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2157#if defined(JSON_HEDLEY_EMPTY_BASES)
2158#undef JSON_HEDLEY_EMPTY_BASES
2161 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2162 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2163#define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2165#define JSON_HEDLEY_EMPTY_BASES
2170#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2171#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2173#if defined(__clang__)
2174#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2176#define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2179#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2180#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2182#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2184#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2185#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2187#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2189#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2190#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2192#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2194#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2195#undef JSON_HEDLEY_CLANG_HAS_FEATURE
2197#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2199#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2200#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2202#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2204#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2205#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2207#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2209#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2210#undef JSON_HEDLEY_CLANG_HAS_WARNING
2212#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2221#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2222#if defined(__clang__)
2223#if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2224#error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2226#elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2227#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2228#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2235#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2236#if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2237#define JSON_HAS_CPP_20
2238#define JSON_HAS_CPP_17
2239#define JSON_HAS_CPP_14
2240#elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2241#define JSON_HAS_CPP_17
2242#define JSON_HAS_CPP_14
2243#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2244#define JSON_HAS_CPP_14
2247#define JSON_HAS_CPP_11
2251#if defined(__clang__)
2252#pragma clang diagnostic push
2253#pragma clang diagnostic ignored "-Wdocumentation"
2254#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2258#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2259#define JSON_THROW(exception) throw exception
2261#define JSON_CATCH(exception) catch(exception)
2262#define JSON_INTERNAL_CATCH(exception) catch(exception)
2265#define JSON_THROW(exception) std::abort()
2266#define JSON_TRY if(true)
2267#define JSON_CATCH(exception) if(false)
2268#define JSON_INTERNAL_CATCH(exception) if(false)
2272#if defined(JSON_THROW_USER)
2274#define JSON_THROW JSON_THROW_USER
2276#if defined(JSON_TRY_USER)
2278#define JSON_TRY JSON_TRY_USER
2280#if defined(JSON_CATCH_USER)
2282#define JSON_CATCH JSON_CATCH_USER
2283#undef JSON_INTERNAL_CATCH
2284#define JSON_INTERNAL_CATCH JSON_CATCH_USER
2286#if defined(JSON_INTERNAL_CATCH_USER)
2287#undef JSON_INTERNAL_CATCH
2288#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2292#if !defined(JSON_ASSERT)
2294#define JSON_ASSERT(x) assert(x)
2298#if defined(JSON_TESTS_PRIVATE)
2299#define JSON_PRIVATE_UNLESS_TESTED public
2301#define JSON_PRIVATE_UNLESS_TESTED private
2309#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2310 template<typename BasicJsonType> \
2311 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2313 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2314 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2315 auto it = std::find_if(std::begin(m), std::end(m), \
2316 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2318 return ej_pair.first == e; \
2320 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2322 template<typename BasicJsonType> \
2323 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2325 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2326 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2327 auto it = std::find_if(std::begin(m), std::end(m), \
2328 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2330 return ej_pair.second == j; \
2332 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2338#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2339 template<template<typename, typename, typename...> class ObjectType, \
2340 template<typename, typename...> class ArrayType, \
2341 class StringType, class BooleanType, class NumberIntegerType, \
2342 class NumberUnsignedType, class NumberFloatType, \
2343 template<typename> class AllocatorType, \
2344 template<typename, typename = void> class JSONSerializer, \
2347#define NLOHMANN_BASIC_JSON_TPL \
2348 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2349 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2350 AllocatorType, JSONSerializer, BinaryType>
2354#define NLOHMANN_JSON_EXPAND( x ) x
2355#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
2356#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2357 NLOHMANN_JSON_PASTE64, \
2358 NLOHMANN_JSON_PASTE63, \
2359 NLOHMANN_JSON_PASTE62, \
2360 NLOHMANN_JSON_PASTE61, \
2361 NLOHMANN_JSON_PASTE60, \
2362 NLOHMANN_JSON_PASTE59, \
2363 NLOHMANN_JSON_PASTE58, \
2364 NLOHMANN_JSON_PASTE57, \
2365 NLOHMANN_JSON_PASTE56, \
2366 NLOHMANN_JSON_PASTE55, \
2367 NLOHMANN_JSON_PASTE54, \
2368 NLOHMANN_JSON_PASTE53, \
2369 NLOHMANN_JSON_PASTE52, \
2370 NLOHMANN_JSON_PASTE51, \
2371 NLOHMANN_JSON_PASTE50, \
2372 NLOHMANN_JSON_PASTE49, \
2373 NLOHMANN_JSON_PASTE48, \
2374 NLOHMANN_JSON_PASTE47, \
2375 NLOHMANN_JSON_PASTE46, \
2376 NLOHMANN_JSON_PASTE45, \
2377 NLOHMANN_JSON_PASTE44, \
2378 NLOHMANN_JSON_PASTE43, \
2379 NLOHMANN_JSON_PASTE42, \
2380 NLOHMANN_JSON_PASTE41, \
2381 NLOHMANN_JSON_PASTE40, \
2382 NLOHMANN_JSON_PASTE39, \
2383 NLOHMANN_JSON_PASTE38, \
2384 NLOHMANN_JSON_PASTE37, \
2385 NLOHMANN_JSON_PASTE36, \
2386 NLOHMANN_JSON_PASTE35, \
2387 NLOHMANN_JSON_PASTE34, \
2388 NLOHMANN_JSON_PASTE33, \
2389 NLOHMANN_JSON_PASTE32, \
2390 NLOHMANN_JSON_PASTE31, \
2391 NLOHMANN_JSON_PASTE30, \
2392 NLOHMANN_JSON_PASTE29, \
2393 NLOHMANN_JSON_PASTE28, \
2394 NLOHMANN_JSON_PASTE27, \
2395 NLOHMANN_JSON_PASTE26, \
2396 NLOHMANN_JSON_PASTE25, \
2397 NLOHMANN_JSON_PASTE24, \
2398 NLOHMANN_JSON_PASTE23, \
2399 NLOHMANN_JSON_PASTE22, \
2400 NLOHMANN_JSON_PASTE21, \
2401 NLOHMANN_JSON_PASTE20, \
2402 NLOHMANN_JSON_PASTE19, \
2403 NLOHMANN_JSON_PASTE18, \
2404 NLOHMANN_JSON_PASTE17, \
2405 NLOHMANN_JSON_PASTE16, \
2406 NLOHMANN_JSON_PASTE15, \
2407 NLOHMANN_JSON_PASTE14, \
2408 NLOHMANN_JSON_PASTE13, \
2409 NLOHMANN_JSON_PASTE12, \
2410 NLOHMANN_JSON_PASTE11, \
2411 NLOHMANN_JSON_PASTE10, \
2412 NLOHMANN_JSON_PASTE9, \
2413 NLOHMANN_JSON_PASTE8, \
2414 NLOHMANN_JSON_PASTE7, \
2415 NLOHMANN_JSON_PASTE6, \
2416 NLOHMANN_JSON_PASTE5, \
2417 NLOHMANN_JSON_PASTE4, \
2418 NLOHMANN_JSON_PASTE3, \
2419 NLOHMANN_JSON_PASTE2, \
2420 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2421#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2422#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2423#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2424#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2425#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2426#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)
2427#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)
2428#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)
2429#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)
2430#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)
2431#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)
2432#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)
2433#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)
2434#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)
2435#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)
2436#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)
2437#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)
2438#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)
2439#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)
2440#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)
2441#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)
2442#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)
2443#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)
2444#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)
2445#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)
2446#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)
2447#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)
2448#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)
2449#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)
2450#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)
2451#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)
2452#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)
2453#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)
2454#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)
2455#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)
2456#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)
2457#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)
2458#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)
2459#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)
2460#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)
2461#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)
2462#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)
2463#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)
2464#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)
2465#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)
2466#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)
2467#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)
2468#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)
2469#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)
2470#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)
2471#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)
2472#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)
2473#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)
2474#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)
2475#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)
2476#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)
2477#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)
2478#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)
2479#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)
2480#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)
2481#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)
2482#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)
2483#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)
2485#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2486#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2493#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2494 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__)) } \
2495 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__)) }
2502#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2503 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__)) } \
2504 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__)) }
2506#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2507#define JSON_USE_IMPLICIT_CONVERSIONS 1
2510#if JSON_USE_IMPLICIT_CONVERSIONS
2511#define JSON_EXPLICIT
2513#define JSON_EXPLICIT explicit
2516#ifndef JSON_DIAGNOSTICS
2517#define JSON_DIAGNOSTICS 0
2540 const std::string &t)
2542 JSON_ASSERT(!f.empty());
2544 for (
auto pos = s.find(f);
2545 pos != std::string::npos;
2546 s.replace(pos, f.size(), t),
2547 pos = s.find(f, pos + t.size()))
2601 constexpr operator size_t()
const
2653 const char *
what() const noexcept
override
2662 JSON_HEDLEY_NON_NULL(3)
2663 exception(
int id_, const
char *what_arg) :
id(id_),
m(what_arg) {}
2665 static std::string name(
const std::string &ename,
int id_)
2667 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2670 template<
typename BasicJsonType>
2671 static std::string diagnostics(
const BasicJsonType &leaf_element)
2674 std::vector<std::string> tokens;
2676 for (
const auto *current = &leaf_element; current->m_parent !=
nullptr; current = current->m_parent)
2678 switch (current->m_parent->type())
2682 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2684 if (¤t->m_parent->m_value.array->operator[](i) == current)
2686 tokens.emplace_back(std::to_string(i));
2696 for (
const auto &element : *current->m_parent->m_value.object)
2698 if (&element.second == current)
2700 tokens.emplace_back(element.first.c_str());
2726 return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2727 [](
const std::string & a,
const std::string & b)
2729 return a +
"/" + detail::escape(b);
2732 static_cast<void>(leaf_element);
2739 std::runtime_error
m;
2799 template<
typename BasicJsonType>
2802 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2803 position_string(pos) +
": " + exception::diagnostics(context) + what_arg;
2807 template<
typename BasicJsonType>
2808 static parse_error create(
int id_, std::size_t byte_,
const std::string &what_arg,
const BasicJsonType &context)
2810 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2811 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2812 ": " + exception::diagnostics(context) + what_arg;
2828 parse_error(
int id_, std::size_t byte_,
const char *what_arg)
2831 static std::string position_string(
const position_t &pos)
2833 return " at line " + std::to_string(pos.
lines_read + 1) +
2878 template<
typename BasicJsonType>
2879 static invalid_iterator create(
int id_,
const std::string &what_arg,
const BasicJsonType &context)
2881 std::string w = exception::name(
"invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2886 JSON_HEDLEY_NON_NULL(3)
2933 template<
typename BasicJsonType>
2934 static type_error create(
int id_,
const std::string &what_arg,
const BasicJsonType &context)
2936 std::string w = exception::name(
"type_error", id_) + exception::diagnostics(context) + what_arg;
2941 JSON_HEDLEY_NON_NULL(3)
2981 template<
typename BasicJsonType>
2982 static out_of_range create(
int id_,
const std::string &what_arg,
const BasicJsonType &context)
2984 std::string w = exception::name(
"out_of_range", id_) + exception::diagnostics(context) + what_arg;
2989 JSON_HEDLEY_NON_NULL(3)
3020 template<
typename BasicJsonType>
3021 static other_error create(
int id_,
const std::string &what_arg,
const BasicJsonType &context)
3023 std::string w = exception::name(
"other_error", id_) + exception::diagnostics(context) + what_arg;
3028 JSON_HEDLEY_NON_NULL(3)
3040#include <type_traits>
3052using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3054#ifdef JSON_HAS_CPP_14
3057using std::enable_if_t;
3058using std::index_sequence;
3059using std::make_index_sequence;
3060using std::index_sequence_for;
3065template<
bool B,
typename T =
void>
3066using enable_if_t =
typename std::enable_if<B, T>::type;
3092template <
typename T, T... Ints>
3095 using value_type = T;
3096 static constexpr std::size_t size()
noexcept
3098 return sizeof...(Ints);
3107template <
size_t... Ints>
3110namespace utility_internal
3113template <
typename Seq,
size_t SeqSize,
size_t Rem>
3117template <
typename T, T... Ints,
size_t SeqSize>
3123template <
typename T, T... Ints,
size_t SeqSize>
3131template <
typename T,
size_t N>
3135 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3138template <
typename T>
3153template <
typename T, T N>
3154using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3162using make_index_sequence = make_integer_sequence<size_t, N>;
3169template <
typename... Ts>
3170using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3184 static constexpr T value{};
3209#include <type_traits>
3229template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
3240template<
typename It,
typename =
void>
3243template<
typename It>
3246 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3247 typename It::reference, typename It::iterator_category >>
3249 using difference_type =
typename It::difference_type;
3250 using value_type =
typename It::value_type;
3251 using pointer =
typename It::pointer;
3252 using reference =
typename It::reference;
3253 using iterator_category =
typename It::iterator_category;
3258template<
typename T,
typename =
void>
3272 using iterator_category = std::random_access_iterator_tag;
3273 using value_type = T;
3274 using difference_type = ptrdiff_t;
3276 using reference = T&;
3288#include <type_traits>
3304 void operator=(
nonesuch const &) =
delete;
3305 void operator=(
nonesuch &&) =
delete;
3308template<
class Default,
3310 template<
class...>
class Op,
3314 using value_t = std::false_type;
3315 using type = Default;
3318template<
class Default,
template<
class...>
class Op,
class... Args>
3319struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3321 using value_t = std::true_type;
3322 using type = Op<Args...>;
3325template<
template<
class...>
class Op,
class... Args>
3328template<
template<
class...>
class Op,
class... Args>
3331template<
template<
class...>
class Op,
class... Args>
3334template<
class Default,
template<
class...>
class Op,
class... Args>
3337template<
class Default,
template<
class...>
class Op,
class... Args>
3338using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
3340template<
class Expected,
template<
class...>
class Op,
class... Args>
3341using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3343template<
class To,
template<
class...>
class Op,
class... Args>
3344using is_detected_convertible =
3345 std::is_convertible<detected_t<Op, Args...>, To>;
3350#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3351#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3373template<
typename T =
void,
typename SFINAE =
void>
3374struct adl_serializer;
3376template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3378 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3379 class StringType = std::string,
class BooleanType = bool,
3380 class NumberIntegerType = std::int64_t,
3381 class NumberUnsignedType = std::uint64_t,
3382 class NumberFloatType = double,
3383 template<
typename U>
class AllocatorType = std::allocator,
3384 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3386 class BinaryType = std::vector<std::uint8_t>>
3400template<
typename BasicJsonType>
3413template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3457NLOHMANN_BASIC_JSON_TPL_DECLARATION
3478using mapped_type_t =
typename T::mapped_type;
3481using key_type_t =
typename T::key_type;
3484using value_type_t =
typename T::value_type;
3487using difference_type_t =
typename T::difference_type;
3490using pointer_t =
typename T::pointer;
3493using reference_t =
typename T::reference;
3496using iterator_category_t =
typename T::iterator_category;
3499using iterator_t =
typename T::iterator;
3501template<
typename T,
typename... Args>
3502using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3504template<
typename T,
typename... Args>
3505using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3507template<
typename T,
typename U>
3508using get_template_function =
decltype(std::declval<T>().template get<U>());
3511template<
typename BasicJsonType,
typename T,
typename =
void>
3518template <
typename BasicJsonType,
typename T>
3521 static constexpr bool value = is_detected<get_template_function, const BasicJsonType &, T>::value;
3524template<
typename BasicJsonType,
typename T>
3527 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3529 static constexpr bool value =
3530 is_detected_exact<void, from_json_function, serializer,
3531 const BasicJsonType &, T &>::value;
3536template<
typename BasicJsonType,
typename T,
typename =
void>
3539template<
typename BasicJsonType,
typename T>
3542 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3544 static constexpr bool value =
3545 is_detected_exact<T, from_json_function, serializer,
3546 const BasicJsonType &>::value;
3551template<
typename BasicJsonType,
typename T,
typename =
void>
3554template<
typename BasicJsonType,
typename T>
3557 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3559 static constexpr bool value =
3560 is_detected_exact<void, to_json_function, serializer, BasicJsonType &,
3572template<
class B1,
class... Bn>
3574: std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3577template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3582template <
typename T>
3585template <
typename T1,
typename T2>
3587 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3589template <
typename T1,
typename T2>
3591 :
conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3593template <
typename... Ts>
3595 :
conjunction<is_default_constructible<Ts>...> {};
3597template <
typename... Ts>
3599 :
conjunction<is_default_constructible<Ts>...> {};
3602template <
typename T,
typename... Args>
3605template <
typename T1,
typename T2>
3608template <
typename T1,
typename T2>
3611template <
typename... Ts>
3614template <
typename... Ts>
3618template<
typename T,
typename =
void>
3628 static constexpr auto value =
3629 is_detected<value_type_t, traits>::value &&
3630 is_detected<difference_type_t, traits>::value &&
3631 is_detected<pointer_t, traits>::value &&
3632 is_detected<iterator_category_t, traits>::value &&
3633 is_detected<reference_t, traits>::value;
3640template<
typename T,
typename =
void>
3646template<
typename BasicJsonType,
typename CompatibleObjectType,
3650template<
typename BasicJsonType,
typename CompatibleObjectType>
3652 BasicJsonType, CompatibleObjectType,
3653 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::
value &&
3654 is_detected<key_type_t, CompatibleObjectType>::value >>
3656 using object_t =
typename BasicJsonType::object_t;
3659 static constexpr bool value =
3661 typename CompatibleObjectType::key_type>::value &&
3663 typename CompatibleObjectType::mapped_type>::value;
3666template<
typename BasicJsonType,
typename CompatibleObjectType>
3670template<
typename BasicJsonType,
typename ConstructibleObjectType,
3674template<
typename BasicJsonType,
typename ConstructibleObjectType>
3676 BasicJsonType, ConstructibleObjectType,
3677 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::
value &&
3678 is_detected<key_type_t, ConstructibleObjectType>::value >>
3680 using object_t =
typename BasicJsonType::object_t;
3682 static constexpr bool value =
3684 (std::is_move_assignable<ConstructibleObjectType>::value ||
3685 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3687 typename object_t::key_type>::value &&
3689 typename object_t::mapped_type,
3690 typename ConstructibleObjectType::mapped_type >::value)) ||
3692 typename ConstructibleObjectType::mapped_type>::value ||
3695 typename ConstructibleObjectType::mapped_type >::value);
3698template<
typename BasicJsonType,
typename ConstructibleObjectType>
3701 ConstructibleObjectType> {};
3703template<
typename BasicJsonType,
typename CompatibleStringType,
3707template<
typename BasicJsonType,
typename CompatibleStringType>
3709 BasicJsonType, CompatibleStringType,
3710 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3711 value_type_t, CompatibleStringType>::value >>
3713 static constexpr auto value =
3717template<
typename BasicJsonType,
typename ConstructibleStringType>
3721template<
typename BasicJsonType,
typename ConstructibleStringType,
3725template<
typename BasicJsonType,
typename ConstructibleStringType>
3727 BasicJsonType, ConstructibleStringType,
3728 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3729 value_type_t, ConstructibleStringType>::value >>
3731 static constexpr auto value =
3733 typename BasicJsonType::string_t>::value;
3736template<
typename BasicJsonType,
typename ConstructibleStringType>
3740template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3743template<
typename BasicJsonType,
typename CompatibleArrayType>
3745 BasicJsonType, CompatibleArrayType,
3746 enable_if_t < is_detected<value_type_t, CompatibleArrayType>::
value &&
3747 is_detected<iterator_t, CompatibleArrayType>::value &&
3752 iterator_traits<CompatibleArrayType >>::value >>
3754 static constexpr bool value =
3756 typename CompatibleArrayType::value_type>::value;
3759template<
typename BasicJsonType,
typename CompatibleArrayType>
3763template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3766template<
typename BasicJsonType,
typename ConstructibleArrayType>
3768 BasicJsonType, ConstructibleArrayType,
3769 enable_if_t<
std::is_same<ConstructibleArrayType,
3770 typename BasicJsonType::value_type>::value >>
3771 : std::true_type {};
3773template<
typename BasicJsonType,
typename ConstructibleArrayType>
3775 BasicJsonType, ConstructibleArrayType,
3776 enable_if_t < !
std::is_same<ConstructibleArrayType,
3777 typename BasicJsonType::value_type>::value &&
3779(std::is_move_assignable<ConstructibleArrayType>::value ||
3780 std::is_copy_assignable<ConstructibleArrayType>::value) &&
3781is_detected<value_type_t, ConstructibleArrayType>::value &&
3782is_detected<iterator_t, ConstructibleArrayType>::value &&
3784detected_t<value_type_t, ConstructibleArrayType >>::value >>
3786 static constexpr bool value =
3794 (std::is_same<
typename ConstructibleArrayType::value_type,
3795 typename BasicJsonType::array_t::value_type>::value ||
3797 typename ConstructibleArrayType::value_type>::value ||
3799 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
3802template<
typename BasicJsonType,
typename ConstructibleArrayType>
3806template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3810template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3812 RealIntegerType, CompatibleNumberIntegerType,
3813 enable_if_t <
std::is_integral<RealIntegerType>::value &&
3814 std::is_integral<CompatibleNumberIntegerType>::value &&
3815 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3818 using RealLimits = std::numeric_limits<RealIntegerType>;
3819 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3821 static constexpr auto value =
3823 CompatibleNumberIntegerType>::value &&
3824 CompatibleLimits::is_integer &&
3825 RealLimits::is_signed == CompatibleLimits::is_signed;
3828template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3831 CompatibleNumberIntegerType> {};
3833template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3836template<
typename BasicJsonType,
typename CompatibleType>
3838 BasicJsonType, CompatibleType,
3841 static constexpr bool value =
3845template<
typename BasicJsonType,
typename CompatibleType>
3849template<
typename T1,
typename T2>
3852template<
typename T1,
typename... Args>
3857template <
typename T>
3867 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
3868 template <
typename C>
static two test(...);
3870 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
3874template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
3875T conditional_static_cast(U value)
3877 return static_cast<T
>(value);
3880template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
3881T conditional_static_cast(U value)
3896template<
typename BasicJsonType>
3897void from_json(
const BasicJsonType &j,
typename std::nullptr_t &n)
3899 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3901 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name()), j));
3908template <
typename BasicJsonType,
typename ArithmeticType,
3909 enable_if_t < std::is_arithmetic<ArithmeticType>::value &&
3910 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3912void get_arithmetic_value(
const BasicJsonType &j, ArithmeticType &val)
3914 switch (
static_cast<value_t>(j))
3918 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t *>());
3924 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t *>());
3930 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t *>());
3942 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
3946template<
typename BasicJsonType>
3947void from_json(
const BasicJsonType &j,
typename BasicJsonType::boolean_t &b)
3949 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3951 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name()), j));
3954 b = *j.template get_ptr<const typename BasicJsonType::boolean_t *>();
3957template<
typename BasicJsonType>
3958void from_json(
const BasicJsonType &j,
typename BasicJsonType::string_t &s)
3960 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3962 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3965 s = *j.template get_ptr<const typename BasicJsonType::string_t *>();
3969 typename BasicJsonType,
typename ConstructibleStringType,
3971 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value &&
3972 !std::is_same<
typename BasicJsonType::string_t,
3973 ConstructibleStringType>::value,
3975void from_json(
const BasicJsonType &j, ConstructibleStringType &s)
3977 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3979 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3982 s = *j.template get_ptr<const typename BasicJsonType::string_t *>();
3985template<
typename BasicJsonType>
3986void from_json(
const BasicJsonType &j,
typename BasicJsonType::number_float_t &val)
3988 get_arithmetic_value(j, val);
3991template<
typename BasicJsonType>
3992void from_json(
const BasicJsonType &j,
typename BasicJsonType::number_unsigned_t &val)
3994 get_arithmetic_value(j, val);
3997template<
typename BasicJsonType>
3998void from_json(
const BasicJsonType &j,
typename BasicJsonType::number_integer_t &val)
4000 get_arithmetic_value(j, val);
4003template<
typename BasicJsonType,
typename EnumType,
4004 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4005void from_json(
const BasicJsonType &j, EnumType &e)
4007 typename std::underlying_type<EnumType>::type val;
4008 get_arithmetic_value(j, val);
4009 e =
static_cast<EnumType
>(val);
4013template<
typename BasicJsonType,
typename T,
typename Allocator,
4014 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4015void from_json(
const BasicJsonType &j, std::forward_list<T, Allocator> &l)
4017 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4019 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4023 std::transform(j.rbegin(), j.rend(),
4024 std::front_inserter(l), [](
const BasicJsonType & i)
4026 return i.template get<T>();
4031template<
typename BasicJsonType,
typename T,
4032 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4033void from_json(
const BasicJsonType &j, std::valarray<T> &l)
4035 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4037 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4041 std::transform(j.begin(), j.end(), std::begin(l),
4042 [](
const BasicJsonType & elem)
4044 return elem.template get<T>();
4048template<
typename BasicJsonType,
typename T, std::
size_t N>
4049auto from_json(
const BasicJsonType &j, T (&arr)[N])
4050->
decltype(j.template get<T>(), void())
4052 for (std::size_t i = 0; i < N; ++i)
4054 arr[i] = j.at(i).template get<T>();
4058template<
typename BasicJsonType>
4059void from_json_array_impl(
const BasicJsonType &j,
typename BasicJsonType::array_t &arr, priority_tag<3> )
4061 arr = *j.template get_ptr<const typename BasicJsonType::array_t *>();
4064template<
typename BasicJsonType,
typename T, std::
size_t N>
4065auto from_json_array_impl(
const BasicJsonType &j, std::array<T, N> &arr,
4067->
decltype(j.template get<T>(), void())
4069 for (std::size_t i = 0; i < N; ++i)
4071 arr[i] = j.at(i).template get<T>();
4075template<
typename BasicJsonType,
typename ConstructibleArrayType,
4077 std::is_assignable<ConstructibleArrayType &, ConstructibleArrayType>::value,
4079auto from_json_array_impl(
const BasicJsonType &j, ConstructibleArrayType &arr, priority_tag<1> )
4081 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4082 j.template get<typename ConstructibleArrayType::value_type>(),
4086 ConstructibleArrayType ret;
4087 ret.reserve(j.size());
4088 std::transform(j.begin(), j.end(),
4089 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4093 return i.template get<typename ConstructibleArrayType::value_type>();
4095 arr = std::move(ret);
4098template<
typename BasicJsonType,
typename ConstructibleArrayType,
4100 std::is_assignable<ConstructibleArrayType &, ConstructibleArrayType>::value,
4102void from_json_array_impl(
const BasicJsonType &j, ConstructibleArrayType &arr,
4106 ConstructibleArrayType ret;
4108 j.begin(), j.end(), std::inserter(ret, end(ret)),
4109 [](
const BasicJsonType & i)
4113 return i.template get<typename ConstructibleArrayType::value_type>();
4115 arr = std::move(ret);
4118template <
typename BasicJsonType,
typename ConstructibleArrayType,
4120 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value &&
4121 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value &&
4122 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value &&
4123 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value &&
4124 !is_basic_json<ConstructibleArrayType>::value,
4126auto from_json(
const BasicJsonType &j, ConstructibleArrayType &arr)
4127->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4128j.template get<typename ConstructibleArrayType::value_type>(),
4131 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4133 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4136 from_json_array_impl(j, arr, priority_tag<3> {});
4139template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4140std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType &&j,
4141 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4143 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4146template <
typename BasicJsonType,
typename T, std::
size_t N >
4147auto from_json(BasicJsonType &&j, identity_tag<std::array<T, N>> tag)
4148->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4150 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4152 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4155 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4158template<
typename BasicJsonType>
4159void from_json(
const BasicJsonType &j,
typename BasicJsonType::binary_t &bin)
4161 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4163 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name()), j));
4166 bin = *j.template get_ptr<const typename BasicJsonType::binary_t *>();
4169template<
typename BasicJsonType,
typename ConstructibleObjectType,
4170 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4171void from_json(
const BasicJsonType &j, ConstructibleObjectType &obj)
4173 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4175 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name()), j));
4178 ConstructibleObjectType ret;
4179 const auto *inner_object = j.template get_ptr<const typename BasicJsonType::object_t *>();
4180 using value_type =
typename ConstructibleObjectType::value_type;
4182 inner_object->begin(), inner_object->end(),
4183 std::inserter(ret, ret.begin()),
4184 [](
typename BasicJsonType::object_t::value_type
const & p)
4186 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4188 obj = std::move(ret);
4195template <
typename BasicJsonType,
typename ArithmeticType,
4197 std::is_arithmetic<ArithmeticType>::value &&
4198 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value &&
4199 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value &&
4200 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value &&
4201 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4203void from_json(
const BasicJsonType &j, ArithmeticType &val)
4205 switch (
static_cast<value_t>(j))
4209 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t *>());
4215 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t *>());
4221 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t *>());
4227 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t *>());
4238 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4242template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4243std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType &&j, index_sequence<Idx...> )
4245 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4248template <
typename BasicJsonType,
class A1,
class A2 >
4249std::pair<A1, A2> from_json_tuple_impl(BasicJsonType &&j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4251 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4252 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4255template<
typename BasicJsonType,
typename A1,
typename A2>
4256void from_json_tuple_impl(BasicJsonType &&j, std::pair<A1, A2> &p, priority_tag<1> )
4258 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4261template<
typename BasicJsonType,
typename... Args>
4262std::tuple<Args...> from_json_tuple_impl(BasicJsonType &&j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4264 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4267template<
typename BasicJsonType,
typename... Args>
4268void from_json_tuple_impl(BasicJsonType &&j, std::tuple<Args...> &t, priority_tag<3> )
4270 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4273template<
typename BasicJsonType,
typename TupleRelated>
4274auto from_json(BasicJsonType &&j, TupleRelated &&t)
4275->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4277 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4279 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4282 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4285template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4286 typename = enable_if_t < !std::is_constructible <
4287 typename BasicJsonType::string_t, Key >::value >>
4288void from_json(
const BasicJsonType &j, std::map<Key, Value, Compare, Allocator> &m)
4290 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4292 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4297 for (
const auto &p : j)
4299 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4301 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4304 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4308template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
4309 typename = enable_if_t < !std::is_constructible <
4310 typename BasicJsonType::string_t, Key >::value >>
4311void from_json(
const BasicJsonType &j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator> &m)
4313 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4315 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4320 for (
const auto &p : j)
4322 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4324 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4327 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4333 template<
typename BasicJsonType,
typename T>
4334 auto operator()(
const BasicJsonType &j, T &&val)
const
4335 noexcept(
noexcept(from_json(j, std::forward<T>(val))))
4336 ->
decltype(from_json(j, std::forward<T>(val)))
4338 return from_json(j, std::forward<T>(val));
4359#include <type_traits>
4382template<
typename string_type>
4383void int_to_string( string_type &target, std::size_t value )
4386 using std::to_string;
4392 using difference_type = std::ptrdiff_t;
4396 using iterator_category = std::input_iterator_tag;
4397 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().
key() ) >::type >::type;
4443 const string_type &
key()
const
4445 JSON_ASSERT(
anchor.m_object !=
nullptr);
4447 switch (
anchor.m_object->type())
4480 typename IteratorType::reference
value()
const
4513template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
4521template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
4535#if defined(__clang__)
4537#pragma clang diagnostic push
4538#pragma clang diagnostic ignored "-Wmismatched-tags"
4540template<
typename IteratorType>
4542 :
public std::integral_constant<std::size_t, 2> {};
4544template<std::
size_t N,
typename IteratorType>
4548 using type =
decltype(
4549 get<N>(std::declval <
4552#if defined(__clang__)
4553#pragma clang diagnostic pop
4584 template<
typename BasicJsonType>
4585 static void construct(BasicJsonType &j,
typename BasicJsonType::boolean_t b)
noexcept
4587 j.m_value.destroy(j.m_type);
4590 j.assert_invariant();
4597 template<
typename BasicJsonType>
4598 static void construct(BasicJsonType &j,
const typename BasicJsonType::string_t &s)
4600 j.m_value.destroy(j.m_type);
4603 j.assert_invariant();
4606 template<
typename BasicJsonType>
4607 static void construct(BasicJsonType &j,
typename BasicJsonType::string_t &&s)
4609 j.m_value.destroy(j.m_type);
4611 j.m_value = std::move(s);
4612 j.assert_invariant();
4615 template <
typename BasicJsonType,
typename CompatibleStringType,
4616 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4618 static void construct(BasicJsonType &j,
const CompatibleStringType &str)
4620 j.m_value.destroy(j.m_type);
4622 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4623 j.assert_invariant();
4630 template<
typename BasicJsonType>
4631 static void construct(BasicJsonType &j,
const typename BasicJsonType::binary_t &b)
4633 j.m_value.destroy(j.m_type);
4635 j.m_value =
typename BasicJsonType::binary_t(b);
4636 j.assert_invariant();
4639 template<
typename BasicJsonType>
4640 static void construct(BasicJsonType &j,
typename BasicJsonType::binary_t &&b)
4642 j.m_value.destroy(j.m_type);
4644 j.m_value =
typename BasicJsonType::binary_t(std::move(b));
4645 j.assert_invariant();
4652 template<
typename BasicJsonType>
4653 static void construct(BasicJsonType &j,
typename BasicJsonType::number_float_t val)
noexcept
4655 j.m_value.destroy(j.m_type);
4658 j.assert_invariant();
4665 template<
typename BasicJsonType>
4666 static void construct(BasicJsonType &j,
typename BasicJsonType::number_unsigned_t val)
noexcept
4668 j.m_value.destroy(j.m_type);
4671 j.assert_invariant();
4678 template<
typename BasicJsonType>
4679 static void construct(BasicJsonType &j,
typename BasicJsonType::number_integer_t val)
noexcept
4681 j.m_value.destroy(j.m_type);
4684 j.assert_invariant();
4691 template<
typename BasicJsonType>
4692 static void construct(BasicJsonType &j,
const typename BasicJsonType::array_t &arr)
4694 j.m_value.destroy(j.m_type);
4698 j.assert_invariant();
4701 template<
typename BasicJsonType>
4702 static void construct(BasicJsonType &j,
typename BasicJsonType::array_t &&arr)
4704 j.m_value.destroy(j.m_type);
4706 j.m_value = std::move(arr);
4708 j.assert_invariant();
4711 template <
typename BasicJsonType,
typename CompatibleArrayType,
4712 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4714 static void construct(BasicJsonType &j,
const CompatibleArrayType &arr)
4718 j.m_value.destroy(j.m_type);
4720 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4722 j.assert_invariant();
4725 template<
typename BasicJsonType>
4726 static void construct(BasicJsonType &j,
const std::vector<bool> &arr)
4728 j.m_value.destroy(j.m_type);
4731 j.m_value.array->reserve(arr.size());
4733 for (
const bool x : arr)
4735 j.m_value.array->push_back(x);
4736 j.set_parent(j.m_value.array->back());
4739 j.assert_invariant();
4742 template<
typename BasicJsonType,
typename T,
4743 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4744 static void construct(BasicJsonType &j,
const std::valarray<T> &arr)
4746 j.m_value.destroy(j.m_type);
4749 j.m_value.array->resize(arr.size());
4753 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4757 j.assert_invariant();
4764 template<
typename BasicJsonType>
4765 static void construct(BasicJsonType &j,
const typename BasicJsonType::object_t &obj)
4767 j.m_value.destroy(j.m_type);
4771 j.assert_invariant();
4774 template<
typename BasicJsonType>
4775 static void construct(BasicJsonType &j,
typename BasicJsonType::object_t &&obj)
4777 j.m_value.destroy(j.m_type);
4779 j.m_value = std::move(obj);
4781 j.assert_invariant();
4784 template <
typename BasicJsonType,
typename CompatibleObjectType,
4785 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4786 static void construct(BasicJsonType &j,
const CompatibleObjectType &obj)
4790 j.m_value.destroy(j.m_type);
4792 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4794 j.assert_invariant();
4802template<
typename BasicJsonType,
typename T,
4803 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4804void to_json(BasicJsonType &j, T b)
noexcept
4809template<
typename BasicJsonType,
typename CompatibleString,
4810 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4811void to_json(BasicJsonType &j,
const CompatibleString &s)
4813 external_constructor<value_t::string>::construct(j, s);
4816template<
typename BasicJsonType>
4817void to_json(BasicJsonType &j,
typename BasicJsonType::string_t &&s)
4819 external_constructor<value_t::string>::construct(j, std::move(s));
4822template<
typename BasicJsonType,
typename FloatType,
4823 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4824void to_json(BasicJsonType &j, FloatType val)
noexcept
4826 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4829template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4830 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4831void to_json(BasicJsonType &j, CompatibleNumberUnsignedType val)
noexcept
4833 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4836template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4837 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4838void to_json(BasicJsonType &j, CompatibleNumberIntegerType val)
noexcept
4840 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4843template<
typename BasicJsonType,
typename EnumType,
4844 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4845void to_json(BasicJsonType &j, EnumType e)
noexcept
4847 using underlying_type =
typename std::underlying_type<EnumType>::type;
4848 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4851template<
typename BasicJsonType>
4852void to_json(BasicJsonType &j,
const std::vector<bool> &e)
4854 external_constructor<value_t::array>::construct(j, e);
4857template <
typename BasicJsonType,
typename CompatibleArrayType,
4858 enable_if_t < is_compatible_array_type<BasicJsonType,
4859 CompatibleArrayType>::value &&
4860 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value &&
4861 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value &&
4862 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value &&
4863 !is_basic_json<CompatibleArrayType>::value,
4865void to_json(BasicJsonType &j,
const CompatibleArrayType &arr)
4867 external_constructor<value_t::array>::construct(j, arr);
4870template<
typename BasicJsonType>
4871void to_json(BasicJsonType &j,
const typename BasicJsonType::binary_t &bin)
4873 external_constructor<value_t::binary>::construct(j, bin);
4876template<
typename BasicJsonType,
typename T,
4877 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4878void to_json(BasicJsonType &j,
const std::valarray<T> &arr)
4880 external_constructor<value_t::array>::construct(j, std::move(arr));
4883template<
typename BasicJsonType>
4884void to_json(BasicJsonType &j,
typename BasicJsonType::array_t &&arr)
4886 external_constructor<value_t::array>::construct(j, std::move(arr));
4889template <
typename BasicJsonType,
typename CompatibleObjectType,
4890 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4891void to_json(BasicJsonType &j,
const CompatibleObjectType &obj)
4893 external_constructor<value_t::object>::construct(j, obj);
4896template<
typename BasicJsonType>
4897void to_json(BasicJsonType &j,
typename BasicJsonType::object_t &&obj)
4899 external_constructor<value_t::object>::construct(j, std::move(obj));
4903 typename BasicJsonType,
typename T, std::size_t N,
4904 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4905 const T(&)[N]>::value,
4907void to_json(BasicJsonType &j,
const T(&arr)[N])
4909 external_constructor<value_t::array>::construct(j, arr);
4912template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value &&std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4913void to_json(BasicJsonType &j,
const std::pair<T1, T2> &p)
4915 j = { p.first, p.second };
4919template<
typename BasicJsonType,
typename T,
4920 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4921void to_json(BasicJsonType &j,
const T &b)
4923 j = { {b.key(), b.value()} };
4926template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4927void to_json_tuple_impl(BasicJsonType &j,
const Tuple &t, index_sequence<Idx...> )
4929 j = { std::get<Idx>(t)... };
4932template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4933void to_json(BasicJsonType &j,
const T &t)
4935 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4940 template<
typename BasicJsonType,
typename T>
4941 auto operator()(BasicJsonType &j, T &&val)
const noexcept(
noexcept(to_json(j, std::forward<T>(val))))
4942 ->
decltype(to_json(j, std::forward<T>(val)), void())
4944 return to_json(j, std::forward<T>(val));
4966template<
typename ValueType,
typename>
4980 template<
typename BasicJsonType,
typename TargetType = ValueType>
4981 static auto from_json(BasicJsonType && j, TargetType &val)
noexcept(
4982 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4983 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
4985 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5000 template<
typename BasicJsonType,
typename TargetType = ValueType>
5005 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
5017 template<
typename BasicJsonType,
typename TargetType = ValueType>
5018 static auto to_json(BasicJsonType &j, TargetType && val)
noexcept(
5019 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5020 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
5022 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5050template<
typename BinaryType>
5073 , m_subtype(subtype_)
5074 , m_has_subtype(
true)
5079 , m_subtype(subtype_)
5080 , m_has_subtype(
true)
5083 bool operator==(
const byte_container_with_subtype &rhs)
const
5085 return std::tie(
static_cast<const BinaryType &
>(*
this), m_subtype, m_has_subtype) ==
5086 std::tie(
static_cast<const BinaryType &
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5089 bool operator!=(
const byte_container_with_subtype &rhs)
const
5091 return !(rhs == *
this);
5114 m_subtype = subtype_;
5115 m_has_subtype =
true;
5163 return m_has_subtype;
5188 m_has_subtype =
false;
5193 bool m_has_subtype =
false;
5209#include <functional>
5222inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
5224 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5239template<
typename BasicJsonType>
5240std::size_t
hash(
const BasicJsonType &j)
5242 using string_t =
typename BasicJsonType::string_t;
5243 using number_integer_t =
typename BasicJsonType::number_integer_t;
5244 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5245 using number_float_t =
typename BasicJsonType::number_float_t;
5246 const auto type =
static_cast<std::size_t
>(j.type());
5250 case BasicJsonType::value_t::null:
5251 case BasicJsonType::value_t::discarded:
5253 return combine(type, 0);
5256 case BasicJsonType::value_t::object:
5258 auto seed = combine(type, j.size());
5260 for (
const auto &element : j.items())
5262 const auto h = std::hash<string_t> {}(element.key());
5263 seed = combine(seed, h);
5264 seed = combine(seed,
hash(element.value()));
5270 case BasicJsonType::value_t::array:
5272 auto seed = combine(type, j.size());
5274 for (
const auto &element : j)
5276 seed = combine(seed,
hash(element));
5282 case BasicJsonType::value_t::string:
5284 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t &>());
5285 return combine(type, h);
5288 case BasicJsonType::value_t::boolean:
5290 const auto h = std::hash<bool> {}(j.template get<bool>());
5291 return combine(type, h);
5294 case BasicJsonType::value_t::number_integer:
5296 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5297 return combine(type, h);
5300 case BasicJsonType::value_t::number_unsigned:
5302 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5303 return combine(type, h);
5306 case BasicJsonType::value_t::number_float:
5308 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5309 return combine(type, h);
5312 case BasicJsonType::value_t::binary:
5314 auto seed = combine(type, j.get_binary().size());
5315 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5316 seed = combine(seed, h);
5317 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
5319 for (
const auto byte : j.get_binary())
5321 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5364#include <type_traits>
5396 using char_type = char;
5398 JSON_HEDLEY_NON_NULL(2)
5410 std::char_traits<char>::int_type get_character()
noexcept
5412 return std::fgetc(
m_file);
5433 using char_type = char;
5441 is->clear(
is->rdstate() & std::ios::eofbit);
5446 :
is(&i), sb(i.rdbuf())
5455 :
is(rhs.is), sb(rhs.sb)
5464 std::char_traits<char>::int_type get_character()
5466 auto res = sb->sbumpc();
5469 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
5471 is->clear(
is->rdstate() | std::ios::eofbit);
5479 std::istream *
is =
nullptr;
5480 std::streambuf *sb =
nullptr;
5486template<
typename IteratorType>
5490 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
5493 : current(std::move(first)), end(std::move(last))
5496 typename std::char_traits<char_type>::int_type get_character()
5498 if (JSON_HEDLEY_LIKELY(current != end))
5500 auto result = std::char_traits<char_type>::to_int_type(*current);
5501 std::advance(current, 1);
5505 return std::char_traits<char_type>::eof();
5509 IteratorType current;
5512 template<
typename BaseInputAdapter,
size_t T>
5517 return current == end;
5522template<
typename BaseInputAdapter,
size_t T>
5525template<
typename BaseInputAdapter>
5529 static void fill_buffer(BaseInputAdapter &input,
5530 std::array<std::char_traits<char>::int_type, 4> &utf8_bytes,
5531 size_t &utf8_bytes_index,
5532 size_t &utf8_bytes_filled)
5534 utf8_bytes_index = 0;
5536 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5538 utf8_bytes[0] = std::char_traits<char>::eof();
5539 utf8_bytes_filled = 1;
5545 const auto wc = input.get_character();
5550 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5551 utf8_bytes_filled = 1;
5554 else if (wc <= 0x7FF)
5556 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5557 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5558 utf8_bytes_filled = 2;
5561 else if (wc <= 0xFFFF)
5563 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5564 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5565 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5566 utf8_bytes_filled = 3;
5569 else if (wc <= 0x10FFFF)
5571 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5572 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5573 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5574 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5575 utf8_bytes_filled = 4;
5581 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5582 utf8_bytes_filled = 1;
5588template<
typename BaseInputAdapter>
5592 static void fill_buffer(BaseInputAdapter &input,
5593 std::array<std::char_traits<char>::int_type, 4> &utf8_bytes,
5594 size_t &utf8_bytes_index,
5595 size_t &utf8_bytes_filled)
5597 utf8_bytes_index = 0;
5599 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5601 utf8_bytes[0] = std::char_traits<char>::eof();
5602 utf8_bytes_filled = 1;
5608 const auto wc = input.get_character();
5613 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5614 utf8_bytes_filled = 1;
5617 else if (wc <= 0x7FF)
5619 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
5620 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5621 utf8_bytes_filled = 2;
5624 else if (0xD800 > wc || wc >= 0xE000)
5626 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
5627 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5628 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5629 utf8_bytes_filled = 3;
5634 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5636 const auto wc2 =
static_cast<unsigned int>(input.get_character());
5637 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5638 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
5639 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
5640 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
5641 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
5642 utf8_bytes_filled = 4;
5647 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5648 utf8_bytes_filled = 1;
5656template<
typename BaseInputAdapter,
typename W
ideCharType>
5660 using char_type = char;
5663 : base_adapter(base) {}
5665 typename std::char_traits<char>::int_type get_character()
noexcept
5670 fill_buffer<sizeof(WideCharType)>();
5682 BaseInputAdapter base_adapter;
5691 std::array<std::char_traits<char>::int_type, 4>
utf8_bytes = {{0, 0, 0, 0}};
5700template<
typename IteratorType,
typename Enable =
void>
5703 using iterator_type = IteratorType;
5704 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5707 static adapter_type create(IteratorType first, IteratorType last)
5709 return adapter_type(std::move(first), std::move(last));
5716 using value_type =
typename std::iterator_traits<T>::value_type;
5719 value =
sizeof(value_type) > 1
5723template<
typename IteratorType>
5726 using iterator_type = IteratorType;
5727 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5731 static adapter_type create(IteratorType first, IteratorType last)
5738template<
typename IteratorType>
5742 return factory_type::create(first, last);
5749namespace container_input_adapter_factory_impl
5755template<
typename ContainerType,
typename Enable =
void>
5758template<
typename ContainerType>
5760 void_t<decltype(begin(
std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5762 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5764 static adapter_type create(
const ContainerType &container)
5766 return input_adapter(begin(container), end(container));
5772template<
typename ContainerType>
5780inline file_input_adapter input_adapter(std::FILE *file)
5782 return file_input_adapter(file);
5785inline input_stream_adapter input_adapter(std::istream &stream)
5787 return input_stream_adapter(stream);
5790inline input_stream_adapter input_adapter(std::istream &&stream)
5792 return input_stream_adapter(stream);
5796using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char *>(), std::declval<const char *>()));
5799template <
typename CharT,
5800 typename std::enable_if <
5801 std::is_pointer<CharT>::value &&
5802 !std::is_array<CharT>::value &&
5803 std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
5804 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5806contiguous_bytes_input_adapter input_adapter(CharT b)
5808 auto length = std::strlen(
reinterpret_cast<const char *
>(b));
5809 const auto *ptr =
reinterpret_cast<const char *
>(b);
5810 return input_adapter(ptr, ptr + length);
5813template<
typename T, std::
size_t N>
5814auto input_adapter(T (&array)[N]) ->
decltype(input_adapter(array, array + N))
5816 return input_adapter(array, array + N);
5825 template <
typename CharT,
5826 typename std::enable_if <
5827 std::is_pointer<CharT>::value &&
5828 std::is_integral<typename std::remove_pointer<CharT>::type>::value &&
5829 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5832 : ia(
reinterpret_cast<const char *
>(b),
reinterpret_cast<const char *
>(b) + l) {}
5834 template<
class IteratorType,
5835 typename std::enable_if<
5836 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5839 : ia(input_adapter(first, last)) {}
5841 contiguous_bytes_input_adapter &&get()
5843 return std::move(ia);
5847 contiguous_bytes_input_adapter ia;
5876template<
typename BasicJsonType>
5879 using number_integer_t =
typename BasicJsonType::number_integer_t;
5880 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5881 using number_float_t =
typename BasicJsonType::number_float_t;
5882 using string_t =
typename BasicJsonType::string_t;
5883 using binary_t =
typename BasicJsonType::binary_t;
5950 virtual bool key(string_t &val) = 0;
5980 const std::string &last_token,
6007template<
typename BasicJsonType>
6011 using number_integer_t =
typename BasicJsonType::number_integer_t;
6012 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6013 using number_float_t =
typename BasicJsonType::number_float_t;
6014 using string_t =
typename BasicJsonType::string_t;
6015 using binary_t =
typename BasicJsonType::binary_t;
6023 : root(r), allow_exceptions(allow_exceptions_)
6035 handle_value(
nullptr);
6057 bool number_float(number_float_t val,
const string_t & )
6063 bool string(string_t &val)
6069 bool binary(binary_t &val)
6071 handle_value(std::move(val));
6077 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6079 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6081 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6087 bool key(string_t &val)
6090 object_element = &(ref_stack.back()->m_value.object->operator[](val));
6096 ref_stack.back()->set_parents();
6097 ref_stack.pop_back();
6103 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6105 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6107 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6115 ref_stack.back()->set_parents();
6116 ref_stack.pop_back();
6120 template<
class Exception>
6121 bool parse_error(std::size_t ,
const std::string & ,
6122 const Exception &ex)
6125 static_cast<void>(ex);
6127 if (allow_exceptions)
6135 constexpr bool is_errored()
const
6147 template<
typename Value>
6148 JSON_HEDLEY_RETURNS_NON_NULL
6151 if (ref_stack.empty())
6153 root = BasicJsonType(std::forward<Value>(v));
6157 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6159 if (ref_stack.back()->is_array())
6161 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6162 return &(ref_stack.back()->m_value.array->back());
6165 JSON_ASSERT(ref_stack.back()->is_object());
6166 JSON_ASSERT(object_element);
6167 *object_element = BasicJsonType(std::forward<Value>(v));
6168 return object_element;
6174 std::vector<BasicJsonType *> ref_stack {};
6176 BasicJsonType *object_element =
nullptr;
6178 bool errored =
false;
6180 const bool allow_exceptions =
true;
6183template<
typename BasicJsonType>
6187 using number_integer_t =
typename BasicJsonType::number_integer_t;
6188 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6189 using number_float_t =
typename BasicJsonType::number_float_t;
6190 using string_t =
typename BasicJsonType::string_t;
6191 using binary_t =
typename BasicJsonType::binary_t;
6192 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6193 using parse_event_t =
typename BasicJsonType::parse_event_t;
6196 const parser_callback_t cb,
6197 const bool allow_exceptions_ =
true)
6198 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6200 keep_stack.push_back(
true);
6212 handle_value(
nullptr);
6234 bool number_float(number_float_t val,
const string_t & )
6240 bool string(string_t &val)
6246 bool binary(binary_t &val)
6248 handle_value(std::move(val));
6255 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start,
discarded);
6256 keep_stack.push_back(keep);
6257 auto val = handle_value(BasicJsonType::value_t::object,
true);
6258 ref_stack.push_back(val.second);
6261 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6263 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6269 bool key(string_t &val)
6271 BasicJsonType k = BasicJsonType(val);
6273 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
6274 key_keep_stack.push_back(keep);
6277 if (keep && ref_stack.back())
6279 object_element = &(ref_stack.back()->m_value.object->operator[](val) =
discarded);
6287 if (ref_stack.back())
6289 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6297 ref_stack.back()->set_parents();
6301 JSON_ASSERT(!ref_stack.empty());
6302 JSON_ASSERT(!keep_stack.empty());
6303 ref_stack.pop_back();
6304 keep_stack.pop_back();
6306 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6309 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6311 if (it->is_discarded())
6313 ref_stack.back()->erase(it);
6324 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start,
discarded);
6325 keep_stack.push_back(keep);
6326 auto val = handle_value(BasicJsonType::value_t::array,
true);
6327 ref_stack.push_back(val.second);
6330 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6332 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6342 if (ref_stack.back())
6344 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6348 ref_stack.back()->set_parents();
6358 JSON_ASSERT(!ref_stack.empty());
6359 JSON_ASSERT(!keep_stack.empty());
6360 ref_stack.pop_back();
6361 keep_stack.pop_back();
6364 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6366 ref_stack.back()->m_value.array->pop_back();
6372 template<
class Exception>
6373 bool parse_error(std::size_t ,
const std::string & ,
6374 const Exception &ex)
6377 static_cast<void>(ex);
6379 if (allow_exceptions)
6387 constexpr bool is_errored()
const
6408 template<
typename Value>
6409 std::pair<bool, BasicJsonType *>
handle_value(Value &&v,
const bool skip_callback =
false)
6411 JSON_ASSERT(!keep_stack.empty());
6415 if (!keep_stack.back())
6417 return {
false,
nullptr};
6421 auto value = BasicJsonType(std::forward<Value>(v));
6423 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value,
value);
6428 return {
false,
nullptr};
6431 if (ref_stack.empty())
6433 root = std::move(
value);
6434 return {
true, &root};
6439 if (!ref_stack.back())
6441 return {
false,
nullptr};
6445 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6448 if (ref_stack.back()->is_array())
6450 ref_stack.back()->m_value.array->emplace_back(std::move(
value));
6451 return {
true, &(ref_stack.back()->m_value.array->back())};
6455 JSON_ASSERT(ref_stack.back()->is_object());
6457 JSON_ASSERT(!key_keep_stack.empty());
6458 const bool store_element = key_keep_stack.back();
6459 key_keep_stack.pop_back();
6463 return {
false,
nullptr};
6466 JSON_ASSERT(object_element);
6467 *object_element = std::move(
value);
6468 return {
true, object_element};
6474 std::vector<BasicJsonType *> ref_stack {};
6476 std::vector<bool> keep_stack {};
6478 std::vector<bool> key_keep_stack {};
6480 BasicJsonType *object_element =
nullptr;
6482 bool errored =
false;
6484 const parser_callback_t callback =
nullptr;
6486 const bool allow_exceptions =
true;
6488 BasicJsonType
discarded = BasicJsonType::value_t::discarded;
6491template<
typename BasicJsonType>
6495 using number_integer_t =
typename BasicJsonType::number_integer_t;
6496 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6497 using number_float_t =
typename BasicJsonType::number_float_t;
6498 using string_t =
typename BasicJsonType::string_t;
6499 using binary_t =
typename BasicJsonType::binary_t;
6541 bool key(string_t & )
6578#include <initializer_list>
6598template<
typename BasicJsonType>
6625 JSON_HEDLEY_RETURNS_NON_NULL
6632 return "<uninitialized>";
6635 return "true literal";
6638 return "false literal";
6641 return "null literal";
6644 return "string literal";
6649 return "number literal";
6670 return "<parse error>";
6673 return "end of input";
6676 return "'[', '{', or a literal";
6680 return "unknown token";
6690template<
typename BasicJsonType,
typename InputAdapterType>
6693 using number_integer_t =
typename BasicJsonType::number_integer_t;
6694 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6695 using number_float_t =
typename BasicJsonType::number_float_t;
6696 using string_t =
typename BasicJsonType::string_t;
6697 using char_type =
typename InputAdapterType::char_type;
6698 using char_int_type =
typename std::char_traits<char_type>::int_type;
6703 explicit lexer(InputAdapterType &&adapter,
bool ignore_comments_ =
false) noexcept
6704 :
ia(std::move(adapter))
6725 const auto *loc = localeconv();
6726 JSON_ASSERT(loc !=
nullptr);
6727 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6754 const auto factors = { 12u, 8u, 4u, 0u };
6756 for (
const auto factor : factors)
6762 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x30u) << factor);
6767 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x37u) << factor);
6772 codepoint +=
static_cast<int>((
static_cast<unsigned int>(
current) - 0x57u) << factor);
6781 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6802 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6805 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6809 if (JSON_HEDLEY_LIKELY(*range <=
current &&
current <= *(++range)))
6852 case std::char_traits<char_type>::eof():
6855 return token_type::parse_error;
6861 return token_type::value_string;
6913 int codepoint = codepoint1;
6915 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6917 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6918 return token_type::parse_error;
6922 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6925 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6929 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6931 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6932 return token_type::parse_error;
6936 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6939 codepoint =
static_cast<int>(
6941 (
static_cast<unsigned int>(codepoint1) << 10u)
6943 +
static_cast<unsigned int>(codepoint2)
6952 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6953 return token_type::parse_error;
6959 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6960 return token_type::parse_error;
6966 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6968 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6969 return token_type::parse_error;
6974 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6977 if (codepoint < 0x80)
6980 add(
static_cast<char_int_type
>(codepoint));
6983 else if (codepoint <= 0x7FF)
6986 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6987 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6990 else if (codepoint <= 0xFFFF)
6993 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
6994 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6995 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7001 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7002 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7003 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7004 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7012 error_message =
"invalid string: forbidden character after backslash";
7013 return token_type::parse_error;
7022 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7023 return token_type::parse_error;
7028 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7029 return token_type::parse_error;
7034 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7035 return token_type::parse_error;
7040 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7041 return token_type::parse_error;
7046 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7047 return token_type::parse_error;
7052 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7053 return token_type::parse_error;
7058 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7059 return token_type::parse_error;
7064 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7065 return token_type::parse_error;
7070 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7071 return token_type::parse_error;
7076 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7077 return token_type::parse_error;
7082 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7083 return token_type::parse_error;
7088 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7089 return token_type::parse_error;
7094 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7095 return token_type::parse_error;
7100 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7101 return token_type::parse_error;
7106 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7107 return token_type::parse_error;
7112 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7113 return token_type::parse_error;
7118 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7119 return token_type::parse_error;
7124 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7125 return token_type::parse_error;
7130 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7131 return token_type::parse_error;
7136 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7137 return token_type::parse_error;
7142 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7143 return token_type::parse_error;
7148 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7149 return token_type::parse_error;
7154 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7155 return token_type::parse_error;
7160 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7161 return token_type::parse_error;
7166 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7167 return token_type::parse_error;
7172 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7173 return token_type::parse_error;
7178 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7179 return token_type::parse_error;
7184 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7185 return token_type::parse_error;
7190 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7191 return token_type::parse_error;
7196 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7197 return token_type::parse_error;
7202 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7203 return token_type::parse_error;
7208 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7209 return token_type::parse_error;
7346 return token_type::parse_error;
7356 return token_type::parse_error;
7380 return token_type::parse_error;
7390 return token_type::parse_error;
7398 if (JSON_HEDLEY_UNLIKELY(!(
next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7400 return token_type::parse_error;
7410 if (JSON_HEDLEY_UNLIKELY(!(
next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7412 return token_type::parse_error;
7420 if (JSON_HEDLEY_UNLIKELY(!(
next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7422 return token_type::parse_error;
7431 return token_type::parse_error;
7454 case std::char_traits<char_type>::eof():
7471 case std::char_traits<char_type>::eof():
7502 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7508 JSON_HEDLEY_NON_NULL(2)
7509 static
void strtof(
float &f, const
char *str,
char **endptr) noexcept
7511 f = std::strtof(str, endptr);
7514 JSON_HEDLEY_NON_NULL(2)
7515 static
void strtof(
double &f, const
char *str,
char **endptr) noexcept
7517 f = std::strtod(str, endptr);
7520 JSON_HEDLEY_NON_NULL(2)
7521 static
void strtof(
long double &f, const
char *str,
char **endptr) noexcept
7523 f = std::strtold(str, endptr);
7572 token_type number_type = token_type::value_unsigned;
7580 goto scan_number_minus;
7586 goto scan_number_zero;
7600 goto scan_number_any1;
7610 number_type = token_type::value_integer;
7617 goto scan_number_zero;
7631 goto scan_number_any1;
7637 return token_type::parse_error;
7649 goto scan_number_decimal1;
7656 goto scan_number_exponent;
7660 goto scan_number_done;
7680 goto scan_number_any1;
7686 goto scan_number_decimal1;
7693 goto scan_number_exponent;
7697 goto scan_number_done;
7700scan_number_decimal1:
7702 number_type = token_type::value_float;
7718 goto scan_number_decimal2;
7724 return token_type::parse_error;
7728scan_number_decimal2:
7745 goto scan_number_decimal2;
7752 goto scan_number_exponent;
7756 goto scan_number_done;
7759scan_number_exponent:
7761 number_type = token_type::value_float;
7769 goto scan_number_sign;
7784 goto scan_number_any2;
7790 "invalid number; expected '+', '-', or digit after exponent";
7791 return token_type::parse_error;
7812 goto scan_number_any2;
7817 error_message =
"invalid number; expected digit after exponent sign";
7818 return token_type::parse_error;
7839 goto scan_number_any2;
7843 goto scan_number_done;
7850 char *endptr =
nullptr;
7854 if (number_type == token_type::value_unsigned)
7856 const auto x = std::strtoull(
token_buffer.data(), &endptr, 10);
7862 value_unsigned =
static_cast<number_unsigned_t
>(x);
7864 if (value_unsigned == x)
7866 return token_type::value_unsigned;
7871 else if (number_type == token_type::value_integer)
7873 const auto x = std::strtoll(
token_buffer.data(), &endptr, 10);
7879 value_integer =
static_cast<number_integer_t
>(x);
7881 if (value_integer == x)
7883 return token_type::value_integer;
7893 return token_type::value_float;
7901 JSON_HEDLEY_NON_NULL(2)
7905 JSON_ASSERT(std::char_traits<char_type>::to_char_type(
current) == literal_text[0]);
7907 for (std::size_t i = 1; i < length; ++i)
7909 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7912 return token_type::parse_error;
7957 if (JSON_HEDLEY_LIKELY(
current != std::char_traits<char_type>::eof()))
7998 if (JSON_HEDLEY_LIKELY(
current != std::char_traits<char_type>::eof()))
8008 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8019 return value_integer;
8025 return value_unsigned;
8060 if (
static_cast<unsigned char>(c) <=
'\x1F')
8063 std::array<char, 9> cs{{}};
8064 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
8065 result += cs.data();
8071 result.push_back(
static_cast<std::string::value_type
>(c));
8079 JSON_HEDLEY_RETURNS_NON_NULL
8098 return get() == 0xBB && get() == 0xBF;
8107 void skip_whitespace()
8121 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8122 return token_type::parse_error;
8133 return token_type::parse_error;
8144 return token_type::begin_array;
8147 return token_type::end_array;
8150 return token_type::begin_object;
8153 return token_type::end_object;
8156 return token_type::name_separator;
8159 return token_type::value_separator;
8164 std::array<char_type, 4> true_literal = {{char_type(
't'), char_type(
'r'), char_type(
'u'), char_type(
'e')}};
8165 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8170 std::array<char_type, 5> false_literal = {{char_type(
'f'), char_type(
'a'), char_type(
'l'), char_type(
's'), char_type(
'e')}};
8171 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8176 std::array<char_type, 4> null_literal = {{char_type(
'n'), char_type(
'u'), char_type(
'l'), char_type(
'l')}};
8177 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8201 case std::char_traits<char_type>::eof():
8202 return token_type::end_of_input;
8207 return token_type::parse_error;
8219 char_int_type
current = std::char_traits<char_type>::eof();
8237 number_integer_t value_integer = 0;
8238 number_unsigned_t value_unsigned = 0;
8239 number_float_t value_float = 0;
8266using null_function_t =
decltype(std::declval<T &>().null());
8269using boolean_function_t =
8270 decltype(std::declval<T &>().boolean(std::declval<bool>()));
8272template<
typename T,
typename Integer>
8273using number_integer_function_t =
8274 decltype(std::declval<T &>().number_integer(std::declval<Integer>()));
8276template<
typename T,
typename Un
signed>
8277using number_unsigned_function_t =
8278 decltype(std::declval<T &>().number_unsigned(std::declval<Unsigned>()));
8280template<
typename T,
typename Float,
typename String>
8281using number_float_function_t =
decltype(std::declval<T &>().number_float(
8282 std::declval<Float>(), std::declval<const String &>()));
8284template<
typename T,
typename String>
8285using string_function_t =
8286 decltype(std::declval<T &>().string(std::declval<String &>()));
8288template<
typename T,
typename Binary>
8289using binary_function_t =
8290 decltype(std::declval<T &>().binary(std::declval<Binary &>()));
8293using start_object_function_t =
8294 decltype(std::declval<T &>().start_object(std::declval<std::size_t>()));
8296template<
typename T,
typename String>
8297using key_function_t =
8298 decltype(std::declval<T &>().key(std::declval<String &>()));
8301using end_object_function_t =
decltype(std::declval<T &>().end_object());
8304using start_array_function_t =
8305 decltype(std::declval<T &>().start_array(std::declval<std::size_t>()));
8308using end_array_function_t =
decltype(std::declval<T &>().end_array());
8310template<
typename T,
typename Exception>
8311using parse_error_function_t =
decltype(std::declval<T &>().parse_error(
8312 std::declval<std::size_t>(), std::declval<const std::string &>(),
8313 std::declval<const Exception &>()));
8315template<
typename SAX,
typename BasicJsonType>
8320 "BasicJsonType must be of type basic_json<...>");
8322 using number_integer_t =
typename BasicJsonType::number_integer_t;
8323 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8324 using number_float_t =
typename BasicJsonType::number_float_t;
8325 using string_t =
typename BasicJsonType::string_t;
8326 using binary_t =
typename BasicJsonType::binary_t;
8327 using exception_t =
typename BasicJsonType::exception;
8330 static constexpr bool value =
8331 is_detected_exact<bool, null_function_t, SAX>::value &&
8332 is_detected_exact<bool, boolean_function_t, SAX>::value &&
8333 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8334 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8335 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8336 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8337 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8338 is_detected_exact<bool, start_object_function_t, SAX>::value &&
8339 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8340 is_detected_exact<bool, end_object_function_t, SAX>::value &&
8341 is_detected_exact<bool, start_array_function_t, SAX>::value &&
8342 is_detected_exact<bool, end_array_function_t, SAX>::value &&
8343 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8346template<
typename SAX,
typename BasicJsonType>
8351 "BasicJsonType must be of type basic_json<...>");
8353 using number_integer_t =
typename BasicJsonType::number_integer_t;
8354 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8355 using number_float_t =
typename BasicJsonType::number_float_t;
8356 using string_t =
typename BasicJsonType::string_t;
8357 using binary_t =
typename BasicJsonType::binary_t;
8358 using exception_t =
typename BasicJsonType::exception;
8361 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8362 "Missing/invalid function: bool null()");
8363 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8364 "Missing/invalid function: bool boolean(bool)");
8365 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8366 "Missing/invalid function: bool boolean(bool)");
8368 is_detected_exact<bool, number_integer_function_t, SAX,
8369 number_integer_t>::value,
8370 "Missing/invalid function: bool number_integer(number_integer_t)");
8372 is_detected_exact<bool, number_unsigned_function_t, SAX,
8373 number_unsigned_t>::value,
8374 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8375 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
8376 number_float_t, string_t>::value,
8377 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8379 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8380 "Missing/invalid function: bool string(string_t&)");
8382 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8383 "Missing/invalid function: bool binary(binary_t&)");
8384 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8385 "Missing/invalid function: bool start_object(std::size_t)");
8386 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8387 "Missing/invalid function: bool key(string_t&)");
8388 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8389 "Missing/invalid function: bool end_object()");
8390 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8391 "Missing/invalid function: bool start_array(std::size_t)");
8392 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8393 "Missing/invalid function: bool end_array()");
8395 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8396 "Missing/invalid function: bool parse_error(std::size_t, const "
8397 "std::string&, const exception&)");
8429 return *
reinterpret_cast<char *
>(&num) == 1;
8440template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
8443 using number_integer_t =
typename BasicJsonType::number_integer_t;
8444 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8445 using number_float_t =
typename BasicJsonType::number_float_t;
8446 using string_t =
typename BasicJsonType::string_t;
8447 using binary_t =
typename BasicJsonType::binary_t;
8448 using json_sax_t = SAX;
8449 using char_type =
typename InputAdapterType::char_type;
8450 using char_int_type =
typename std::char_traits<char_type>::int_type;
8478 JSON_HEDLEY_NON_NULL(3)
8481 const
bool strict = true,
8485 bool result =
false;
8489 case input_format_t::bson:
8493 case input_format_t::cbor:
8497 case input_format_t::msgpack:
8501 case input_format_t::ubjson:
8505 case input_format_t::json:
8513 if (format == input_format_t::ubjson)
8523 if (JSON_HEDLEY_UNLIKELY(
current != std::char_traits<char_type>::eof()))
8544 std::int32_t document_size{};
8545 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8547 if (JSON_HEDLEY_UNLIKELY(!
sax->start_object(std::size_t(-1))))
8557 return sax->end_object();
8569 auto out = std::back_inserter(result);
8575 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::bson,
"cstring")))
8585 *out++ =
static_cast<typename string_t::value_type
>(
current);
8600 template<
typename NumberType>
8603 if (JSON_HEDLEY_UNLIKELY(len < 1))
8609 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) &&
get() != std::char_traits<char_type>::eof();
8621 template<
typename NumberType>
8624 if (JSON_HEDLEY_UNLIKELY(len < 0))
8631 std::uint8_t subtype{};
8632 get_number<std::uint8_t>(input_format_t::bson, subtype);
8633 result.set_subtype(subtype);
8634 return get_binary(input_format_t::bson, len, result);
8648 const std::size_t element_type_parse_position)
8650 switch (element_type)
8655 return get_number<double, true>(input_format_t::bson, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
8684 return sax->boolean(
get() != 0);
8694 std::int32_t
value{};
8695 return get_number<std::int32_t, true>(input_format_t::bson,
value) &&
sax->number_integer(
value);
8700 std::int64_t
value{};
8701 return get_number<std::int64_t, true>(input_format_t::bson,
value) &&
sax->number_integer(
value);
8706 std::array<char, 3> cr{{}};
8707 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
8708 return sax->parse_error(element_type_parse_position, std::string(cr.data()),
parse_error::create(114, element_type_parse_position,
"Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType()));
8729 while (
auto element_type =
get())
8731 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::bson,
"element list")))
8736 const std::size_t element_type_parse_position =
chars_read;
8743 if (!is_array && !
sax->key(
key))
8766 std::int32_t document_size{};
8767 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8769 if (JSON_HEDLEY_UNLIKELY(!
sax->start_array(std::size_t(-1))))
8779 return sax->end_array();
8800 case std::char_traits<char_type>::eof():
8828 return sax->number_unsigned(
static_cast<number_unsigned_t
>(
current));
8832 std::uint8_t number{};
8833 return get_number(input_format_t::cbor, number) &&
sax->number_unsigned(number);
8838 std::uint16_t number{};
8839 return get_number(input_format_t::cbor, number) &&
sax->number_unsigned(number);
8844 std::uint32_t number{};
8845 return get_number(input_format_t::cbor, number) &&
sax->number_unsigned(number);
8850 std::uint64_t number{};
8851 return get_number(input_format_t::cbor, number) &&
sax->number_unsigned(number);
8879 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 -
current));
8883 std::uint8_t number{};
8884 return get_number(input_format_t::cbor, number) &&
sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8889 std::uint16_t number{};
8890 return get_number(input_format_t::cbor, number) &&
sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8895 std::uint32_t number{};
8896 return get_number(input_format_t::cbor, number) &&
sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8901 std::uint64_t number{};
8902 return get_number(input_format_t::cbor, number) &&
sax->number_integer(
static_cast<number_integer_t
>(-1)
8903 -
static_cast<number_integer_t
>(number));
9001 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(
current) & 0x1Fu), tag_handler);
9006 return get_number(input_format_t::cbor, len) &&
get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9011 std::uint16_t len{};
9012 return get_number(input_format_t::cbor, len) &&
get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9017 std::uint32_t len{};
9018 return get_number(input_format_t::cbor, len) &&
get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9023 std::uint64_t len{};
9024 return get_number(input_format_t::cbor, len) &&
get_cbor_array(detail::conditional_static_cast<std::size_t>(len), tag_handler);
9055 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(
current) & 0x1Fu), tag_handler);
9060 return get_number(input_format_t::cbor, len) &&
get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9065 std::uint16_t len{};
9066 return get_number(input_format_t::cbor, len) &&
get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9071 std::uint32_t len{};
9072 return get_number(input_format_t::cbor, len) &&
get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9077 std::uint64_t len{};
9078 return get_number(input_format_t::cbor, len) &&
get_cbor_object(detail::conditional_static_cast<std::size_t>(len), tag_handler);
9104 switch (tag_handler)
9119 std::uint8_t subtype_to_ignore{};
9120 get_number(input_format_t::cbor, subtype_to_ignore);
9126 std::uint16_t subtype_to_ignore{};
9127 get_number(input_format_t::cbor, subtype_to_ignore);
9133 std::uint32_t subtype_to_ignore{};
9134 get_number(input_format_t::cbor, subtype_to_ignore);
9140 std::uint64_t subtype_to_ignore{};
9141 get_number(input_format_t::cbor, subtype_to_ignore);
9161 std::uint8_t subtype{};
9162 get_number(input_format_t::cbor, subtype);
9163 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9169 std::uint16_t subtype{};
9170 get_number(input_format_t::cbor, subtype);
9171 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9177 std::uint32_t subtype{};
9178 get_number(input_format_t::cbor, subtype);
9179 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9185 std::uint64_t subtype{};
9186 get_number(input_format_t::cbor, subtype);
9187 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9206 return sax->boolean(
false);
9209 return sax->boolean(
true);
9216 const auto byte1_raw =
get();
9218 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::cbor,
"number")))
9223 const auto byte2_raw =
get();
9225 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::cbor,
"number")))
9230 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9231 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9240 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9241 const double val = [&half]
9243 const int exp = (half >> 10u) & 0x1Fu;
9244 const unsigned int mant = half & 0x3FFu;
9245 JSON_ASSERT(0 <= exp &&exp <= 32);
9246 JSON_ASSERT(mant <= 1024);
9251 return std::ldexp(mant, -24);
9255 ? std::numeric_limits<double>::infinity()
9256 : std::numeric_limits<double>::quiet_NaN();
9259 return std::ldexp(mant + 1024, exp - 25);
9262 return sax->number_float((half & 0x8000u) != 0
9263 ?
static_cast<number_float_t
>(-val)
9264 :
static_cast<number_float_t
>(val),
"");
9270 return get_number(input_format_t::cbor, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
9276 return get_number(input_format_t::cbor, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
9300 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::cbor,
"string")))
9333 return get_string(input_format_t::cbor,
static_cast<unsigned int>(
current) & 0x1Fu, result);
9339 return get_number(input_format_t::cbor, len) &&
get_string(input_format_t::cbor, len, result);
9344 std::uint16_t len{};
9345 return get_number(input_format_t::cbor, len) &&
get_string(input_format_t::cbor, len, result);
9350 std::uint32_t len{};
9351 return get_number(input_format_t::cbor, len) &&
get_string(input_format_t::cbor, len, result);
9356 std::uint64_t len{};
9357 return get_number(input_format_t::cbor, len) &&
get_string(input_format_t::cbor, len, result);
9362 while (
get() != 0xFF)
9371 result.append(chunk);
9398 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::cbor,
"binary")))
9431 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(
current) & 0x1Fu, result);
9437 return get_number(input_format_t::cbor, len) &&
9438 get_binary(input_format_t::cbor, len, result);
9443 std::uint16_t len{};
9444 return get_number(input_format_t::cbor, len) &&
9445 get_binary(input_format_t::cbor, len, result);
9450 std::uint32_t len{};
9451 return get_number(input_format_t::cbor, len) &&
9452 get_binary(input_format_t::cbor, len, result);
9457 std::uint64_t len{};
9458 return get_number(input_format_t::cbor, len) &&
9459 get_binary(input_format_t::cbor, len, result);
9464 while (
get() != 0xFF)
9473 result.insert(result.end(), chunk.begin(), chunk.end());
9496 if (JSON_HEDLEY_UNLIKELY(!
sax->start_array(len)))
9501 if (len != std::size_t(-1))
9503 for (std::size_t i = 0; i < len; ++i)
9514 while (
get() != 0xFF)
9523 return sax->end_array();
9535 if (JSON_HEDLEY_UNLIKELY(!
sax->start_object(len)))
9544 if (len != std::size_t(-1))
9546 for (std::size_t i = 0; i < len; ++i)
9566 while (
get() != 0xFF)
9583 return sax->end_object();
9598 case std::char_traits<char_type>::eof():
9730 return sax->number_unsigned(
static_cast<number_unsigned_t
>(
current));
9815 return sax->boolean(
false);
9818 return sax->boolean(
true);
9839 return get_number(input_format_t::msgpack, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
9845 return get_number(input_format_t::msgpack, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
9850 std::uint8_t number{};
9851 return get_number(input_format_t::msgpack, number) &&
sax->number_unsigned(number);
9856 std::uint16_t number{};
9857 return get_number(input_format_t::msgpack, number) &&
sax->number_unsigned(number);
9862 std::uint32_t number{};
9863 return get_number(input_format_t::msgpack, number) &&
sax->number_unsigned(number);
9868 std::uint64_t number{};
9869 return get_number(input_format_t::msgpack, number) &&
sax->number_unsigned(number);
9874 std::int8_t number{};
9875 return get_number(input_format_t::msgpack, number) &&
sax->number_integer(number);
9880 std::int16_t number{};
9881 return get_number(input_format_t::msgpack, number) &&
sax->number_integer(number);
9886 std::int32_t number{};
9887 return get_number(input_format_t::msgpack, number) &&
sax->number_integer(number);
9892 std::int64_t number{};
9893 return get_number(input_format_t::msgpack, number) &&
sax->number_integer(number);
9898 std::uint16_t len{};
9899 return get_number(input_format_t::msgpack, len) &&
get_msgpack_array(
static_cast<std::size_t
>(len));
9904 std::uint32_t len{};
9905 return get_number(input_format_t::msgpack, len) &&
get_msgpack_array(
static_cast<std::size_t
>(len));
9910 std::uint16_t len{};
9911 return get_number(input_format_t::msgpack, len) &&
get_msgpack_object(
static_cast<std::size_t
>(len));
9916 std::uint32_t len{};
9917 return get_number(input_format_t::msgpack, len) &&
get_msgpack_object(
static_cast<std::size_t
>(len));
9953 return sax->number_integer(
static_cast<std::int8_t
>(
current));
9975 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::msgpack,
"string")))
10016 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(
current) & 0x1Fu, result);
10021 std::uint8_t len{};
10022 return get_number(input_format_t::msgpack, len) &&
get_string(input_format_t::msgpack, len, result);
10027 std::uint16_t len{};
10028 return get_number(input_format_t::msgpack, len) &&
get_string(input_format_t::msgpack, len, result);
10033 std::uint32_t len{};
10034 return get_number(input_format_t::msgpack, len) &&
get_string(input_format_t::msgpack, len, result);
10058 auto assign_and_return_true = [&result](std::int8_t subtype)
10060 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10068 std::uint8_t len{};
10069 return get_number(input_format_t::msgpack, len) &&
10070 get_binary(input_format_t::msgpack, len, result);
10075 std::uint16_t len{};
10076 return get_number(input_format_t::msgpack, len) &&
10077 get_binary(input_format_t::msgpack, len, result);
10082 std::uint32_t len{};
10083 return get_number(input_format_t::msgpack, len) &&
10084 get_binary(input_format_t::msgpack, len, result);
10089 std::uint8_t len{};
10090 std::int8_t subtype{};
10091 return get_number(input_format_t::msgpack, len) &&
10092 get_number(input_format_t::msgpack, subtype) &&
10093 get_binary(input_format_t::msgpack, len, result) &&
10094 assign_and_return_true(subtype);
10099 std::uint16_t len{};
10100 std::int8_t subtype{};
10101 return get_number(input_format_t::msgpack, len) &&
10102 get_number(input_format_t::msgpack, subtype) &&
10103 get_binary(input_format_t::msgpack, len, result) &&
10104 assign_and_return_true(subtype);
10109 std::uint32_t len{};
10110 std::int8_t subtype{};
10111 return get_number(input_format_t::msgpack, len) &&
10112 get_number(input_format_t::msgpack, subtype) &&
10113 get_binary(input_format_t::msgpack, len, result) &&
10114 assign_and_return_true(subtype);
10119 std::int8_t subtype{};
10120 return get_number(input_format_t::msgpack, subtype) &&
10121 get_binary(input_format_t::msgpack, 1, result) &&
10122 assign_and_return_true(subtype);
10127 std::int8_t subtype{};
10128 return get_number(input_format_t::msgpack, subtype) &&
10129 get_binary(input_format_t::msgpack, 2, result) &&
10130 assign_and_return_true(subtype);
10135 std::int8_t subtype{};
10136 return get_number(input_format_t::msgpack, subtype) &&
10137 get_binary(input_format_t::msgpack, 4, result) &&
10138 assign_and_return_true(subtype);
10143 std::int8_t subtype{};
10144 return get_number(input_format_t::msgpack, subtype) &&
10145 get_binary(input_format_t::msgpack, 8, result) &&
10146 assign_and_return_true(subtype);
10151 std::int8_t subtype{};
10152 return get_number(input_format_t::msgpack, subtype) &&
10153 get_binary(input_format_t::msgpack, 16, result) &&
10154 assign_and_return_true(subtype);
10168 if (JSON_HEDLEY_UNLIKELY(!
sax->start_array(len)))
10173 for (std::size_t i = 0; i < len; ++i)
10181 return sax->end_array();
10190 if (JSON_HEDLEY_UNLIKELY(!
sax->start_object(len)))
10197 for (std::size_t i = 0; i < len; ++i)
10214 return sax->end_object();
10254 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::ubjson,
"value")))
10263 std::uint8_t len{};
10264 return get_number(input_format_t::ubjson, len) &&
get_string(input_format_t::ubjson, len, result);
10270 return get_number(input_format_t::ubjson, len) &&
get_string(input_format_t::ubjson, len, result);
10275 std::int16_t len{};
10276 return get_number(input_format_t::ubjson, len) &&
get_string(input_format_t::ubjson, len, result);
10281 std::int32_t len{};
10282 return get_number(input_format_t::ubjson, len) &&
get_string(input_format_t::ubjson, len, result);
10287 std::int64_t len{};
10288 return get_number(input_format_t::ubjson, len) &&
get_string(input_format_t::ubjson, len, result);
10293 return sax->parse_error(
chars_read, last_token,
parse_error::create(113,
chars_read,
exception_message(input_format_t::ubjson,
"expected length type specification (U, i, I, l, L); last byte: 0x" + last_token,
"string"), BasicJsonType()));
10307 std::uint8_t number{};
10309 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10314 result =
static_cast<std::size_t
>(number);
10320 std::int8_t number{};
10322 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10327 result =
static_cast<std::size_t
>(number);
10333 std::int16_t number{};
10335 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10340 result =
static_cast<std::size_t
>(number);
10346 std::int32_t number{};
10348 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10353 result =
static_cast<std::size_t
>(number);
10359 std::int64_t number{};
10361 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10366 result =
static_cast<std::size_t
>(number);
10373 return sax->parse_error(
chars_read, last_token,
parse_error::create(113,
chars_read,
exception_message(input_format_t::ubjson,
"expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token,
"size"), BasicJsonType()));
10390 result.first = string_t::npos;
10396 result.second =
get();
10398 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::ubjson,
"type")))
10405 if (JSON_HEDLEY_UNLIKELY(
current !=
'#'))
10407 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::ubjson,
"value")))
10435 case std::char_traits<char_type>::eof():
10439 return sax->boolean(
true);
10442 return sax->boolean(
false);
10445 return sax->null();
10449 std::uint8_t number{};
10450 return get_number(input_format_t::ubjson, number) &&
sax->number_unsigned(number);
10455 std::int8_t number{};
10456 return get_number(input_format_t::ubjson, number) &&
sax->number_integer(number);
10461 std::int16_t number{};
10462 return get_number(input_format_t::ubjson, number) &&
sax->number_integer(number);
10467 std::int32_t number{};
10468 return get_number(input_format_t::ubjson, number) &&
sax->number_integer(number);
10473 std::int64_t number{};
10474 return get_number(input_format_t::ubjson, number) &&
sax->number_integer(number);
10480 return get_number(input_format_t::ubjson, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
10486 return get_number(input_format_t::ubjson, number) &&
sax->number_float(
static_cast<number_float_t
>(number),
"");
10491 return get_ubjson_high_precision_number();
10498 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::ubjson,
"char")))
10503 if (JSON_HEDLEY_UNLIKELY(
current > 127))
10509 string_t s(1,
static_cast<typename string_t::value_type
>(
current));
10510 return sax->string(s);
10538 std::pair<std::size_t, char_int_type> size_and_type;
10545 if (size_and_type.first != string_t::npos)
10547 if (JSON_HEDLEY_UNLIKELY(!
sax->start_array(size_and_type.first)))
10552 if (size_and_type.second != 0)
10554 if (size_and_type.second !=
'N')
10556 for (std::size_t i = 0; i < size_and_type.first; ++i)
10568 for (std::size_t i = 0; i < size_and_type.first; ++i)
10580 if (JSON_HEDLEY_UNLIKELY(!
sax->start_array(std::size_t(-1))))
10596 return sax->end_array();
10604 std::pair<std::size_t, char_int_type> size_and_type;
10613 if (size_and_type.first != string_t::npos)
10615 if (JSON_HEDLEY_UNLIKELY(!
sax->start_object(size_and_type.first)))
10620 if (size_and_type.second != 0)
10622 for (std::size_t i = 0; i < size_and_type.first; ++i)
10640 for (std::size_t i = 0; i < size_and_type.first; ++i)
10659 if (JSON_HEDLEY_UNLIKELY(!
sax->start_object(std::size_t(-1))))
10681 return sax->end_object();
10687 bool get_ubjson_high_precision_number()
10690 std::size_t size{};
10693 if (JSON_HEDLEY_UNLIKELY(!res))
10699 std::vector<char> number_vector;
10701 for (std::size_t i = 0; i < size; ++i)
10705 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(input_format_t::ubjson,
"number")))
10710 number_vector.push_back(
static_cast<char>(
current));
10714 using ia_type =
decltype(detail::input_adapter(number_vector));
10715 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
10716 const auto result_number = number_lexer.scan();
10717 const auto number_string = number_lexer.get_token_string();
10718 const auto result_remainder = number_lexer.scan();
10721 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10726 switch (result_number)
10728 case token_type::value_integer:
10729 return sax->number_integer(number_lexer.get_number_integer());
10731 case token_type::value_unsigned:
10732 return sax->number_unsigned(number_lexer.get_number_unsigned());
10734 case token_type::value_float:
10735 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10737 case token_type::uninitialized:
10738 case token_type::literal_true:
10739 case token_type::literal_false:
10740 case token_type::literal_null:
10741 case token_type::value_string:
10742 case token_type::begin_array:
10743 case token_type::begin_object:
10744 case token_type::end_array:
10745 case token_type::end_object:
10746 case token_type::name_separator:
10747 case token_type::value_separator:
10748 case token_type::parse_error:
10749 case token_type::end_of_input:
10750 case token_type::literal_or_value:
10802 template<
typename NumberType,
bool InputIsLittleEndian = false>
10803 bool get_number(
const input_format_t format, NumberType &result)
10806 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
10808 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
10812 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(format,
"number")))
10820 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(
current);
10825 vec[i] =
static_cast<std::uint8_t
>(
current);
10830 std::memcpy(&result, vec.data(),
sizeof(NumberType));
10848 template<
typename NumberType>
10850 const NumberType len,
10853 bool success =
true;
10855 for (NumberType i = 0; i < len; i++)
10859 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(format,
"string")))
10865 result.push_back(
static_cast<typename string_t::value_type
>(
current));
10885 template<
typename NumberType>
10887 const NumberType len,
10890 bool success =
true;
10892 for (NumberType i = 0; i < len; i++)
10896 if (JSON_HEDLEY_UNLIKELY(!
unexpect_eof(format,
"binary")))
10902 result.push_back(
static_cast<std::uint8_t
>(
current));
10913 JSON_HEDLEY_NON_NULL(3)
10916 if (JSON_HEDLEY_UNLIKELY(
current == std::char_traits<char_type>::eof()))
10930 std::array<char, 3> cr{{}};
10931 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(
current));
10932 return std::string{cr.data()};
10942 const std::string &detail,
10943 const std::string &context)
const
10945 std::string error_msg =
"syntax error while parsing ";
10949 case input_format_t::cbor:
10950 error_msg +=
"CBOR";
10953 case input_format_t::msgpack:
10954 error_msg +=
"MessagePack";
10957 case input_format_t::ubjson:
10958 error_msg +=
"UBJSON";
10961 case input_format_t::bson:
10962 error_msg +=
"BSON";
10965 case input_format_t::json:
10967 JSON_ASSERT(
false);
10970 return error_msg +
" " + context +
": " + detail;
10978 char_int_type
current = std::char_traits<char_type>::eof();
11001#include <functional>
11045template<
typename BasicJsonType>
11046using parser_callback_t =
11047 std::function<bool(
int ,
parse_event_t , BasicJsonType & )>;
11054template<
typename BasicJsonType,
typename InputAdapterType>
11057 using number_integer_t =
typename BasicJsonType::number_integer_t;
11058 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
11059 using number_float_t =
typename BasicJsonType::number_float_t;
11060 using string_t =
typename BasicJsonType::string_t;
11062 using token_type =
typename lexer_t::token_type;
11067 const parser_callback_t<BasicJsonType> cb =
nullptr,
11068 const bool allow_exceptions_ =
true,
11069 const bool skip_comments =
false)
11071 ,
m_lexer(
std::move(adapter), skip_comments)
11088 void parse(
const bool strict, BasicJsonType &result)
11093 sax_parse_internal(&sdp);
11101 exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
11105 if (sdp.is_errored())
11113 if (result.is_discarded())
11122 sax_parse_internal(&sdp);
11133 if (sdp.is_errored())
11140 result.assert_invariant();
11152 return sax_parse(&sax_acceptor,
strict);
11155 template<
typename SAX>
11156 JSON_HEDLEY_NON_NULL(2)
11157 bool sax_parse(SAX *sax, const
bool strict = true)
11160 const bool result = sax_parse_internal(sax);
11163 if (result && strict && (
get_token() != token_type::end_of_input))
11174 template<
typename SAX>
11175 JSON_HEDLEY_NON_NULL(2)
11176 bool sax_parse_internal(SAX *sax)
11180 std::vector<bool> states;
11182 bool skip_to_state_evaluation =
false;
11186 if (!skip_to_state_evaluation)
11191 case token_type::begin_object:
11193 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
11199 if (
get_token() == token_type::end_object)
11201 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11210 if (JSON_HEDLEY_UNLIKELY(
last_token != token_type::value_string))
11223 if (JSON_HEDLEY_UNLIKELY(
get_token() != token_type::name_separator))
11231 states.push_back(
false);
11237 case token_type::begin_array:
11239 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
11245 if (
get_token() == token_type::end_array)
11247 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11256 states.push_back(
true);
11261 case token_type::value_float:
11265 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
11280 case token_type::literal_false:
11282 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
11290 case token_type::literal_null:
11292 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
11300 case token_type::literal_true:
11302 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
11310 case token_type::value_integer:
11320 case token_type::value_string:
11330 case token_type::value_unsigned:
11340 case token_type::parse_error:
11348 case token_type::uninitialized:
11349 case token_type::end_array:
11350 case token_type::end_object:
11351 case token_type::name_separator:
11352 case token_type::value_separator:
11353 case token_type::end_of_input:
11354 case token_type::literal_or_value:
11366 skip_to_state_evaluation =
false;
11370 if (states.empty())
11379 if (
get_token() == token_type::value_separator)
11387 if (JSON_HEDLEY_LIKELY(
last_token == token_type::end_array))
11389 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11398 JSON_ASSERT(!states.empty());
11400 skip_to_state_evaluation =
true;
11412 if (
get_token() == token_type::value_separator)
11415 if (JSON_HEDLEY_UNLIKELY(
get_token() != token_type::value_string))
11428 if (JSON_HEDLEY_UNLIKELY(
get_token() != token_type::name_separator))
11441 if (JSON_HEDLEY_LIKELY(
last_token == token_type::end_object))
11443 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11452 JSON_ASSERT(!states.empty());
11454 skip_to_state_evaluation =
true;
11470 std::string exception_message(
const token_type expected,
const std::string &context)
11472 std::string error_msg =
"syntax error ";
11474 if (!context.empty())
11476 error_msg +=
"while parsing " + context +
" ";
11492 if (expected != token_type::uninitialized)
11542 using difference_type = std::ptrdiff_t;
11543 static constexpr difference_type begin_value = 0;
11544 static constexpr difference_type end_value = begin_value + 1;
11546JSON_PRIVATE_UNLESS_TESTED:
11548 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11551 constexpr difference_type get_value()
const noexcept
11559 m_it = begin_value;
11571 return m_it == begin_value;
11577 return m_it == end_value;
11582 return lhs.m_it == rhs.m_it;
11585 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
11587 return lhs.m_it < rhs.m_it;
11590 primitive_iterator_t operator+(difference_type n)
noexcept
11592 auto result = *
this;
11597 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
11599 return lhs.m_it - rhs.m_it;
11602 primitive_iterator_t &operator++() noexcept
11608 primitive_iterator_t
const operator++(
int)
noexcept
11610 auto result = *
this;
11615 primitive_iterator_t &operator--() noexcept
11621 primitive_iterator_t
const operator--(
int)
noexcept
11623 auto result = *
this;
11628 primitive_iterator_t &operator+=(difference_type n)
noexcept
11634 primitive_iterator_t &operator-=(difference_type n)
noexcept
11670#include <type_traits>
11692template<
typename IteratorType>
class iteration_proxy;
11693template<
typename IteratorType>
class iteration_proxy_value;
11711template<
typename BasicJsonType>
11718 friend BasicJsonType;
11722 using object_t =
typename BasicJsonType::object_t;
11723 using array_t =
typename BasicJsonType::array_t;
11726 "iter_impl only accepts (const) basic_json");
11742 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
11743 typename BasicJsonType::const_pointer,
11744 typename BasicJsonType::pointer>::type;
11747 typename std::conditional<std::is_const<BasicJsonType>::value,
11748 typename BasicJsonType::const_reference,
11749 typename BasicJsonType::reference>::type;
11764 JSON_ASSERT(m_object !=
nullptr);
11766 switch (m_object->m_type)
11813 : m_object(other.m_object),
m_it(other.m_it)
11824 if (&other !=
this)
11826 m_object = other.m_object;
11839 : m_object(other.m_object),
m_it(other.m_it)
11850 m_object = other.m_object;
11855JSON_PRIVATE_UNLESS_TESTED:
11860 void set_begin() noexcept
11862 JSON_ASSERT(m_object !=
nullptr);
11864 switch (m_object->m_type)
11906 JSON_ASSERT(m_object !=
nullptr);
11908 switch (m_object->m_type)
11945 JSON_ASSERT(m_object !=
nullptr);
11947 switch (m_object->m_type)
11962 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11978 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11989 JSON_ASSERT(m_object !=
nullptr);
11991 switch (m_object->m_type)
12020 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12031 auto result = *
this;
12042 JSON_ASSERT(m_object !=
nullptr);
12044 switch (m_object->m_type)
12082 auto result = *
this;
12093 JSON_ASSERT(m_object !=
nullptr);
12095 switch (m_object->m_type)
12131 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 >
12135 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
12137 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
12140 JSON_ASSERT(m_object !=
nullptr);
12142 switch (m_object->m_type)
12167 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 >
12180 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
12182 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
12185 JSON_ASSERT(m_object !=
nullptr);
12187 switch (m_object->m_type)
12190 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
12214 return !other.operator < (*this);
12241 JSON_ASSERT(m_object !=
nullptr);
12243 switch (m_object->m_type)
12246 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12287 auto result = *
this;
12309 auto result = *
this;
12320 JSON_ASSERT(m_object !=
nullptr);
12322 switch (m_object->m_type)
12325 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12349 JSON_ASSERT(m_object !=
nullptr);
12351 switch (m_object->m_type)
12354 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
12360 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12376 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12385 const typename object_t::key_type &
key()
const
12387 JSON_ASSERT(m_object !=
nullptr);
12389 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
12394 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
12406JSON_PRIVATE_UNLESS_TESTED:
12450template<
typename Base>
12454 using difference_type = std::ptrdiff_t;
12524 auto it = --this->base();
12531 auto it = --this->base();
12532 return it.operator * ();
12543#include <algorithm>
12562template<
typename BasicJsonType>
12566 NLOHMANN_BASIC_JSON_TPL_DECLARATION
12592 : reference_tokens(
split(s))
12611 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12613 [](
const std::string & a,
const std::string & b)
12615 return a +
"/" + detail::escape(b);
12620 operator std::string()
const
12643 reference_tokens.insert(reference_tokens.end(),
12644 ptr.reference_tokens.begin(),
12645 ptr.reference_tokens.end());
12689 return *
this /= std::to_string(array_idx);
12793 if (JSON_HEDLEY_UNLIKELY(
empty()))
12795 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12798 reference_tokens.pop_back();
12817 if (JSON_HEDLEY_UNLIKELY(
empty()))
12819 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12822 return reference_tokens.back();
12839 reference_tokens.push_back(token);
12845 reference_tokens.push_back(std::move(token));
12864 return reference_tokens.empty();
12878 static typename BasicJsonType::size_type
array_index(
const std::string &s)
12880 using size_type =
typename BasicJsonType::size_type;
12883 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
12889 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
12894 std::size_t processed_chars = 0;
12895 unsigned long long res = 0;
12898 res = std::stoull(s, &processed_chars);
12900 JSON_CATCH(std::out_of_range &)
12902 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12906 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12908 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12913 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
12915 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type", BasicJsonType()));
12918 return static_cast<size_type
>(res);
12921JSON_PRIVATE_UNLESS_TESTED:
12924 if (JSON_HEDLEY_UNLIKELY(
empty()))
12926 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12930 result.reference_tokens = {reference_tokens[0]};
12949 for (
const auto &reference_token : reference_tokens)
12951 switch (result->type())
12955 if (reference_token ==
"0")
12958 result = &result->operator[](0);
12964 result = &result->operator[](reference_token);
12973 result = &result->operator[](reference_token);
12980 result = &result->operator[](
array_index(reference_token));
12998 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", j));
13026 for (
const auto &reference_token : reference_tokens)
13029 if (ptr->is_null())
13033 std::all_of(reference_token.begin(), reference_token.end(),
13034 [](
const unsigned char x)
13036 return std::isdigit(x);
13039 *ptr = (nums || reference_token ==
"-")
13044 switch (ptr->type())
13049 ptr = &ptr->operator[](reference_token);
13055 if (reference_token ==
"-")
13058 ptr = &ptr->operator[](ptr->m_value.array->size());
13064 ptr = &ptr->operator[](
array_index(reference_token));
13079 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13094 for (
const auto &reference_token : reference_tokens)
13096 switch (ptr->type())
13101 ptr = &ptr->at(reference_token);
13107 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13110 JSON_THROW(detail::out_of_range::create(402,
13111 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
13112 ") is out of range", *ptr));
13129 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13151 for (
const auto &reference_token : reference_tokens)
13153 switch (ptr->type())
13158 ptr = &ptr->operator[](reference_token);
13164 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13167 JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", *ptr));
13171 ptr = &ptr->operator[](
array_index(reference_token));
13184 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13199 for (
const auto &reference_token : reference_tokens)
13201 switch (ptr->type())
13206 ptr = &ptr->at(reference_token);
13212 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13215 JSON_THROW(detail::out_of_range::create(402,
13216 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
13217 ") is out of range", *ptr));
13234 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13247 for (
const auto &reference_token : reference_tokens)
13249 switch (ptr->type())
13253 if (!ptr->contains(reference_token))
13259 ptr = &ptr->operator[](reference_token);
13265 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13271 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
13277 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
13279 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
13285 for (std::size_t i = 1; i < reference_token.size(); i++)
13287 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
13297 if (idx >= ptr->size())
13303 ptr = &ptr->operator[](idx);
13337 static std::vector<std::string>
split(
const std::string &reference_string)
13339 std::vector<std::string> result;
13342 if (reference_string.empty())
13348 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
13350 JSON_THROW(
detail::parse_error::create(107, 1,
"JSON pointer must be empty or begin with '/' - was: '" + reference_string +
"'", BasicJsonType()));
13358 std::size_t slash = reference_string.find_first_of(
'/', 1),
13365 start = (slash == std::string::npos) ? 0 : slash + 1,
13367 slash = reference_string.find_first_of(
'/', start))
13371 auto reference_token = reference_string.substr(start, slash - start);
13374 for (std::size_t pos = reference_token.find_first_of(
'~');
13375 pos != std::string::npos;
13376 pos = reference_token.find_first_of(
'~', pos + 1))
13378 JSON_ASSERT(reference_token[pos] ==
'~');
13381 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
13382 (reference_token[pos + 1] !=
'0' &&
13383 reference_token[pos + 1] !=
'1')))
13391 result.push_back(reference_token);
13405 static void flatten(
const std::string &reference_string,
13406 const BasicJsonType &value,
13407 BasicJsonType &result)
13409 switch (value.type())
13413 if (value.m_value.array->empty())
13416 result[reference_string] =
nullptr;
13422 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
13424 flatten(reference_string +
"/" + std::to_string(i),
13425 value.m_value.array->operator[](i), result);
13434 if (value.m_value.object->empty())
13437 result[reference_string] =
nullptr;
13443 for (
const auto &element : *value.m_value.object)
13463 result[reference_string] = value;
13479 static BasicJsonType
13482 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
13484 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", value));
13487 BasicJsonType result;
13490 for (
const auto &element : *value.m_value.object)
13492 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
13494 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", element.second));
13501 json_pointer(element.first).get_and_create(result) = element.second;
13521 return lhs.reference_tokens == rhs.reference_tokens;
13538 return !(lhs == rhs);
13549#include <initializer_list>
13559template<
typename BasicJsonType>
13563 using value_type = BasicJsonType;
13566 : owned_value(std::move(
value))
13570 : value_ref(&
value)
13573 json_ref(std::initializer_list<json_ref> init)
13574 : owned_value(init)
13579 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
13581 : owned_value(std::forward<Args>(args)...)
13591 value_type moved_or_copied()
const
13593 if (value_ref ==
nullptr)
13595 return std::move(owned_value);
13601 value_type
const &operator*()
const
13603 return value_ref ? *value_ref : owned_value;
13606 value_type
const *operator->()
const
13612 mutable value_type owned_value =
nullptr;
13613 value_type
const *value_ref =
nullptr;
13629#include <algorithm>
13645#include <algorithm>
13667 virtual void write_character(CharType c) = 0;
13668 virtual void write_characters(
const CharType *s, std::size_t length) = 0;
13679template<
typename CharType>
13683template<
typename CharType,
typename AllocatorType = std::allocator<CharType>>
13691 void write_character(CharType c)
override
13696 JSON_HEDLEY_NON_NULL(2)
13697 void write_characters(
const CharType *s, std::size_t length)
override
13699 std::copy(s, s + length, std::back_inserter(v));
13703 std::vector<CharType, AllocatorType> &v;
13708template<
typename CharType>
13716 void write_character(CharType c)
override
13721 JSON_HEDLEY_NON_NULL(2)
13722 void write_characters(
const CharType *s, std::size_t length)
override
13724 stream.write(s,
static_cast<std::streamsize
>(length));
13728 std::basic_ostream<CharType> &stream;
13733template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13741 void write_character(CharType c)
override
13746 JSON_HEDLEY_NON_NULL(2)
13747 void write_characters(
const CharType *s, std::size_t length)
override
13749 str.append(s, length);
13756template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13760 template<
typename AllocatorType = std::allocator<CharType>>
13795template<
typename BasicJsonType,
typename CharType>
13798 using string_t =
typename BasicJsonType::string_t;
13799 using binary_t =
typename BasicJsonType::binary_t;
13800 using number_float_t =
typename BasicJsonType::number_float_t;
13838 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
13852 oa->write_character(to_char_type(0xF6));
13858 oa->write_character(j.m_value.boolean
13859 ? to_char_type(0xF5)
13860 : to_char_type(0xF4));
13866 if (j.m_value.number_integer >= 0)
13871 if (j.m_value.number_integer <= 0x17)
13873 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13876 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13878 oa->write_character(to_char_type(0x18));
13879 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13882 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13884 oa->write_character(to_char_type(0x19));
13885 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13888 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13890 oa->write_character(to_char_type(0x1A));
13891 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13896 oa->write_character(to_char_type(0x1B));
13897 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13905 const auto positive_number = -1 - j.m_value.number_integer;
13907 if (j.m_value.number_integer >= -24)
13909 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
13912 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13914 oa->write_character(to_char_type(0x38));
13915 write_number(
static_cast<std::uint8_t
>(positive_number));
13918 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13920 oa->write_character(to_char_type(0x39));
13921 write_number(
static_cast<std::uint16_t
>(positive_number));
13924 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13926 oa->write_character(to_char_type(0x3A));
13927 write_number(
static_cast<std::uint32_t
>(positive_number));
13932 oa->write_character(to_char_type(0x3B));
13933 write_number(
static_cast<std::uint64_t
>(positive_number));
13942 if (j.m_value.number_unsigned <= 0x17)
13944 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13947 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13949 oa->write_character(to_char_type(0x18));
13950 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13953 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13955 oa->write_character(to_char_type(0x19));
13956 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
13959 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13961 oa->write_character(to_char_type(0x1A));
13962 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
13967 oa->write_character(to_char_type(0x1B));
13968 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
13976 if (std::isnan(j.m_value.number_float))
13979 oa->write_character(to_char_type(0xF9));
13980 oa->write_character(to_char_type(0x7E));
13981 oa->write_character(to_char_type(0x00));
13984 else if (std::isinf(j.m_value.number_float))
13987 oa->write_character(to_char_type(0xf9));
13988 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13989 oa->write_character(to_char_type(0x00));
13994 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
14003 const auto N = j.m_value.string->size();
14007 write_number(
static_cast<std::uint8_t
>(0x60 + N));
14010 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14012 oa->write_character(to_char_type(0x78));
14013 write_number(
static_cast<std::uint8_t
>(N));
14016 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14018 oa->write_character(to_char_type(0x79));
14019 write_number(
static_cast<std::uint16_t
>(N));
14022 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14024 oa->write_character(to_char_type(0x7A));
14025 write_number(
static_cast<std::uint32_t
>(N));
14029 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
14031 oa->write_character(to_char_type(0x7B));
14032 write_number(
static_cast<std::uint64_t
>(N));
14037 oa->write_characters(
14038 reinterpret_cast<const CharType *
>(j.m_value.string->c_str()),
14039 j.m_value.string->size());
14046 const auto N = j.m_value.array->size();
14050 write_number(
static_cast<std::uint8_t
>(0x80 + N));
14053 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14055 oa->write_character(to_char_type(0x98));
14056 write_number(
static_cast<std::uint8_t
>(N));
14059 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14061 oa->write_character(to_char_type(0x99));
14062 write_number(
static_cast<std::uint16_t
>(N));
14065 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14067 oa->write_character(to_char_type(0x9A));
14068 write_number(
static_cast<std::uint32_t
>(N));
14072 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
14074 oa->write_character(to_char_type(0x9B));
14075 write_number(
static_cast<std::uint64_t
>(N));
14081 for (
const auto &el : *j.m_value.array)
14091 if (j.m_value.binary->has_subtype())
14093 if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
14095 write_number(
static_cast<std::uint8_t
>(0xd8));
14096 write_number(
static_cast<std::uint8_t
>(j.m_value.binary->subtype()));
14099 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
14101 write_number(
static_cast<std::uint8_t
>(0xd9));
14102 write_number(
static_cast<std::uint16_t
>(j.m_value.binary->subtype()));
14105 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
14107 write_number(
static_cast<std::uint8_t
>(0xda));
14108 write_number(
static_cast<std::uint32_t
>(j.m_value.binary->subtype()));
14111 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
14113 write_number(
static_cast<std::uint8_t
>(0xdb));
14114 write_number(
static_cast<std::uint64_t
>(j.m_value.binary->subtype()));
14119 const auto N = j.m_value.binary->size();
14123 write_number(
static_cast<std::uint8_t
>(0x40 + N));
14126 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14128 oa->write_character(to_char_type(0x58));
14129 write_number(
static_cast<std::uint8_t
>(N));
14132 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14134 oa->write_character(to_char_type(0x59));
14135 write_number(
static_cast<std::uint16_t
>(N));
14138 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14140 oa->write_character(to_char_type(0x5A));
14141 write_number(
static_cast<std::uint32_t
>(N));
14145 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
14147 oa->write_character(to_char_type(0x5B));
14148 write_number(
static_cast<std::uint64_t
>(N));
14153 oa->write_characters(
14154 reinterpret_cast<const CharType *
>(j.m_value.binary->data()),
14162 const auto N = j.m_value.object->size();
14166 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
14169 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14171 oa->write_character(to_char_type(0xB8));
14172 write_number(
static_cast<std::uint8_t
>(N));
14175 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14177 oa->write_character(to_char_type(0xB9));
14178 write_number(
static_cast<std::uint16_t
>(N));
14181 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14183 oa->write_character(to_char_type(0xBA));
14184 write_number(
static_cast<std::uint32_t
>(N));
14188 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
14190 oa->write_character(to_char_type(0xBB));
14191 write_number(
static_cast<std::uint64_t
>(N));
14197 for (
const auto &el : *j.m_value.object)
14221 oa->write_character(to_char_type(0xC0));
14227 oa->write_character(j.m_value.boolean
14228 ? to_char_type(0xC3)
14229 : to_char_type(0xC2));
14235 if (j.m_value.number_integer >= 0)
14240 if (j.m_value.number_unsigned < 128)
14243 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14246 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14249 oa->write_character(to_char_type(0xCC));
14250 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14253 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14256 oa->write_character(to_char_type(0xCD));
14257 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14260 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14263 oa->write_character(to_char_type(0xCE));
14264 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14267 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14270 oa->write_character(to_char_type(0xCF));
14271 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14277 if (j.m_value.number_integer >= -32)
14280 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14283 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
14284 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14287 oa->write_character(to_char_type(0xD0));
14288 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14291 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
14292 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14295 oa->write_character(to_char_type(0xD1));
14296 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
14299 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
14300 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14303 oa->write_character(to_char_type(0xD2));
14304 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
14307 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
14308 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14311 oa->write_character(to_char_type(0xD3));
14312 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
14321 if (j.m_value.number_unsigned < 128)
14324 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14327 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14330 oa->write_character(to_char_type(0xCC));
14331 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14334 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14337 oa->write_character(to_char_type(0xCD));
14338 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14341 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14344 oa->write_character(to_char_type(0xCE));
14345 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14348 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14351 oa->write_character(to_char_type(0xCF));
14352 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14360 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
14367 const auto N = j.m_value.string->size();
14372 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
14375 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14378 oa->write_character(to_char_type(0xD9));
14379 write_number(
static_cast<std::uint8_t
>(N));
14382 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14385 oa->write_character(to_char_type(0xDA));
14386 write_number(
static_cast<std::uint16_t
>(N));
14389 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14392 oa->write_character(to_char_type(0xDB));
14393 write_number(
static_cast<std::uint32_t
>(N));
14397 oa->write_characters(
14398 reinterpret_cast<const CharType *
>(j.m_value.string->c_str()),
14399 j.m_value.string->size());
14406 const auto N = j.m_value.array->size();
14411 write_number(
static_cast<std::uint8_t
>(0x90 | N));
14414 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14417 oa->write_character(to_char_type(0xDC));
14418 write_number(
static_cast<std::uint16_t
>(N));
14421 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14424 oa->write_character(to_char_type(0xDD));
14425 write_number(
static_cast<std::uint32_t
>(N));
14429 for (
const auto &el : *j.m_value.array)
14441 const bool use_ext = j.m_value.binary->has_subtype();
14443 const auto N = j.m_value.binary->size();
14445 if (N <= (std::numeric_limits<std::uint8_t>::max)())
14447 std::uint8_t output_type{};
14455 output_type = 0xD4;
14459 output_type = 0xD5;
14463 output_type = 0xD6;
14467 output_type = 0xD7;
14471 output_type = 0xD8;
14475 output_type = 0xC7;
14483 output_type = 0xC4;
14487 oa->write_character(to_char_type(output_type));
14491 write_number(
static_cast<std::uint8_t
>(N));
14495 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14497 std::uint8_t output_type = use_ext
14500 oa->write_character(to_char_type(output_type));
14501 write_number(
static_cast<std::uint16_t
>(N));
14504 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14506 std::uint8_t output_type = use_ext
14509 oa->write_character(to_char_type(output_type));
14510 write_number(
static_cast<std::uint32_t
>(N));
14516 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
14520 oa->write_characters(
14521 reinterpret_cast<const CharType *
>(j.m_value.binary->data()),
14529 const auto N = j.m_value.object->size();
14534 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
14537 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14540 oa->write_character(to_char_type(0xDE));
14541 write_number(
static_cast<std::uint16_t
>(N));
14544 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14547 oa->write_character(to_char_type(0xDF));
14548 write_number(
static_cast<std::uint32_t
>(N));
14552 for (
const auto &el : *j.m_value.object)
14574 const bool use_type,
const bool add_prefix =
true)
14582 oa->write_character(to_char_type(
'Z'));
14592 oa->write_character(j.m_value.boolean
14593 ? to_char_type(
'T')
14594 : to_char_type(
'F'));
14602 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
14608 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
14614 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
14622 oa->write_character(to_char_type(
'S'));
14625 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
14626 oa->write_characters(
14627 reinterpret_cast<const CharType *
>(j.m_value.string->c_str()),
14628 j.m_value.string->size());
14636 oa->write_character(to_char_type(
'['));
14639 bool prefix_required =
true;
14641 if (use_type && !j.m_value.array->empty())
14643 JSON_ASSERT(use_count);
14645 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
14646 [
this, first_prefix](
const BasicJsonType & v)
14648 return ubjson_prefix(v) == first_prefix;
14653 prefix_required =
false;
14654 oa->write_character(to_char_type(
'$'));
14655 oa->write_character(first_prefix);
14661 oa->write_character(to_char_type(
'#'));
14662 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
14665 for (
const auto &el : *j.m_value.array)
14667 write_ubjson(el, use_count, use_type, prefix_required);
14672 oa->write_character(to_char_type(
']'));
14682 oa->write_character(to_char_type(
'['));
14685 if (use_type && !j.m_value.binary->empty())
14687 JSON_ASSERT(use_count);
14688 oa->write_character(to_char_type(
'$'));
14689 oa->write_character(
'U');
14694 oa->write_character(to_char_type(
'#'));
14695 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
14700 oa->write_characters(
14701 reinterpret_cast<const CharType *
>(j.m_value.binary->data()),
14702 j.m_value.binary->size());
14707 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
14709 oa->write_character(to_char_type(
'U'));
14710 oa->write_character(j.m_value.binary->data()[i]);
14716 oa->write_character(to_char_type(
']'));
14726 oa->write_character(to_char_type(
'{'));
14729 bool prefix_required =
true;
14731 if (use_type && !j.m_value.object->empty())
14733 JSON_ASSERT(use_count);
14735 const bool same_prefix = std::all_of(j.begin(), j.end(),
14736 [
this, first_prefix](
const BasicJsonType & v)
14738 return ubjson_prefix(v) == first_prefix;
14743 prefix_required =
false;
14744 oa->write_character(to_char_type(
'$'));
14745 oa->write_character(first_prefix);
14751 oa->write_character(to_char_type(
'#'));
14752 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
14755 for (
const auto &el : *j.m_value.object)
14757 write_number_with_ubjson_prefix(el.first.size(),
true);
14758 oa->write_characters(
14759 reinterpret_cast<const CharType *
>(el.first.c_str()),
14761 write_ubjson(el.second, use_count, use_type, prefix_required);
14766 oa->write_character(to_char_type(
'}'));
14789 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
14791 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14793 JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")", j));
14794 static_cast<void>(j);
14797 return 1ul + name.size() + 1u;
14804 const std::uint8_t element_type)
14806 oa->write_character(to_char_type(element_type));
14807 oa->write_characters(
14808 reinterpret_cast<const CharType *
>(name.c_str()),
14819 oa->write_character(
value ? to_char_type(0x01) : to_char_type(0x00));
14826 const double value)
14829 write_number<double, true>(
value);
14837 return sizeof(std::int32_t) +
value.size() + 1ul;
14844 const string_t &value)
14847 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(
value.size() + 1ul));
14848 oa->write_characters(
14849 reinterpret_cast<const CharType *
>(
value.c_str()),
14866 return (std::numeric_limits<std::int32_t>::min)() <=
value &&
value <= (std::numeric_limits<std::int32_t>::max)()
14867 ?
sizeof(std::int32_t)
14868 :
sizeof(std::int64_t);
14875 const std::int64_t value)
14877 if ((std::numeric_limits<std::int32_t>::min)() <=
value &&
value <= (std::numeric_limits<std::int32_t>::max)())
14880 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(
value));
14886 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(
value));
14895 return (
value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14896 ?
sizeof(std::int32_t)
14897 :
sizeof(std::int64_t);
14904 const BasicJsonType &j)
14906 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14909 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(j.m_value.number_unsigned));
14912 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14915 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(j.m_value.number_unsigned));
14920 JSON_THROW(out_of_range::create(407,
"integer number " + std::to_string(j.m_value.number_unsigned) +
" cannot be represented by BSON as it does not fit int64", j));
14928 const typename BasicJsonType::object_t &value)
14939 std::size_t array_index = 0ul;
14940 const std::size_t embedded_document_size = std::accumulate(std::begin(
value), std::end(
value), std::size_t(0), [&array_index](std::size_t result,
const typename BasicJsonType::array_t::value_type & el)
14944 return sizeof(std::int32_t) + embedded_document_size + 1ul;
14952 return sizeof(std::int32_t) +
value.size() + 1ul;
14959 const typename BasicJsonType::array_t &value)
14963 std::size_t array_index = 0ul;
14965 for (
const auto &el :
value)
14970 oa->write_character(to_char_type(0x00));
14977 const binary_t &value)
14980 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(
value.size()));
14981 write_number(
value.has_subtype() ?
static_cast<std::uint8_t
>(
value.subtype()) : std::uint8_t(0x00));
14982 oa->write_characters(
reinterpret_cast<const CharType *
>(
value.data()),
value.size());
14990 const BasicJsonType &j)
15006 return header_size + 1ul;
15009 return header_size + 8ul;
15021 return header_size + 0ul;
15026 JSON_ASSERT(
false);
15039 const BasicJsonType &j)
15073 JSON_ASSERT(
false);
15087 std::size_t document_size = std::accumulate(
value.begin(),
value.end(), std::size_t(0),
15088 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
15090 return result += calc_bson_element_size(el.first, el.second);
15092 return sizeof(std::int32_t) + document_size + 1ul;
15103 for (
const auto &el :
value)
15108 oa->write_character(to_char_type(0x00));
15115 static constexpr CharType get_cbor_float_prefix(
float )
15117 return to_char_type(0xFA);
15120 static constexpr CharType get_cbor_float_prefix(
double )
15122 return to_char_type(0xFB);
15129 static constexpr CharType get_msgpack_float_prefix(
float )
15131 return to_char_type(0xCA);
15134 static constexpr CharType get_msgpack_float_prefix(
double )
15136 return to_char_type(0xCB);
15144 template<
typename NumberType,
typename std::enable_if<
15145 std::is_floating_point<NumberType>::value,
int>::type = 0>
15146 void write_number_with_ubjson_prefix(
const NumberType n,
15147 const bool add_prefix)
15151 oa->write_character(get_ubjson_float_prefix(n));
15158 template<
typename NumberType,
typename std::enable_if<
15159 std::is_unsigned<NumberType>::value,
int>::type = 0>
15160 void write_number_with_ubjson_prefix(
const NumberType n,
15161 const bool add_prefix)
15163 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
15167 oa->write_character(to_char_type(
'i'));
15170 write_number(
static_cast<std::uint8_t
>(n));
15173 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
15177 oa->write_character(to_char_type(
'U'));
15180 write_number(
static_cast<std::uint8_t
>(n));
15183 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
15187 oa->write_character(to_char_type(
'I'));
15190 write_number(
static_cast<std::int16_t
>(n));
15193 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
15197 oa->write_character(to_char_type(
'l'));
15200 write_number(
static_cast<std::int32_t
>(n));
15203 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
15207 oa->write_character(to_char_type(
'L'));
15210 write_number(
static_cast<std::int64_t
>(n));
15217 oa->write_character(to_char_type(
'H'));
15220 const auto number = BasicJsonType(n).dump();
15221 write_number_with_ubjson_prefix(number.size(),
true);
15223 for (std::size_t i = 0; i < number.size(); ++i)
15225 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15231 template <
typename NumberType,
typename std::enable_if <
15232 std::is_signed<NumberType>::value &&
15233 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
15234 void write_number_with_ubjson_prefix(
const NumberType n,
15235 const bool add_prefix)
15237 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
15241 oa->write_character(to_char_type(
'i'));
15244 write_number(
static_cast<std::int8_t
>(n));
15247 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)()))
15251 oa->write_character(to_char_type(
'U'));
15254 write_number(
static_cast<std::uint8_t
>(n));
15257 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
15261 oa->write_character(to_char_type(
'I'));
15264 write_number(
static_cast<std::int16_t
>(n));
15267 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
15271 oa->write_character(to_char_type(
'l'));
15274 write_number(
static_cast<std::int32_t
>(n));
15277 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
15281 oa->write_character(to_char_type(
'L'));
15284 write_number(
static_cast<std::int64_t
>(n));
15292 oa->write_character(to_char_type(
'H'));
15295 const auto number = BasicJsonType(n).dump();
15296 write_number_with_ubjson_prefix(number.size(),
true);
15298 for (std::size_t i = 0; i < number.size(); ++i)
15300 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15318 return j.m_value.boolean ?
'T' :
'F';
15322 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)())
15327 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)())
15332 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)())
15337 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)())
15342 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)())
15353 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
15358 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
15363 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
15368 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
15373 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
15383 return get_ubjson_float_prefix(j.m_value.number_float);
15401 static constexpr CharType get_ubjson_float_prefix(
float )
15406 static constexpr CharType get_ubjson_float_prefix(
double )
15426 template<
typename NumberType,
bool OutputIsLittleEndian = false>
15427 void write_number(
const NumberType n)
15430 std::array<CharType,
sizeof(NumberType)> vec{};
15431 std::memcpy(vec.data(), &n,
sizeof(NumberType));
15437 std::reverse(vec.begin(), vec.end());
15440 oa->write_characters(vec.data(),
sizeof(NumberType));
15446#pragma GCC diagnostic push
15447#pragma GCC diagnostic ignored "-Wfloat-equal"
15450 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
15451 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
15452 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
15454 oa->write_character(format == detail::input_format_t::cbor
15455 ? get_cbor_float_prefix(
static_cast<float>(n))
15456 : get_msgpack_float_prefix(
static_cast<float>(n)));
15457 write_number(
static_cast<float>(n));
15462 oa->write_character(format == detail::input_format_t::cbor
15463 ? get_cbor_float_prefix(n)
15464 : get_msgpack_float_prefix(n));
15469#pragma GCC diagnostic pop
15478 template <
typename C = CharType,
15479 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
15480 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
15482 return *
reinterpret_cast<char *
>(&x);
15485 template <
typename C = CharType,
15486 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
15487 static CharType to_char_type(std::uint8_t x)
noexcept
15489 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
15490 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
15492 std::memcpy(&result, &x,
sizeof(x));
15496 template<
typename C = CharType,
15497 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
15498 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
15503 template <
typename InputCharType,
typename C = CharType,
15505 std::is_signed<C>::value &&
15506 std::is_signed<char>::value &&
15507 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
15509 static constexpr CharType to_char_type(InputCharType x)
noexcept
15529#include <algorithm>
15538#include <type_traits>
15549#include <type_traits>
15581template<
typename Target,
typename Source>
15582Target reinterpret_bits(
const Source source)
15584 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
15586 std::memcpy(&target, &source,
sizeof(Source));
15592 static constexpr int kPrecision = 64;
15594 std::uint64_t f = 0;
15597 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
15605 JSON_ASSERT(x.e == y.e);
15606 JSON_ASSERT(x.f >= y.f);
15607 return {x.f - y.f, x.e};
15616 static_assert(kPrecision == 64,
"internal error");
15638 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
15639 const std::uint64_t u_hi = x.f >> 32u;
15640 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
15641 const std::uint64_t v_hi = y.f >> 32u;
15642 const std::uint64_t p0 = u_lo * v_lo;
15643 const std::uint64_t p1 = u_lo * v_hi;
15644 const std::uint64_t p2 = u_hi * v_lo;
15645 const std::uint64_t p3 = u_hi * v_hi;
15646 const std::uint64_t p0_hi = p0 >> 32u;
15647 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
15648 const std::uint64_t p1_hi = p1 >> 32u;
15649 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
15650 const std::uint64_t p2_hi = p2 >> 32u;
15651 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
15660 Q += std::uint64_t{1} << (64u - 32u - 1u);
15661 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
15662 return {h, x.e + y.e + 64};
15671 JSON_ASSERT(x.f != 0);
15673 while ((x.f >> 63u) == 0)
15688 const int delta = x.e - target_exponent;
15689 JSON_ASSERT(delta >= 0);
15690 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15691 return {x.f << delta, target_exponent};
15708template<
typename FloatType>
15711 JSON_ASSERT(std::isfinite(
value));
15712 JSON_ASSERT(
value > 0);
15719 static_assert(std::numeric_limits<FloatType>::is_iec559,
15720 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
15721 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
15722 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
15723 constexpr int kMinExp = 1 - kBias;
15724 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
15725 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
15726 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(
value));
15727 const std::uint64_t E = bits >> (kPrecision - 1);
15728 const std::uint64_t F = bits & (kHiddenBit - 1);
15729 const bool is_denormal = E == 0;
15730 const diyfp v = is_denormal
15731 ?
diyfp(F, kMinExp)
15732 :
diyfp(F + kHiddenBit,
static_cast<int>(E) - kBias);
15753 const bool lower_boundary_is_closer = F == 0 && E > 1;
15754 const diyfp m_plus =
diyfp(2 * v.f + 1, v.e - 1);
15755 const diyfp m_minus = lower_boundary_is_closer
15756 ?
diyfp(4 * v.f - 1, v.e - 2)
15757 :
diyfp(2 * v.f - 1, v.e - 1);
15820constexpr int kAlpha = -60;
15821constexpr int kGamma = -32;
15887 constexpr int kCachedPowersMinDecExp = -300;
15888 constexpr int kCachedPowersDecStep = 8;
15889 static constexpr std::array<cached_power, 79> kCachedPowers =
15892 { 0xAB70FE17C79AC6CA, -1060, -300 },
15893 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15894 { 0xBE5691EF416BD60C, -1007, -284 },
15895 { 0x8DD01FAD907FFC3C, -980, -276 },
15896 { 0xD3515C2831559A83, -954, -268 },
15897 { 0x9D71AC8FADA6C9B5, -927, -260 },
15898 { 0xEA9C227723EE8BCB, -901, -252 },
15899 { 0xAECC49914078536D, -874, -244 },
15900 { 0x823C12795DB6CE57, -847, -236 },
15901 { 0xC21094364DFB5637, -821, -228 },
15902 { 0x9096EA6F3848984F, -794, -220 },
15903 { 0xD77485CB25823AC7, -768, -212 },
15904 { 0xA086CFCD97BF97F4, -741, -204 },
15905 { 0xEF340A98172AACE5, -715, -196 },
15906 { 0xB23867FB2A35B28E, -688, -188 },
15907 { 0x84C8D4DFD2C63F3B, -661, -180 },
15908 { 0xC5DD44271AD3CDBA, -635, -172 },
15909 { 0x936B9FCEBB25C996, -608, -164 },
15910 { 0xDBAC6C247D62A584, -582, -156 },
15911 { 0xA3AB66580D5FDAF6, -555, -148 },
15912 { 0xF3E2F893DEC3F126, -529, -140 },
15913 { 0xB5B5ADA8AAFF80B8, -502, -132 },
15914 { 0x87625F056C7C4A8B, -475, -124 },
15915 { 0xC9BCFF6034C13053, -449, -116 },
15916 { 0x964E858C91BA2655, -422, -108 },
15917 { 0xDFF9772470297EBD, -396, -100 },
15918 { 0xA6DFBD9FB8E5B88F, -369, -92 },
15919 { 0xF8A95FCF88747D94, -343, -84 },
15920 { 0xB94470938FA89BCF, -316, -76 },
15921 { 0x8A08F0F8BF0F156B, -289, -68 },
15922 { 0xCDB02555653131B6, -263, -60 },
15923 { 0x993FE2C6D07B7FAC, -236, -52 },
15924 { 0xE45C10C42A2B3B06, -210, -44 },
15925 { 0xAA242499697392D3, -183, -36 },
15926 { 0xFD87B5F28300CA0E, -157, -28 },
15927 { 0xBCE5086492111AEB, -130, -20 },
15928 { 0x8CBCCC096F5088CC, -103, -12 },
15929 { 0xD1B71758E219652C, -77, -4 },
15930 { 0x9C40000000000000, -50, 4 },
15931 { 0xE8D4A51000000000, -24, 12 },
15932 { 0xAD78EBC5AC620000, 3, 20 },
15933 { 0x813F3978F8940984, 30, 28 },
15934 { 0xC097CE7BC90715B3, 56, 36 },
15935 { 0x8F7E32CE7BEA5C70, 83, 44 },
15936 { 0xD5D238A4ABE98068, 109, 52 },
15937 { 0x9F4F2726179A2245, 136, 60 },
15938 { 0xED63A231D4C4FB27, 162, 68 },
15939 { 0xB0DE65388CC8ADA8, 189, 76 },
15940 { 0x83C7088E1AAB65DB, 216, 84 },
15941 { 0xC45D1DF942711D9A, 242, 92 },
15942 { 0x924D692CA61BE758, 269, 100 },
15943 { 0xDA01EE641A708DEA, 295, 108 },
15944 { 0xA26DA3999AEF774A, 322, 116 },
15945 { 0xF209787BB47D6B85, 348, 124 },
15946 { 0xB454E4A179DD1877, 375, 132 },
15947 { 0x865B86925B9BC5C2, 402, 140 },
15948 { 0xC83553C5C8965D3D, 428, 148 },
15949 { 0x952AB45CFA97A0B3, 455, 156 },
15950 { 0xDE469FBD99A05FE3, 481, 164 },
15951 { 0xA59BC234DB398C25, 508, 172 },
15952 { 0xF6C69A72A3989F5C, 534, 180 },
15953 { 0xB7DCBF5354E9BECE, 561, 188 },
15954 { 0x88FCF317F22241E2, 588, 196 },
15955 { 0xCC20CE9BD35C78A5, 614, 204 },
15956 { 0x98165AF37B2153DF, 641, 212 },
15957 { 0xE2A0B5DC971F303A, 667, 220 },
15958 { 0xA8D9D1535CE3B396, 694, 228 },
15959 { 0xFB9B7CD9A4A7443C, 720, 236 },
15960 { 0xBB764C4CA7A44410, 747, 244 },
15961 { 0x8BAB8EEFB6409C1A, 774, 252 },
15962 { 0xD01FEF10A657842C, 800, 260 },
15963 { 0x9B10A4E5E9913129, 827, 268 },
15964 { 0xE7109BFBA19C0C9D, 853, 276 },
15965 { 0xAC2820D9623BF429, 880, 284 },
15966 { 0x80444B5E7AA7CF85, 907, 292 },
15967 { 0xBF21E44003ACDD2D, 933, 300 },
15968 { 0x8E679C2F5E44FF8F, 960, 308 },
15969 { 0xD433179D9C8CB841, 986, 316 },
15970 { 0x9E19DB92B4E31BA9, 1013, 324 },
15977 JSON_ASSERT(e >= -1500);
15978 JSON_ASSERT(e <= 1500);
15979 const int f = kAlpha - e - 1;
15980 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
15981 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15982 JSON_ASSERT(index >= 0);
15983 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
15984 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
15985 JSON_ASSERT(kAlpha <= cached.e + e + 64);
15986 JSON_ASSERT(kGamma >= cached.e + e + 64);
15997 if (n >= 1000000000)
15999 pow10 = 1000000000;
16004 if (n >= 100000000)
16056inline void grisu2_round(
char *buf,
int len, std::uint64_t dist, std::uint64_t delta,
16057 std::uint64_t rest, std::uint64_t ten_k)
16059 JSON_ASSERT(len >= 1);
16060 JSON_ASSERT(dist <= delta);
16061 JSON_ASSERT(rest <= delta);
16062 JSON_ASSERT(ten_k > 0);
16084 && delta - rest >= ten_k
16085 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
16087 JSON_ASSERT(buf[len - 1] !=
'0');
16100 static_assert(kAlpha >= -60,
"internal error");
16101 static_assert(kGamma <= -32,
"internal error");
16113 JSON_ASSERT(M_plus.e >= kAlpha);
16114 JSON_ASSERT(M_plus.e <= kGamma);
16115 std::uint64_t delta =
diyfp::sub(M_plus, M_minus).f;
16116 std::uint64_t dist =
diyfp::sub(M_plus, w ).f;
16123 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
16124 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
16125 std::uint64_t p2 = M_plus.f & (one.f - 1);
16129 JSON_ASSERT(p1 > 0);
16130 std::uint32_t pow10{};
16157 const std::uint32_t d = p1 / pow10;
16158 const std::uint32_t r = p1 % pow10;
16163 JSON_ASSERT(d <= 9);
16164 buffer[length++] =
static_cast<char>(
'0' + d);
16182 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
16187 decimal_exponent += n;
16197 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
16198 grisu2_round(buffer, length, dist, delta, rest, ten_n);
16246 JSON_ASSERT(p2 > delta);
16257 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
16259 const std::uint64_t d = p2 >> -one.e;
16260 const std::uint64_t r = p2 & (one.f - 1);
16266 JSON_ASSERT(d <= 9);
16267 buffer[length++] =
static_cast<char>(
'0' + d);
16291 decimal_exponent -= m;
16298 const std::uint64_t ten_m = one.f;
16299 grisu2_round(buffer, length, dist, delta, p2, ten_m);
16320JSON_HEDLEY_NON_NULL(1)
16321inline
void grisu2(
char *buf,
int &len,
int &decimal_exponent,
16324 JSON_ASSERT(m_plus.e == m_minus.e);
16325 JSON_ASSERT(m_plus.e == v.e);
16335 const diyfp c_minus_k(cached.f, cached.e);
16361 const diyfp M_minus(w_minus.f + 1, w_minus.e);
16362 const diyfp M_plus (w_plus.f - 1, w_plus.e );
16363 decimal_exponent = -cached.k;
16372template<
typename FloatType>
16373JSON_HEDLEY_NON_NULL(1)
16374void
grisu2(
char *buf,
int &len,
int &decimal_exponent, FloatType value)
16376 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
16377 "internal error: not enough precision");
16378 JSON_ASSERT(std::isfinite(
value));
16379 JSON_ASSERT(
value > 0);
16401 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
16409JSON_HEDLEY_NON_NULL(1)
16410JSON_HEDLEY_RETURNS_NON_NULL
16413 JSON_ASSERT(e > -1000);
16414 JSON_ASSERT(e < 1000);
16427 auto k =
static_cast<std::uint32_t
>(e);
16434 *buf++ =
static_cast<char>(
'0' + k);
16439 *buf++ =
static_cast<char>(
'0' + k / 10);
16441 *buf++ =
static_cast<char>(
'0' + k);
16446 *buf++ =
static_cast<char>(
'0' + k / 100);
16448 *buf++ =
static_cast<char>(
'0' + k / 10);
16450 *buf++ =
static_cast<char>(
'0' + k);
16465JSON_HEDLEY_NON_NULL(1)
16466JSON_HEDLEY_RETURNS_NON_NULL
16468 int min_exp,
int max_exp)
16470 JSON_ASSERT(min_exp < 0);
16471 JSON_ASSERT(max_exp > 0);
16473 const int n = len + decimal_exponent;
16479 if (k <= n && n <= max_exp)
16483 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
16487 return buf + (
static_cast<size_t>(n) + 2);
16490 if (0 < n && n <= max_exp)
16494 JSON_ASSERT(k > n);
16495 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
16497 return buf + (
static_cast<size_t>(k) + 1U);
16500 if (min_exp < n && n <= 0)
16504 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
16507 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
16508 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
16522 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
16524 buf += 1 +
static_cast<size_t>(k);
16543template<
typename FloatType>
16544JSON_HEDLEY_NON_NULL(1, 2)
16545JSON_HEDLEY_RETURNS_NON_NULL
16546char *
to_chars(
char *first, const
char *last, FloatType value)
16548 static_cast<void>(last);
16549 JSON_ASSERT(std::isfinite(
value));
16552 if (std::signbit(
value))
16559#pragma GCC diagnostic push
16560#pragma GCC diagnostic ignored "-Wfloat-equal"
16573#pragma GCC diagnostic pop
16575 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
16581 int decimal_exponent = 0;
16583 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
16585 constexpr int kMinExp = -4;
16587 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
16588 JSON_ASSERT(last - first >= kMaxExp + 2);
16589 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
16590 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
16626template<
typename BasicJsonType>
16629 using string_t =
typename BasicJsonType::string_t;
16630 using number_float_t =
typename BasicJsonType::number_float_t;
16631 using number_integer_t =
typename BasicJsonType::number_integer_t;
16632 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
16633 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
16634 static constexpr std::uint8_t UTF8_ACCEPT = 0;
16635 static constexpr std::uint8_t UTF8_REJECT = 1;
16646 ,
loc(
std::localeconv())
16684 const bool pretty_print,
16685 const bool ensure_ascii,
16686 const unsigned int indent_step,
16687 const unsigned int current_indent = 0)
16689 switch (val.m_type)
16693 if (val.m_value.object->empty())
16695 o->write_characters(
"{}", 2);
16701 o->write_characters(
"{\n", 2);
16703 const auto new_indent = current_indent + indent_step;
16705 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16711 auto i = val.m_value.object->cbegin();
16713 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16716 o->write_character(
'\"');
16717 dump_escaped(i->first, ensure_ascii);
16718 o->write_characters(
"\": ", 3);
16719 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16720 o->write_characters(
",\n", 2);
16724 JSON_ASSERT(i != val.m_value.object->cend());
16725 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16727 o->write_character(
'\"');
16728 dump_escaped(i->first, ensure_ascii);
16729 o->write_characters(
"\": ", 3);
16730 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16731 o->write_character(
'\n');
16732 o->write_characters(
indent_string.c_str(), current_indent);
16733 o->write_character(
'}');
16738 o->write_character(
'{');
16740 auto i = val.m_value.object->cbegin();
16742 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16744 o->write_character(
'\"');
16745 dump_escaped(i->first, ensure_ascii);
16746 o->write_characters(
"\":", 2);
16747 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16748 o->write_character(
',');
16752 JSON_ASSERT(i != val.m_value.object->cend());
16753 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16754 o->write_character(
'\"');
16755 dump_escaped(i->first, ensure_ascii);
16756 o->write_characters(
"\":", 2);
16757 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16758 o->write_character(
'}');
16766 if (val.m_value.array->empty())
16768 o->write_characters(
"[]", 2);
16774 o->write_characters(
"[\n", 2);
16776 const auto new_indent = current_indent + indent_step;
16778 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16784 for (
auto i = val.m_value.array->cbegin();
16785 i != val.m_value.array->cend() - 1; ++i)
16788 dump(*i,
true, ensure_ascii, indent_step, new_indent);
16789 o->write_characters(
",\n", 2);
16793 JSON_ASSERT(!val.m_value.array->empty());
16795 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
16796 o->write_character(
'\n');
16797 o->write_characters(
indent_string.c_str(), current_indent);
16798 o->write_character(
']');
16803 o->write_character(
'[');
16806 for (
auto i = val.m_value.array->cbegin();
16807 i != val.m_value.array->cend() - 1; ++i)
16809 dump(*i,
false, ensure_ascii, indent_step, current_indent);
16810 o->write_character(
',');
16814 JSON_ASSERT(!val.m_value.array->empty());
16815 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
16816 o->write_character(
']');
16824 o->write_character(
'\"');
16825 dump_escaped(*val.m_value.string, ensure_ascii);
16826 o->write_character(
'\"');
16834 o->write_characters(
"{\n", 2);
16836 const auto new_indent = current_indent + indent_step;
16838 if (JSON_HEDLEY_UNLIKELY(
indent_string.size() < new_indent))
16844 o->write_characters(
"\"bytes\": [", 10);
16846 if (!val.m_value.binary->empty())
16848 for (
auto i = val.m_value.binary->cbegin();
16849 i != val.m_value.binary->cend() - 1; ++i)
16852 o->write_characters(
", ", 2);
16855 dump_integer(val.m_value.binary->back());
16858 o->write_characters(
"],\n", 3);
16860 o->write_characters(
"\"subtype\": ", 11);
16862 if (val.m_value.binary->has_subtype())
16864 dump_integer(val.m_value.binary->subtype());
16869 o->write_characters(
"null", 4);
16872 o->write_character(
'\n');
16873 o->write_characters(
indent_string.c_str(), current_indent);
16874 o->write_character(
'}');
16879 o->write_characters(
"{\"bytes\":[", 10);
16881 if (!val.m_value.binary->empty())
16883 for (
auto i = val.m_value.binary->cbegin();
16884 i != val.m_value.binary->cend() - 1; ++i)
16887 o->write_character(
',');
16890 dump_integer(val.m_value.binary->back());
16893 o->write_characters(
"],\"subtype\":", 12);
16895 if (val.m_value.binary->has_subtype())
16897 dump_integer(val.m_value.binary->subtype());
16898 o->write_character(
'}');
16903 o->write_characters(
"null}", 5);
16912 if (val.m_value.boolean)
16914 o->write_characters(
"true", 4);
16919 o->write_characters(
"false", 5);
16927 dump_integer(val.m_value.number_integer);
16933 dump_integer(val.m_value.number_unsigned);
16939 dump_float(val.m_value.number_float);
16945 o->write_characters(
"<discarded>", 11);
16951 o->write_characters(
"null", 4);
16956 JSON_ASSERT(
false);
16960JSON_PRIVATE_UNLESS_TESTED:
16975 void dump_escaped(
const string_t &s,
const bool ensure_ascii)
16977 std::uint32_t codepoint{};
16978 std::uint8_t state = UTF8_ACCEPT;
16979 std::size_t bytes = 0;
16981 std::size_t bytes_after_last_accept = 0;
16982 std::size_t undumped_chars = 0;
16984 for (std::size_t i = 0; i < s.size(); ++i)
16986 const auto byte =
static_cast<std::uint8_t
>(s[i]);
16988 switch (decode(state, codepoint,
byte))
17047 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
17049 if (codepoint <= 0xFFFF)
17052 (std::snprintf)(
string_buffer.data() + bytes, 7,
"\\u%04x",
17053 static_cast<std::uint16_t
>(codepoint));
17060 (std::snprintf)(
string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
17061 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
17062 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
17088 bytes_after_last_accept = bytes;
17089 undumped_chars = 0;
17099 std::string sn(9,
'\0');
17101 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
17102 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn, BasicJsonType()));
17112 if (undumped_chars > 0)
17119 bytes = bytes_after_last_accept;
17136 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
17137 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
17138 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
17150 bytes_after_last_accept = bytes;
17153 undumped_chars = 0;
17155 state = UTF8_ACCEPT;
17160 JSON_ASSERT(
false);
17181 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
17197 std::string sn(9,
'\0');
17199 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
17200 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
17206 o->write_characters(
string_buffer.data(), bytes_after_last_accept);
17213 o->write_characters(
string_buffer.data(), bytes_after_last_accept);
17218 o->write_characters(
"\\ufffd", 6);
17223 o->write_characters(
"\xEF\xBF\xBD", 3);
17230 JSON_ASSERT(
false);
17244 inline unsigned int count_digits(number_unsigned_t x)
noexcept
17246 unsigned int n_digits = 1;
17257 return n_digits + 1;
17262 return n_digits + 2;
17267 return n_digits + 3;
17284 template <
typename NumberType, detail::enable_if_t <
17285 std::is_integral<NumberType>::value ||
17286 std::is_same<NumberType, number_unsigned_t>::value ||
17287 std::is_same<NumberType, number_integer_t>::value ||
17288 std::is_same<NumberType, binary_char_t>::value,
17290 void dump_integer(NumberType x)
17292 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
17295 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
17296 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
17297 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
17298 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
17299 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
17300 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
17301 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
17302 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
17303 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
17304 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
17311 o->write_character(
'0');
17317 const bool is_negative = std::is_signed<NumberType>::value && !(x >= 0);
17318 number_unsigned_t abs_value;
17319 unsigned int n_chars{};
17324 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
17326 n_chars = 1 + count_digits(abs_value);
17331 abs_value =
static_cast<number_unsigned_t
>(x);
17332 n_chars = count_digits(abs_value);
17339 buffer_ptr += n_chars;
17343 while (abs_value >= 100)
17345 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
17347 *(--buffer_ptr) = digits_to_99[digits_index][1];
17348 *(--buffer_ptr) = digits_to_99[digits_index][0];
17351 if (abs_value >= 10)
17353 const auto digits_index =
static_cast<unsigned>(abs_value);
17354 *(--buffer_ptr) = digits_to_99[digits_index][1];
17355 *(--buffer_ptr) = digits_to_99[digits_index][0];
17360 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
17374 void dump_float(number_float_t x)
17377 if (!std::isfinite(x))
17379 o->write_characters(
"null", 4);
17388 static constexpr bool is_ieee_single_or_double
17389 = (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) ||
17390 (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);
17391 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
17394 void dump_float(number_float_t x, std::true_type )
17397 auto *end = ::nlohmann::detail::to_chars(begin, begin +
number_buffer.size(), x);
17398 o->write_characters(begin,
static_cast<size_t>(end - begin));
17401 void dump_float(number_float_t x, std::false_type )
17404 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
17409 JSON_ASSERT(len > 0);
17411 JSON_ASSERT(
static_cast<std::size_t
>(len) <
number_buffer.size());
17434 o->write_characters(
number_buffer.data(),
static_cast<std::size_t
>(len));
17436 const bool value_is_int_like =
17440 return c ==
'.' || c ==
'e';
17443 if (value_is_int_like)
17445 o->write_characters(
".0", 2);
17470 static std::uint8_t decode(std::uint8_t &state, std::uint32_t &codep,
const std::uint8_t
byte)
noexcept
17472 static const std::array<std::uint8_t, 400> utf8d =
17475 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,
17476 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,
17477 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,
17478 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,
17479 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,
17480 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,
17481 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,
17482 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
17483 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
17484 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
17485 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,
17486 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,
17487 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,
17488 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
17491 JSON_ASSERT(
byte < utf8d.size());
17492 const std::uint8_t type = utf8d[byte];
17493 codep = (state != UTF8_ACCEPT)
17494 ? (
byte & 0x3fu) | (codep << 6u)
17495 : (0xFFu >> type) & (byte);
17496 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
17497 JSON_ASSERT(index < 400);
17498 state = utf8d[index];
17507 number_unsigned_t remove_sign(number_unsigned_t x)
17509 JSON_ASSERT(
false);
17522 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
17524 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
17525 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
17530 output_adapter_t<char> o =
nullptr;
17563#include <functional>
17564#include <initializer_list>
17567#include <stdexcept>
17568#include <type_traits>
17580template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
17581 class Allocator = std::allocator<std::pair<const Key, T>>>
17584 using key_type = Key;
17585 using mapped_type = T;
17586 using Container = std::vector<std::pair<const Key, T>, Allocator>;
17587 using typename Container::iterator;
17588 using typename Container::const_iterator;
17589 using typename Container::size_type;
17590 using typename Container::value_type;
17594 ordered_map(
const Allocator &alloc = Allocator()) : Container{alloc} {}
17595 template <
class It>
17596 ordered_map(It first, It last,
const Allocator &alloc = Allocator())
17597 : Container{first, last, alloc} {}
17598 ordered_map(std::initializer_list<T> init,
const Allocator &alloc = Allocator() )
17599 : Container{init, alloc} {}
17601 std::pair<iterator, bool> emplace(
const key_type &key, T &&t)
17603 for (
auto it = this->begin(); it != this->end(); ++it)
17605 if (it->first == key)
17607 return {it,
false};
17611 Container::emplace_back(key, t);
17612 return {--this->end(),
true};
17615 T &operator[](
const Key &key)
17617 return emplace(key, T{}).first->second;
17620 const T &operator[](
const Key &key)
const
17625 T &at(
const Key &key)
17627 for (
auto it = this->begin(); it != this->end(); ++it)
17629 if (it->first == key)
17635 JSON_THROW(std::out_of_range(
"key not found"));
17638 const T &at(
const Key &key)
const
17640 for (
auto it = this->begin(); it != this->end(); ++it)
17642 if (it->first == key)
17648 JSON_THROW(std::out_of_range(
"key not found"));
17651 size_type erase(
const Key &key)
17653 for (
auto it = this->begin(); it != this->end(); ++it)
17655 if (it->first == key)
17658 for (
auto next = it; ++next != this->end(); ++it)
17661 new (&*it) value_type{std::move(*next)};
17664 Container::pop_back();
17672 iterator erase(iterator pos)
17677 for (
auto next = it; ++next != this->end(); ++it)
17680 new (&*it) value_type{std::move(*next)};
17683 Container::pop_back();
17687 size_type count(
const Key &key)
const
17689 for (
auto it = this->begin(); it != this->end(); ++it)
17691 if (it->first == key)
17700 iterator find(
const Key &key)
17702 for (
auto it = this->begin(); it != this->end(); ++it)
17704 if (it->first == key)
17710 return Container::end();
17713 const_iterator find(
const Key &key)
const
17715 for (
auto it = this->begin(); it != this->end(); ++it)
17717 if (it->first == key)
17723 return Container::end();
17726 std::pair<iterator, bool> insert( value_type &&value )
17728 return emplace(value.first, std::move(value.second));
17731 std::pair<iterator, bool> insert(
const value_type &value )
17733 for (
auto it = this->begin(); it != this->end(); ++it)
17735 if (it->first == value.first)
17737 return {it,
false};
17741 Container::push_back(value);
17742 return {--this->end(),
true};
17745 template<
typename InputIt>
17746 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
17747 std::input_iterator_tag>::value>::type;
17749 template<
typename InputIt,
typename = require_input_iter<InputIt>>
17750 void insert(InputIt first, InputIt last)
17752 for (
auto it = first; it != last; ++it)
17762#if defined(JSON_HAS_CPP_17)
17763#include <string_view>
17858NLOHMANN_BASIC_JSON_TPL_DECLARATION
17863 friend ::nlohmann::json_pointer<basic_json>;
17865 template<
typename BasicJsonType,
typename InputType>
17866 friend class ::nlohmann::detail::parser;
17867 friend ::nlohmann::detail::serializer<basic_json>;
17868 template<
typename BasicJsonType>
17869 friend class ::nlohmann::detail::iter_impl;
17870 template<
typename BasicJsonType,
typename CharType>
17871 friend class ::nlohmann::detail::binary_writer;
17872 template<
typename BasicJsonType,
typename InputType,
typename SAX>
17873 friend class ::nlohmann::detail::binary_reader;
17874 template<
typename BasicJsonType>
17875 friend class ::nlohmann::detail::json_sax_dom_parser;
17876 template<
typename BasicJsonType>
17877 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17878 friend class ::nlohmann::detail::exception;
17883JSON_PRIVATE_UNLESS_TESTED:
17887 template<
typename InputAdapterType>
17888 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17889 InputAdapterType adapter,
17890 detail::parser_callback_t<basic_json>cb =
nullptr,
17891 const bool allow_exceptions =
true,
17892 const bool ignore_comments =
false
17895 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17896 std::move(cb), allow_exceptions, ignore_comments);
17901 template<
typename BasicJsonType>
17903 template<
typename BasicJsonType>
17905 template<
typename Iterator>
17909 template<
typename CharType>
17912 template<
typename InputType>
17916JSON_PRIVATE_UNLESS_TESTED:
17923 template<
typename T,
typename SFINAE>
17924 using json_serializer = JSONSerializer<T, SFINAE>;
17986 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
17988 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
18036 JSON_HEDLEY_WARN_UNUSED_RESULT
18040 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
18041 result[
"name"] =
"JSON for Modern C++";
18042 result[
"url"] =
"https://github.com/nlohmann/json";
18043 result[
"version"][
"string"] =
18044 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
18045 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
18046 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
18047 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
18048 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
18049 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
18051 result[
"platform"] =
"win32";
18052#elif defined __linux__
18053 result[
"platform"] =
"linux";
18054#elif defined __APPLE__
18055 result[
"platform"] =
"apple";
18056#elif defined __unix__
18057 result[
"platform"] =
"unix";
18059 result[
"platform"] =
"unknown";
18061#if defined(__ICC) || defined(__INTEL_COMPILER)
18062 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
18063#elif defined(__clang__)
18064 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
18065#elif defined(__GNUC__) || defined(__GNUG__)
18066 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
18067#elif defined(__HP_cc) || defined(__HP_aCC)
18068 result[
"compiler"] =
"hp"
18069#elif defined(__IBMCPP__)
18070 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
18071#elif defined(_MSC_VER)
18072 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
18073#elif defined(__PGI)
18074 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
18075#elif defined(__SUNPRO_CC)
18076 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
18078 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
18081 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
18083 result[
"compiler"][
"c++"] =
"unknown";
18098#if defined(JSON_HAS_CPP_14)
18101 using object_comparator_t = std::less<>;
18103 using object_comparator_t = std::less<StringType>;
18191 object_comparator_t,
18192 AllocatorType<std::pair<
const StringType,
18239 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
18606 template<
typename T,
typename... Args>
18607 JSON_HEDLEY_RETURNS_NON_NULL
18610 AllocatorType<T> alloc;
18611 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
18612 auto deleter = [&](T * obj)
18614 AllocatorTraits::deallocate(alloc, obj, 1);
18616 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
18617 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
18618 JSON_ASSERT(obj !=
nullptr);
18619 return obj.release();
18626JSON_PRIVATE_UNLESS_TESTED:
18688 object = create<object_t>();
18694 array = create<array_t>();
18700 string = create<string_t>(
"");
18706 binary = create<binary_t>();
18747 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.10.2",
basic_json()));
18758 string = create<string_t>(
value);
18764 string = create<string_t>(std::move(
value));
18770 object = create<object_t>(
value);
18776 object = create<object_t>(std::move(
value));
18815 void destroy(value_t t)
18820 std::vector<basic_json> stack;
18825 stack.reserve(
array->size());
18826 std::move(
array->begin(),
array->end(), std::back_inserter(stack));
18833 for (
auto &&it : *
object)
18835 stack.push_back(std::move(it.second));
18839 while (!stack.empty())
18842 basic_json current_item(std::move(stack.back()));
18847 if (current_item.is_array())
18849 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
18850 current_item.m_value.array->clear();
18853 else if (current_item.is_object())
18855 for (
auto &&it : *current_item.m_value.object)
18857 stack.push_back(std::move(it.second));
18860 current_item.m_value.object->clear();
18872 AllocatorType<object_t> alloc;
18873 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
18874 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
18880 AllocatorType<array_t> alloc;
18881 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
array);
18882 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
array, 1);
18888 AllocatorType<string_t> alloc;
18889 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
18890 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
18896 AllocatorType<binary_t> alloc;
18897 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
binary);
18898 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
binary, 1);
18941#if JSON_DIAGNOSTICS
18947 return j.m_parent ==
this;
18952 static_cast<void>(check_parents);
18957#if JSON_DIAGNOSTICS
18963 for (
auto &element : *
m_value.array)
18965 element.m_parent =
this;
18973 for (
auto &element : *
m_value.object)
18975 element.second.m_parent =
this;
18998#if JSON_DIAGNOSTICS
19002 (it + i)->m_parent =
this;
19006 static_cast<void>(
count);
19013#if JSON_DIAGNOSTICS
19015 if (old_capacity != std::size_t(-1))
19020 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
19030#ifdef JSON_HEDLEY_MSVC_VERSION
19031#pragma warning(push )
19032#pragma warning(disable : 4127)
19035 if (detail::is_ordered_map<object_t>::value)
19041#ifdef JSON_HEDLEY_MSVC_VERSION
19042#pragma warning( pop )
19046 static_cast<void>(j);
19047 static_cast<void>(old_capacity);
19256 template <
typename CompatibleType,
19257 typename U = detail::uncvref_t<CompatibleType>,
19258 detail::enable_if_t <
19261 JSONSerializer<U>::to_json(std::declval<basic_json_t &>(),
19262 std::forward<CompatibleType>(val))))
19264 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
19295 template <
typename BasicJsonType,
19296 detail::enable_if_t <
19300 using other_boolean_t =
typename BasicJsonType::boolean_t;
19301 using other_number_float_t =
typename BasicJsonType::number_float_t;
19302 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
19303 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
19304 using other_string_t =
typename BasicJsonType::string_t;
19305 using other_object_t =
typename BasicJsonType::object_t;
19306 using other_array_t =
typename BasicJsonType::array_t;
19307 using other_binary_t =
typename BasicJsonType::binary_t;
19309 switch (val.type())
19312 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
19316 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
19320 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
19324 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
19328 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t &>());
19332 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t &>());
19336 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t &>());
19340 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t &>());
19352 JSON_ASSERT(
false);
19434 bool type_deduction =
true,
19439 bool is_an_object = std::all_of(init.begin(), init.end(),
19442 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
19446 if (!type_deduction)
19451 is_an_object =
false;
19455 if (JSON_HEDLEY_UNLIKELY(manual_type ==
value_t::object && !is_an_object))
19457 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
19467 for (
auto &element_ref : init)
19469 auto element = element_ref.moved_or_copied();
19471 std::move(*((*element.m_value.array)[0].m_value.string)),
19472 std::move((*element.m_value.array)[1]));
19480 m_value.array = create<array_t>(init.begin(), init.end());
19514 JSON_HEDLEY_WARN_UNUSED_RESULT
19519 res.m_value = init;
19551 JSON_HEDLEY_WARN_UNUSED_RESULT
19556 res.m_value =
binary_t(init, subtype);
19561 JSON_HEDLEY_WARN_UNUSED_RESULT
19566 res.m_value = std::move(init);
19571 JSON_HEDLEY_WARN_UNUSED_RESULT
19576 res.m_value =
binary_t(std::move(init), subtype);
19617 JSON_HEDLEY_WARN_UNUSED_RESULT
19661 JSON_HEDLEY_WARN_UNUSED_RESULT
19692 m_value.array = create<array_t>(cnt, val);
19752 template <
class InputIT,
typename std::enable_if <
19753 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
19754 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
19757 JSON_ASSERT(first.m_object !=
nullptr);
19758 JSON_ASSERT(last.m_object !=
nullptr);
19761 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19763 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
19767 m_type = first.m_object->m_type;
19778 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
19779 || !last.m_it.primitive_iterator.is_end()))
19781 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
19800 m_value.number_integer = first.m_object->m_value.number_integer;
19806 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
19812 m_value.number_float = first.m_object->m_value.number_float;
19818 m_value.boolean = first.m_object->m_value.boolean;
19824 m_value = *first.m_object->m_value.string;
19830 m_value.object = create<object_t>(first.m_it.object_iterator,
19831 last.m_it.object_iterator);
19837 m_value.array = create<array_t>(first.m_it.array_iterator,
19838 last.m_it.array_iterator);
19844 m_value = *first.m_object->m_value.binary;
19851 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
19863 template<
typename JsonRef,
19864 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
19865 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
19894 : m_type(other.m_type)
19986 : m_type(std::move(other.m_type)),
19987 m_value(std::move(other.m_value))
19990 other.assert_invariant(
false);
19993 other.m_value = {};
20022 std::is_nothrow_move_constructible<value_t>::value &&
20023 std::is_nothrow_move_assignable<value_t>::value &&
20024 std::is_nothrow_move_constructible<json_value>::value &&
20025 std::is_nothrow_move_assignable<json_value>::value
20031 swap(m_type, other.m_type);
20118 const char indent_char =
' ',
20119 const bool ensure_ascii =
false,
20127 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
20132 s.dump(*
this,
false, ensure_ascii, 0);
20549 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
20659 template<
typename ReferenceType,
typename ThisType>
20663 auto *ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20665 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20670 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
20704 template<
typename PointerType,
typename std::enable_if<
20705 std::is_pointer<PointerType>::value,
int>
::type = 0>
20709 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20716 template <
typename PointerType,
typename std::enable_if <
20717 std::is_pointer<PointerType>::value &&
20718 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
20722 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20764 template <
typename ValueType,
20765 detail::enable_if_t <
20770 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t &>(), std::declval<ValueType &>())))
20773 JSONSerializer<ValueType>::from_json(*
this, ret);
20807 template <
typename ValueType,
20808 detail::enable_if_t <
20812 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t &>())))
20814 return JSONSerializer<ValueType>::from_json(*
this);
20832 template <
typename BasicJsonType,
20833 detail::enable_if_t <
20855 template<
typename BasicJsonType,
20856 detail::enable_if_t<
20857 std::is_same<BasicJsonType, basic_json_t>::value,
20868 template<
typename PointerType,
20869 detail::enable_if_t<
20870 std::is_pointer<PointerType>::value,
20873 ->
decltype(std::declval<const basic_json_t &>().template get_ptr<PointerType>())
20876 return get_ptr<PointerType>();
20903 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20904#if defined(JSON_HAS_CPP_14)
20914 static_assert(!std::is_reference<ValueTypeCV>::value,
20915 "get() cannot be used with reference types, you might want to use get_ref()");
20916 return get_impl<ValueType>(detail::priority_tag<4> {});
20946 template<
typename PointerType,
typename std::enable_if<
20947 std::is_pointer<PointerType>::value,
int>
::type = 0>
20951 return get_ptr<PointerType>();
20987 template <
typename ValueType,
20988 detail::enable_if_t <
20992 ValueType &
get_to(ValueType &v)
const noexcept(
noexcept(
20993 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t &>(), v)))
20995 JSONSerializer<ValueType>::from_json(*
this, v);
21001 template<
typename ValueType,
21002 detail::enable_if_t <
21005 ValueType &
get_to(ValueType &v)
const
21012 typename T, std::size_t N,
21013 typename Array = T (&)[N],
21014 detail::enable_if_t <
21015 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
21016 Array
get_to(T (&v)[N])
const
21017 noexcept(
noexcept(JSONSerializer<Array>::from_json(
21018 std::declval<const basic_json_t &>(), v)))
21020 JSONSerializer<Array>::from_json(*
this, v);
21050 template<
typename ReferenceType,
typename std::enable_if<
21051 std::is_reference<ReferenceType>::value,
int>
::type = 0>
21055 return get_ref_impl<ReferenceType>(*
this);
21062 template <
typename ReferenceType,
typename std::enable_if <
21063 std::is_reference<ReferenceType>::value &&
21064 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
21068 return get_ref_impl<ReferenceType>(*
this);
21100 template <
typename ValueType,
typename std::enable_if <
21108#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
21113 JSON_EXPLICIT
operator ValueType()
const
21116 return get<ValueType>();
21132 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
21135 return *get_ptr<binary_t *>();
21143 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
21146 return *get_ptr<const binary_t *>();
21189 if (JSON_HEDLEY_LIKELY(
is_array()))
21193 return set_parent(
m_value.array->at(idx));
21195 JSON_CATCH (std::out_of_range &)
21198 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21204 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21237 if (JSON_HEDLEY_LIKELY(
is_array()))
21241 return m_value.array->at(idx);
21243 JSON_CATCH (std::out_of_range &)
21246 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21252 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21293 return set_parent(
m_value.object->at(key));
21295 JSON_CATCH (std::out_of_range &)
21298 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21304 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21345 return m_value.object->at(key);
21347 JSON_CATCH (std::out_of_range &)
21350 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21356 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21391 m_value.array = create<array_t>();
21396 if (JSON_HEDLEY_LIKELY(
is_array()))
21399 if (idx >=
m_value.array->size())
21401#if JSON_DIAGNOSTICS
21403 const auto previous_size =
m_value.array->size();
21405 m_value.array->resize(idx + 1);
21406#if JSON_DIAGNOSTICS
21412 return m_value.array->operator[](idx);
21415 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21440 if (JSON_HEDLEY_LIKELY(
is_array()))
21442 return m_value.array->operator[](idx);
21445 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21481 m_value.object = create<object_t>();
21488 return set_parent(
m_value.object->operator[](key));
21491 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21529 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
21530 return m_value.object->find(key)->second;
21533 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21563 template<
typename T>
21564 JSON_HEDLEY_NON_NULL(2)
21578 return set_parent(
m_value.object->operator[](key));
21581 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21614 template<
typename T>
21615 JSON_HEDLEY_NON_NULL(2)
21621 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
21622 return m_value.object->find(key)->second;
21625 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21679 template <
class ValueType,
typename std::enable_if <
21681 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
21682 ValueType
value(
const typename object_t::key_type &key,
const ValueType &default_value)
const
21688 const auto it =
find(key);
21692 return it->template get<ValueType>();
21695 return default_value;
21698 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21705 string_t value(
const typename object_t::key_type &key,
const char *default_value)
const
21753 template<
class ValueType,
typename std::enable_if<
21763 return ptr.
get_checked(
this).template get<ValueType>();
21767 return default_value;
21771 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21778 JSON_HEDLEY_NON_NULL(3)
21916 template <
class IteratorType,
typename std::enable_if <
21917 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21918 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21923 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21925 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
21928 IteratorType result =
end();
21939 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21941 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
21946 AllocatorType<string_t> alloc;
21947 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.string);
21948 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21954 AllocatorType<binary_t> alloc;
21955 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.binary);
21956 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21967 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
21973 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
21980 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22032 template <
class IteratorType,
typename std::enable_if <
22033 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
22034 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
22036 IteratorType
erase(IteratorType first, IteratorType last)
22039 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
22041 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
22044 IteratorType result =
end();
22055 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
22056 || !last.m_it.primitive_iterator.is_end()))
22058 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
22063 AllocatorType<string_t> alloc;
22064 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.string);
22065 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
22071 AllocatorType<binary_t> alloc;
22072 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.binary);
22073 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
22084 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
22085 last.m_it.object_iterator);
22091 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
22092 last.m_it.array_iterator);
22099 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22139 return m_value.object->erase(key);
22142 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22172 if (JSON_HEDLEY_LIKELY(
is_array()))
22174 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
22176 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
22184 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22222 template<
typename KeyT>
22225 auto result =
end();
22229 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
22239 template<
typename KeyT>
22242 auto result =
cend();
22246 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
22273 template<
typename KeyT>
22305 template <
typename KeyT,
typename std::enable_if <
22380 result.set_begin();
22420 result.set_begin();
22684 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22687 return ref.items();
22693 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22696 return ref.items();
22845 return m_value.array->empty();
22851 return m_value.object->empty();
22925 return m_value.array->size();
22931 return m_value.object->size();
22997 return m_value.array->max_size();
23003 return m_value.object->max_size();
23153 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
23165 const auto old_capacity =
m_value.array->capacity();
23166 m_value.array->push_back(std::move(val));
23167 set_parent(
m_value.array->back(), old_capacity);
23190 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
23202 const auto old_capacity =
m_value.array->capacity();
23203 m_value.array->push_back(val);
23204 set_parent(
m_value.array->back(), old_capacity);
23242 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
23254 auto res =
m_value.object->insert(val);
23255 set_parent(res.first->second);
23295 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
23297 basic_json &&key = init.begin()->moved_or_copied();
23298 push_back(
typename object_t::value_type(
23299 std::move(key.get_ref<
string_t &>()), (init.begin() + 1)->moved_or_copied()));
23341 template<
class... Args>
23347 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
23359 const auto old_capacity =
m_value.array->capacity();
23360 m_value.array->emplace_back(std::forward<Args>(args)...);
23361 return set_parent(
m_value.array->back(), old_capacity);
23391 template<
class... Args>
23397 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
23409 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
23410 set_parent(res.first->second);
23413 it.m_it.object_iterator = res.first;
23415 return {it, res.second};
23421 template<
typename... Args>
23425 JSON_ASSERT(
m_value.array !=
nullptr);
23461 if (JSON_HEDLEY_LIKELY(
is_array()))
23464 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23466 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23473 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23482 return insert(pos, val);
23512 if (JSON_HEDLEY_LIKELY(
is_array()))
23515 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23517 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23524 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23560 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23562 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23566 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23568 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23572 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23574 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23577 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23579 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
23613 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23615 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23619 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23621 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23654 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23656 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23660 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23662 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23666 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23668 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23699 m_value.object = create<object_t>();
23703 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23705 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23708 if (JSON_HEDLEY_UNLIKELY(!j.
is_object()))
23710 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.
type_name()), *
this));
23713 for (
auto it = j.
cbegin(); it != j.
cend(); ++it)
23715 m_value.object->operator[](it.key()) = it.value();
23716#if JSON_DIAGNOSTICS
23717 m_value.object->operator[](it.key()).m_parent =
this;
23754 m_value.object = create<object_t>();
23758 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23760 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23764 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23766 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23770 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
23771 || !last.m_object->is_object()))
23773 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23776 for (
auto it = first; it != last; ++it)
23778 m_value.object->operator[](it.key()) = it.value();
23779#if JSON_DIAGNOSTICS
23780 m_value.object->operator[](it.key()).m_parent =
this;
23803 std::is_nothrow_move_constructible<value_t>::value &&
23804 std::is_nothrow_move_assignable<value_t>::value &&
23805 std::is_nothrow_move_constructible<json_value>::value &&
23806 std::is_nothrow_move_assignable<json_value>::value
23809 std::swap(m_type, other.m_type);
23810 std::swap(
m_value, other.m_value);
23812 other.set_parents();
23835 std::is_nothrow_move_constructible<value_t>::value &&
23836 std::is_nothrow_move_assignable<value_t>::value &&
23837 std::is_nothrow_move_constructible<json_value>::value &&
23838 std::is_nothrow_move_assignable<json_value>::value
23867 if (JSON_HEDLEY_LIKELY(
is_array()))
23869 std::swap(*(
m_value.array), other);
23874 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23903 std::swap(*(
m_value.object), other);
23908 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23937 std::swap(*(
m_value.string), other);
23942 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23971 std::swap(*(
m_value.binary), other);
23976 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23986 std::swap(*(
m_value.binary), other);
23991 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
24063#pragma GCC diagnostic push
24064#pragma GCC diagnostic ignored "-Wfloat-equal"
24066 const auto lhs_type = lhs.type();
24067 const auto rhs_type = rhs.type();
24069 if (lhs_type == rhs_type)
24074 return *lhs.m_value.array == *rhs.m_value.array;
24077 return *lhs.m_value.object == *rhs.m_value.object;
24083 return *lhs.m_value.string == *rhs.m_value.string;
24086 return lhs.m_value.boolean == rhs.m_value.boolean;
24089 return lhs.m_value.number_integer == rhs.m_value.number_integer;
24092 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
24095 return lhs.m_value.number_float == rhs.m_value.number_float;
24098 return *lhs.m_value.binary == *rhs.m_value.binary;
24108 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
24113 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
24118 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
24123 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
24128 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
24133 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
24138#pragma GCC diagnostic pop
24146 template<
typename ScalarType,
typename std::enable_if<
24147 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24157 template<
typename ScalarType,
typename std::enable_if<
24158 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24184 return !(lhs == rhs);
24191 template<
typename ScalarType,
typename std::enable_if<
24192 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24202 template<
typename ScalarType,
typename std::enable_if<
24203 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24237 const auto lhs_type = lhs.type();
24238 const auto rhs_type = rhs.type();
24240 if (lhs_type == rhs_type)
24247 return (*lhs.m_value.array) < (*rhs.m_value.array);
24250 return (*lhs.m_value.object) < (*rhs.m_value.object);
24256 return (*lhs.m_value.string) < (*rhs.m_value.string);
24259 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
24262 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
24265 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
24268 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
24271 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
24281 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
24286 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
24291 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
24296 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
24301 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
24306 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
24319 template<
typename ScalarType,
typename std::enable_if<
24320 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24330 template<
typename ScalarType,
typename std::enable_if<
24331 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24358 return !(rhs < lhs);
24365 template<
typename ScalarType,
typename std::enable_if<
24366 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24376 template<
typename ScalarType,
typename std::enable_if<
24377 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24404 return !(lhs <= rhs);
24411 template<
typename ScalarType,
typename std::enable_if<
24412 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24422 template<
typename ScalarType,
typename std::enable_if<
24423 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24450 return !(lhs < rhs);
24457 template<
typename ScalarType,
typename std::enable_if<
24458 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24468 template<
typename ScalarType,
typename std::enable_if<
24469 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24518 const bool pretty_print = o.width() > 0;
24519 const auto indentation = pretty_print ? o.width() : 0;
24524 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24536 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream &,
const basic_json &))
24603 template<
typename InputType>
24604 JSON_HEDLEY_WARN_UNUSED_RESULT
24607 const bool allow_exceptions =
true,
24608 const bool ignore_comments =
false)
24611 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24641 template<
typename IteratorType>
24642 JSON_HEDLEY_WARN_UNUSED_RESULT
24646 const bool allow_exceptions =
true,
24647 const bool ignore_comments =
false)
24650 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24654 JSON_HEDLEY_WARN_UNUSED_RESULT
24655 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
24658 const bool allow_exceptions =
true,
24659 const bool ignore_comments =
false)
24662 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
24696 template<
typename InputType>
24698 const bool ignore_comments =
false)
24700 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
24703 template<
typename IteratorType>
24704 static bool accept(IteratorType first, IteratorType last,
24705 const bool ignore_comments =
false)
24707 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
24710 JSON_HEDLEY_WARN_UNUSED_RESULT
24711 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
24712 static bool accept(detail::span_input_adapter &&i,
24713 const bool ignore_comments =
false)
24715 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
24758 template <
typename InputType,
typename SAX>
24759 JSON_HEDLEY_NON_NULL(2)
24762 const
bool strict = true,
24763 const
bool ignore_comments = false)
24765 auto ia = detail::input_adapter(std::forward<InputType>(i));
24766 return format == input_format_t::json
24767 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24771 template<
class IteratorType,
class SAX>
24772 JSON_HEDLEY_NON_NULL(3)
24773 static
bool sax_parse(IteratorType first, IteratorType last, SAX *sax,
24774 input_format_t format = input_format_t::
json,
24775 const
bool strict = true,
24776 const
bool ignore_comments = false)
24778 auto ia = detail::input_adapter(std::move(first), std::move(last));
24779 return format == input_format_t::json
24780 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24784 template <
typename SAX>
24785 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
24786 JSON_HEDLEY_NON_NULL(2)
24787 static
bool sax_parse(detail::span_input_adapter &&i, SAX *sax,
24788 input_format_t format = input_format_t::
json,
24789 const
bool strict = true,
24790 const
bool ignore_comments = false)
24793 return format == input_format_t::json
24795 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24797 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24808 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream &,
basic_json &))
24841 parser(detail::input_adapter(i)).parse(
false, j);
24882 JSON_HEDLEY_RETURNS_NON_NULL
24907 return "discarded";
24919JSON_PRIVATE_UNLESS_TESTED:
24930#if JSON_DIAGNOSTICS
25043 std::vector<std::uint8_t> result;
25050 binary_writer<std::uint8_t>(o).write_cbor(j);
25055 binary_writer<char>(o).write_cbor(j);
25138 std::vector<std::uint8_t> result;
25145 binary_writer<std::uint8_t>(o).write_msgpack(j);
25150 binary_writer<char>(o).write_msgpack(j);
25240 const bool use_size =
false,
25241 const bool use_type =
false)
25243 std::vector<std::uint8_t> result;
25244 to_ubjson(j, result, use_size, use_type);
25249 const bool use_size =
false,
const bool use_type =
false)
25251 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
25255 const bool use_size =
false,
const bool use_type =
false)
25257 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
25319 std::vector<std::uint8_t> result;
25448 template<
typename InputType>
25449 JSON_HEDLEY_WARN_UNUSED_RESULT
25451 const bool strict =
true,
25452 const bool allow_exceptions =
true,
25457 auto ia = detail::input_adapter(std::forward<InputType>(i));
25465 template<
typename IteratorType>
25466 JSON_HEDLEY_WARN_UNUSED_RESULT
25468 const bool strict =
true,
25469 const bool allow_exceptions =
true,
25474 auto ia = detail::input_adapter(std::move(first), std::move(last));
25479 template<
typename T>
25480 JSON_HEDLEY_WARN_UNUSED_RESULT
25481 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
25483 const bool strict =
true,
25484 const bool allow_exceptions =
true,
25487 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
25491 JSON_HEDLEY_WARN_UNUSED_RESULT
25492 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
25494 const bool strict =
true,
25495 const bool allow_exceptions =
true,
25499 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25502 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25592 template<
typename InputType>
25593 JSON_HEDLEY_WARN_UNUSED_RESULT
25595 const bool strict =
true,
25596 const bool allow_exceptions =
true)
25600 auto ia = detail::input_adapter(std::forward<InputType>(i));
25608 template<
typename IteratorType>
25609 JSON_HEDLEY_WARN_UNUSED_RESULT
25611 const bool strict =
true,
25612 const bool allow_exceptions =
true)
25616 auto ia = detail::input_adapter(std::move(first), std::move(last));
25622 template<
typename T>
25623 JSON_HEDLEY_WARN_UNUSED_RESULT
25624 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25626 const bool strict =
true,
25627 const bool allow_exceptions =
true)
25629 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
25632 JSON_HEDLEY_WARN_UNUSED_RESULT
25633 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25635 const bool strict =
true,
25636 const bool allow_exceptions =
true)
25639 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25642 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25709 template<
typename InputType>
25710 JSON_HEDLEY_WARN_UNUSED_RESULT
25712 const bool strict =
true,
25713 const bool allow_exceptions =
true)
25717 auto ia = detail::input_adapter(std::forward<InputType>(i));
25725 template<
typename IteratorType>
25726 JSON_HEDLEY_WARN_UNUSED_RESULT
25728 const bool strict =
true,
25729 const bool allow_exceptions =
true)
25733 auto ia = detail::input_adapter(std::move(first), std::move(last));
25738 template<
typename T>
25739 JSON_HEDLEY_WARN_UNUSED_RESULT
25740 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25742 const bool strict =
true,
25743 const bool allow_exceptions =
true)
25745 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
25748 JSON_HEDLEY_WARN_UNUSED_RESULT
25749 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25751 const bool strict =
true,
25752 const bool allow_exceptions =
true)
25755 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25758 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25823 template<
typename InputType>
25824 JSON_HEDLEY_WARN_UNUSED_RESULT
25826 const bool strict =
true,
25827 const bool allow_exceptions =
true)
25831 auto ia = detail::input_adapter(std::forward<InputType>(i));
25839 template<
typename IteratorType>
25840 JSON_HEDLEY_WARN_UNUSED_RESULT
25842 const bool strict =
true,
25843 const bool allow_exceptions =
true)
25847 auto ia = detail::input_adapter(std::move(first), std::move(last));
25852 template<
typename T>
25853 JSON_HEDLEY_WARN_UNUSED_RESULT
25854 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25856 const bool strict =
true,
25857 const bool allow_exceptions =
true)
25859 return from_bson(ptr, ptr + len, strict, allow_exceptions);
25862 JSON_HEDLEY_WARN_UNUSED_RESULT
25863 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25865 const bool strict =
true,
25866 const bool allow_exceptions =
true)
25869 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25872 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
26161 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
26162 const auto get_op = [](
const std::string & op)
26166 return patch_operations::add;
26169 if (op ==
"remove")
26171 return patch_operations::remove;
26174 if (op ==
"replace")
26176 return patch_operations::replace;
26181 return patch_operations::move;
26186 return patch_operations::copy;
26191 return patch_operations::test;
26194 return patch_operations::invalid;
26209 if (top_pointer != ptr)
26211 result.
at(top_pointer);
26215 const auto last_path = ptr.
back();
26219 switch (parent.m_type)
26225 parent[last_path] = val;
26231 if (last_path ==
"-")
26241 if (JSON_HEDLEY_UNLIKELY(idx > parent.
size()))
26244 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
26263 JSON_ASSERT(
false);
26267 const auto operation_remove = [
this, &result](
json_pointer & ptr)
26270 const auto last_path = ptr.
back();
26278 auto it = parent.
find(last_path);
26280 if (JSON_HEDLEY_LIKELY(it != parent.
end()))
26287 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
26299 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
26301 JSON_THROW(
parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
26305 for (
const auto &val : json_patch)
26308 const auto get_value = [&val](
const std::string & op,
26309 const std::string & member,
26313 auto it = val.
m_value.object->find(member);
26316 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
26319 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
26322 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
26326 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
26329 JSON_THROW(
parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
26337 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
26343 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
26344 const auto path = get_value(op,
"path",
true).template get<std::string>();
26347 switch (get_op(op))
26349 case patch_operations::add:
26351 operation_add(ptr, get_value(
"add",
"value",
false));
26355 case patch_operations::remove:
26357 operation_remove(ptr);
26361 case patch_operations::replace:
26364 result.
at(ptr) = get_value(
"replace",
"value",
false);
26368 case patch_operations::move:
26370 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
26378 operation_remove(from_ptr);
26379 operation_add(ptr, v);
26383 case patch_operations::copy:
26385 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
26392 operation_add(ptr, v);
26396 case patch_operations::test:
26398 bool success =
false;
26403 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
26411 if (JSON_HEDLEY_UNLIKELY(!success))
26413 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
26419 case patch_operations::invalid:
26465 JSON_HEDLEY_WARN_UNUSED_RESULT
26467 const std::string &path =
"")
26473 if (source == target)
26478 if (source.
type() != target.
type())
26483 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26488 switch (source.
type())
26495 while (i < source.
size() && i < target.
size())
26498 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
26499 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26508 while (i < source.
size())
26515 {
"path", path +
"/" + std::to_string(i)}
26521 while (i < target.
size())
26526 {
"path", path +
"/-"},
26527 {
"value", target[i]}
26538 for (
auto it = source.
cbegin(); it != source.
cend(); ++it)
26543 if (target.
find(it.key()) != target.
end())
26546 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
26547 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26555 {
"op",
"remove"}, {
"path", path_key}
26561 for (
auto it = target.
cbegin(); it != target.
cend(); ++it)
26563 if (source.
find(it.key()) == source.
end())
26569 {
"op",
"add"}, {
"path", path_key},
26570 {
"value", it.value()}
26591 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26660 for (
auto it = apply_patch.
begin(); it != apply_patch.
end(); ++it)
26662 if (it.value().is_null())
26676 *
this = apply_patch;
26692NLOHMANN_BASIC_JSON_TPL_DECLARATION
26740#ifndef JSON_HAS_CPP_20
26749 is_nothrow_move_constructible<nlohmann::json>::value &&
26750 is_nothrow_move_assignable<nlohmann::json>::value
26773JSON_HEDLEY_NON_NULL(1)
26792JSON_HEDLEY_NON_NULL(1)
26793inline
nlohmann::
json::json_pointer operator "" _json_pointer(const
char *s,
std::
size_t n)
26802#if defined(__clang__)
26803#pragma clang diagnostic pop
26808#undef JSON_INTERNAL_CATCH
26812#undef JSON_PRIVATE_UNLESS_TESTED
26813#undef JSON_HAS_CPP_11
26814#undef JSON_HAS_CPP_14
26815#undef JSON_HAS_CPP_17
26816#undef JSON_HAS_CPP_20
26817#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
26818#undef NLOHMANN_BASIC_JSON_TPL
26819#undef JSON_EXPLICIT
26824#undef JSON_HEDLEY_ALWAYS_INLINE
26825#undef JSON_HEDLEY_ARM_VERSION
26826#undef JSON_HEDLEY_ARM_VERSION_CHECK
26827#undef JSON_HEDLEY_ARRAY_PARAM
26828#undef JSON_HEDLEY_ASSUME
26829#undef JSON_HEDLEY_BEGIN_C_DECLS
26830#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
26831#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
26832#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
26833#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
26834#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
26835#undef JSON_HEDLEY_CLANG_HAS_FEATURE
26836#undef JSON_HEDLEY_CLANG_HAS_WARNING
26837#undef JSON_HEDLEY_COMPCERT_VERSION
26838#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
26839#undef JSON_HEDLEY_CONCAT
26840#undef JSON_HEDLEY_CONCAT3
26841#undef JSON_HEDLEY_CONCAT3_EX
26842#undef JSON_HEDLEY_CONCAT_EX
26843#undef JSON_HEDLEY_CONST
26844#undef JSON_HEDLEY_CONSTEXPR
26845#undef JSON_HEDLEY_CONST_CAST
26846#undef JSON_HEDLEY_CPP_CAST
26847#undef JSON_HEDLEY_CRAY_VERSION
26848#undef JSON_HEDLEY_CRAY_VERSION_CHECK
26849#undef JSON_HEDLEY_C_DECL
26850#undef JSON_HEDLEY_DEPRECATED
26851#undef JSON_HEDLEY_DEPRECATED_FOR
26852#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
26853#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
26854#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
26855#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
26856#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
26857#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
26858#undef JSON_HEDLEY_DIAGNOSTIC_POP
26859#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
26860#undef JSON_HEDLEY_DMC_VERSION
26861#undef JSON_HEDLEY_DMC_VERSION_CHECK
26862#undef JSON_HEDLEY_EMPTY_BASES
26863#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
26864#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
26865#undef JSON_HEDLEY_END_C_DECLS
26866#undef JSON_HEDLEY_FLAGS
26867#undef JSON_HEDLEY_FLAGS_CAST
26868#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
26869#undef JSON_HEDLEY_GCC_HAS_BUILTIN
26870#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
26871#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
26872#undef JSON_HEDLEY_GCC_HAS_EXTENSION
26873#undef JSON_HEDLEY_GCC_HAS_FEATURE
26874#undef JSON_HEDLEY_GCC_HAS_WARNING
26875#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
26876#undef JSON_HEDLEY_GCC_VERSION
26877#undef JSON_HEDLEY_GCC_VERSION_CHECK
26878#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
26879#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
26880#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
26881#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
26882#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
26883#undef JSON_HEDLEY_GNUC_HAS_FEATURE
26884#undef JSON_HEDLEY_GNUC_HAS_WARNING
26885#undef JSON_HEDLEY_GNUC_VERSION
26886#undef JSON_HEDLEY_GNUC_VERSION_CHECK
26887#undef JSON_HEDLEY_HAS_ATTRIBUTE
26888#undef JSON_HEDLEY_HAS_BUILTIN
26889#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
26890#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
26891#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
26892#undef JSON_HEDLEY_HAS_EXTENSION
26893#undef JSON_HEDLEY_HAS_FEATURE
26894#undef JSON_HEDLEY_HAS_WARNING
26895#undef JSON_HEDLEY_IAR_VERSION
26896#undef JSON_HEDLEY_IAR_VERSION_CHECK
26897#undef JSON_HEDLEY_IBM_VERSION
26898#undef JSON_HEDLEY_IBM_VERSION_CHECK
26899#undef JSON_HEDLEY_IMPORT
26900#undef JSON_HEDLEY_INLINE
26901#undef JSON_HEDLEY_INTEL_CL_VERSION
26902#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
26903#undef JSON_HEDLEY_INTEL_VERSION
26904#undef JSON_HEDLEY_INTEL_VERSION_CHECK
26905#undef JSON_HEDLEY_IS_CONSTANT
26906#undef JSON_HEDLEY_IS_CONSTEXPR_
26907#undef JSON_HEDLEY_LIKELY
26908#undef JSON_HEDLEY_MALLOC
26909#undef JSON_HEDLEY_MCST_LCC_VERSION
26910#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
26911#undef JSON_HEDLEY_MESSAGE
26912#undef JSON_HEDLEY_MSVC_VERSION
26913#undef JSON_HEDLEY_MSVC_VERSION_CHECK
26914#undef JSON_HEDLEY_NEVER_INLINE
26915#undef JSON_HEDLEY_NON_NULL
26916#undef JSON_HEDLEY_NO_ESCAPE
26917#undef JSON_HEDLEY_NO_RETURN
26918#undef JSON_HEDLEY_NO_THROW
26919#undef JSON_HEDLEY_NULL
26920#undef JSON_HEDLEY_PELLES_VERSION
26921#undef JSON_HEDLEY_PELLES_VERSION_CHECK
26922#undef JSON_HEDLEY_PGI_VERSION
26923#undef JSON_HEDLEY_PGI_VERSION_CHECK
26924#undef JSON_HEDLEY_PREDICT
26925#undef JSON_HEDLEY_PRINTF_FORMAT
26926#undef JSON_HEDLEY_PRIVATE
26927#undef JSON_HEDLEY_PUBLIC
26928#undef JSON_HEDLEY_PURE
26929#undef JSON_HEDLEY_REINTERPRET_CAST
26930#undef JSON_HEDLEY_REQUIRE
26931#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
26932#undef JSON_HEDLEY_REQUIRE_MSG
26933#undef JSON_HEDLEY_RESTRICT
26934#undef JSON_HEDLEY_RETURNS_NON_NULL
26935#undef JSON_HEDLEY_SENTINEL
26936#undef JSON_HEDLEY_STATIC_ASSERT
26937#undef JSON_HEDLEY_STATIC_CAST
26938#undef JSON_HEDLEY_STRINGIFY
26939#undef JSON_HEDLEY_STRINGIFY_EX
26940#undef JSON_HEDLEY_SUNPRO_VERSION
26941#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
26942#undef JSON_HEDLEY_TINYC_VERSION
26943#undef JSON_HEDLEY_TINYC_VERSION_CHECK
26944#undef JSON_HEDLEY_TI_ARMCL_VERSION
26945#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
26946#undef JSON_HEDLEY_TI_CL2000_VERSION
26947#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
26948#undef JSON_HEDLEY_TI_CL430_VERSION
26949#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
26950#undef JSON_HEDLEY_TI_CL6X_VERSION
26951#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
26952#undef JSON_HEDLEY_TI_CL7X_VERSION
26953#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
26954#undef JSON_HEDLEY_TI_CLPRU_VERSION
26955#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
26956#undef JSON_HEDLEY_TI_VERSION
26957#undef JSON_HEDLEY_TI_VERSION_CHECK
26958#undef JSON_HEDLEY_UNAVAILABLE
26959#undef JSON_HEDLEY_UNLIKELY
26960#undef JSON_HEDLEY_UNPREDICTABLE
26961#undef JSON_HEDLEY_UNREACHABLE
26962#undef JSON_HEDLEY_UNREACHABLE_RETURN
26963#undef JSON_HEDLEY_VERSION
26964#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
26965#undef JSON_HEDLEY_VERSION_DECODE_MINOR
26966#undef JSON_HEDLEY_VERSION_DECODE_REVISION
26967#undef JSON_HEDLEY_VERSION_ENCODE
26968#undef JSON_HEDLEY_WARNING
26969#undef JSON_HEDLEY_WARN_UNUSED_RESULT
26970#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG
26971#undef JSON_HEDLEY_FALL_THROUGH
void insert(const_iterator first, const_iterator last)
inserts elements
array_t * get_impl_ptr(array_t *) noexcept
get a pointer to the value (array)
detail::parser_callback_t< basic_json > parser_callback_t
per-element parser callback type
bool contains(KeyT &&key) const
check the existence of an element in a JSON object
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
const_reverse_iterator crbegin() const noexcept
returns a const reverse iterator to the last element
constexpr const number_unsigned_t * get_impl_ptr(const number_unsigned_t *) const noexcept
get a pointer to the value (unsigned number)
number_unsigned_t number_unsigned
number (unsigned integer)
const_reference operator[](const json_pointer &ptr) const
access specified element via JSON Pointer
reference operator[](const json_pointer &ptr)
access specified element via JSON Pointer
friend bool operator==(const_reference lhs, ScalarType rhs) noexcept
comparison: equal
ValueType value(const typename object_t::key_type &key, const ValueType &default_value) const
access specified object element with default value
constexpr bool is_number_float() const noexcept
return whether value is a floating-point number
NumberIntegerType number_integer_t
a type for a number (integer)
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
comparison: equal
NLOHMANN_BASIC_JSON_TPL basic_json_t
workaround type for MSVC
static bool sax_parse(InputType &&i, SAX *sax, input_format_t format=input_format_t::json, const bool strict=true, const bool ignore_comments=false)
generate SAX events
ReferenceType get_ref()
get a reference value (implicit)
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
reference emplace_back(Args &&... args)
add an object to an array
const_iterator find(KeyT &&key) const
find an element in a JSON object
basic_json(const value_t v)
create an empty value with a given type
object_t * get_impl_ptr(object_t *) noexcept
get a pointer to the value (object)
size_type max_size() const noexcept
returns the maximum possible number of elements
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
static std::vector< std::uint8_t > to_bson(const basic_json &j)
Serializes the given JSON object j to BSON and returns a vector containing the corresponding BSON-rep...
value_type & reference
the type of an element reference
void erase(const size_type idx)
remove element from a JSON array given an index
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
const_reference at(const typename object_t::key_type &key) const
access specified object element with bounds checking
reference at(const typename object_t::key_type &key)
access specified object element with bounds checking
iterator begin() noexcept
returns an iterator to the first element
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
friend bool operator==(ScalarType lhs, const_reference rhs) noexcept
comparison: equal
json_value(object_t &&value)
constructor for rvalue objects
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
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)
copy assignment
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
json_value(number_float_t v) noexcept
constructor for numbers (floating-point)
const_reverse_iterator rend() const noexcept
returns a const reverse iterator to one before the first
void assert_invariant(bool check_parents=true) const noexcept
checks the class invariants
json_value(string_t &&value)
constructor for rvalue strings
const_iterator cend() const noexcept
returns a const iterator to one past the last element
json_value(number_integer_t v) noexcept
constructor for numbers (integer)
number_unsigned_t * get_impl_ptr(number_unsigned_t *) noexcept
get a pointer to the value (unsigned number)
reference back()
access the last element
boolean_t * get_impl_ptr(boolean_t *) noexcept
get a pointer to the value (boolean)
const binary_t & get_binary() const
constexpr const boolean_t * get_impl_ptr(const boolean_t *) const noexcept
get a pointer to the value (boolean)
static bool accept(InputType &&i, const bool ignore_comments=false)
check if the input is valid JSON
StringType string_t
a type for a string
size_type size() const noexcept
returns the number of elements
void push_back(const basic_json &val)
add an object to an array
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json meta()
returns version information on the library
ValueType value(const json_pointer &ptr, const ValueType &default_value) const
access specified object element via JSON Pointer with default value
void update(const_reference j)
updates a JSON object from another object, overwriting existing keys
std::size_t size_type
a type to represent container sizes
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
std::ptrdiff_t difference_type
a type to represent differences between iterators
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
reference operator[](const typename object_t::key_type &key)
access specified object element
json_value(number_unsigned_t v) noexcept
constructor for numbers (unsigned)
reference operator+=(basic_json &&val)
add an object to an array
basic_json(const BasicJsonType &val)
create a JSON value from an existing one
typename std::allocator_traits< allocator_type >::const_pointer const_pointer
the type of an element const pointer
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.
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
constexpr const binary_t * get_impl_ptr(const binary_t *) const noexcept
get a pointer to the value (binary)
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
BooleanType boolean_t
a type for a boolean
void push_back(initializer_list_t init)
add an object to an object
boolean_t get_impl(boolean_t *) const
get a boolean (explicit)
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
IteratorType erase(IteratorType pos)
remove element given an iterator
static void to_bson(const basic_json &j, detail::output_adapter< std::uint8_t > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept
comparison: not equal
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.
constexpr bool is_structured() const noexcept
return whether type is structured
friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept
comparison: less than or equal
const_iterator begin() const noexcept
returns a const iterator to the first element
friend bool operator<(const_reference lhs, ScalarType rhs) noexcept
comparison: less than
reference at(size_type idx)
access specified array element with bounds checking
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)
reference front()
access the first element
constexpr bool is_primitive() const noexcept
return whether type is primitive
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
void swap(object_t &other)
exchanges the values
constexpr bool is_object() const noexcept
return whether value is an object
const_reference front() const
access the first element
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
NumberFloatType number_float_t
a type for a number (floating-point)
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
bool empty() const noexcept
checks whether the container is empty.
json_value(value_t t)
constructor for empty values of a given type
basic_json(const basic_json &other)
copy constructor
~basic_json() noexcept
destructor
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
basic_json(basic_json &&other) noexcept
move constructor
friend bool operator>(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than
BasicJsonType get_impl(detail::priority_tag< 2 >) const
get special-case overload
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
inserts elements
friend bool operator<(ScalarType lhs, const_reference rhs) noexcept
comparison: less than
json_value m_value
the value of the current element
void swap(typename binary_t::container_type &other)
exchanges the values
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
void swap(array_t &other)
exchanges the values
ValueType get_impl(detail::priority_tag< 0 >) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), std::declval< ValueType & >())))
get a value (explicit)
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
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)
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
json_value(const string_t &value)
constructor for strings
json_value(const binary_t &value)
constructor for binary arrays (internal type)
ReferenceType get_ref() const
get a reference value (implicit)
json_value(const array_t &value)
constructor for arrays
iterator insert(const_iterator pos, const_iterator first, const_iterator last)
inserts elements
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
const_reference at(const json_pointer &ptr) const
access specified element via JSON Pointer
const_iterator end() const noexcept
returns a const iterator to one past the last element
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
auto get_ptr() noexcept -> decltype(std::declval< basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
iteration_proxy< const_iterator > items() const noexcept
helper to access iterator member functions in range-based for
iterator insert(const_iterator pos, initializer_list_t ilist)
inserts elements
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
constexpr const number_integer_t * get_impl_ptr(const number_integer_t *) const noexcept
get a pointer to the value (integer number)
constexpr const string_t * get_impl_ptr(const string_t *) const noexcept
get a pointer to the value (string)
json_value(const object_t &value)
constructor for objects
IteratorType erase(IteratorType first, IteratorType last)
remove elements given an iterator range
json_value(typename binary_t::container_type &&value)
constructor for rvalue binary arrays
json_value(boolean_t v) noexcept
constructor for booleans
constexpr bool is_boolean() const noexcept
return whether value is a boolean
iterator end() noexcept
returns an iterator to one past the last element
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
void clear() noexcept
clears the contents
friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept
comparison: greater than or equal
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
constexpr bool is_binary() const noexcept
return whether value is a binary array
static JSON_HEDLEY_RETURNS_NON_NULL T * create(Args &&... args)
helper for exception-safe object creation
binary_t * binary
binary (stored with pointer to save storage)
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
iterator insert(const_iterator pos, basic_json &&val)
inserts element
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
reference operator[](size_type idx)
access specified array element
friend bool operator>(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than
static void to_bson(const basic_json &j, detail::output_adapter< char > o)
Serializes the given JSON object j to BSON and forwards the corresponding BSON-representation to the ...
void update(const_iterator first, const_iterator last)
updates a JSON object from another object, overwriting existing keys
reference at(const json_pointer &ptr)
access specified element via JSON Pointer
void swap(binary_t &other)
exchanges the values
iter_impl< basic_json > iterator
an iterator for a basic_json container
json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
a const reverse iterator for a basic_json container
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
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept
comparison: not equal
const_reverse_iterator rbegin() const noexcept
returns a const reverse iterator to the last element
void swap(string_t &other)
exchanges the values
const_reference back() const
access the last element
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
ValueType get_impl(detail::priority_tag< 1 >) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >())))
get a value (explicit); special case
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json binary(typename binary_t::container_type &&init)
explicitly create a binary array (without subtype)
constexpr bool is_string() const noexcept
return whether value is a string
number_integer_t * get_impl_ptr(number_integer_t *) noexcept
get a pointer to the value (integer number)
constexpr bool is_array() const noexcept
return whether value is an array
iterator insert_iterator(const_iterator pos, Args &&... args)
Helper for insertion of an iterator.
basic_json flatten() const
return flattened JSON value
constexpr const number_float_t * get_impl_ptr(const number_float_t *) const noexcept
get a pointer to the value (floating-point number)
constexpr const array_t * get_impl_ptr(const array_t *) const noexcept
get a pointer to the value (array)
friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept
comparison: greater than or equal
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
void push_back(basic_json &&val)
add an object to an array
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
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
json_value(const typename binary_t::container_type &value)
constructor for binary arrays
constexpr bool is_number() const noexcept
return whether value is a number
number_float_t number_float
number (floating-point)
string_t * get_impl_ptr(string_t *) noexcept
get a pointer to the value (string)
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
string_t * string
string (stored with pointer to save storage)
reference operator+=(initializer_list_t init)
add an object to an object
constexpr bool is_number_integer() const noexcept
return whether value is an integer number
std::initializer_list< detail::json_ref< basic_json > > initializer_list_t
helper type for initializer lists of basic_json values
number_float_t * get_impl_ptr(number_float_t *) noexcept
get a pointer to the value (floating-point number)
json_value(binary_t &&value)
constructor for rvalue binary arrays (internal type)
const_reference operator[](const typename object_t::key_type &key) const
read-only access specified object element
iterator find(KeyT &&key)
find an element in a JSON object
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
const_reference operator[](size_type idx) const
access specified array element
array_t * array
array (stored with pointer to save storage)
AllocatorType< basic_json > allocator_type
the allocator type
basic_json get_impl(detail::priority_tag< 3 >) const
get special-case overload
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
void push_back(const typename object_t::value_type &val)
add an object to an object
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(IteratorType first, IteratorType last, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a pair of character iterators
number_integer_t number_integer
number (integer)
bool contains(const json_pointer &ptr) const
check the existence of an element in a JSON object given a JSON pointer
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
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
string_t value(const typename object_t::key_type &key, const char *default_value) const
overload for a default value of type const char*
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
basic_json unflatten() const
unflatten a previously flattened JSON value
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
reference operator+=(const typename object_t::value_type &val)
add an object to an object
const_iterator cbegin() const noexcept
returns a const iterator to the first element
friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept
comparison: less than or equal
friend std::istream & operator>>(std::istream &i, basic_json &j)
deserialize from stream
json_value(array_t &&value)
constructor for rvalue arrays
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
const_reference at(size_type idx) const
access specified array element with bounds checking
iterator insert(const_iterator pos, const basic_json &val)
inserts element
constexpr bool is_discarded() const noexcept
return whether value is discarded
constexpr auto get_impl(detail::priority_tag< 4 >) const noexcept -> decltype(std::declval< const basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
constexpr bool is_null() const noexcept
return whether value is null
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
binary_t * get_impl_ptr(binary_t *) noexcept
get a pointer to the value (binary)
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > > > object_t
a type for an object
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)
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
reference operator+=(const basic_json &val)
add an object to an array
size_type erase(const typename object_t::key_type &key)
remove element from a JSON object given a key
static ReferenceType get_ref_impl(ThisType &obj)
helper function to implement get_ref()
basic_json(size_type cnt, const basic_json &val)
construct an array with count copies of given value
static allocator_type get_allocator()
returns the allocator associated with the container
constexpr const object_t * get_impl_ptr(const object_t *) const noexcept
get a pointer to the value (object)
constexpr auto get_ptr() const noexcept -> decltype(std::declval< const basic_json_t & >().get_impl_ptr(std::declval< PointerType >()))
get a pointer value (implicit)
reverse_iterator rbegin() noexcept
returns an iterator to the reverse-beginning
a class to store JSON values
json_value()=default
default constructor (for null values)
BinaryType container_type
the type of the underlying container
void clear_subtype() noexcept
clears the binary subtype
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
void set_subtype(subtype_type subtype_) noexcept
sets the binary subtype
constexpr subtype_type subtype() const noexcept
return the binary subtype
std::uint64_t subtype_type
the type of the subtype
an internal type for a backed binary type
bool get_msgpack_array(const std::size_t len)
bool get_bson_string(const NumberType len, string_t &result)
Parses a zero-terminated string of length len from the BSON input.
bool parse_bson_element_internal(const char_int_type element_type, const std::size_t element_type_parse_position)
Read a BSON document element of the given element_type.
bool parse_bson_array()
Reads an array from the BSON input and passes it to the SAX-parser.
char_int_type get_ignore_noop()
binary_reader(InputAdapterType &&adapter) noexcept
create a binary reader
bool get_bson_cstr(string_t &result)
Parses a C-style string from the BSON input.
bool get_cbor_array(const std::size_t len, const cbor_tag_handler_t tag_handler)
bool get_msgpack_binary(binary_t &result)
reads a MessagePack byte array
bool get_cbor_object(const std::size_t len, const cbor_tag_handler_t tag_handler)
bool get_ubjson_string(string_t &result, const bool get_char=true)
reads a UBJSON string
bool parse_bson_element_list(const bool is_array)
Read a BSON element list (as specified in the BSON-spec)
bool parse_cbor_internal(const bool get_char, const cbor_tag_handler_t tag_handler)
bool get_string(const input_format_t format, const NumberType len, string_t &result)
create a string by reading characters from the input
bool get_cbor_string(string_t &result)
reads a CBOR string
InputAdapterType ia
input adapter
bool get_binary(const input_format_t format, const NumberType len, binary_t &result)
create a byte array by reading bytes from the input
bool parse_ubjson_internal(const bool get_char=true)
bool unexpect_eof(const input_format_t format, const char *context) const
bool get_ubjson_size_type(std::pair< std::size_t, char_int_type > &result)
determine the type and size for a container
std::string get_token_string() const
bool get_ubjson_value(const char_int_type prefix)
bool get_msgpack_object(const std::size_t len)
bool get_bson_binary(const NumberType len, binary_t &result)
Parses a byte array input of length len from the BSON input.
std::string exception_message(const input_format_t format, const std::string &detail, const std::string &context) const
std::size_t chars_read
the number of characters read
char_int_type current
the current character
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)
json_sax_t * sax
the SAX parser
bool get_ubjson_size_value(std::size_t &result)
bool parse_bson_internal()
Reads in a BSON-object and passes it to the SAX-parser.
bool get_cbor_binary(binary_t &result)
reads a CBOR byte array
char_int_type get()
get next character from the input
const bool is_little_endian
whether we can assume little endianess
bool get_msgpack_string(string_t &result)
reads a MessagePack string
bool parse_msgpack_internal()
deserialization of CBOR, MessagePack, and UBJSON values
void write_bson_array(const string_t &name, const typename BasicJsonType::array_t &value)
Writes a BSON element with key name and array value.
const bool is_little_endian
whether we can assume little endianess
void write_ubjson(const BasicJsonType &j, const bool use_count, const bool use_type, const bool add_prefix=true)
static std::size_t calc_bson_entry_header_size(const string_t &name, const BasicJsonType &j)
void write_bson_entry_header(const string_t &name, const std::uint8_t element_type)
Writes the given element_type and name to the output adapter.
static std::size_t calc_bson_element_size(const string_t &name, const BasicJsonType &j)
Calculates the size necessary to serialize the JSON value j with its name.
void write_bson_double(const string_t &name, const double value)
Writes a BSON element with key name and double value value.
void write_bson_object(const typename BasicJsonType::object_t &value)
binary_writer(output_adapter_t< CharType > adapter)
create a binary writer
CharType ubjson_prefix(const BasicJsonType &j) const noexcept
determine the type prefix of container values
void write_bson_integer(const string_t &name, const std::int64_t value)
Writes a BSON element with key name and integer value.
void write_bson_string(const string_t &name, const string_t &value)
Writes a BSON element with key name and string value value.
void write_bson_object_entry(const string_t &name, const typename BasicJsonType::object_t &value)
Writes a BSON element with key name and object value.
output_adapter_t< CharType > oa
the output
void write_bson_element(const string_t &name, const BasicJsonType &j)
Serializes the JSON value j to BSON and associates it with the key name.
void write_bson_binary(const string_t &name, const binary_t &value)
Writes a BSON element with key name and binary value value.
void write_bson_null(const string_t &name)
Writes a BSON element with key name and null value.
static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t &value)
void write_bson(const BasicJsonType &j)
void write_cbor(const BasicJsonType &j)
static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept
void write_bson_unsigned(const string_t &name, const BasicJsonType &j)
Writes a BSON element with key name and unsigned value.
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t &value)
Calculates the size of the BSON serialization of the given JSON-object j.
void write_bson_boolean(const string_t &name, const bool value)
Writes a BSON element with key name and boolean value value.
void write_msgpack(const BasicJsonType &j)
static std::size_t calc_bson_string_size(const string_t &value)
static std::size_t calc_bson_integer_size(const std::int64_t value)
static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t &value)
serialization to CBOR and MessagePack values
const int id
the id of the exception
std::runtime_error m
an exception object as storage for error messages
const char * what() const noexcept override
returns the explanatory string
general exception of the basic_json class
exception indicating errors with iterators
bool operator<(const iter_impl &other) const
comparison: smaller
iter_impl operator-(difference_type i) const
subtract from iterator
bool operator!=(const IterImpl &other) const
comparison: not equal
iter_impl const operator--(int)
post-decrement (it–)
void set_end() noexcept
set the iterator past the last value
typename BasicJsonType::difference_type difference_type
a type to represent differences between iterators
iter_impl & operator--()
pre-decrement (–it)
difference_type operator-(const iter_impl &other) const
return difference
iter_impl & operator=(const iter_impl< const BasicJsonType > &other) noexcept
converting assignment
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)
reference operator*() const
return a reference to the value pointed to by the iterator
bool operator>=(const iter_impl &other) const
comparison: greater than or equal
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)
iter_impl & operator=(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting assignment
pointer operator->() const
dereference the iterator
iter_impl(const iter_impl< const BasicJsonType > &other) noexcept
const copy constructor
iter_impl const operator++(int)
post-increment (it++)
iter_impl(const iter_impl< typename std::remove_const< BasicJsonType >::type > &other) noexcept
converting constructor
internal_iterator< typename std::remove_const< BasicJsonType >::type > m_it
the actual iterator of the associated instance
iter_impl operator+(difference_type i) const
add to iterator
friend iter_impl operator+(difference_type i, const iter_impl &it)
addition of distance and iterator
const object_t::key_type & key() const
return the key of an object iterator
bool operator==(const IterImpl &other) const
comparison: equal
bool operator>(const iter_impl &other) const
comparison: greater than
typename BasicJsonType::value_type value_type
the type of the values when the iterator is dereferenced
reference value() const
return the value of an iterator
friend other_iter_impl
allow basic_json to access private members
iter_impl & operator++()
pre-increment (++it)
reference operator[](difference_type n) const
access to successor
bool operator<=(const iter_impl &other) const
comparison: less than or equal
std::bidirectional_iterator_tag iterator_category
The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17.
iter_impl & operator+=(difference_type i)
add to iterator
iter_impl & operator-=(difference_type i)
subtract from iterator
a template for a bidirectional iterator for the basic_json class This class implements a both iterato...
IteratorType anchor
the iterator
const string_type empty_str
an empty string (to return a reference for primitive values)
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
std::size_t array_index_last
last stringified array index
string_type array_index_str
a string representation of the array index
IteratorType::reference value() const
return value of the iterator
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
std::size_t array_index
an index for arrays (used to create key names)
iteration_proxy_value & operator*()
dereference operator (needed for range-based for)
const string_type & key() const
return key of the iterator
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
iteration_proxy_value< IteratorType > begin() noexcept
return iterator begin (needed for range-based for)
iteration_proxy_value< IteratorType > end() noexcept
return iterator end (needed for range-based for)
IteratorType::reference container
the container to iterate
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
proxy class for the items() function
json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
create reverse iterator from iterator
json_reverse_iterator const operator--(int)
post-decrement (it–)
typename Base::reference reference
the reference type for the pointed-to element
json_reverse_iterator operator-(difference_type i) const
subtract from iterator
json_reverse_iterator & operator+=(difference_type i)
add to iterator
std::reverse_iterator< Base > base_iterator
shortcut to the reverse iterator adapter
json_reverse_iterator(const base_iterator &it) noexcept
create reverse iterator from base class
reference operator[](difference_type n) const
access to successor
difference_type operator-(const json_reverse_iterator &other) const
return difference
json_reverse_iterator operator+(difference_type i) const
add to iterator
json_reverse_iterator const operator++(int)
post-increment (it++)
auto key() const -> decltype(std::declval< Base >().key())
return the key of an object iterator
json_reverse_iterator & operator--()
pre-decrement (–it)
reference value() const
return the value of an iterator
json_reverse_iterator & operator++()
pre-increment (++it)
a template for a reverse iterator class
std::pair< bool, BasicJsonType * > handle_value(Value &&v, const bool skip_callback=false)
BasicJsonType & root
the parsed JSON value
JSON_HEDLEY_RETURNS_NON_NULL BasicJsonType * handle_value(Value &&v)
BasicJsonType & root
the parsed JSON value
json_sax_dom_parser(BasicJsonType &r, const bool allow_exceptions_=true)
SAX implementation to create a JSON value from SAX events.
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)
token_type
token types for the parser
@ value_float
an floating point number – use get_number_float() for actual value
@ begin_array
the character for array begin [
@ value_string
a string – use get_string() for actual value
@ end_array
the character for array end ]
@ uninitialized
indicating the scanner is uninitialized
@ parse_error
indicating a parse error
@ value_integer
a signed integer – use get_number_integer() for actual value
@ value_separator
the value separator ,
@ end_object
the character for object end }
@ literal_true
the true literal
@ begin_object
the character for object begin {
@ value_unsigned
an unsigned integer – use get_number_unsigned() for actual value
@ literal_null
the null literal
@ end_of_input
indicating the end of the input buffer
@ name_separator
the name separator :
@ literal_or_value
a literal or the begin of a value (only for diagnostics)
@ literal_false
the false literal
string_t & get_string()
return current string value (implicitly resets the token; useful only once)
const bool ignore_comments
whether comments should be ignored (true) or signaled as errors (false)
void add(char_int_type c)
add a character to token_buffer
void reset() noexcept
reset token_buffer; current character is beginning of token
bool next_unget
whether the next get() call should just return current
char_int_type current
the current character
static JSON_HEDLEY_PURE char get_decimal_point() noexcept
return the locale-dependent decimal point
InputAdapterType ia
input adapter
const char_int_type decimal_point_char
the decimal point
bool skip_bom()
skip the UTF-8 byte order mark
const char * error_message
a description of occurred lexer errors
position_t position
the start position of the current token
constexpr position_t get_position() const noexcept
return position of last read token
std::vector< char_type > token_string
raw input token string (for error messages)
constexpr number_integer_t get_number_integer() const noexcept
return integer value
token_type scan_number()
scan a number literal
void unget()
unget current character (read it again on next get)
token_type scan_string()
scan a string literal
constexpr number_unsigned_t get_number_unsigned() const noexcept
return unsigned integer value
string_t token_buffer
buffer for variable-length tokens (numbers, strings)
token_type scan_literal(const char_type *literal_text, const std::size_t length, token_type return_type)
constexpr number_float_t get_number_float() const noexcept
return floating-point value
int get_codepoint()
get codepoint from 4 hex characters following \u
std::string get_token_string() const
return the last read token (for errors only).
bool next_byte_in_range(std::initializer_list< char_int_type > ranges)
check if the next byte(s) are inside a given range
bool scan_comment()
scan a comment
JSON_HEDLEY_RETURNS_NON_NULL constexpr const char * get_error_message() const noexcept
return syntax error message
exception indicating other library errors
exception indicating access out of the defined range
output adapter for output streams
output adapter for basic_string
output adapter for byte vectors
const std::size_t byte
byte index of the parse error
static parse_error create(int id_, const position_t &pos, const std::string &what_arg, const BasicJsonType &context)
create a parse error exception
exception indicating a parse error
token_type get_token()
get next token from lexer
token_type last_token
the type of the last read token
parser(InputAdapterType &&adapter, const parser_callback_t< BasicJsonType > cb=nullptr, const bool allow_exceptions_=true, const bool skip_comments=false)
a parser reading from an input adapter
bool accept(const bool strict=true)
public accept interface
const parser_callback_t< BasicJsonType > callback
callback function
void parse(const bool strict, BasicJsonType &result)
public parser interface
const bool allow_exceptions
whether to throw exceptions in case of errors
constexpr bool is_end() const noexcept
return whether the iterator is at end
constexpr bool is_begin() const noexcept
return whether the iterator can be dereferenced
void set_begin() noexcept
set iterator to a defined beginning
void set_end() noexcept
set iterator to a defined past the end
const error_handler_t error_handler
error_handler how to react on decoding errors
const std::lconv * loc
the locale
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
const char decimal_point
the locale's decimal point character
const char thousands_sep
the locale's thousand separator character
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
const char indent_char
the indentation character
std::array< char, 512 > string_buffer
string buffer
serializer(output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
string_t indent_string
the indentation string
exception indicating executing a member function with a wrong type
std::vector< std::string > reference_tokens
the reference tokens
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
json_pointer & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
std::string to_string() const
return a string representation of the JSON pointer
const BasicJsonType & get_unchecked(const BasicJsonType *ptr) const
return a const reference to the pointed to value
friend bool operator==(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for equality
void pop_back()
remove last reference token
const std::string & back() const
return last reference token
const BasicJsonType & get_checked(const BasicJsonType *ptr) const
bool empty() const noexcept
return whether pointer points to the root document
friend bool operator!=(json_pointer const &lhs, json_pointer const &rhs) noexcept
compares two JSON pointers for inequality
void push_back(const std::string &token)
append an unescaped token at the end of the reference pointer
json_pointer(const std::string &s="")
create JSON pointer
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
bool contains(const BasicJsonType *ptr) const
static BasicJsonType unflatten(const BasicJsonType &value)
friend json_pointer operator/(const json_pointer &ptr, std::string token)
create a new JSON pointer by appending the unescaped token at the end of the JSON pointer
BasicJsonType & get_and_create(BasicJsonType &j) const
create and return a reference to the pointed to value
static void flatten(const std::string &reference_string, const BasicJsonType &value, BasicJsonType &result)
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
BasicJsonType & get_checked(BasicJsonType *ptr) const
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
static BasicJsonType::size_type array_index(const std::string &s)
BasicJsonType & get_unchecked(BasicJsonType *ptr) const
return a reference to the pointed to value
friend json_pointer operator/(const json_pointer &ptr, std::size_t array_idx)
create a new JSON pointer by appending the array-index-token at the end of the JSON pointer
json_pointer parent_pointer() const
returns the parent of this JSON pointer
static std::vector< std::string > split(const std::string &reference_string)
split the string input to reference tokens
void grisu2(char *buf, int &len, int &decimal_exponent, diyfp m_minus, diyfp v, diyfp m_plus)
JSON_HEDLEY_RETURNS_NON_NULL char * format_buffer(char *buf, int len, int decimal_exponent, int min_exp, int max_exp)
prettify v = buf * 10^decimal_exponent
boundaries compute_boundaries(FloatType value)
int find_largest_pow10(const std::uint32_t n, std::uint32_t &pow10)
JSON_HEDLEY_RETURNS_NON_NULL char * append_exponent(char *buf, int e)
appends a decimal representation of e to buf
void grisu2_digit_gen(char *buffer, int &length, int &decimal_exponent, diyfp M_minus, diyfp w, diyfp M_plus)
cached_power get_cached_power_for_binary_exponent(int e)
bool operator<(const value_t lhs, const value_t rhs) noexcept
comparison operator for JSON types
static void unescape(std::string &s)
string unescaping as described in RFC 6901 (Sect. 4)
value_t
the JSON type enumeration
@ 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)
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
cbor_tag_handler_t
how to treat CBOR tags
@ store
store tags as binary type
@ error
throw a parse_error exception in case of a tag
@ value
the parser finished reading a JSON value
@ key
the parser read a key of a value in an object
@ array_end
the parser read ] and finished processing a JSON array
@ array_start
the parser read [ and started to process a JSON array
@ object_start
the parser read { and started to process a JSON object
@ object_end
the parser read } and finished processing a JSON object
error_handler_t
how to treat decoding errors
@ strict
throw a type_error exception in case of invalid UTF-8
@ ignore
ignore invalid UTF-8 sequences
@ replace
replace invalid UTF-8 sequences with U+FFFD
std::size_t hash(const BasicJsonType &j)
hash a JSON value
std::shared_ptr< output_adapter_protocol< CharType > > output_adapter_t
a type to simplify interfaces
std::string escape(std::string s)
string escaping as described in RFC 6901 (Sect. 4)
input_format_t
the supported input formats
void replace_substring(std::string &s, const std::string &f, const std::string &t)
replace all occurrences of a substring by another string
static bool little_endianess(int num=1) noexcept
determine system byte order
primitive_iterator_t primitive_iterator
generic iterator for all other types
BasicJsonType::array_t::iterator array_iterator
iterator for JSON arrays
BasicJsonType::object_t::iterator object_iterator
iterator for JSON objects
basic_json<> json
default JSON class
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
namespace for Niels Lohmann
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
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
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
default JSONSerializer template argument
static diyfp normalize(diyfp x) noexcept
normalize x such that the significand is >= 2^(q-1)
static diyfp normalize_to(const diyfp &x, const int target_exponent) noexcept
normalize x such that the result has the exponent E
static diyfp mul(const diyfp &x, const diyfp &y) noexcept
returns x * y
static diyfp sub(const diyfp &x, const diyfp &y) noexcept
returns x - y
abstract output adapter interface
std::size_t lines_read
the number of lines read
std::size_t chars_read_current_line
the number of characters read in the current line
std::size_t chars_read_total
the total number of characters read
struct to capture the start position of the current token
virtual bool start_object(std::size_t elements)=0
the beginning of an object was read
virtual bool string(string_t &val)=0
a string was read
virtual bool null()=0
a null value was read
virtual bool end_array()=0
the end of an array was read
virtual bool key(string_t &val)=0
an object key was read
virtual bool binary(binary_t &val)=0
a binary string was read
virtual bool start_array(std::size_t elements)=0
the beginning of an array 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 boolean(bool val)=0
a boolean value was read
virtual bool end_object()=0
the end of an object was read
virtual bool number_unsigned(number_unsigned_t val)=0
an unsigned integer number was read
virtual bool number_float(number_float_t val, const string_t &s)=0
an floating-point number was read
virtual bool number_integer(number_integer_t val)=0
an integer number was read
ordered_map: a minimal map-like container that preserves insertion order for use within nlohmann::bas...
std::size_t operator()(const nlohmann::json &j) const
return a hash value for a JSON object
bool operator()(nlohmann::detail::value_t lhs, nlohmann::detail::value_t rhs) const noexcept
compare two value_t enum values