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 3
40#include <initializer_list>
62#include <forward_list>
68#include <unordered_map>
120enum class value_t : std::uint8_t
147inline bool operator<(
const value_t lhs,
const value_t rhs)
noexcept
149 static constexpr std::array<std::uint8_t, 9> order = {{
156 const auto l_index =
static_cast<std::size_t
>(lhs);
157 const auto r_index =
static_cast<std::size_t
>(rhs);
158 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
186#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
187#if defined(JSON_HEDLEY_VERSION)
188 #undef JSON_HEDLEY_VERSION
190#define JSON_HEDLEY_VERSION 15
192#if defined(JSON_HEDLEY_STRINGIFY_EX)
193 #undef JSON_HEDLEY_STRINGIFY_EX
195#define JSON_HEDLEY_STRINGIFY_EX(x) #x
197#if defined(JSON_HEDLEY_STRINGIFY)
198 #undef JSON_HEDLEY_STRINGIFY
200#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
202#if defined(JSON_HEDLEY_CONCAT_EX)
203 #undef JSON_HEDLEY_CONCAT_EX
205#define JSON_HEDLEY_CONCAT_EX(a,b) a##b
207#if defined(JSON_HEDLEY_CONCAT)
208 #undef JSON_HEDLEY_CONCAT
210#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
212#if defined(JSON_HEDLEY_CONCAT3_EX)
213 #undef JSON_HEDLEY_CONCAT3_EX
215#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
217#if defined(JSON_HEDLEY_CONCAT3)
218 #undef JSON_HEDLEY_CONCAT3
220#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
222#if defined(JSON_HEDLEY_VERSION_ENCODE)
223 #undef JSON_HEDLEY_VERSION_ENCODE
225#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
227#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
228 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
230#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
232#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
233 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
235#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
237#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
238 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
240#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
242#if defined(JSON_HEDLEY_GNUC_VERSION)
243 #undef JSON_HEDLEY_GNUC_VERSION
245#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
246 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
247#elif defined(__GNUC__)
248 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
251#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
252 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
254#if defined(JSON_HEDLEY_GNUC_VERSION)
255 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
257 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
260#if defined(JSON_HEDLEY_MSVC_VERSION)
261 #undef JSON_HEDLEY_MSVC_VERSION
263#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
264 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
265#elif defined(_MSC_FULL_VER) && !defined(__ICL)
266 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
267#elif defined(_MSC_VER) && !defined(__ICL)
268 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
271#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
272 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
274#if !defined(JSON_HEDLEY_MSVC_VERSION)
275 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
276#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
277 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
278#elif defined(_MSC_VER) && (_MSC_VER >= 1200)
279 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
281 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
284#if defined(JSON_HEDLEY_INTEL_VERSION)
285 #undef JSON_HEDLEY_INTEL_VERSION
287#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
288 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
289#elif defined(__INTEL_COMPILER) && !defined(__ICL)
290 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
293#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
294 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
296#if defined(JSON_HEDLEY_INTEL_VERSION)
297 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
299 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
302#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
303 #undef JSON_HEDLEY_INTEL_CL_VERSION
305#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
306 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
309#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
310 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
312#if defined(JSON_HEDLEY_INTEL_CL_VERSION)
313 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
315 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
318#if defined(JSON_HEDLEY_PGI_VERSION)
319 #undef JSON_HEDLEY_PGI_VERSION
321#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
322 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
325#if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
326 #undef JSON_HEDLEY_PGI_VERSION_CHECK
328#if defined(JSON_HEDLEY_PGI_VERSION)
329 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
331 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
334#if defined(JSON_HEDLEY_SUNPRO_VERSION)
335 #undef JSON_HEDLEY_SUNPRO_VERSION
337#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
338 #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)
339#elif defined(__SUNPRO_C)
340 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
341#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
342 #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)
343#elif defined(__SUNPRO_CC)
344 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
347#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
348 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
350#if defined(JSON_HEDLEY_SUNPRO_VERSION)
351 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
353 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
356#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
357 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
359#if defined(__EMSCRIPTEN__)
360 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
363#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
364 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
366#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
367 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
369 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
372#if defined(JSON_HEDLEY_ARM_VERSION)
373 #undef JSON_HEDLEY_ARM_VERSION
375#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
376 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
377#elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
378 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
381#if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
382 #undef JSON_HEDLEY_ARM_VERSION_CHECK
384#if defined(JSON_HEDLEY_ARM_VERSION)
385 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
387 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
390#if defined(JSON_HEDLEY_IBM_VERSION)
391 #undef JSON_HEDLEY_IBM_VERSION
393#if defined(__ibmxl__)
394 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
395#elif defined(__xlC__) && defined(__xlC_ver__)
396 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
397#elif defined(__xlC__)
398 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
401#if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
402 #undef JSON_HEDLEY_IBM_VERSION_CHECK
404#if defined(JSON_HEDLEY_IBM_VERSION)
405 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
407 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
410#if defined(JSON_HEDLEY_TI_VERSION)
411 #undef JSON_HEDLEY_TI_VERSION
414 defined(__TI_COMPILER_VERSION__) && \
416 defined(__TMS470__) || defined(__TI_ARM__) || \
417 defined(__MSP430__) || \
418 defined(__TMS320C2000__) \
420#if (__TI_COMPILER_VERSION__ >= 16000000)
421 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
425#if defined(JSON_HEDLEY_TI_VERSION_CHECK)
426 #undef JSON_HEDLEY_TI_VERSION_CHECK
428#if defined(JSON_HEDLEY_TI_VERSION)
429 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
431 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
434#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
435 #undef JSON_HEDLEY_TI_CL2000_VERSION
437#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
438 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
441#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
442 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
444#if defined(JSON_HEDLEY_TI_CL2000_VERSION)
445 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
447 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
450#if defined(JSON_HEDLEY_TI_CL430_VERSION)
451 #undef JSON_HEDLEY_TI_CL430_VERSION
453#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
454 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
457#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
458 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
460#if defined(JSON_HEDLEY_TI_CL430_VERSION)
461 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
463 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
466#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
467 #undef JSON_HEDLEY_TI_ARMCL_VERSION
469#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
470 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
473#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
474 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
476#if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
477 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
479 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
482#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
483 #undef JSON_HEDLEY_TI_CL6X_VERSION
485#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
486 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
489#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
490 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
492#if defined(JSON_HEDLEY_TI_CL6X_VERSION)
493 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
495 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
498#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
499 #undef JSON_HEDLEY_TI_CL7X_VERSION
501#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
502 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
505#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
506 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
508#if defined(JSON_HEDLEY_TI_CL7X_VERSION)
509 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
511 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
514#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
515 #undef JSON_HEDLEY_TI_CLPRU_VERSION
517#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
518 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
521#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
522 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
524#if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
525 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
527 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
530#if defined(JSON_HEDLEY_CRAY_VERSION)
531 #undef JSON_HEDLEY_CRAY_VERSION
534 #if defined(_RELEASE_PATCHLEVEL)
535 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
537 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
541#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
542 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
544#if defined(JSON_HEDLEY_CRAY_VERSION)
545 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
547 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
550#if defined(JSON_HEDLEY_IAR_VERSION)
551 #undef JSON_HEDLEY_IAR_VERSION
553#if defined(__IAR_SYSTEMS_ICC__)
555 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
557 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
561#if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
562 #undef JSON_HEDLEY_IAR_VERSION_CHECK
564#if defined(JSON_HEDLEY_IAR_VERSION)
565 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
567 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
570#if defined(JSON_HEDLEY_TINYC_VERSION)
571 #undef JSON_HEDLEY_TINYC_VERSION
573#if defined(__TINYC__)
574 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
577#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
578 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
580#if defined(JSON_HEDLEY_TINYC_VERSION)
581 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
583 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
586#if defined(JSON_HEDLEY_DMC_VERSION)
587 #undef JSON_HEDLEY_DMC_VERSION
590 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
593#if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
594 #undef JSON_HEDLEY_DMC_VERSION_CHECK
596#if defined(JSON_HEDLEY_DMC_VERSION)
597 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
599 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
602#if defined(JSON_HEDLEY_COMPCERT_VERSION)
603 #undef JSON_HEDLEY_COMPCERT_VERSION
605#if defined(__COMPCERT_VERSION__)
606 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
609#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
610 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
612#if defined(JSON_HEDLEY_COMPCERT_VERSION)
613 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
615 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
618#if defined(JSON_HEDLEY_PELLES_VERSION)
619 #undef JSON_HEDLEY_PELLES_VERSION
622 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
625#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
626 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
628#if defined(JSON_HEDLEY_PELLES_VERSION)
629 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
631 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
634#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
635 #undef JSON_HEDLEY_MCST_LCC_VERSION
637#if defined(__LCC__) && defined(__LCC_MINOR__)
638 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
641#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
642 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
644#if defined(JSON_HEDLEY_MCST_LCC_VERSION)
645 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
647 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
650#if defined(JSON_HEDLEY_GCC_VERSION)
651 #undef JSON_HEDLEY_GCC_VERSION
654 defined(JSON_HEDLEY_GNUC_VERSION) && \
655 !defined(__clang__) && \
656 !defined(JSON_HEDLEY_INTEL_VERSION) && \
657 !defined(JSON_HEDLEY_PGI_VERSION) && \
658 !defined(JSON_HEDLEY_ARM_VERSION) && \
659 !defined(JSON_HEDLEY_CRAY_VERSION) && \
660 !defined(JSON_HEDLEY_TI_VERSION) && \
661 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
662 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
663 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
664 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
665 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
666 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
667 !defined(__COMPCERT__) && \
668 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
669 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
672#if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
673 #undef JSON_HEDLEY_GCC_VERSION_CHECK
675#if defined(JSON_HEDLEY_GCC_VERSION)
676 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
678 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
681#if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
682 #undef JSON_HEDLEY_HAS_ATTRIBUTE
685 defined(__has_attribute) && \
687 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
689# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
691# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
694#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
695 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
697#if defined(__has_attribute)
698 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
700 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
703#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
704 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
706#if defined(__has_attribute)
707 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
709 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
712#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
713 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
716 defined(__has_cpp_attribute) && \
717 defined(__cplusplus) && \
718 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
719 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
721 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
724#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
725 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
727#if !defined(__cplusplus) || !defined(__has_cpp_attribute)
728 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
730 !defined(JSON_HEDLEY_PGI_VERSION) && \
731 !defined(JSON_HEDLEY_IAR_VERSION) && \
732 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
733 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
734 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
736 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
739#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
740 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
742#if defined(__has_cpp_attribute) && defined(__cplusplus)
743 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
745 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
748#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
749 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
751#if defined(__has_cpp_attribute) && defined(__cplusplus)
752 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
754 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
757#if defined(JSON_HEDLEY_HAS_BUILTIN)
758 #undef JSON_HEDLEY_HAS_BUILTIN
760#if defined(__has_builtin)
761 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
763 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
766#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
767 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
769#if defined(__has_builtin)
770 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
772 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
775#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
776 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
778#if defined(__has_builtin)
779 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
781 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
784#if defined(JSON_HEDLEY_HAS_FEATURE)
785 #undef JSON_HEDLEY_HAS_FEATURE
787#if defined(__has_feature)
788 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
790 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
793#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
794 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
796#if defined(__has_feature)
797 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
799 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
802#if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
803 #undef JSON_HEDLEY_GCC_HAS_FEATURE
805#if defined(__has_feature)
806 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
808 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
811#if defined(JSON_HEDLEY_HAS_EXTENSION)
812 #undef JSON_HEDLEY_HAS_EXTENSION
814#if defined(__has_extension)
815 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
817 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
820#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
821 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
823#if defined(__has_extension)
824 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
826 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
829#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
830 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
832#if defined(__has_extension)
833 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
835 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
838#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
839 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
841#if defined(__has_declspec_attribute)
842 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
844 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
847#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
848 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
850#if defined(__has_declspec_attribute)
851 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
853 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
856#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
857 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
859#if defined(__has_declspec_attribute)
860 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
862 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
865#if defined(JSON_HEDLEY_HAS_WARNING)
866 #undef JSON_HEDLEY_HAS_WARNING
868#if defined(__has_warning)
869 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
871 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
874#if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
875 #undef JSON_HEDLEY_GNUC_HAS_WARNING
877#if defined(__has_warning)
878 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
880 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
883#if defined(JSON_HEDLEY_GCC_HAS_WARNING)
884 #undef JSON_HEDLEY_GCC_HAS_WARNING
886#if defined(__has_warning)
887 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
889 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
893 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
894 defined(__clang__) || \
895 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
896 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
897 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
898 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
899 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
900 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
901 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
902 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
903 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
904 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
905 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
906 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
907 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
908 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
909 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
910 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
911 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
912#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
913 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
915 #define JSON_HEDLEY_PRAGMA(value)
918#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
919 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
921#if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
922 #undef JSON_HEDLEY_DIAGNOSTIC_POP
924#if defined(__clang__)
925 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
926 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
927#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
928 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
929 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
930#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
931 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
932 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
934 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
935 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
936 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
937 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
938#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
939 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
940 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
942 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
943 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
944 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
945 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
946 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
947 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
948 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
949 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
950#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
951 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
952 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
954 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
955 #define JSON_HEDLEY_DIAGNOSTIC_POP
960#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
961 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
963#if defined(__cplusplus)
964# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
965# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
966# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
967# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
968 JSON_HEDLEY_DIAGNOSTIC_PUSH \
969 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
970 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
971 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
973 JSON_HEDLEY_DIAGNOSTIC_POP
975# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
976 JSON_HEDLEY_DIAGNOSTIC_PUSH \
977 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
978 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
980 JSON_HEDLEY_DIAGNOSTIC_POP
983# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
984 JSON_HEDLEY_DIAGNOSTIC_PUSH \
985 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
987 JSON_HEDLEY_DIAGNOSTIC_POP
991#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
992 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
995#if defined(JSON_HEDLEY_CONST_CAST)
996 #undef JSON_HEDLEY_CONST_CAST
998#if defined(__cplusplus)
999# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
1001 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1002 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1003 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1004# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1005 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1006 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1008 JSON_HEDLEY_DIAGNOSTIC_POP \
1011# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1014#if defined(JSON_HEDLEY_REINTERPRET_CAST)
1015 #undef JSON_HEDLEY_REINTERPRET_CAST
1017#if defined(__cplusplus)
1018 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1020 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1023#if defined(JSON_HEDLEY_STATIC_CAST)
1024 #undef JSON_HEDLEY_STATIC_CAST
1026#if defined(__cplusplus)
1027 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1029 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1032#if defined(JSON_HEDLEY_CPP_CAST)
1033 #undef JSON_HEDLEY_CPP_CAST
1035#if defined(__cplusplus)
1036# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1037# define JSON_HEDLEY_CPP_CAST(T, expr) \
1038 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1039 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1041 JSON_HEDLEY_DIAGNOSTIC_POP
1042# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1043# define JSON_HEDLEY_CPP_CAST(T, expr) \
1044 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1045 _Pragma("diag_suppress=Pe137") \
1046 JSON_HEDLEY_DIAGNOSTIC_POP
1048# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1051# define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1054#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1055 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1057#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1058 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1059#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1060 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1061#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1062 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1063#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1064 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1065#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1066 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1067#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1068 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1069#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1070 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1071#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1072 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1074 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1075 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1076 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1077 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1078 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1079 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1080 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1081 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1082 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1083 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1084 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1085 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1086#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1087 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1088#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1089 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1090#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1091 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1092#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1093 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1095 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1098#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1099 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1101#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1102 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1103#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1104 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1105#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1106 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1107#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1108 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1109#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1110 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1111#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1112 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1114 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1115 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1116 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1117 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1118 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1119#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1120 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1121#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1122 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1123#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1124 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1126 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1129#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1130 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1132#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1133 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1134#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1135 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1136#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1137 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1138#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1139 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1140#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1141 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1142#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1143 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1144#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1145 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1146#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1147 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1149 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1150 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1151 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1152 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1153#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1154 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1155#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1156 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1158 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1161#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1162 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1164#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1165 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1166#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1167 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1168#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1169 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1171 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1174#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1175 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1177#if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1178 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1179#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1180 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1181#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1182 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1183#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1184 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1186 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1189#if defined(JSON_HEDLEY_DEPRECATED)
1190 #undef JSON_HEDLEY_DEPRECATED
1192#if defined(JSON_HEDLEY_DEPRECATED_FOR)
1193 #undef JSON_HEDLEY_DEPRECATED_FOR
1196 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1197 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1198 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1199 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1201 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1202 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1203 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1204 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1205 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1206 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1207 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1208 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1209 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1210 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1211 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1212 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1213 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1214 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1215#elif defined(__cplusplus) && (__cplusplus >= 201402L)
1216 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1217 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1219 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1220 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1221 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1222 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1223 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1225 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1226 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1227 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1228 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1229 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1230 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1231 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1232 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1233 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1234 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1235 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1236 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1238 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1239 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1240 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1241 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1242 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1243#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1244 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1245 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1247 #define JSON_HEDLEY_DEPRECATED(since)
1248 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1251#if defined(JSON_HEDLEY_UNAVAILABLE)
1252 #undef JSON_HEDLEY_UNAVAILABLE
1255 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1256 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1257 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1258 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1259 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1261 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1271 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1272 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1273 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1274 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1275 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1276 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1277 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1278 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1279 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1280 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1281 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1282 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1283 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1284 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1285 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1286 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1287 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1288 #define __attribute__((__warn_unused_result__))
1289 #define _MSG(msg) __attribute__((__warn_unused_result__))
1290#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1291 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1292 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1293#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1294 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1295 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1296#elif defined(_Check_return_)
1297 #define _Check_return_
1298 #define _MSG(msg) _Check_return_
1304#if defined(JSON_HEDLEY_SENTINEL)
1305 #undef JSON_HEDLEY_SENTINEL
1308 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1309 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1310 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1311 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1312 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1313 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1315 #define JSON_HEDLEY_SENTINEL(position)
1318#if defined(JSON_HEDLEY_NO_RETURN)
1319 #undef JSON_HEDLEY_NO_RETURN
1321#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1322 #define JSON_HEDLEY_NO_RETURN __noreturn
1324 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1325 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1326 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1327#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1328 #define JSON_HEDLEY_NO_RETURN _Noreturn
1329#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1330 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1332 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1333 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1334 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1335 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1336 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1337 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1338 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1339 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1340 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1341 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1342 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1343 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1344 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1345 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1346 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1347 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1348 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1349 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1350#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1351 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1353 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1354 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1355 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1356#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1357 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1358#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1359 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1360#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1361 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1363 #define JSON_HEDLEY_NO_RETURN
1366#if defined(JSON_HEDLEY_NO_ESCAPE)
1367 #undef JSON_HEDLEY_NO_ESCAPE
1369#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1370 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1372 #define JSON_HEDLEY_NO_ESCAPE
1375#if defined(JSON_HEDLEY_UNREACHABLE)
1376 #undef JSON_HEDLEY_UNREACHABLE
1378#if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1379 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1381#if defined(JSON_HEDLEY_ASSUME)
1382 #undef JSON_HEDLEY_ASSUME
1385 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1386 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1387 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1388 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1389#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1390 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1392 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1393 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1394 #if defined(__cplusplus)
1395 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1397 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1401 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1402 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1403 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1404 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1405 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1406 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1407 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1408 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1409#elif defined(JSON_HEDLEY_ASSUME)
1410 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1412#if !defined(JSON_HEDLEY_ASSUME)
1413 #if defined(JSON_HEDLEY_UNREACHABLE)
1414 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1416 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1419#if defined(JSON_HEDLEY_UNREACHABLE)
1421 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1422 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1423 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1425 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1428 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1430#if !defined(JSON_HEDLEY_UNREACHABLE)
1431 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1434JSON_HEDLEY_DIAGNOSTIC_PUSH
1435#if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1436 #pragma clang diagnostic ignored "-Wpedantic"
1438#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1439 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1441#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1442 #if defined(__clang__)
1443 #pragma clang diagnostic ignored "-Wvariadic-macros"
1444 #elif defined(JSON_HEDLEY_GCC_VERSION)
1445 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1448#if defined(JSON_HEDLEY_NON_NULL)
1449 #undef JSON_HEDLEY_NON_NULL
1452 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1453 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1454 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1455 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1456 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1458 #define JSON_HEDLEY_NON_NULL(...)
1460JSON_HEDLEY_DIAGNOSTIC_POP
1462#if defined(JSON_HEDLEY_PRINTF_FORMAT)
1463 #undef JSON_HEDLEY_PRINTF_FORMAT
1465#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1466 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1467#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO)
1468 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check)))
1470 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1471 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1472 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1473 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1474 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1475 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1476 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1477 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1478 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1479 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1480 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1481 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1482 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1483 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1484 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1485 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1486 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1487 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1488#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1489 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1491 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1494#if defined(JSON_HEDLEY_CONSTEXPR)
1495 #undef JSON_HEDLEY_CONSTEXPR
1497#if defined(__cplusplus)
1498 #if __cplusplus >= 201103L
1499 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1502#if !defined(JSON_HEDLEY_CONSTEXPR)
1503 #define JSON_HEDLEY_CONSTEXPR
1506#if defined(JSON_HEDLEY_PREDICT)
1507 #undef JSON_HEDLEY_PREDICT
1509#if defined(JSON_HEDLEY_LIKELY)
1510 #undef JSON_HEDLEY_LIKELY
1512#if defined(JSON_HEDLEY_UNLIKELY)
1513 #undef JSON_HEDLEY_UNLIKELY
1515#if defined(JSON_HEDLEY_UNPREDICTABLE)
1516 #undef JSON_HEDLEY_UNPREDICTABLE
1518#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1519 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1522 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1523 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1524 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1525# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1526# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1527# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1528# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1529# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1531 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1532 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1533 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1534 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1535 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1536 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1537 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1538 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1539 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1540 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1541 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1542 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1543 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1544 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1545 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1546 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1547# define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1548 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1549# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1551 double hedley_probability_ = (probability); \
1552 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1554# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1556 double hedley_probability_ = (probability); \
1557 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1559# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1560# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1562# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1563# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1564# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1565# define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1566# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1568#if !defined(JSON_HEDLEY_UNPREDICTABLE)
1569 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1572#if defined(JSON_HEDLEY_MALLOC)
1573 #undef JSON_HEDLEY_MALLOC
1576 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1577 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1578 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1579 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1580 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1581 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1582 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1583 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1584 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1585 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1586 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1587 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1588 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1589 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1590 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1591 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1592 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1593 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1594 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1595#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1596 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1598 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1599 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1600 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1602 #define JSON_HEDLEY_MALLOC
1605#if defined(JSON_HEDLEY_PURE)
1606 #undef JSON_HEDLEY_PURE
1609 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1610 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1611 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1612 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1613 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1614 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1615 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1616 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1617 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1618 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1619 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1620 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1621 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1622 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1623 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1624 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1625 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1626 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1627 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1628# define JSON_HEDLEY_PURE __attribute__((__pure__))
1629#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1630# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1631#elif defined(__cplusplus) && \
1633 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1634 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1635 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1637# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1639# define JSON_HEDLEY_PURE
1642#if defined(JSON_HEDLEY_CONST)
1643 #undef JSON_HEDLEY_CONST
1646 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1647 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1648 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1649 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1650 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1651 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1652 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1653 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1654 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1655 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1656 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1657 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1658 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1659 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1660 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1661 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1662 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1663 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1664 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1665 #define JSON_HEDLEY_CONST __attribute__((__const__))
1667 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1668 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1670 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1673#if defined(JSON_HEDLEY_RESTRICT)
1674 #undef JSON_HEDLEY_RESTRICT
1676#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1677 #define JSON_HEDLEY_RESTRICT restrict
1679 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1680 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1681 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1682 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1683 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1684 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1685 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1686 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1687 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1688 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1689 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1690 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1691 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1692 defined(__clang__) || \
1693 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1694 #define JSON_HEDLEY_RESTRICT __restrict
1695#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1696 #define JSON_HEDLEY_RESTRICT _Restrict
1698 #define JSON_HEDLEY_RESTRICT
1701#if defined(JSON_HEDLEY_INLINE)
1702 #undef JSON_HEDLEY_INLINE
1705 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1706 (defined(__cplusplus) && (__cplusplus >= 199711L))
1707 #define JSON_HEDLEY_INLINE inline
1709 defined(JSON_HEDLEY_GCC_VERSION) || \
1710 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1711 #define JSON_HEDLEY_INLINE __inline__
1713 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1714 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1715 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1716 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1717 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1718 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1719 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1720 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1721 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1722 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1723 #define JSON_HEDLEY_INLINE __inline
1725 #define JSON_HEDLEY_INLINE
1728#if defined(JSON_HEDLEY_ALWAYS_INLINE)
1729 #undef JSON_HEDLEY_ALWAYS_INLINE
1732 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1733 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1734 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1735 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1736 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1737 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1738 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1739 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1740 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1741 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1742 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1743 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1744 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1745 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1746 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1747 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1748 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1749 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1750 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1751# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1753 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1754 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1755# define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1756#elif defined(__cplusplus) && \
1758 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1759 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1760 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1761 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1762 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1763 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1765# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1766#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1767# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1769# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1772#if defined(JSON_HEDLEY_NEVER_INLINE)
1773 #undef JSON_HEDLEY_NEVER_INLINE
1776 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1777 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1778 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1779 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1780 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1781 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1782 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1783 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1784 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1785 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1786 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1787 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1788 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1789 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1790 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1791 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1792 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1793 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1794 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1795 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1797 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1798 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1799 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1800#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1801 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1802#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1803 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1804#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1805 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1806#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1807 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1808#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1809 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1811 #define JSON_HEDLEY_NEVER_INLINE
1814#if defined(JSON_HEDLEY_PRIVATE)
1815 #undef JSON_HEDLEY_PRIVATE
1817#if defined(JSON_HEDLEY_PUBLIC)
1818 #undef JSON_HEDLEY_PUBLIC
1820#if defined(JSON_HEDLEY_IMPORT)
1821 #undef JSON_HEDLEY_IMPORT
1823#if defined(_WIN32) || defined(__CYGWIN__)
1824# define JSON_HEDLEY_PRIVATE
1825# define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1826# define JSON_HEDLEY_IMPORT __declspec(dllimport)
1829 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1830 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1831 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1832 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1833 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1834 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1836 defined(__TI_EABI__) && \
1838 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1839 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1842 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1843# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1844# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1846# define JSON_HEDLEY_PRIVATE
1847# define JSON_HEDLEY_PUBLIC
1849# define JSON_HEDLEY_IMPORT extern
1852#if defined(JSON_HEDLEY_NO_THROW)
1853 #undef JSON_HEDLEY_NO_THROW
1856 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1857 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1858 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1859 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1860 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1862 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1863 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1864 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1865 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1867 #define JSON_HEDLEY_NO_THROW
1870#if defined(JSON_HEDLEY_FALL_THROUGH)
1871 #undef JSON_HEDLEY_FALL_THROUGH
1874 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1875 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1876 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1877 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1878#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1879 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1880#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1881 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1882#elif defined(__fallthrough)
1883 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1885 #define JSON_HEDLEY_FALL_THROUGH
1892 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1893 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1894 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1895 #define __attribute__((__returns_nonnull__))
1896#elif defined(_Ret_notnull_)
1897 #define _Ret_notnull_
1902#if defined(JSON_HEDLEY_ARRAY_PARAM)
1903 #undef JSON_HEDLEY_ARRAY_PARAM
1906 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1907 !defined(__STDC_NO_VLA__) && \
1908 !defined(__cplusplus) && \
1909 !defined(JSON_HEDLEY_PGI_VERSION) && \
1910 !defined(JSON_HEDLEY_TINYC_VERSION)
1911 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1913 #define JSON_HEDLEY_ARRAY_PARAM(name)
1916#if defined(JSON_HEDLEY_IS_CONSTANT)
1917 #undef JSON_HEDLEY_IS_CONSTANT
1919#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1920 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1924#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1925 #undef JSON_HEDLEY_IS_CONSTEXPR_
1928 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1929 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1930 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1931 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1932 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1933 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1934 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1935 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1936 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1937 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1938 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1940#if !defined(__cplusplus)
1942 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1943 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1944 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1945 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1946 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1947 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1948 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1949#if defined(__INTPTR_TYPE__)
1950 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1953 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1957 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1958 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1959 !defined(JSON_HEDLEY_PGI_VERSION) && \
1960 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1961 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1962 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1963 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1964 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1965 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1966#if defined(__INTPTR_TYPE__)
1967 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1970 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1973 defined(JSON_HEDLEY_GCC_VERSION) || \
1974 defined(JSON_HEDLEY_INTEL_VERSION) || \
1975 defined(JSON_HEDLEY_TINYC_VERSION) || \
1976 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1977 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1978 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1979 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1980 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1981 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1983# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1987 ((void*) ((expr) * 0L) ) : \
1988((struct { char v[sizeof(void) * 2]; } *) 1) \
1994#if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1995 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1996 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1998 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
2000 #if !defined(JSON_HEDLEY_IS_CONSTANT)
2001 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2003 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2006#if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2007 #undef JSON_HEDLEY_BEGIN_C_DECLS
2009#if defined(JSON_HEDLEY_END_C_DECLS)
2010 #undef JSON_HEDLEY_END_C_DECLS
2012#if defined(JSON_HEDLEY_C_DECL)
2013 #undef JSON_HEDLEY_C_DECL
2015#if defined(__cplusplus)
2016 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2017 #define JSON_HEDLEY_END_C_DECLS }
2018 #define JSON_HEDLEY_C_DECL extern "C"
2020 #define JSON_HEDLEY_BEGIN_C_DECLS
2021 #define JSON_HEDLEY_END_C_DECLS
2022 #define JSON_HEDLEY_C_DECL
2025#if defined(JSON_HEDLEY_STATIC_ASSERT)
2026 #undef JSON_HEDLEY_STATIC_ASSERT
2029 !defined(__cplusplus) && ( \
2030 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2031 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2032 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2033 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2034 defined(_Static_assert) \
2036# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2038 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2039 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2040 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2041# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2043# define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2046#if defined(JSON_HEDLEY_NULL)
2047 #undef JSON_HEDLEY_NULL
2049#if defined(__cplusplus)
2050 #if __cplusplus >= 201103L
2051 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2053 #define JSON_HEDLEY_NULL NULL
2055 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2058 #define JSON_HEDLEY_NULL NULL
2060 #define JSON_HEDLEY_NULL ((void*) 0)
2063#if defined(JSON_HEDLEY_MESSAGE)
2064 #undef JSON_HEDLEY_MESSAGE
2066#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2067# define JSON_HEDLEY_MESSAGE(msg) \
2068 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2069 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2070 JSON_HEDLEY_PRAGMA(message msg) \
2071 JSON_HEDLEY_DIAGNOSTIC_POP
2073 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2074 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2075# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2076#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2077# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2078#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2079# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2080#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2081# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2083# define JSON_HEDLEY_MESSAGE(msg)
2086#if defined(JSON_HEDLEY_WARNING)
2087 #undef JSON_HEDLEY_WARNING
2089#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2090# define JSON_HEDLEY_WARNING(msg) \
2091 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2092 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2093 JSON_HEDLEY_PRAGMA(clang warning msg) \
2094 JSON_HEDLEY_DIAGNOSTIC_POP
2096 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2097 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2098 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2099# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2101 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2102 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2103# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2105# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2108#if defined(JSON_HEDLEY_REQUIRE)
2109 #undef JSON_HEDLEY_REQUIRE
2111#if defined(JSON_HEDLEY_REQUIRE_MSG)
2112 #undef JSON_HEDLEY_REQUIRE_MSG
2114#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2115# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2116# define JSON_HEDLEY_REQUIRE(expr) \
2117 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2118 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2119 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2120 JSON_HEDLEY_DIAGNOSTIC_POP
2121# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2122 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2123 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2124 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2125 JSON_HEDLEY_DIAGNOSTIC_POP
2127# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2128# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2131# define JSON_HEDLEY_REQUIRE(expr)
2132# define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2135#if defined(JSON_HEDLEY_FLAGS)
2136 #undef JSON_HEDLEY_FLAGS
2138#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2139 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2141 #define JSON_HEDLEY_FLAGS
2144#if defined(JSON_HEDLEY_FLAGS_CAST)
2145 #undef JSON_HEDLEY_FLAGS_CAST
2147#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2148# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2149 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2150 _Pragma("warning(disable:188)") \
2152 JSON_HEDLEY_DIAGNOSTIC_POP \
2155# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2158#if defined(JSON_HEDLEY_EMPTY_BASES)
2159 #undef JSON_HEDLEY_EMPTY_BASES
2162 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2163 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2164 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2166 #define JSON_HEDLEY_EMPTY_BASES
2171#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2172 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2174#if defined(__clang__)
2175 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2177 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2180#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2181 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2183#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2185#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2186 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2188#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2190#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2191 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2193#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2195#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2196 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2198#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2200#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2201 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2203#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2205#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2206 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2208#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2210#if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2211 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2213#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2220#include <type_traits>
2229template<
typename ...Ts>
struct make_void
2233template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
2245 nonesuch() =
delete;
2246 ~nonesuch() =
delete;
2247 nonesuch(nonesuch
const&) =
delete;
2248 nonesuch(nonesuch
const&&) =
delete;
2249 void operator=(nonesuch
const&) =
delete;
2250 void operator=(nonesuch&&) =
delete;
2253template<
class Default,
2255 template<
class...>
class Op,
2259 using value_t = std::false_type;
2260 using type = Default;
2263template<
class Default,
template<
class...>
class Op,
class... Args>
2264struct detector<Default, void_t<Op<Args...>>, Op, Args...>
2266 using value_t = std::true_type;
2267 using type = Op<Args...>;
2270template<
template<
class...>
class Op,
class... Args>
2271using is_detected =
typename detector<nonesuch, void, Op, Args...>::value_t;
2273template<
template<
class...>
class Op,
class... Args>
2274struct is_detected_lazy : is_detected<Op, Args...> { };
2276template<
template<
class...>
class Op,
class... Args>
2277using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
2279template<
class Default,
template<
class...>
class Op,
class... Args>
2280using detected_or = detector<Default, void, Op, Args...>;
2282template<
class Default,
template<
class...>
class Op,
class... Args>
2283using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
2285template<
class Expected,
template<
class...>
class Op,
class... Args>
2286using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
2288template<
class To,
template<
class...>
class Op,
class... Args>
2289using is_detected_convertible =
2290 std::is_convertible<detected_t<Op, Args...>, To>;
2299#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2300 #if defined(__clang__)
2301 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2302 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2304 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2305 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2306 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2313#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2314 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2315 #define JSON_HAS_CPP_20
2316 #define JSON_HAS_CPP_17
2317 #define JSON_HAS_CPP_14
2318 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2319 #define JSON_HAS_CPP_17
2320 #define JSON_HAS_CPP_14
2321 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2322 #define JSON_HAS_CPP_14
2325 #define JSON_HAS_CPP_11
2329#if defined(__clang__)
2330 #pragma clang diagnostic push
2331 #pragma clang diagnostic ignored "-Wdocumentation"
2332 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2336#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2337 #define JSON_THROW(exception) throw exception
2338 #define JSON_TRY try
2339 #define JSON_CATCH(exception) catch(exception)
2340 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2343 #define JSON_THROW(exception) std::abort()
2344 #define JSON_TRY if(true)
2345 #define JSON_CATCH(exception) if(false)
2346 #define JSON_INTERNAL_CATCH(exception) if(false)
2350#if defined(JSON_THROW_USER)
2352 #define JSON_THROW JSON_THROW_USER
2354#if defined(JSON_TRY_USER)
2356 #define JSON_TRY JSON_TRY_USER
2358#if defined(JSON_CATCH_USER)
2360 #define JSON_CATCH JSON_CATCH_USER
2361 #undef JSON_INTERNAL_CATCH
2362 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2364#if defined(JSON_INTERNAL_CATCH_USER)
2365 #undef JSON_INTERNAL_CATCH
2366 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2370#if !defined(JSON_ASSERT)
2372 #define JSON_ASSERT(x) assert(x)
2376#if defined(JSON_TESTS_PRIVATE)
2377 #define JSON_PRIVATE_UNLESS_TESTED public
2379 #define JSON_PRIVATE_UNLESS_TESTED private
2387#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2388 template<typename BasicJsonType> \
2389 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2391 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2392 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2393 auto it = std::find_if(std::begin(m), std::end(m), \
2394 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2396 return ej_pair.first == e; \
2398 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2400 template<typename BasicJsonType> \
2401 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2403 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2404 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2405 auto it = std::find_if(std::begin(m), std::end(m), \
2406 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2408 return ej_pair.second == j; \
2410 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2416#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2417 template<template<typename, typename, typename...> class ObjectType, \
2418 template<typename, typename...> class ArrayType, \
2419 class StringType, class BooleanType, class NumberIntegerType, \
2420 class NumberUnsignedType, class NumberFloatType, \
2421 template<typename> class AllocatorType, \
2422 template<typename, typename = void> class JSONSerializer, \
2425#define NLOHMANN_BASIC_JSON_TPL \
2426 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2427 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2428 AllocatorType, JSONSerializer, BinaryType>
2432#define NLOHMANN_JSON_EXPAND( x ) x
2433#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
2434#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2435 NLOHMANN_JSON_PASTE64, \
2436 NLOHMANN_JSON_PASTE63, \
2437 NLOHMANN_JSON_PASTE62, \
2438 NLOHMANN_JSON_PASTE61, \
2439 NLOHMANN_JSON_PASTE60, \
2440 NLOHMANN_JSON_PASTE59, \
2441 NLOHMANN_JSON_PASTE58, \
2442 NLOHMANN_JSON_PASTE57, \
2443 NLOHMANN_JSON_PASTE56, \
2444 NLOHMANN_JSON_PASTE55, \
2445 NLOHMANN_JSON_PASTE54, \
2446 NLOHMANN_JSON_PASTE53, \
2447 NLOHMANN_JSON_PASTE52, \
2448 NLOHMANN_JSON_PASTE51, \
2449 NLOHMANN_JSON_PASTE50, \
2450 NLOHMANN_JSON_PASTE49, \
2451 NLOHMANN_JSON_PASTE48, \
2452 NLOHMANN_JSON_PASTE47, \
2453 NLOHMANN_JSON_PASTE46, \
2454 NLOHMANN_JSON_PASTE45, \
2455 NLOHMANN_JSON_PASTE44, \
2456 NLOHMANN_JSON_PASTE43, \
2457 NLOHMANN_JSON_PASTE42, \
2458 NLOHMANN_JSON_PASTE41, \
2459 NLOHMANN_JSON_PASTE40, \
2460 NLOHMANN_JSON_PASTE39, \
2461 NLOHMANN_JSON_PASTE38, \
2462 NLOHMANN_JSON_PASTE37, \
2463 NLOHMANN_JSON_PASTE36, \
2464 NLOHMANN_JSON_PASTE35, \
2465 NLOHMANN_JSON_PASTE34, \
2466 NLOHMANN_JSON_PASTE33, \
2467 NLOHMANN_JSON_PASTE32, \
2468 NLOHMANN_JSON_PASTE31, \
2469 NLOHMANN_JSON_PASTE30, \
2470 NLOHMANN_JSON_PASTE29, \
2471 NLOHMANN_JSON_PASTE28, \
2472 NLOHMANN_JSON_PASTE27, \
2473 NLOHMANN_JSON_PASTE26, \
2474 NLOHMANN_JSON_PASTE25, \
2475 NLOHMANN_JSON_PASTE24, \
2476 NLOHMANN_JSON_PASTE23, \
2477 NLOHMANN_JSON_PASTE22, \
2478 NLOHMANN_JSON_PASTE21, \
2479 NLOHMANN_JSON_PASTE20, \
2480 NLOHMANN_JSON_PASTE19, \
2481 NLOHMANN_JSON_PASTE18, \
2482 NLOHMANN_JSON_PASTE17, \
2483 NLOHMANN_JSON_PASTE16, \
2484 NLOHMANN_JSON_PASTE15, \
2485 NLOHMANN_JSON_PASTE14, \
2486 NLOHMANN_JSON_PASTE13, \
2487 NLOHMANN_JSON_PASTE12, \
2488 NLOHMANN_JSON_PASTE11, \
2489 NLOHMANN_JSON_PASTE10, \
2490 NLOHMANN_JSON_PASTE9, \
2491 NLOHMANN_JSON_PASTE8, \
2492 NLOHMANN_JSON_PASTE7, \
2493 NLOHMANN_JSON_PASTE6, \
2494 NLOHMANN_JSON_PASTE5, \
2495 NLOHMANN_JSON_PASTE4, \
2496 NLOHMANN_JSON_PASTE3, \
2497 NLOHMANN_JSON_PASTE2, \
2498 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2499#define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2500#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2501#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2502#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2503#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2504#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)
2505#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)
2506#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)
2507#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)
2508#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)
2509#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)
2510#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)
2511#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)
2512#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)
2513#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)
2514#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)
2515#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)
2516#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)
2517#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)
2518#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)
2519#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)
2520#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)
2521#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)
2522#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)
2523#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)
2524#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)
2525#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)
2526#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)
2527#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)
2528#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)
2529#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)
2530#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)
2531#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)
2532#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)
2533#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)
2534#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)
2535#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)
2536#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)
2537#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)
2538#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)
2539#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)
2540#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)
2541#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)
2542#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)
2543#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)
2544#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)
2545#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)
2546#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)
2547#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)
2548#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)
2549#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)
2550#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)
2551#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)
2552#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)
2553#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)
2554#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)
2555#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)
2556#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)
2557#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)
2558#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)
2559#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)
2560#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)
2561#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)
2563#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2564#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2571#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2572 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__)) } \
2573 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__)) }
2580#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2581 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__)) } \
2582 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__)) }
2591#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \
2592 namespace detail { \
2593 using std::std_name; \
2595 template<typename... T> \
2596 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2599 namespace detail2 { \
2600 struct std_name##_tag \
2604 template<typename... T> \
2605 std_name##_tag std_name(T&&...); \
2607 template<typename... T> \
2608 using result_of_##std_name = decltype(std_name(std::declval<T>()...)); \
2610 template<typename... T> \
2611 struct would_call_std_##std_name \
2613 static constexpr auto const value = ::nlohmann::detail:: \
2614 is_detected_exact<std_name##_tag, result_of_##std_name, T...>::value; \
2618 template<typename... T> \
2619 struct would_call_std_##std_name : detail2::would_call_std_##std_name<T...> \
2623#ifndef JSON_USE_IMPLICIT_CONVERSIONS
2624 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2627#if JSON_USE_IMPLICIT_CONVERSIONS
2628 #define JSON_EXPLICIT
2630 #define JSON_EXPLICIT explicit
2633#ifndef JSON_DIAGNOSTICS
2634 #define JSON_DIAGNOSTICS 0
2656inline void replace_substring(std::string& s,
const std::string& f,
2657 const std::string& t)
2659 JSON_ASSERT(!f.empty());
2660 for (
auto pos = s.find(f);
2661 pos != std::string::npos;
2662 s.replace(pos, f.size(), t),
2663 pos = s.find(f, pos + t.size()))
2674inline std::string escape(std::string s)
2676 replace_substring(s,
"~",
"~0");
2677 replace_substring(s,
"/",
"~1");
2688static void unescape(std::string& s)
2690 replace_substring(s,
"~1",
"/");
2691 replace_substring(s,
"~0",
"~");
2710 std::size_t chars_read_total = 0;
2712 std::size_t chars_read_current_line = 0;
2714 std::size_t lines_read = 0;
2717 constexpr operator size_t()
const
2719 return chars_read_total;
2765class exception :
public std::exception
2769 const char* what() const noexcept
override
2778 JSON_HEDLEY_NON_NULL(3)
2779 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
2781 static std::string name(
const std::string& ename,
int id_)
2783 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2786 template<
typename BasicJsonType>
2787 static std::string diagnostics(
const BasicJsonType& leaf_element)
2790 std::vector<std::string> tokens;
2791 for (
const auto* current = &leaf_element; current->m_parent !=
nullptr; current = current->m_parent)
2793 switch (current->m_parent->type())
2795 case value_t::array:
2797 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2799 if (¤t->m_parent->m_value.array->operator[](i) == current)
2801 tokens.emplace_back(std::to_string(i));
2808 case value_t::object:
2810 for (
const auto& element : *current->m_parent->m_value.object)
2812 if (&element.second == current)
2814 tokens.emplace_back(element.first.c_str());
2822 case value_t::string:
2823 case value_t::boolean:
2824 case value_t::number_integer:
2825 case value_t::number_unsigned:
2826 case value_t::number_float:
2827 case value_t::binary:
2828 case value_t::discarded:
2839 return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2840 [](
const std::string & a,
const std::string & b)
2842 return a +
"/" + detail::escape(b);
2845 static_cast<void>(leaf_element);
2852 std::runtime_error m;
2900class parse_error :
public exception
2912 template<
typename BasicJsonType>
2913 static parse_error create(
int id_,
const position_t& pos,
const std::string& what_arg,
const BasicJsonType& context)
2915 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2916 position_string(pos) +
": " + exception::diagnostics(context) + what_arg;
2917 return parse_error(id_, pos.chars_read_total, w.c_str());
2920 template<
typename BasicJsonType>
2921 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg,
const BasicJsonType& context)
2923 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2924 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2925 ": " + exception::diagnostics(context) + what_arg;
2926 return parse_error(id_, byte_, w.c_str());
2938 const std::size_t byte;
2941 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
2942 : exception(id_, what_arg), byte(byte_) {}
2944 static std::string position_string(
const position_t& pos)
2946 return " at line " + std::to_string(pos.lines_read + 1) +
2947 ", column " + std::to_string(pos.chars_read_current_line);
2988class invalid_iterator :
public exception
2991 template<
typename BasicJsonType>
2992 static invalid_iterator create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2994 std::string w = exception::name(
"invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2995 return invalid_iterator(id_, w.c_str());
2999 JSON_HEDLEY_NON_NULL(3)
3000 invalid_iterator(
int id_, const
char* what_arg)
3001 : exception(id_, what_arg) {}
3043class type_error :
public exception
3046 template<
typename BasicJsonType>
3047 static type_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3049 std::string w = exception::name(
"type_error", id_) + exception::diagnostics(context) + what_arg;
3050 return type_error(id_, w.c_str());
3054 JSON_HEDLEY_NON_NULL(3)
3055 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3091class out_of_range :
public exception
3094 template<
typename BasicJsonType>
3095 static out_of_range create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3097 std::string w = exception::name(
"out_of_range", id_) + exception::diagnostics(context) + what_arg;
3098 return out_of_range(id_, w.c_str());
3102 JSON_HEDLEY_NON_NULL(3)
3103 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3130class other_error :
public exception
3133 template<
typename BasicJsonType>
3134 static other_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3136 std::string w = exception::name(
"other_error", id_) + exception::diagnostics(context) + what_arg;
3137 return other_error(id_, w.c_str());
3141 JSON_HEDLEY_NON_NULL(3)
3142 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3153#include <type_traits>
3165using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3167#ifdef JSON_HAS_CPP_14
3170using std::enable_if_t;
3171using std::index_sequence;
3172using std::make_index_sequence;
3173using std::index_sequence_for;
3178template<
bool B,
typename T =
void>
3179using enable_if_t =
typename std::enable_if<B, T>::type;
3205template <
typename T, T... Ints>
3206struct integer_sequence
3208 using value_type = T;
3209 static constexpr std::size_t size() noexcept
3211 return sizeof...(Ints);
3220template <
size_t... Ints>
3221using index_sequence = integer_sequence<size_t, Ints...>;
3223namespace utility_internal
3226template <
typename Seq,
size_t SeqSize,
size_t Rem>
3230template <
typename T, T... Ints,
size_t SeqSize>
3231struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3233 using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3236template <
typename T, T... Ints,
size_t SeqSize>
3237struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3239 using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3244template <
typename T,
size_t N>
3248 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3251template <
typename T>
3254 using type = integer_sequence<T>;
3266template <
typename T, T N>
3267using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3275using make_index_sequence = make_integer_sequence<size_t, N>;
3282template <
typename... Ts>
3283using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3290template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
3291template<>
struct priority_tag<0> {};
3297 static constexpr T value{};
3301constexpr T static_const<T>::value;
3314template <
class T>
struct identity_tag {};
3322#include <type_traits>
3343template<
typename It,
typename =
void>
3344struct iterator_types {};
3346template<
typename It>
3347struct iterator_types <
3349 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3350 typename It::reference, typename It::iterator_category >>
3352 using difference_type =
typename It::difference_type;
3353 using value_type =
typename It::value_type;
3354 using pointer =
typename It::pointer;
3355 using reference =
typename It::reference;
3356 using iterator_category =
typename It::iterator_category;
3361template<
typename T,
typename =
void>
3362struct iterator_traits
3367struct iterator_traits < T, enable_if_t < !
std::is_pointer<T>::value >>
3373struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3375 using iterator_category = std::random_access_iterator_tag;
3376 using value_type = T;
3377 using difference_type = ptrdiff_t;
3379 using reference = T&;
3411#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3412#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3434template<
typename T =
void,
typename SFINAE =
void>
3435struct adl_serializer;
3437template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3439 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3440 class StringType = std::string,
class BooleanType = bool,
3441 class NumberIntegerType = std::int64_t,
3442 class NumberUnsignedType = std::uint64_t,
3443 class NumberFloatType = double,
3444 template<
typename U>
class AllocatorType = std::allocator,
3445 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3447 class BinaryType = std::vector<std::uint8_t>>
3461template<
typename BasicJsonType>
3474template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3516template<
typename>
struct is_basic_json : std::false_type {};
3518NLOHMANN_BASIC_JSON_TPL_DECLARATION
3519struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3529struct is_json_ref : std::false_type {};
3532struct is_json_ref<json_ref<T>> : std::true_type {};
3539using mapped_type_t =
typename T::mapped_type;
3542using key_type_t =
typename T::key_type;
3545using value_type_t =
typename T::value_type;
3548using difference_type_t =
typename T::difference_type;
3551using pointer_t =
typename T::pointer;
3554using reference_t =
typename T::reference;
3557using iterator_category_t =
typename T::iterator_category;
3559template<
typename T,
typename... Args>
3560using to_json_function =
decltype(T::to_json(std::declval<Args>()...));
3562template<
typename T,
typename... Args>
3563using from_json_function =
decltype(T::from_json(std::declval<Args>()...));
3565template<
typename T,
typename U>
3566using get_template_function =
decltype(std::declval<T>().template get<U>());
3569template<
typename BasicJsonType,
typename T,
typename =
void>
3570struct has_from_json : std::false_type {};
3576template <
typename BasicJsonType,
typename T>
3579 static constexpr bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3582template<
typename BasicJsonType,
typename T>
3583struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3585 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3587 static constexpr bool value =
3588 is_detected_exact<void, from_json_function, serializer,
3589 const BasicJsonType&, T&>::value;
3594template<
typename BasicJsonType,
typename T,
typename =
void>
3595struct has_non_default_from_json : std::false_type {};
3597template<
typename BasicJsonType,
typename T>
3598struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3600 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3602 static constexpr bool value =
3603 is_detected_exact<T, from_json_function, serializer,
3604 const BasicJsonType&>::value;
3609template<
typename BasicJsonType,
typename T,
typename =
void>
3610struct has_to_json : std::false_type {};
3612template<
typename BasicJsonType,
typename T>
3613struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3615 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3617 static constexpr bool value =
3618 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3628template<
class...>
struct conjunction : std::true_type { };
3629template<
class B1>
struct conjunction<B1> : B1 { };
3630template<
class B1,
class... Bn>
3631struct conjunction<B1, Bn...>
3632: std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3635template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3640template <
typename T>
3641struct is_default_constructible : std::is_default_constructible<T> {};
3643template <
typename T1,
typename T2>
3644struct is_default_constructible<
std::pair<T1, T2>>
3645 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3647template <
typename T1,
typename T2>
3648struct is_default_constructible<const
std::pair<T1, T2>>
3649 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3651template <
typename... Ts>
3652struct is_default_constructible<
std::tuple<Ts...>>
3653 : conjunction<is_default_constructible<Ts>...> {};
3655template <
typename... Ts>
3656struct is_default_constructible<const
std::tuple<Ts...>>
3657 : conjunction<is_default_constructible<Ts>...> {};
3660template <
typename T,
typename... Args>
3661struct is_constructible : std::is_constructible<T, Args...> {};
3663template <
typename T1,
typename T2>
3664struct is_constructible<
std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
3666template <
typename T1,
typename T2>
3667struct is_constructible<const
std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
3669template <
typename... Ts>
3670struct is_constructible<
std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
3672template <
typename... Ts>
3673struct is_constructible<const
std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
3676template<
typename T,
typename =
void>
3677struct is_iterator_traits : std::false_type {};
3680struct is_iterator_traits<iterator_traits<T>>
3683 using traits = iterator_traits<T>;
3686 static constexpr auto value =
3687 is_detected<value_type_t, traits>::value &&
3688 is_detected<difference_type_t, traits>::value &&
3689 is_detected<pointer_t, traits>::value &&
3690 is_detected<iterator_category_t, traits>::value &&
3691 is_detected<reference_t, traits>::value;
3698 using t_ref =
typename std::add_lvalue_reference<T>::type;
3700 using iterator = detected_t<result_of_begin, t_ref>;
3701 using sentinel = detected_t<result_of_end, t_ref>;
3706 static constexpr auto is_iterator_begin =
3707 is_iterator_traits<iterator_traits<iterator>>::value;
3710 static constexpr bool value = !std::is_same<iterator, nonesuch>::value && !std::is_same<sentinel, nonesuch>::value && is_iterator_begin;
3714using iterator_t = enable_if_t<is_range<R>::value, result_of_begin<decltype(std::declval<R&>())>>;
3717using range_value_t = value_type_t<iterator_traits<iterator_t<T>>>;
3723template<
typename T,
typename =
void>
3724struct is_complete_type : std::false_type {};
3727struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3729template<
typename BasicJsonType,
typename CompatibleObjectType,
3731struct is_compatible_object_type_impl : std::false_type {};
3733template<
typename BasicJsonType,
typename CompatibleObjectType>
3734struct is_compatible_object_type_impl <
3735 BasicJsonType, CompatibleObjectType,
3736 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3737 is_detected<key_type_t, CompatibleObjectType>::value >>
3739 using object_t =
typename BasicJsonType::object_t;
3742 static constexpr bool value =
3743 is_constructible<
typename object_t::key_type,
3744 typename CompatibleObjectType::key_type>::value &&
3745 is_constructible<
typename object_t::mapped_type,
3746 typename CompatibleObjectType::mapped_type>::value;
3749template<
typename BasicJsonType,
typename CompatibleObjectType>
3750struct is_compatible_object_type
3751 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3753template<
typename BasicJsonType,
typename ConstructibleObjectType,
3755struct is_constructible_object_type_impl : std::false_type {};
3757template<
typename BasicJsonType,
typename ConstructibleObjectType>
3758struct is_constructible_object_type_impl <
3759 BasicJsonType, ConstructibleObjectType,
3760 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3761 is_detected<key_type_t, ConstructibleObjectType>::value >>
3763 using object_t =
typename BasicJsonType::object_t;
3765 static constexpr bool value =
3766 (is_default_constructible<ConstructibleObjectType>::value &&
3767 (std::is_move_assignable<ConstructibleObjectType>::value ||
3768 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3769 (is_constructible<
typename ConstructibleObjectType::key_type,
3770 typename object_t::key_type>::value &&
3772 typename object_t::mapped_type,
3773 typename ConstructibleObjectType::mapped_type >::value)) ||
3774 (has_from_json<BasicJsonType,
3775 typename ConstructibleObjectType::mapped_type>::value ||
3776 has_non_default_from_json <
3778 typename ConstructibleObjectType::mapped_type >::value);
3781template<
typename BasicJsonType,
typename ConstructibleObjectType>
3782struct is_constructible_object_type
3783 : is_constructible_object_type_impl<BasicJsonType,
3784 ConstructibleObjectType> {};
3786template<
typename BasicJsonType,
typename CompatibleStringType,
3788struct is_compatible_string_type_impl : std::false_type {};
3790template<
typename BasicJsonType,
typename CompatibleStringType>
3791struct is_compatible_string_type_impl <
3792 BasicJsonType, CompatibleStringType,
3793 enable_if_t<is_detected_convertible<typename BasicJsonType::string_t::value_type,
3795 CompatibleStringType>::value >>
3797 static constexpr auto value =
3798 is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3801template<
typename BasicJsonType,
typename ConstructibleStringType>
3802struct is_compatible_string_type
3803 : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3805template<
typename BasicJsonType,
typename ConstructibleStringType,
3807struct is_constructible_string_type_impl : std::false_type {};
3809template<
typename BasicJsonType,
typename ConstructibleStringType>
3810struct is_constructible_string_type_impl <
3811 BasicJsonType, ConstructibleStringType,
3812 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3813 value_type_t, ConstructibleStringType>::value >>
3815 static constexpr auto value =
3816 is_constructible<ConstructibleStringType,
3817 typename BasicJsonType::string_t>::value;
3820template<
typename BasicJsonType,
typename ConstructibleStringType>
3821struct is_constructible_string_type
3822 : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3824template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3825struct is_compatible_array_type_impl : std::false_type {};
3827template<
typename BasicJsonType,
typename CompatibleArrayType>
3828struct is_compatible_array_type_impl <
3829 BasicJsonType, CompatibleArrayType,
3831 is_detected<iterator_t, CompatibleArrayType>::value&&
3832 is_iterator_traits<iterator_traits<detected_t<iterator_t, CompatibleArrayType>>>::value >>
3834 static constexpr bool value =
3835 is_constructible<BasicJsonType,
3836 range_value_t<CompatibleArrayType>>::value;
3839template<
typename BasicJsonType,
typename CompatibleArrayType>
3840struct is_compatible_array_type
3841 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3843template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3844struct is_constructible_array_type_impl : std::false_type {};
3846template<
typename BasicJsonType,
typename ConstructibleArrayType>
3847struct is_constructible_array_type_impl <
3848 BasicJsonType, ConstructibleArrayType,
3849 enable_if_t<
std::is_same<ConstructibleArrayType,
3850 typename BasicJsonType::value_type>::value >>
3851 : std::true_type {};
3853template<
typename BasicJsonType,
typename ConstructibleArrayType>
3854struct is_constructible_array_type_impl <
3855 BasicJsonType, ConstructibleArrayType,
3856 enable_if_t < !
std::is_same<ConstructibleArrayType,
3857 typename BasicJsonType::value_type>::value&&
3858 !is_compatible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
3859 is_default_constructible<ConstructibleArrayType>::value&&
3860(std::is_move_assignable<ConstructibleArrayType>::value ||
3861 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3862is_detected<iterator_t, ConstructibleArrayType>::value&&
3863is_iterator_traits<iterator_traits<detected_t<iterator_t, ConstructibleArrayType>>>::value&&
3864is_detected<range_value_t, ConstructibleArrayType>::value&&
3866detected_t<range_value_t, ConstructibleArrayType >>::value >>
3868 using value_type = range_value_t<ConstructibleArrayType>;
3870 static constexpr bool value =
3871 std::is_same<value_type,
3872 typename BasicJsonType::array_t::value_type>::value ||
3873 has_from_json<BasicJsonType,
3874 value_type>::value ||
3875 has_non_default_from_json <
3877 value_type >::value;
3880template<
typename BasicJsonType,
typename ConstructibleArrayType>
3881struct is_constructible_array_type
3882 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3884template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3886struct is_compatible_integer_type_impl : std::false_type {};
3888template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3889struct is_compatible_integer_type_impl <
3890 RealIntegerType, CompatibleNumberIntegerType,
3891 enable_if_t <
std::is_integral<RealIntegerType>::value&&
3892 std::is_integral<CompatibleNumberIntegerType>::value&&
3893 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3896 using RealLimits = std::numeric_limits<RealIntegerType>;
3897 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3899 static constexpr auto value =
3900 is_constructible<RealIntegerType,
3901 CompatibleNumberIntegerType>::value &&
3902 CompatibleLimits::is_integer &&
3903 RealLimits::is_signed == CompatibleLimits::is_signed;
3906template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3907struct is_compatible_integer_type
3908 : is_compatible_integer_type_impl<RealIntegerType,
3909 CompatibleNumberIntegerType> {};
3911template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3912struct is_compatible_type_impl: std::false_type {};
3914template<
typename BasicJsonType,
typename CompatibleType>
3915struct is_compatible_type_impl <
3916 BasicJsonType, CompatibleType,
3917 enable_if_t<is_complete_type<CompatibleType>::value >>
3919 static constexpr bool value =
3920 has_to_json<BasicJsonType, CompatibleType>::value;
3923template<
typename BasicJsonType,
typename CompatibleType>
3924struct is_compatible_type
3925 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3927template<
typename T1,
typename T2>
3928struct is_constructible_tuple : std::false_type {};
3930template<
typename T1,
typename... Args>
3931struct is_constructible_tuple<T1,
std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
3935template <
typename T>
3936struct is_ordered_map
3945 template <
typename C>
static one test(
decltype(&C::capacity) ) ;
3946 template <
typename C>
static two test(...);
3948 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
3952template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
3953T conditional_static_cast(U value)
3955 return static_cast<T
>(value);
3958template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
3959T conditional_static_cast(U value)
3974template<
typename BasicJsonType>
3975void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
3977 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3979 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name()), j));
3985template <
typename BasicJsonType,
typename ArithmeticType,
3986 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3987 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3989void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
3991 switch (
static_cast<value_t
>(j))
3993 case value_t::number_unsigned:
3995 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3998 case value_t::number_integer:
4000 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4003 case value_t::number_float:
4005 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4010 case value_t::object:
4011 case value_t::array:
4012 case value_t::string:
4013 case value_t::boolean:
4014 case value_t::binary:
4015 case value_t::discarded:
4017 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4021template<
typename BasicJsonType>
4022void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
4024 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
4026 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name()), j));
4028 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
4031template<
typename BasicJsonType>
4032void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
4034 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4036 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
4038 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4042 typename BasicJsonType,
typename ConstructibleStringType,
4044 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
4045 !std::is_same<
typename BasicJsonType::string_t,
4046 ConstructibleStringType>::value,
4048void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
4050 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
4052 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
4055 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
4058template<
typename BasicJsonType>
4059void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
4061 get_arithmetic_value(j, val);
4064template<
typename BasicJsonType>
4065void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
4067 get_arithmetic_value(j, val);
4070template<
typename BasicJsonType>
4071void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
4073 get_arithmetic_value(j, val);
4076template<
typename BasicJsonType,
typename EnumType,
4077 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4078void from_json(
const BasicJsonType& j, EnumType& e)
4080 typename std::underlying_type<EnumType>::type val;
4081 get_arithmetic_value(j, val);
4082 e =
static_cast<EnumType
>(val);
4086template<
typename BasicJsonType,
typename T,
typename Allocator,
4087 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4088void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4090 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4092 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4095 std::transform(j.rbegin(), j.rend(),
4096 std::front_inserter(l), [](
const BasicJsonType & i)
4098 return i.template get<T>();
4103template<
typename BasicJsonType,
typename T,
4104 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4105void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4107 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4109 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4112 std::transform(j.begin(), j.end(), std::begin(l),
4113 [](
const BasicJsonType & elem)
4115 return elem.template get<T>();
4119template<
typename BasicJsonType,
typename T, std::
size_t N>
4120auto from_json(
const BasicJsonType& j, T (&arr)[N])
4121->
decltype(j.template get<T>(), void())
4123 for (std::size_t i = 0; i < N; ++i)
4125 arr[i] = j.at(i).template get<T>();
4129template<
typename BasicJsonType>
4130void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4132 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4135template<
typename BasicJsonType,
typename T, std::
size_t N>
4136auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4138->
decltype(j.template get<T>(), void())
4140 for (std::size_t i = 0; i < N; ++i)
4142 arr[i] = j.at(i).template get<T>();
4146template<
typename BasicJsonType,
typename ConstructibleArrayType,
4148 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4150auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4152 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4153 j.template get<typename ConstructibleArrayType::value_type>(),
4158 ConstructibleArrayType ret;
4159 ret.reserve(j.size());
4160 std::transform(j.begin(), j.end(),
4161 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4165 return i.template get<typename ConstructibleArrayType::value_type>();
4167 arr = std::move(ret);
4170template<
typename BasicJsonType,
typename ConstructibleArrayType,
4172 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4174void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4179 ConstructibleArrayType ret;
4181 j.begin(), j.end(), std::inserter(ret, end(ret)),
4182 [](
const BasicJsonType & i)
4186 return i.template get<typename ConstructibleArrayType::value_type>();
4188 arr = std::move(ret);
4191template <
typename BasicJsonType,
typename ConstructibleArrayType,
4193 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4194 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4195 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4196 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4197 !is_basic_json<ConstructibleArrayType>::value,
4199auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4200->
decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4201j.template get<typename ConstructibleArrayType::value_type>(),
4204 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4206 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4209 from_json_array_impl(j, arr, priority_tag<3> {});
4212template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4213std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4214 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4216 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4219template <
typename BasicJsonType,
typename T, std::
size_t N >
4220auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4221->
decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4223 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4225 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4228 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4231template<
typename BasicJsonType>
4232void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4234 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4236 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name()), j));
4239 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4242template<
typename BasicJsonType,
typename ConstructibleObjectType,
4243 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4244void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4246 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4248 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name()), j));
4251 ConstructibleObjectType ret;
4252 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4253 using value_type =
typename ConstructibleObjectType::value_type;
4255 inner_object->begin(), inner_object->end(),
4256 std::inserter(ret, ret.begin()),
4257 [](
typename BasicJsonType::object_t::value_type
const & p)
4259 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4261 obj = std::move(ret);
4268template <
typename BasicJsonType,
typename ArithmeticType,
4270 std::is_arithmetic<ArithmeticType>::value&&
4271 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4272 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4273 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4274 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4276void from_json(
const BasicJsonType& j, ArithmeticType& val)
4278 switch (
static_cast<value_t
>(j))
4280 case value_t::number_unsigned:
4282 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4285 case value_t::number_integer:
4287 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4290 case value_t::number_float:
4292 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4295 case value_t::boolean:
4297 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4302 case value_t::object:
4303 case value_t::array:
4304 case value_t::string:
4305 case value_t::binary:
4306 case value_t::discarded:
4308 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4312template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4313std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
4315 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4318template <
typename BasicJsonType,
class A1,
class A2 >
4319std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4321 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4322 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4325template<
typename BasicJsonType,
typename A1,
typename A2>
4326void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
4328 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4331template<
typename BasicJsonType,
typename... Args>
4332std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4334 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4337template<
typename BasicJsonType,
typename... Args>
4338void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
4340 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4343template<
typename BasicJsonType,
typename TupleRelated>
4344auto from_json(BasicJsonType&& j, TupleRelated&& t)
4345->
decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4347 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4349 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4352 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4355template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4356 typename = enable_if_t < !std::is_constructible <
4357 typename BasicJsonType::string_t, Key >::value >>
4358void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4360 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4362 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4365 for (
const auto& p : j)
4367 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4369 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4371 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4375template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
4376 typename = enable_if_t < !std::is_constructible <
4377 typename BasicJsonType::string_t, Key >::value >>
4378void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4380 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4382 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4385 for (
const auto& p : j)
4387 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4389 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4391 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4397 template<
typename BasicJsonType,
typename T>
4398 auto operator()(
const BasicJsonType& j, T&& val)
const
4399 noexcept(
noexcept(
from_json(j, std::forward<T>(val))))
4400 ->
decltype(
from_json(j, std::forward<T>(val)))
4402 return from_json(j, std::forward<T>(val));
4412constexpr const auto&
from_json = detail::static_const<detail::from_json_fn>::value;
4423#include <type_traits>
4446template<
typename string_type>
4447void int_to_string( string_type& target, std::size_t value )
4450 using std::to_string;
4453template<
typename IteratorType>
class iteration_proxy_value
4456 using difference_type = std::ptrdiff_t;
4457 using value_type = iteration_proxy_value;
4458 using pointer = value_type * ;
4459 using reference = value_type & ;
4460 using iterator_category = std::input_iterator_tag;
4461 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4465 IteratorType anchor;
4467 std::size_t array_index = 0;
4469 mutable std::size_t array_index_last = 0;
4471 mutable string_type array_index_str =
"0";
4473 const string_type empty_str{};
4476 explicit iteration_proxy_value(IteratorType it) noexcept
4477 : anchor(std::move(it))
4481 iteration_proxy_value& operator*()
4487 iteration_proxy_value& operator++()
4496 bool operator==(
const iteration_proxy_value& o)
const
4498 return anchor == o.anchor;
4502 bool operator!=(
const iteration_proxy_value& o)
const
4504 return anchor != o.anchor;
4508 const string_type& key()
const
4510 JSON_ASSERT(anchor.m_object !=
nullptr);
4512 switch (anchor.m_object->type())
4515 case value_t::array:
4517 if (array_index != array_index_last)
4519 int_to_string( array_index_str, array_index );
4520 array_index_last = array_index;
4522 return array_index_str;
4526 case value_t::object:
4527 return anchor.key();
4531 case value_t::string:
4532 case value_t::boolean:
4533 case value_t::number_integer:
4534 case value_t::number_unsigned:
4535 case value_t::number_float:
4536 case value_t::binary:
4537 case value_t::discarded:
4544 typename IteratorType::reference value()
const
4546 return anchor.value();
4551template<
typename IteratorType>
class iteration_proxy
4555 typename IteratorType::reference container;
4559 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
4560 : container(cont) {}
4563 iteration_proxy_value<IteratorType> begin() noexcept
4565 return iteration_proxy_value<IteratorType>(container.begin());
4569 iteration_proxy_value<IteratorType> end() noexcept
4571 return iteration_proxy_value<IteratorType>(container.end());
4577template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
4578auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
4585template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
4586auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
4599#if defined(__clang__)
4601 #pragma clang diagnostic push
4602 #pragma clang diagnostic ignored "-Wmismatched-tags"
4604template<
typename IteratorType>
4605class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4606 :
public std::integral_constant<std::size_t, 2> {};
4608template<std::
size_t N,
typename IteratorType>
4609class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4612 using type =
decltype(
4613 get<N>(std::declval <
4614 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4616#if defined(__clang__)
4617 #pragma clang diagnostic pop
4643template<value_t>
struct external_constructor;
4646struct external_constructor<value_t::boolean>
4648 template<
typename BasicJsonType>
4649 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b)
noexcept
4651 j.m_value.destroy(j.m_type);
4652 j.m_type = value_t::boolean;
4654 j.assert_invariant();
4659struct external_constructor<value_t::string>
4661 template<
typename BasicJsonType>
4662 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
4664 j.m_value.destroy(j.m_type);
4665 j.m_type = value_t::string;
4667 j.assert_invariant();
4670 template<
typename BasicJsonType>
4671 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4673 j.m_value.destroy(j.m_type);
4674 j.m_type = value_t::string;
4675 j.m_value = std::move(s);
4676 j.assert_invariant();
4679 template <
typename BasicJsonType,
typename CompatibleStringType,
4680 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4682 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
4684 j.m_value.destroy(j.m_type);
4685 j.m_type = value_t::string;
4686 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4687 j.assert_invariant();
4692struct external_constructor<value_t::binary>
4694 template<
typename BasicJsonType>
4695 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
4697 j.m_value.destroy(j.m_type);
4698 j.m_type = value_t::binary;
4699 j.m_value =
typename BasicJsonType::binary_t(b);
4700 j.assert_invariant();
4703 template<
typename BasicJsonType>
4704 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
4706 j.m_value.destroy(j.m_type);
4707 j.m_type = value_t::binary;
4708 j.m_value =
typename BasicJsonType::binary_t(std::move(b));
4709 j.assert_invariant();
4714struct external_constructor<value_t::number_float>
4716 template<
typename BasicJsonType>
4717 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val)
noexcept
4719 j.m_value.destroy(j.m_type);
4720 j.m_type = value_t::number_float;
4722 j.assert_invariant();
4727struct external_constructor<value_t::number_unsigned>
4729 template<
typename BasicJsonType>
4730 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val)
noexcept
4732 j.m_value.destroy(j.m_type);
4733 j.m_type = value_t::number_unsigned;
4735 j.assert_invariant();
4740struct external_constructor<value_t::number_integer>
4742 template<
typename BasicJsonType>
4743 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val)
noexcept
4745 j.m_value.destroy(j.m_type);
4746 j.m_type = value_t::number_integer;
4748 j.assert_invariant();
4753struct external_constructor<value_t::array>
4755 template<
typename BasicJsonType>
4756 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
4758 j.m_value.destroy(j.m_type);
4759 j.m_type = value_t::array;
4762 j.assert_invariant();
4765 template<
typename BasicJsonType>
4766 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4768 j.m_value.destroy(j.m_type);
4769 j.m_type = value_t::array;
4770 j.m_value = std::move(arr);
4772 j.assert_invariant();
4775 template <
typename BasicJsonType,
typename CompatibleArrayType,
4776 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4778 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
4783 j.m_value.destroy(j.m_type);
4784 j.m_type = value_t::array;
4785 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4787 j.assert_invariant();
4790 template<
typename BasicJsonType>
4791 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
4793 j.m_value.destroy(j.m_type);
4794 j.m_type = value_t::array;
4795 j.m_value = value_t::array;
4796 j.m_value.array->reserve(arr.size());
4797 for (
const bool x : arr)
4799 j.m_value.array->push_back(x);
4800 j.set_parent(j.m_value.array->back());
4802 j.assert_invariant();
4805 template<
typename BasicJsonType,
typename T,
4806 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4807 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
4809 j.m_value.destroy(j.m_type);
4810 j.m_type = value_t::array;
4811 j.m_value = value_t::array;
4812 j.m_value.array->resize(arr.size());
4815 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4818 j.assert_invariant();
4823struct external_constructor<value_t::object>
4825 template<
typename BasicJsonType>
4826 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
4828 j.m_value.destroy(j.m_type);
4829 j.m_type = value_t::object;
4832 j.assert_invariant();
4835 template<
typename BasicJsonType>
4836 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4838 j.m_value.destroy(j.m_type);
4839 j.m_type = value_t::object;
4840 j.m_value = std::move(obj);
4842 j.assert_invariant();
4845 template <
typename BasicJsonType,
typename CompatibleObjectType,
4846 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4847 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
4852 j.m_value.destroy(j.m_type);
4853 j.m_type = value_t::object;
4854 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4856 j.assert_invariant();
4864template<
typename BasicJsonType,
typename T,
4865 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4866void to_json(BasicJsonType& j, T b)
noexcept
4868 external_constructor<value_t::boolean>::construct(j, b);
4871template<
typename BasicJsonType,
typename CompatibleString,
4872 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4873void to_json(BasicJsonType& j,
const CompatibleString& s)
4875 external_constructor<value_t::string>::construct(j, s);
4878template<
typename BasicJsonType>
4879void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4881 external_constructor<value_t::string>::construct(j, std::move(s));
4884template<
typename BasicJsonType,
typename FloatType,
4885 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4886void to_json(BasicJsonType& j, FloatType val)
noexcept
4888 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4891template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4892 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4893void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val)
noexcept
4895 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4898template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4899 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4900void to_json(BasicJsonType& j, CompatibleNumberIntegerType val)
noexcept
4902 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4905template<
typename BasicJsonType,
typename EnumType,
4906 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4907void to_json(BasicJsonType& j, EnumType e)
noexcept
4909 using underlying_type =
typename std::underlying_type<EnumType>::type;
4910 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4913template<
typename BasicJsonType>
4914void to_json(BasicJsonType& j,
const std::vector<bool>& e)
4916 external_constructor<value_t::array>::construct(j, e);
4919template <
typename BasicJsonType,
typename CompatibleArrayType,
4920 enable_if_t < is_compatible_array_type<BasicJsonType,
4921 CompatibleArrayType>::value&&
4922 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4923 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4924 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4925 !is_basic_json<CompatibleArrayType>::value,
4927void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4929 external_constructor<value_t::array>::construct(j, arr);
4932template<
typename BasicJsonType>
4933void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
4935 external_constructor<value_t::binary>::construct(j, bin);
4938template<
typename BasicJsonType,
typename T,
4939 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4940void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4942 external_constructor<value_t::array>::construct(j, std::move(arr));
4945template<
typename BasicJsonType>
4946void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4948 external_constructor<value_t::array>::construct(j, std::move(arr));
4951template <
typename BasicJsonType,
typename CompatibleObjectType,
4952 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4953void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4955 external_constructor<value_t::object>::construct(j, obj);
4958template<
typename BasicJsonType>
4959void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4961 external_constructor<value_t::object>::construct(j, std::move(obj));
4965 typename BasicJsonType,
typename T, std::size_t N,
4966 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4967 const T(&)[N]>::value,
4969void to_json(BasicJsonType& j,
const T(&arr)[N])
4971 external_constructor<value_t::array>::construct(j, arr);
4974template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4975void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
4977 j = { p.first, p.second };
4981template<
typename BasicJsonType,
typename T,
4982 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4983void to_json(BasicJsonType& j,
const T& b)
4985 j = { {b.key(), b.value()} };
4988template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4989void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
4991 j = { std::get<Idx>(t)... };
4994template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4995void to_json(BasicJsonType& j,
const T& t)
4997 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
5002 template<
typename BasicJsonType,
typename T>
5003 auto operator()(BasicJsonType& j, T&& val)
const noexcept(
noexcept(
to_json(j, std::forward<T>(val))))
5004 ->
decltype(
to_json(j, std::forward<T>(val)), void())
5006 return to_json(j, std::forward<T>(val));
5016constexpr const auto&
to_json = detail::static_const<detail::to_json_fn>::value;
5028template<
typename ValueType,
typename>
5042 template<
typename BasicJsonType,
typename TargetType = ValueType>
5043 static auto from_json(BasicJsonType && j, TargetType& val)
noexcept(
5044 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
5045 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
5047 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
5062 template<
typename BasicJsonType,
typename TargetType = ValueType>
5064 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
5065 ->
decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
5067 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
5079 template<
typename BasicJsonType,
typename TargetType = ValueType>
5080 static auto to_json(BasicJsonType& j, TargetType && val)
noexcept(
5081 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5082 ->
decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
5084 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5112template<
typename BinaryType>
5135 , m_subtype(subtype_)
5136 , m_has_subtype(
true)
5141 , m_subtype(subtype_)
5142 , m_has_subtype(
true)
5147 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5148 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5153 return !(rhs == *
this);
5176 m_subtype = subtype_;
5177 m_has_subtype =
true;
5225 return m_has_subtype;
5250 m_has_subtype =
false;
5255 bool m_has_subtype =
false;
5271#include <functional>
5284inline std::size_t combine(std::size_t seed, std::size_t h)
noexcept
5286 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5301template<
typename BasicJsonType>
5302std::size_t hash(
const BasicJsonType& j)
5304 using string_t =
typename BasicJsonType::string_t;
5305 using number_integer_t =
typename BasicJsonType::number_integer_t;
5306 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5307 using number_float_t =
typename BasicJsonType::number_float_t;
5309 const auto type =
static_cast<std::size_t
>(j.type());
5312 case BasicJsonType::value_t::null:
5313 case BasicJsonType::value_t::discarded:
5315 return combine(type, 0);
5318 case BasicJsonType::value_t::object:
5320 auto seed = combine(type, j.size());
5321 for (
const auto& element : j.items())
5323 const auto h = std::hash<string_t> {}(element.key());
5324 seed = combine(seed, h);
5325 seed = combine(seed, hash(element.value()));
5330 case BasicJsonType::value_t::array:
5332 auto seed = combine(type, j.size());
5333 for (
const auto& element : j)
5335 seed = combine(seed, hash(element));
5340 case BasicJsonType::value_t::string:
5342 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5343 return combine(type, h);
5346 case BasicJsonType::value_t::boolean:
5348 const auto h = std::hash<bool> {}(j.template get<bool>());
5349 return combine(type, h);
5352 case BasicJsonType::value_t::number_integer:
5354 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5355 return combine(type, h);
5358 case BasicJsonType::value_t::number_unsigned:
5360 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5361 return combine(type, h);
5364 case BasicJsonType::value_t::number_float:
5366 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5367 return combine(type, h);
5370 case BasicJsonType::value_t::binary:
5372 auto seed = combine(type, j.get_binary().size());
5373 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5374 seed = combine(seed, h);
5375 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
5376 for (
const auto byte : j.get_binary())
5378 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5420#include <type_traits>
5438enum class input_format_t {
json, cbor, msgpack, ubjson, bson };
5449class file_input_adapter
5452 using char_type = char;
5454 JSON_HEDLEY_NON_NULL(2)
5455 explicit file_input_adapter(
std::FILE* f) noexcept
5460 file_input_adapter(
const file_input_adapter&) =
delete;
5461 file_input_adapter(file_input_adapter&&) noexcept = default;
5462 file_input_adapter& operator=(const file_input_adapter&) = delete;
5463 file_input_adapter& operator=(file_input_adapter&&) = delete;
5464 ~file_input_adapter() = default;
5466 std::char_traits<
char>::int_type get_character() noexcept
5468 return std::fgetc(m_file);
5486class input_stream_adapter
5489 using char_type = char;
5491 ~input_stream_adapter()
5497 is->clear(is->rdstate() & std::ios::eofbit);
5501 explicit input_stream_adapter(std::istream& i)
5502 : is(&i), sb(i.rdbuf())
5506 input_stream_adapter(
const input_stream_adapter&) =
delete;
5507 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
5508 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
5510 input_stream_adapter(input_stream_adapter&& rhs) noexcept
5511 : is(rhs.is), sb(rhs.sb)
5520 std::char_traits<char>::int_type get_character()
5522 auto res = sb->sbumpc();
5524 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
5526 is->clear(is->rdstate() | std::ios::eofbit);
5533 std::istream* is =
nullptr;
5534 std::streambuf* sb =
nullptr;
5540template<
typename IteratorType>
5541class iterator_input_adapter
5544 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
5546 iterator_input_adapter(IteratorType first, IteratorType last)
5547 : current(
std::move(first)), end(
std::move(last))
5550 typename std::char_traits<char_type>::int_type get_character()
5552 if (JSON_HEDLEY_LIKELY(current != end))
5554 auto result = std::char_traits<char_type>::to_int_type(*current);
5555 std::advance(current, 1);
5559 return std::char_traits<char_type>::eof();
5563 IteratorType current;
5566 template<
typename BaseInputAdapter,
size_t T>
5567 friend struct wide_string_input_helper;
5571 return current == end;
5576template<
typename BaseInputAdapter,
size_t T>
5577struct wide_string_input_helper;
5579template<
typename BaseInputAdapter>
5580struct wide_string_input_helper<BaseInputAdapter, 4>
5583 static void fill_buffer(BaseInputAdapter& input,
5584 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5585 size_t& utf8_bytes_index,
5586 size_t& utf8_bytes_filled)
5588 utf8_bytes_index = 0;
5590 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5592 utf8_bytes[0] = std::char_traits<char>::eof();
5593 utf8_bytes_filled = 1;
5598 const auto wc = input.get_character();
5603 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5604 utf8_bytes_filled = 1;
5606 else if (wc <= 0x7FF)
5608 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5609 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5610 utf8_bytes_filled = 2;
5612 else if (wc <= 0xFFFF)
5614 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5615 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5616 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5617 utf8_bytes_filled = 3;
5619 else if (wc <= 0x10FFFF)
5621 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5622 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5623 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5624 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5625 utf8_bytes_filled = 4;
5630 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5631 utf8_bytes_filled = 1;
5637template<
typename BaseInputAdapter>
5638struct wide_string_input_helper<BaseInputAdapter, 2>
5641 static void fill_buffer(BaseInputAdapter& input,
5642 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5643 size_t& utf8_bytes_index,
5644 size_t& utf8_bytes_filled)
5646 utf8_bytes_index = 0;
5648 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5650 utf8_bytes[0] = std::char_traits<char>::eof();
5651 utf8_bytes_filled = 1;
5656 const auto wc = input.get_character();
5661 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5662 utf8_bytes_filled = 1;
5664 else if (wc <= 0x7FF)
5666 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
5667 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5668 utf8_bytes_filled = 2;
5670 else if (0xD800 > wc || wc >= 0xE000)
5672 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
5673 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5674 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5675 utf8_bytes_filled = 3;
5679 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5681 const auto wc2 =
static_cast<unsigned int>(input.get_character());
5682 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5683 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
5684 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
5685 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
5686 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
5687 utf8_bytes_filled = 4;
5691 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5692 utf8_bytes_filled = 1;
5700template<
typename BaseInputAdapter,
typename W
ideCharType>
5701class wide_string_input_adapter
5704 using char_type = char;
5706 wide_string_input_adapter(BaseInputAdapter base)
5707 : base_adapter(base) {}
5709 typename std::char_traits<char>::int_type get_character() noexcept
5712 if (utf8_bytes_index == utf8_bytes_filled)
5714 fill_buffer<sizeof(WideCharType)>();
5716 JSON_ASSERT(utf8_bytes_filled > 0);
5717 JSON_ASSERT(utf8_bytes_index == 0);
5721 JSON_ASSERT(utf8_bytes_filled > 0);
5722 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5723 return utf8_bytes[utf8_bytes_index++];
5727 BaseInputAdapter base_adapter;
5732 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5736 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5739 std::size_t utf8_bytes_index = 0;
5741 std::size_t utf8_bytes_filled = 0;
5745template<
typename IteratorType,
typename Enable =
void>
5746struct iterator_input_adapter_factory
5748 using iterator_type = IteratorType;
5749 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5750 using adapter_type = iterator_input_adapter<iterator_type>;
5752 static adapter_type create(IteratorType first, IteratorType last)
5754 return adapter_type(std::move(first), std::move(last));
5759struct is_iterator_of_multibyte
5761 using value_type =
typename std::iterator_traits<T>::value_type;
5764 value =
sizeof(value_type) > 1
5768template<
typename IteratorType>
5769struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5771 using iterator_type = IteratorType;
5772 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5773 using base_adapter_type = iterator_input_adapter<iterator_type>;
5774 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5776 static adapter_type create(IteratorType first, IteratorType last)
5778 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5783template<
typename IteratorType>
5784typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5786 using factory_type = iterator_input_adapter_factory<IteratorType>;
5787 return factory_type::create(first, last);
5794namespace container_input_adapter_factory_impl
5800template<
typename ContainerType,
typename Enable =
void>
5801struct container_input_adapter_factory {};
5803template<
typename ContainerType>
5804struct container_input_adapter_factory< ContainerType,
5805 void_t<decltype(begin(
std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5807 using adapter_type =
decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5809 static adapter_type create(
const ContainerType& container)
5811 return input_adapter(begin(container), end(container));
5817template<
typename ContainerType>
5818typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
5820 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
5825inline file_input_adapter input_adapter(std::FILE* file)
5827 return file_input_adapter(file);
5830inline input_stream_adapter input_adapter(std::istream& stream)
5832 return input_stream_adapter(stream);
5835inline input_stream_adapter input_adapter(std::istream&& stream)
5837 return input_stream_adapter(stream);
5841using contiguous_bytes_input_adapter =
decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5844template <
typename CharT,
5845 typename std::enable_if <
5846 std::is_pointer<CharT>::value&&
5847 !std::is_array<CharT>::value&&
5848 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5849 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5851contiguous_bytes_input_adapter input_adapter(CharT b)
5853 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
5854 const auto* ptr =
reinterpret_cast<const char*
>(b);
5855 return input_adapter(ptr, ptr + length);
5858template<
typename T, std::
size_t N>
5859auto input_adapter(T (&array)[N]) ->
decltype(input_adapter(array, array + N))
5861 return input_adapter(array, array + N);
5867class span_input_adapter
5870 template <
typename CharT,
5871 typename std::enable_if <
5872 std::is_pointer<CharT>::value&&
5873 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5874 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5876 span_input_adapter(CharT b, std::size_t l)
5877 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5879 template<
class IteratorType,
5880 typename std::enable_if<
5881 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5883 span_input_adapter(IteratorType first, IteratorType last)
5884 : ia(input_adapter(first, last)) {}
5886 contiguous_bytes_input_adapter&& get()
5888 return std::move(ia);
5892 contiguous_bytes_input_adapter ia;
5921template<
typename BasicJsonType>
5934 virtual bool null() = 0;
6025 const std::string& last_token,
6026 const detail::exception& ex) = 0;
6052template<
typename BasicJsonType>
6053class json_sax_dom_parser
6059 using string_t =
typename BasicJsonType::string_t;
6060 using binary_t =
typename BasicJsonType::binary_t;
6067 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true)
6068 : root(r), allow_exceptions(allow_exceptions_)
6072 json_sax_dom_parser(
const json_sax_dom_parser&) =
delete;
6073 json_sax_dom_parser(json_sax_dom_parser&&) =
default;
6074 json_sax_dom_parser&
operator=(
const json_sax_dom_parser&) =
delete;
6075 json_sax_dom_parser&
operator=(json_sax_dom_parser&&) =
default;
6076 ~json_sax_dom_parser() =
default;
6080 handle_value(
nullptr);
6116 handle_value(std::move(val));
6122 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6124 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6126 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6135 object_element = &(ref_stack.back()->m_value.object->operator[](val));
6141 ref_stack.back()->set_parents();
6142 ref_stack.pop_back();
6148 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6150 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6152 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6160 ref_stack.back()->set_parents();
6161 ref_stack.pop_back();
6165 template<
class Exception>
6166 bool parse_error(std::size_t ,
const std::string& ,
6167 const Exception& ex)
6170 static_cast<void>(ex);
6171 if (allow_exceptions)
6178 constexpr bool is_errored()
const
6190 template<
typename Value>
6192 BasicJsonType* handle_value(Value&& v)
6194 if (ref_stack.empty())
6196 root = BasicJsonType(std::forward<Value>(v));
6200 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6202 if (ref_stack.back()->is_array())
6204 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6205 return &(ref_stack.back()->m_value.array->back());
6208 JSON_ASSERT(ref_stack.back()->is_object());
6209 JSON_ASSERT(object_element);
6210 *object_element = BasicJsonType(std::forward<Value>(v));
6211 return object_element;
6215 BasicJsonType& root;
6217 std::vector<BasicJsonType*> ref_stack {};
6219 BasicJsonType* object_element =
nullptr;
6221 bool errored =
false;
6223 const bool allow_exceptions =
true;
6226template<
typename BasicJsonType>
6227class json_sax_dom_callback_parser
6233 using string_t =
typename BasicJsonType::string_t;
6234 using binary_t =
typename BasicJsonType::binary_t;
6235 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6236 using parse_event_t =
typename BasicJsonType::parse_event_t;
6238 json_sax_dom_callback_parser(BasicJsonType& r,
6239 const parser_callback_t cb,
6240 const bool allow_exceptions_ =
true)
6241 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6243 keep_stack.push_back(
true);
6247 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
6248 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
6249 json_sax_dom_callback_parser&
operator=(
const json_sax_dom_callback_parser&) =
delete;
6250 json_sax_dom_callback_parser&
operator=(json_sax_dom_callback_parser&&) =
default;
6251 ~json_sax_dom_callback_parser() =
default;
6255 handle_value(
nullptr);
6291 handle_value(std::move(val));
6298 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
6299 keep_stack.push_back(keep);
6301 auto val = handle_value(BasicJsonType::value_t::object,
true);
6302 ref_stack.push_back(val.second);
6305 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6307 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6315 BasicJsonType k = BasicJsonType(val);
6318 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
6319 key_keep_stack.push_back(keep);
6322 if (keep && ref_stack.back())
6324 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
6332 if (ref_stack.back())
6334 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6337 *ref_stack.back() = discarded;
6341 ref_stack.back()->set_parents();
6345 JSON_ASSERT(!ref_stack.empty());
6346 JSON_ASSERT(!keep_stack.empty());
6347 ref_stack.pop_back();
6348 keep_stack.pop_back();
6350 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6353 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6355 if (it->is_discarded())
6357 ref_stack.back()->erase(it);
6368 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
6369 keep_stack.push_back(keep);
6371 auto val = handle_value(BasicJsonType::value_t::array,
true);
6372 ref_stack.push_back(val.second);
6375 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6377 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6387 if (ref_stack.back())
6389 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6392 ref_stack.back()->set_parents();
6397 *ref_stack.back() = discarded;
6401 JSON_ASSERT(!ref_stack.empty());
6402 JSON_ASSERT(!keep_stack.empty());
6403 ref_stack.pop_back();
6404 keep_stack.pop_back();
6407 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6409 ref_stack.back()->m_value.array->pop_back();
6415 template<
class Exception>
6416 bool parse_error(std::size_t ,
const std::string& ,
6417 const Exception& ex)
6420 static_cast<void>(ex);
6421 if (allow_exceptions)
6428 constexpr bool is_errored()
const
6449 template<
typename Value>
6450 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
6452 JSON_ASSERT(!keep_stack.empty());
6456 if (!keep_stack.back())
6458 return {
false,
nullptr};
6462 auto value = BasicJsonType(std::forward<Value>(v));
6465 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6470 return {
false,
nullptr};
6473 if (ref_stack.empty())
6475 root = std::move(value);
6476 return {
true, &root};
6481 if (!ref_stack.back())
6483 return {
false,
nullptr};
6487 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6490 if (ref_stack.back()->is_array())
6492 ref_stack.back()->m_value.array->emplace_back(std::move(value));
6493 return {
true, &(ref_stack.back()->m_value.array->back())};
6497 JSON_ASSERT(ref_stack.back()->is_object());
6499 JSON_ASSERT(!key_keep_stack.empty());
6500 const bool store_element = key_keep_stack.back();
6501 key_keep_stack.pop_back();
6505 return {
false,
nullptr};
6508 JSON_ASSERT(object_element);
6509 *object_element = std::move(value);
6510 return {
true, object_element};
6514 BasicJsonType& root;
6516 std::vector<BasicJsonType*> ref_stack {};
6518 std::vector<bool> keep_stack {};
6520 std::vector<bool> key_keep_stack {};
6522 BasicJsonType* object_element =
nullptr;
6524 bool errored =
false;
6526 const parser_callback_t callback =
nullptr;
6528 const bool allow_exceptions =
true;
6530 BasicJsonType discarded = BasicJsonType::value_t::discarded;
6533template<
typename BasicJsonType>
6534class json_sax_acceptor
6540 using string_t =
typename BasicJsonType::string_t;
6541 using binary_t =
typename BasicJsonType::binary_t;
6603 bool parse_error(std::size_t ,
const std::string& ,
const detail::exception& )
6620#include <initializer_list>
6640template<
typename BasicJsonType>
6645 enum class token_type
6669 static const char* token_type_name(
const token_type t)
noexcept
6673 case token_type::uninitialized:
6674 return "<uninitialized>";
6675 case token_type::literal_true:
6676 return "true literal";
6677 case token_type::literal_false:
6678 return "false literal";
6679 case token_type::literal_null:
6680 return "null literal";
6681 case token_type::value_string:
6682 return "string literal";
6683 case token_type::value_unsigned:
6684 case token_type::value_integer:
6685 case token_type::value_float:
6686 return "number literal";
6687 case token_type::begin_array:
6689 case token_type::begin_object:
6691 case token_type::end_array:
6693 case token_type::end_object:
6695 case token_type::name_separator:
6697 case token_type::value_separator:
6699 case token_type::parse_error:
6700 return "<parse error>";
6701 case token_type::end_of_input:
6702 return "end of input";
6703 case token_type::literal_or_value:
6704 return "'[', '{', or a literal";
6707 return "unknown token";
6717template<
typename BasicJsonType,
typename InputAdapterType>
6718class lexer :
public lexer_base<BasicJsonType>
6720 using number_integer_t =
typename BasicJsonType::number_integer_t;
6721 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6722 using number_float_t =
typename BasicJsonType::number_float_t;
6723 using string_t =
typename BasicJsonType::string_t;
6724 using char_type =
typename InputAdapterType::char_type;
6725 using char_int_type =
typename std::char_traits<char_type>::int_type;
6728 using token_type =
typename lexer_base<BasicJsonType>::token_type;
6730 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
6731 : ia(
std::move(adapter))
6732 , ignore_comments(ignore_comments_)
6733 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6737 lexer(
const lexer&) =
delete;
6738 lexer(lexer&&) =
default;
6739 lexer& operator=(lexer&) =
delete;
6740 lexer& operator=(lexer&&) =
default;
6750 static char get_decimal_point() noexcept
6752 const auto* loc = localeconv();
6753 JSON_ASSERT(loc !=
nullptr);
6754 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6779 JSON_ASSERT(current ==
'u');
6782 const auto factors = { 12u, 8u, 4u, 0u };
6783 for (
const auto factor : factors)
6787 if (current >=
'0' && current <=
'9')
6789 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
6791 else if (current >=
'A' && current <=
'F')
6793 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
6795 else if (current >=
'a' && current <=
'f')
6797 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
6805 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6824 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6826 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6829 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6832 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6838 error_message =
"invalid string: ill-formed UTF-8 byte";
6861 token_type scan_string()
6867 JSON_ASSERT(current ==
'\"');
6875 case std::char_traits<char_type>::eof():
6877 error_message =
"invalid string: missing closing quote";
6878 return token_type::parse_error;
6884 return token_type::value_string;
6928 const int codepoint1 = get_codepoint();
6929 int codepoint = codepoint1;
6931 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6933 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6934 return token_type::parse_error;
6938 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6941 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6943 const int codepoint2 = get_codepoint();
6945 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6947 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6948 return token_type::parse_error;
6952 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6955 codepoint =
static_cast<int>(
6957 (
static_cast<unsigned int>(codepoint1) << 10u)
6959 +
static_cast<unsigned int>(codepoint2)
6967 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6968 return token_type::parse_error;
6973 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6974 return token_type::parse_error;
6979 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6981 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6982 return token_type::parse_error;
6987 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6990 if (codepoint < 0x80)
6993 add(
static_cast<char_int_type
>(codepoint));
6995 else if (codepoint <= 0x7FF)
6998 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6999 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7001 else if (codepoint <= 0xFFFF)
7004 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
7005 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7006 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7011 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
7012 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
7013 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
7014 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
7022 error_message =
"invalid string: forbidden character after backslash";
7023 return token_type::parse_error;
7032 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
7033 return token_type::parse_error;
7038 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
7039 return token_type::parse_error;
7044 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
7045 return token_type::parse_error;
7050 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
7051 return token_type::parse_error;
7056 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
7057 return token_type::parse_error;
7062 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
7063 return token_type::parse_error;
7068 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
7069 return token_type::parse_error;
7074 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
7075 return token_type::parse_error;
7080 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7081 return token_type::parse_error;
7086 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7087 return token_type::parse_error;
7092 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7093 return token_type::parse_error;
7098 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7099 return token_type::parse_error;
7104 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7105 return token_type::parse_error;
7110 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7111 return token_type::parse_error;
7116 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7117 return token_type::parse_error;
7122 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7123 return token_type::parse_error;
7128 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7129 return token_type::parse_error;
7134 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7135 return token_type::parse_error;
7140 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7141 return token_type::parse_error;
7146 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7147 return token_type::parse_error;
7152 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7153 return token_type::parse_error;
7158 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7159 return token_type::parse_error;
7164 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7165 return token_type::parse_error;
7170 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7171 return token_type::parse_error;
7176 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7177 return token_type::parse_error;
7182 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7183 return token_type::parse_error;
7188 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7189 return token_type::parse_error;
7194 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7195 return token_type::parse_error;
7200 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7201 return token_type::parse_error;
7206 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7207 return token_type::parse_error;
7212 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7213 return token_type::parse_error;
7218 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7219 return token_type::parse_error;
7354 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7356 return token_type::parse_error;
7364 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7366 return token_type::parse_error;
7388 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7390 return token_type::parse_error;
7398 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7400 return token_type::parse_error;
7408 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7410 return token_type::parse_error;
7420 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7422 return token_type::parse_error;
7430 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7432 return token_type::parse_error;
7440 error_message =
"invalid string: ill-formed UTF-8 byte";
7441 return token_type::parse_error;
7464 case std::char_traits<char_type>::eof():
7481 case std::char_traits<char_type>::eof():
7484 error_message =
"invalid comment; missing closing '*/'";
7512 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7518 JSON_HEDLEY_NON_NULL(2)
7519 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7521 f = std::strtof(str, endptr);
7524 JSON_HEDLEY_NON_NULL(2)
7525 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7527 f = std::strtod(str, endptr);
7530 JSON_HEDLEY_NON_NULL(2)
7531 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
7533 f = std::strtold(str, endptr);
7576 token_type scan_number()
7583 token_type number_type = token_type::value_unsigned;
7591 goto scan_number_minus;
7597 goto scan_number_zero;
7611 goto scan_number_any1;
7621 number_type = token_type::value_integer;
7627 goto scan_number_zero;
7641 goto scan_number_any1;
7646 error_message =
"invalid number; expected digit after '-'";
7647 return token_type::parse_error;
7657 add(decimal_point_char);
7658 goto scan_number_decimal1;
7665 goto scan_number_exponent;
7669 goto scan_number_done;
7688 goto scan_number_any1;
7693 add(decimal_point_char);
7694 goto scan_number_decimal1;
7701 goto scan_number_exponent;
7705 goto scan_number_done;
7708scan_number_decimal1:
7710 number_type = token_type::value_float;
7725 goto scan_number_decimal2;
7730 error_message =
"invalid number; expected digit after '.'";
7731 return token_type::parse_error;
7735scan_number_decimal2:
7751 goto scan_number_decimal2;
7758 goto scan_number_exponent;
7762 goto scan_number_done;
7765scan_number_exponent:
7767 number_type = token_type::value_float;
7774 goto scan_number_sign;
7789 goto scan_number_any2;
7795 "invalid number; expected '+', '-', or digit after exponent";
7796 return token_type::parse_error;
7816 goto scan_number_any2;
7821 error_message =
"invalid number; expected digit after exponent sign";
7822 return token_type::parse_error;
7842 goto scan_number_any2;
7846 goto scan_number_done;
7854 char* endptr =
nullptr;
7858 if (number_type == token_type::value_unsigned)
7860 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7863 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7867 value_unsigned =
static_cast<number_unsigned_t
>(x);
7868 if (value_unsigned == x)
7870 return token_type::value_unsigned;
7874 else if (number_type == token_type::value_integer)
7876 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7879 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7883 value_integer =
static_cast<number_integer_t
>(x);
7884 if (value_integer == x)
7886 return token_type::value_integer;
7893 strtof(value_float, token_buffer.data(), &endptr);
7896 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7898 return token_type::value_float;
7906 JSON_HEDLEY_NON_NULL(2)
7907 token_type scan_literal(const char_type* literal_text, const
std::
size_t length,
7908 token_type return_type)
7910 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7911 for (std::size_t i = 1; i < length; ++i)
7913 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7915 error_message =
"invalid literal";
7916 return token_type::parse_error;
7927 void reset() noexcept
7929 token_buffer.clear();
7930 token_string.clear();
7931 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7946 ++position.chars_read_total;
7947 ++position.chars_read_current_line;
7956 current = ia.get_character();
7959 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7961 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7964 if (current ==
'\n')
7966 ++position.lines_read;
7967 position.chars_read_current_line = 0;
7985 --position.chars_read_total;
7988 if (position.chars_read_current_line == 0)
7990 if (position.lines_read > 0)
7992 --position.lines_read;
7997 --position.chars_read_current_line;
8000 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
8002 JSON_ASSERT(!token_string.empty());
8003 token_string.pop_back();
8008 void add(char_int_type c)
8010 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
8019 constexpr number_integer_t get_number_integer() const noexcept
8021 return value_integer;
8025 constexpr number_unsigned_t get_number_unsigned() const noexcept
8027 return value_unsigned;
8031 constexpr number_float_t get_number_float() const noexcept
8037 string_t& get_string()
8039 return token_buffer;
8047 constexpr position_t get_position() const noexcept
8055 std::string get_token_string()
const
8059 for (
const auto c : token_string)
8061 if (
static_cast<unsigned char>(c) <=
'\x1F')
8064 std::array<char, 9> cs{{}};
8065 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
8066 result += cs.data();
8071 result.push_back(
static_cast<std::string::value_type
>(c));
8080 constexpr const char* get_error_message() const noexcept
8082 return error_message;
8098 return get() == 0xBB && get() == 0xBF;
8107 void skip_whitespace()
8113 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8119 if (position.chars_read_total == 0 && !skip_bom())
8121 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8122 return token_type::parse_error;
8129 while (ignore_comments && current ==
'/')
8131 if (!scan_comment())
8133 return token_type::parse_error;
8144 return token_type::begin_array;
8146 return token_type::end_array;
8148 return token_type::begin_object;
8150 return token_type::end_object;
8152 return token_type::name_separator;
8154 return token_type::value_separator;
8159 std::array<char_type, 4> true_literal = {{char_type(
't'), char_type(
'r'), char_type(
'u'), char_type(
'e')}};
8160 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8164 std::array<char_type, 5> false_literal = {{char_type(
'f'), char_type(
'a'), char_type(
'l'), char_type(
's'), char_type(
'e')}};
8165 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8169 std::array<char_type, 4> null_literal = {{char_type(
'n'), char_type(
'u'), char_type(
'l'), char_type(
'l')}};
8170 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8175 return scan_string();
8189 return scan_number();
8194 case std::char_traits<char_type>::eof():
8195 return token_type::end_of_input;
8199 error_message =
"invalid literal";
8200 return token_type::parse_error;
8206 InputAdapterType ia;
8209 const bool ignore_comments =
false;
8212 char_int_type current = std::char_traits<char_type>::eof();
8215 bool next_unget =
false;
8218 position_t position {};
8221 std::vector<char_type> token_string {};
8224 string_t token_buffer {};
8227 const char* error_message =
"";
8230 number_integer_t value_integer = 0;
8231 number_unsigned_t value_unsigned = 0;
8232 number_float_t value_float = 0;
8235 const char_int_type decimal_point_char =
'.';
8259using null_function_t =
decltype(std::declval<T&>().null());
8262using boolean_function_t =
8263 decltype(std::declval<T&>().boolean(std::declval<bool>()));
8265template<
typename T,
typename Integer>
8266using number_integer_function_t =
8267 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8269template<
typename T,
typename Un
signed>
8270using number_unsigned_function_t =
8271 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8273template<
typename T,
typename Float,
typename String>
8274using number_float_function_t =
decltype(std::declval<T&>().number_float(
8275 std::declval<Float>(), std::declval<const String&>()));
8277template<
typename T,
typename String>
8278using string_function_t =
8279 decltype(std::declval<T&>().string(std::declval<String&>()));
8281template<
typename T,
typename Binary>
8282using binary_function_t =
8283 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8286using start_object_function_t =
8287 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8289template<
typename T,
typename String>
8290using key_function_t =
8291 decltype(std::declval<T&>().key(std::declval<String&>()));
8294using end_object_function_t =
decltype(std::declval<T&>().end_object());
8297using start_array_function_t =
8298 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
8301using end_array_function_t =
decltype(std::declval<T&>().end_array());
8303template<
typename T,
typename Exception>
8304using parse_error_function_t =
decltype(std::declval<T&>().parse_error(
8305 std::declval<std::size_t>(), std::declval<const std::string&>(),
8306 std::declval<const Exception&>()));
8308template<
typename SAX,
typename BasicJsonType>
8312 static_assert(is_basic_json<BasicJsonType>::value,
8313 "BasicJsonType must be of type basic_json<...>");
8315 using number_integer_t =
typename BasicJsonType::number_integer_t;
8316 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8317 using number_float_t =
typename BasicJsonType::number_float_t;
8318 using string_t =
typename BasicJsonType::string_t;
8319 using binary_t =
typename BasicJsonType::binary_t;
8320 using exception_t =
typename BasicJsonType::exception;
8323 static constexpr bool value =
8324 is_detected_exact<bool, null_function_t, SAX>::value &&
8325 is_detected_exact<bool, boolean_function_t, SAX>::value &&
8326 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8327 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8328 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8329 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8330 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8331 is_detected_exact<bool, start_object_function_t, SAX>::value &&
8332 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8333 is_detected_exact<bool, end_object_function_t, SAX>::value &&
8334 is_detected_exact<bool, start_array_function_t, SAX>::value &&
8335 is_detected_exact<bool, end_array_function_t, SAX>::value &&
8336 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8339template<
typename SAX,
typename BasicJsonType>
8340struct is_sax_static_asserts
8343 static_assert(is_basic_json<BasicJsonType>::value,
8344 "BasicJsonType must be of type basic_json<...>");
8346 using number_integer_t =
typename BasicJsonType::number_integer_t;
8347 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8348 using number_float_t =
typename BasicJsonType::number_float_t;
8349 using string_t =
typename BasicJsonType::string_t;
8350 using binary_t =
typename BasicJsonType::binary_t;
8351 using exception_t =
typename BasicJsonType::exception;
8354 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8355 "Missing/invalid function: bool null()");
8356 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8357 "Missing/invalid function: bool boolean(bool)");
8358 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8359 "Missing/invalid function: bool boolean(bool)");
8361 is_detected_exact<bool, number_integer_function_t, SAX,
8362 number_integer_t>::value,
8363 "Missing/invalid function: bool number_integer(number_integer_t)");
8365 is_detected_exact<bool, number_unsigned_function_t, SAX,
8366 number_unsigned_t>::value,
8367 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8368 static_assert(is_detected_exact<bool, number_float_function_t, SAX,
8369 number_float_t, string_t>::value,
8370 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8372 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8373 "Missing/invalid function: bool string(string_t&)");
8375 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8376 "Missing/invalid function: bool binary(binary_t&)");
8377 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8378 "Missing/invalid function: bool start_object(std::size_t)");
8379 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8380 "Missing/invalid function: bool key(string_t&)");
8381 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8382 "Missing/invalid function: bool end_object()");
8383 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8384 "Missing/invalid function: bool start_array(std::size_t)");
8385 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8386 "Missing/invalid function: bool end_array()");
8388 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8389 "Missing/invalid function: bool parse_error(std::size_t, const "
8390 "std::string&, const exception&)");
8406enum class cbor_tag_handler_t
8420static inline bool little_endianess(
int num = 1) noexcept
8422 return *
reinterpret_cast<char*
>(&num) == 1;
8433template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
8436 using number_integer_t =
typename BasicJsonType::number_integer_t;
8437 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8438 using number_float_t =
typename BasicJsonType::number_float_t;
8439 using string_t =
typename BasicJsonType::string_t;
8440 using binary_t =
typename BasicJsonType::binary_t;
8441 using json_sax_t = SAX;
8442 using char_type =
typename InputAdapterType::char_type;
8443 using char_int_type =
typename std::char_traits<char_type>::int_type;
8451 explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
8453 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
8457 binary_reader(
const binary_reader&) =
delete;
8458 binary_reader(binary_reader&&) =
default;
8459 binary_reader& operator=(
const binary_reader&) =
delete;
8460 binary_reader& operator=(binary_reader&&) =
default;
8461 ~binary_reader() =
default;
8471 JSON_HEDLEY_NON_NULL(3)
8472 bool sax_parse(const input_format_t format,
8474 const
bool strict = true,
8475 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8478 bool result =
false;
8482 case input_format_t::bson:
8483 result = parse_bson_internal();
8486 case input_format_t::cbor:
8487 result = parse_cbor_internal(
true, tag_handler);
8490 case input_format_t::msgpack:
8491 result = parse_msgpack_internal();
8494 case input_format_t::ubjson:
8495 result = parse_ubjson_internal();
8498 case input_format_t::json:
8504 if (result && strict)
8506 if (format == input_format_t::ubjson)
8515 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8517 return sax->parse_error(chars_read, get_token_string(),
8518 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value"), BasicJsonType()));
8534 bool parse_bson_internal()
8536 std::int32_t document_size{};
8537 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8539 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8544 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
8549 return sax->end_object();
8559 bool get_bson_cstr(string_t& result)
8561 auto out = std::back_inserter(result);
8565 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
8569 if (current == 0x00)
8573 *out++ =
static_cast<typename string_t::value_type
>(current);
8588 template<
typename NumberType>
8589 bool get_bson_string(
const NumberType len, string_t& result)
8591 if (JSON_HEDLEY_UNLIKELY(len < 1))
8593 auto last_token = get_token_string();
8594 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson,
"string length must be at least 1, is " + std::to_string(len),
"string"), BasicJsonType()));
8597 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
8609 template<
typename NumberType>
8610 bool get_bson_binary(
const NumberType len, binary_t& result)
8612 if (JSON_HEDLEY_UNLIKELY(len < 0))
8614 auto last_token = get_token_string();
8615 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson,
"byte array length cannot be negative, is " + std::to_string(len),
"binary"), BasicJsonType()));
8619 std::uint8_t subtype{};
8620 get_number<std::uint8_t>(input_format_t::bson, subtype);
8621 result.set_subtype(subtype);
8623 return get_binary(input_format_t::bson, len, result);
8636 bool parse_bson_element_internal(
const char_int_type element_type,
8637 const std::size_t element_type_parse_position)
8639 switch (element_type)
8644 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8651 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8656 return parse_bson_internal();
8661 return parse_bson_array();
8668 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8673 return sax->boolean(get() != 0);
8683 std::int32_t value{};
8684 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8689 std::int64_t value{};
8690 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8695 std::array<char, 3> cr{{}};
8696 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
8697 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()));
8714 bool parse_bson_element_list(
const bool is_array)
8718 while (
auto element_type = get())
8720 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
8725 const std::size_t element_type_parse_position = chars_read;
8726 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
8731 if (!is_array && !sax->key(key))
8736 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8752 bool parse_bson_array()
8754 std::int32_t document_size{};
8755 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8757 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8762 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
8767 return sax->end_array();
8782 bool parse_cbor_internal(
const bool get_char,
8783 const cbor_tag_handler_t tag_handler)
8785 switch (get_char ? get() : current)
8788 case std::char_traits<char_type>::eof():
8789 return unexpect_eof(input_format_t::cbor,
"value");
8816 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8820 std::uint8_t number{};
8821 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8826 std::uint16_t number{};
8827 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8832 std::uint32_t number{};
8833 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8838 std::uint64_t number{};
8839 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8867 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
8871 std::uint8_t number{};
8872 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8877 std::uint16_t number{};
8878 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8883 std::uint32_t number{};
8884 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8889 std::uint64_t number{};
8890 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
8891 -
static_cast<number_integer_t
>(number));
8926 return get_cbor_binary(b) && sax->binary(b);
8961 return get_cbor_string(s) && sax->string(s);
8989 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8994 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8999 std::uint16_t len{};
9000 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9005 std::uint32_t len{};
9006 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
9011 std::uint64_t len{};
9012 return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast<std::size_t>(len), tag_handler);
9016 return get_cbor_array(std::size_t(-1), tag_handler);
9043 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
9048 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9053 std::uint16_t len{};
9054 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9059 std::uint32_t len{};
9060 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
9065 std::uint64_t len{};
9066 return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast<std::size_t>(len), tag_handler);
9070 return get_cbor_object(std::size_t(-1), tag_handler);
9092 switch (tag_handler)
9094 case cbor_tag_handler_t::error:
9096 auto last_token = get_token_string();
9097 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
9100 case cbor_tag_handler_t::ignore:
9107 std::uint8_t subtype_to_ignore{};
9108 get_number(input_format_t::cbor, subtype_to_ignore);
9113 std::uint16_t subtype_to_ignore{};
9114 get_number(input_format_t::cbor, subtype_to_ignore);
9119 std::uint32_t subtype_to_ignore{};
9120 get_number(input_format_t::cbor, subtype_to_ignore);
9125 std::uint64_t subtype_to_ignore{};
9126 get_number(input_format_t::cbor, subtype_to_ignore);
9132 return parse_cbor_internal(
true, tag_handler);
9135 case cbor_tag_handler_t::store:
9143 std::uint8_t subtype{};
9144 get_number(input_format_t::cbor, subtype);
9145 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9150 std::uint16_t subtype{};
9151 get_number(input_format_t::cbor, subtype);
9152 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9157 std::uint32_t subtype{};
9158 get_number(input_format_t::cbor, subtype);
9159 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9164 std::uint64_t subtype{};
9165 get_number(input_format_t::cbor, subtype);
9166 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9170 return parse_cbor_internal(
true, tag_handler);
9173 return get_cbor_binary(b) && sax->binary(b);
9183 return sax->boolean(
false);
9186 return sax->boolean(
true);
9193 const auto byte1_raw = get();
9194 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9198 const auto byte2_raw = get();
9199 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9204 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9205 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9215 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9216 const double val = [&half]
9218 const int exp = (half >> 10u) & 0x1Fu;
9219 const unsigned int mant = half & 0x3FFu;
9220 JSON_ASSERT(0 <= exp&& exp <= 32);
9221 JSON_ASSERT(mant <= 1024);
9225 return std::ldexp(mant, -24);
9228 ? std::numeric_limits<double>::infinity()
9229 :
std::numeric_limits<double>::quiet_NaN();
9231 return std::ldexp(mant + 1024, exp - 25);
9234 return sax->number_float((half & 0x8000u) != 0
9235 ?
static_cast<number_float_t
>(-val)
9236 :
static_cast<number_float_t
>(val),
"");
9242 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9248 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9253 auto last_token = get_token_string();
9254 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
9270 bool get_cbor_string(string_t& result)
9272 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
9305 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9311 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9316 std::uint16_t len{};
9317 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9322 std::uint32_t len{};
9323 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9328 std::uint64_t len{};
9329 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9334 while (get() != 0xFF)
9337 if (!get_cbor_string(chunk))
9341 result.append(chunk);
9348 auto last_token = get_token_string();
9349 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor,
"expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token,
"string"), BasicJsonType()));
9365 bool get_cbor_binary(binary_t& result)
9367 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
9400 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9406 return get_number(input_format_t::cbor, len) &&
9407 get_binary(input_format_t::cbor, len, result);
9412 std::uint16_t len{};
9413 return get_number(input_format_t::cbor, len) &&
9414 get_binary(input_format_t::cbor, len, result);
9419 std::uint32_t len{};
9420 return get_number(input_format_t::cbor, len) &&
9421 get_binary(input_format_t::cbor, len, result);
9426 std::uint64_t len{};
9427 return get_number(input_format_t::cbor, len) &&
9428 get_binary(input_format_t::cbor, len, result);
9433 while (get() != 0xFF)
9436 if (!get_cbor_binary(chunk))
9440 result.insert(result.end(), chunk.begin(), chunk.end());
9447 auto last_token = get_token_string();
9448 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor,
"expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token,
"binary"), BasicJsonType()));
9459 bool get_cbor_array(
const std::size_t len,
9460 const cbor_tag_handler_t tag_handler)
9462 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9467 if (len != std::size_t(-1))
9469 for (std::size_t i = 0; i < len; ++i)
9471 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9479 while (get() != 0xFF)
9481 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
9488 return sax->end_array();
9497 bool get_cbor_object(
const std::size_t len,
9498 const cbor_tag_handler_t tag_handler)
9500 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9508 if (len != std::size_t(-1))
9510 for (std::size_t i = 0; i < len; ++i)
9513 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9518 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9527 while (get() != 0xFF)
9529 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9534 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9543 return sax->end_object();
9553 bool parse_msgpack_internal()
9558 case std::char_traits<char_type>::eof():
9559 return unexpect_eof(input_format_t::msgpack,
"value");
9690 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9709 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9728 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9768 return get_msgpack_string(s) && sax->string(s);
9775 return sax->boolean(
false);
9778 return sax->boolean(
true);
9793 return get_msgpack_binary(b) && sax->binary(b);
9799 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9805 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9810 std::uint8_t number{};
9811 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9816 std::uint16_t number{};
9817 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9822 std::uint32_t number{};
9823 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9828 std::uint64_t number{};
9829 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9834 std::int8_t number{};
9835 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9840 std::int16_t number{};
9841 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9846 std::int32_t number{};
9847 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9852 std::int64_t number{};
9853 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9858 std::uint16_t len{};
9859 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9864 std::uint32_t len{};
9865 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9870 std::uint16_t len{};
9871 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9876 std::uint32_t len{};
9877 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9913 return sax->number_integer(
static_cast<std::int8_t
>(current));
9917 auto last_token = get_token_string();
9918 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
9933 bool get_msgpack_string(string_t& result)
9935 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
9976 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
9982 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9987 std::uint16_t len{};
9988 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9993 std::uint32_t len{};
9994 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9999 auto last_token = get_token_string();
10000 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack,
"expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token,
"string"), BasicJsonType()));
10015 bool get_msgpack_binary(binary_t& result)
10018 auto assign_and_return_true = [&result](std::int8_t subtype)
10020 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
10028 std::uint8_t len{};
10029 return get_number(input_format_t::msgpack, len) &&
10030 get_binary(input_format_t::msgpack, len, result);
10035 std::uint16_t len{};
10036 return get_number(input_format_t::msgpack, len) &&
10037 get_binary(input_format_t::msgpack, len, result);
10042 std::uint32_t len{};
10043 return get_number(input_format_t::msgpack, len) &&
10044 get_binary(input_format_t::msgpack, len, result);
10049 std::uint8_t len{};
10050 std::int8_t subtype{};
10051 return get_number(input_format_t::msgpack, len) &&
10052 get_number(input_format_t::msgpack, subtype) &&
10053 get_binary(input_format_t::msgpack, len, result) &&
10054 assign_and_return_true(subtype);
10059 std::uint16_t len{};
10060 std::int8_t subtype{};
10061 return get_number(input_format_t::msgpack, len) &&
10062 get_number(input_format_t::msgpack, subtype) &&
10063 get_binary(input_format_t::msgpack, len, result) &&
10064 assign_and_return_true(subtype);
10069 std::uint32_t len{};
10070 std::int8_t subtype{};
10071 return get_number(input_format_t::msgpack, len) &&
10072 get_number(input_format_t::msgpack, subtype) &&
10073 get_binary(input_format_t::msgpack, len, result) &&
10074 assign_and_return_true(subtype);
10079 std::int8_t subtype{};
10080 return get_number(input_format_t::msgpack, subtype) &&
10081 get_binary(input_format_t::msgpack, 1, result) &&
10082 assign_and_return_true(subtype);
10087 std::int8_t subtype{};
10088 return get_number(input_format_t::msgpack, subtype) &&
10089 get_binary(input_format_t::msgpack, 2, result) &&
10090 assign_and_return_true(subtype);
10095 std::int8_t subtype{};
10096 return get_number(input_format_t::msgpack, subtype) &&
10097 get_binary(input_format_t::msgpack, 4, result) &&
10098 assign_and_return_true(subtype);
10103 std::int8_t subtype{};
10104 return get_number(input_format_t::msgpack, subtype) &&
10105 get_binary(input_format_t::msgpack, 8, result) &&
10106 assign_and_return_true(subtype);
10111 std::int8_t subtype{};
10112 return get_number(input_format_t::msgpack, subtype) &&
10113 get_binary(input_format_t::msgpack, 16, result) &&
10114 assign_and_return_true(subtype);
10126 bool get_msgpack_array(
const std::size_t len)
10128 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10133 for (std::size_t i = 0; i < len; ++i)
10135 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10141 return sax->end_array();
10148 bool get_msgpack_object(
const std::size_t len)
10150 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10156 for (std::size_t i = 0; i < len; ++i)
10159 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
10164 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10171 return sax->end_object();
10185 bool parse_ubjson_internal(
const bool get_char =
true)
10187 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10204 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
10211 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
10220 std::uint8_t len{};
10221 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10227 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10232 std::int16_t len{};
10233 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10238 std::int32_t len{};
10239 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10244 std::int64_t len{};
10245 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10249 auto last_token = get_token_string();
10250 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()));
10258 bool get_ubjson_size_value(std::size_t& result)
10260 switch (get_ignore_noop())
10264 std::uint8_t number{};
10265 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10269 result =
static_cast<std::size_t
>(number);
10275 std::int8_t number{};
10276 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10280 result =
static_cast<std::size_t
>(number);
10286 std::int16_t number{};
10287 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10291 result =
static_cast<std::size_t
>(number);
10297 std::int32_t number{};
10298 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10302 result =
static_cast<std::size_t
>(number);
10308 std::int64_t number{};
10309 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10313 result =
static_cast<std::size_t
>(number);
10319 auto last_token = get_token_string();
10320 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()));
10335 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
10337 result.first = string_t::npos;
10342 if (current ==
'$')
10344 result.second = get();
10345 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"type")))
10351 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
10353 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
10357 auto last_token = get_token_string();
10358 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson,
"expected '#' after type information; last byte: 0x" + last_token,
"size"), BasicJsonType()));
10361 return get_ubjson_size_value(result.first);
10364 if (current ==
'#')
10366 return get_ubjson_size_value(result.first);
10376 bool get_ubjson_value(
const char_int_type prefix)
10380 case std::char_traits<char_type>::eof():
10381 return unexpect_eof(input_format_t::ubjson,
"value");
10384 return sax->boolean(
true);
10386 return sax->boolean(
false);
10389 return sax->null();
10393 std::uint8_t number{};
10394 return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
10399 std::int8_t number{};
10400 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10405 std::int16_t number{};
10406 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10411 std::int32_t number{};
10412 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10417 std::int64_t number{};
10418 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10424 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10430 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10435 return get_ubjson_high_precision_number();
10441 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"char")))
10445 if (JSON_HEDLEY_UNLIKELY(current > 127))
10447 auto last_token = get_token_string();
10448 return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson,
"byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token,
"char"), BasicJsonType()));
10450 string_t s(1,
static_cast<typename string_t::value_type
>(current));
10451 return sax->string(s);
10457 return get_ubjson_string(s) && sax->string(s);
10461 return get_ubjson_array();
10464 return get_ubjson_object();
10468 auto last_token = get_token_string();
10469 return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson,
"invalid byte: 0x" + last_token,
"value"), BasicJsonType()));
10477 bool get_ubjson_array()
10479 std::pair<std::size_t, char_int_type> size_and_type;
10480 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10485 if (size_and_type.first != string_t::npos)
10487 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10492 if (size_and_type.second != 0)
10494 if (size_and_type.second !=
'N')
10496 for (std::size_t i = 0; i < size_and_type.first; ++i)
10498 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10507 for (std::size_t i = 0; i < size_and_type.first; ++i)
10509 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10518 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10523 while (current !=
']')
10525 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
10533 return sax->end_array();
10539 bool get_ubjson_object()
10541 std::pair<std::size_t, char_int_type> size_and_type;
10542 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10548 if (size_and_type.first != string_t::npos)
10550 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10555 if (size_and_type.second != 0)
10557 for (std::size_t i = 0; i < size_and_type.first; ++i)
10559 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10563 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10572 for (std::size_t i = 0; i < size_and_type.first; ++i)
10574 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10578 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10588 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10593 while (current !=
'}')
10595 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
10599 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10608 return sax->end_object();
10614 bool get_ubjson_high_precision_number()
10617 std::size_t size{};
10618 auto res = get_ubjson_size_value(size);
10619 if (JSON_HEDLEY_UNLIKELY(!res))
10625 std::vector<char> number_vector;
10626 for (std::size_t i = 0; i < size; ++i)
10629 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"number")))
10633 number_vector.push_back(
static_cast<char>(current));
10637 using ia_type =
decltype(detail::input_adapter(number_vector));
10638 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
10639 const auto result_number = number_lexer.scan();
10640 const auto number_string = number_lexer.get_token_string();
10641 const auto result_remainder = number_lexer.scan();
10643 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
10645 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10647 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number"), BasicJsonType()));
10650 switch (result_number)
10652 case token_type::value_integer:
10653 return sax->number_integer(number_lexer.get_number_integer());
10654 case token_type::value_unsigned:
10655 return sax->number_unsigned(number_lexer.get_number_unsigned());
10656 case token_type::value_float:
10657 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10658 case token_type::uninitialized:
10659 case token_type::literal_true:
10660 case token_type::literal_false:
10661 case token_type::literal_null:
10662 case token_type::value_string:
10663 case token_type::begin_array:
10664 case token_type::begin_object:
10665 case token_type::end_array:
10666 case token_type::end_object:
10667 case token_type::name_separator:
10668 case token_type::value_separator:
10669 case token_type::parse_error:
10670 case token_type::end_of_input:
10671 case token_type::literal_or_value:
10673 return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson,
"invalid number text: " + number_lexer.get_token_string(),
"high-precision number"), BasicJsonType()));
10690 char_int_type get()
10693 return current = ia.get_character();
10699 char_int_type get_ignore_noop()
10705 while (current ==
'N');
10723 template<
typename NumberType,
bool InputIsLittleEndian = false>
10724 bool get_number(
const input_format_t format, NumberType& result)
10727 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
10728 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
10731 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
10737 if (is_little_endian != InputIsLittleEndian)
10739 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
10743 vec[i] =
static_cast<std::uint8_t
>(current);
10748 std::memcpy(&result, vec.data(),
sizeof(NumberType));
10766 template<
typename NumberType>
10767 bool get_string(
const input_format_t format,
10768 const NumberType len,
10771 bool success =
true;
10772 for (NumberType i = 0; i < len; i++)
10775 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
10780 result.push_back(
static_cast<typename string_t::value_type
>(current));
10799 template<
typename NumberType>
10800 bool get_binary(
const input_format_t format,
10801 const NumberType len,
10804 bool success =
true;
10805 for (NumberType i = 0; i < len; i++)
10808 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
10813 result.push_back(
static_cast<std::uint8_t
>(current));
10823 JSON_HEDLEY_NON_NULL(3)
10824 bool unexpect_eof(const input_format_t format, const
char* context)
const
10826 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10828 return sax->parse_error(chars_read,
"<end of file>",
10829 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context), BasicJsonType()));
10837 std::string get_token_string()
const
10839 std::array<char, 3> cr{{}};
10840 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
10841 return std::string{cr.data()};
10850 std::string exception_message(
const input_format_t format,
10851 const std::string& detail,
10852 const std::string& context)
const
10854 std::string error_msg =
"syntax error while parsing ";
10858 case input_format_t::cbor:
10859 error_msg +=
"CBOR";
10862 case input_format_t::msgpack:
10863 error_msg +=
"MessagePack";
10866 case input_format_t::ubjson:
10867 error_msg +=
"UBJSON";
10870 case input_format_t::bson:
10871 error_msg +=
"BSON";
10874 case input_format_t::json:
10876 JSON_ASSERT(
false);
10879 return error_msg +
" " + context +
": " + detail;
10884 InputAdapterType ia;
10887 char_int_type current = std::char_traits<char_type>::eof();
10890 std::size_t chars_read = 0;
10893 const bool is_little_endian = little_endianess();
10896 json_sax_t* sax =
nullptr;
10910#include <functional>
10938enum class parse_event_t : std::uint8_t
10954template<
typename BasicJsonType>
10955using parser_callback_t =
10956 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
10963template<
typename BasicJsonType,
typename InputAdapterType>
10966 using number_integer_t =
typename BasicJsonType::number_integer_t;
10967 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
10968 using number_float_t =
typename BasicJsonType::number_float_t;
10969 using string_t =
typename BasicJsonType::string_t;
10970 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10971 using token_type =
typename lexer_t::token_type;
10975 explicit parser(InputAdapterType&& adapter,
10976 const parser_callback_t<BasicJsonType> cb =
nullptr,
10977 const bool allow_exceptions_ =
true,
10978 const bool skip_comments =
false)
10980 , m_lexer(
std::move(adapter), skip_comments)
10981 , allow_exceptions(allow_exceptions_)
10997 void parse(
const bool strict, BasicJsonType& result)
11001 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
11002 sax_parse_internal(&sdp);
11005 if (strict && (get_token() != token_type::end_of_input))
11007 sdp.parse_error(m_lexer.get_position(),
11008 m_lexer.get_token_string(),
11009 parse_error::create(101, m_lexer.get_position(),
11010 exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
11014 if (sdp.is_errored())
11016 result = value_t::discarded;
11022 if (result.is_discarded())
11029 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
11030 sax_parse_internal(&sdp);
11033 if (strict && (get_token() != token_type::end_of_input))
11035 sdp.parse_error(m_lexer.get_position(),
11036 m_lexer.get_token_string(),
11037 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
11041 if (sdp.is_errored())
11043 result = value_t::discarded;
11048 result.assert_invariant();
11057 bool accept(
const bool strict =
true)
11059 json_sax_acceptor<BasicJsonType> sax_acceptor;
11060 return sax_parse(&sax_acceptor, strict);
11063 template<
typename SAX>
11064 JSON_HEDLEY_NON_NULL(2)
11065 bool sax_parse(SAX* sax, const
bool strict = true)
11067 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
11068 const bool result = sax_parse_internal(sax);
11071 if (result && strict && (get_token() != token_type::end_of_input))
11073 return sax->parse_error(m_lexer.get_position(),
11074 m_lexer.get_token_string(),
11075 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
11082 template<
typename SAX>
11083 JSON_HEDLEY_NON_NULL(2)
11084 bool sax_parse_internal(SAX* sax)
11088 std::vector<bool> states;
11090 bool skip_to_state_evaluation =
false;
11094 if (!skip_to_state_evaluation)
11097 switch (last_token)
11099 case token_type::begin_object:
11101 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
11107 if (get_token() == token_type::end_object)
11109 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11117 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
11119 return sax->parse_error(m_lexer.get_position(),
11120 m_lexer.get_token_string(),
11121 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
11123 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11129 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11131 return sax->parse_error(m_lexer.get_position(),
11132 m_lexer.get_token_string(),
11133 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
11137 states.push_back(
false);
11144 case token_type::begin_array:
11146 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
11152 if (get_token() == token_type::end_array)
11154 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11162 states.push_back(
true);
11168 case token_type::value_float:
11170 const auto res = m_lexer.get_number_float();
11172 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
11174 return sax->parse_error(m_lexer.get_position(),
11175 m_lexer.get_token_string(),
11176 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'", BasicJsonType()));
11179 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
11187 case token_type::literal_false:
11189 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
11196 case token_type::literal_null:
11198 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
11205 case token_type::literal_true:
11207 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
11214 case token_type::value_integer:
11216 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
11223 case token_type::value_string:
11225 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
11232 case token_type::value_unsigned:
11234 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
11241 case token_type::parse_error:
11244 return sax->parse_error(m_lexer.get_position(),
11245 m_lexer.get_token_string(),
11246 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"), BasicJsonType()));
11249 case token_type::uninitialized:
11250 case token_type::end_array:
11251 case token_type::end_object:
11252 case token_type::name_separator:
11253 case token_type::value_separator:
11254 case token_type::end_of_input:
11255 case token_type::literal_or_value:
11258 return sax->parse_error(m_lexer.get_position(),
11259 m_lexer.get_token_string(),
11260 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"), BasicJsonType()));
11266 skip_to_state_evaluation =
false;
11270 if (states.empty())
11279 if (get_token() == token_type::value_separator)
11287 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
11289 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11298 JSON_ASSERT(!states.empty());
11300 skip_to_state_evaluation =
true;
11304 return sax->parse_error(m_lexer.get_position(),
11305 m_lexer.get_token_string(),
11306 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"), BasicJsonType()));
11312 if (get_token() == token_type::value_separator)
11315 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
11317 return sax->parse_error(m_lexer.get_position(),
11318 m_lexer.get_token_string(),
11319 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
11322 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11328 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11330 return sax->parse_error(m_lexer.get_position(),
11331 m_lexer.get_token_string(),
11332 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
11341 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
11343 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11352 JSON_ASSERT(!states.empty());
11354 skip_to_state_evaluation =
true;
11358 return sax->parse_error(m_lexer.get_position(),
11359 m_lexer.get_token_string(),
11360 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"), BasicJsonType()));
11365 token_type get_token()
11367 return last_token = m_lexer.scan();
11370 std::string exception_message(
const token_type expected,
const std::string& context)
11372 std::string error_msg =
"syntax error ";
11374 if (!context.empty())
11376 error_msg +=
"while parsing " + context +
" ";
11381 if (last_token == token_type::parse_error)
11383 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
11384 m_lexer.get_token_string() +
"'";
11388 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
11391 if (expected != token_type::uninitialized)
11393 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
11401 const parser_callback_t<BasicJsonType> callback =
nullptr;
11403 token_type last_token = token_type::uninitialized;
11407 const bool allow_exceptions =
true;
11438class primitive_iterator_t
11441 using difference_type = std::ptrdiff_t;
11442 static constexpr difference_type begin_value = 0;
11443 static constexpr difference_type end_value = begin_value + 1;
11445 JSON_PRIVATE_UNLESS_TESTED:
11447 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11450 constexpr difference_type get_value() const noexcept
11456 void set_begin() noexcept
11458 m_it = begin_value;
11462 void set_end() noexcept
11468 constexpr bool is_begin() const noexcept
11470 return m_it == begin_value;
11474 constexpr bool is_end() const noexcept
11476 return m_it == end_value;
11479 friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
11481 return lhs.m_it == rhs.m_it;
11484 friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
11486 return lhs.m_it < rhs.m_it;
11489 primitive_iterator_t operator+(difference_type n)
noexcept
11491 auto result = *
this;
11496 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs)
noexcept
11498 return lhs.m_it - rhs.m_it;
11501 primitive_iterator_t& operator++() noexcept
11507 primitive_iterator_t
const operator++(
int)
noexcept
11509 auto result = *
this;
11514 primitive_iterator_t& operator--() noexcept
11520 primitive_iterator_t
const operator--(
int)
noexcept
11522 auto result = *
this;
11527 primitive_iterator_t& operator+=(difference_type n)
noexcept
11533 primitive_iterator_t& operator-=(difference_type n)
noexcept
11553template<
typename BasicJsonType>
struct internal_iterator
11556 typename BasicJsonType::object_t::iterator object_iterator {};
11558 typename BasicJsonType::array_t::iterator array_iterator {};
11560 primitive_iterator_t primitive_iterator {};
11569#include <type_traits>
11591template<
typename IteratorType>
class iteration_proxy;
11592template<
typename IteratorType>
class iteration_proxy_value;
11610template<
typename BasicJsonType>
11614 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
11616 friend other_iter_impl;
11617 friend BasicJsonType;
11618 friend iteration_proxy<iter_impl>;
11619 friend iteration_proxy_value<iter_impl>;
11621 using object_t =
typename BasicJsonType::object_t;
11622 using array_t =
typename BasicJsonType::array_t;
11624 static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value,
11625 "iter_impl only accepts (const) basic_json");
11634 using iterator_category = std::bidirectional_iterator_tag;
11637 using value_type =
typename BasicJsonType::value_type;
11639 using difference_type =
typename BasicJsonType::difference_type;
11641 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
11642 typename BasicJsonType::const_pointer,
11643 typename BasicJsonType::pointer>::type;
11646 typename std::conditional<std::is_const<BasicJsonType>::value,
11647 typename BasicJsonType::const_reference,
11648 typename BasicJsonType::reference>::type;
11650 iter_impl() =
default;
11651 ~iter_impl() =
default;
11652 iter_impl(iter_impl&&) noexcept = default;
11653 iter_impl& operator=(iter_impl&&) noexcept = default;
11661 explicit iter_impl(pointer
object) noexcept : m_object(
object)
11663 JSON_ASSERT(m_object !=
nullptr);
11665 switch (m_object->m_type)
11667 case value_t::object:
11669 m_it.object_iterator =
typename object_t::iterator();
11673 case value_t::array:
11675 m_it.array_iterator =
typename array_t::iterator();
11679 case value_t::null:
11680 case value_t::string:
11681 case value_t::boolean:
11682 case value_t::number_integer:
11683 case value_t::number_unsigned:
11684 case value_t::number_float:
11685 case value_t::binary:
11686 case value_t::discarded:
11689 m_it.primitive_iterator = primitive_iterator_t();
11711 iter_impl(
const iter_impl<const BasicJsonType>& other) noexcept
11712 : m_object(other.m_object), m_it(other.m_it)
11721 iter_impl& operator=(
const iter_impl<const BasicJsonType>& other)
noexcept
11723 if (&other !=
this)
11725 m_object = other.m_object;
11736 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11737 : m_object(other.m_object), m_it(other.m_it)
11746 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other)
noexcept
11748 m_object = other.m_object;
11753 JSON_PRIVATE_UNLESS_TESTED:
11758 void set_begin() noexcept
11760 JSON_ASSERT(m_object !=
nullptr);
11762 switch (m_object->m_type)
11764 case value_t::object:
11766 m_it.object_iterator = m_object->m_value.object->begin();
11770 case value_t::array:
11772 m_it.array_iterator = m_object->m_value.array->begin();
11776 case value_t::null:
11779 m_it.primitive_iterator.set_end();
11783 case value_t::string:
11784 case value_t::boolean:
11785 case value_t::number_integer:
11786 case value_t::number_unsigned:
11787 case value_t::number_float:
11788 case value_t::binary:
11789 case value_t::discarded:
11792 m_it.primitive_iterator.set_begin();
11802 void set_end() noexcept
11804 JSON_ASSERT(m_object !=
nullptr);
11806 switch (m_object->m_type)
11808 case value_t::object:
11810 m_it.object_iterator = m_object->m_value.object->end();
11814 case value_t::array:
11816 m_it.array_iterator = m_object->m_value.array->end();
11820 case value_t::null:
11821 case value_t::string:
11822 case value_t::boolean:
11823 case value_t::number_integer:
11824 case value_t::number_unsigned:
11825 case value_t::number_float:
11826 case value_t::binary:
11827 case value_t::discarded:
11830 m_it.primitive_iterator.set_end();
11841 reference operator*()
const
11843 JSON_ASSERT(m_object !=
nullptr);
11845 switch (m_object->m_type)
11847 case value_t::object:
11849 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11850 return m_it.object_iterator->second;
11853 case value_t::array:
11855 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11856 return *m_it.array_iterator;
11859 case value_t::null:
11860 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11862 case value_t::string:
11863 case value_t::boolean:
11864 case value_t::number_integer:
11865 case value_t::number_unsigned:
11866 case value_t::number_float:
11867 case value_t::binary:
11868 case value_t::discarded:
11871 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11876 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11885 pointer operator->()
const
11887 JSON_ASSERT(m_object !=
nullptr);
11889 switch (m_object->m_type)
11891 case value_t::object:
11893 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11894 return &(m_it.object_iterator->second);
11897 case value_t::array:
11899 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11900 return &*m_it.array_iterator;
11903 case value_t::null:
11904 case value_t::string:
11905 case value_t::boolean:
11906 case value_t::number_integer:
11907 case value_t::number_unsigned:
11908 case value_t::number_float:
11909 case value_t::binary:
11910 case value_t::discarded:
11913 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11918 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11927 iter_impl
const operator++(
int)
11929 auto result = *
this;
11938 iter_impl& operator++()
11940 JSON_ASSERT(m_object !=
nullptr);
11942 switch (m_object->m_type)
11944 case value_t::object:
11946 std::advance(m_it.object_iterator, 1);
11950 case value_t::array:
11952 std::advance(m_it.array_iterator, 1);
11956 case value_t::null:
11957 case value_t::string:
11958 case value_t::boolean:
11959 case value_t::number_integer:
11960 case value_t::number_unsigned:
11961 case value_t::number_float:
11962 case value_t::binary:
11963 case value_t::discarded:
11966 ++m_it.primitive_iterator;
11978 iter_impl
const operator--(
int)
11980 auto result = *
this;
11989 iter_impl& operator--()
11991 JSON_ASSERT(m_object !=
nullptr);
11993 switch (m_object->m_type)
11995 case value_t::object:
11997 std::advance(m_it.object_iterator, -1);
12001 case value_t::array:
12003 std::advance(m_it.array_iterator, -1);
12007 case value_t::null:
12008 case value_t::string:
12009 case value_t::boolean:
12010 case value_t::number_integer:
12011 case value_t::number_unsigned:
12012 case value_t::number_float:
12013 case value_t::binary:
12014 case value_t::discarded:
12017 --m_it.primitive_iterator;
12029 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 >
12030 bool operator==(
const IterImpl& other)
const
12033 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
12035 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
12038 JSON_ASSERT(m_object !=
nullptr);
12040 switch (m_object->m_type)
12042 case value_t::object:
12043 return (m_it.object_iterator == other.m_it.object_iterator);
12045 case value_t::array:
12046 return (m_it.array_iterator == other.m_it.array_iterator);
12048 case value_t::null:
12049 case value_t::string:
12050 case value_t::boolean:
12051 case value_t::number_integer:
12052 case value_t::number_unsigned:
12053 case value_t::number_float:
12054 case value_t::binary:
12055 case value_t::discarded:
12057 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
12065 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 >
12066 bool operator!=(
const IterImpl& other)
const
12068 return !operator==(other);
12075 bool operator<(
const iter_impl& other)
const
12078 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
12080 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
12083 JSON_ASSERT(m_object !=
nullptr);
12085 switch (m_object->m_type)
12087 case value_t::object:
12088 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
12090 case value_t::array:
12091 return (m_it.array_iterator < other.m_it.array_iterator);
12093 case value_t::null:
12094 case value_t::string:
12095 case value_t::boolean:
12096 case value_t::number_integer:
12097 case value_t::number_unsigned:
12098 case value_t::number_float:
12099 case value_t::binary:
12100 case value_t::discarded:
12102 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
12110 bool operator<=(
const iter_impl& other)
const
12112 return !other.operator < (*this);
12119 bool operator>(
const iter_impl& other)
const
12121 return !operator<=(other);
12128 bool operator>=(
const iter_impl& other)
const
12130 return !operator<(other);
12137 iter_impl& operator+=(difference_type i)
12139 JSON_ASSERT(m_object !=
nullptr);
12141 switch (m_object->m_type)
12143 case value_t::object:
12144 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12146 case value_t::array:
12148 std::advance(m_it.array_iterator, i);
12152 case value_t::null:
12153 case value_t::string:
12154 case value_t::boolean:
12155 case value_t::number_integer:
12156 case value_t::number_unsigned:
12157 case value_t::number_float:
12158 case value_t::binary:
12159 case value_t::discarded:
12162 m_it.primitive_iterator += i;
12174 iter_impl& operator-=(difference_type i)
12176 return operator+=(-i);
12183 iter_impl operator+(difference_type i)
const
12185 auto result = *
this;
12194 friend iter_impl operator+(difference_type i,
const iter_impl& it)
12205 iter_impl operator-(difference_type i)
const
12207 auto result = *
this;
12216 difference_type operator-(
const iter_impl& other)
const
12218 JSON_ASSERT(m_object !=
nullptr);
12220 switch (m_object->m_type)
12222 case value_t::object:
12223 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12225 case value_t::array:
12226 return m_it.array_iterator - other.m_it.array_iterator;
12228 case value_t::null:
12229 case value_t::string:
12230 case value_t::boolean:
12231 case value_t::number_integer:
12232 case value_t::number_unsigned:
12233 case value_t::number_float:
12234 case value_t::binary:
12235 case value_t::discarded:
12237 return m_it.primitive_iterator - other.m_it.primitive_iterator;
12245 reference operator[](difference_type n)
const
12247 JSON_ASSERT(m_object !=
nullptr);
12249 switch (m_object->m_type)
12251 case value_t::object:
12252 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
12254 case value_t::array:
12255 return *std::next(m_it.array_iterator, n);
12257 case value_t::null:
12258 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12260 case value_t::string:
12261 case value_t::boolean:
12262 case value_t::number_integer:
12263 case value_t::number_unsigned:
12264 case value_t::number_float:
12265 case value_t::binary:
12266 case value_t::discarded:
12269 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
12274 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12283 const typename object_t::key_type& key()
const
12285 JSON_ASSERT(m_object !=
nullptr);
12287 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
12289 return m_it.object_iterator->first;
12292 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
12299 reference value()
const
12301 return operator*();
12304 JSON_PRIVATE_UNLESS_TESTED:
12306 pointer m_object =
nullptr;
12308 internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
12348template<
typename Base>
12349class json_reverse_iterator :
public std::reverse_iterator<Base>
12352 using difference_type = std::ptrdiff_t;
12354 using base_iterator = std::reverse_iterator<Base>;
12356 using reference =
typename Base::reference;
12359 explicit json_reverse_iterator(
const typename base_iterator::iterator_type& it) noexcept
12360 : base_iterator(it) {}
12363 explicit json_reverse_iterator(
const base_iterator& it) noexcept : base_iterator(it) {}
12366 json_reverse_iterator
const operator++(
int)
12368 return static_cast<json_reverse_iterator
>(base_iterator::operator++(1));
12372 json_reverse_iterator& operator++()
12374 return static_cast<json_reverse_iterator&
>(base_iterator::operator++());
12378 json_reverse_iterator
const operator--(
int)
12380 return static_cast<json_reverse_iterator
>(base_iterator::operator--(1));
12384 json_reverse_iterator& operator--()
12386 return static_cast<json_reverse_iterator&
>(base_iterator::operator--());
12390 json_reverse_iterator& operator+=(difference_type i)
12392 return static_cast<json_reverse_iterator&
>(base_iterator::operator+=(i));
12396 json_reverse_iterator operator+(difference_type i)
const
12398 return static_cast<json_reverse_iterator
>(base_iterator::operator+(i));
12402 json_reverse_iterator operator-(difference_type i)
const
12404 return static_cast<json_reverse_iterator
>(base_iterator::operator-(i));
12408 difference_type operator-(
const json_reverse_iterator& other)
const
12410 return base_iterator(*
this) - base_iterator(other);
12414 reference operator[](difference_type n)
const
12416 return *(this->operator+(n));
12420 auto key() const -> decltype(
std::declval<Base>().key())
12422 auto it = --this->base();
12427 reference value()
const
12429 auto it = --this->base();
12430 return it.operator * ();
12441#include <algorithm>
12460template<
typename BasicJsonType>
12464 NLOHMANN_BASIC_JSON_TPL_DECLARATION
12490 : reference_tokens(split(s))
12509 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12511 [](
const std::string & a,
const std::string & b)
12513 return a +
"/" + detail::escape(b);
12518 operator std::string()
const
12541 reference_tokens.insert(reference_tokens.end(),
12542 ptr.reference_tokens.begin(),
12543 ptr.reference_tokens.end());
12587 return *
this /= std::to_string(array_idx);
12691 if (JSON_HEDLEY_UNLIKELY(
empty()))
12693 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12696 reference_tokens.pop_back();
12715 if (JSON_HEDLEY_UNLIKELY(
empty()))
12717 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12720 return reference_tokens.back();
12737 reference_tokens.push_back(token);
12743 reference_tokens.push_back(std::move(token));
12762 return reference_tokens.empty();
12776 static typename BasicJsonType::size_type array_index(
const std::string& s)
12778 using size_type =
typename BasicJsonType::size_type;
12781 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
12783 JSON_THROW(detail::parse_error::create(106, 0,
"array index '" + s +
"' must not begin with '0'", BasicJsonType()));
12787 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
12789 JSON_THROW(detail::parse_error::create(109, 0,
"array index '" + s +
"' is not a number", BasicJsonType()));
12792 std::size_t processed_chars = 0;
12793 unsigned long long res = 0;
12796 res = std::stoull(s, &processed_chars);
12798 JSON_CATCH(std::out_of_range&)
12800 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12804 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12806 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12811 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
12813 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type", BasicJsonType()));
12816 return static_cast<size_type
>(res);
12819 JSON_PRIVATE_UNLESS_TESTED:
12822 if (JSON_HEDLEY_UNLIKELY(
empty()))
12824 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12828 result.reference_tokens = {reference_tokens[0]};
12841 BasicJsonType& get_and_create(BasicJsonType& j)
const
12847 for (
const auto& reference_token : reference_tokens)
12849 switch (result->type())
12851 case detail::value_t::null:
12853 if (reference_token ==
"0")
12856 result = &result->operator[](0);
12861 result = &result->operator[](reference_token);
12866 case detail::value_t::object:
12869 result = &result->operator[](reference_token);
12873 case detail::value_t::array:
12876 result = &result->operator[](array_index(reference_token));
12886 case detail::value_t::string:
12887 case detail::value_t::boolean:
12888 case detail::value_t::number_integer:
12889 case detail::value_t::number_unsigned:
12890 case detail::value_t::number_float:
12891 case detail::value_t::binary:
12892 case detail::value_t::discarded:
12894 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", j));
12920 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
12922 for (
const auto& reference_token : reference_tokens)
12925 if (ptr->is_null())
12929 std::all_of(reference_token.begin(), reference_token.end(),
12930 [](
const unsigned char x)
12932 return std::isdigit(x);
12936 *ptr = (nums || reference_token ==
"-")
12937 ? detail::value_t::array
12938 : detail::value_t::object;
12941 switch (ptr->type())
12943 case detail::value_t::object:
12946 ptr = &ptr->operator[](reference_token);
12950 case detail::value_t::array:
12952 if (reference_token ==
"-")
12955 ptr = &ptr->operator[](ptr->m_value.array->size());
12960 ptr = &ptr->operator[](array_index(reference_token));
12965 case detail::value_t::null:
12966 case detail::value_t::string:
12967 case detail::value_t::boolean:
12968 case detail::value_t::number_integer:
12969 case detail::value_t::number_unsigned:
12970 case detail::value_t::number_float:
12971 case detail::value_t::binary:
12972 case detail::value_t::discarded:
12974 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12987 BasicJsonType& get_checked(BasicJsonType* ptr)
const
12989 for (
const auto& reference_token : reference_tokens)
12991 switch (ptr->type())
12993 case detail::value_t::object:
12996 ptr = &ptr->at(reference_token);
13000 case detail::value_t::array:
13002 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13005 JSON_THROW(detail::out_of_range::create(402,
13006 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
13007 ") is out of range", *ptr));
13011 ptr = &ptr->at(array_index(reference_token));
13015 case detail::value_t::null:
13016 case detail::value_t::string:
13017 case detail::value_t::boolean:
13018 case detail::value_t::number_integer:
13019 case detail::value_t::number_unsigned:
13020 case detail::value_t::number_float:
13021 case detail::value_t::binary:
13022 case detail::value_t::discarded:
13024 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13044 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
13046 for (
const auto& reference_token : reference_tokens)
13048 switch (ptr->type())
13050 case detail::value_t::object:
13053 ptr = &ptr->operator[](reference_token);
13057 case detail::value_t::array:
13059 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13062 JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", *ptr));
13066 ptr = &ptr->operator[](array_index(reference_token));
13070 case detail::value_t::null:
13071 case detail::value_t::string:
13072 case detail::value_t::boolean:
13073 case detail::value_t::number_integer:
13074 case detail::value_t::number_unsigned:
13075 case detail::value_t::number_float:
13076 case detail::value_t::binary:
13077 case detail::value_t::discarded:
13079 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13092 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
13094 for (
const auto& reference_token : reference_tokens)
13096 switch (ptr->type())
13098 case detail::value_t::object:
13101 ptr = &ptr->at(reference_token);
13105 case detail::value_t::array:
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));
13116 ptr = &ptr->at(array_index(reference_token));
13120 case detail::value_t::null:
13121 case detail::value_t::string:
13122 case detail::value_t::boolean:
13123 case detail::value_t::number_integer:
13124 case detail::value_t::number_unsigned:
13125 case detail::value_t::number_float:
13126 case detail::value_t::binary:
13127 case detail::value_t::discarded:
13129 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13140 bool contains(
const BasicJsonType* ptr)
const
13142 for (
const auto& reference_token : reference_tokens)
13144 switch (ptr->type())
13146 case detail::value_t::object:
13148 if (!ptr->contains(reference_token))
13154 ptr = &ptr->operator[](reference_token);
13158 case detail::value_t::array:
13160 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13165 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
13170 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
13172 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
13177 for (std::size_t i = 1; i < reference_token.size(); i++)
13179 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
13187 const auto idx = array_index(reference_token);
13188 if (idx >= ptr->size())
13194 ptr = &ptr->operator[](idx);
13198 case detail::value_t::null:
13199 case detail::value_t::string:
13200 case detail::value_t::boolean:
13201 case detail::value_t::number_integer:
13202 case detail::value_t::number_unsigned:
13203 case detail::value_t::number_float:
13204 case detail::value_t::binary:
13205 case detail::value_t::discarded:
13228 static std::vector<std::string> split(
const std::string& reference_string)
13230 std::vector<std::string> result;
13233 if (reference_string.empty())
13239 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
13241 JSON_THROW(detail::parse_error::create(107, 1,
"JSON pointer must be empty or begin with '/' - was: '" + reference_string +
"'", BasicJsonType()));
13249 std::size_t slash = reference_string.find_first_of(
'/', 1),
13256 start = (slash == std::string::npos) ? 0 : slash + 1,
13258 slash = reference_string.find_first_of(
'/', start))
13262 auto reference_token = reference_string.substr(start, slash - start);
13265 for (std::size_t pos = reference_token.find_first_of(
'~');
13266 pos != std::string::npos;
13267 pos = reference_token.find_first_of(
'~', pos + 1))
13269 JSON_ASSERT(reference_token[pos] ==
'~');
13272 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
13273 (reference_token[pos + 1] !=
'0' &&
13274 reference_token[pos + 1] !=
'1')))
13276 JSON_THROW(detail::parse_error::create(108, 0,
"escape character '~' must be followed with '0' or '1'", BasicJsonType()));
13281 detail::unescape(reference_token);
13282 result.push_back(reference_token);
13296 static void flatten(
const std::string& reference_string,
13297 const BasicJsonType& value,
13298 BasicJsonType& result)
13300 switch (value.type())
13302 case detail::value_t::array:
13304 if (value.m_value.array->empty())
13307 result[reference_string] =
nullptr;
13312 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
13314 flatten(reference_string +
"/" + std::to_string(i),
13315 value.m_value.array->operator[](i), result);
13321 case detail::value_t::object:
13323 if (value.m_value.object->empty())
13326 result[reference_string] =
nullptr;
13331 for (
const auto& element : *value.m_value.object)
13333 flatten(reference_string +
"/" + detail::escape(element.first), element.second, result);
13339 case detail::value_t::null:
13340 case detail::value_t::string:
13341 case detail::value_t::boolean:
13342 case detail::value_t::number_integer:
13343 case detail::value_t::number_unsigned:
13344 case detail::value_t::number_float:
13345 case detail::value_t::binary:
13346 case detail::value_t::discarded:
13350 result[reference_string] = value;
13366 static BasicJsonType
13367 unflatten(
const BasicJsonType& value)
13369 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
13371 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", value));
13374 BasicJsonType result;
13377 for (
const auto& element : *value.m_value.object)
13379 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
13381 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", element.second));
13388 json_pointer(element.first).get_and_create(result) = element.second;
13408 return lhs.reference_tokens == rhs.reference_tokens;
13425 return !(lhs == rhs);
13429 std::vector<std::string> reference_tokens;
13436#include <initializer_list>
13446template<
typename BasicJsonType>
13450 using value_type = BasicJsonType;
13452 json_ref(value_type&& value)
13453 : owned_value(
std::move(value))
13456 json_ref(
const value_type& value)
13457 : value_ref(&value)
13460 json_ref(std::initializer_list<json_ref> init)
13461 : owned_value(init)
13466 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
13467 json_ref(Args && ... args)
13468 : owned_value(
std::forward<Args>(args)...)
13472 json_ref(json_ref&&) noexcept = default;
13473 json_ref(const json_ref&) = delete;
13474 json_ref& operator=(const json_ref&) = delete;
13475 json_ref& operator=(json_ref&&) = delete;
13476 ~json_ref() = default;
13478 value_type moved_or_copied()
const
13480 if (value_ref ==
nullptr)
13482 return std::move(owned_value);
13487 value_type
const& operator*()
const
13489 return value_ref ? *value_ref : owned_value;
13492 value_type
const* operator->()
const
13498 mutable value_type owned_value =
nullptr;
13499 value_type
const* value_ref =
nullptr;
13515#include <algorithm>
13531#include <algorithm>
13551template<
typename CharType>
struct output_adapter_protocol
13553 virtual void write_character(CharType c) = 0;
13554 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
13555 virtual ~output_adapter_protocol() =
default;
13557 output_adapter_protocol() =
default;
13558 output_adapter_protocol(
const output_adapter_protocol&) =
default;
13559 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
13560 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
13561 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
13565template<typename CharType>
13566using output_adapter_t =
std::shared_ptr<output_adapter_protocol<CharType>>;
13569template<typename CharType, typename AllocatorType =
std::allocator<CharType>>
13570class output_vector_adapter : public output_adapter_protocol<CharType>
13573 explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
13577 void write_character(CharType c)
override
13582 JSON_HEDLEY_NON_NULL(2)
13583 void write_characters(const CharType* s,
std::
size_t length)
override
13585 std::copy(s, s + length, std::back_inserter(v));
13589 std::vector<CharType, AllocatorType>& v;
13594template<
typename CharType>
13595class output_stream_adapter :
public output_adapter_protocol<CharType>
13598 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
13602 void write_character(CharType c)
override
13607 JSON_HEDLEY_NON_NULL(2)
13608 void write_characters(const CharType* s,
std::
size_t length)
override
13610 stream.write(s,
static_cast<std::streamsize
>(length));
13614 std::basic_ostream<CharType>& stream;
13619template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13620class output_string_adapter :
public output_adapter_protocol<CharType>
13623 explicit output_string_adapter(StringType& s) noexcept
13627 void write_character(CharType c)
override
13632 JSON_HEDLEY_NON_NULL(2)
13633 void write_characters(const CharType* s,
std::
size_t length)
override
13635 str.append(s, length);
13642template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13643class output_adapter
13646 template<
typename AllocatorType = std::allocator<CharType>>
13647 output_adapter(std::vector<CharType, AllocatorType>& vec)
13648 : oa(
std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
13651 output_adapter(std::basic_ostream<CharType>& s)
13652 : oa(
std::make_shared<output_stream_adapter<CharType>>(s)) {}
13655 output_adapter(StringType& s)
13656 : oa(
std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13658 operator output_adapter_t<CharType>()
13664 output_adapter_t<CharType> oa =
nullptr;
13681template<
typename BasicJsonType,
typename CharType>
13684 using string_t =
typename BasicJsonType::string_t;
13685 using binary_t =
typename BasicJsonType::binary_t;
13686 using number_float_t =
typename BasicJsonType::number_float_t;
13694 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(
std::move(adapter))
13703 void write_bson(
const BasicJsonType& j)
13707 case value_t::object:
13709 write_bson_object(*j.m_value.object);
13713 case value_t::null:
13714 case value_t::array:
13715 case value_t::string:
13716 case value_t::boolean:
13717 case value_t::number_integer:
13718 case value_t::number_unsigned:
13719 case value_t::number_float:
13720 case value_t::binary:
13721 case value_t::discarded:
13724 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
13732 void write_cbor(
const BasicJsonType& j)
13736 case value_t::null:
13738 oa->write_character(to_char_type(0xF6));
13742 case value_t::boolean:
13744 oa->write_character(j.m_value.boolean
13745 ? to_char_type(0xF5)
13746 : to_char_type(0xF4));
13750 case value_t::number_integer:
13752 if (j.m_value.number_integer >= 0)
13757 if (j.m_value.number_integer <= 0x17)
13759 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13761 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13763 oa->write_character(to_char_type(0x18));
13764 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13766 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13768 oa->write_character(to_char_type(0x19));
13769 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13771 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13773 oa->write_character(to_char_type(0x1A));
13774 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13778 oa->write_character(to_char_type(0x1B));
13779 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13786 const auto positive_number = -1 - j.m_value.number_integer;
13787 if (j.m_value.number_integer >= -24)
13789 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
13791 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13793 oa->write_character(to_char_type(0x38));
13794 write_number(
static_cast<std::uint8_t
>(positive_number));
13796 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13798 oa->write_character(to_char_type(0x39));
13799 write_number(
static_cast<std::uint16_t
>(positive_number));
13801 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13803 oa->write_character(to_char_type(0x3A));
13804 write_number(
static_cast<std::uint32_t
>(positive_number));
13808 oa->write_character(to_char_type(0x3B));
13809 write_number(
static_cast<std::uint64_t
>(positive_number));
13815 case value_t::number_unsigned:
13817 if (j.m_value.number_unsigned <= 0x17)
13819 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13821 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13823 oa->write_character(to_char_type(0x18));
13824 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13826 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13828 oa->write_character(to_char_type(0x19));
13829 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
13831 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13833 oa->write_character(to_char_type(0x1A));
13834 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
13838 oa->write_character(to_char_type(0x1B));
13839 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
13844 case value_t::number_float:
13846 if (std::isnan(j.m_value.number_float))
13849 oa->write_character(to_char_type(0xF9));
13850 oa->write_character(to_char_type(0x7E));
13851 oa->write_character(to_char_type(0x00));
13853 else if (std::isinf(j.m_value.number_float))
13856 oa->write_character(to_char_type(0xf9));
13857 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13858 oa->write_character(to_char_type(0x00));
13862 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13867 case value_t::string:
13870 const auto N = j.m_value.string->size();
13873 write_number(
static_cast<std::uint8_t
>(0x60 + N));
13875 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13877 oa->write_character(to_char_type(0x78));
13878 write_number(
static_cast<std::uint8_t
>(N));
13880 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13882 oa->write_character(to_char_type(0x79));
13883 write_number(
static_cast<std::uint16_t
>(N));
13885 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13887 oa->write_character(to_char_type(0x7A));
13888 write_number(
static_cast<std::uint32_t
>(N));
13891 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13893 oa->write_character(to_char_type(0x7B));
13894 write_number(
static_cast<std::uint64_t
>(N));
13899 oa->write_characters(
13900 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13901 j.m_value.string->size());
13905 case value_t::array:
13908 const auto N = j.m_value.array->size();
13911 write_number(
static_cast<std::uint8_t
>(0x80 + N));
13913 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13915 oa->write_character(to_char_type(0x98));
13916 write_number(
static_cast<std::uint8_t
>(N));
13918 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13920 oa->write_character(to_char_type(0x99));
13921 write_number(
static_cast<std::uint16_t
>(N));
13923 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13925 oa->write_character(to_char_type(0x9A));
13926 write_number(
static_cast<std::uint32_t
>(N));
13929 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13931 oa->write_character(to_char_type(0x9B));
13932 write_number(
static_cast<std::uint64_t
>(N));
13937 for (
const auto& el : *j.m_value.array)
13944 case value_t::binary:
13946 if (j.m_value.binary->has_subtype())
13948 if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
13950 write_number(
static_cast<std::uint8_t
>(0xd8));
13951 write_number(
static_cast<std::uint8_t
>(j.m_value.binary->subtype()));
13953 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
13955 write_number(
static_cast<std::uint8_t
>(0xd9));
13956 write_number(
static_cast<std::uint16_t
>(j.m_value.binary->subtype()));
13958 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
13960 write_number(
static_cast<std::uint8_t
>(0xda));
13961 write_number(
static_cast<std::uint32_t
>(j.m_value.binary->subtype()));
13963 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
13965 write_number(
static_cast<std::uint8_t
>(0xdb));
13966 write_number(
static_cast<std::uint64_t
>(j.m_value.binary->subtype()));
13971 const auto N = j.m_value.binary->size();
13974 write_number(
static_cast<std::uint8_t
>(0x40 + N));
13976 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13978 oa->write_character(to_char_type(0x58));
13979 write_number(
static_cast<std::uint8_t
>(N));
13981 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13983 oa->write_character(to_char_type(0x59));
13984 write_number(
static_cast<std::uint16_t
>(N));
13986 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13988 oa->write_character(to_char_type(0x5A));
13989 write_number(
static_cast<std::uint32_t
>(N));
13992 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13994 oa->write_character(to_char_type(0x5B));
13995 write_number(
static_cast<std::uint64_t
>(N));
14000 oa->write_characters(
14001 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14007 case value_t::object:
14010 const auto N = j.m_value.object->size();
14013 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
14015 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14017 oa->write_character(to_char_type(0xB8));
14018 write_number(
static_cast<std::uint8_t
>(N));
14020 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14022 oa->write_character(to_char_type(0xB9));
14023 write_number(
static_cast<std::uint16_t
>(N));
14025 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14027 oa->write_character(to_char_type(0xBA));
14028 write_number(
static_cast<std::uint32_t
>(N));
14031 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
14033 oa->write_character(to_char_type(0xBB));
14034 write_number(
static_cast<std::uint64_t
>(N));
14039 for (
const auto& el : *j.m_value.object)
14041 write_cbor(el.first);
14042 write_cbor(el.second);
14047 case value_t::discarded:
14056 void write_msgpack(
const BasicJsonType& j)
14060 case value_t::null:
14062 oa->write_character(to_char_type(0xC0));
14066 case value_t::boolean:
14068 oa->write_character(j.m_value.boolean
14069 ? to_char_type(0xC3)
14070 : to_char_type(0xC2));
14074 case value_t::number_integer:
14076 if (j.m_value.number_integer >= 0)
14081 if (j.m_value.number_unsigned < 128)
14084 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14086 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14089 oa->write_character(to_char_type(0xCC));
14090 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14092 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14095 oa->write_character(to_char_type(0xCD));
14096 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14098 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14101 oa->write_character(to_char_type(0xCE));
14102 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14104 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14107 oa->write_character(to_char_type(0xCF));
14108 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14113 if (j.m_value.number_integer >= -32)
14116 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14118 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
14119 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14122 oa->write_character(to_char_type(0xD0));
14123 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14125 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
14126 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14129 oa->write_character(to_char_type(0xD1));
14130 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
14132 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
14133 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14136 oa->write_character(to_char_type(0xD2));
14137 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
14139 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
14140 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14143 oa->write_character(to_char_type(0xD3));
14144 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
14150 case value_t::number_unsigned:
14152 if (j.m_value.number_unsigned < 128)
14155 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14157 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14160 oa->write_character(to_char_type(0xCC));
14161 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14163 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14166 oa->write_character(to_char_type(0xCD));
14167 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14169 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14172 oa->write_character(to_char_type(0xCE));
14173 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14175 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14178 oa->write_character(to_char_type(0xCF));
14179 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14184 case value_t::number_float:
14186 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
14190 case value_t::string:
14193 const auto N = j.m_value.string->size();
14197 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
14199 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14202 oa->write_character(to_char_type(0xD9));
14203 write_number(
static_cast<std::uint8_t
>(N));
14205 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14208 oa->write_character(to_char_type(0xDA));
14209 write_number(
static_cast<std::uint16_t
>(N));
14211 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14214 oa->write_character(to_char_type(0xDB));
14215 write_number(
static_cast<std::uint32_t
>(N));
14219 oa->write_characters(
14220 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
14221 j.m_value.string->size());
14225 case value_t::array:
14228 const auto N = j.m_value.array->size();
14232 write_number(
static_cast<std::uint8_t
>(0x90 | N));
14234 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14237 oa->write_character(to_char_type(0xDC));
14238 write_number(
static_cast<std::uint16_t
>(N));
14240 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14243 oa->write_character(to_char_type(0xDD));
14244 write_number(
static_cast<std::uint32_t
>(N));
14248 for (
const auto& el : *j.m_value.array)
14255 case value_t::binary:
14259 const bool use_ext = j.m_value.binary->has_subtype();
14262 const auto N = j.m_value.binary->size();
14263 if (N <= (std::numeric_limits<std::uint8_t>::max)())
14265 std::uint8_t output_type{};
14272 output_type = 0xD4;
14275 output_type = 0xD5;
14278 output_type = 0xD6;
14281 output_type = 0xD7;
14284 output_type = 0xD8;
14287 output_type = 0xC7;
14295 output_type = 0xC4;
14299 oa->write_character(to_char_type(output_type));
14302 write_number(
static_cast<std::uint8_t
>(N));
14305 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14307 std::uint8_t output_type = use_ext
14311 oa->write_character(to_char_type(output_type));
14312 write_number(
static_cast<std::uint16_t
>(N));
14314 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14316 std::uint8_t output_type = use_ext
14320 oa->write_character(to_char_type(output_type));
14321 write_number(
static_cast<std::uint32_t
>(N));
14327 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
14331 oa->write_characters(
14332 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14338 case value_t::object:
14341 const auto N = j.m_value.object->size();
14345 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
14347 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14350 oa->write_character(to_char_type(0xDE));
14351 write_number(
static_cast<std::uint16_t
>(N));
14353 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14356 oa->write_character(to_char_type(0xDF));
14357 write_number(
static_cast<std::uint32_t
>(N));
14361 for (
const auto& el : *j.m_value.object)
14363 write_msgpack(el.first);
14364 write_msgpack(el.second);
14369 case value_t::discarded:
14381 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
14382 const bool use_type,
const bool add_prefix =
true)
14386 case value_t::null:
14390 oa->write_character(to_char_type(
'Z'));
14395 case value_t::boolean:
14399 oa->write_character(j.m_value.boolean
14400 ? to_char_type(
'T')
14401 : to_char_type(
'F'));
14406 case value_t::number_integer:
14408 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
14412 case value_t::number_unsigned:
14414 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
14418 case value_t::number_float:
14420 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
14424 case value_t::string:
14428 oa->write_character(to_char_type(
'S'));
14430 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
14431 oa->write_characters(
14432 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
14433 j.m_value.string->size());
14437 case value_t::array:
14441 oa->write_character(to_char_type(
'['));
14444 bool prefix_required =
true;
14445 if (use_type && !j.m_value.array->empty())
14447 JSON_ASSERT(use_count);
14448 const CharType first_prefix = ubjson_prefix(j.front());
14449 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
14450 [
this, first_prefix](
const BasicJsonType & v)
14452 return ubjson_prefix(v) == first_prefix;
14457 prefix_required =
false;
14458 oa->write_character(to_char_type(
'$'));
14459 oa->write_character(first_prefix);
14465 oa->write_character(to_char_type(
'#'));
14466 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
14469 for (
const auto& el : *j.m_value.array)
14471 write_ubjson(el, use_count, use_type, prefix_required);
14476 oa->write_character(to_char_type(
']'));
14482 case value_t::binary:
14486 oa->write_character(to_char_type(
'['));
14489 if (use_type && !j.m_value.binary->empty())
14491 JSON_ASSERT(use_count);
14492 oa->write_character(to_char_type(
'$'));
14493 oa->write_character(
'U');
14498 oa->write_character(to_char_type(
'#'));
14499 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
14504 oa->write_characters(
14505 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14506 j.m_value.binary->size());
14510 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
14512 oa->write_character(to_char_type(
'U'));
14513 oa->write_character(j.m_value.binary->data()[i]);
14519 oa->write_character(to_char_type(
']'));
14525 case value_t::object:
14529 oa->write_character(to_char_type(
'{'));
14532 bool prefix_required =
true;
14533 if (use_type && !j.m_value.object->empty())
14535 JSON_ASSERT(use_count);
14536 const CharType first_prefix = ubjson_prefix(j.front());
14537 const bool same_prefix = std::all_of(j.begin(), j.end(),
14538 [
this, first_prefix](
const BasicJsonType & v)
14540 return ubjson_prefix(v) == first_prefix;
14545 prefix_required =
false;
14546 oa->write_character(to_char_type(
'$'));
14547 oa->write_character(first_prefix);
14553 oa->write_character(to_char_type(
'#'));
14554 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
14557 for (
const auto& el : *j.m_value.object)
14559 write_number_with_ubjson_prefix(el.first.size(),
true);
14560 oa->write_characters(
14561 reinterpret_cast<const CharType*
>(el.first.c_str()),
14563 write_ubjson(el.second, use_count, use_type, prefix_required);
14568 oa->write_character(to_char_type(
'}'));
14574 case value_t::discarded:
14589 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
14591 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
14592 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14594 JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")", j));
14595 static_cast<void>(j);
14598 return 1ul + name.size() + 1u;
14604 void write_bson_entry_header(
const string_t& name,
14605 const std::uint8_t element_type)
14607 oa->write_character(to_char_type(element_type));
14608 oa->write_characters(
14609 reinterpret_cast<const CharType*
>(name.c_str()),
14616 void write_bson_boolean(
const string_t& name,
14619 write_bson_entry_header(name, 0x08);
14620 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
14626 void write_bson_double(
const string_t& name,
14627 const double value)
14629 write_bson_entry_header(name, 0x01);
14630 write_number<double, true>(value);
14636 static std::size_t calc_bson_string_size(
const string_t& value)
14638 return sizeof(std::int32_t) + value.size() + 1ul;
14644 void write_bson_string(
const string_t& name,
14645 const string_t& value)
14647 write_bson_entry_header(name, 0x02);
14649 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
14650 oa->write_characters(
14651 reinterpret_cast<const CharType*
>(value.c_str()),
14658 void write_bson_null(
const string_t& name)
14660 write_bson_entry_header(name, 0x0A);
14666 static std::size_t calc_bson_integer_size(
const std::int64_t value)
14668 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
14669 ?
sizeof(std::int32_t)
14670 :
sizeof(std::int64_t);
14676 void write_bson_integer(
const string_t& name,
14677 const std::int64_t value)
14679 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
14681 write_bson_entry_header(name, 0x10);
14682 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
14686 write_bson_entry_header(name, 0x12);
14687 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
14694 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value)
noexcept
14696 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14697 ?
sizeof(std::int32_t)
14698 :
sizeof(std::int64_t);
14704 void write_bson_unsigned(
const string_t& name,
14705 const BasicJsonType& j)
14707 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14709 write_bson_entry_header(name, 0x10 );
14710 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(j.m_value.number_unsigned));
14712 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14714 write_bson_entry_header(name, 0x12 );
14715 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(j.m_value.number_unsigned));
14719 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));
14726 void write_bson_object_entry(
const string_t& name,
14727 const typename BasicJsonType::object_t& value)
14729 write_bson_entry_header(name, 0x03);
14730 write_bson_object(value);
14736 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
14738 std::size_t array_index = 0ul;
14740 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)
14742 return result + calc_bson_element_size(std::to_string(array_index++), el);
14745 return sizeof(std::int32_t) + embedded_document_size + 1ul;
14751 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
14753 return sizeof(std::int32_t) + value.size() + 1ul;
14759 void write_bson_array(
const string_t& name,
14760 const typename BasicJsonType::array_t& value)
14762 write_bson_entry_header(name, 0x04);
14763 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
14765 std::size_t array_index = 0ul;
14767 for (
const auto& el : value)
14769 write_bson_element(std::to_string(array_index++), el);
14772 oa->write_character(to_char_type(0x00));
14778 void write_bson_binary(
const string_t& name,
14779 const binary_t& value)
14781 write_bson_entry_header(name, 0x05);
14783 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size()));
14784 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) : std::uint8_t(0x00));
14786 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
14793 static std::size_t calc_bson_element_size(
const string_t& name,
14794 const BasicJsonType& j)
14796 const auto header_size = calc_bson_entry_header_size(name, j);
14799 case value_t::object:
14800 return header_size + calc_bson_object_size(*j.m_value.object);
14802 case value_t::array:
14803 return header_size + calc_bson_array_size(*j.m_value.array);
14805 case value_t::binary:
14806 return header_size + calc_bson_binary_size(*j.m_value.binary);
14808 case value_t::boolean:
14809 return header_size + 1ul;
14811 case value_t::number_float:
14812 return header_size + 8ul;
14814 case value_t::number_integer:
14815 return header_size + calc_bson_integer_size(j.m_value.number_integer);
14817 case value_t::number_unsigned:
14818 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14820 case value_t::string:
14821 return header_size + calc_bson_string_size(*j.m_value.string);
14823 case value_t::null:
14824 return header_size + 0ul;
14827 case value_t::discarded:
14829 JSON_ASSERT(
false);
14841 void write_bson_element(
const string_t& name,
14842 const BasicJsonType& j)
14846 case value_t::object:
14847 return write_bson_object_entry(name, *j.m_value.object);
14849 case value_t::array:
14850 return write_bson_array(name, *j.m_value.array);
14852 case value_t::binary:
14853 return write_bson_binary(name, *j.m_value.binary);
14855 case value_t::boolean:
14856 return write_bson_boolean(name, j.m_value.boolean);
14858 case value_t::number_float:
14859 return write_bson_double(name, j.m_value.number_float);
14861 case value_t::number_integer:
14862 return write_bson_integer(name, j.m_value.number_integer);
14864 case value_t::number_unsigned:
14865 return write_bson_unsigned(name, j);
14867 case value_t::string:
14868 return write_bson_string(name, *j.m_value.string);
14870 case value_t::null:
14871 return write_bson_null(name);
14874 case value_t::discarded:
14876 JSON_ASSERT(
false);
14888 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
14890 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14891 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
14893 return result += calc_bson_element_size(el.first, el.second);
14896 return sizeof(std::int32_t) + document_size + 1ul;
14903 void write_bson_object(
const typename BasicJsonType::object_t& value)
14905 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
14907 for (
const auto& el : value)
14909 write_bson_element(el.first, el.second);
14912 oa->write_character(to_char_type(0x00));
14919 static constexpr CharType get_cbor_float_prefix(
float )
14921 return to_char_type(0xFA);
14924 static constexpr CharType get_cbor_float_prefix(
double )
14926 return to_char_type(0xFB);
14933 static constexpr CharType get_msgpack_float_prefix(
float )
14935 return to_char_type(0xCA);
14938 static constexpr CharType get_msgpack_float_prefix(
double )
14940 return to_char_type(0xCB);
14948 template<
typename NumberType,
typename std::enable_if<
14949 std::is_floating_point<NumberType>::value,
int>::type = 0>
14950 void write_number_with_ubjson_prefix(
const NumberType n,
14951 const bool add_prefix)
14955 oa->write_character(get_ubjson_float_prefix(n));
14961 template<
typename NumberType,
typename std::enable_if<
14962 std::is_unsigned<NumberType>::value,
int>::type = 0>
14963 void write_number_with_ubjson_prefix(
const NumberType n,
14964 const bool add_prefix)
14966 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14970 oa->write_character(to_char_type(
'i'));
14972 write_number(
static_cast<std::uint8_t
>(n));
14974 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14978 oa->write_character(to_char_type(
'U'));
14980 write_number(
static_cast<std::uint8_t
>(n));
14982 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14986 oa->write_character(to_char_type(
'I'));
14988 write_number(
static_cast<std::int16_t
>(n));
14990 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14994 oa->write_character(to_char_type(
'l'));
14996 write_number(
static_cast<std::int32_t
>(n));
14998 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
15002 oa->write_character(to_char_type(
'L'));
15004 write_number(
static_cast<std::int64_t
>(n));
15010 oa->write_character(to_char_type(
'H'));
15013 const auto number = BasicJsonType(n).dump();
15014 write_number_with_ubjson_prefix(number.size(),
true);
15015 for (std::size_t i = 0; i < number.size(); ++i)
15017 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15023 template <
typename NumberType,
typename std::enable_if <
15024 std::is_signed<NumberType>::value&&
15025 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
15026 void write_number_with_ubjson_prefix(
const NumberType n,
15027 const bool add_prefix)
15029 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
15033 oa->write_character(to_char_type(
'i'));
15035 write_number(
static_cast<std::int8_t
>(n));
15037 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)()))
15041 oa->write_character(to_char_type(
'U'));
15043 write_number(
static_cast<std::uint8_t
>(n));
15045 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
15049 oa->write_character(to_char_type(
'I'));
15051 write_number(
static_cast<std::int16_t
>(n));
15053 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
15057 oa->write_character(to_char_type(
'l'));
15059 write_number(
static_cast<std::int32_t
>(n));
15061 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
15065 oa->write_character(to_char_type(
'L'));
15067 write_number(
static_cast<std::int64_t
>(n));
15074 oa->write_character(to_char_type(
'H'));
15077 const auto number = BasicJsonType(n).dump();
15078 write_number_with_ubjson_prefix(number.size(),
true);
15079 for (std::size_t i = 0; i < number.size(); ++i)
15081 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15090 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
15094 case value_t::null:
15097 case value_t::boolean:
15098 return j.m_value.boolean ?
'T' :
'F';
15100 case value_t::number_integer:
15102 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)())
15106 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)())
15110 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)())
15114 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)())
15118 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)())
15126 case value_t::number_unsigned:
15128 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
15132 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
15136 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
15140 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
15144 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
15152 case value_t::number_float:
15153 return get_ubjson_float_prefix(j.m_value.number_float);
15155 case value_t::string:
15158 case value_t::array:
15159 case value_t::binary:
15162 case value_t::object:
15165 case value_t::discarded:
15171 static constexpr CharType get_ubjson_float_prefix(
float )
15176 static constexpr CharType get_ubjson_float_prefix(
double )
15196 template<
typename NumberType,
bool OutputIsLittleEndian = false>
15197 void write_number(
const NumberType n)
15200 std::array<CharType,
sizeof(NumberType)> vec{};
15201 std::memcpy(vec.data(), &n,
sizeof(NumberType));
15204 if (is_little_endian != OutputIsLittleEndian)
15207 std::reverse(vec.begin(), vec.end());
15210 oa->write_characters(vec.data(),
sizeof(NumberType));
15213 void write_compact_float(
const number_float_t n, detail::input_format_t format)
15216#pragma GCC diagnostic push
15217#pragma GCC diagnostic ignored "-Wfloat-equal"
15219 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
15220 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
15221 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
15223 oa->write_character(format == detail::input_format_t::cbor
15224 ? get_cbor_float_prefix(
static_cast<float>(n))
15225 : get_msgpack_float_prefix(
static_cast<float>(n)));
15226 write_number(
static_cast<float>(n));
15230 oa->write_character(format == detail::input_format_t::cbor
15231 ? get_cbor_float_prefix(n)
15232 : get_msgpack_float_prefix(n));
15236#pragma GCC diagnostic pop
15245 template <
typename C = CharType,
15246 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
15247 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
15249 return *
reinterpret_cast<char*
>(&x);
15252 template <
typename C = CharType,
15253 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
15254 static CharType to_char_type(std::uint8_t x)
noexcept
15256 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
15257 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
15259 std::memcpy(&result, &x,
sizeof(x));
15263 template<
typename C = CharType,
15264 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
15265 static constexpr CharType to_char_type(std::uint8_t x)
noexcept
15270 template <
typename InputCharType,
typename C = CharType,
15272 std::is_signed<C>::value &&
15273 std::is_signed<char>::value &&
15274 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
15276 static constexpr CharType to_char_type(InputCharType x)
noexcept
15283 const bool is_little_endian = little_endianess();
15286 output_adapter_t<CharType> oa =
nullptr;
15296#include <algorithm>
15305#include <type_traits>
15316#include <type_traits>
15348template<
typename Target,
typename Source>
15349Target reinterpret_bits(
const Source source)
15351 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
15354 std::memcpy(&target, &source,
sizeof(Source));
15360 static constexpr int kPrecision = 64;
15362 std::uint64_t f = 0;
15365 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
15371 static diyfp sub(
const diyfp& x,
const diyfp& y)
noexcept
15373 JSON_ASSERT(x.e == y.e);
15374 JSON_ASSERT(x.f >= y.f);
15376 return {x.f - y.f, x.e};
15383 static diyfp mul(
const diyfp& x,
const diyfp& y)
noexcept
15385 static_assert(kPrecision == 64,
"internal error");
15410 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
15411 const std::uint64_t u_hi = x.f >> 32u;
15412 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
15413 const std::uint64_t v_hi = y.f >> 32u;
15415 const std::uint64_t p0 = u_lo * v_lo;
15416 const std::uint64_t p1 = u_lo * v_hi;
15417 const std::uint64_t p2 = u_hi * v_lo;
15418 const std::uint64_t p3 = u_hi * v_hi;
15420 const std::uint64_t p0_hi = p0 >> 32u;
15421 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
15422 const std::uint64_t p1_hi = p1 >> 32u;
15423 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
15424 const std::uint64_t p2_hi = p2 >> 32u;
15426 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
15437 Q += std::uint64_t{1} << (64u - 32u - 1u);
15439 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
15441 return {h, x.e + y.e + 64};
15448 static diyfp normalize(diyfp x)
noexcept
15450 JSON_ASSERT(x.f != 0);
15452 while ((x.f >> 63u) == 0)
15465 static diyfp normalize_to(
const diyfp& x,
const int target_exponent)
noexcept
15467 const int delta = x.e - target_exponent;
15469 JSON_ASSERT(delta >= 0);
15470 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15472 return {x.f << delta, target_exponent};
15489template<
typename FloatType>
15490boundaries compute_boundaries(FloatType value)
15492 JSON_ASSERT(std::isfinite(value));
15493 JSON_ASSERT(value > 0);
15502 static_assert(std::numeric_limits<FloatType>::is_iec559,
15503 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
15505 constexpr int kPrecision = std::numeric_limits<FloatType>::digits;
15506 constexpr int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
15507 constexpr int kMinExp = 1 - kBias;
15508 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
15510 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
15512 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
15513 const std::uint64_t E = bits >> (kPrecision - 1);
15514 const std::uint64_t F = bits & (kHiddenBit - 1);
15516 const bool is_denormal = E == 0;
15517 const diyfp v = is_denormal
15518 ? diyfp(F, kMinExp)
15519 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
15542 const bool lower_boundary_is_closer = F == 0 && E > 1;
15543 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
15544 const diyfp m_minus = lower_boundary_is_closer
15545 ? diyfp(4 * v.f - 1, v.e - 2)
15546 : diyfp(2 * v.f - 1, v.e - 1);
15549 const diyfp w_plus = diyfp::normalize(m_plus);
15552 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
15554 return {diyfp::normalize(v), w_minus, w_plus};
15612constexpr int kAlpha = -60;
15613constexpr int kGamma = -32;
15629inline cached_power get_cached_power_for_binary_exponent(
int e)
15681 constexpr int kCachedPowersMinDecExp = -300;
15682 constexpr int kCachedPowersDecStep = 8;
15684 static constexpr std::array<cached_power, 79> kCachedPowers =
15687 { 0xAB70FE17C79AC6CA, -1060, -300 },
15688 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15689 { 0xBE5691EF416BD60C, -1007, -284 },
15690 { 0x8DD01FAD907FFC3C, -980, -276 },
15691 { 0xD3515C2831559A83, -954, -268 },
15692 { 0x9D71AC8FADA6C9B5, -927, -260 },
15693 { 0xEA9C227723EE8BCB, -901, -252 },
15694 { 0xAECC49914078536D, -874, -244 },
15695 { 0x823C12795DB6CE57, -847, -236 },
15696 { 0xC21094364DFB5637, -821, -228 },
15697 { 0x9096EA6F3848984F, -794, -220 },
15698 { 0xD77485CB25823AC7, -768, -212 },
15699 { 0xA086CFCD97BF97F4, -741, -204 },
15700 { 0xEF340A98172AACE5, -715, -196 },
15701 { 0xB23867FB2A35B28E, -688, -188 },
15702 { 0x84C8D4DFD2C63F3B, -661, -180 },
15703 { 0xC5DD44271AD3CDBA, -635, -172 },
15704 { 0x936B9FCEBB25C996, -608, -164 },
15705 { 0xDBAC6C247D62A584, -582, -156 },
15706 { 0xA3AB66580D5FDAF6, -555, -148 },
15707 { 0xF3E2F893DEC3F126, -529, -140 },
15708 { 0xB5B5ADA8AAFF80B8, -502, -132 },
15709 { 0x87625F056C7C4A8B, -475, -124 },
15710 { 0xC9BCFF6034C13053, -449, -116 },
15711 { 0x964E858C91BA2655, -422, -108 },
15712 { 0xDFF9772470297EBD, -396, -100 },
15713 { 0xA6DFBD9FB8E5B88F, -369, -92 },
15714 { 0xF8A95FCF88747D94, -343, -84 },
15715 { 0xB94470938FA89BCF, -316, -76 },
15716 { 0x8A08F0F8BF0F156B, -289, -68 },
15717 { 0xCDB02555653131B6, -263, -60 },
15718 { 0x993FE2C6D07B7FAC, -236, -52 },
15719 { 0xE45C10C42A2B3B06, -210, -44 },
15720 { 0xAA242499697392D3, -183, -36 },
15721 { 0xFD87B5F28300CA0E, -157, -28 },
15722 { 0xBCE5086492111AEB, -130, -20 },
15723 { 0x8CBCCC096F5088CC, -103, -12 },
15724 { 0xD1B71758E219652C, -77, -4 },
15725 { 0x9C40000000000000, -50, 4 },
15726 { 0xE8D4A51000000000, -24, 12 },
15727 { 0xAD78EBC5AC620000, 3, 20 },
15728 { 0x813F3978F8940984, 30, 28 },
15729 { 0xC097CE7BC90715B3, 56, 36 },
15730 { 0x8F7E32CE7BEA5C70, 83, 44 },
15731 { 0xD5D238A4ABE98068, 109, 52 },
15732 { 0x9F4F2726179A2245, 136, 60 },
15733 { 0xED63A231D4C4FB27, 162, 68 },
15734 { 0xB0DE65388CC8ADA8, 189, 76 },
15735 { 0x83C7088E1AAB65DB, 216, 84 },
15736 { 0xC45D1DF942711D9A, 242, 92 },
15737 { 0x924D692CA61BE758, 269, 100 },
15738 { 0xDA01EE641A708DEA, 295, 108 },
15739 { 0xA26DA3999AEF774A, 322, 116 },
15740 { 0xF209787BB47D6B85, 348, 124 },
15741 { 0xB454E4A179DD1877, 375, 132 },
15742 { 0x865B86925B9BC5C2, 402, 140 },
15743 { 0xC83553C5C8965D3D, 428, 148 },
15744 { 0x952AB45CFA97A0B3, 455, 156 },
15745 { 0xDE469FBD99A05FE3, 481, 164 },
15746 { 0xA59BC234DB398C25, 508, 172 },
15747 { 0xF6C69A72A3989F5C, 534, 180 },
15748 { 0xB7DCBF5354E9BECE, 561, 188 },
15749 { 0x88FCF317F22241E2, 588, 196 },
15750 { 0xCC20CE9BD35C78A5, 614, 204 },
15751 { 0x98165AF37B2153DF, 641, 212 },
15752 { 0xE2A0B5DC971F303A, 667, 220 },
15753 { 0xA8D9D1535CE3B396, 694, 228 },
15754 { 0xFB9B7CD9A4A7443C, 720, 236 },
15755 { 0xBB764C4CA7A44410, 747, 244 },
15756 { 0x8BAB8EEFB6409C1A, 774, 252 },
15757 { 0xD01FEF10A657842C, 800, 260 },
15758 { 0x9B10A4E5E9913129, 827, 268 },
15759 { 0xE7109BFBA19C0C9D, 853, 276 },
15760 { 0xAC2820D9623BF429, 880, 284 },
15761 { 0x80444B5E7AA7CF85, 907, 292 },
15762 { 0xBF21E44003ACDD2D, 933, 300 },
15763 { 0x8E679C2F5E44FF8F, 960, 308 },
15764 { 0xD433179D9C8CB841, 986, 316 },
15765 { 0x9E19DB92B4E31BA9, 1013, 324 },
15773 JSON_ASSERT(e >= -1500);
15774 JSON_ASSERT(e <= 1500);
15775 const int f = kAlpha - e - 1;
15776 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
15778 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15779 JSON_ASSERT(index >= 0);
15780 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
15782 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
15783 JSON_ASSERT(kAlpha <= cached.e + e + 64);
15784 JSON_ASSERT(kGamma >= cached.e + e + 64);
15793inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
15796 if (n >= 1000000000)
15798 pow10 = 1000000000;
15802 if (n >= 100000000)
15847inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
15848 std::uint64_t rest, std::uint64_t ten_k)
15850 JSON_ASSERT(len >= 1);
15851 JSON_ASSERT(dist <= delta);
15852 JSON_ASSERT(rest <= delta);
15853 JSON_ASSERT(ten_k > 0);
15875 && delta - rest >= ten_k
15876 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15878 JSON_ASSERT(buf[len - 1] !=
'0');
15888inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
15889 diyfp M_minus, diyfp w, diyfp M_plus)
15891 static_assert(kAlpha >= -60,
"internal error");
15892 static_assert(kGamma <= -32,
"internal error");
15906 JSON_ASSERT(M_plus.e >= kAlpha);
15907 JSON_ASSERT(M_plus.e <= kGamma);
15909 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
15910 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
15919 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15921 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
15922 std::uint64_t p2 = M_plus.f & (one.f - 1);
15928 JSON_ASSERT(p1 > 0);
15930 std::uint32_t pow10{};
15931 const int k = find_largest_pow10(p1, pow10);
15958 const std::uint32_t d = p1 / pow10;
15959 const std::uint32_t r = p1 % pow10;
15964 JSON_ASSERT(d <= 9);
15965 buffer[length++] =
static_cast<char>(
'0' + d);
15984 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15989 decimal_exponent += n;
16000 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
16001 grisu2_round(buffer, length, dist, delta, rest, ten_n);
16051 JSON_ASSERT(p2 > delta);
16062 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
16064 const std::uint64_t d = p2 >> -one.e;
16065 const std::uint64_t r = p2 & (one.f - 1);
16071 JSON_ASSERT(d <= 9);
16072 buffer[length++] =
static_cast<char>(
'0' + d);
16097 decimal_exponent -= m;
16105 const std::uint64_t ten_m = one.f;
16106 grisu2_round(buffer, length, dist, delta, p2, ten_m);
16128JSON_HEDLEY_NON_NULL(1)
16129inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
16130 diyfp m_minus, diyfp v, diyfp m_plus)
16132 JSON_ASSERT(m_plus.e == m_minus.e);
16133 JSON_ASSERT(m_plus.e == v.e);
16144 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
16146 const diyfp c_minus_k(cached.f, cached.e);
16149 const diyfp w = diyfp::mul(v, c_minus_k);
16150 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
16151 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
16174 const diyfp M_minus(w_minus.f + 1, w_minus.e);
16175 const diyfp M_plus (w_plus.f - 1, w_plus.e );
16177 decimal_exponent = -cached.k;
16179 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
16187template<
typename FloatType>
16188JSON_HEDLEY_NON_NULL(1)
16189void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
16191 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
16192 "internal error: not enough precision");
16194 JSON_ASSERT(std::isfinite(value));
16195 JSON_ASSERT(value > 0);
16214 const boundaries w = compute_boundaries(
static_cast<double>(value));
16216 const boundaries w = compute_boundaries(value);
16219 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
16227JSON_HEDLEY_NON_NULL(1)
16229inline
char* append_exponent(
char* buf,
int e)
16231 JSON_ASSERT(e > -1000);
16232 JSON_ASSERT(e < 1000);
16244 auto k =
static_cast<std::uint32_t
>(e);
16250 *buf++ =
static_cast<char>(
'0' + k);
16254 *buf++ =
static_cast<char>(
'0' + k / 10);
16256 *buf++ =
static_cast<char>(
'0' + k);
16260 *buf++ =
static_cast<char>(
'0' + k / 100);
16262 *buf++ =
static_cast<char>(
'0' + k / 10);
16264 *buf++ =
static_cast<char>(
'0' + k);
16279JSON_HEDLEY_NON_NULL(1)
16281inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
16282 int min_exp,
int max_exp)
16284 JSON_ASSERT(min_exp < 0);
16285 JSON_ASSERT(max_exp > 0);
16288 const int n = len + decimal_exponent;
16294 if (k <= n && n <= max_exp)
16299 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
16303 return buf + (
static_cast<size_t>(n) + 2);
16306 if (0 < n && n <= max_exp)
16311 JSON_ASSERT(k > n);
16313 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
16315 return buf + (
static_cast<size_t>(k) + 1U);
16318 if (min_exp < n && n <= 0)
16323 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
16326 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
16327 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
16342 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
16344 buf += 1 +
static_cast<size_t>(k);
16348 return append_exponent(buf, n - 1);
16363template<
typename FloatType>
16364JSON_HEDLEY_NON_NULL(1, 2)
16366char* to_chars(
char* first, const
char* last, FloatType value)
16368 static_cast<void>(last);
16369 JSON_ASSERT(std::isfinite(value));
16372 if (std::signbit(value))
16379#pragma GCC diagnostic push
16380#pragma GCC diagnostic ignored "-Wfloat-equal"
16391#pragma GCC diagnostic pop
16394 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
16401 int decimal_exponent = 0;
16402 dtoa_impl::grisu2(first, len, decimal_exponent, value);
16404 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
16407 constexpr int kMinExp = -4;
16409 constexpr int kMaxExp = std::numeric_limits<FloatType>::digits10;
16411 JSON_ASSERT(last - first >= kMaxExp + 2);
16412 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
16413 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
16415 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
16443enum class error_handler_t
16450template<
typename BasicJsonType>
16453 using string_t =
typename BasicJsonType::string_t;
16454 using number_float_t =
typename BasicJsonType::number_float_t;
16455 using number_integer_t =
typename BasicJsonType::number_integer_t;
16456 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
16457 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
16458 static constexpr std::uint8_t UTF8_ACCEPT = 0;
16459 static constexpr std::uint8_t UTF8_REJECT = 1;
16467 serializer(output_adapter_t<char> s,
const char ichar,
16468 error_handler_t error_handler_ = error_handler_t::strict)
16470 , loc(
std::localeconv())
16471 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' :
std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
16472 , decimal_point(loc->decimal_point == nullptr ?
'\0' :
std::char_traits<char>::to_char_type(* (loc->decimal_point)))
16473 , indent_char(ichar)
16474 , indent_string(512, indent_char)
16475 , error_handler(error_handler_)
16479 serializer(
const serializer&) =
delete;
16480 serializer& operator=(
const serializer&) =
delete;
16481 serializer(serializer&&) =
delete;
16482 serializer& operator=(serializer&&) =
delete;
16483 ~serializer() =
default;
16507 void dump(
const BasicJsonType& val,
16508 const bool pretty_print,
16509 const bool ensure_ascii,
16510 const unsigned int indent_step,
16511 const unsigned int current_indent = 0)
16513 switch (val.m_type)
16515 case value_t::object:
16517 if (val.m_value.object->empty())
16519 o->write_characters(
"{}", 2);
16525 o->write_characters(
"{\n", 2);
16528 const auto new_indent = current_indent + indent_step;
16529 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16531 indent_string.resize(indent_string.size() * 2,
' ');
16535 auto i = val.m_value.object->cbegin();
16536 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16538 o->write_characters(indent_string.c_str(), new_indent);
16539 o->write_character(
'\"');
16540 dump_escaped(i->first, ensure_ascii);
16541 o->write_characters(
"\": ", 3);
16542 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16543 o->write_characters(
",\n", 2);
16547 JSON_ASSERT(i != val.m_value.object->cend());
16548 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16549 o->write_characters(indent_string.c_str(), new_indent);
16550 o->write_character(
'\"');
16551 dump_escaped(i->first, ensure_ascii);
16552 o->write_characters(
"\": ", 3);
16553 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16555 o->write_character(
'\n');
16556 o->write_characters(indent_string.c_str(), current_indent);
16557 o->write_character(
'}');
16561 o->write_character(
'{');
16564 auto i = val.m_value.object->cbegin();
16565 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16567 o->write_character(
'\"');
16568 dump_escaped(i->first, ensure_ascii);
16569 o->write_characters(
"\":", 2);
16570 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16571 o->write_character(
',');
16575 JSON_ASSERT(i != val.m_value.object->cend());
16576 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16577 o->write_character(
'\"');
16578 dump_escaped(i->first, ensure_ascii);
16579 o->write_characters(
"\":", 2);
16580 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16582 o->write_character(
'}');
16588 case value_t::array:
16590 if (val.m_value.array->empty())
16592 o->write_characters(
"[]", 2);
16598 o->write_characters(
"[\n", 2);
16601 const auto new_indent = current_indent + indent_step;
16602 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16604 indent_string.resize(indent_string.size() * 2,
' ');
16608 for (
auto i = val.m_value.array->cbegin();
16609 i != val.m_value.array->cend() - 1; ++i)
16611 o->write_characters(indent_string.c_str(), new_indent);
16612 dump(*i,
true, ensure_ascii, indent_step, new_indent);
16613 o->write_characters(
",\n", 2);
16617 JSON_ASSERT(!val.m_value.array->empty());
16618 o->write_characters(indent_string.c_str(), new_indent);
16619 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
16621 o->write_character(
'\n');
16622 o->write_characters(indent_string.c_str(), current_indent);
16623 o->write_character(
']');
16627 o->write_character(
'[');
16630 for (
auto i = val.m_value.array->cbegin();
16631 i != val.m_value.array->cend() - 1; ++i)
16633 dump(*i,
false, ensure_ascii, indent_step, current_indent);
16634 o->write_character(
',');
16638 JSON_ASSERT(!val.m_value.array->empty());
16639 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
16641 o->write_character(
']');
16647 case value_t::string:
16649 o->write_character(
'\"');
16650 dump_escaped(*val.m_value.string, ensure_ascii);
16651 o->write_character(
'\"');
16655 case value_t::binary:
16659 o->write_characters(
"{\n", 2);
16662 const auto new_indent = current_indent + indent_step;
16663 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16665 indent_string.resize(indent_string.size() * 2,
' ');
16668 o->write_characters(indent_string.c_str(), new_indent);
16670 o->write_characters(
"\"bytes\": [", 10);
16672 if (!val.m_value.binary->empty())
16674 for (
auto i = val.m_value.binary->cbegin();
16675 i != val.m_value.binary->cend() - 1; ++i)
16678 o->write_characters(
", ", 2);
16680 dump_integer(val.m_value.binary->back());
16683 o->write_characters(
"],\n", 3);
16684 o->write_characters(indent_string.c_str(), new_indent);
16686 o->write_characters(
"\"subtype\": ", 11);
16687 if (val.m_value.binary->has_subtype())
16689 dump_integer(val.m_value.binary->subtype());
16693 o->write_characters(
"null", 4);
16695 o->write_character(
'\n');
16696 o->write_characters(indent_string.c_str(), current_indent);
16697 o->write_character(
'}');
16701 o->write_characters(
"{\"bytes\":[", 10);
16703 if (!val.m_value.binary->empty())
16705 for (
auto i = val.m_value.binary->cbegin();
16706 i != val.m_value.binary->cend() - 1; ++i)
16709 o->write_character(
',');
16711 dump_integer(val.m_value.binary->back());
16714 o->write_characters(
"],\"subtype\":", 12);
16715 if (val.m_value.binary->has_subtype())
16717 dump_integer(val.m_value.binary->subtype());
16718 o->write_character(
'}');
16722 o->write_characters(
"null}", 5);
16728 case value_t::boolean:
16730 if (val.m_value.boolean)
16732 o->write_characters(
"true", 4);
16736 o->write_characters(
"false", 5);
16741 case value_t::number_integer:
16743 dump_integer(val.m_value.number_integer);
16747 case value_t::number_unsigned:
16749 dump_integer(val.m_value.number_unsigned);
16753 case value_t::number_float:
16755 dump_float(val.m_value.number_float);
16759 case value_t::discarded:
16761 o->write_characters(
"<discarded>", 11);
16765 case value_t::null:
16767 o->write_characters(
"null", 4);
16772 JSON_ASSERT(
false);
16776 JSON_PRIVATE_UNLESS_TESTED:
16791 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
16793 std::uint32_t codepoint{};
16794 std::uint8_t state = UTF8_ACCEPT;
16795 std::size_t bytes = 0;
16798 std::size_t bytes_after_last_accept = 0;
16799 std::size_t undumped_chars = 0;
16801 for (std::size_t i = 0; i < s.size(); ++i)
16803 const auto byte =
static_cast<std::uint8_t
>(s[i]);
16805 switch (decode(state, codepoint,
byte))
16813 string_buffer[bytes++] =
'\\';
16814 string_buffer[bytes++] =
'b';
16820 string_buffer[bytes++] =
'\\';
16821 string_buffer[bytes++] =
't';
16827 string_buffer[bytes++] =
'\\';
16828 string_buffer[bytes++] =
'n';
16834 string_buffer[bytes++] =
'\\';
16835 string_buffer[bytes++] =
'f';
16841 string_buffer[bytes++] =
'\\';
16842 string_buffer[bytes++] =
'r';
16848 string_buffer[bytes++] =
'\\';
16849 string_buffer[bytes++] =
'\"';
16855 string_buffer[bytes++] =
'\\';
16856 string_buffer[bytes++] =
'\\';
16864 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16866 if (codepoint <= 0xFFFF)
16869 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
16870 static_cast<std::uint16_t
>(codepoint));
16876 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
16877 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
16878 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
16886 string_buffer[bytes++] = s[i];
16895 if (string_buffer.size() - bytes < 13)
16897 o->write_characters(string_buffer.data(), bytes);
16902 bytes_after_last_accept = bytes;
16903 undumped_chars = 0;
16909 switch (error_handler)
16911 case error_handler_t::strict:
16913 std::string sn(9,
'\0');
16915 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
16916 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn, BasicJsonType()));
16919 case error_handler_t::ignore:
16920 case error_handler_t::replace:
16926 if (undumped_chars > 0)
16933 bytes = bytes_after_last_accept;
16935 if (error_handler == error_handler_t::replace)
16940 string_buffer[bytes++] =
'\\';
16941 string_buffer[bytes++] =
'u';
16942 string_buffer[bytes++] =
'f';
16943 string_buffer[bytes++] =
'f';
16944 string_buffer[bytes++] =
'f';
16945 string_buffer[bytes++] =
'd';
16949 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
16950 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
16951 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
16957 if (string_buffer.size() - bytes < 13)
16959 o->write_characters(string_buffer.data(), bytes);
16963 bytes_after_last_accept = bytes;
16966 undumped_chars = 0;
16969 state = UTF8_ACCEPT;
16974 JSON_ASSERT(
false);
16984 string_buffer[bytes++] = s[i];
16993 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16998 o->write_characters(string_buffer.data(), bytes);
17004 switch (error_handler)
17006 case error_handler_t::strict:
17008 std::string sn(9,
'\0');
17010 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
17011 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
17014 case error_handler_t::ignore:
17017 o->write_characters(string_buffer.data(), bytes_after_last_accept);
17021 case error_handler_t::replace:
17024 o->write_characters(string_buffer.data(), bytes_after_last_accept);
17028 o->write_characters(
"\\ufffd", 6);
17032 o->write_characters(
"\xEF\xBF\xBD", 3);
17038 JSON_ASSERT(
false);
17052 inline unsigned int count_digits(number_unsigned_t x)
noexcept
17054 unsigned int n_digits = 1;
17063 return n_digits + 1;
17067 return n_digits + 2;
17071 return n_digits + 3;
17087 template <
typename NumberType, detail::enable_if_t <
17088 std::is_integral<NumberType>::value ||
17089 std::is_same<NumberType, number_unsigned_t>::value ||
17090 std::is_same<NumberType, number_integer_t>::value ||
17091 std::is_same<NumberType, binary_char_t>::value,
17093 void dump_integer(NumberType x)
17095 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
17098 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
17099 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
17100 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
17101 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
17102 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
17103 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
17104 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
17105 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
17106 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
17107 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
17114 o->write_character(
'0');
17119 auto buffer_ptr = number_buffer.begin();
17121 const bool is_negative = std::is_signed<NumberType>::value && !(x >= 0);
17122 number_unsigned_t abs_value;
17124 unsigned int n_chars{};
17129 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
17132 n_chars = 1 + count_digits(abs_value);
17136 abs_value =
static_cast<number_unsigned_t
>(x);
17137 n_chars = count_digits(abs_value);
17141 JSON_ASSERT(n_chars < number_buffer.size() - 1);
17145 buffer_ptr += n_chars;
17149 while (abs_value >= 100)
17151 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
17153 *(--buffer_ptr) = digits_to_99[digits_index][1];
17154 *(--buffer_ptr) = digits_to_99[digits_index][0];
17157 if (abs_value >= 10)
17159 const auto digits_index =
static_cast<unsigned>(abs_value);
17160 *(--buffer_ptr) = digits_to_99[digits_index][1];
17161 *(--buffer_ptr) = digits_to_99[digits_index][0];
17165 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
17168 o->write_characters(number_buffer.data(), n_chars);
17179 void dump_float(number_float_t x)
17182 if (!std::isfinite(x))
17184 o->write_characters(
"null", 4);
17193 static constexpr bool is_ieee_single_or_double
17194 = (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) ||
17195 (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);
17197 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
17200 void dump_float(number_float_t x, std::true_type )
17202 auto* begin = number_buffer.data();
17203 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
17205 o->write_characters(begin,
static_cast<size_t>(end - begin));
17208 void dump_float(number_float_t x, std::false_type )
17211 static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
17215 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
17218 JSON_ASSERT(len > 0);
17220 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
17223 if (thousands_sep !=
'\0')
17225 auto*
const end = std::remove(number_buffer.begin(),
17226 number_buffer.begin() + len, thousands_sep);
17227 std::fill(end, number_buffer.end(),
'\0');
17228 JSON_ASSERT((end - number_buffer.begin()) <= len);
17229 len = (end - number_buffer.begin());
17233 if (decimal_point !=
'\0' && decimal_point !=
'.')
17235 auto*
const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
17236 if (dec_pos != number_buffer.end())
17242 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
17245 const bool value_is_int_like =
17246 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
17249 return c ==
'.' || c ==
'e';
17252 if (value_is_int_like)
17254 o->write_characters(
".0", 2);
17279 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte)
noexcept
17281 static const std::array<std::uint8_t, 400> utf8d =
17284 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,
17285 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,
17286 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,
17287 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,
17288 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,
17289 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,
17290 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,
17291 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
17292 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
17293 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
17294 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,
17295 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,
17296 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,
17297 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
17301 JSON_ASSERT(
byte < utf8d.size());
17302 const std::uint8_t type = utf8d[byte];
17304 codep = (state != UTF8_ACCEPT)
17305 ? (
byte & 0x3fu) | (codep << 6u)
17306 : (0xFFu >> type) & (byte);
17308 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
17309 JSON_ASSERT(index < 400);
17310 state = utf8d[index];
17319 number_unsigned_t remove_sign(number_unsigned_t x)
17321 JSON_ASSERT(
false);
17334 inline number_unsigned_t remove_sign(number_integer_t x)
noexcept
17336 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
17337 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
17342 output_adapter_t<char> o =
nullptr;
17345 std::array<char, 64> number_buffer{{}};
17348 const std::lconv* loc =
nullptr;
17350 const char thousands_sep =
'\0';
17352 const char decimal_point =
'\0';
17355 std::array<char, 512> string_buffer{{}};
17358 const char indent_char;
17360 string_t indent_string;
17363 const error_handler_t error_handler;
17375#include <functional>
17376#include <initializer_list>
17379#include <stdexcept>
17380#include <type_traits>
17392template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
17393 class Allocator = std::allocator<std::pair<const Key, T>>>
17398 using Container = std::vector<std::pair<const Key, T>, Allocator>;
17399 using typename Container::iterator;
17400 using typename Container::const_iterator;
17401 using typename Container::size_type;
17402 using typename Container::value_type;
17407 template <
class It>
17410 ordered_map(std::initializer_list<T> init,
const Allocator& alloc = Allocator() )
17415 for (
auto it = this->begin(); it != this->end(); ++it)
17417 if (it->first == key)
17419 return {it,
false};
17422 Container::emplace_back(key, t);
17423 return {--this->end(),
true};
17428 return emplace(key, T{}).first->second;
17438 for (
auto it = this->begin(); it != this->end(); ++it)
17440 if (it->first == key)
17446 JSON_THROW(std::out_of_range(
"key not found"));
17449 const T&
at(
const Key& key)
const
17451 for (
auto it = this->begin(); it != this->end(); ++it)
17453 if (it->first == key)
17459 JSON_THROW(std::out_of_range(
"key not found"));
17464 for (
auto it = this->begin(); it != this->end(); ++it)
17466 if (it->first == key)
17469 for (
auto next = it; ++next != this->end(); ++it)
17472 new (&*it) value_type{std::move(*next)};
17474 Container::pop_back();
17486 for (
auto next = it; ++next != this->end(); ++it)
17489 new (&*it) value_type{std::move(*next)};
17491 Container::pop_back();
17497 for (
auto it = this->begin(); it != this->end(); ++it)
17499 if (it->first == key)
17509 for (
auto it = this->begin(); it != this->end(); ++it)
17511 if (it->first == key)
17516 return Container::end();
17519 const_iterator
find(
const Key& key)
const
17521 for (
auto it = this->begin(); it != this->end(); ++it)
17523 if (it->first == key)
17528 return Container::end();
17531 std::pair<iterator, bool>
insert( value_type&& value )
17533 return emplace(value.first, std::move(value.second));
17536 std::pair<iterator, bool>
insert(
const value_type& value )
17538 for (
auto it = this->begin(); it != this->end(); ++it)
17540 if (it->first == value.first)
17542 return {it,
false};
17545 Container::push_back(value);
17546 return {--this->end(),
true};
17549 template<
typename InputIt>
17550 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
17551 std::input_iterator_tag>::value>::type;
17553 template<
typename InputIt,
typename = require_input_iter<InputIt>>
17556 for (
auto it = first; it != last; ++it)
17566#if defined(JSON_HAS_CPP_17)
17567 #include <string_view>
17662NLOHMANN_BASIC_JSON_TPL_DECLARATION
17667 friend ::nlohmann::json_pointer<basic_json>;
17669 template<
typename BasicJsonType,
typename InputType>
17670 friend class ::nlohmann::detail::parser;
17671 friend ::nlohmann::detail::serializer<basic_json>;
17672 template<
typename BasicJsonType>
17673 friend class ::nlohmann::detail::iter_impl;
17674 template<
typename BasicJsonType,
typename CharType>
17675 friend class ::nlohmann::detail::binary_writer;
17676 template<
typename BasicJsonType,
typename InputType,
typename SAX>
17677 friend class ::nlohmann::detail::binary_reader;
17678 template<
typename BasicJsonType>
17679 friend class ::nlohmann::detail::json_sax_dom_parser;
17680 template<
typename BasicJsonType>
17681 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17682 friend class ::nlohmann::detail::exception;
17685 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
17687 JSON_PRIVATE_UNLESS_TESTED:
17689 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
17691 template<
typename InputAdapterType>
17692 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17693 InputAdapterType adapter,
17694 detail::parser_callback_t<basic_json>cb =
nullptr,
17695 const bool allow_exceptions =
true,
17696 const bool ignore_comments =
false
17699 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17700 std::move(cb), allow_exceptions, ignore_comments);
17704 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
17705 template<
typename BasicJsonType>
17706 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
17707 template<
typename BasicJsonType>
17708 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
17709 template<
typename Iterator>
17710 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
17711 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
17713 template<
typename CharType>
17714 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
17716 template<
typename InputType>
17717 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
17718 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
17720 JSON_PRIVATE_UNLESS_TESTED:
17721 using serializer = ::nlohmann::detail::serializer<basic_json>;
17724 using value_t = detail::value_t;
17727 template<
typename T,
typename SFINAE>
17730 using error_handler_t = detail::error_handler_t;
17732 using cbor_tag_handler_t = detail::cbor_tag_handler_t;
17736 using input_format_t = detail::input_format_t;
17790 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
17792 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
17845 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
17846 result[
"name"] =
"JSON for Modern C++";
17847 result[
"url"] =
"https://github.com/nlohmann/json";
17848 result[
"version"][
"string"] =
17849 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
17850 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
17851 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
17852 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
17853 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
17854 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
17857 result[
"platform"] =
"win32";
17858#elif defined __linux__
17859 result[
"platform"] =
"linux";
17860#elif defined __APPLE__
17861 result[
"platform"] =
"apple";
17862#elif defined __unix__
17863 result[
"platform"] =
"unix";
17865 result[
"platform"] =
"unknown";
17868#if defined(__ICC) || defined(__INTEL_COMPILER)
17869 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
17870#elif defined(__clang__)
17871 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
17872#elif defined(__GNUC__) || defined(__GNUG__)
17873 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
17874#elif defined(__HP_cc) || defined(__HP_aCC)
17875 result[
"compiler"] =
"hp"
17876#elif defined(__IBMCPP__)
17877 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
17878#elif defined(_MSC_VER)
17879 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
17880#elif defined(__PGI)
17881 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
17882#elif defined(__SUNPRO_CC)
17883 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
17885 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
17889 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
17891 result[
"compiler"][
"c++"] =
"unknown";
17906#if defined(JSON_HAS_CPP_14)
18000 AllocatorType<std::pair<
const StringType,
18047 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
18414 template<
typename T,
typename... Args>
18416 static T* create(Args&& ... args)
18418 AllocatorType<T> alloc;
18419 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
18421 auto deleter = [&](T * obj)
18423 AllocatorTraits::deallocate(alloc, obj, 1);
18425 std::unique_ptr<T,
decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
18426 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
18427 JSON_ASSERT(obj !=
nullptr);
18428 return obj.release();
18435 JSON_PRIVATE_UNLESS_TESTED:
18481 json_value() =
default;
18483 json_value(
boolean_t v) noexcept : boolean(v) {}
18495 case value_t::object:
18497 object = create<object_t>();
18501 case value_t::array:
18503 array = create<array_t>();
18507 case value_t::string:
18509 string = create<string_t>(
"");
18513 case value_t::binary:
18515 binary = create<binary_t>();
18519 case value_t::boolean:
18525 case value_t::number_integer:
18531 case value_t::number_unsigned:
18537 case value_t::number_float:
18543 case value_t::null:
18549 case value_t::discarded:
18553 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
18555 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.10.3",
basic_json()));
18565 string = create<string_t>(
value);
18571 string = create<string_t>(std::move(
value));
18577 object = create<object_t>(
value);
18583 object = create<object_t>(std::move(
value));
18589 array = create<array_t>(
value);
18595 array = create<array_t>(std::move(
value));
18601 binary = create<binary_t>(
value);
18607 binary = create<binary_t>(std::move(
value));
18613 binary = create<binary_t>(
value);
18619 binary = create<binary_t>(std::move(
value));
18624 if (t == value_t::array || t == value_t::object)
18627 std::vector<basic_json> stack;
18630 if (t == value_t::array)
18632 stack.reserve(array->size());
18633 std::move(array->begin(), array->end(), std::back_inserter(stack));
18638 for (
auto&& it : *
object)
18640 stack.push_back(std::move(it.second));
18644 while (!stack.empty())
18647 basic_json current_item(std::move(stack.back()));
18652 if (current_item.is_array())
18654 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
18656 current_item.m_value.array->clear();
18658 else if (current_item.is_object())
18660 for (
auto&& it : *current_item.m_value.object)
18662 stack.push_back(std::move(it.second));
18665 current_item.m_value.object->clear();
18675 case value_t::object:
18677 AllocatorType<object_t> alloc;
18678 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
object);
18679 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
object, 1);
18683 case value_t::array:
18685 AllocatorType<array_t> alloc;
18686 std::allocator_traits<
decltype(alloc)>::destroy(alloc, array);
18687 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, array, 1);
18691 case value_t::string:
18693 AllocatorType<string_t> alloc;
18694 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
string);
18695 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
string, 1);
18699 case value_t::binary:
18701 AllocatorType<binary_t> alloc;
18702 std::allocator_traits<
decltype(alloc)>::destroy(alloc, binary);
18703 std::allocator_traits<
decltype(alloc)>::deallocate(alloc, binary, 1);
18707 case value_t::null:
18708 case value_t::boolean:
18709 case value_t::number_integer:
18710 case value_t::number_unsigned:
18711 case value_t::number_float:
18712 case value_t::discarded:
18740 void assert_invariant(
bool check_parents =
true) const noexcept
18742 JSON_ASSERT(m_type != value_t::object ||
m_value.object !=
nullptr);
18743 JSON_ASSERT(m_type != value_t::array ||
m_value.array !=
nullptr);
18744 JSON_ASSERT(m_type != value_t::string ||
m_value.string !=
nullptr);
18745 JSON_ASSERT(m_type != value_t::binary ||
m_value.binary !=
nullptr);
18747#if JSON_DIAGNOSTICS
18753 return j.m_parent ==
this;
18758 static_cast<void>(check_parents);
18763#if JSON_DIAGNOSTICS
18766 case value_t::array:
18768 for (
auto& element : *
m_value.array)
18770 element.m_parent =
this;
18775 case value_t::object:
18777 for (
auto& element : *
m_value.object)
18779 element.second.m_parent =
this;
18784 case value_t::null:
18785 case value_t::string:
18786 case value_t::boolean:
18787 case value_t::number_integer:
18788 case value_t::number_unsigned:
18789 case value_t::number_float:
18790 case value_t::binary:
18791 case value_t::discarded:
18800#if JSON_DIAGNOSTICS
18801 for (
typename iterator::difference_type i = 0; i <
count; ++i)
18803 (it + i)->m_parent =
this;
18806 static_cast<void>(
count);
18813#if JSON_DIAGNOSTICS
18814 if (old_capacity != std::size_t(-1))
18817 JSON_ASSERT(
type() == value_t::array);
18818 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
18828#ifdef JSON_HEDLEY_MSVC_VERSION
18829#pragma warning(push )
18830#pragma warning(disable : 4127)
18832 if (detail::is_ordered_map<object_t>::value)
18837#ifdef JSON_HEDLEY_MSVC_VERSION
18838#pragma warning( pop )
18843 static_cast<void>(j);
18844 static_cast<void>(old_capacity);
18869 using parse_event_t = detail::parse_event_t;
18964 assert_invariant();
18988 assert_invariant();
19053 template <
typename CompatibleType,
19054 typename U = detail::uncvref_t<CompatibleType>,
19055 detail::enable_if_t <
19056 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
19058 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
19059 std::forward<CompatibleType>(val))))
19061 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
19063 assert_invariant();
19092 template <
typename BasicJsonType,
19093 detail::enable_if_t <
19094 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
19097 using other_boolean_t =
typename BasicJsonType::boolean_t;
19098 using other_number_float_t =
typename BasicJsonType::number_float_t;
19099 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
19100 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
19101 using other_string_t =
typename BasicJsonType::string_t;
19102 using other_object_t =
typename BasicJsonType::object_t;
19103 using other_array_t =
typename BasicJsonType::array_t;
19104 using other_binary_t =
typename BasicJsonType::binary_t;
19106 switch (val.type())
19108 case value_t::boolean:
19109 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
19111 case value_t::number_float:
19112 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
19114 case value_t::number_integer:
19115 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
19117 case value_t::number_unsigned:
19118 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
19120 case value_t::string:
19121 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
19123 case value_t::object:
19124 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
19126 case value_t::array:
19127 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
19129 case value_t::binary:
19130 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
19132 case value_t::null:
19135 case value_t::discarded:
19136 m_type = value_t::discarded;
19139 JSON_ASSERT(
false);
19142 assert_invariant();
19220 bool type_deduction =
true,
19221 value_t manual_type = value_t::array)
19225 bool is_an_object = std::all_of(init.begin(), init.end(),
19226 [](
const detail::json_ref<basic_json>& element_ref)
19228 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
19232 if (!type_deduction)
19235 if (manual_type == value_t::array)
19237 is_an_object =
false;
19241 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
19243 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
19250 m_type = value_t::object;
19253 for (
auto& element_ref : init)
19255 auto element = element_ref.moved_or_copied();
19257 std::move(*((*element.m_value.array)[0].m_value.string)),
19258 std::move((*element.m_value.array)[1]));
19264 m_type = value_t::array;
19265 m_value.array = create<array_t>(init.begin(), init.end());
19269 assert_invariant();
19303 res.m_type = value_t::binary;
19304 res.m_value = init;
19340 res.m_type = value_t::binary;
19341 res.m_value =
binary_t(init, subtype);
19350 res.m_type = value_t::binary;
19351 res.m_value = std::move(init);
19360 res.m_type = value_t::binary;
19361 res.m_value =
binary_t(std::move(init), subtype);
19405 return basic_json(init,
false, value_t::array);
19449 return basic_json(init,
false, value_t::object);
19475 : m_type(value_t::array)
19477 m_value.array = create<array_t>(cnt, val);
19479 assert_invariant();
19537 template <
class InputIT,
typename std::enable_if <
19538 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
19539 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
19542 JSON_ASSERT(first.m_object !=
nullptr);
19543 JSON_ASSERT(last.m_object !=
nullptr);
19546 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19548 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
19552 m_type = first.m_object->m_type;
19557 case value_t::boolean:
19558 case value_t::number_float:
19559 case value_t::number_integer:
19560 case value_t::number_unsigned:
19561 case value_t::string:
19563 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
19564 || !last.m_it.primitive_iterator.is_end()))
19566 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
19571 case value_t::null:
19572 case value_t::object:
19573 case value_t::array:
19574 case value_t::binary:
19575 case value_t::discarded:
19582 case value_t::number_integer:
19584 m_value.number_integer = first.m_object->m_value.number_integer;
19588 case value_t::number_unsigned:
19590 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
19594 case value_t::number_float:
19596 m_value.number_float = first.m_object->m_value.number_float;
19600 case value_t::boolean:
19602 m_value.boolean = first.m_object->m_value.boolean;
19606 case value_t::string:
19608 m_value = *first.m_object->m_value.string;
19612 case value_t::object:
19614 m_value.object = create<object_t>(first.m_it.object_iterator,
19615 last.m_it.object_iterator);
19619 case value_t::array:
19621 m_value.array = create<array_t>(first.m_it.array_iterator,
19622 last.m_it.array_iterator);
19626 case value_t::binary:
19628 m_value = *first.m_object->m_value.binary;
19632 case value_t::null:
19633 case value_t::discarded:
19635 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
19639 assert_invariant();
19647 template<
typename JsonRef,
19648 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
19649 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
19678 : m_type(other.m_type)
19681 other.assert_invariant();
19685 case value_t::object:
19691 case value_t::array:
19697 case value_t::string:
19703 case value_t::boolean:
19709 case value_t::number_integer:
19715 case value_t::number_unsigned:
19721 case value_t::number_float:
19727 case value_t::binary:
19733 case value_t::null:
19734 case value_t::discarded:
19740 assert_invariant();
19770 : m_type(std::move(other.m_type)),
19771 m_value(std::move(other.m_value))
19774 other.assert_invariant(
false);
19777 other.m_type = value_t::null;
19778 other.m_value = {};
19781 assert_invariant();
19808 std::is_nothrow_move_constructible<value_t>::value&&
19809 std::is_nothrow_move_assignable<value_t>::value&&
19810 std::is_nothrow_move_constructible<json_value>::value&&
19811 std::is_nothrow_move_assignable<json_value>::value
19815 other.assert_invariant();
19818 swap(m_type, other.m_type);
19822 assert_invariant();
19843 assert_invariant(
false);
19906 const char indent_char =
' ',
19907 const bool ensure_ascii =
false,
19908 const error_handler_t error_handler = error_handler_t::strict)
const
19911 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19915 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
19919 s.dump(*
this,
false, ensure_ascii, 0);
19958 constexpr value_t
type() const noexcept
20040 return m_type == value_t::null;
20062 return m_type == value_t::boolean;
20121 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
20149 return m_type == value_t::number_unsigned;
20177 return m_type == value_t::number_float;
20199 return m_type == value_t::object;
20221 return m_type == value_t::array;
20243 return m_type == value_t::string;
20265 return m_type == value_t::binary;
20292 return m_type == value_t::discarded;
20336 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
20358 constexpr const array_t* get_impl_ptr(
const array_t* )
const noexcept
20446 template<
typename ReferenceType,
typename ThisType>
20447 static ReferenceType get_ref_impl(ThisType& obj)
20450 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20452 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20457 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
20491 template<
typename PointerType,
typename std::enable_if<
20492 std::is_pointer<PointerType>::value,
int>
::type = 0>
20493 auto get_ptr() noexcept -> decltype(
std::declval<basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20496 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20503 template <
typename PointerType,
typename std::enable_if <
20504 std::is_pointer<PointerType>::value&&
20505 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
20506 constexpr auto get_ptr() const noexcept -> decltype(
std::declval<const basic_json_t&>().get_impl_ptr(
std::declval<PointerType>()))
20509 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20551 template <
typename ValueType,
20552 detail::enable_if_t <
20553 detail::is_default_constructible<ValueType>::value&&
20554 detail::has_from_json<basic_json_t, ValueType>::value,
20556 ValueType get_impl(detail::priority_tag<0> )
const noexcept(
noexcept(
20557 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20560 JSONSerializer<ValueType>::from_json(*
this, ret);
20594 template <
typename ValueType,
20595 detail::enable_if_t <
20596 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
20598 ValueType get_impl(detail::priority_tag<1> )
const noexcept(
noexcept(
20599 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20601 return JSONSerializer<ValueType>::from_json(*
this);
20619 template <
typename BasicJsonType,
20620 detail::enable_if_t <
20621 detail::is_basic_json<BasicJsonType>::value,
20623 BasicJsonType get_impl(detail::priority_tag<2> )
const
20642 template<
typename BasicJsonType,
20643 detail::enable_if_t<
20644 std::is_same<BasicJsonType, basic_json_t>::value,
20646 basic_json get_impl(detail::priority_tag<3> )
const
20655 template<
typename PointerType,
20656 detail::enable_if_t<
20657 std::is_pointer<PointerType>::value,
20659 constexpr auto get_impl(detail::priority_tag<4> )
const noexcept
20660 ->
decltype(std::declval<const basic_json_t&>().template get_ptr<PointerType>())
20663 return get_ptr<PointerType>();
20690 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20691#if defined(JSON_HAS_CPP_14)
20695 noexcept(
std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
20696 ->
decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
20701 static_assert(!std::is_reference<ValueTypeCV>::value,
20702 "get() cannot be used with reference types, you might want to use get_ref()");
20703 return get_impl<ValueType>(detail::priority_tag<4> {});
20733 template<
typename PointerType,
typename std::enable_if<
20734 std::is_pointer<PointerType>::value,
int>
::type = 0>
20735 auto get() noexcept -> decltype(
std::declval<basic_json_t&>().template
get_ptr<PointerType>())
20738 return get_ptr<PointerType>();
20774 template <
typename ValueType,
20775 detail::enable_if_t <
20776 !detail::is_basic_json<ValueType>::value&&
20777 detail::has_from_json<basic_json_t, ValueType>::value,
20779 ValueType &
get_to(ValueType& v)
const noexcept(
noexcept(
20780 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
20782 JSONSerializer<ValueType>::from_json(*
this, v);
20788 template<
typename ValueType,
20789 detail::enable_if_t <
20790 detail::is_basic_json<ValueType>::value,
20799 typename T, std::size_t N,
20800 typename Array = T (&)[N],
20801 detail::enable_if_t <
20802 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
20804 noexcept(
noexcept(JSONSerializer<Array>::from_json(
20805 std::declval<const basic_json_t&>(), v)))
20807 JSONSerializer<Array>::from_json(*
this, v);
20837 template<
typename ReferenceType,
typename std::enable_if<
20838 std::is_reference<ReferenceType>::value,
int>
::type = 0>
20842 return get_ref_impl<ReferenceType>(*
this);
20849 template <
typename ReferenceType,
typename std::enable_if <
20850 std::is_reference<ReferenceType>::value&&
20851 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
20855 return get_ref_impl<ReferenceType>(*
this);
20887 template <
typename ValueType,
typename std::enable_if <
20888 detail::conjunction <
20889 detail::negation<std::is_pointer<ValueType>>,
20890 detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
20891 detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
20892 detail::negation<detail::is_basic_json<ValueType>>,
20893 detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
20895#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20896 detail::negation<std::is_same<ValueType, std::string_view>>,
20898 detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
20900 JSON_EXPLICIT
operator ValueType()
const
20903 return get<ValueType>();
20919 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20922 return *get_ptr<binary_t*>();
20930 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20933 return *get_ptr<const binary_t*>();
20976 if (JSON_HEDLEY_LIKELY(
is_array()))
20980 return set_parent(
m_value.array->at(idx));
20982 JSON_CATCH (std::out_of_range&)
20985 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20990 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21023 if (JSON_HEDLEY_LIKELY(
is_array()))
21027 return m_value.array->at(idx);
21029 JSON_CATCH (std::out_of_range&)
21032 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21037 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21071 reference at(
const typename object_t::key_type& key)
21078 return set_parent(
m_value.object->at(key));
21080 JSON_CATCH (std::out_of_range&)
21083 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21088 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21129 return m_value.object->at(key);
21131 JSON_CATCH (std::out_of_range&)
21134 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21139 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21173 m_type = value_t::array;
21174 m_value.array = create<array_t>();
21175 assert_invariant();
21179 if (JSON_HEDLEY_LIKELY(
is_array()))
21182 if (idx >=
m_value.array->size())
21184#if JSON_DIAGNOSTICS
21186 const auto old_size =
m_value.array->size();
21187 const auto old_capacity =
m_value.array->capacity();
21189 m_value.array->resize(idx + 1);
21191#if JSON_DIAGNOSTICS
21192 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
21200 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(old_size),
static_cast<typename iterator::difference_type
>(idx + 1 - old_size));
21203 assert_invariant();
21206 return m_value.array->operator[](idx);
21209 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21234 if (JSON_HEDLEY_LIKELY(
is_array()))
21236 return m_value.array->operator[](idx);
21239 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21274 m_type = value_t::object;
21275 m_value.object = create<object_t>();
21276 assert_invariant();
21282 return set_parent(
m_value.object->operator[](key));
21285 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21323 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
21324 return m_value.object->find(key)->second;
21327 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21357 template<
typename T>
21358 JSON_HEDLEY_NON_NULL(2)
21364 m_type = value_t::object;
21366 assert_invariant();
21372 return set_parent(
m_value.object->operator[](key));
21375 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21408 template<
typename T>
21409 JSON_HEDLEY_NON_NULL(2)
21415 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
21416 return m_value.object->find(key)->second;
21419 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21473 template <
class ValueType,
typename std::enable_if <
21474 detail::is_getable<basic_json_t, ValueType>::value
21475 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
21476 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
21482 const auto it =
find(key);
21485 return it->template get<ValueType>();
21488 return default_value;
21491 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21498 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
21546 template<
class ValueType,
typename std::enable_if<
21547 detail::is_getable<basic_json_t, ValueType>::value,
int>
::type = 0>
21556 return ptr.get_checked(
this).template get<ValueType>();
21560 return default_value;
21564 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21571 JSON_HEDLEY_NON_NULL(3)
21709 template <
class IteratorType,
typename std::enable_if <
21710 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21711 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21713 IteratorType
erase(IteratorType pos)
21716 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21718 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
21721 IteratorType result =
end();
21725 case value_t::boolean:
21726 case value_t::number_float:
21727 case value_t::number_integer:
21728 case value_t::number_unsigned:
21729 case value_t::string:
21730 case value_t::binary:
21732 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21734 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
21739 AllocatorType<string_t> alloc;
21740 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.string);
21741 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21746 AllocatorType<binary_t> alloc;
21747 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.binary);
21748 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21752 m_type = value_t::null;
21753 assert_invariant();
21757 case value_t::object:
21759 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
21763 case value_t::array:
21765 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
21769 case value_t::null:
21770 case value_t::discarded:
21772 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21824 template <
class IteratorType,
typename std::enable_if <
21825 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21826 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21828 IteratorType
erase(IteratorType first, IteratorType last)
21831 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21833 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
21836 IteratorType result =
end();
21840 case value_t::boolean:
21841 case value_t::number_float:
21842 case value_t::number_integer:
21843 case value_t::number_unsigned:
21844 case value_t::string:
21845 case value_t::binary:
21847 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21848 || !last.m_it.primitive_iterator.is_end()))
21850 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
21855 AllocatorType<string_t> alloc;
21856 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.string);
21857 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21862 AllocatorType<binary_t> alloc;
21863 std::allocator_traits<
decltype(alloc)>::destroy(alloc,
m_value.binary);
21864 std::allocator_traits<
decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21868 m_type = value_t::null;
21869 assert_invariant();
21873 case value_t::object:
21875 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
21876 last.m_it.object_iterator);
21880 case value_t::array:
21882 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
21883 last.m_it.array_iterator);
21887 case value_t::null:
21888 case value_t::discarded:
21890 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21930 return m_value.object->erase(key);
21933 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21963 if (JSON_HEDLEY_LIKELY(
is_array()))
21965 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
21967 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21974 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22012 template<
typename KeyT>
22015 auto result =
end();
22019 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
22029 template<
typename KeyT>
22032 auto result =
cend();
22036 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
22063 template<
typename KeyT>
22095 template <
typename KeyT,
typename std::enable_if <
22130 return ptr.contains(
this);
22170 result.set_begin();
22210 result.set_begin();
22474 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22477 return ref.items();
22483 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22486 return ref.items();
22557 iteration_proxy<iterator>
items() noexcept
22559 return iteration_proxy<iterator>(*
this);
22565 iteration_proxy<const_iterator>
items() const noexcept
22567 return iteration_proxy<const_iterator>(*
this);
22622 bool empty() const noexcept
22626 case value_t::null:
22632 case value_t::array:
22635 return m_value.array->empty();
22638 case value_t::object:
22641 return m_value.object->empty();
22644 case value_t::string:
22645 case value_t::boolean:
22646 case value_t::number_integer:
22647 case value_t::number_unsigned:
22648 case value_t::number_float:
22649 case value_t::binary:
22650 case value_t::discarded:
22706 case value_t::null:
22712 case value_t::array:
22715 return m_value.array->size();
22718 case value_t::object:
22721 return m_value.object->size();
22724 case value_t::string:
22725 case value_t::boolean:
22726 case value_t::number_integer:
22727 case value_t::number_unsigned:
22728 case value_t::number_float:
22729 case value_t::binary:
22730 case value_t::discarded:
22784 case value_t::array:
22787 return m_value.array->max_size();
22790 case value_t::object:
22793 return m_value.object->max_size();
22796 case value_t::null:
22797 case value_t::string:
22798 case value_t::boolean:
22799 case value_t::number_integer:
22800 case value_t::number_unsigned:
22801 case value_t::number_float:
22802 case value_t::binary:
22803 case value_t::discarded:
22859 void clear() noexcept
22863 case value_t::number_integer:
22869 case value_t::number_unsigned:
22875 case value_t::number_float:
22881 case value_t::boolean:
22887 case value_t::string:
22893 case value_t::binary:
22899 case value_t::array:
22905 case value_t::object:
22911 case value_t::null:
22912 case value_t::discarded:
22943 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22949 m_type = value_t::array;
22951 assert_invariant();
22955 const auto old_capacity =
m_value.array->capacity();
22956 m_value.array->push_back(std::move(val));
22957 set_parent(
m_value.array->back(), old_capacity);
22980 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22986 m_type = value_t::array;
22988 assert_invariant();
22992 const auto old_capacity =
m_value.array->capacity();
22993 m_value.array->push_back(val);
22994 set_parent(
m_value.array->back(), old_capacity);
23027 void push_back(
const typename object_t::value_type& val)
23032 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
23038 m_type = value_t::object;
23040 assert_invariant();
23044 auto res =
m_value.object->insert(val);
23045 set_parent(res.first->second);
23085 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
23087 basic_json&& key = init.begin()->moved_or_copied();
23088 push_back(
typename object_t::value_type(
23089 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
23130 template<
class... Args>
23136 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
23142 m_type = value_t::array;
23144 assert_invariant();
23148 const auto old_capacity =
m_value.array->capacity();
23149 m_value.array->emplace_back(std::forward<Args>(args)...);
23150 return set_parent(
m_value.array->back(), old_capacity);
23180 template<
class... Args>
23181 std::pair<iterator, bool>
emplace(Args&& ... args)
23186 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
23192 m_type = value_t::object;
23194 assert_invariant();
23198 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
23199 set_parent(res.first->second);
23203 it.m_it.object_iterator = res.first;
23206 return {it, res.second};
23212 template<
typename... Args>
23216 JSON_ASSERT(
m_value.array !=
nullptr);
23218 auto insert_pos = std::distance(
m_value.array->begin(), pos.m_it.array_iterator);
23219 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
23220 result.m_it.array_iterator =
m_value.array->begin() + insert_pos;
23255 if (JSON_HEDLEY_LIKELY(
is_array()))
23258 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23260 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23267 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23276 return insert(pos, val);
23306 if (JSON_HEDLEY_LIKELY(
is_array()))
23309 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23311 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23318 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23354 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23356 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23360 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23362 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23366 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23368 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23371 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23373 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
23377 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
23407 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23409 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23413 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23415 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23448 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23450 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23454 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23456 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23460 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23462 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23465 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23492 m_type = value_t::object;
23493 m_value.object = create<object_t>();
23494 assert_invariant();
23499 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23501 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
23503 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name()), *
this));
23506 for (
auto it = j.cbegin(); it != j.cend(); ++it)
23508 m_value.object->operator[](it.key()) = it.value();
23509#if JSON_DIAGNOSTICS
23510 m_value.object->operator[](it.key()).m_parent =
this;
23546 m_type = value_t::object;
23547 m_value.object = create<object_t>();
23548 assert_invariant();
23553 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23557 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23559 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23563 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
23564 || !last.m_object->is_object()))
23566 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23569 for (
auto it = first; it != last; ++it)
23571 m_value.object->operator[](it.key()) = it.value();
23572#if JSON_DIAGNOSTICS
23573 m_value.object->operator[](it.key()).m_parent =
this;
23596 std::is_nothrow_move_constructible<value_t>::value&&
23597 std::is_nothrow_move_assignable<value_t>::value&&
23598 std::is_nothrow_move_constructible<json_value>::value&&
23599 std::is_nothrow_move_assignable<json_value>::value
23602 std::swap(m_type, other.m_type);
23603 std::swap(
m_value, other.m_value);
23606 other.set_parents();
23607 assert_invariant();
23629 std::is_nothrow_move_constructible<value_t>::value&&
23630 std::is_nothrow_move_assignable<value_t>::value&&
23631 std::is_nothrow_move_constructible<json_value>::value&&
23632 std::is_nothrow_move_assignable<json_value>::value
23661 if (JSON_HEDLEY_LIKELY(
is_array()))
23663 std::swap(*(
m_value.array), other);
23667 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23696 std::swap(*(
m_value.object), other);
23700 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23729 std::swap(*(
m_value.string), other);
23733 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23762 std::swap(*(
m_value.binary), other);
23766 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23776 std::swap(*(
m_value.binary), other);
23780 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23852#pragma GCC diagnostic push
23853#pragma GCC diagnostic ignored "-Wfloat-equal"
23855 const auto lhs_type = lhs.type();
23856 const auto rhs_type = rhs.type();
23858 if (lhs_type == rhs_type)
23862 case value_t::array:
23863 return *lhs.m_value.array == *rhs.m_value.array;
23865 case value_t::object:
23866 return *lhs.m_value.object == *rhs.m_value.object;
23868 case value_t::null:
23871 case value_t::string:
23872 return *lhs.m_value.string == *rhs.m_value.string;
23874 case value_t::boolean:
23875 return lhs.m_value.boolean == rhs.m_value.boolean;
23877 case value_t::number_integer:
23878 return lhs.m_value.number_integer == rhs.m_value.number_integer;
23880 case value_t::number_unsigned:
23881 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23883 case value_t::number_float:
23884 return lhs.m_value.number_float == rhs.m_value.number_float;
23886 case value_t::binary:
23887 return *lhs.m_value.binary == *rhs.m_value.binary;
23889 case value_t::discarded:
23894 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23896 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23898 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23900 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
23902 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23904 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23906 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23908 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23910 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23912 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23914 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23916 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23921#pragma GCC diagnostic pop
23929 template<
typename ScalarType,
typename std::enable_if<
23930 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23940 template<
typename ScalarType,
typename std::enable_if<
23941 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23967 return !(lhs == rhs);
23974 template<
typename ScalarType,
typename std::enable_if<
23975 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23985 template<
typename ScalarType,
typename std::enable_if<
23986 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24020 const auto lhs_type = lhs.type();
24021 const auto rhs_type = rhs.type();
24023 if (lhs_type == rhs_type)
24027 case value_t::array:
24030 return (*lhs.m_value.array) < (*rhs.m_value.array);
24032 case value_t::object:
24033 return (*lhs.m_value.object) < (*rhs.m_value.object);
24035 case value_t::null:
24038 case value_t::string:
24039 return (*lhs.m_value.string) < (*rhs.m_value.string);
24041 case value_t::boolean:
24042 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
24044 case value_t::number_integer:
24045 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
24047 case value_t::number_unsigned:
24048 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
24050 case value_t::number_float:
24051 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
24053 case value_t::binary:
24054 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
24056 case value_t::discarded:
24061 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
24063 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
24065 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
24067 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
24069 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
24071 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
24073 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
24075 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
24077 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
24079 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
24081 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
24083 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
24096 template<
typename ScalarType,
typename std::enable_if<
24097 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24107 template<
typename ScalarType,
typename std::enable_if<
24108 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24135 return !(rhs < lhs);
24142 template<
typename ScalarType,
typename std::enable_if<
24143 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24153 template<
typename ScalarType,
typename std::enable_if<
24154 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24181 return !(lhs <= rhs);
24188 template<
typename ScalarType,
typename std::enable_if<
24189 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24199 template<
typename ScalarType,
typename std::enable_if<
24200 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24227 return !(lhs < rhs);
24234 template<
typename ScalarType,
typename std::enable_if<
24235 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24245 template<
typename ScalarType,
typename std::enable_if<
24246 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24295 const bool pretty_print = o.width() > 0;
24296 const auto indentation = pretty_print ? o.width() : 0;
24302 serializer s(detail::output_adapter<char>(o), o.fill());
24303 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24315 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
24382 template<
typename InputType>
24386 const bool allow_exceptions =
true,
24387 const bool ignore_comments =
false)
24390 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24420 template<
typename IteratorType>
24425 const bool allow_exceptions =
true,
24426 const bool ignore_comments =
false)
24429 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24434 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
24437 const bool allow_exceptions =
true,
24438 const bool ignore_comments =
false)
24441 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
24475 template<
typename InputType>
24476 static bool accept(InputType&& i,
24477 const bool ignore_comments =
false)
24479 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
24482 template<
typename IteratorType>
24483 static bool accept(IteratorType first, IteratorType last,
24484 const bool ignore_comments =
false)
24486 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
24490 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
24491 static bool accept(detail::span_input_adapter&& i,
24492 const bool ignore_comments =
false)
24494 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
24537 template <
typename InputType,
typename SAX>
24538 JSON_HEDLEY_NON_NULL(2)
24539 static
bool sax_parse(InputType&& i, SAX* sax,
24541 const
bool strict = true,
24542 const
bool ignore_comments = false)
24544 auto ia = detail::input_adapter(std::forward<InputType>(i));
24545 return format == input_format_t::json
24546 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24547 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24550 template<
class IteratorType,
class SAX>
24551 JSON_HEDLEY_NON_NULL(3)
24552 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24553 input_format_t format = input_format_t::
json,
24554 const
bool strict = true,
24555 const
bool ignore_comments = false)
24557 auto ia = detail::input_adapter(std::move(first), std::move(last));
24558 return format == input_format_t::json
24559 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24560 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24563 template <
typename SAX>
24564 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
24565 JSON_HEDLEY_NON_NULL(2)
24566 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
24567 input_format_t format = input_format_t::
json,
24568 const
bool strict = true,
24569 const
bool ignore_comments = false)
24572 return format == input_format_t::json
24574 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24576 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24587 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24620 parser(detail::input_adapter(i)).parse(
false, j);
24667 case value_t::null:
24669 case value_t::object:
24671 case value_t::array:
24673 case value_t::string:
24675 case value_t::boolean:
24677 case value_t::binary:
24679 case value_t::discarded:
24680 return "discarded";
24681 case value_t::number_integer:
24682 case value_t::number_unsigned:
24683 case value_t::number_float:
24691 JSON_PRIVATE_UNLESS_TESTED:
24697 value_t m_type = value_t::null;
24702#if JSON_DIAGNOSTICS
24815 std::vector<std::uint8_t> result;
24820 static void to_cbor(
const basic_json& j, detail::output_adapter<std::uint8_t> o)
24822 binary_writer<std::uint8_t>(o).write_cbor(j);
24827 binary_writer<char>(o).write_cbor(j);
24910 std::vector<std::uint8_t> result;
24917 binary_writer<std::uint8_t>(o).write_msgpack(j);
24922 binary_writer<char>(o).write_msgpack(j);
25012 const bool use_size =
false,
25013 const bool use_type =
false)
25015 std::vector<std::uint8_t> result;
25016 to_ubjson(j, result, use_size, use_type);
25021 const bool use_size =
false,
const bool use_type =
false)
25023 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
25027 const bool use_size =
false,
const bool use_type =
false)
25029 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
25091 std::vector<std::uint8_t> result;
25104 static void to_bson(
const basic_json& j, detail::output_adapter<std::uint8_t> o)
25106 binary_writer<std::uint8_t>(o).write_bson(j);
25114 binary_writer<char>(o).write_bson(j);
25220 template<
typename InputType>
25223 const bool strict =
true,
25224 const bool allow_exceptions =
true,
25228 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25229 auto ia = detail::input_adapter(std::forward<InputType>(i));
25230 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25231 return res ? result :
basic_json(value_t::discarded);
25237 template<
typename IteratorType>
25240 const bool strict =
true,
25241 const bool allow_exceptions =
true,
25245 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25246 auto ia = detail::input_adapter(std::move(first), std::move(last));
25247 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25248 return res ? result :
basic_json(value_t::discarded);
25251 template<
typename T>
25253 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
25255 const bool strict =
true,
25256 const bool allow_exceptions =
true,
25259 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
25266 const bool strict =
true,
25267 const bool allow_exceptions =
true,
25268 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
25271 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25274 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25364 template<
typename InputType>
25367 const bool strict =
true,
25368 const bool allow_exceptions =
true)
25371 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25372 auto ia = detail::input_adapter(std::forward<InputType>(i));
25373 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25374 return res ? result :
basic_json(value_t::discarded);
25380 template<
typename IteratorType>
25383 const bool strict =
true,
25384 const bool allow_exceptions =
true)
25387 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25388 auto ia = detail::input_adapter(std::move(first), std::move(last));
25389 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25390 return res ? result :
basic_json(value_t::discarded);
25394 template<
typename T>
25396 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25398 const bool strict =
true,
25399 const bool allow_exceptions =
true)
25401 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
25405 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25407 const bool strict =
true,
25408 const bool allow_exceptions =
true)
25411 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25414 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25415 return res ? result :
basic_json(value_t::discarded);
25481 template<
typename InputType>
25484 const bool strict =
true,
25485 const bool allow_exceptions =
true)
25488 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25489 auto ia = detail::input_adapter(std::forward<InputType>(i));
25490 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25491 return res ? result :
basic_json(value_t::discarded);
25497 template<
typename IteratorType>
25500 const bool strict =
true,
25501 const bool allow_exceptions =
true)
25504 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25505 auto ia = detail::input_adapter(std::move(first), std::move(last));
25506 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25507 return res ? result :
basic_json(value_t::discarded);
25510 template<
typename T>
25512 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25514 const bool strict =
true,
25515 const bool allow_exceptions =
true)
25517 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
25521 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25523 const bool strict =
true,
25524 const bool allow_exceptions =
true)
25527 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25530 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25531 return res ? result :
basic_json(value_t::discarded);
25595 template<
typename InputType>
25598 const bool strict =
true,
25599 const bool allow_exceptions =
true)
25602 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25603 auto ia = detail::input_adapter(std::forward<InputType>(i));
25604 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25605 return res ? result :
basic_json(value_t::discarded);
25611 template<
typename IteratorType>
25614 const bool strict =
true,
25615 const bool allow_exceptions =
true)
25618 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25619 auto ia = detail::input_adapter(std::move(first), std::move(last));
25620 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25621 return res ? result :
basic_json(value_t::discarded);
25624 template<
typename T>
25626 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25628 const bool strict =
true,
25629 const bool allow_exceptions =
true)
25631 return from_bson(ptr, ptr + len, strict, allow_exceptions);
25635 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25637 const bool strict =
true,
25638 const bool allow_exceptions =
true)
25641 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25644 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25645 return res ? result :
basic_json(value_t::discarded);
25691 return ptr.get_unchecked(
this);
25719 return ptr.get_unchecked(
this);
25762 return ptr.get_checked(
this);
25805 return ptr.get_checked(
this);
25833 json_pointer::flatten(
"", *
this, result);
25869 return json_pointer::unflatten(*
this);
25934 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25936 const auto get_op = [](
const std::string & op)
25940 return patch_operations::add;
25942 if (op ==
"remove")
25944 return patch_operations::remove;
25946 if (op ==
"replace")
25948 return patch_operations::replace;
25952 return patch_operations::move;
25956 return patch_operations::copy;
25960 return patch_operations::test;
25963 return patch_operations::invalid;
25978 if (top_pointer != ptr)
25980 result.
at(top_pointer);
25984 const auto last_path = ptr.
back();
25988 switch (parent.m_type)
25990 case value_t::null:
25991 case value_t::object:
25994 parent[last_path] = val;
25998 case value_t::array:
26000 if (last_path ==
"-")
26007 const auto idx = json_pointer::array_index(last_path);
26008 if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
26011 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
26015 parent.insert(parent.begin() +
static_cast<difference_type>(idx), val);
26021 case value_t::string:
26022 case value_t::boolean:
26023 case value_t::number_integer:
26024 case value_t::number_unsigned:
26025 case value_t::number_float:
26026 case value_t::binary:
26027 case value_t::discarded:
26029 JSON_ASSERT(
false);
26034 const auto operation_remove = [
this, &result](
json_pointer & ptr)
26037 const auto last_path = ptr.back();
26042 if (parent.is_object())
26045 auto it = parent.
find(last_path);
26046 if (JSON_HEDLEY_LIKELY(it != parent.end()))
26052 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
26055 else if (parent.is_array())
26058 parent.erase(json_pointer::array_index(last_path));
26063 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
26065 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
26069 for (
const auto& val : json_patch)
26072 const auto get_value = [&val](
const std::string & op,
26073 const std::string & member,
26077 auto it = val.m_value.object->find(member);
26080 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
26083 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
26086 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
26090 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
26093 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
26101 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
26103 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", val));
26107 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
26108 const auto path = get_value(op,
"path",
true).template get<std::string>();
26111 switch (get_op(op))
26113 case patch_operations::add:
26115 operation_add(ptr, get_value(
"add",
"value",
false));
26119 case patch_operations::remove:
26121 operation_remove(ptr);
26125 case patch_operations::replace:
26128 result.
at(ptr) = get_value(
"replace",
"value",
false);
26132 case patch_operations::move:
26134 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
26144 operation_remove(from_ptr);
26145 operation_add(ptr, v);
26149 case patch_operations::copy:
26151 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
26160 operation_add(ptr, v);
26164 case patch_operations::test:
26166 bool success =
false;
26171 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
26179 if (JSON_HEDLEY_UNLIKELY(!success))
26181 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
26187 case patch_operations::invalid:
26192 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid", val));
26235 const std::string& path =
"")
26241 if (source == target)
26246 if (source.type() != target.type())
26251 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26256 switch (source.type())
26258 case value_t::array:
26262 while (i < source.size() && i < target.size())
26265 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
26266 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26275 while (i < source.size())
26282 {
"path", path +
"/" + std::to_string(i)}
26288 while (i < target.size())
26293 {
"path", path +
"/-"},
26294 {
"value", target[i]}
26302 case value_t::object:
26305 for (
auto it = source.cbegin(); it != source.cend(); ++it)
26308 const auto path_key = path +
"/" + detail::escape(it.key());
26310 if (target.find(it.key()) != target.end())
26313 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
26314 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26321 {
"op",
"remove"}, {
"path", path_key}
26327 for (
auto it = target.cbegin(); it != target.cend(); ++it)
26329 if (source.find(it.key()) == source.end())
26332 const auto path_key = path +
"/" + detail::escape(it.key());
26335 {
"op",
"add"}, {
"path", path_key},
26336 {
"value", it.value()}
26344 case value_t::null:
26345 case value_t::string:
26346 case value_t::boolean:
26347 case value_t::number_integer:
26348 case value_t::number_unsigned:
26349 case value_t::number_float:
26350 case value_t::binary:
26351 case value_t::discarded:
26357 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26419 if (apply_patch.is_object())
26425 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
26427 if (it.value().is_null())
26439 *
this = apply_patch;
26455NLOHMANN_BASIC_JSON_TPL_DECLARATION
26456std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
26481 return nlohmann::detail::hash(j);
26489struct less<::nlohmann::detail::value_t>
26495 bool operator()(nlohmann::detail::value_t lhs,
26496 nlohmann::detail::value_t rhs)
const noexcept
26498 return nlohmann::detail::operator<(lhs, rhs);
26503#ifndef JSON_HAS_CPP_20
26512 is_nothrow_move_constructible<nlohmann::json>::value&&
26513 is_nothrow_move_assignable<nlohmann::json>::value
26536JSON_HEDLEY_NON_NULL(1)
26537inline
nlohmann::json operator "" _json(const
char* s,
std::
size_t n)
26555JSON_HEDLEY_NON_NULL(1)
26556inline
nlohmann::json::json_pointer operator "" _json_pointer(const
char* s,
std::
size_t n)
26565#if defined(__clang__)
26566 #pragma clang diagnostic pop
26571#undef JSON_INTERNAL_CATCH
26575#undef JSON_PRIVATE_UNLESS_TESTED
26576#undef JSON_HAS_CPP_11
26577#undef JSON_HAS_CPP_14
26578#undef JSON_HAS_CPP_17
26579#undef JSON_HAS_CPP_20
26580#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
26581#undef NLOHMANN_BASIC_JSON_TPL
26582#undef JSON_EXPLICIT
26583#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL
26588#undef JSON_HEDLEY_ALWAYS_INLINE
26589#undef JSON_HEDLEY_ARM_VERSION
26590#undef JSON_HEDLEY_ARM_VERSION_CHECK
26591#undef JSON_HEDLEY_ARRAY_PARAM
26592#undef JSON_HEDLEY_ASSUME
26593#undef JSON_HEDLEY_BEGIN_C_DECLS
26594#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
26595#undef JSON_HEDLEY_CLANG_HAS_BUILTIN
26596#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
26597#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
26598#undef JSON_HEDLEY_CLANG_HAS_EXTENSION
26599#undef JSON_HEDLEY_CLANG_HAS_FEATURE
26600#undef JSON_HEDLEY_CLANG_HAS_WARNING
26601#undef JSON_HEDLEY_COMPCERT_VERSION
26602#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
26603#undef JSON_HEDLEY_CONCAT
26604#undef JSON_HEDLEY_CONCAT3
26605#undef JSON_HEDLEY_CONCAT3_EX
26606#undef JSON_HEDLEY_CONCAT_EX
26607#undef JSON_HEDLEY_CONST
26608#undef JSON_HEDLEY_CONSTEXPR
26609#undef JSON_HEDLEY_CONST_CAST
26610#undef JSON_HEDLEY_CPP_CAST
26611#undef JSON_HEDLEY_CRAY_VERSION
26612#undef JSON_HEDLEY_CRAY_VERSION_CHECK
26613#undef JSON_HEDLEY_C_DECL
26614#undef JSON_HEDLEY_DEPRECATED
26615#undef JSON_HEDLEY_DEPRECATED_FOR
26616#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
26617#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
26618#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
26619#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
26620#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
26621#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
26622#undef JSON_HEDLEY_DIAGNOSTIC_POP
26623#undef JSON_HEDLEY_DIAGNOSTIC_PUSH
26624#undef JSON_HEDLEY_DMC_VERSION
26625#undef JSON_HEDLEY_DMC_VERSION_CHECK
26626#undef JSON_HEDLEY_EMPTY_BASES
26627#undef JSON_HEDLEY_EMSCRIPTEN_VERSION
26628#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
26629#undef JSON_HEDLEY_END_C_DECLS
26630#undef JSON_HEDLEY_FLAGS
26631#undef JSON_HEDLEY_FLAGS_CAST
26632#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
26633#undef JSON_HEDLEY_GCC_HAS_BUILTIN
26634#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
26635#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
26636#undef JSON_HEDLEY_GCC_HAS_EXTENSION
26637#undef JSON_HEDLEY_GCC_HAS_FEATURE
26638#undef JSON_HEDLEY_GCC_HAS_WARNING
26639#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
26640#undef JSON_HEDLEY_GCC_VERSION
26641#undef JSON_HEDLEY_GCC_VERSION_CHECK
26642#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
26643#undef JSON_HEDLEY_GNUC_HAS_BUILTIN
26644#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
26645#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
26646#undef JSON_HEDLEY_GNUC_HAS_EXTENSION
26647#undef JSON_HEDLEY_GNUC_HAS_FEATURE
26648#undef JSON_HEDLEY_GNUC_HAS_WARNING
26649#undef JSON_HEDLEY_GNUC_VERSION
26650#undef JSON_HEDLEY_GNUC_VERSION_CHECK
26651#undef JSON_HEDLEY_HAS_ATTRIBUTE
26652#undef JSON_HEDLEY_HAS_BUILTIN
26653#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
26654#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
26655#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
26656#undef JSON_HEDLEY_HAS_EXTENSION
26657#undef JSON_HEDLEY_HAS_FEATURE
26658#undef JSON_HEDLEY_HAS_WARNING
26659#undef JSON_HEDLEY_IAR_VERSION
26660#undef JSON_HEDLEY_IAR_VERSION_CHECK
26661#undef JSON_HEDLEY_IBM_VERSION
26662#undef JSON_HEDLEY_IBM_VERSION_CHECK
26663#undef JSON_HEDLEY_IMPORT
26664#undef JSON_HEDLEY_INLINE
26665#undef JSON_HEDLEY_INTEL_CL_VERSION
26666#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
26667#undef JSON_HEDLEY_INTEL_VERSION
26668#undef JSON_HEDLEY_INTEL_VERSION_CHECK
26669#undef JSON_HEDLEY_IS_CONSTANT
26670#undef JSON_HEDLEY_IS_CONSTEXPR_
26671#undef JSON_HEDLEY_LIKELY
26672#undef JSON_HEDLEY_MALLOC
26673#undef JSON_HEDLEY_MCST_LCC_VERSION
26674#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
26675#undef JSON_HEDLEY_MESSAGE
26676#undef JSON_HEDLEY_MSVC_VERSION
26677#undef JSON_HEDLEY_MSVC_VERSION_CHECK
26678#undef JSON_HEDLEY_NEVER_INLINE
26679#undef JSON_HEDLEY_NON_NULL
26680#undef JSON_HEDLEY_NO_ESCAPE
26681#undef JSON_HEDLEY_NO_RETURN
26682#undef JSON_HEDLEY_NO_THROW
26683#undef JSON_HEDLEY_NULL
26684#undef JSON_HEDLEY_PELLES_VERSION
26685#undef JSON_HEDLEY_PELLES_VERSION_CHECK
26686#undef JSON_HEDLEY_PGI_VERSION
26687#undef JSON_HEDLEY_PGI_VERSION_CHECK
26688#undef JSON_HEDLEY_PREDICT
26689#undef JSON_HEDLEY_PRINTF_FORMAT
26690#undef JSON_HEDLEY_PRIVATE
26691#undef JSON_HEDLEY_PUBLIC
26692#undef JSON_HEDLEY_PURE
26693#undef JSON_HEDLEY_REINTERPRET_CAST
26694#undef JSON_HEDLEY_REQUIRE
26695#undef JSON_HEDLEY_REQUIRE_CONSTEXPR
26696#undef JSON_HEDLEY_REQUIRE_MSG
26697#undef JSON_HEDLEY_RESTRICT
26699#undef JSON_HEDLEY_SENTINEL
26700#undef JSON_HEDLEY_STATIC_ASSERT
26701#undef JSON_HEDLEY_STATIC_CAST
26702#undef JSON_HEDLEY_STRINGIFY
26703#undef JSON_HEDLEY_STRINGIFY_EX
26704#undef JSON_HEDLEY_SUNPRO_VERSION
26705#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
26706#undef JSON_HEDLEY_TINYC_VERSION
26707#undef JSON_HEDLEY_TINYC_VERSION_CHECK
26708#undef JSON_HEDLEY_TI_ARMCL_VERSION
26709#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
26710#undef JSON_HEDLEY_TI_CL2000_VERSION
26711#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
26712#undef JSON_HEDLEY_TI_CL430_VERSION
26713#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
26714#undef JSON_HEDLEY_TI_CL6X_VERSION
26715#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
26716#undef JSON_HEDLEY_TI_CL7X_VERSION
26717#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
26718#undef JSON_HEDLEY_TI_CLPRU_VERSION
26719#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
26720#undef JSON_HEDLEY_TI_VERSION
26721#undef JSON_HEDLEY_TI_VERSION_CHECK
26722#undef JSON_HEDLEY_UNAVAILABLE
26723#undef JSON_HEDLEY_UNLIKELY
26724#undef JSON_HEDLEY_UNPREDICTABLE
26725#undef JSON_HEDLEY_UNREACHABLE
26726#undef JSON_HEDLEY_UNREACHABLE_RETURN
26727#undef JSON_HEDLEY_VERSION
26728#undef JSON_HEDLEY_VERSION_DECODE_MAJOR
26729#undef JSON_HEDLEY_VERSION_DECODE_MINOR
26730#undef JSON_HEDLEY_VERSION_DECODE_REVISION
26731#undef JSON_HEDLEY_VERSION_ENCODE
26732#undef JSON_HEDLEY_WARNING
26735#undef JSON_HEDLEY_FALL_THROUGH
ValueType & get_to(ValueType &v) const
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
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
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
detail::exception exception
general exception of the basic_json class
ReferenceType get_ref()
get a reference value (implicit)
static 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
static basic_json from_cbor(const T *ptr, std::size_t len, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
basic_json(const value_t v)
create an empty value with a given type
size_type max_size() const noexcept
returns the maximum possible number of elements
static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
creates a diff as a JSON patch
detail::input_format_t input_format_t
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
const_reverse_iterator crend() const noexcept
returns a const reverse iterator to one before the first
detail::out_of_range out_of_range
exception indicating access out of the defined range
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
basic_json(const JsonRef &ref)
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 basic_json array(initializer_list_t init={})
explicitly create an array from an initializer list
const_iterator cend() const noexcept
returns a const iterator to one past the last element
reference back()
access the last element
const binary_t & get_binary() const
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
static basic_json meta()
returns version information on the library
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 basic_json binary(const typename binary_t::container_type &init)
explicitly create a binary array (without subtype)
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
typename std::allocator_traits< allocator_type >::pointer pointer
the type of an element pointer
static 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
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 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
reference at(size_type idx)
access specified array element with bounds checking
static 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
detail::parse_error parse_error
exception indicating a parse error
constexpr bool is_object() const noexcept
return whether value is an object
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.
basic_json(const basic_json &other)
copy constructor
~basic_json() noexcept
destructor
friend struct detail::external_constructor
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
detail::invalid_iterator invalid_iterator
exception indicating errors with iterators
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
comparison: not equal
detail::other_error other_error
exception indicating other library errors
json_value m_value
the value of the current element
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
comparison: greater than or equal
reverse_iterator rend() noexcept
returns an iterator to the reverse-end
static 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
ReferenceType get_ref() const
get a reference value (implicit)
auto get() noexcept -> decltype(std::declval< basic_json_t & >().template get_ptr< PointerType >())
get a pointer value (explicit)
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)
ArrayType< basic_json, AllocatorType< basic_json > > array_t
a type for an array
Array get_to(T(&v)[N]) const noexcept(noexcept(JSONSerializer< Array >::from_json(std::declval< const basic_json_t & >(), v)))
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
comparison: greater than
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
constexpr bool is_binary() const noexcept
return whether value is a binary array
static basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
reference operator[](size_type idx)
access specified array element
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 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<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
static 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
constexpr bool is_array() const noexcept
return whether value is an array
iterator insert_iterator(const_iterator pos, Args &&... args)
basic_json flatten() const
return flattened JSON value
const char * type_name() const noexcept
return the type as string
const value_type & const_reference
the type of an element const reference
void push_back(basic_json &&val)
add an object to an array
size_type count(KeyT &&key) const
returns the number of occurrences of a key in a JSON object
constexpr bool is_number() const noexcept
return whether value is a number
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
std::less< StringType > object_comparator_t
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
iterator find(KeyT &&key)
find an element in a JSON object
detail::type_error type_error
exception indicating executing a member function with a wrong type
basic_json(std::nullptr_t=nullptr) noexcept
create a null object
AllocatorType< basic_json > allocator_type
the allocator type
nlohmann::byte_container_with_subtype< BinaryType > binary_t
a type for a packed binary type
JSONSerializer< T, SFINAE > json_serializer
static 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
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)
const_iterator cbegin() const noexcept
returns a const iterator to the first element
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
iterator insert(const_iterator pos, const basic_json &val)
inserts element
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
constexpr bool is_discarded() const noexcept
return whether value is discarded
constexpr bool is_null() const noexcept
return whether value is null
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
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 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
byte_container_with_subtype(const container_type &b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
BinaryType container_type
the type of the underlying container
byte_container_with_subtype(const container_type &b) noexcept(noexcept(container_type(b)))
byte_container_with_subtype(container_type &&b) noexcept(noexcept(container_type(std::move(b))))
bool operator!=(const byte_container_with_subtype &rhs) const
void clear_subtype() noexcept
clears the binary subtype
byte_container_with_subtype() noexcept(noexcept(container_type()))
byte_container_with_subtype(container_type &&b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
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
bool operator==(const byte_container_with_subtype &rhs) const
an internal type for a backed binary type
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
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
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
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
void push_back(std::string &&token)
append an unescaped token at the end of the reference pointer
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON pointer
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
constexpr const auto & to_json
constexpr const auto & from_json
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
NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin)
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
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
typename BasicJsonType::number_integer_t number_integer_t
typename BasicJsonType::binary_t binary_t
virtual bool end_array()=0
the end of an array was read
virtual bool key(string_t &val)=0
an object key was read
typename BasicJsonType::number_unsigned_t number_unsigned_t
virtual bool binary(binary_t &val)=0
a binary string was read
typename BasicJsonType::number_float_t number_float_t
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
json_sax(json_sax &&) noexcept=default
virtual bool boolean(bool val)=0
a boolean value was read
json_sax(const json_sax &)=default
json_sax & operator=(const json_sax &)=default
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
typename BasicJsonType::string_t string_t
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(std::initializer_list< T > init, const Allocator &alloc=Allocator())
std::vector< std::pair< const Key, T >, Allocator > Container
const T & at(const Key &key) const
iterator find(const Key &key)
iterator erase(iterator pos)
void insert(InputIt first, InputIt last)
std::pair< iterator, bool > insert(value_type &&value)
const_iterator find(const Key &key) const
size_type erase(const Key &key)
T & operator[](const Key &key)
ordered_map(const Allocator &alloc=Allocator())
typename std::enable_if< std::is_convertible< typename std::iterator_traits< InputIt >::iterator_category, std::input_iterator_tag >::value >::type require_input_iter
ordered_map(It first, It last, const Allocator &alloc=Allocator())
std::pair< iterator, bool > insert(const value_type &value)
size_type count(const Key &key) const
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
const T & operator[](const Key &key) const