30 #ifndef INCLUDE_NLOHMANN_JSON_HPP_
31 #define INCLUDE_NLOHMANN_JSON_HPP_
33 #define NLOHMANN_JSON_VERSION_MAJOR 3
34 #define NLOHMANN_JSON_VERSION_MINOR 10
35 #define NLOHMANN_JSON_VERSION_PATCH 2
40 #include <initializer_list>
54 #include <type_traits>
62 #include <forward_list>
67 #include <type_traits>
68 #include <unordered_map>
120 enum class value_t : std::uint8_t
147 inline 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
621 #if defined(__POCC__)
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)
1434 JSON_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(...)
1460 JSON_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)
2222 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2223 #if defined(__clang__)
2224 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2225 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2227 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2228 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2229 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2236 #if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11)
2237 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2238 #define JSON_HAS_CPP_20
2239 #define JSON_HAS_CPP_17
2240 #define JSON_HAS_CPP_14
2241 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2242 #define JSON_HAS_CPP_17
2243 #define JSON_HAS_CPP_14
2244 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2245 #define JSON_HAS_CPP_14
2248 #define JSON_HAS_CPP_11
2252 #if defined(__clang__)
2253 #pragma clang diagnostic push
2254 #pragma clang diagnostic ignored "-Wdocumentation"
2255 #pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
2259 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2260 #define JSON_THROW(exception) throw exception
2261 #define JSON_TRY try
2262 #define JSON_CATCH(exception) catch(exception)
2263 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2266 #define JSON_THROW(exception) std::abort()
2267 #define JSON_TRY if(true)
2268 #define JSON_CATCH(exception) if(false)
2269 #define JSON_INTERNAL_CATCH(exception) if(false)
2273 #if defined(JSON_THROW_USER)
2275 #define JSON_THROW JSON_THROW_USER
2277 #if defined(JSON_TRY_USER)
2279 #define JSON_TRY JSON_TRY_USER
2281 #if defined(JSON_CATCH_USER)
2283 #define JSON_CATCH JSON_CATCH_USER
2284 #undef JSON_INTERNAL_CATCH
2285 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2287 #if defined(JSON_INTERNAL_CATCH_USER)
2288 #undef JSON_INTERNAL_CATCH
2289 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2293 #if !defined(JSON_ASSERT)
2295 #define JSON_ASSERT(x) assert(x)
2299 #if defined(JSON_TESTS_PRIVATE)
2300 #define JSON_PRIVATE_UNLESS_TESTED public
2302 #define JSON_PRIVATE_UNLESS_TESTED private
2310 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2311 template<typename BasicJsonType> \
2312 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2314 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2315 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2316 auto it = std::find_if(std::begin(m), std::end(m), \
2317 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2319 return ej_pair.first == e; \
2321 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2323 template<typename BasicJsonType> \
2324 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2326 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2327 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2328 auto it = std::find_if(std::begin(m), std::end(m), \
2329 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2331 return ej_pair.second == j; \
2333 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2339 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2340 template<template<typename, typename, typename...> class ObjectType, \
2341 template<typename, typename...> class ArrayType, \
2342 class StringType, class BooleanType, class NumberIntegerType, \
2343 class NumberUnsignedType, class NumberFloatType, \
2344 template<typename> class AllocatorType, \
2345 template<typename, typename = void> class JSONSerializer, \
2348 #define NLOHMANN_BASIC_JSON_TPL \
2349 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2350 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2351 AllocatorType, JSONSerializer, BinaryType>
2355 #define NLOHMANN_JSON_EXPAND( x ) x
2356 #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
2357 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2358 NLOHMANN_JSON_PASTE64, \
2359 NLOHMANN_JSON_PASTE63, \
2360 NLOHMANN_JSON_PASTE62, \
2361 NLOHMANN_JSON_PASTE61, \
2362 NLOHMANN_JSON_PASTE60, \
2363 NLOHMANN_JSON_PASTE59, \
2364 NLOHMANN_JSON_PASTE58, \
2365 NLOHMANN_JSON_PASTE57, \
2366 NLOHMANN_JSON_PASTE56, \
2367 NLOHMANN_JSON_PASTE55, \
2368 NLOHMANN_JSON_PASTE54, \
2369 NLOHMANN_JSON_PASTE53, \
2370 NLOHMANN_JSON_PASTE52, \
2371 NLOHMANN_JSON_PASTE51, \
2372 NLOHMANN_JSON_PASTE50, \
2373 NLOHMANN_JSON_PASTE49, \
2374 NLOHMANN_JSON_PASTE48, \
2375 NLOHMANN_JSON_PASTE47, \
2376 NLOHMANN_JSON_PASTE46, \
2377 NLOHMANN_JSON_PASTE45, \
2378 NLOHMANN_JSON_PASTE44, \
2379 NLOHMANN_JSON_PASTE43, \
2380 NLOHMANN_JSON_PASTE42, \
2381 NLOHMANN_JSON_PASTE41, \
2382 NLOHMANN_JSON_PASTE40, \
2383 NLOHMANN_JSON_PASTE39, \
2384 NLOHMANN_JSON_PASTE38, \
2385 NLOHMANN_JSON_PASTE37, \
2386 NLOHMANN_JSON_PASTE36, \
2387 NLOHMANN_JSON_PASTE35, \
2388 NLOHMANN_JSON_PASTE34, \
2389 NLOHMANN_JSON_PASTE33, \
2390 NLOHMANN_JSON_PASTE32, \
2391 NLOHMANN_JSON_PASTE31, \
2392 NLOHMANN_JSON_PASTE30, \
2393 NLOHMANN_JSON_PASTE29, \
2394 NLOHMANN_JSON_PASTE28, \
2395 NLOHMANN_JSON_PASTE27, \
2396 NLOHMANN_JSON_PASTE26, \
2397 NLOHMANN_JSON_PASTE25, \
2398 NLOHMANN_JSON_PASTE24, \
2399 NLOHMANN_JSON_PASTE23, \
2400 NLOHMANN_JSON_PASTE22, \
2401 NLOHMANN_JSON_PASTE21, \
2402 NLOHMANN_JSON_PASTE20, \
2403 NLOHMANN_JSON_PASTE19, \
2404 NLOHMANN_JSON_PASTE18, \
2405 NLOHMANN_JSON_PASTE17, \
2406 NLOHMANN_JSON_PASTE16, \
2407 NLOHMANN_JSON_PASTE15, \
2408 NLOHMANN_JSON_PASTE14, \
2409 NLOHMANN_JSON_PASTE13, \
2410 NLOHMANN_JSON_PASTE12, \
2411 NLOHMANN_JSON_PASTE11, \
2412 NLOHMANN_JSON_PASTE10, \
2413 NLOHMANN_JSON_PASTE9, \
2414 NLOHMANN_JSON_PASTE8, \
2415 NLOHMANN_JSON_PASTE7, \
2416 NLOHMANN_JSON_PASTE6, \
2417 NLOHMANN_JSON_PASTE5, \
2418 NLOHMANN_JSON_PASTE4, \
2419 NLOHMANN_JSON_PASTE3, \
2420 NLOHMANN_JSON_PASTE2, \
2421 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2422 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2423 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2424 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2425 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2426 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2427 #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)
2428 #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)
2429 #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)
2430 #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)
2431 #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)
2432 #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)
2433 #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)
2434 #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)
2435 #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)
2436 #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)
2437 #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)
2438 #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)
2439 #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)
2440 #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)
2441 #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)
2442 #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)
2443 #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)
2444 #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)
2445 #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)
2446 #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)
2447 #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)
2448 #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)
2449 #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)
2450 #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)
2451 #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)
2452 #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)
2453 #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)
2454 #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)
2455 #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)
2456 #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)
2457 #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)
2458 #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)
2459 #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)
2460 #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)
2461 #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)
2462 #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)
2463 #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)
2464 #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)
2465 #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)
2466 #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)
2467 #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)
2468 #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)
2469 #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)
2470 #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)
2471 #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)
2472 #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)
2473 #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)
2474 #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)
2475 #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)
2476 #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)
2477 #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)
2478 #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)
2479 #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)
2480 #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)
2481 #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)
2482 #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)
2483 #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)
2484 #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)
2486 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2487 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2494 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2495 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__)) } \
2496 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__)) }
2503 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2504 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__)) } \
2505 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__)) }
2507 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2508 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2511 #if JSON_USE_IMPLICIT_CONVERSIONS
2512 #define JSON_EXPLICIT
2514 #define JSON_EXPLICIT explicit
2517 #ifndef JSON_DIAGNOSTICS
2518 #define JSON_DIAGNOSTICS 0
2540 inline void replace_substring(std::string& s,
const std::string& f,
2541 const std::string& t)
2543 JSON_ASSERT(!f.empty());
2544 for (
auto pos = s.find(f);
2545 pos != std::string::npos;
2546 s.replace(pos, f.size(), t),
2547 pos = s.find(f, pos + t.size()))
2558 inline std::string escape(std::string s)
2560 replace_substring(s,
"~",
"~0");
2561 replace_substring(s,
"/",
"~1");
2572 static void unescape(std::string& s)
2574 replace_substring(s,
"~1",
"/");
2575 replace_substring(s,
"~0",
"~");
2594 std::size_t chars_read_total = 0;
2596 std::size_t chars_read_current_line = 0;
2598 std::size_t lines_read = 0;
2601 constexpr
operator size_t()
const
2603 return chars_read_total;
2649 class exception :
public std::exception
2653 const char* what() const noexcept
override
2662 JSON_HEDLEY_NON_NULL(3)
2663 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
2665 static std::string name(
const std::string& ename,
int id_)
2667 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2670 template<
typename BasicJsonType>
2671 static std::string diagnostics(
const BasicJsonType& leaf_element)
2673 #if JSON_DIAGNOSTICS
2674 std::vector<std::string> tokens;
2675 for (
const auto* current = &leaf_element; current->m_parent !=
nullptr; current = current->m_parent)
2677 switch (current->m_parent->type())
2679 case value_t::array:
2681 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2683 if (¤t->m_parent->m_value.array->operator[](i) == current)
2685 tokens.emplace_back(std::to_string(i));
2692 case value_t::object:
2694 for (
const auto& element : *current->m_parent->m_value.object)
2696 if (&element.second == current)
2698 tokens.emplace_back(element.first.c_str());
2706 case value_t::string:
2707 case value_t::boolean:
2708 case value_t::number_integer:
2709 case value_t::number_unsigned:
2710 case value_t::number_float:
2711 case value_t::binary:
2712 case value_t::discarded:
2723 return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2724 [](
const std::string & a,
const std::string & b)
2726 return a +
"/" + detail::escape(b);
2729 static_cast<void>(leaf_element);
2736 std::runtime_error m;
2784 class parse_error :
public exception
2796 template<
typename BasicJsonType>
2797 static parse_error create(
int id_,
const position_t& pos,
const std::string& what_arg,
const BasicJsonType& context)
2799 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2800 position_string(pos) +
": " + exception::diagnostics(context) + what_arg;
2801 return parse_error(id_, pos.chars_read_total, w.c_str());
2804 template<
typename BasicJsonType>
2805 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg,
const BasicJsonType& context)
2807 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2808 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2809 ": " + exception::diagnostics(context) + what_arg;
2810 return parse_error(id_, byte_, w.c_str());
2822 const std::size_t byte;
2825 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
2826 : exception(id_, what_arg), byte(byte_) {}
2828 static std::string position_string(
const position_t& pos)
2830 return " at line " + std::to_string(pos.lines_read + 1) +
2831 ", column " + std::to_string(pos.chars_read_current_line);
2872 class invalid_iterator :
public exception
2875 template<
typename BasicJsonType>
2876 static invalid_iterator create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2878 std::string w = exception::name(
"invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2879 return invalid_iterator(id_, w.c_str());
2883 JSON_HEDLEY_NON_NULL(3)
2884 invalid_iterator(
int id_, const
char* what_arg)
2885 : exception(id_, what_arg) {}
2927 class type_error :
public exception
2930 template<
typename BasicJsonType>
2931 static type_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2933 std::string w = exception::name(
"type_error", id_) + exception::diagnostics(context) + what_arg;
2934 return type_error(id_, w.c_str());
2938 JSON_HEDLEY_NON_NULL(3)
2939 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2975 class out_of_range :
public exception
2978 template<
typename BasicJsonType>
2979 static out_of_range create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2981 std::string w = exception::name(
"out_of_range", id_) + exception::diagnostics(context) + what_arg;
2982 return out_of_range(id_, w.c_str());
2986 JSON_HEDLEY_NON_NULL(3)
2987 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3014 class other_error :
public exception
3017 template<
typename BasicJsonType>
3018 static other_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3020 std::string w = exception::name(
"other_error", id_) + exception::diagnostics(context) + what_arg;
3021 return other_error(id_, w.c_str());
3025 JSON_HEDLEY_NON_NULL(3)
3026 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3037 #include <type_traits>
3048 template<
typename T>
3049 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3051 #ifdef JSON_HAS_CPP_14
3054 using std::enable_if_t;
3055 using std::index_sequence;
3056 using std::make_index_sequence;
3057 using std::index_sequence_for;
3062 template<
bool B,
typename T =
void>
3063 using enable_if_t =
typename std::enable_if<B, T>::type;
3089 template <
typename T, T... Ints>
3090 struct integer_sequence
3092 using value_type = T;
3093 static constexpr std::size_t size() noexcept
3095 return sizeof...(Ints);
3104 template <
size_t... Ints>
3105 using index_sequence = integer_sequence<size_t, Ints...>;
3107 namespace utility_internal
3110 template <
typename Seq,
size_t SeqSize,
size_t Rem>
3114 template <
typename T, T... Ints,
size_t SeqSize>
3115 struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3117 using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3120 template <
typename T, T... Ints,
size_t SeqSize>
3121 struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3123 using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3128 template <
typename T,
size_t N>
3132 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3135 template <
typename T>
3138 using type = integer_sequence<T>;
3150 template <
typename T, T N>
3151 using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3159 using make_index_sequence = make_integer_sequence<size_t, N>;
3166 template <
typename... Ts>
3167 using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3174 template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
3175 template<>
struct priority_tag<0> {};
3178 template<
typename T>
3181 static constexpr T value{};
3184 template<
typename T>
3185 constexpr T static_const<T>::value;
3198 template <
class T>
struct identity_tag {};
3206 #include <type_traits>
3222 template<
typename ...Ts>
struct make_void
3226 template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
3237 template<
typename It,
typename =
void>
3238 struct iterator_types {};
3240 template<
typename It>
3241 struct iterator_types <
3243 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3244 typename It::reference, typename It::iterator_category >>
3246 using difference_type =
typename It::difference_type;
3247 using value_type =
typename It::value_type;
3248 using pointer =
typename It::pointer;
3249 using reference =
typename It::reference;
3250 using iterator_category =
typename It::iterator_category;
3255 template<
typename T,
typename =
void>
3256 struct iterator_traits
3260 template<
typename T>
3261 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3266 template<
typename T>
3267 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3269 using iterator_category = std::random_access_iterator_tag;
3270 using value_type = T;
3271 using difference_type = ptrdiff_t;
3273 using reference = T&;
3285 #include <type_traits>
3297 nonesuch() =
delete;
3298 ~nonesuch() =
delete;
3299 nonesuch(nonesuch
const&) =
delete;
3300 nonesuch(nonesuch
const&&) =
delete;
3301 void operator=(nonesuch
const&) =
delete;
3302 void operator=(nonesuch&&) =
delete;
3305 template<
class Default,
3307 template<
class...>
class Op,
3311 using value_t = std::false_type;
3312 using type = Default;
3315 template<
class Default,
template<
class...>
class Op,
class... Args>
3316 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3318 using value_t = std::true_type;
3319 using type = Op<Args...>;
3322 template<
template<
class...>
class Op,
class... Args>
3323 using is_detected =
typename detector<nonesuch, void, Op, Args...>::value_t;
3325 template<
template<
class...>
class Op,
class... Args>
3326 struct is_detected_lazy : is_detected<Op, Args...> { };
3328 template<
template<
class...>
class Op,
class... Args>
3329 using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
3331 template<
class Default,
template<
class...>
class Op,
class... Args>
3332 using detected_or = detector<Default, void, Op, Args...>;
3334 template<
class Default,
template<
class...>
class Op,
class... Args>
3335 using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
3337 template<
class Expected,
template<
class...>
class Op,
class... Args>
3338 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3340 template<
class To,
template<
class...>
class Op,
class... Args>
3341 using is_detected_convertible =
3342 std::is_convertible<detected_t<Op, Args...>, To>;
3347 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3348 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3370 template<
typename T =
void,
typename SFINAE =
void>
3371 struct adl_serializer;
3373 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3375 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3376 class StringType = std::string,
class BooleanType = bool,
3377 class NumberIntegerType = std::int64_t,
3378 class NumberUnsignedType = std::uint64_t,
3379 class NumberFloatType = double,
3380 template<
typename U>
class AllocatorType = std::allocator,
3381 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3383 class BinaryType = std::vector<std::uint8_t>>
3397 template<
typename BasicJsonType>
3410 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3452 template<
typename>
struct is_basic_json : std::false_type {};
3454 NLOHMANN_BASIC_JSON_TPL_DECLARATION
3455 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3465 struct is_json_ref : std::false_type {};
3467 template<
typename T>
3468 struct is_json_ref<json_ref<T>> : std::true_type {};
3474 template<
typename T>
3475 using mapped_type_t =
typename T::mapped_type;
3477 template<
typename T>
3478 using key_type_t =
typename T::key_type;
3480 template<
typename T>
3481 using value_type_t =
typename T::value_type;
3483 template<
typename T>
3484 using difference_type_t =
typename T::difference_type;
3486 template<
typename T>
3487 using pointer_t =
typename T::pointer;
3489 template<
typename T>
3490 using reference_t =
typename T::reference;
3492 template<
typename T>
3493 using iterator_category_t =
typename T::iterator_category;
3495 template<
typename T>
3496 using iterator_t =
typename T::iterator;
3498 template<
typename T,
typename... Args>
3499 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3501 template<
typename T,
typename... Args>
3502 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3504 template<
typename T,
typename U>
3505 using get_template_function = decltype(std::declval<T>().
template get<U>());
3508 template<
typename BasicJsonType,
typename T,
typename =
void>
3509 struct has_from_json : std::false_type {};
3515 template <
typename BasicJsonType,
typename T>
3518 static constexpr
bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3521 template<
typename BasicJsonType,
typename T>
3522 struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3524 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3526 static constexpr
bool value =
3527 is_detected_exact<void, from_json_function, serializer,
3528 const BasicJsonType&, T&>::value;
3533 template<
typename BasicJsonType,
typename T,
typename =
void>
3534 struct has_non_default_from_json : std::false_type {};
3536 template<
typename BasicJsonType,
typename T>
3537 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3539 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3541 static constexpr
bool value =
3542 is_detected_exact<T, from_json_function, serializer,
3543 const BasicJsonType&>::value;
3548 template<
typename BasicJsonType,
typename T,
typename =
void>
3549 struct has_to_json : std::false_type {};
3551 template<
typename BasicJsonType,
typename T>
3552 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3554 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3556 static constexpr
bool value =
3557 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3567 template<
class...>
struct conjunction : std::true_type { };
3568 template<
class B1>
struct conjunction<B1> : B1 { };
3569 template<
class B1,
class... Bn>
3570 struct conjunction<B1, Bn...>
3571 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3574 template<
class B>
struct negation : std::integral_constant < bool, !B::value > { };
3579 template <
typename T>
3580 struct is_default_constructible : std::is_default_constructible<T> {};
3582 template <
typename T1,
typename T2>
3583 struct is_default_constructible<std::pair<T1, T2>>
3584 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3586 template <
typename T1,
typename T2>
3587 struct is_default_constructible<const std::pair<T1, T2>>
3588 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3590 template <
typename... Ts>
3591 struct is_default_constructible<std::tuple<Ts...>>
3592 : conjunction<is_default_constructible<Ts>...> {};
3594 template <
typename... Ts>
3595 struct is_default_constructible<const std::tuple<Ts...>>
3596 : conjunction<is_default_constructible<Ts>...> {};
3599 template <
typename T,
typename... Args>
3600 struct is_constructible : std::is_constructible<T, Args...> {};
3602 template <
typename T1,
typename T2>
3603 struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
3605 template <
typename T1,
typename T2>
3606 struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
3608 template <
typename... Ts>
3609 struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
3611 template <
typename... Ts>
3612 struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
3615 template<
typename T,
typename =
void>
3616 struct is_iterator_traits : std::false_type {};
3618 template<
typename T>
3619 struct is_iterator_traits<iterator_traits<T>>
3622 using traits = iterator_traits<T>;
3625 static constexpr
auto value =
3626 is_detected<value_type_t, traits>::value &&
3627 is_detected<difference_type_t, traits>::value &&
3628 is_detected<pointer_t, traits>::value &&
3629 is_detected<iterator_category_t, traits>::value &&
3630 is_detected<reference_t, traits>::value;
3637 template<
typename T,
typename =
void>
3638 struct is_complete_type : std::false_type {};
3640 template<
typename T>
3641 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3643 template<
typename BasicJsonType,
typename CompatibleObjectType,
3645 struct is_compatible_object_type_impl : std::false_type {};
3647 template<
typename BasicJsonType,
typename CompatibleObjectType>
3648 struct is_compatible_object_type_impl <
3649 BasicJsonType, CompatibleObjectType,
3650 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3651 is_detected<key_type_t, CompatibleObjectType>::value >>
3653 using object_t =
typename BasicJsonType::object_t;
3656 static constexpr
bool value =
3657 is_constructible<
typename object_t::key_type,
3658 typename CompatibleObjectType::key_type>::value &&
3659 is_constructible<
typename object_t::mapped_type,
3660 typename CompatibleObjectType::mapped_type>::value;
3663 template<
typename BasicJsonType,
typename CompatibleObjectType>
3664 struct is_compatible_object_type
3665 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3667 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3669 struct is_constructible_object_type_impl : std::false_type {};
3671 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3672 struct is_constructible_object_type_impl <
3673 BasicJsonType, ConstructibleObjectType,
3674 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3675 is_detected<key_type_t, ConstructibleObjectType>::value >>
3677 using object_t =
typename BasicJsonType::object_t;
3679 static constexpr
bool value =
3680 (is_default_constructible<ConstructibleObjectType>::value &&
3681 (std::is_move_assignable<ConstructibleObjectType>::value ||
3682 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3683 (is_constructible<
typename ConstructibleObjectType::key_type,
3684 typename object_t::key_type>::value &&
3686 typename object_t::mapped_type,
3687 typename ConstructibleObjectType::mapped_type >::value)) ||
3688 (has_from_json<BasicJsonType,
3689 typename ConstructibleObjectType::mapped_type>::value ||
3690 has_non_default_from_json <
3692 typename ConstructibleObjectType::mapped_type >::value);
3695 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3696 struct is_constructible_object_type
3697 : is_constructible_object_type_impl<BasicJsonType,
3698 ConstructibleObjectType> {};
3700 template<
typename BasicJsonType,
typename CompatibleStringType,
3702 struct is_compatible_string_type_impl : std::false_type {};
3704 template<
typename BasicJsonType,
typename CompatibleStringType>
3705 struct is_compatible_string_type_impl <
3706 BasicJsonType, CompatibleStringType,
3707 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3708 value_type_t, CompatibleStringType>::value >>
3710 static constexpr
auto value =
3711 is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3714 template<
typename BasicJsonType,
typename ConstructibleStringType>
3715 struct is_compatible_string_type
3716 : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3718 template<
typename BasicJsonType,
typename ConstructibleStringType,
3720 struct is_constructible_string_type_impl : std::false_type {};
3722 template<
typename BasicJsonType,
typename ConstructibleStringType>
3723 struct is_constructible_string_type_impl <
3724 BasicJsonType, ConstructibleStringType,
3725 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3726 value_type_t, ConstructibleStringType>::value >>
3728 static constexpr
auto value =
3729 is_constructible<ConstructibleStringType,
3730 typename BasicJsonType::string_t>::value;
3733 template<
typename BasicJsonType,
typename ConstructibleStringType>
3734 struct is_constructible_string_type
3735 : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3737 template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3738 struct is_compatible_array_type_impl : std::false_type {};
3740 template<
typename BasicJsonType,
typename CompatibleArrayType>
3741 struct is_compatible_array_type_impl <
3742 BasicJsonType, CompatibleArrayType,
3743 enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3744 is_detected<iterator_t, CompatibleArrayType>::value&&
3748 !is_iterator_traits <
3749 iterator_traits<CompatibleArrayType >>::value >>
3751 static constexpr
bool value =
3752 is_constructible<BasicJsonType,
3753 typename CompatibleArrayType::value_type>::value;
3756 template<
typename BasicJsonType,
typename CompatibleArrayType>
3757 struct is_compatible_array_type
3758 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3760 template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3761 struct is_constructible_array_type_impl : std::false_type {};
3763 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3764 struct is_constructible_array_type_impl <
3765 BasicJsonType, ConstructibleArrayType,
3766 enable_if_t<std::is_same<ConstructibleArrayType,
3767 typename BasicJsonType::value_type>::value >>
3768 : std::true_type {};
3770 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3771 struct is_constructible_array_type_impl <
3772 BasicJsonType, ConstructibleArrayType,
3773 enable_if_t < !std::is_same<ConstructibleArrayType,
3774 typename BasicJsonType::value_type>::value&&
3775 is_default_constructible<ConstructibleArrayType>::value&&
3776 (std::is_move_assignable<ConstructibleArrayType>::value ||
3777 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3778 is_detected<value_type_t, ConstructibleArrayType>::value&&
3779 is_detected<iterator_t, ConstructibleArrayType>::value&&
3781 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3783 static constexpr
bool value =
3789 !is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
3791 (std::is_same<
typename ConstructibleArrayType::value_type,
3792 typename BasicJsonType::array_t::value_type>::value ||
3793 has_from_json<BasicJsonType,
3794 typename ConstructibleArrayType::value_type>::value ||
3795 has_non_default_from_json <
3796 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
3799 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3800 struct is_constructible_array_type
3801 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3803 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3805 struct is_compatible_integer_type_impl : std::false_type {};
3807 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3808 struct is_compatible_integer_type_impl <
3809 RealIntegerType, CompatibleNumberIntegerType,
3810 enable_if_t < std::is_integral<RealIntegerType>::value&&
3811 std::is_integral<CompatibleNumberIntegerType>::value&&
3812 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3815 using RealLimits = std::numeric_limits<RealIntegerType>;
3816 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3818 static constexpr
auto value =
3819 is_constructible<RealIntegerType,
3820 CompatibleNumberIntegerType>::value &&
3821 CompatibleLimits::is_integer &&
3822 RealLimits::is_signed == CompatibleLimits::is_signed;
3825 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3826 struct is_compatible_integer_type
3827 : is_compatible_integer_type_impl<RealIntegerType,
3828 CompatibleNumberIntegerType> {};
3830 template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3831 struct is_compatible_type_impl: std::false_type {};
3833 template<
typename BasicJsonType,
typename CompatibleType>
3834 struct is_compatible_type_impl <
3835 BasicJsonType, CompatibleType,
3836 enable_if_t<is_complete_type<CompatibleType>::value >>
3838 static constexpr
bool value =
3839 has_to_json<BasicJsonType, CompatibleType>::value;
3842 template<
typename BasicJsonType,
typename CompatibleType>
3843 struct is_compatible_type
3844 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3846 template<
typename T1,
typename T2>
3847 struct is_constructible_tuple : std::false_type {};
3849 template<
typename T1,
typename... Args>
3850 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
3854 template <
typename T>
3855 struct is_ordered_map
3864 template <
typename C>
static one test( decltype(&C::capacity) ) ;
3865 template <
typename C>
static two test(...);
3867 enum { value =
sizeof(test<T>(
nullptr)) ==
sizeof(
char) };
3871 template < typename T, typename U, enable_if_t < !std::is_same<T, U>::value,
int > = 0 >
3872 T conditional_static_cast(U value)
3874 return static_cast<T
>(value);
3877 template<typename T, typename U, enable_if_t<std::is_same<T, U>::value,
int> = 0>
3878 T conditional_static_cast(U value)
3893 template<
typename BasicJsonType>
3894 void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
3896 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3898 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name()), j));
3904 template <
typename BasicJsonType,
typename ArithmeticType,
3905 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3906 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3908 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
3910 switch (
static_cast<value_t
>(j))
3912 case value_t::number_unsigned:
3914 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3917 case value_t::number_integer:
3919 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3922 case value_t::number_float:
3924 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3929 case value_t::object:
3930 case value_t::array:
3931 case value_t::string:
3932 case value_t::boolean:
3933 case value_t::binary:
3934 case value_t::discarded:
3936 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
3940 template<
typename BasicJsonType>
3941 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
3943 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3945 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name()), j));
3947 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3950 template<
typename BasicJsonType>
3951 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
3953 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3955 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3957 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3961 typename BasicJsonType,
typename ConstructibleStringType,
3963 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
3964 !std::is_same<
typename BasicJsonType::string_t,
3965 ConstructibleStringType>::value,
3967 void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
3969 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3971 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3974 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3977 template<
typename BasicJsonType>
3978 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
3980 get_arithmetic_value(j, val);
3983 template<
typename BasicJsonType>
3984 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
3986 get_arithmetic_value(j, val);
3989 template<
typename BasicJsonType>
3990 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
3992 get_arithmetic_value(j, val);
3995 template<
typename BasicJsonType,
typename EnumType,
3996 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
3997 void from_json(
const BasicJsonType& j, EnumType& e)
3999 typename std::underlying_type<EnumType>::type val;
4000 get_arithmetic_value(j, val);
4001 e =
static_cast<EnumType
>(val);
4005 template<
typename BasicJsonType,
typename T,
typename Allocator,
4006 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4007 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
4009 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4011 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4014 std::transform(j.rbegin(), j.rend(),
4015 std::front_inserter(l), [](
const BasicJsonType & i)
4017 return i.template get<T>();
4022 template<
typename BasicJsonType,
typename T,
4023 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
4024 void from_json(
const BasicJsonType& j, std::valarray<T>& l)
4026 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4028 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4031 std::transform(j.begin(), j.end(), std::begin(l),
4032 [](
const BasicJsonType & elem)
4034 return elem.template get<T>();
4038 template<
typename BasicJsonType,
typename T, std::
size_t N>
4039 auto from_json(
const BasicJsonType& j, T (&arr)[N])
4040 -> decltype(j.template get<T>(),
void())
4042 for (std::size_t i = 0; i < N; ++i)
4044 arr[i] = j.at(i).template get<T>();
4048 template<
typename BasicJsonType>
4049 void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
4051 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
4054 template<
typename BasicJsonType,
typename T, std::
size_t N>
4055 auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
4057 -> decltype(j.template get<T>(),
void())
4059 for (std::size_t i = 0; i < N; ++i)
4061 arr[i] = j.at(i).template get<T>();
4065 template<
typename BasicJsonType,
typename ConstructibleArrayType,
4067 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4069 auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4071 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4072 j.template get<typename ConstructibleArrayType::value_type>(),
4077 ConstructibleArrayType ret;
4078 ret.reserve(j.size());
4079 std::transform(j.begin(), j.end(),
4080 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4084 return i.template get<typename ConstructibleArrayType::value_type>();
4086 arr = std::move(ret);
4089 template<
typename BasicJsonType,
typename ConstructibleArrayType,
4091 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4093 void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4098 ConstructibleArrayType ret;
4100 j.begin(), j.end(), std::inserter(ret, end(ret)),
4101 [](
const BasicJsonType & i)
4105 return i.template get<typename ConstructibleArrayType::value_type>();
4107 arr = std::move(ret);
4110 template <
typename BasicJsonType,
typename ConstructibleArrayType,
4112 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4113 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4114 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4115 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4116 !is_basic_json<ConstructibleArrayType>::value,
4118 auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4119 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4120 j.template get<typename ConstructibleArrayType::value_type>(),
4123 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4125 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4128 from_json_array_impl(j, arr, priority_tag<3> {});
4131 template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4132 std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4133 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4135 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4138 template <
typename BasicJsonType,
typename T, std::
size_t N >
4139 auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4140 -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4142 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4144 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4147 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4150 template<
typename BasicJsonType>
4151 void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4153 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4155 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name()), j));
4158 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4161 template<
typename BasicJsonType,
typename ConstructibleObjectType,
4162 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4163 void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4165 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4167 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name()), j));
4170 ConstructibleObjectType ret;
4171 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4172 using value_type =
typename ConstructibleObjectType::value_type;
4174 inner_object->begin(), inner_object->end(),
4175 std::inserter(ret, ret.begin()),
4176 [](
typename BasicJsonType::object_t::value_type
const & p)
4178 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4180 obj = std::move(ret);
4187 template <
typename BasicJsonType,
typename ArithmeticType,
4189 std::is_arithmetic<ArithmeticType>::value&&
4190 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4191 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4192 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4193 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4195 void from_json(
const BasicJsonType& j, ArithmeticType& val)
4197 switch (
static_cast<value_t
>(j))
4199 case value_t::number_unsigned:
4201 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4204 case value_t::number_integer:
4206 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4209 case value_t::number_float:
4211 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4214 case value_t::boolean:
4216 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4221 case value_t::object:
4222 case value_t::array:
4223 case value_t::string:
4224 case value_t::binary:
4225 case value_t::discarded:
4227 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4231 template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4232 std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
4234 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4237 template <
typename BasicJsonType,
class A1,
class A2 >
4238 std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4240 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4241 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4244 template<
typename BasicJsonType,
typename A1,
typename A2>
4245 void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
4247 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4250 template<
typename BasicJsonType,
typename... Args>
4251 std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4253 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4256 template<
typename BasicJsonType,
typename... Args>
4257 void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
4259 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4262 template<
typename BasicJsonType,
typename TupleRelated>
4263 auto from_json(BasicJsonType&& j, TupleRelated&& t)
4264 -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4266 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4268 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4271 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4274 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4275 typename = enable_if_t < !std::is_constructible <
4276 typename BasicJsonType::string_t, Key >::value >>
4277 void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4279 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4281 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4284 for (
const auto& p : j)
4286 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4288 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4290 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4294 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
4295 typename = enable_if_t < !std::is_constructible <
4296 typename BasicJsonType::string_t, Key >::value >>
4297 void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4299 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4301 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4304 for (
const auto& p : j)
4306 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4308 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4310 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4316 template<
typename BasicJsonType,
typename T>
4317 auto operator()(
const BasicJsonType& j, T&& val)
const
4318 noexcept(noexcept(
from_json(j, std::forward<T>(val))))
4319 -> decltype(
from_json(j, std::forward<T>(val)))
4321 return from_json(j, std::forward<T>(val));
4331 constexpr
const auto&
from_json = detail::static_const<detail::from_json_fn>::value;
4338 #include <algorithm>
4342 #include <type_traits>
4365 template<
typename string_type>
4366 void int_to_string( string_type& target, std::size_t value )
4369 using std::to_string;
4372 template<
typename IteratorType>
class iteration_proxy_value
4375 using difference_type = std::ptrdiff_t;
4376 using value_type = iteration_proxy_value;
4377 using pointer = value_type * ;
4378 using reference = value_type & ;
4379 using iterator_category = std::input_iterator_tag;
4380 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4384 IteratorType anchor;
4386 std::size_t array_index = 0;
4388 mutable std::size_t array_index_last = 0;
4390 mutable string_type array_index_str =
"0";
4392 const string_type empty_str{};
4395 explicit iteration_proxy_value(IteratorType it) noexcept
4396 : anchor(std::move(it))
4400 iteration_proxy_value& operator*()
4406 iteration_proxy_value& operator++()
4415 bool operator==(
const iteration_proxy_value& o)
const
4417 return anchor == o.anchor;
4421 bool operator!=(
const iteration_proxy_value& o)
const
4423 return anchor != o.anchor;
4427 const string_type& key()
const
4429 JSON_ASSERT(anchor.m_object !=
nullptr);
4431 switch (anchor.m_object->type())
4434 case value_t::array:
4436 if (array_index != array_index_last)
4438 int_to_string( array_index_str, array_index );
4439 array_index_last = array_index;
4441 return array_index_str;
4445 case value_t::object:
4446 return anchor.key();
4450 case value_t::string:
4451 case value_t::boolean:
4452 case value_t::number_integer:
4453 case value_t::number_unsigned:
4454 case value_t::number_float:
4455 case value_t::binary:
4456 case value_t::discarded:
4463 typename IteratorType::reference value()
const
4465 return anchor.value();
4470 template<
typename IteratorType>
class iteration_proxy
4474 typename IteratorType::reference container;
4478 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
4479 : container(cont) {}
4482 iteration_proxy_value<IteratorType> begin() noexcept
4484 return iteration_proxy_value<IteratorType>(container.begin());
4488 iteration_proxy_value<IteratorType> end() noexcept
4490 return iteration_proxy_value<IteratorType>(container.end());
4496 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
4497 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
4504 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
4505 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
4518 #if defined(__clang__)
4520 #pragma clang diagnostic push
4521 #pragma clang diagnostic ignored "-Wmismatched-tags"
4523 template<
typename IteratorType>
4524 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4525 :
public std::integral_constant<std::size_t, 2> {};
4527 template<std::
size_t N,
typename IteratorType>
4528 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4531 using type = decltype(
4532 get<N>(std::declval <
4533 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4535 #if defined(__clang__)
4536 #pragma clang diagnostic pop
4562 template<value_t>
struct external_constructor;
4565 struct external_constructor<value_t::boolean>
4567 template<
typename BasicJsonType>
4568 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b) noexcept
4570 j.m_value.destroy(j.m_type);
4571 j.m_type = value_t::boolean;
4573 j.assert_invariant();
4578 struct external_constructor<value_t::string>
4580 template<
typename BasicJsonType>
4581 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
4583 j.m_value.destroy(j.m_type);
4584 j.m_type = value_t::string;
4586 j.assert_invariant();
4589 template<
typename BasicJsonType>
4590 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4592 j.m_value.destroy(j.m_type);
4593 j.m_type = value_t::string;
4594 j.m_value = std::move(s);
4595 j.assert_invariant();
4598 template <
typename BasicJsonType,
typename CompatibleStringType,
4599 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4601 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
4603 j.m_value.destroy(j.m_type);
4604 j.m_type = value_t::string;
4605 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4606 j.assert_invariant();
4611 struct external_constructor<value_t::binary>
4613 template<
typename BasicJsonType>
4614 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
4616 j.m_value.destroy(j.m_type);
4617 j.m_type = value_t::binary;
4618 j.m_value =
typename BasicJsonType::binary_t(b);
4619 j.assert_invariant();
4622 template<
typename BasicJsonType>
4623 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
4625 j.m_value.destroy(j.m_type);
4626 j.m_type = value_t::binary;
4627 j.m_value =
typename BasicJsonType::binary_t(std::move(b));
4628 j.assert_invariant();
4633 struct external_constructor<value_t::number_float>
4635 template<
typename BasicJsonType>
4636 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
4638 j.m_value.destroy(j.m_type);
4639 j.m_type = value_t::number_float;
4641 j.assert_invariant();
4646 struct external_constructor<value_t::number_unsigned>
4648 template<
typename BasicJsonType>
4649 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
4651 j.m_value.destroy(j.m_type);
4652 j.m_type = value_t::number_unsigned;
4654 j.assert_invariant();
4659 struct external_constructor<value_t::number_integer>
4661 template<
typename BasicJsonType>
4662 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
4664 j.m_value.destroy(j.m_type);
4665 j.m_type = value_t::number_integer;
4667 j.assert_invariant();
4672 struct external_constructor<value_t::array>
4674 template<
typename BasicJsonType>
4675 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
4677 j.m_value.destroy(j.m_type);
4678 j.m_type = value_t::array;
4681 j.assert_invariant();
4684 template<
typename BasicJsonType>
4685 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4687 j.m_value.destroy(j.m_type);
4688 j.m_type = value_t::array;
4689 j.m_value = std::move(arr);
4691 j.assert_invariant();
4694 template <
typename BasicJsonType,
typename CompatibleArrayType,
4695 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4697 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
4702 j.m_value.destroy(j.m_type);
4703 j.m_type = value_t::array;
4704 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4706 j.assert_invariant();
4709 template<
typename BasicJsonType>
4710 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
4712 j.m_value.destroy(j.m_type);
4713 j.m_type = value_t::array;
4714 j.m_value = value_t::array;
4715 j.m_value.array->reserve(arr.size());
4716 for (
const bool x : arr)
4718 j.m_value.array->push_back(x);
4719 j.set_parent(j.m_value.array->back());
4721 j.assert_invariant();
4724 template<
typename BasicJsonType,
typename T,
4725 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4726 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
4728 j.m_value.destroy(j.m_type);
4729 j.m_type = value_t::array;
4730 j.m_value = value_t::array;
4731 j.m_value.array->resize(arr.size());
4734 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4737 j.assert_invariant();
4742 struct external_constructor<value_t::object>
4744 template<
typename BasicJsonType>
4745 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
4747 j.m_value.destroy(j.m_type);
4748 j.m_type = value_t::object;
4751 j.assert_invariant();
4754 template<
typename BasicJsonType>
4755 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4757 j.m_value.destroy(j.m_type);
4758 j.m_type = value_t::object;
4759 j.m_value = std::move(obj);
4761 j.assert_invariant();
4764 template <
typename BasicJsonType,
typename CompatibleObjectType,
4765 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4766 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
4771 j.m_value.destroy(j.m_type);
4772 j.m_type = value_t::object;
4773 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4775 j.assert_invariant();
4783 template<
typename BasicJsonType,
typename T,
4784 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4785 void to_json(BasicJsonType& j, T b) noexcept
4787 external_constructor<value_t::boolean>::construct(j, b);
4790 template<
typename BasicJsonType,
typename CompatibleString,
4791 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4792 void to_json(BasicJsonType& j,
const CompatibleString& s)
4794 external_constructor<value_t::string>::construct(j, s);
4797 template<
typename BasicJsonType>
4798 void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4800 external_constructor<value_t::string>::construct(j, std::move(s));
4803 template<
typename BasicJsonType,
typename FloatType,
4804 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4805 void to_json(BasicJsonType& j, FloatType val) noexcept
4807 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4810 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4811 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4812 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4814 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4817 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4818 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4819 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4821 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4824 template<
typename BasicJsonType,
typename EnumType,
4825 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4826 void to_json(BasicJsonType& j, EnumType e) noexcept
4828 using underlying_type =
typename std::underlying_type<EnumType>::type;
4829 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4832 template<
typename BasicJsonType>
4833 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
4835 external_constructor<value_t::array>::construct(j, e);
4838 template <
typename BasicJsonType,
typename CompatibleArrayType,
4839 enable_if_t < is_compatible_array_type<BasicJsonType,
4840 CompatibleArrayType>::value&&
4841 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4842 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4843 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4844 !is_basic_json<CompatibleArrayType>::value,
4846 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4848 external_constructor<value_t::array>::construct(j, arr);
4851 template<
typename BasicJsonType>
4852 void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
4854 external_constructor<value_t::binary>::construct(j, bin);
4857 template<
typename BasicJsonType,
typename T,
4858 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4859 void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4861 external_constructor<value_t::array>::construct(j, std::move(arr));
4864 template<
typename BasicJsonType>
4865 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4867 external_constructor<value_t::array>::construct(j, std::move(arr));
4870 template <
typename BasicJsonType,
typename CompatibleObjectType,
4871 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4872 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4874 external_constructor<value_t::object>::construct(j, obj);
4877 template<
typename BasicJsonType>
4878 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4880 external_constructor<value_t::object>::construct(j, std::move(obj));
4884 typename BasicJsonType,
typename T, std::size_t N,
4885 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4886 const T(&)[N]>::value,
4888 void to_json(BasicJsonType& j,
const T(&arr)[N])
4890 external_constructor<value_t::array>::construct(j, arr);
4893 template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4894 void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
4896 j = { p.first, p.second };
4900 template<
typename BasicJsonType,
typename T,
4901 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4902 void to_json(BasicJsonType& j,
const T& b)
4904 j = { {b.key(), b.value()} };
4907 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4908 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
4910 j = { std::get<Idx>(t)... };
4913 template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4914 void to_json(BasicJsonType& j,
const T& t)
4916 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4921 template<
typename BasicJsonType,
typename T>
4922 auto operator()(BasicJsonType& j, T&& val)
const noexcept(noexcept(
to_json(j, std::forward<T>(val))))
4923 -> decltype(
to_json(j, std::forward<T>(val)),
void())
4925 return to_json(j, std::forward<T>(val));
4935 constexpr
const auto&
to_json = detail::static_const<detail::to_json_fn>::value;
4947 template<
typename ValueType,
typename>
4961 template<
typename BasicJsonType,
typename TargetType = ValueType>
4962 static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
4963 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4964 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
4966 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4981 template<
typename BasicJsonType,
typename TargetType = ValueType>
4983 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
4984 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
4986 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
4998 template<
typename BasicJsonType,
typename TargetType = ValueType>
4999 static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
5000 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
5001 -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
5003 ::nlohmann::to_json(j, std::forward<TargetType>(val));
5031 template<
typename BinaryType>
5054 , m_subtype(subtype_)
5055 , m_has_subtype(true)
5060 , m_subtype(subtype_)
5061 , m_has_subtype(true)
5066 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
5067 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
5072 return !(rhs == *
this);
5095 m_subtype = subtype_;
5096 m_has_subtype =
true;
5144 return m_has_subtype;
5169 m_has_subtype =
false;
5174 bool m_has_subtype =
false;
5190 #include <functional>
5203 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
5205 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5220 template<
typename BasicJsonType>
5221 std::size_t hash(
const BasicJsonType& j)
5223 using string_t =
typename BasicJsonType::string_t;
5224 using number_integer_t =
typename BasicJsonType::number_integer_t;
5225 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5226 using number_float_t =
typename BasicJsonType::number_float_t;
5228 const auto type =
static_cast<std::size_t
>(j.type());
5231 case BasicJsonType::value_t::null:
5232 case BasicJsonType::value_t::discarded:
5234 return combine(type, 0);
5237 case BasicJsonType::value_t::object:
5239 auto seed = combine(type, j.size());
5240 for (
const auto& element : j.items())
5242 const auto h = std::hash<string_t> {}(element.key());
5243 seed = combine(seed, h);
5244 seed = combine(seed, hash(element.value()));
5249 case BasicJsonType::value_t::array:
5251 auto seed = combine(type, j.size());
5252 for (
const auto& element : j)
5254 seed = combine(seed, hash(element));
5259 case BasicJsonType::value_t::string:
5261 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5262 return combine(type, h);
5265 case BasicJsonType::value_t::boolean:
5267 const auto h = std::hash<bool> {}(j.template get<bool>());
5268 return combine(type, h);
5271 case BasicJsonType::value_t::number_integer:
5273 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5274 return combine(type, h);
5277 case BasicJsonType::value_t::number_unsigned:
5279 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5280 return combine(type, h);
5283 case BasicJsonType::value_t::number_float:
5285 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5286 return combine(type, h);
5289 case BasicJsonType::value_t::binary:
5291 auto seed = combine(type, j.get_binary().size());
5292 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5293 seed = combine(seed, h);
5294 seed = combine(seed,
static_cast<std::size_t
>(j.get_binary().subtype()));
5295 for (
const auto byte : j.get_binary())
5297 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5314 #include <algorithm>
5339 #include <type_traits>
5357 enum class input_format_t {
json, cbor, msgpack, ubjson, bson };
5368 class file_input_adapter
5371 using char_type = char;
5373 JSON_HEDLEY_NON_NULL(2)
5374 explicit file_input_adapter(std::FILE* f) noexcept
5379 file_input_adapter(
const file_input_adapter&) =
delete;
5380 file_input_adapter(file_input_adapter&&) noexcept = default;
5381 file_input_adapter& operator=(const file_input_adapter&) = delete;
5382 file_input_adapter& operator=(file_input_adapter&&) = delete;
5383 ~file_input_adapter() = default;
5385 std::char_traits<
char>::int_type get_character() noexcept
5387 return std::fgetc(m_file);
5405 class input_stream_adapter
5408 using char_type = char;
5410 ~input_stream_adapter()
5416 is->clear(is->rdstate() & std::ios::eofbit);
5420 explicit input_stream_adapter(std::istream& i)
5421 : is(&i), sb(i.rdbuf())
5425 input_stream_adapter(
const input_stream_adapter&) =
delete;
5426 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
5427 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
5429 input_stream_adapter(input_stream_adapter&& rhs) noexcept
5430 : is(rhs.is), sb(rhs.sb)
5439 std::char_traits<char>::int_type get_character()
5441 auto res = sb->sbumpc();
5443 if (JSON_HEDLEY_UNLIKELY(res == std::char_traits<char>::eof()))
5445 is->clear(is->rdstate() | std::ios::eofbit);
5452 std::istream* is =
nullptr;
5453 std::streambuf* sb =
nullptr;
5459 template<
typename IteratorType>
5460 class iterator_input_adapter
5463 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
5465 iterator_input_adapter(IteratorType first, IteratorType last)
5466 : current(std::move(first)), end(std::move(last))
5469 typename std::char_traits<char_type>::int_type get_character()
5471 if (JSON_HEDLEY_LIKELY(current != end))
5473 auto result = std::char_traits<char_type>::to_int_type(*current);
5474 std::advance(current, 1);
5478 return std::char_traits<char_type>::eof();
5482 IteratorType current;
5485 template<
typename BaseInputAdapter,
size_t T>
5486 friend struct wide_string_input_helper;
5490 return current == end;
5495 template<
typename BaseInputAdapter,
size_t T>
5496 struct wide_string_input_helper;
5498 template<
typename BaseInputAdapter>
5499 struct wide_string_input_helper<BaseInputAdapter, 4>
5502 static void fill_buffer(BaseInputAdapter& input,
5503 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5504 size_t& utf8_bytes_index,
5505 size_t& utf8_bytes_filled)
5507 utf8_bytes_index = 0;
5509 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5511 utf8_bytes[0] = std::char_traits<char>::eof();
5512 utf8_bytes_filled = 1;
5517 const auto wc = input.get_character();
5522 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5523 utf8_bytes_filled = 1;
5525 else if (wc <= 0x7FF)
5527 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5528 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5529 utf8_bytes_filled = 2;
5531 else if (wc <= 0xFFFF)
5533 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5534 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5535 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5536 utf8_bytes_filled = 3;
5538 else if (wc <= 0x10FFFF)
5540 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5541 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5542 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5543 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5544 utf8_bytes_filled = 4;
5549 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5550 utf8_bytes_filled = 1;
5556 template<
typename BaseInputAdapter>
5557 struct wide_string_input_helper<BaseInputAdapter, 2>
5560 static void fill_buffer(BaseInputAdapter& input,
5561 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5562 size_t& utf8_bytes_index,
5563 size_t& utf8_bytes_filled)
5565 utf8_bytes_index = 0;
5567 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5569 utf8_bytes[0] = std::char_traits<char>::eof();
5570 utf8_bytes_filled = 1;
5575 const auto wc = input.get_character();
5580 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5581 utf8_bytes_filled = 1;
5583 else if (wc <= 0x7FF)
5585 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
5586 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5587 utf8_bytes_filled = 2;
5589 else if (0xD800 > wc || wc >= 0xE000)
5591 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
5592 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5593 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5594 utf8_bytes_filled = 3;
5598 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5600 const auto wc2 =
static_cast<unsigned int>(input.get_character());
5601 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5602 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
5603 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
5604 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
5605 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
5606 utf8_bytes_filled = 4;
5610 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5611 utf8_bytes_filled = 1;
5619 template<
typename BaseInputAdapter,
typename W
ideCharType>
5620 class wide_string_input_adapter
5623 using char_type = char;
5625 wide_string_input_adapter(BaseInputAdapter base)
5626 : base_adapter(base) {}
5628 typename std::char_traits<char>::int_type get_character() noexcept
5631 if (utf8_bytes_index == utf8_bytes_filled)
5633 fill_buffer<sizeof(WideCharType)>();
5635 JSON_ASSERT(utf8_bytes_filled > 0);
5636 JSON_ASSERT(utf8_bytes_index == 0);
5640 JSON_ASSERT(utf8_bytes_filled > 0);
5641 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5642 return utf8_bytes[utf8_bytes_index++];
5646 BaseInputAdapter base_adapter;
5651 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5655 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5658 std::size_t utf8_bytes_index = 0;
5660 std::size_t utf8_bytes_filled = 0;
5664 template<
typename IteratorType,
typename Enable =
void>
5665 struct iterator_input_adapter_factory
5667 using iterator_type = IteratorType;
5668 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5669 using adapter_type = iterator_input_adapter<iterator_type>;
5671 static adapter_type create(IteratorType first, IteratorType last)
5673 return adapter_type(std::move(first), std::move(last));
5677 template<
typename T>
5678 struct is_iterator_of_multibyte
5680 using value_type =
typename std::iterator_traits<T>::value_type;
5683 value =
sizeof(value_type) > 1
5687 template<
typename IteratorType>
5688 struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5690 using iterator_type = IteratorType;
5691 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5692 using base_adapter_type = iterator_input_adapter<iterator_type>;
5693 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5695 static adapter_type create(IteratorType first, IteratorType last)
5697 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5702 template<
typename IteratorType>
5703 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5705 using factory_type = iterator_input_adapter_factory<IteratorType>;
5706 return factory_type::create(first, last);
5713 namespace container_input_adapter_factory_impl
5719 template<
typename ContainerType,
typename Enable =
void>
5720 struct container_input_adapter_factory {};
5722 template<
typename ContainerType>
5723 struct container_input_adapter_factory< ContainerType,
5724 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5726 using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5728 static adapter_type create(
const ContainerType& container)
5730 return input_adapter(begin(container), end(container));
5736 template<
typename ContainerType>
5737 typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
5739 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
5744 inline file_input_adapter input_adapter(std::FILE* file)
5746 return file_input_adapter(file);
5749 inline input_stream_adapter input_adapter(std::istream& stream)
5751 return input_stream_adapter(stream);
5754 inline input_stream_adapter input_adapter(std::istream&& stream)
5756 return input_stream_adapter(stream);
5760 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5763 template <
typename CharT,
5764 typename std::enable_if <
5765 std::is_pointer<CharT>::value&&
5766 !std::is_array<CharT>::value&&
5767 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5768 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5770 contiguous_bytes_input_adapter input_adapter(CharT b)
5772 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
5773 const auto* ptr =
reinterpret_cast<const char*
>(b);
5774 return input_adapter(ptr, ptr + length);
5777 template<
typename T, std::
size_t N>
5778 auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
5780 return input_adapter(array, array + N);
5786 class span_input_adapter
5789 template <
typename CharT,
5790 typename std::enable_if <
5791 std::is_pointer<CharT>::value&&
5792 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5793 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5795 span_input_adapter(CharT b, std::size_t l)
5796 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5798 template<
class IteratorType,
5799 typename std::enable_if<
5800 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5802 span_input_adapter(IteratorType first, IteratorType last)
5803 : ia(input_adapter(first, last)) {}
5805 contiguous_bytes_input_adapter&& get()
5807 return std::move(ia);
5811 contiguous_bytes_input_adapter ia;
5840 template<
typename BasicJsonType>
5853 virtual bool null() = 0;
5944 const std::string& last_token,
5945 const detail::exception& ex) = 0;
5971 template<
typename BasicJsonType>
5972 class json_sax_dom_parser
5978 using string_t =
typename BasicJsonType::string_t;
5979 using binary_t =
typename BasicJsonType::binary_t;
5986 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true)
5987 : root(r), allow_exceptions(allow_exceptions_)
5991 json_sax_dom_parser(
const json_sax_dom_parser&) =
delete;
5992 json_sax_dom_parser(json_sax_dom_parser&&) =
default;
5993 json_sax_dom_parser&
operator=(
const json_sax_dom_parser&) =
delete;
5994 json_sax_dom_parser&
operator=(json_sax_dom_parser&&) =
default;
5995 ~json_sax_dom_parser() =
default;
5999 handle_value(
nullptr);
6035 handle_value(std::move(val));
6041 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
6043 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6045 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6054 object_element = &(ref_stack.back()->m_value.object->operator[](val));
6060 ref_stack.back()->set_parents();
6061 ref_stack.pop_back();
6067 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
6069 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6071 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6079 ref_stack.back()->set_parents();
6080 ref_stack.pop_back();
6084 template<
class Exception>
6085 bool parse_error(std::size_t ,
const std::string& ,
6086 const Exception& ex)
6089 static_cast<void>(ex);
6090 if (allow_exceptions)
6097 constexpr
bool is_errored()
const
6109 template<
typename Value>
6111 BasicJsonType* handle_value(Value&& v)
6113 if (ref_stack.empty())
6115 root = BasicJsonType(std::forward<Value>(v));
6119 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6121 if (ref_stack.back()->is_array())
6123 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6124 return &(ref_stack.back()->m_value.array->back());
6127 JSON_ASSERT(ref_stack.back()->is_object());
6128 JSON_ASSERT(object_element);
6129 *object_element = BasicJsonType(std::forward<Value>(v));
6130 return object_element;
6134 BasicJsonType& root;
6136 std::vector<BasicJsonType*> ref_stack {};
6138 BasicJsonType* object_element =
nullptr;
6140 bool errored =
false;
6142 const bool allow_exceptions =
true;
6145 template<
typename BasicJsonType>
6146 class json_sax_dom_callback_parser
6152 using string_t =
typename BasicJsonType::string_t;
6153 using binary_t =
typename BasicJsonType::binary_t;
6154 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6155 using parse_event_t =
typename BasicJsonType::parse_event_t;
6157 json_sax_dom_callback_parser(BasicJsonType& r,
6158 const parser_callback_t cb,
6159 const bool allow_exceptions_ =
true)
6160 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6162 keep_stack.push_back(
true);
6166 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
6167 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
6168 json_sax_dom_callback_parser&
operator=(
const json_sax_dom_callback_parser&) =
delete;
6169 json_sax_dom_callback_parser&
operator=(json_sax_dom_callback_parser&&) =
default;
6170 ~json_sax_dom_callback_parser() =
default;
6174 handle_value(
nullptr);
6210 handle_value(std::move(val));
6217 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
6218 keep_stack.push_back(keep);
6220 auto val = handle_value(BasicJsonType::value_t::object,
true);
6221 ref_stack.push_back(val.second);
6224 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6226 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6234 BasicJsonType k = BasicJsonType(val);
6237 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
6238 key_keep_stack.push_back(keep);
6241 if (keep && ref_stack.back())
6243 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
6251 if (ref_stack.back())
6253 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6256 *ref_stack.back() = discarded;
6260 ref_stack.back()->set_parents();
6264 JSON_ASSERT(!ref_stack.empty());
6265 JSON_ASSERT(!keep_stack.empty());
6266 ref_stack.pop_back();
6267 keep_stack.pop_back();
6269 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6272 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6274 if (it->is_discarded())
6276 ref_stack.back()->erase(it);
6287 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
6288 keep_stack.push_back(keep);
6290 auto val = handle_value(BasicJsonType::value_t::array,
true);
6291 ref_stack.push_back(val.second);
6294 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6296 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6306 if (ref_stack.back())
6308 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6311 ref_stack.back()->set_parents();
6316 *ref_stack.back() = discarded;
6320 JSON_ASSERT(!ref_stack.empty());
6321 JSON_ASSERT(!keep_stack.empty());
6322 ref_stack.pop_back();
6323 keep_stack.pop_back();
6326 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6328 ref_stack.back()->m_value.array->pop_back();
6334 template<
class Exception>
6335 bool parse_error(std::size_t ,
const std::string& ,
6336 const Exception& ex)
6339 static_cast<void>(ex);
6340 if (allow_exceptions)
6347 constexpr
bool is_errored()
const
6368 template<
typename Value>
6369 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
6371 JSON_ASSERT(!keep_stack.empty());
6375 if (!keep_stack.back())
6377 return {
false,
nullptr};
6381 auto value = BasicJsonType(std::forward<Value>(v));
6384 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6389 return {
false,
nullptr};
6392 if (ref_stack.empty())
6394 root = std::move(value);
6395 return {
true, &root};
6400 if (!ref_stack.back())
6402 return {
false,
nullptr};
6406 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6409 if (ref_stack.back()->is_array())
6411 ref_stack.back()->m_value.array->emplace_back(std::move(value));
6412 return {
true, &(ref_stack.back()->m_value.array->back())};
6416 JSON_ASSERT(ref_stack.back()->is_object());
6418 JSON_ASSERT(!key_keep_stack.empty());
6419 const bool store_element = key_keep_stack.back();
6420 key_keep_stack.pop_back();
6424 return {
false,
nullptr};
6427 JSON_ASSERT(object_element);
6428 *object_element = std::move(value);
6429 return {
true, object_element};
6433 BasicJsonType& root;
6435 std::vector<BasicJsonType*> ref_stack {};
6437 std::vector<bool> keep_stack {};
6439 std::vector<bool> key_keep_stack {};
6441 BasicJsonType* object_element =
nullptr;
6443 bool errored =
false;
6445 const parser_callback_t callback =
nullptr;
6447 const bool allow_exceptions =
true;
6449 BasicJsonType discarded = BasicJsonType::value_t::discarded;
6452 template<
typename BasicJsonType>
6453 class json_sax_acceptor
6459 using string_t =
typename BasicJsonType::string_t;
6460 using binary_t =
typename BasicJsonType::binary_t;
6522 bool parse_error(std::size_t ,
const std::string& ,
const detail::exception& )
6539 #include <initializer_list>
6559 template<
typename BasicJsonType>
6564 enum class token_type
6588 static const char* token_type_name(
const token_type t) noexcept
6592 case token_type::uninitialized:
6593 return "<uninitialized>";
6594 case token_type::literal_true:
6595 return "true literal";
6596 case token_type::literal_false:
6597 return "false literal";
6598 case token_type::literal_null:
6599 return "null literal";
6600 case token_type::value_string:
6601 return "string literal";
6602 case token_type::value_unsigned:
6603 case token_type::value_integer:
6604 case token_type::value_float:
6605 return "number literal";
6606 case token_type::begin_array:
6608 case token_type::begin_object:
6610 case token_type::end_array:
6612 case token_type::end_object:
6614 case token_type::name_separator:
6616 case token_type::value_separator:
6618 case token_type::parse_error:
6619 return "<parse error>";
6620 case token_type::end_of_input:
6621 return "end of input";
6622 case token_type::literal_or_value:
6623 return "'[', '{', or a literal";
6626 return "unknown token";
6636 template<
typename BasicJsonType,
typename InputAdapterType>
6637 class lexer :
public lexer_base<BasicJsonType>
6639 using number_integer_t =
typename BasicJsonType::number_integer_t;
6640 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6641 using number_float_t =
typename BasicJsonType::number_float_t;
6642 using string_t =
typename BasicJsonType::string_t;
6643 using char_type =
typename InputAdapterType::char_type;
6644 using char_int_type =
typename std::char_traits<char_type>::int_type;
6647 using token_type =
typename lexer_base<BasicJsonType>::token_type;
6649 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
6650 : ia(std::move(adapter))
6651 , ignore_comments(ignore_comments_)
6652 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6656 lexer(
const lexer&) =
delete;
6657 lexer(lexer&&) =
default;
6658 lexer& operator=(lexer&) =
delete;
6659 lexer& operator=(lexer&&) =
default;
6669 static char get_decimal_point() noexcept
6671 const auto* loc = localeconv();
6672 JSON_ASSERT(loc !=
nullptr);
6673 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6698 JSON_ASSERT(current ==
'u');
6701 const auto factors = { 12u, 8u, 4u, 0u };
6702 for (
const auto factor : factors)
6706 if (current >=
'0' && current <=
'9')
6708 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
6710 else if (current >=
'A' && current <=
'F')
6712 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
6714 else if (current >=
'a' && current <=
'f')
6716 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
6724 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6743 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6745 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6748 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6751 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6757 error_message =
"invalid string: ill-formed UTF-8 byte";
6780 token_type scan_string()
6786 JSON_ASSERT(current ==
'\"');
6794 case std::char_traits<char_type>::eof():
6796 error_message =
"invalid string: missing closing quote";
6797 return token_type::parse_error;
6803 return token_type::value_string;
6847 const int codepoint1 = get_codepoint();
6848 int codepoint = codepoint1;
6850 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6852 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6853 return token_type::parse_error;
6857 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6860 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6862 const int codepoint2 = get_codepoint();
6864 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6866 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6867 return token_type::parse_error;
6871 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6874 codepoint =
static_cast<int>(
6876 (
static_cast<unsigned int>(codepoint1) << 10u)
6878 +
static_cast<unsigned int>(codepoint2)
6886 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6887 return token_type::parse_error;
6892 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6893 return token_type::parse_error;
6898 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6900 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6901 return token_type::parse_error;
6906 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6909 if (codepoint < 0x80)
6912 add(
static_cast<char_int_type
>(codepoint));
6914 else if (codepoint <= 0x7FF)
6917 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6918 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6920 else if (codepoint <= 0xFFFF)
6923 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
6924 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6925 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6930 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
6931 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6932 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6933 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6941 error_message =
"invalid string: forbidden character after backslash";
6942 return token_type::parse_error;
6951 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6952 return token_type::parse_error;
6957 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6958 return token_type::parse_error;
6963 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6964 return token_type::parse_error;
6969 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6970 return token_type::parse_error;
6975 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6976 return token_type::parse_error;
6981 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6982 return token_type::parse_error;
6987 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6988 return token_type::parse_error;
6993 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6994 return token_type::parse_error;
6999 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
7000 return token_type::parse_error;
7005 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
7006 return token_type::parse_error;
7011 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
7012 return token_type::parse_error;
7017 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
7018 return token_type::parse_error;
7023 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
7024 return token_type::parse_error;
7029 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
7030 return token_type::parse_error;
7035 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
7036 return token_type::parse_error;
7041 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
7042 return token_type::parse_error;
7047 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
7048 return token_type::parse_error;
7053 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
7054 return token_type::parse_error;
7059 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
7060 return token_type::parse_error;
7065 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
7066 return token_type::parse_error;
7071 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
7072 return token_type::parse_error;
7077 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
7078 return token_type::parse_error;
7083 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
7084 return token_type::parse_error;
7089 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
7090 return token_type::parse_error;
7095 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
7096 return token_type::parse_error;
7101 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
7102 return token_type::parse_error;
7107 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
7108 return token_type::parse_error;
7113 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
7114 return token_type::parse_error;
7119 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7120 return token_type::parse_error;
7125 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7126 return token_type::parse_error;
7131 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7132 return token_type::parse_error;
7137 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7138 return token_type::parse_error;
7273 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7275 return token_type::parse_error;
7283 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7285 return token_type::parse_error;
7307 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7309 return token_type::parse_error;
7317 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7319 return token_type::parse_error;
7327 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7329 return token_type::parse_error;
7339 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7341 return token_type::parse_error;
7349 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7351 return token_type::parse_error;
7359 error_message =
"invalid string: ill-formed UTF-8 byte";
7360 return token_type::parse_error;
7383 case std::char_traits<char_type>::eof():
7400 case std::char_traits<char_type>::eof():
7403 error_message =
"invalid comment; missing closing '*/'";
7431 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7437 JSON_HEDLEY_NON_NULL(2)
7438 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7440 f = std::strtof(str, endptr);
7443 JSON_HEDLEY_NON_NULL(2)
7444 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7446 f = std::strtod(str, endptr);
7449 JSON_HEDLEY_NON_NULL(2)
7450 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
7452 f = std::strtold(str, endptr);
7495 token_type scan_number()
7502 token_type number_type = token_type::value_unsigned;
7510 goto scan_number_minus;
7516 goto scan_number_zero;
7530 goto scan_number_any1;
7540 number_type = token_type::value_integer;
7546 goto scan_number_zero;
7560 goto scan_number_any1;
7565 error_message =
"invalid number; expected digit after '-'";
7566 return token_type::parse_error;
7576 add(decimal_point_char);
7577 goto scan_number_decimal1;
7584 goto scan_number_exponent;
7588 goto scan_number_done;
7607 goto scan_number_any1;
7612 add(decimal_point_char);
7613 goto scan_number_decimal1;
7620 goto scan_number_exponent;
7624 goto scan_number_done;
7627 scan_number_decimal1:
7629 number_type = token_type::value_float;
7644 goto scan_number_decimal2;
7649 error_message =
"invalid number; expected digit after '.'";
7650 return token_type::parse_error;
7654 scan_number_decimal2:
7670 goto scan_number_decimal2;
7677 goto scan_number_exponent;
7681 goto scan_number_done;
7684 scan_number_exponent:
7686 number_type = token_type::value_float;
7693 goto scan_number_sign;
7708 goto scan_number_any2;
7714 "invalid number; expected '+', '-', or digit after exponent";
7715 return token_type::parse_error;
7735 goto scan_number_any2;
7740 error_message =
"invalid number; expected digit after exponent sign";
7741 return token_type::parse_error;
7761 goto scan_number_any2;
7765 goto scan_number_done;
7773 char* endptr =
nullptr;
7777 if (number_type == token_type::value_unsigned)
7779 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7782 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7786 value_unsigned =
static_cast<number_unsigned_t
>(x);
7787 if (value_unsigned == x)
7789 return token_type::value_unsigned;
7793 else if (number_type == token_type::value_integer)
7795 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7798 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7802 value_integer =
static_cast<number_integer_t
>(x);
7803 if (value_integer == x)
7805 return token_type::value_integer;
7812 strtof(value_float, token_buffer.data(), &endptr);
7815 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7817 return token_type::value_float;
7825 JSON_HEDLEY_NON_NULL(2)
7826 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
7827 token_type return_type)
7829 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7830 for (std::size_t i = 1; i < length; ++i)
7832 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7834 error_message =
"invalid literal";
7835 return token_type::parse_error;
7846 void reset() noexcept
7848 token_buffer.clear();
7849 token_string.clear();
7850 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7865 ++position.chars_read_total;
7866 ++position.chars_read_current_line;
7875 current = ia.get_character();
7878 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7880 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7883 if (current ==
'\n')
7885 ++position.lines_read;
7886 position.chars_read_current_line = 0;
7904 --position.chars_read_total;
7907 if (position.chars_read_current_line == 0)
7909 if (position.lines_read > 0)
7911 --position.lines_read;
7916 --position.chars_read_current_line;
7919 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7921 JSON_ASSERT(!token_string.empty());
7922 token_string.pop_back();
7927 void add(char_int_type c)
7929 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
7938 constexpr number_integer_t get_number_integer() const noexcept
7940 return value_integer;
7944 constexpr number_unsigned_t get_number_unsigned() const noexcept
7946 return value_unsigned;
7950 constexpr number_float_t get_number_float() const noexcept
7956 string_t& get_string()
7958 return token_buffer;
7966 constexpr position_t get_position() const noexcept
7974 std::string get_token_string()
const
7978 for (
const auto c : token_string)
7980 if (
static_cast<unsigned char>(c) <=
'\x1F')
7983 std::array<char, 9> cs{{}};
7984 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
7985 result += cs.data();
7990 result.push_back(
static_cast<std::string::value_type
>(c));
7999 constexpr
const char* get_error_message() const noexcept
8001 return error_message;
8017 return get() == 0xBB && get() == 0xBF;
8026 void skip_whitespace()
8032 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
8038 if (position.chars_read_total == 0 && !skip_bom())
8040 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
8041 return token_type::parse_error;
8048 while (ignore_comments && current ==
'/')
8050 if (!scan_comment())
8052 return token_type::parse_error;
8063 return token_type::begin_array;
8065 return token_type::end_array;
8067 return token_type::begin_object;
8069 return token_type::end_object;
8071 return token_type::name_separator;
8073 return token_type::value_separator;
8078 std::array<char_type, 4> true_literal = {{char_type(
't'), char_type(
'r'), char_type(
'u'), char_type(
'e')}};
8079 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
8083 std::array<char_type, 5> false_literal = {{char_type(
'f'), char_type(
'a'), char_type(
'l'), char_type(
's'), char_type(
'e')}};
8084 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
8088 std::array<char_type, 4> null_literal = {{char_type(
'n'), char_type(
'u'), char_type(
'l'), char_type(
'l')}};
8089 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
8094 return scan_string();
8108 return scan_number();
8113 case std::char_traits<char_type>::eof():
8114 return token_type::end_of_input;
8118 error_message =
"invalid literal";
8119 return token_type::parse_error;
8125 InputAdapterType ia;
8128 const bool ignore_comments =
false;
8131 char_int_type current = std::char_traits<char_type>::eof();
8134 bool next_unget =
false;
8137 position_t position {};
8140 std::vector<char_type> token_string {};
8143 string_t token_buffer {};
8146 const char* error_message =
"";
8149 number_integer_t value_integer = 0;
8150 number_unsigned_t value_unsigned = 0;
8151 number_float_t value_float = 0;
8154 const char_int_type decimal_point_char =
'.';
8177 template<
typename T>
8178 using null_function_t = decltype(std::declval<T&>().
null());
8180 template<
typename T>
8181 using boolean_function_t =
8182 decltype(std::declval<T&>().
boolean(std::declval<bool>()));
8184 template<
typename T,
typename Integer>
8185 using number_integer_function_t =
8186 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8188 template<
typename T,
typename Un
signed>
8189 using number_unsigned_function_t =
8190 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8192 template<
typename T,
typename Float,
typename String>
8193 using number_float_function_t = decltype(std::declval<T&>().number_float(
8194 std::declval<Float>(), std::declval<const String&>()));
8196 template<
typename T,
typename String>
8197 using string_function_t =
8198 decltype(std::declval<T&>().
string(std::declval<String&>()));
8200 template<
typename T,
typename Binary>
8201 using binary_function_t =
8202 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8204 template<
typename T>
8205 using start_object_function_t =
8206 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8208 template<
typename T,
typename String>
8209 using key_function_t =
8210 decltype(std::declval<T&>().key(std::declval<String&>()));
8212 template<
typename T>
8213 using end_object_function_t = decltype(std::declval<T&>().end_object());
8215 template<
typename T>
8216 using start_array_function_t =
8217 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
8219 template<
typename T>
8220 using end_array_function_t = decltype(std::declval<T&>().end_array());
8222 template<
typename T,
typename Exception>
8223 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
8224 std::declval<std::size_t>(), std::declval<const std::string&>(),
8225 std::declval<const Exception&>()));
8227 template<
typename SAX,
typename BasicJsonType>
8231 static_assert(is_basic_json<BasicJsonType>::value,
8232 "BasicJsonType must be of type basic_json<...>");
8234 using number_integer_t =
typename BasicJsonType::number_integer_t;
8235 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8236 using number_float_t =
typename BasicJsonType::number_float_t;
8237 using string_t =
typename BasicJsonType::string_t;
8238 using binary_t =
typename BasicJsonType::binary_t;
8239 using exception_t =
typename BasicJsonType::exception;
8242 static constexpr
bool value =
8243 is_detected_exact<bool, null_function_t, SAX>::value &&
8244 is_detected_exact<bool, boolean_function_t, SAX>::value &&
8245 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8246 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8247 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8248 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8249 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8250 is_detected_exact<bool, start_object_function_t, SAX>::value &&
8251 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8252 is_detected_exact<bool, end_object_function_t, SAX>::value &&
8253 is_detected_exact<bool, start_array_function_t, SAX>::value &&
8254 is_detected_exact<bool, end_array_function_t, SAX>::value &&
8255 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8258 template<
typename SAX,
typename BasicJsonType>
8259 struct is_sax_static_asserts
8262 static_assert(is_basic_json<BasicJsonType>::value,
8263 "BasicJsonType must be of type basic_json<...>");
8265 using number_integer_t =
typename BasicJsonType::number_integer_t;
8266 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8267 using number_float_t =
typename BasicJsonType::number_float_t;
8268 using string_t =
typename BasicJsonType::string_t;
8269 using binary_t =
typename BasicJsonType::binary_t;
8270 using exception_t =
typename BasicJsonType::exception;
8273 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8274 "Missing/invalid function: bool null()");
8275 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8276 "Missing/invalid function: bool boolean(bool)");
8277 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8278 "Missing/invalid function: bool boolean(bool)");
8280 is_detected_exact<
bool, number_integer_function_t, SAX,
8281 number_integer_t>::value,
8282 "Missing/invalid function: bool number_integer(number_integer_t)");
8284 is_detected_exact<
bool, number_unsigned_function_t, SAX,
8285 number_unsigned_t>::value,
8286 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8287 static_assert(is_detected_exact<
bool, number_float_function_t, SAX,
8288 number_float_t, string_t>::value,
8289 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8291 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8292 "Missing/invalid function: bool string(string_t&)");
8294 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8295 "Missing/invalid function: bool binary(binary_t&)");
8296 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8297 "Missing/invalid function: bool start_object(std::size_t)");
8298 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8299 "Missing/invalid function: bool key(string_t&)");
8300 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8301 "Missing/invalid function: bool end_object()");
8302 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8303 "Missing/invalid function: bool start_array(std::size_t)");
8304 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8305 "Missing/invalid function: bool end_array()");
8307 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8308 "Missing/invalid function: bool parse_error(std::size_t, const "
8309 "std::string&, const exception&)");
8325 enum class cbor_tag_handler_t
8339 static inline bool little_endianess(
int num = 1) noexcept
8341 return *
reinterpret_cast<char*
>(&num) == 1;
8352 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
8355 using number_integer_t =
typename BasicJsonType::number_integer_t;
8356 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8357 using number_float_t =
typename BasicJsonType::number_float_t;
8358 using string_t =
typename BasicJsonType::string_t;
8359 using binary_t =
typename BasicJsonType::binary_t;
8360 using json_sax_t = SAX;
8361 using char_type =
typename InputAdapterType::char_type;
8362 using char_int_type =
typename std::char_traits<char_type>::int_type;
8370 explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
8372 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
8376 binary_reader(
const binary_reader&) =
delete;
8377 binary_reader(binary_reader&&) =
default;
8378 binary_reader& operator=(
const binary_reader&) =
delete;
8379 binary_reader& operator=(binary_reader&&) =
default;
8380 ~binary_reader() =
default;
8390 JSON_HEDLEY_NON_NULL(3)
8391 bool sax_parse(const input_format_t format,
8393 const
bool strict = true,
8394 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8397 bool result =
false;
8401 case input_format_t::bson:
8402 result = parse_bson_internal();
8405 case input_format_t::cbor:
8406 result = parse_cbor_internal(
true, tag_handler);
8409 case input_format_t::msgpack:
8410 result = parse_msgpack_internal();
8413 case input_format_t::ubjson:
8414 result = parse_ubjson_internal();
8417 case input_format_t::json:
8423 if (result && strict)
8425 if (format == input_format_t::ubjson)
8434 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8436 return sax->parse_error(chars_read, get_token_string(),
8437 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value"), BasicJsonType()));
8453 bool parse_bson_internal()
8455 std::int32_t document_size{};
8456 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8458 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8463 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
8468 return sax->end_object();
8478 bool get_bson_cstr(string_t& result)
8480 auto out = std::back_inserter(result);
8484 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
8488 if (current == 0x00)
8492 *out++ =
static_cast<typename string_t::value_type
>(current);
8507 template<
typename NumberType>
8508 bool get_bson_string(
const NumberType len, string_t& result)
8510 if (JSON_HEDLEY_UNLIKELY(len < 1))
8512 auto last_token = get_token_string();
8513 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()));
8516 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
8528 template<
typename NumberType>
8529 bool get_bson_binary(
const NumberType len, binary_t& result)
8531 if (JSON_HEDLEY_UNLIKELY(len < 0))
8533 auto last_token = get_token_string();
8534 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()));
8538 std::uint8_t subtype{};
8539 get_number<std::uint8_t>(input_format_t::bson, subtype);
8540 result.set_subtype(subtype);
8542 return get_binary(input_format_t::bson, len, result);
8555 bool parse_bson_element_internal(
const char_int_type element_type,
8556 const std::size_t element_type_parse_position)
8558 switch (element_type)
8563 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8570 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8575 return parse_bson_internal();
8580 return parse_bson_array();
8587 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8592 return sax->boolean(get() != 0);
8602 std::int32_t value{};
8603 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8608 std::int64_t value{};
8609 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8614 std::array<char, 3> cr{{}};
8615 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
8616 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()));
8633 bool parse_bson_element_list(
const bool is_array)
8637 while (
auto element_type = get())
8639 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
8644 const std::size_t element_type_parse_position = chars_read;
8645 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
8650 if (!is_array && !sax->key(key))
8655 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8671 bool parse_bson_array()
8673 std::int32_t document_size{};
8674 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8676 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8681 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
8686 return sax->end_array();
8701 bool parse_cbor_internal(
const bool get_char,
8702 const cbor_tag_handler_t tag_handler)
8704 switch (get_char ? get() : current)
8707 case std::char_traits<char_type>::eof():
8708 return unexpect_eof(input_format_t::cbor,
"value");
8735 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8739 std::uint8_t number{};
8740 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8745 std::uint16_t number{};
8746 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8751 std::uint32_t number{};
8752 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8757 std::uint64_t number{};
8758 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8786 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
8790 std::uint8_t number{};
8791 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8796 std::uint16_t number{};
8797 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8802 std::uint32_t number{};
8803 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8808 std::uint64_t number{};
8809 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
8810 -
static_cast<number_integer_t
>(number));
8845 return get_cbor_binary(b) && sax->binary(b);
8880 return get_cbor_string(s) && sax->string(s);
8908 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8913 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8918 std::uint16_t len{};
8919 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8924 std::uint32_t len{};
8925 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8930 std::uint64_t len{};
8931 return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast<std::size_t>(len), tag_handler);
8935 return get_cbor_array(std::size_t(-1), tag_handler);
8962 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8967 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8972 std::uint16_t len{};
8973 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8978 std::uint32_t len{};
8979 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8984 std::uint64_t len{};
8985 return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast<std::size_t>(len), tag_handler);
8989 return get_cbor_object(std::size_t(-1), tag_handler);
9011 switch (tag_handler)
9013 case cbor_tag_handler_t::error:
9015 auto last_token = get_token_string();
9016 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()));
9019 case cbor_tag_handler_t::ignore:
9026 std::uint8_t subtype_to_ignore{};
9027 get_number(input_format_t::cbor, subtype_to_ignore);
9032 std::uint16_t subtype_to_ignore{};
9033 get_number(input_format_t::cbor, subtype_to_ignore);
9038 std::uint32_t subtype_to_ignore{};
9039 get_number(input_format_t::cbor, subtype_to_ignore);
9044 std::uint64_t subtype_to_ignore{};
9045 get_number(input_format_t::cbor, subtype_to_ignore);
9051 return parse_cbor_internal(
true, tag_handler);
9054 case cbor_tag_handler_t::store:
9062 std::uint8_t subtype{};
9063 get_number(input_format_t::cbor, subtype);
9064 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9069 std::uint16_t subtype{};
9070 get_number(input_format_t::cbor, subtype);
9071 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9076 std::uint32_t subtype{};
9077 get_number(input_format_t::cbor, subtype);
9078 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9083 std::uint64_t subtype{};
9084 get_number(input_format_t::cbor, subtype);
9085 b.set_subtype(detail::conditional_static_cast<typename binary_t::subtype_type>(subtype));
9089 return parse_cbor_internal(
true, tag_handler);
9092 return get_cbor_binary(b) && sax->binary(b);
9102 return sax->boolean(
false);
9105 return sax->boolean(
true);
9112 const auto byte1_raw = get();
9113 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9117 const auto byte2_raw = get();
9118 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
9123 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
9124 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
9134 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
9135 const double val = [&half]
9137 const int exp = (half >> 10u) & 0x1Fu;
9138 const unsigned int mant = half & 0x3FFu;
9139 JSON_ASSERT(0 <= exp&& exp <= 32);
9140 JSON_ASSERT(mant <= 1024);
9144 return std::ldexp(mant, -24);
9147 ? std::numeric_limits<double>::infinity()
9148 : std::numeric_limits<double>::quiet_NaN();
9150 return std::ldexp(mant + 1024, exp - 25);
9153 return sax->number_float((half & 0x8000u) != 0
9154 ?
static_cast<number_float_t
>(-val)
9155 :
static_cast<number_float_t
>(val),
"");
9161 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9167 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9172 auto last_token = get_token_string();
9173 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()));
9189 bool get_cbor_string(string_t& result)
9191 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
9224 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9230 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9235 std::uint16_t len{};
9236 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9241 std::uint32_t len{};
9242 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9247 std::uint64_t len{};
9248 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9253 while (get() != 0xFF)
9256 if (!get_cbor_string(chunk))
9260 result.append(chunk);
9267 auto last_token = get_token_string();
9268 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()));
9284 bool get_cbor_binary(binary_t& result)
9286 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
9319 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9325 return get_number(input_format_t::cbor, len) &&
9326 get_binary(input_format_t::cbor, len, result);
9331 std::uint16_t len{};
9332 return get_number(input_format_t::cbor, len) &&
9333 get_binary(input_format_t::cbor, len, result);
9338 std::uint32_t len{};
9339 return get_number(input_format_t::cbor, len) &&
9340 get_binary(input_format_t::cbor, len, result);
9345 std::uint64_t len{};
9346 return get_number(input_format_t::cbor, len) &&
9347 get_binary(input_format_t::cbor, len, result);
9352 while (get() != 0xFF)
9355 if (!get_cbor_binary(chunk))
9359 result.insert(result.end(), chunk.begin(), chunk.end());
9366 auto last_token = get_token_string();
9367 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()));
9378 bool get_cbor_array(
const std::size_t len,
9379 const cbor_tag_handler_t tag_handler)
9381 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9386 if (len != std::size_t(-1))
9388 for (std::size_t i = 0; i < len; ++i)
9390 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9398 while (get() != 0xFF)
9400 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
9407 return sax->end_array();
9416 bool get_cbor_object(
const std::size_t len,
9417 const cbor_tag_handler_t tag_handler)
9419 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9427 if (len != std::size_t(-1))
9429 for (std::size_t i = 0; i < len; ++i)
9432 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9437 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9446 while (get() != 0xFF)
9448 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9453 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9462 return sax->end_object();
9472 bool parse_msgpack_internal()
9477 case std::char_traits<char_type>::eof():
9478 return unexpect_eof(input_format_t::msgpack,
"value");
9609 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9628 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9647 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9687 return get_msgpack_string(s) && sax->string(s);
9694 return sax->boolean(
false);
9697 return sax->boolean(
true);
9712 return get_msgpack_binary(b) && sax->binary(b);
9718 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9724 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9729 std::uint8_t number{};
9730 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9735 std::uint16_t number{};
9736 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9741 std::uint32_t number{};
9742 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9747 std::uint64_t number{};
9748 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9753 std::int8_t number{};
9754 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9759 std::int16_t number{};
9760 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9765 std::int32_t number{};
9766 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9771 std::int64_t number{};
9772 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9777 std::uint16_t len{};
9778 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9783 std::uint32_t len{};
9784 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9789 std::uint16_t len{};
9790 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9795 std::uint32_t len{};
9796 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9832 return sax->number_integer(
static_cast<std::int8_t
>(current));
9836 auto last_token = get_token_string();
9837 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()));
9852 bool get_msgpack_string(string_t& result)
9854 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
9895 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
9901 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9906 std::uint16_t len{};
9907 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9912 std::uint32_t len{};
9913 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9918 auto last_token = get_token_string();
9919 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()));
9934 bool get_msgpack_binary(binary_t& result)
9937 auto assign_and_return_true = [&result](std::int8_t subtype)
9939 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
9948 return get_number(input_format_t::msgpack, len) &&
9949 get_binary(input_format_t::msgpack, len, result);
9954 std::uint16_t len{};
9955 return get_number(input_format_t::msgpack, len) &&
9956 get_binary(input_format_t::msgpack, len, result);
9961 std::uint32_t len{};
9962 return get_number(input_format_t::msgpack, len) &&
9963 get_binary(input_format_t::msgpack, len, result);
9969 std::int8_t subtype{};
9970 return get_number(input_format_t::msgpack, len) &&
9971 get_number(input_format_t::msgpack, subtype) &&
9972 get_binary(input_format_t::msgpack, len, result) &&
9973 assign_and_return_true(subtype);
9978 std::uint16_t len{};
9979 std::int8_t subtype{};
9980 return get_number(input_format_t::msgpack, len) &&
9981 get_number(input_format_t::msgpack, subtype) &&
9982 get_binary(input_format_t::msgpack, len, result) &&
9983 assign_and_return_true(subtype);
9988 std::uint32_t len{};
9989 std::int8_t subtype{};
9990 return get_number(input_format_t::msgpack, len) &&
9991 get_number(input_format_t::msgpack, subtype) &&
9992 get_binary(input_format_t::msgpack, len, result) &&
9993 assign_and_return_true(subtype);
9998 std::int8_t subtype{};
9999 return get_number(input_format_t::msgpack, subtype) &&
10000 get_binary(input_format_t::msgpack, 1, result) &&
10001 assign_and_return_true(subtype);
10006 std::int8_t subtype{};
10007 return get_number(input_format_t::msgpack, subtype) &&
10008 get_binary(input_format_t::msgpack, 2, result) &&
10009 assign_and_return_true(subtype);
10014 std::int8_t subtype{};
10015 return get_number(input_format_t::msgpack, subtype) &&
10016 get_binary(input_format_t::msgpack, 4, result) &&
10017 assign_and_return_true(subtype);
10022 std::int8_t subtype{};
10023 return get_number(input_format_t::msgpack, subtype) &&
10024 get_binary(input_format_t::msgpack, 8, result) &&
10025 assign_and_return_true(subtype);
10030 std::int8_t subtype{};
10031 return get_number(input_format_t::msgpack, subtype) &&
10032 get_binary(input_format_t::msgpack, 16, result) &&
10033 assign_and_return_true(subtype);
10045 bool get_msgpack_array(
const std::size_t len)
10047 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
10052 for (std::size_t i = 0; i < len; ++i)
10054 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10060 return sax->end_array();
10067 bool get_msgpack_object(
const std::size_t len)
10069 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
10075 for (std::size_t i = 0; i < len; ++i)
10078 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
10083 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
10090 return sax->end_object();
10104 bool parse_ubjson_internal(
const bool get_char =
true)
10106 return get_ubjson_value(get_char ? get_ignore_noop() : current);
10123 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
10130 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
10139 std::uint8_t len{};
10140 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10146 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10151 std::int16_t len{};
10152 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10157 std::int32_t len{};
10158 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10163 std::int64_t len{};
10164 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10168 auto last_token = get_token_string();
10169 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()));
10177 bool get_ubjson_size_value(std::size_t& result)
10179 switch (get_ignore_noop())
10183 std::uint8_t number{};
10184 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10188 result =
static_cast<std::size_t
>(number);
10194 std::int8_t number{};
10195 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10199 result =
static_cast<std::size_t
>(number);
10205 std::int16_t number{};
10206 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10210 result =
static_cast<std::size_t
>(number);
10216 std::int32_t number{};
10217 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10221 result =
static_cast<std::size_t
>(number);
10227 std::int64_t number{};
10228 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10232 result =
static_cast<std::size_t
>(number);
10238 auto last_token = get_token_string();
10239 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()));
10254 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
10256 result.first = string_t::npos;
10261 if (current ==
'$')
10263 result.second = get();
10264 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"type")))
10270 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
10272 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
10276 auto last_token = get_token_string();
10277 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()));
10280 return get_ubjson_size_value(result.first);
10283 if (current ==
'#')
10285 return get_ubjson_size_value(result.first);
10295 bool get_ubjson_value(
const char_int_type prefix)
10299 case std::char_traits<char_type>::eof():
10300 return unexpect_eof(input_format_t::ubjson,
"value");
10303 return sax->boolean(
true);
10305 return sax->boolean(
false);
10308 return sax->null();
10312 std::uint8_t number{};
10313 return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
10318 std::int8_t number{};
10319 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10324 std::int16_t number{};
10325 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10330 std::int32_t number{};
10331 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10336 std::int64_t number{};
10337 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10343 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10349 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10354 return get_ubjson_high_precision_number();
10360 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"char")))
10364 if (JSON_HEDLEY_UNLIKELY(current > 127))
10366 auto last_token = get_token_string();
10367 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()));
10369 string_t s(1,
static_cast<typename string_t::value_type
>(current));
10370 return sax->string(s);
10376 return get_ubjson_string(s) && sax->string(s);
10380 return get_ubjson_array();
10383 return get_ubjson_object();
10387 auto last_token = get_token_string();
10388 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()));
10396 bool get_ubjson_array()
10398 std::pair<std::size_t, char_int_type> size_and_type;
10399 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10404 if (size_and_type.first != string_t::npos)
10406 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10411 if (size_and_type.second != 0)
10413 if (size_and_type.second !=
'N')
10415 for (std::size_t i = 0; i < size_and_type.first; ++i)
10417 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10426 for (std::size_t i = 0; i < size_and_type.first; ++i)
10428 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10437 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10442 while (current !=
']')
10444 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
10452 return sax->end_array();
10458 bool get_ubjson_object()
10460 std::pair<std::size_t, char_int_type> size_and_type;
10461 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10467 if (size_and_type.first != string_t::npos)
10469 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10474 if (size_and_type.second != 0)
10476 for (std::size_t i = 0; i < size_and_type.first; ++i)
10478 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10482 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10491 for (std::size_t i = 0; i < size_and_type.first; ++i)
10493 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10497 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10507 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10512 while (current !=
'}')
10514 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
10518 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10527 return sax->end_object();
10533 bool get_ubjson_high_precision_number()
10536 std::size_t size{};
10537 auto res = get_ubjson_size_value(size);
10538 if (JSON_HEDLEY_UNLIKELY(!res))
10544 std::vector<char> number_vector;
10545 for (std::size_t i = 0; i < size; ++i)
10548 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"number")))
10552 number_vector.push_back(
static_cast<char>(current));
10556 using ia_type = decltype(detail::input_adapter(number_vector));
10557 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
10558 const auto result_number = number_lexer.scan();
10559 const auto number_string = number_lexer.get_token_string();
10560 const auto result_remainder = number_lexer.scan();
10562 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
10564 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10566 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()));
10569 switch (result_number)
10571 case token_type::value_integer:
10572 return sax->number_integer(number_lexer.get_number_integer());
10573 case token_type::value_unsigned:
10574 return sax->number_unsigned(number_lexer.get_number_unsigned());
10575 case token_type::value_float:
10576 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10577 case token_type::uninitialized:
10578 case token_type::literal_true:
10579 case token_type::literal_false:
10580 case token_type::literal_null:
10581 case token_type::value_string:
10582 case token_type::begin_array:
10583 case token_type::begin_object:
10584 case token_type::end_array:
10585 case token_type::end_object:
10586 case token_type::name_separator:
10587 case token_type::value_separator:
10588 case token_type::parse_error:
10589 case token_type::end_of_input:
10590 case token_type::literal_or_value:
10592 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()));
10609 char_int_type get()
10612 return current = ia.get_character();
10618 char_int_type get_ignore_noop()
10624 while (current ==
'N');
10642 template<
typename NumberType,
bool InputIsLittleEndian = false>
10643 bool get_number(
const input_format_t format, NumberType& result)
10646 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
10647 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
10650 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
10656 if (is_little_endian != InputIsLittleEndian)
10658 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
10662 vec[i] =
static_cast<std::uint8_t
>(current);
10667 std::memcpy(&result, vec.data(),
sizeof(NumberType));
10685 template<
typename NumberType>
10686 bool get_string(
const input_format_t format,
10687 const NumberType len,
10690 bool success =
true;
10691 for (NumberType i = 0; i < len; i++)
10694 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
10699 result.push_back(
static_cast<typename string_t::value_type
>(current));
10718 template<
typename NumberType>
10719 bool get_binary(
const input_format_t format,
10720 const NumberType len,
10723 bool success =
true;
10724 for (NumberType i = 0; i < len; i++)
10727 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
10732 result.push_back(
static_cast<std::uint8_t
>(current));
10742 JSON_HEDLEY_NON_NULL(3)
10743 bool unexpect_eof(const input_format_t format, const
char* context)
const
10745 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10747 return sax->parse_error(chars_read,
"<end of file>",
10748 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context), BasicJsonType()));
10756 std::string get_token_string()
const
10758 std::array<char, 3> cr{{}};
10759 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
10760 return std::string{cr.data()};
10769 std::string exception_message(
const input_format_t format,
10770 const std::string& detail,
10771 const std::string& context)
const
10773 std::string error_msg =
"syntax error while parsing ";
10777 case input_format_t::cbor:
10778 error_msg +=
"CBOR";
10781 case input_format_t::msgpack:
10782 error_msg +=
"MessagePack";
10785 case input_format_t::ubjson:
10786 error_msg +=
"UBJSON";
10789 case input_format_t::bson:
10790 error_msg +=
"BSON";
10793 case input_format_t::json:
10795 JSON_ASSERT(
false);
10798 return error_msg +
" " + context +
": " + detail;
10803 InputAdapterType ia;
10806 char_int_type current = std::char_traits<char_type>::eof();
10809 std::size_t chars_read = 0;
10812 const bool is_little_endian = little_endianess();
10815 json_sax_t* sax =
nullptr;
10829 #include <functional>
10857 enum class parse_event_t : std::uint8_t
10873 template<
typename BasicJsonType>
10874 using parser_callback_t =
10875 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
10882 template<
typename BasicJsonType,
typename InputAdapterType>
10885 using number_integer_t =
typename BasicJsonType::number_integer_t;
10886 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
10887 using number_float_t =
typename BasicJsonType::number_float_t;
10888 using string_t =
typename BasicJsonType::string_t;
10889 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10890 using token_type =
typename lexer_t::token_type;
10894 explicit parser(InputAdapterType&& adapter,
10895 const parser_callback_t<BasicJsonType> cb =
nullptr,
10896 const bool allow_exceptions_ =
true,
10897 const bool skip_comments =
false)
10899 , m_lexer(std::move(adapter), skip_comments)
10900 , allow_exceptions(allow_exceptions_)
10916 void parse(
const bool strict, BasicJsonType& result)
10920 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
10921 sax_parse_internal(&sdp);
10924 if (strict && (get_token() != token_type::end_of_input))
10926 sdp.parse_error(m_lexer.get_position(),
10927 m_lexer.get_token_string(),
10928 parse_error::create(101, m_lexer.get_position(),
10929 exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10933 if (sdp.is_errored())
10935 result = value_t::discarded;
10941 if (result.is_discarded())
10948 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
10949 sax_parse_internal(&sdp);
10952 if (strict && (get_token() != token_type::end_of_input))
10954 sdp.parse_error(m_lexer.get_position(),
10955 m_lexer.get_token_string(),
10956 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10960 if (sdp.is_errored())
10962 result = value_t::discarded;
10967 result.assert_invariant();
10976 bool accept(
const bool strict =
true)
10978 json_sax_acceptor<BasicJsonType> sax_acceptor;
10979 return sax_parse(&sax_acceptor, strict);
10982 template<
typename SAX>
10983 JSON_HEDLEY_NON_NULL(2)
10984 bool sax_parse(SAX* sax, const
bool strict = true)
10986 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
10987 const bool result = sax_parse_internal(sax);
10990 if (result && strict && (get_token() != token_type::end_of_input))
10992 return sax->parse_error(m_lexer.get_position(),
10993 m_lexer.get_token_string(),
10994 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
11001 template<
typename SAX>
11002 JSON_HEDLEY_NON_NULL(2)
11003 bool sax_parse_internal(SAX* sax)
11007 std::vector<bool> states;
11009 bool skip_to_state_evaluation =
false;
11013 if (!skip_to_state_evaluation)
11016 switch (last_token)
11018 case token_type::begin_object:
11020 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
11026 if (get_token() == token_type::end_object)
11028 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11036 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
11038 return sax->parse_error(m_lexer.get_position(),
11039 m_lexer.get_token_string(),
11040 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
11042 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11048 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11050 return sax->parse_error(m_lexer.get_position(),
11051 m_lexer.get_token_string(),
11052 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
11056 states.push_back(
false);
11063 case token_type::begin_array:
11065 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
11071 if (get_token() == token_type::end_array)
11073 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11081 states.push_back(
true);
11087 case token_type::value_float:
11089 const auto res = m_lexer.get_number_float();
11091 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
11093 return sax->parse_error(m_lexer.get_position(),
11094 m_lexer.get_token_string(),
11095 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'", BasicJsonType()));
11098 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
11106 case token_type::literal_false:
11108 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
11115 case token_type::literal_null:
11117 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
11124 case token_type::literal_true:
11126 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
11133 case token_type::value_integer:
11135 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
11142 case token_type::value_string:
11144 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
11151 case token_type::value_unsigned:
11153 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
11160 case token_type::parse_error:
11163 return sax->parse_error(m_lexer.get_position(),
11164 m_lexer.get_token_string(),
11165 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"), BasicJsonType()));
11168 case token_type::uninitialized:
11169 case token_type::end_array:
11170 case token_type::end_object:
11171 case token_type::name_separator:
11172 case token_type::value_separator:
11173 case token_type::end_of_input:
11174 case token_type::literal_or_value:
11177 return sax->parse_error(m_lexer.get_position(),
11178 m_lexer.get_token_string(),
11179 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"), BasicJsonType()));
11185 skip_to_state_evaluation =
false;
11189 if (states.empty())
11198 if (get_token() == token_type::value_separator)
11206 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
11208 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11217 JSON_ASSERT(!states.empty());
11219 skip_to_state_evaluation =
true;
11223 return sax->parse_error(m_lexer.get_position(),
11224 m_lexer.get_token_string(),
11225 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"), BasicJsonType()));
11231 if (get_token() == token_type::value_separator)
11234 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
11236 return sax->parse_error(m_lexer.get_position(),
11237 m_lexer.get_token_string(),
11238 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
11241 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11247 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11249 return sax->parse_error(m_lexer.get_position(),
11250 m_lexer.get_token_string(),
11251 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
11260 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
11262 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11271 JSON_ASSERT(!states.empty());
11273 skip_to_state_evaluation =
true;
11277 return sax->parse_error(m_lexer.get_position(),
11278 m_lexer.get_token_string(),
11279 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"), BasicJsonType()));
11284 token_type get_token()
11286 return last_token = m_lexer.scan();
11289 std::string exception_message(
const token_type expected,
const std::string& context)
11291 std::string error_msg =
"syntax error ";
11293 if (!context.empty())
11295 error_msg +=
"while parsing " + context +
" ";
11300 if (last_token == token_type::parse_error)
11302 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
11303 m_lexer.get_token_string() +
"'";
11307 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
11310 if (expected != token_type::uninitialized)
11312 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
11320 const parser_callback_t<BasicJsonType> callback =
nullptr;
11322 token_type last_token = token_type::uninitialized;
11326 const bool allow_exceptions =
true;
11357 class primitive_iterator_t
11360 using difference_type = std::ptrdiff_t;
11361 static constexpr difference_type begin_value = 0;
11362 static constexpr difference_type end_value = begin_value + 1;
11364 JSON_PRIVATE_UNLESS_TESTED:
11366 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11369 constexpr difference_type get_value() const noexcept
11375 void set_begin() noexcept
11377 m_it = begin_value;
11381 void set_end() noexcept
11387 constexpr
bool is_begin() const noexcept
11389 return m_it == begin_value;
11393 constexpr
bool is_end() const noexcept
11395 return m_it == end_value;
11398 friend constexpr
bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11400 return lhs.m_it == rhs.m_it;
11403 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11405 return lhs.m_it < rhs.m_it;
11408 primitive_iterator_t operator+(difference_type n) noexcept
11410 auto result = *
this;
11415 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11417 return lhs.m_it - rhs.m_it;
11420 primitive_iterator_t& operator++() noexcept
11426 primitive_iterator_t
const operator++(
int) noexcept
11428 auto result = *
this;
11433 primitive_iterator_t& operator--() noexcept
11439 primitive_iterator_t
const operator--(
int) noexcept
11441 auto result = *
this;
11446 primitive_iterator_t& operator+=(difference_type n) noexcept
11452 primitive_iterator_t& operator-=(difference_type n) noexcept
11472 template<
typename BasicJsonType>
struct internal_iterator
11475 typename BasicJsonType::object_t::iterator object_iterator {};
11477 typename BasicJsonType::array_t::iterator array_iterator {};
11479 primitive_iterator_t primitive_iterator {};
11487 #include <iterator>
11488 #include <type_traits>
11510 template<
typename IteratorType>
class iteration_proxy;
11511 template<
typename IteratorType>
class iteration_proxy_value;
11529 template<
typename BasicJsonType>
11533 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
11535 friend other_iter_impl;
11536 friend BasicJsonType;
11537 friend iteration_proxy<iter_impl>;
11538 friend iteration_proxy_value<iter_impl>;
11540 using object_t =
typename BasicJsonType::object_t;
11541 using array_t =
typename BasicJsonType::array_t;
11543 static_assert(is_basic_json<
typename std::remove_const<BasicJsonType>::type>::value,
11544 "iter_impl only accepts (const) basic_json");
11553 using iterator_category = std::bidirectional_iterator_tag;
11556 using value_type =
typename BasicJsonType::value_type;
11558 using difference_type =
typename BasicJsonType::difference_type;
11560 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
11561 typename BasicJsonType::const_pointer,
11562 typename BasicJsonType::pointer>::type;
11565 typename std::conditional<std::is_const<BasicJsonType>::value,
11566 typename BasicJsonType::const_reference,
11567 typename BasicJsonType::reference>::type;
11569 iter_impl() =
default;
11570 ~iter_impl() =
default;
11571 iter_impl(iter_impl&&) noexcept = default;
11572 iter_impl& operator=(iter_impl&&) noexcept = default;
11580 explicit iter_impl(pointer
object) noexcept : m_object(
object)
11582 JSON_ASSERT(m_object !=
nullptr);
11584 switch (m_object->m_type)
11586 case value_t::object:
11588 m_it.object_iterator =
typename object_t::iterator();
11592 case value_t::array:
11594 m_it.array_iterator =
typename array_t::iterator();
11598 case value_t::null:
11599 case value_t::string:
11600 case value_t::boolean:
11601 case value_t::number_integer:
11602 case value_t::number_unsigned:
11603 case value_t::number_float:
11604 case value_t::binary:
11605 case value_t::discarded:
11608 m_it.primitive_iterator = primitive_iterator_t();
11630 iter_impl(
const iter_impl<const BasicJsonType>& other) noexcept
11631 : m_object(other.m_object), m_it(other.m_it)
11640 iter_impl& operator=(
const iter_impl<const BasicJsonType>& other) noexcept
11642 if (&other !=
this)
11644 m_object = other.m_object;
11655 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11656 : m_object(other.m_object), m_it(other.m_it)
11665 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11667 m_object = other.m_object;
11672 JSON_PRIVATE_UNLESS_TESTED:
11677 void set_begin() noexcept
11679 JSON_ASSERT(m_object !=
nullptr);
11681 switch (m_object->m_type)
11683 case value_t::object:
11685 m_it.object_iterator = m_object->m_value.object->begin();
11689 case value_t::array:
11691 m_it.array_iterator = m_object->m_value.array->begin();
11695 case value_t::null:
11698 m_it.primitive_iterator.set_end();
11702 case value_t::string:
11703 case value_t::boolean:
11704 case value_t::number_integer:
11705 case value_t::number_unsigned:
11706 case value_t::number_float:
11707 case value_t::binary:
11708 case value_t::discarded:
11711 m_it.primitive_iterator.set_begin();
11721 void set_end() noexcept
11723 JSON_ASSERT(m_object !=
nullptr);
11725 switch (m_object->m_type)
11727 case value_t::object:
11729 m_it.object_iterator = m_object->m_value.object->end();
11733 case value_t::array:
11735 m_it.array_iterator = m_object->m_value.array->end();
11739 case value_t::null:
11740 case value_t::string:
11741 case value_t::boolean:
11742 case value_t::number_integer:
11743 case value_t::number_unsigned:
11744 case value_t::number_float:
11745 case value_t::binary:
11746 case value_t::discarded:
11749 m_it.primitive_iterator.set_end();
11760 reference operator*()
const
11762 JSON_ASSERT(m_object !=
nullptr);
11764 switch (m_object->m_type)
11766 case value_t::object:
11768 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11769 return m_it.object_iterator->second;
11772 case value_t::array:
11774 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11775 return *m_it.array_iterator;
11778 case value_t::null:
11779 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11781 case value_t::string:
11782 case value_t::boolean:
11783 case value_t::number_integer:
11784 case value_t::number_unsigned:
11785 case value_t::number_float:
11786 case value_t::binary:
11787 case value_t::discarded:
11790 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11795 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11804 pointer operator->()
const
11806 JSON_ASSERT(m_object !=
nullptr);
11808 switch (m_object->m_type)
11810 case value_t::object:
11812 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11813 return &(m_it.object_iterator->second);
11816 case value_t::array:
11818 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11819 return &*m_it.array_iterator;
11822 case value_t::null:
11823 case value_t::string:
11824 case value_t::boolean:
11825 case value_t::number_integer:
11826 case value_t::number_unsigned:
11827 case value_t::number_float:
11828 case value_t::binary:
11829 case value_t::discarded:
11832 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11837 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11846 iter_impl
const operator++(
int)
11848 auto result = *
this;
11857 iter_impl& operator++()
11859 JSON_ASSERT(m_object !=
nullptr);
11861 switch (m_object->m_type)
11863 case value_t::object:
11865 std::advance(m_it.object_iterator, 1);
11869 case value_t::array:
11871 std::advance(m_it.array_iterator, 1);
11875 case value_t::null:
11876 case value_t::string:
11877 case value_t::boolean:
11878 case value_t::number_integer:
11879 case value_t::number_unsigned:
11880 case value_t::number_float:
11881 case value_t::binary:
11882 case value_t::discarded:
11885 ++m_it.primitive_iterator;
11897 iter_impl
const operator--(
int)
11899 auto result = *
this;
11908 iter_impl& operator--()
11910 JSON_ASSERT(m_object !=
nullptr);
11912 switch (m_object->m_type)
11914 case value_t::object:
11916 std::advance(m_it.object_iterator, -1);
11920 case value_t::array:
11922 std::advance(m_it.array_iterator, -1);
11926 case value_t::null:
11927 case value_t::string:
11928 case value_t::boolean:
11929 case value_t::number_integer:
11930 case value_t::number_unsigned:
11931 case value_t::number_float:
11932 case value_t::binary:
11933 case value_t::discarded:
11936 --m_it.primitive_iterator;
11948 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 >
11949 bool operator==(
const IterImpl& other)
const
11952 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11954 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
11957 JSON_ASSERT(m_object !=
nullptr);
11959 switch (m_object->m_type)
11961 case value_t::object:
11962 return (m_it.object_iterator == other.m_it.object_iterator);
11964 case value_t::array:
11965 return (m_it.array_iterator == other.m_it.array_iterator);
11967 case value_t::null:
11968 case value_t::string:
11969 case value_t::boolean:
11970 case value_t::number_integer:
11971 case value_t::number_unsigned:
11972 case value_t::number_float:
11973 case value_t::binary:
11974 case value_t::discarded:
11976 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11984 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 >
11985 bool operator!=(
const IterImpl& other)
const
11987 return !operator==(other);
11994 bool operator<(
const iter_impl& other)
const
11997 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11999 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
12002 JSON_ASSERT(m_object !=
nullptr);
12004 switch (m_object->m_type)
12006 case value_t::object:
12007 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
12009 case value_t::array:
12010 return (m_it.array_iterator < other.m_it.array_iterator);
12012 case value_t::null:
12013 case value_t::string:
12014 case value_t::boolean:
12015 case value_t::number_integer:
12016 case value_t::number_unsigned:
12017 case value_t::number_float:
12018 case value_t::binary:
12019 case value_t::discarded:
12021 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
12029 bool operator<=(
const iter_impl& other)
const
12031 return !other.operator < (*this);
12038 bool operator>(
const iter_impl& other)
const
12040 return !operator<=(other);
12047 bool operator>=(
const iter_impl& other)
const
12049 return !operator<(other);
12056 iter_impl& operator+=(difference_type i)
12058 JSON_ASSERT(m_object !=
nullptr);
12060 switch (m_object->m_type)
12062 case value_t::object:
12063 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12065 case value_t::array:
12067 std::advance(m_it.array_iterator, i);
12071 case value_t::null:
12072 case value_t::string:
12073 case value_t::boolean:
12074 case value_t::number_integer:
12075 case value_t::number_unsigned:
12076 case value_t::number_float:
12077 case value_t::binary:
12078 case value_t::discarded:
12081 m_it.primitive_iterator += i;
12093 iter_impl& operator-=(difference_type i)
12095 return operator+=(-i);
12102 iter_impl operator+(difference_type i)
const
12104 auto result = *
this;
12113 friend iter_impl operator+(difference_type i,
const iter_impl& it)
12124 iter_impl operator-(difference_type i)
const
12126 auto result = *
this;
12135 difference_type operator-(
const iter_impl& other)
const
12137 JSON_ASSERT(m_object !=
nullptr);
12139 switch (m_object->m_type)
12141 case value_t::object:
12142 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
12144 case value_t::array:
12145 return m_it.array_iterator - other.m_it.array_iterator;
12147 case value_t::null:
12148 case value_t::string:
12149 case value_t::boolean:
12150 case value_t::number_integer:
12151 case value_t::number_unsigned:
12152 case value_t::number_float:
12153 case value_t::binary:
12154 case value_t::discarded:
12156 return m_it.primitive_iterator - other.m_it.primitive_iterator;
12164 reference operator[](difference_type n)
const
12166 JSON_ASSERT(m_object !=
nullptr);
12168 switch (m_object->m_type)
12170 case value_t::object:
12171 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
12173 case value_t::array:
12174 return *std::next(m_it.array_iterator, n);
12176 case value_t::null:
12177 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12179 case value_t::string:
12180 case value_t::boolean:
12181 case value_t::number_integer:
12182 case value_t::number_unsigned:
12183 case value_t::number_float:
12184 case value_t::binary:
12185 case value_t::discarded:
12188 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
12193 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
12202 const typename object_t::key_type& key()
const
12204 JSON_ASSERT(m_object !=
nullptr);
12206 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
12208 return m_it.object_iterator->first;
12211 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
12218 reference value()
const
12220 return operator*();
12223 JSON_PRIVATE_UNLESS_TESTED:
12225 pointer m_object =
nullptr;
12227 internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
12238 #include <iterator>
12267 template<
typename Base>
12268 class json_reverse_iterator :
public std::reverse_iterator<Base>
12271 using difference_type = std::ptrdiff_t;
12273 using base_iterator = std::reverse_iterator<Base>;
12275 using reference =
typename Base::reference;
12278 explicit json_reverse_iterator(
const typename base_iterator::iterator_type& it) noexcept
12279 : base_iterator(it) {}
12282 explicit json_reverse_iterator(
const base_iterator& it) noexcept : base_iterator(it) {}
12285 json_reverse_iterator
const operator++(
int)
12287 return static_cast<json_reverse_iterator
>(base_iterator::operator++(1));
12291 json_reverse_iterator& operator++()
12293 return static_cast<json_reverse_iterator&
>(base_iterator::operator++());
12297 json_reverse_iterator
const operator--(
int)
12299 return static_cast<json_reverse_iterator
>(base_iterator::operator--(1));
12303 json_reverse_iterator& operator--()
12305 return static_cast<json_reverse_iterator&
>(base_iterator::operator--());
12309 json_reverse_iterator& operator+=(difference_type i)
12311 return static_cast<json_reverse_iterator&
>(base_iterator::operator+=(i));
12315 json_reverse_iterator operator+(difference_type i)
const
12317 return static_cast<json_reverse_iterator
>(base_iterator::operator+(i));
12321 json_reverse_iterator operator-(difference_type i)
const
12323 return static_cast<json_reverse_iterator
>(base_iterator::operator-(i));
12327 difference_type operator-(
const json_reverse_iterator& other)
const
12329 return base_iterator(*
this) - base_iterator(other);
12333 reference operator[](difference_type n)
const
12335 return *(this->operator+(n));
12339 auto key() const -> decltype(std::declval<Base>().key())
12341 auto it = --this->base();
12346 reference value()
const
12348 auto it = --this->base();
12349 return it.operator * ();
12360 #include <algorithm>
12379 template<
typename BasicJsonType>
12383 NLOHMANN_BASIC_JSON_TPL_DECLARATION
12409 : reference_tokens(split(s))
12428 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12430 [](
const std::string & a,
const std::string & b)
12432 return a +
"/" + detail::escape(b);
12437 operator std::string()
const
12460 reference_tokens.insert(reference_tokens.end(),
12461 ptr.reference_tokens.begin(),
12462 ptr.reference_tokens.end());
12506 return *
this /= std::to_string(array_idx);
12610 if (JSON_HEDLEY_UNLIKELY(
empty()))
12612 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12615 reference_tokens.pop_back();
12634 if (JSON_HEDLEY_UNLIKELY(
empty()))
12636 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12639 return reference_tokens.back();
12656 reference_tokens.push_back(token);
12662 reference_tokens.push_back(std::move(token));
12681 return reference_tokens.empty();
12695 static typename BasicJsonType::size_type array_index(
const std::string& s)
12697 using size_type =
typename BasicJsonType::size_type;
12700 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
12702 JSON_THROW(detail::parse_error::create(106, 0,
"array index '" + s +
"' must not begin with '0'", BasicJsonType()));
12706 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
12708 JSON_THROW(detail::parse_error::create(109, 0,
"array index '" + s +
"' is not a number", BasicJsonType()));
12711 std::size_t processed_chars = 0;
12712 unsigned long long res = 0;
12715 res = std::stoull(s, &processed_chars);
12717 JSON_CATCH(std::out_of_range&)
12719 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12723 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12725 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12730 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
12732 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type", BasicJsonType()));
12735 return static_cast<size_type
>(res);
12738 JSON_PRIVATE_UNLESS_TESTED:
12741 if (JSON_HEDLEY_UNLIKELY(
empty()))
12743 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12747 result.reference_tokens = {reference_tokens[0]};
12760 BasicJsonType& get_and_create(BasicJsonType& j)
const
12766 for (
const auto& reference_token : reference_tokens)
12768 switch (result->type())
12770 case detail::value_t::null:
12772 if (reference_token ==
"0")
12775 result = &result->operator[](0);
12780 result = &result->operator[](reference_token);
12785 case detail::value_t::object:
12788 result = &result->operator[](reference_token);
12792 case detail::value_t::array:
12795 result = &result->operator[](array_index(reference_token));
12805 case detail::value_t::string:
12806 case detail::value_t::boolean:
12807 case detail::value_t::number_integer:
12808 case detail::value_t::number_unsigned:
12809 case detail::value_t::number_float:
12810 case detail::value_t::binary:
12811 case detail::value_t::discarded:
12813 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", j));
12839 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
12841 for (
const auto& reference_token : reference_tokens)
12844 if (ptr->is_null())
12848 std::all_of(reference_token.begin(), reference_token.end(),
12849 [](
const unsigned char x)
12851 return std::isdigit(x);
12855 *ptr = (nums || reference_token ==
"-")
12856 ? detail::value_t::array
12857 : detail::value_t::object;
12860 switch (ptr->type())
12862 case detail::value_t::object:
12865 ptr = &ptr->operator[](reference_token);
12869 case detail::value_t::array:
12871 if (reference_token ==
"-")
12874 ptr = &ptr->operator[](ptr->m_value.array->size());
12879 ptr = &ptr->operator[](array_index(reference_token));
12884 case detail::value_t::null:
12885 case detail::value_t::string:
12886 case detail::value_t::boolean:
12887 case detail::value_t::number_integer:
12888 case detail::value_t::number_unsigned:
12889 case detail::value_t::number_float:
12890 case detail::value_t::binary:
12891 case detail::value_t::discarded:
12893 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12906 BasicJsonType& get_checked(BasicJsonType* ptr)
const
12908 for (
const auto& reference_token : reference_tokens)
12910 switch (ptr->type())
12912 case detail::value_t::object:
12915 ptr = &ptr->at(reference_token);
12919 case detail::value_t::array:
12921 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12924 JSON_THROW(detail::out_of_range::create(402,
12925 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12926 ") is out of range", *ptr));
12930 ptr = &ptr->at(array_index(reference_token));
12934 case detail::value_t::null:
12935 case detail::value_t::string:
12936 case detail::value_t::boolean:
12937 case detail::value_t::number_integer:
12938 case detail::value_t::number_unsigned:
12939 case detail::value_t::number_float:
12940 case detail::value_t::binary:
12941 case detail::value_t::discarded:
12943 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12963 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
12965 for (
const auto& reference_token : reference_tokens)
12967 switch (ptr->type())
12969 case detail::value_t::object:
12972 ptr = &ptr->operator[](reference_token);
12976 case detail::value_t::array:
12978 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12981 JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", *ptr));
12985 ptr = &ptr->operator[](array_index(reference_token));
12989 case detail::value_t::null:
12990 case detail::value_t::string:
12991 case detail::value_t::boolean:
12992 case detail::value_t::number_integer:
12993 case detail::value_t::number_unsigned:
12994 case detail::value_t::number_float:
12995 case detail::value_t::binary:
12996 case detail::value_t::discarded:
12998 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13011 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
13013 for (
const auto& reference_token : reference_tokens)
13015 switch (ptr->type())
13017 case detail::value_t::object:
13020 ptr = &ptr->at(reference_token);
13024 case detail::value_t::array:
13026 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13029 JSON_THROW(detail::out_of_range::create(402,
13030 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
13031 ") is out of range", *ptr));
13035 ptr = &ptr->at(array_index(reference_token));
13039 case detail::value_t::null:
13040 case detail::value_t::string:
13041 case detail::value_t::boolean:
13042 case detail::value_t::number_integer:
13043 case detail::value_t::number_unsigned:
13044 case detail::value_t::number_float:
13045 case detail::value_t::binary:
13046 case detail::value_t::discarded:
13048 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
13059 bool contains(
const BasicJsonType* ptr)
const
13061 for (
const auto& reference_token : reference_tokens)
13063 switch (ptr->type())
13065 case detail::value_t::object:
13067 if (!ptr->contains(reference_token))
13073 ptr = &ptr->operator[](reference_token);
13077 case detail::value_t::array:
13079 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
13084 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
13089 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
13091 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
13096 for (std::size_t i = 1; i < reference_token.size(); i++)
13098 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
13106 const auto idx = array_index(reference_token);
13107 if (idx >= ptr->size())
13113 ptr = &ptr->operator[](idx);
13117 case detail::value_t::null:
13118 case detail::value_t::string:
13119 case detail::value_t::boolean:
13120 case detail::value_t::number_integer:
13121 case detail::value_t::number_unsigned:
13122 case detail::value_t::number_float:
13123 case detail::value_t::binary:
13124 case detail::value_t::discarded:
13147 static std::vector<std::string> split(
const std::string& reference_string)
13149 std::vector<std::string> result;
13152 if (reference_string.empty())
13158 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
13160 JSON_THROW(detail::parse_error::create(107, 1,
"JSON pointer must be empty or begin with '/' - was: '" + reference_string +
"'", BasicJsonType()));
13168 std::size_t slash = reference_string.find_first_of(
'/', 1),
13175 start = (slash == std::string::npos) ? 0 : slash + 1,
13177 slash = reference_string.find_first_of(
'/', start))
13181 auto reference_token = reference_string.substr(start, slash - start);
13184 for (std::size_t pos = reference_token.find_first_of(
'~');
13185 pos != std::string::npos;
13186 pos = reference_token.find_first_of(
'~', pos + 1))
13188 JSON_ASSERT(reference_token[pos] ==
'~');
13191 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
13192 (reference_token[pos + 1] !=
'0' &&
13193 reference_token[pos + 1] !=
'1')))
13195 JSON_THROW(detail::parse_error::create(108, 0,
"escape character '~' must be followed with '0' or '1'", BasicJsonType()));
13200 detail::unescape(reference_token);
13201 result.push_back(reference_token);
13215 static void flatten(
const std::string& reference_string,
13216 const BasicJsonType& value,
13217 BasicJsonType& result)
13219 switch (value.type())
13221 case detail::value_t::array:
13223 if (value.m_value.array->empty())
13226 result[reference_string] =
nullptr;
13231 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
13233 flatten(reference_string +
"/" + std::to_string(i),
13234 value.m_value.array->operator[](i), result);
13240 case detail::value_t::object:
13242 if (value.m_value.object->empty())
13245 result[reference_string] =
nullptr;
13250 for (
const auto& element : *value.m_value.object)
13252 flatten(reference_string +
"/" + detail::escape(element.first), element.second, result);
13258 case detail::value_t::null:
13259 case detail::value_t::string:
13260 case detail::value_t::boolean:
13261 case detail::value_t::number_integer:
13262 case detail::value_t::number_unsigned:
13263 case detail::value_t::number_float:
13264 case detail::value_t::binary:
13265 case detail::value_t::discarded:
13269 result[reference_string] = value;
13285 static BasicJsonType
13286 unflatten(
const BasicJsonType& value)
13288 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
13290 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", value));
13293 BasicJsonType result;
13296 for (
const auto& element : *value.m_value.object)
13298 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
13300 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", element.second));
13307 json_pointer(element.first).get_and_create(result) = element.second;
13327 return lhs.reference_tokens == rhs.reference_tokens;
13344 return !(lhs == rhs);
13348 std::vector<std::string> reference_tokens;
13355 #include <initializer_list>
13365 template<
typename BasicJsonType>
13369 using value_type = BasicJsonType;
13371 json_ref(value_type&& value)
13372 : owned_value(std::move(value))
13375 json_ref(
const value_type& value)
13376 : value_ref(&value)
13379 json_ref(std::initializer_list<json_ref> init)
13380 : owned_value(init)
13385 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
13386 json_ref(Args && ... args)
13387 : owned_value(std::forward<Args>(args)...)
13391 json_ref(json_ref&&) noexcept = default;
13392 json_ref(const json_ref&) = delete;
13393 json_ref& operator=(const json_ref&) = delete;
13394 json_ref& operator=(json_ref&&) = delete;
13395 ~json_ref() = default;
13397 value_type moved_or_copied()
const
13399 if (value_ref ==
nullptr)
13401 return std::move(owned_value);
13406 value_type
const& operator*()
const
13408 return value_ref ? *value_ref : owned_value;
13411 value_type
const* operator->()
const
13417 mutable value_type owned_value =
nullptr;
13418 value_type
const* value_ref =
nullptr;
13434 #include <algorithm>
13450 #include <algorithm>
13452 #include <iterator>
13470 template<
typename CharType>
struct output_adapter_protocol
13472 virtual void write_character(CharType c) = 0;
13473 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
13474 virtual ~output_adapter_protocol() =
default;
13476 output_adapter_protocol() =
default;
13477 output_adapter_protocol(
const output_adapter_protocol&) =
default;
13478 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
13479 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
13480 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
13484 template<typename CharType>
13485 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
13488 template<typename CharType>
13489 class output_vector_adapter : public output_adapter_protocol<CharType>
13492 explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
13496 void write_character(CharType c)
override
13501 JSON_HEDLEY_NON_NULL(2)
13502 void write_characters(const CharType* s, std::
size_t length)
override
13504 std::copy(s, s + length, std::back_inserter(v));
13508 std::vector<CharType>& v;
13513 template<
typename CharType>
13514 class output_stream_adapter :
public output_adapter_protocol<CharType>
13517 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
13521 void write_character(CharType c)
override
13526 JSON_HEDLEY_NON_NULL(2)
13527 void write_characters(const CharType* s, std::
size_t length)
override
13529 stream.write(s,
static_cast<std::streamsize
>(length));
13533 std::basic_ostream<CharType>& stream;
13538 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13539 class output_string_adapter :
public output_adapter_protocol<CharType>
13542 explicit output_string_adapter(StringType& s) noexcept
13546 void write_character(CharType c)
override
13551 JSON_HEDLEY_NON_NULL(2)
13552 void write_characters(const CharType* s, std::
size_t length)
override
13554 str.append(s, length);
13561 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13562 class output_adapter
13565 output_adapter(std::vector<CharType>& vec)
13566 : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
13569 output_adapter(std::basic_ostream<CharType>& s)
13570 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
13573 output_adapter(StringType& s)
13574 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13576 operator output_adapter_t<CharType>()
13582 output_adapter_t<CharType> oa =
nullptr;
13599 template<
typename BasicJsonType,
typename CharType>
13600 class binary_writer
13602 using string_t =
typename BasicJsonType::string_t;
13603 using binary_t =
typename BasicJsonType::binary_t;
13604 using number_float_t =
typename BasicJsonType::number_float_t;
13612 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
13621 void write_bson(
const BasicJsonType& j)
13625 case value_t::object:
13627 write_bson_object(*j.m_value.object);
13631 case value_t::null:
13632 case value_t::array:
13633 case value_t::string:
13634 case value_t::boolean:
13635 case value_t::number_integer:
13636 case value_t::number_unsigned:
13637 case value_t::number_float:
13638 case value_t::binary:
13639 case value_t::discarded:
13642 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));
13650 void write_cbor(
const BasicJsonType& j)
13654 case value_t::null:
13656 oa->write_character(to_char_type(0xF6));
13660 case value_t::boolean:
13662 oa->write_character(j.m_value.boolean
13663 ? to_char_type(0xF5)
13664 : to_char_type(0xF4));
13668 case value_t::number_integer:
13670 if (j.m_value.number_integer >= 0)
13675 if (j.m_value.number_integer <= 0x17)
13677 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13679 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13681 oa->write_character(to_char_type(0x18));
13682 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13684 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13686 oa->write_character(to_char_type(0x19));
13687 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13689 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13691 oa->write_character(to_char_type(0x1A));
13692 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13696 oa->write_character(to_char_type(0x1B));
13697 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13704 const auto positive_number = -1 - j.m_value.number_integer;
13705 if (j.m_value.number_integer >= -24)
13707 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
13709 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13711 oa->write_character(to_char_type(0x38));
13712 write_number(
static_cast<std::uint8_t
>(positive_number));
13714 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13716 oa->write_character(to_char_type(0x39));
13717 write_number(
static_cast<std::uint16_t
>(positive_number));
13719 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13721 oa->write_character(to_char_type(0x3A));
13722 write_number(
static_cast<std::uint32_t
>(positive_number));
13726 oa->write_character(to_char_type(0x3B));
13727 write_number(
static_cast<std::uint64_t
>(positive_number));
13733 case value_t::number_unsigned:
13735 if (j.m_value.number_unsigned <= 0x17)
13737 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13739 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13741 oa->write_character(to_char_type(0x18));
13742 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13744 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13746 oa->write_character(to_char_type(0x19));
13747 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
13749 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13751 oa->write_character(to_char_type(0x1A));
13752 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
13756 oa->write_character(to_char_type(0x1B));
13757 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
13762 case value_t::number_float:
13764 if (std::isnan(j.m_value.number_float))
13767 oa->write_character(to_char_type(0xF9));
13768 oa->write_character(to_char_type(0x7E));
13769 oa->write_character(to_char_type(0x00));
13771 else if (std::isinf(j.m_value.number_float))
13774 oa->write_character(to_char_type(0xf9));
13775 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13776 oa->write_character(to_char_type(0x00));
13780 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13785 case value_t::string:
13788 const auto N = j.m_value.string->size();
13791 write_number(
static_cast<std::uint8_t
>(0x60 + N));
13793 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13795 oa->write_character(to_char_type(0x78));
13796 write_number(
static_cast<std::uint8_t
>(N));
13798 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13800 oa->write_character(to_char_type(0x79));
13801 write_number(
static_cast<std::uint16_t
>(N));
13803 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13805 oa->write_character(to_char_type(0x7A));
13806 write_number(
static_cast<std::uint32_t
>(N));
13809 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13811 oa->write_character(to_char_type(0x7B));
13812 write_number(
static_cast<std::uint64_t
>(N));
13817 oa->write_characters(
13818 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13819 j.m_value.string->size());
13823 case value_t::array:
13826 const auto N = j.m_value.array->size();
13829 write_number(
static_cast<std::uint8_t
>(0x80 + N));
13831 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13833 oa->write_character(to_char_type(0x98));
13834 write_number(
static_cast<std::uint8_t
>(N));
13836 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13838 oa->write_character(to_char_type(0x99));
13839 write_number(
static_cast<std::uint16_t
>(N));
13841 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13843 oa->write_character(to_char_type(0x9A));
13844 write_number(
static_cast<std::uint32_t
>(N));
13847 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13849 oa->write_character(to_char_type(0x9B));
13850 write_number(
static_cast<std::uint64_t
>(N));
13855 for (
const auto& el : *j.m_value.array)
13862 case value_t::binary:
13864 if (j.m_value.binary->has_subtype())
13866 if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint8_t>::max)())
13868 write_number(
static_cast<std::uint8_t
>(0xd8));
13869 write_number(
static_cast<std::uint8_t
>(j.m_value.binary->subtype()));
13871 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint16_t>::max)())
13873 write_number(
static_cast<std::uint8_t
>(0xd9));
13874 write_number(
static_cast<std::uint16_t
>(j.m_value.binary->subtype()));
13876 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint32_t>::max)())
13878 write_number(
static_cast<std::uint8_t
>(0xda));
13879 write_number(
static_cast<std::uint32_t
>(j.m_value.binary->subtype()));
13881 else if (j.m_value.binary->subtype() <= (std::numeric_limits<std::uint64_t>::max)())
13883 write_number(
static_cast<std::uint8_t
>(0xdb));
13884 write_number(
static_cast<std::uint64_t
>(j.m_value.binary->subtype()));
13889 const auto N = j.m_value.binary->size();
13892 write_number(
static_cast<std::uint8_t
>(0x40 + N));
13894 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13896 oa->write_character(to_char_type(0x58));
13897 write_number(
static_cast<std::uint8_t
>(N));
13899 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13901 oa->write_character(to_char_type(0x59));
13902 write_number(
static_cast<std::uint16_t
>(N));
13904 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13906 oa->write_character(to_char_type(0x5A));
13907 write_number(
static_cast<std::uint32_t
>(N));
13910 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13912 oa->write_character(to_char_type(0x5B));
13913 write_number(
static_cast<std::uint64_t
>(N));
13918 oa->write_characters(
13919 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13925 case value_t::object:
13928 const auto N = j.m_value.object->size();
13931 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
13933 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13935 oa->write_character(to_char_type(0xB8));
13936 write_number(
static_cast<std::uint8_t
>(N));
13938 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13940 oa->write_character(to_char_type(0xB9));
13941 write_number(
static_cast<std::uint16_t
>(N));
13943 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13945 oa->write_character(to_char_type(0xBA));
13946 write_number(
static_cast<std::uint32_t
>(N));
13949 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13951 oa->write_character(to_char_type(0xBB));
13952 write_number(
static_cast<std::uint64_t
>(N));
13957 for (
const auto& el : *j.m_value.object)
13959 write_cbor(el.first);
13960 write_cbor(el.second);
13965 case value_t::discarded:
13974 void write_msgpack(
const BasicJsonType& j)
13978 case value_t::null:
13980 oa->write_character(to_char_type(0xC0));
13984 case value_t::boolean:
13986 oa->write_character(j.m_value.boolean
13987 ? to_char_type(0xC3)
13988 : to_char_type(0xC2));
13992 case value_t::number_integer:
13994 if (j.m_value.number_integer >= 0)
13999 if (j.m_value.number_unsigned < 128)
14002 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14004 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14007 oa->write_character(to_char_type(0xCC));
14008 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14010 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14013 oa->write_character(to_char_type(0xCD));
14014 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14016 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14019 oa->write_character(to_char_type(0xCE));
14020 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14022 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14025 oa->write_character(to_char_type(0xCF));
14026 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14031 if (j.m_value.number_integer >= -32)
14034 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14036 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
14037 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
14040 oa->write_character(to_char_type(0xD0));
14041 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
14043 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
14044 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
14047 oa->write_character(to_char_type(0xD1));
14048 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
14050 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
14051 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
14054 oa->write_character(to_char_type(0xD2));
14055 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
14057 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
14058 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
14061 oa->write_character(to_char_type(0xD3));
14062 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
14068 case value_t::number_unsigned:
14070 if (j.m_value.number_unsigned < 128)
14073 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14075 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
14078 oa->write_character(to_char_type(0xCC));
14079 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
14081 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
14084 oa->write_character(to_char_type(0xCD));
14085 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
14087 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
14090 oa->write_character(to_char_type(0xCE));
14091 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
14093 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
14096 oa->write_character(to_char_type(0xCF));
14097 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
14102 case value_t::number_float:
14104 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
14108 case value_t::string:
14111 const auto N = j.m_value.string->size();
14115 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
14117 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
14120 oa->write_character(to_char_type(0xD9));
14121 write_number(
static_cast<std::uint8_t
>(N));
14123 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14126 oa->write_character(to_char_type(0xDA));
14127 write_number(
static_cast<std::uint16_t
>(N));
14129 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14132 oa->write_character(to_char_type(0xDB));
14133 write_number(
static_cast<std::uint32_t
>(N));
14137 oa->write_characters(
14138 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
14139 j.m_value.string->size());
14143 case value_t::array:
14146 const auto N = j.m_value.array->size();
14150 write_number(
static_cast<std::uint8_t
>(0x90 | N));
14152 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14155 oa->write_character(to_char_type(0xDC));
14156 write_number(
static_cast<std::uint16_t
>(N));
14158 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14161 oa->write_character(to_char_type(0xDD));
14162 write_number(
static_cast<std::uint32_t
>(N));
14166 for (
const auto& el : *j.m_value.array)
14173 case value_t::binary:
14177 const bool use_ext = j.m_value.binary->has_subtype();
14180 const auto N = j.m_value.binary->size();
14181 if (N <= (std::numeric_limits<std::uint8_t>::max)())
14183 std::uint8_t output_type{};
14190 output_type = 0xD4;
14193 output_type = 0xD5;
14196 output_type = 0xD6;
14199 output_type = 0xD7;
14202 output_type = 0xD8;
14205 output_type = 0xC7;
14213 output_type = 0xC4;
14217 oa->write_character(to_char_type(output_type));
14220 write_number(
static_cast<std::uint8_t
>(N));
14223 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14225 std::uint8_t output_type = use_ext
14229 oa->write_character(to_char_type(output_type));
14230 write_number(
static_cast<std::uint16_t
>(N));
14232 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14234 std::uint8_t output_type = use_ext
14238 oa->write_character(to_char_type(output_type));
14239 write_number(
static_cast<std::uint32_t
>(N));
14245 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
14249 oa->write_characters(
14250 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14256 case value_t::object:
14259 const auto N = j.m_value.object->size();
14263 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
14265 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
14268 oa->write_character(to_char_type(0xDE));
14269 write_number(
static_cast<std::uint16_t
>(N));
14271 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
14274 oa->write_character(to_char_type(0xDF));
14275 write_number(
static_cast<std::uint32_t
>(N));
14279 for (
const auto& el : *j.m_value.object)
14281 write_msgpack(el.first);
14282 write_msgpack(el.second);
14287 case value_t::discarded:
14299 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
14300 const bool use_type,
const bool add_prefix =
true)
14304 case value_t::null:
14308 oa->write_character(to_char_type(
'Z'));
14313 case value_t::boolean:
14317 oa->write_character(j.m_value.boolean
14318 ? to_char_type(
'T')
14319 : to_char_type(
'F'));
14324 case value_t::number_integer:
14326 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
14330 case value_t::number_unsigned:
14332 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
14336 case value_t::number_float:
14338 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
14342 case value_t::string:
14346 oa->write_character(to_char_type(
'S'));
14348 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
14349 oa->write_characters(
14350 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
14351 j.m_value.string->size());
14355 case value_t::array:
14359 oa->write_character(to_char_type(
'['));
14362 bool prefix_required =
true;
14363 if (use_type && !j.m_value.array->empty())
14365 JSON_ASSERT(use_count);
14366 const CharType first_prefix = ubjson_prefix(j.front());
14367 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
14368 [
this, first_prefix](
const BasicJsonType & v)
14370 return ubjson_prefix(v) == first_prefix;
14375 prefix_required =
false;
14376 oa->write_character(to_char_type(
'$'));
14377 oa->write_character(first_prefix);
14383 oa->write_character(to_char_type(
'#'));
14384 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
14387 for (
const auto& el : *j.m_value.array)
14389 write_ubjson(el, use_count, use_type, prefix_required);
14394 oa->write_character(to_char_type(
']'));
14400 case value_t::binary:
14404 oa->write_character(to_char_type(
'['));
14407 if (use_type && !j.m_value.binary->empty())
14409 JSON_ASSERT(use_count);
14410 oa->write_character(to_char_type(
'$'));
14411 oa->write_character(
'U');
14416 oa->write_character(to_char_type(
'#'));
14417 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
14422 oa->write_characters(
14423 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14424 j.m_value.binary->size());
14428 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
14430 oa->write_character(to_char_type(
'U'));
14431 oa->write_character(j.m_value.binary->data()[i]);
14437 oa->write_character(to_char_type(
']'));
14443 case value_t::object:
14447 oa->write_character(to_char_type(
'{'));
14450 bool prefix_required =
true;
14451 if (use_type && !j.m_value.object->empty())
14453 JSON_ASSERT(use_count);
14454 const CharType first_prefix = ubjson_prefix(j.front());
14455 const bool same_prefix = std::all_of(j.begin(), j.end(),
14456 [
this, first_prefix](
const BasicJsonType & v)
14458 return ubjson_prefix(v) == first_prefix;
14463 prefix_required =
false;
14464 oa->write_character(to_char_type(
'$'));
14465 oa->write_character(first_prefix);
14471 oa->write_character(to_char_type(
'#'));
14472 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
14475 for (
const auto& el : *j.m_value.object)
14477 write_number_with_ubjson_prefix(el.first.size(),
true);
14478 oa->write_characters(
14479 reinterpret_cast<const CharType*
>(el.first.c_str()),
14481 write_ubjson(el.second, use_count, use_type, prefix_required);
14486 oa->write_character(to_char_type(
'}'));
14492 case value_t::discarded:
14507 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
14509 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
14510 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14512 JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")", j));
14513 static_cast<void>(j);
14516 return 1ul + name.size() + 1u;
14522 void write_bson_entry_header(
const string_t& name,
14523 const std::uint8_t element_type)
14525 oa->write_character(to_char_type(element_type));
14526 oa->write_characters(
14527 reinterpret_cast<const CharType*
>(name.c_str()),
14534 void write_bson_boolean(
const string_t& name,
14537 write_bson_entry_header(name, 0x08);
14538 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
14544 void write_bson_double(
const string_t& name,
14545 const double value)
14547 write_bson_entry_header(name, 0x01);
14548 write_number<double, true>(value);
14554 static std::size_t calc_bson_string_size(
const string_t& value)
14556 return sizeof(std::int32_t) + value.size() + 1ul;
14562 void write_bson_string(
const string_t& name,
14563 const string_t& value)
14565 write_bson_entry_header(name, 0x02);
14567 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
14568 oa->write_characters(
14569 reinterpret_cast<const CharType*
>(value.c_str()),
14576 void write_bson_null(
const string_t& name)
14578 write_bson_entry_header(name, 0x0A);
14584 static std::size_t calc_bson_integer_size(
const std::int64_t value)
14586 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
14587 ?
sizeof(std::int32_t)
14588 :
sizeof(std::int64_t);
14594 void write_bson_integer(
const string_t& name,
14595 const std::int64_t value)
14597 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
14599 write_bson_entry_header(name, 0x10);
14600 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
14604 write_bson_entry_header(name, 0x12);
14605 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
14612 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value) noexcept
14614 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14615 ?
sizeof(std::int32_t)
14616 :
sizeof(std::int64_t);
14622 void write_bson_unsigned(
const string_t& name,
14623 const BasicJsonType& j)
14625 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14627 write_bson_entry_header(name, 0x10 );
14628 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(j.m_value.number_unsigned));
14630 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14632 write_bson_entry_header(name, 0x12 );
14633 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(j.m_value.number_unsigned));
14637 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));
14644 void write_bson_object_entry(
const string_t& name,
14645 const typename BasicJsonType::object_t& value)
14647 write_bson_entry_header(name, 0x03);
14648 write_bson_object(value);
14654 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
14656 std::size_t array_index = 0ul;
14658 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)
14660 return result + calc_bson_element_size(std::to_string(array_index++), el);
14663 return sizeof(std::int32_t) + embedded_document_size + 1ul;
14669 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
14671 return sizeof(std::int32_t) + value.size() + 1ul;
14677 void write_bson_array(
const string_t& name,
14678 const typename BasicJsonType::array_t& value)
14680 write_bson_entry_header(name, 0x04);
14681 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
14683 std::size_t array_index = 0ul;
14685 for (
const auto& el : value)
14687 write_bson_element(std::to_string(array_index++), el);
14690 oa->write_character(to_char_type(0x00));
14696 void write_bson_binary(
const string_t& name,
14697 const binary_t& value)
14699 write_bson_entry_header(name, 0x05);
14701 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size()));
14702 write_number(value.has_subtype() ?
static_cast<std::uint8_t
>(value.subtype()) : std::uint8_t(0x00));
14704 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
14711 static std::size_t calc_bson_element_size(
const string_t& name,
14712 const BasicJsonType& j)
14714 const auto header_size = calc_bson_entry_header_size(name, j);
14717 case value_t::object:
14718 return header_size + calc_bson_object_size(*j.m_value.object);
14720 case value_t::array:
14721 return header_size + calc_bson_array_size(*j.m_value.array);
14723 case value_t::binary:
14724 return header_size + calc_bson_binary_size(*j.m_value.binary);
14726 case value_t::boolean:
14727 return header_size + 1ul;
14729 case value_t::number_float:
14730 return header_size + 8ul;
14732 case value_t::number_integer:
14733 return header_size + calc_bson_integer_size(j.m_value.number_integer);
14735 case value_t::number_unsigned:
14736 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14738 case value_t::string:
14739 return header_size + calc_bson_string_size(*j.m_value.string);
14741 case value_t::null:
14742 return header_size + 0ul;
14745 case value_t::discarded:
14747 JSON_ASSERT(
false);
14759 void write_bson_element(
const string_t& name,
14760 const BasicJsonType& j)
14764 case value_t::object:
14765 return write_bson_object_entry(name, *j.m_value.object);
14767 case value_t::array:
14768 return write_bson_array(name, *j.m_value.array);
14770 case value_t::binary:
14771 return write_bson_binary(name, *j.m_value.binary);
14773 case value_t::boolean:
14774 return write_bson_boolean(name, j.m_value.boolean);
14776 case value_t::number_float:
14777 return write_bson_double(name, j.m_value.number_float);
14779 case value_t::number_integer:
14780 return write_bson_integer(name, j.m_value.number_integer);
14782 case value_t::number_unsigned:
14783 return write_bson_unsigned(name, j);
14785 case value_t::string:
14786 return write_bson_string(name, *j.m_value.string);
14788 case value_t::null:
14789 return write_bson_null(name);
14792 case value_t::discarded:
14794 JSON_ASSERT(
false);
14806 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
14808 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14809 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
14811 return result += calc_bson_element_size(el.first, el.second);
14814 return sizeof(std::int32_t) + document_size + 1ul;
14821 void write_bson_object(
const typename BasicJsonType::object_t& value)
14823 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
14825 for (
const auto& el : value)
14827 write_bson_element(el.first, el.second);
14830 oa->write_character(to_char_type(0x00));
14837 static constexpr CharType get_cbor_float_prefix(
float )
14839 return to_char_type(0xFA);
14842 static constexpr CharType get_cbor_float_prefix(
double )
14844 return to_char_type(0xFB);
14851 static constexpr CharType get_msgpack_float_prefix(
float )
14853 return to_char_type(0xCA);
14856 static constexpr CharType get_msgpack_float_prefix(
double )
14858 return to_char_type(0xCB);
14866 template<
typename NumberType,
typename std::enable_if<
14867 std::is_floating_point<NumberType>::value,
int>::type = 0>
14868 void write_number_with_ubjson_prefix(
const NumberType n,
14869 const bool add_prefix)
14873 oa->write_character(get_ubjson_float_prefix(n));
14879 template<
typename NumberType,
typename std::enable_if<
14880 std::is_unsigned<NumberType>::value,
int>::type = 0>
14881 void write_number_with_ubjson_prefix(
const NumberType n,
14882 const bool add_prefix)
14884 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14888 oa->write_character(to_char_type(
'i'));
14890 write_number(
static_cast<std::uint8_t
>(n));
14892 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14896 oa->write_character(to_char_type(
'U'));
14898 write_number(
static_cast<std::uint8_t
>(n));
14900 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14904 oa->write_character(to_char_type(
'I'));
14906 write_number(
static_cast<std::int16_t
>(n));
14908 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14912 oa->write_character(to_char_type(
'l'));
14914 write_number(
static_cast<std::int32_t
>(n));
14916 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14920 oa->write_character(to_char_type(
'L'));
14922 write_number(
static_cast<std::int64_t
>(n));
14928 oa->write_character(to_char_type(
'H'));
14931 const auto number = BasicJsonType(n).dump();
14932 write_number_with_ubjson_prefix(number.size(),
true);
14933 for (std::size_t i = 0; i < number.size(); ++i)
14935 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14941 template <
typename NumberType,
typename std::enable_if <
14942 std::is_signed<NumberType>::value&&
14943 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
14944 void write_number_with_ubjson_prefix(
const NumberType n,
14945 const bool add_prefix)
14947 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14951 oa->write_character(to_char_type(
'i'));
14953 write_number(
static_cast<std::int8_t
>(n));
14955 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)()))
14959 oa->write_character(to_char_type(
'U'));
14961 write_number(
static_cast<std::uint8_t
>(n));
14963 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14967 oa->write_character(to_char_type(
'I'));
14969 write_number(
static_cast<std::int16_t
>(n));
14971 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14975 oa->write_character(to_char_type(
'l'));
14977 write_number(
static_cast<std::int32_t
>(n));
14979 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14983 oa->write_character(to_char_type(
'L'));
14985 write_number(
static_cast<std::int64_t
>(n));
14992 oa->write_character(to_char_type(
'H'));
14995 const auto number = BasicJsonType(n).dump();
14996 write_number_with_ubjson_prefix(number.size(),
true);
14997 for (std::size_t i = 0; i < number.size(); ++i)
14999 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
15008 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
15012 case value_t::null:
15015 case value_t::boolean:
15016 return j.m_value.boolean ?
'T' :
'F';
15018 case value_t::number_integer:
15020 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)())
15024 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)())
15028 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)())
15032 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)())
15036 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)())
15044 case value_t::number_unsigned:
15046 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
15050 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
15054 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
15058 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
15062 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
15070 case value_t::number_float:
15071 return get_ubjson_float_prefix(j.m_value.number_float);
15073 case value_t::string:
15076 case value_t::array:
15077 case value_t::binary:
15080 case value_t::object:
15083 case value_t::discarded:
15089 static constexpr CharType get_ubjson_float_prefix(
float )
15094 static constexpr CharType get_ubjson_float_prefix(
double )
15114 template<
typename NumberType,
bool OutputIsLittleEndian = false>
15115 void write_number(
const NumberType n)
15118 std::array<CharType,
sizeof(NumberType)> vec{};
15119 std::memcpy(vec.data(), &n,
sizeof(NumberType));
15122 if (is_little_endian != OutputIsLittleEndian)
15125 std::reverse(vec.begin(), vec.end());
15128 oa->write_characters(vec.data(),
sizeof(NumberType));
15131 void write_compact_float(
const number_float_t n, detail::input_format_t format)
15134 #pragma GCC diagnostic push
15135 #pragma GCC diagnostic ignored "-Wfloat-equal"
15137 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
15138 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
15139 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
15141 oa->write_character(format == detail::input_format_t::cbor
15142 ? get_cbor_float_prefix(
static_cast<float>(n))
15143 : get_msgpack_float_prefix(
static_cast<float>(n)));
15144 write_number(
static_cast<float>(n));
15148 oa->write_character(format == detail::input_format_t::cbor
15149 ? get_cbor_float_prefix(n)
15150 : get_msgpack_float_prefix(n));
15154 #pragma GCC diagnostic pop
15163 template <
typename C = CharType,
15164 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
15165 static constexpr CharType to_char_type(std::uint8_t x) noexcept
15167 return *
reinterpret_cast<char*
>(&x);
15170 template <
typename C = CharType,
15171 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
15172 static CharType to_char_type(std::uint8_t x) noexcept
15174 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
15175 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
15177 std::memcpy(&result, &x,
sizeof(x));
15181 template<
typename C = CharType,
15182 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
15183 static constexpr CharType to_char_type(std::uint8_t x) noexcept
15188 template <
typename InputCharType,
typename C = CharType,
15190 std::is_signed<C>::value &&
15191 std::is_signed<char>::value &&
15192 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
15194 static constexpr CharType to_char_type(InputCharType x) noexcept
15201 const bool is_little_endian = little_endianess();
15204 output_adapter_t<CharType> oa =
nullptr;
15214 #include <algorithm>
15223 #include <type_traits>
15234 #include <type_traits>
15263 namespace dtoa_impl
15266 template<
typename Target,
typename Source>
15267 Target reinterpret_bits(
const Source source)
15269 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
15272 std::memcpy(&target, &source,
sizeof(Source));
15278 static constexpr
int kPrecision = 64;
15280 std::uint64_t f = 0;
15283 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
15289 static diyfp sub(
const diyfp& x,
const diyfp& y) noexcept
15291 JSON_ASSERT(x.e == y.e);
15292 JSON_ASSERT(x.f >= y.f);
15294 return {x.f - y.f, x.e};
15301 static diyfp mul(
const diyfp& x,
const diyfp& y) noexcept
15303 static_assert(kPrecision == 64,
"internal error");
15328 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
15329 const std::uint64_t u_hi = x.f >> 32u;
15330 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
15331 const std::uint64_t v_hi = y.f >> 32u;
15333 const std::uint64_t p0 = u_lo * v_lo;
15334 const std::uint64_t p1 = u_lo * v_hi;
15335 const std::uint64_t p2 = u_hi * v_lo;
15336 const std::uint64_t p3 = u_hi * v_hi;
15338 const std::uint64_t p0_hi = p0 >> 32u;
15339 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
15340 const std::uint64_t p1_hi = p1 >> 32u;
15341 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
15342 const std::uint64_t p2_hi = p2 >> 32u;
15344 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
15355 Q += std::uint64_t{1} << (64u - 32u - 1u);
15357 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
15359 return {h, x.e + y.e + 64};
15366 static diyfp normalize(diyfp x) noexcept
15368 JSON_ASSERT(x.f != 0);
15370 while ((x.f >> 63u) == 0)
15383 static diyfp normalize_to(
const diyfp& x,
const int target_exponent) noexcept
15385 const int delta = x.e - target_exponent;
15387 JSON_ASSERT(delta >= 0);
15388 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15390 return {x.f << delta, target_exponent};
15407 template<
typename FloatType>
15408 boundaries compute_boundaries(FloatType value)
15410 JSON_ASSERT(std::isfinite(value));
15411 JSON_ASSERT(value > 0);
15420 static_assert(std::numeric_limits<FloatType>::is_iec559,
15421 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
15423 constexpr
int kPrecision = std::numeric_limits<FloatType>::digits;
15424 constexpr
int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
15425 constexpr
int kMinExp = 1 - kBias;
15426 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
15428 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
15430 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
15431 const std::uint64_t E = bits >> (kPrecision - 1);
15432 const std::uint64_t F = bits & (kHiddenBit - 1);
15434 const bool is_denormal = E == 0;
15435 const diyfp v = is_denormal
15436 ? diyfp(F, kMinExp)
15437 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
15460 const bool lower_boundary_is_closer = F == 0 && E > 1;
15461 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
15462 const diyfp m_minus = lower_boundary_is_closer
15463 ? diyfp(4 * v.f - 1, v.e - 2)
15464 : diyfp(2 * v.f - 1, v.e - 1);
15467 const diyfp w_plus = diyfp::normalize(m_plus);
15470 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
15472 return {diyfp::normalize(v), w_minus, w_plus};
15530 constexpr
int kAlpha = -60;
15531 constexpr
int kGamma = -32;
15533 struct cached_power
15547 inline cached_power get_cached_power_for_binary_exponent(
int e)
15599 constexpr
int kCachedPowersMinDecExp = -300;
15600 constexpr
int kCachedPowersDecStep = 8;
15602 static constexpr std::array<cached_power, 79> kCachedPowers =
15605 { 0xAB70FE17C79AC6CA, -1060, -300 },
15606 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15607 { 0xBE5691EF416BD60C, -1007, -284 },
15608 { 0x8DD01FAD907FFC3C, -980, -276 },
15609 { 0xD3515C2831559A83, -954, -268 },
15610 { 0x9D71AC8FADA6C9B5, -927, -260 },
15611 { 0xEA9C227723EE8BCB, -901, -252 },
15612 { 0xAECC49914078536D, -874, -244 },
15613 { 0x823C12795DB6CE57, -847, -236 },
15614 { 0xC21094364DFB5637, -821, -228 },
15615 { 0x9096EA6F3848984F, -794, -220 },
15616 { 0xD77485CB25823AC7, -768, -212 },
15617 { 0xA086CFCD97BF97F4, -741, -204 },
15618 { 0xEF340A98172AACE5, -715, -196 },
15619 { 0xB23867FB2A35B28E, -688, -188 },
15620 { 0x84C8D4DFD2C63F3B, -661, -180 },
15621 { 0xC5DD44271AD3CDBA, -635, -172 },
15622 { 0x936B9FCEBB25C996, -608, -164 },
15623 { 0xDBAC6C247D62A584, -582, -156 },
15624 { 0xA3AB66580D5FDAF6, -555, -148 },
15625 { 0xF3E2F893DEC3F126, -529, -140 },
15626 { 0xB5B5ADA8AAFF80B8, -502, -132 },
15627 { 0x87625F056C7C4A8B, -475, -124 },
15628 { 0xC9BCFF6034C13053, -449, -116 },
15629 { 0x964E858C91BA2655, -422, -108 },
15630 { 0xDFF9772470297EBD, -396, -100 },
15631 { 0xA6DFBD9FB8E5B88F, -369, -92 },
15632 { 0xF8A95FCF88747D94, -343, -84 },
15633 { 0xB94470938FA89BCF, -316, -76 },
15634 { 0x8A08F0F8BF0F156B, -289, -68 },
15635 { 0xCDB02555653131B6, -263, -60 },
15636 { 0x993FE2C6D07B7FAC, -236, -52 },
15637 { 0xE45C10C42A2B3B06, -210, -44 },
15638 { 0xAA242499697392D3, -183, -36 },
15639 { 0xFD87B5F28300CA0E, -157, -28 },
15640 { 0xBCE5086492111AEB, -130, -20 },
15641 { 0x8CBCCC096F5088CC, -103, -12 },
15642 { 0xD1B71758E219652C, -77, -4 },
15643 { 0x9C40000000000000, -50, 4 },
15644 { 0xE8D4A51000000000, -24, 12 },
15645 { 0xAD78EBC5AC620000, 3, 20 },
15646 { 0x813F3978F8940984, 30, 28 },
15647 { 0xC097CE7BC90715B3, 56, 36 },
15648 { 0x8F7E32CE7BEA5C70, 83, 44 },
15649 { 0xD5D238A4ABE98068, 109, 52 },
15650 { 0x9F4F2726179A2245, 136, 60 },
15651 { 0xED63A231D4C4FB27, 162, 68 },
15652 { 0xB0DE65388CC8ADA8, 189, 76 },
15653 { 0x83C7088E1AAB65DB, 216, 84 },
15654 { 0xC45D1DF942711D9A, 242, 92 },
15655 { 0x924D692CA61BE758, 269, 100 },
15656 { 0xDA01EE641A708DEA, 295, 108 },
15657 { 0xA26DA3999AEF774A, 322, 116 },
15658 { 0xF209787BB47D6B85, 348, 124 },
15659 { 0xB454E4A179DD1877, 375, 132 },
15660 { 0x865B86925B9BC5C2, 402, 140 },
15661 { 0xC83553C5C8965D3D, 428, 148 },
15662 { 0x952AB45CFA97A0B3, 455, 156 },
15663 { 0xDE469FBD99A05FE3, 481, 164 },
15664 { 0xA59BC234DB398C25, 508, 172 },
15665 { 0xF6C69A72A3989F5C, 534, 180 },
15666 { 0xB7DCBF5354E9BECE, 561, 188 },
15667 { 0x88FCF317F22241E2, 588, 196 },
15668 { 0xCC20CE9BD35C78A5, 614, 204 },
15669 { 0x98165AF37B2153DF, 641, 212 },
15670 { 0xE2A0B5DC971F303A, 667, 220 },
15671 { 0xA8D9D1535CE3B396, 694, 228 },
15672 { 0xFB9B7CD9A4A7443C, 720, 236 },
15673 { 0xBB764C4CA7A44410, 747, 244 },
15674 { 0x8BAB8EEFB6409C1A, 774, 252 },
15675 { 0xD01FEF10A657842C, 800, 260 },
15676 { 0x9B10A4E5E9913129, 827, 268 },
15677 { 0xE7109BFBA19C0C9D, 853, 276 },
15678 { 0xAC2820D9623BF429, 880, 284 },
15679 { 0x80444B5E7AA7CF85, 907, 292 },
15680 { 0xBF21E44003ACDD2D, 933, 300 },
15681 { 0x8E679C2F5E44FF8F, 960, 308 },
15682 { 0xD433179D9C8CB841, 986, 316 },
15683 { 0x9E19DB92B4E31BA9, 1013, 324 },
15691 JSON_ASSERT(e >= -1500);
15692 JSON_ASSERT(e <= 1500);
15693 const int f = kAlpha - e - 1;
15694 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
15696 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15697 JSON_ASSERT(index >= 0);
15698 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
15700 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
15701 JSON_ASSERT(kAlpha <= cached.e + e + 64);
15702 JSON_ASSERT(kGamma >= cached.e + e + 64);
15711 inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
15714 if (n >= 1000000000)
15716 pow10 = 1000000000;
15720 if (n >= 100000000)
15765 inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
15766 std::uint64_t rest, std::uint64_t ten_k)
15768 JSON_ASSERT(len >= 1);
15769 JSON_ASSERT(dist <= delta);
15770 JSON_ASSERT(rest <= delta);
15771 JSON_ASSERT(ten_k > 0);
15793 && delta - rest >= ten_k
15794 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15796 JSON_ASSERT(buf[len - 1] !=
'0');
15806 inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
15807 diyfp M_minus, diyfp w, diyfp M_plus)
15809 static_assert(kAlpha >= -60,
"internal error");
15810 static_assert(kGamma <= -32,
"internal error");
15824 JSON_ASSERT(M_plus.e >= kAlpha);
15825 JSON_ASSERT(M_plus.e <= kGamma);
15827 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
15828 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
15837 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15839 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
15840 std::uint64_t p2 = M_plus.f & (one.f - 1);
15846 JSON_ASSERT(p1 > 0);
15848 std::uint32_t pow10{};
15849 const int k = find_largest_pow10(p1, pow10);
15876 const std::uint32_t d = p1 / pow10;
15877 const std::uint32_t r = p1 % pow10;
15882 JSON_ASSERT(d <= 9);
15883 buffer[length++] =
static_cast<char>(
'0' + d);
15902 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15907 decimal_exponent += n;
15918 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15919 grisu2_round(buffer, length, dist, delta, rest, ten_n);
15969 JSON_ASSERT(p2 > delta);
15980 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15982 const std::uint64_t d = p2 >> -one.e;
15983 const std::uint64_t r = p2 & (one.f - 1);
15989 JSON_ASSERT(d <= 9);
15990 buffer[length++] =
static_cast<char>(
'0' + d);
16015 decimal_exponent -= m;
16023 const std::uint64_t ten_m = one.f;
16024 grisu2_round(buffer, length, dist, delta, p2, ten_m);
16046 JSON_HEDLEY_NON_NULL(1)
16047 inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
16048 diyfp m_minus, diyfp v, diyfp m_plus)
16050 JSON_ASSERT(m_plus.e == m_minus.e);
16051 JSON_ASSERT(m_plus.e == v.e);
16062 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
16064 const diyfp c_minus_k(cached.f, cached.e);
16067 const diyfp w = diyfp::mul(v, c_minus_k);
16068 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
16069 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
16092 const diyfp M_minus(w_minus.f + 1, w_minus.e);
16093 const diyfp M_plus (w_plus.f - 1, w_plus.e );
16095 decimal_exponent = -cached.k;
16097 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
16105 template<
typename FloatType>
16106 JSON_HEDLEY_NON_NULL(1)
16107 void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
16109 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
16110 "internal error: not enough precision");
16112 JSON_ASSERT(std::isfinite(value));
16113 JSON_ASSERT(value > 0);
16132 const boundaries w = compute_boundaries(
static_cast<double>(value));
16134 const boundaries w = compute_boundaries(value);
16137 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
16145 JSON_HEDLEY_NON_NULL(1)
16147 inline
char* append_exponent(
char* buf,
int e)
16149 JSON_ASSERT(e > -1000);
16150 JSON_ASSERT(e < 1000);
16162 auto k =
static_cast<std::uint32_t
>(e);
16168 *buf++ =
static_cast<char>(
'0' + k);
16172 *buf++ =
static_cast<char>(
'0' + k / 10);
16174 *buf++ =
static_cast<char>(
'0' + k);
16178 *buf++ =
static_cast<char>(
'0' + k / 100);
16180 *buf++ =
static_cast<char>(
'0' + k / 10);
16182 *buf++ =
static_cast<char>(
'0' + k);
16197 JSON_HEDLEY_NON_NULL(1)
16199 inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
16200 int min_exp,
int max_exp)
16202 JSON_ASSERT(min_exp < 0);
16203 JSON_ASSERT(max_exp > 0);
16206 const int n = len + decimal_exponent;
16212 if (k <= n && n <= max_exp)
16217 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
16221 return buf + (
static_cast<size_t>(n) + 2);
16224 if (0 < n && n <= max_exp)
16229 JSON_ASSERT(k > n);
16231 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
16233 return buf + (
static_cast<size_t>(k) + 1U);
16236 if (min_exp < n && n <= 0)
16241 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
16244 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
16245 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
16260 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
16262 buf += 1 +
static_cast<size_t>(k);
16266 return append_exponent(buf, n - 1);
16281 template<
typename FloatType>
16282 JSON_HEDLEY_NON_NULL(1, 2)
16284 char* to_chars(
char* first, const
char* last, FloatType value)
16286 static_cast<void>(last);
16287 JSON_ASSERT(std::isfinite(value));
16290 if (std::signbit(value))
16297 #pragma GCC diagnostic push
16298 #pragma GCC diagnostic ignored "-Wfloat-equal"
16309 #pragma GCC diagnostic pop
16312 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
16319 int decimal_exponent = 0;
16320 dtoa_impl::grisu2(first, len, decimal_exponent, value);
16322 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
16325 constexpr
int kMinExp = -4;
16327 constexpr
int kMaxExp = std::numeric_limits<FloatType>::digits10;
16329 JSON_ASSERT(last - first >= kMaxExp + 2);
16330 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
16331 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
16333 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
16361 enum class error_handler_t
16368 template<
typename BasicJsonType>
16371 using string_t =
typename BasicJsonType::string_t;
16372 using number_float_t =
typename BasicJsonType::number_float_t;
16373 using number_integer_t =
typename BasicJsonType::number_integer_t;
16374 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
16375 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
16376 static constexpr std::uint8_t UTF8_ACCEPT = 0;
16377 static constexpr std::uint8_t UTF8_REJECT = 1;
16385 serializer(output_adapter_t<char> s,
const char ichar,
16386 error_handler_t error_handler_ = error_handler_t::strict)
16388 , loc(std::localeconv())
16389 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
16390 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
16391 , indent_char(ichar)
16392 , indent_string(512, indent_char)
16393 , error_handler(error_handler_)
16397 serializer(
const serializer&) =
delete;
16398 serializer& operator=(
const serializer&) =
delete;
16399 serializer(serializer&&) =
delete;
16400 serializer& operator=(serializer&&) =
delete;
16401 ~serializer() =
default;
16425 void dump(
const BasicJsonType& val,
16426 const bool pretty_print,
16427 const bool ensure_ascii,
16428 const unsigned int indent_step,
16429 const unsigned int current_indent = 0)
16431 switch (val.m_type)
16433 case value_t::object:
16435 if (val.m_value.object->empty())
16437 o->write_characters(
"{}", 2);
16443 o->write_characters(
"{\n", 2);
16446 const auto new_indent = current_indent + indent_step;
16447 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16449 indent_string.resize(indent_string.size() * 2,
' ');
16453 auto i = val.m_value.object->cbegin();
16454 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16456 o->write_characters(indent_string.c_str(), new_indent);
16457 o->write_character(
'\"');
16458 dump_escaped(i->first, ensure_ascii);
16459 o->write_characters(
"\": ", 3);
16460 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16461 o->write_characters(
",\n", 2);
16465 JSON_ASSERT(i != val.m_value.object->cend());
16466 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16467 o->write_characters(indent_string.c_str(), new_indent);
16468 o->write_character(
'\"');
16469 dump_escaped(i->first, ensure_ascii);
16470 o->write_characters(
"\": ", 3);
16471 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16473 o->write_character(
'\n');
16474 o->write_characters(indent_string.c_str(), current_indent);
16475 o->write_character(
'}');
16479 o->write_character(
'{');
16482 auto i = val.m_value.object->cbegin();
16483 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16485 o->write_character(
'\"');
16486 dump_escaped(i->first, ensure_ascii);
16487 o->write_characters(
"\":", 2);
16488 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16489 o->write_character(
',');
16493 JSON_ASSERT(i != val.m_value.object->cend());
16494 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16495 o->write_character(
'\"');
16496 dump_escaped(i->first, ensure_ascii);
16497 o->write_characters(
"\":", 2);
16498 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16500 o->write_character(
'}');
16506 case value_t::array:
16508 if (val.m_value.array->empty())
16510 o->write_characters(
"[]", 2);
16516 o->write_characters(
"[\n", 2);
16519 const auto new_indent = current_indent + indent_step;
16520 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16522 indent_string.resize(indent_string.size() * 2,
' ');
16526 for (
auto i = val.m_value.array->cbegin();
16527 i != val.m_value.array->cend() - 1; ++i)
16529 o->write_characters(indent_string.c_str(), new_indent);
16530 dump(*i,
true, ensure_ascii, indent_step, new_indent);
16531 o->write_characters(
",\n", 2);
16535 JSON_ASSERT(!val.m_value.array->empty());
16536 o->write_characters(indent_string.c_str(), new_indent);
16537 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
16539 o->write_character(
'\n');
16540 o->write_characters(indent_string.c_str(), current_indent);
16541 o->write_character(
']');
16545 o->write_character(
'[');
16548 for (
auto i = val.m_value.array->cbegin();
16549 i != val.m_value.array->cend() - 1; ++i)
16551 dump(*i,
false, ensure_ascii, indent_step, current_indent);
16552 o->write_character(
',');
16556 JSON_ASSERT(!val.m_value.array->empty());
16557 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
16559 o->write_character(
']');
16565 case value_t::string:
16567 o->write_character(
'\"');
16568 dump_escaped(*val.m_value.string, ensure_ascii);
16569 o->write_character(
'\"');
16573 case value_t::binary:
16577 o->write_characters(
"{\n", 2);
16580 const auto new_indent = current_indent + indent_step;
16581 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16583 indent_string.resize(indent_string.size() * 2,
' ');
16586 o->write_characters(indent_string.c_str(), new_indent);
16588 o->write_characters(
"\"bytes\": [", 10);
16590 if (!val.m_value.binary->empty())
16592 for (
auto i = val.m_value.binary->cbegin();
16593 i != val.m_value.binary->cend() - 1; ++i)
16596 o->write_characters(
", ", 2);
16598 dump_integer(val.m_value.binary->back());
16601 o->write_characters(
"],\n", 3);
16602 o->write_characters(indent_string.c_str(), new_indent);
16604 o->write_characters(
"\"subtype\": ", 11);
16605 if (val.m_value.binary->has_subtype())
16607 dump_integer(val.m_value.binary->subtype());
16611 o->write_characters(
"null", 4);
16613 o->write_character(
'\n');
16614 o->write_characters(indent_string.c_str(), current_indent);
16615 o->write_character(
'}');
16619 o->write_characters(
"{\"bytes\":[", 10);
16621 if (!val.m_value.binary->empty())
16623 for (
auto i = val.m_value.binary->cbegin();
16624 i != val.m_value.binary->cend() - 1; ++i)
16627 o->write_character(
',');
16629 dump_integer(val.m_value.binary->back());
16632 o->write_characters(
"],\"subtype\":", 12);
16633 if (val.m_value.binary->has_subtype())
16635 dump_integer(val.m_value.binary->subtype());
16636 o->write_character(
'}');
16640 o->write_characters(
"null}", 5);
16646 case value_t::boolean:
16648 if (val.m_value.boolean)
16650 o->write_characters(
"true", 4);
16654 o->write_characters(
"false", 5);
16659 case value_t::number_integer:
16661 dump_integer(val.m_value.number_integer);
16665 case value_t::number_unsigned:
16667 dump_integer(val.m_value.number_unsigned);
16671 case value_t::number_float:
16673 dump_float(val.m_value.number_float);
16677 case value_t::discarded:
16679 o->write_characters(
"<discarded>", 11);
16683 case value_t::null:
16685 o->write_characters(
"null", 4);
16690 JSON_ASSERT(
false);
16694 JSON_PRIVATE_UNLESS_TESTED:
16709 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
16711 std::uint32_t codepoint{};
16712 std::uint8_t state = UTF8_ACCEPT;
16713 std::size_t bytes = 0;
16716 std::size_t bytes_after_last_accept = 0;
16717 std::size_t undumped_chars = 0;
16719 for (std::size_t i = 0; i < s.size(); ++i)
16721 const auto byte =
static_cast<std::uint8_t
>(s[i]);
16723 switch (decode(state, codepoint,
byte))
16731 string_buffer[bytes++] =
'\\';
16732 string_buffer[bytes++] =
'b';
16738 string_buffer[bytes++] =
'\\';
16739 string_buffer[bytes++] =
't';
16745 string_buffer[bytes++] =
'\\';
16746 string_buffer[bytes++] =
'n';
16752 string_buffer[bytes++] =
'\\';
16753 string_buffer[bytes++] =
'f';
16759 string_buffer[bytes++] =
'\\';
16760 string_buffer[bytes++] =
'r';
16766 string_buffer[bytes++] =
'\\';
16767 string_buffer[bytes++] =
'\"';
16773 string_buffer[bytes++] =
'\\';
16774 string_buffer[bytes++] =
'\\';
16782 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16784 if (codepoint <= 0xFFFF)
16787 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
16788 static_cast<std::uint16_t
>(codepoint));
16794 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
16795 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
16796 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
16804 string_buffer[bytes++] = s[i];
16813 if (string_buffer.size() - bytes < 13)
16815 o->write_characters(string_buffer.data(), bytes);
16820 bytes_after_last_accept = bytes;
16821 undumped_chars = 0;
16827 switch (error_handler)
16829 case error_handler_t::strict:
16831 std::string sn(9,
'\0');
16833 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
16834 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn, BasicJsonType()));
16837 case error_handler_t::ignore:
16838 case error_handler_t::replace:
16844 if (undumped_chars > 0)
16851 bytes = bytes_after_last_accept;
16853 if (error_handler == error_handler_t::replace)
16858 string_buffer[bytes++] =
'\\';
16859 string_buffer[bytes++] =
'u';
16860 string_buffer[bytes++] =
'f';
16861 string_buffer[bytes++] =
'f';
16862 string_buffer[bytes++] =
'f';
16863 string_buffer[bytes++] =
'd';
16867 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
16868 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
16869 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
16875 if (string_buffer.size() - bytes < 13)
16877 o->write_characters(string_buffer.data(), bytes);
16881 bytes_after_last_accept = bytes;
16884 undumped_chars = 0;
16887 state = UTF8_ACCEPT;
16892 JSON_ASSERT(
false);
16902 string_buffer[bytes++] = s[i];
16911 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16916 o->write_characters(string_buffer.data(), bytes);
16922 switch (error_handler)
16924 case error_handler_t::strict:
16926 std::string sn(9,
'\0');
16928 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
16929 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
16932 case error_handler_t::ignore:
16935 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16939 case error_handler_t::replace:
16942 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16946 o->write_characters(
"\\ufffd", 6);
16950 o->write_characters(
"\xEF\xBF\xBD", 3);
16956 JSON_ASSERT(
false);
16970 inline unsigned int count_digits(number_unsigned_t x) noexcept
16972 unsigned int n_digits = 1;
16981 return n_digits + 1;
16985 return n_digits + 2;
16989 return n_digits + 3;
17005 template <
typename NumberType, detail::enable_if_t <
17006 std::is_integral<NumberType>::value ||
17007 std::is_same<NumberType, number_unsigned_t>::value ||
17008 std::is_same<NumberType, number_integer_t>::value ||
17009 std::is_same<NumberType, binary_char_t>::value,
17011 void dump_integer(NumberType x)
17013 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
17016 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
17017 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
17018 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
17019 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
17020 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
17021 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
17022 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
17023 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
17024 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
17025 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
17032 o->write_character(
'0');
17037 auto buffer_ptr = number_buffer.begin();
17039 const bool is_negative = std::is_signed<NumberType>::value && !(x >= 0);
17040 number_unsigned_t abs_value;
17042 unsigned int n_chars{};
17047 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
17050 n_chars = 1 + count_digits(abs_value);
17054 abs_value =
static_cast<number_unsigned_t
>(x);
17055 n_chars = count_digits(abs_value);
17059 JSON_ASSERT(n_chars < number_buffer.size() - 1);
17063 buffer_ptr += n_chars;
17067 while (abs_value >= 100)
17069 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
17071 *(--buffer_ptr) = digits_to_99[digits_index][1];
17072 *(--buffer_ptr) = digits_to_99[digits_index][0];
17075 if (abs_value >= 10)
17077 const auto digits_index =
static_cast<unsigned>(abs_value);
17078 *(--buffer_ptr) = digits_to_99[digits_index][1];
17079 *(--buffer_ptr) = digits_to_99[digits_index][0];
17083 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
17086 o->write_characters(number_buffer.data(), n_chars);
17097 void dump_float(number_float_t x)
17100 if (!std::isfinite(x))
17102 o->write_characters(
"null", 4);
17111 static constexpr
bool is_ieee_single_or_double
17112 = (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) ||
17113 (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);
17115 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
17118 void dump_float(number_float_t x, std::true_type )
17120 auto* begin = number_buffer.data();
17121 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
17123 o->write_characters(begin,
static_cast<size_t>(end - begin));
17126 void dump_float(number_float_t x, std::false_type )
17129 static constexpr
auto d = std::numeric_limits<number_float_t>::max_digits10;
17133 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
17136 JSON_ASSERT(len > 0);
17138 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
17141 if (thousands_sep !=
'\0')
17143 auto*
const end = std::remove(number_buffer.begin(),
17144 number_buffer.begin() + len, thousands_sep);
17145 std::fill(end, number_buffer.end(),
'\0');
17146 JSON_ASSERT((end - number_buffer.begin()) <= len);
17147 len = (end - number_buffer.begin());
17151 if (decimal_point !=
'\0' && decimal_point !=
'.')
17153 auto*
const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
17154 if (dec_pos != number_buffer.end())
17160 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
17163 const bool value_is_int_like =
17164 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
17167 return c ==
'.' || c ==
'e';
17170 if (value_is_int_like)
17172 o->write_characters(
".0", 2);
17197 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte) noexcept
17199 static const std::array<std::uint8_t, 400> utf8d =
17202 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,
17203 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,
17204 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,
17205 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,
17206 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,
17207 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,
17208 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,
17209 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
17210 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
17211 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
17212 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,
17213 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,
17214 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,
17215 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
17219 JSON_ASSERT(
byte < utf8d.size());
17220 const std::uint8_t type = utf8d[byte];
17222 codep = (state != UTF8_ACCEPT)
17223 ? (
byte & 0x3fu) | (codep << 6u)
17224 : (0xFFu >> type) & (byte);
17226 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
17227 JSON_ASSERT(index < 400);
17228 state = utf8d[index];
17237 number_unsigned_t remove_sign(number_unsigned_t x)
17239 JSON_ASSERT(
false);
17252 inline number_unsigned_t remove_sign(number_integer_t x) noexcept
17254 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
17255 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
17260 output_adapter_t<char> o =
nullptr;
17263 std::array<char, 64> number_buffer{{}};
17266 const std::lconv* loc =
nullptr;
17268 const char thousands_sep =
'\0';
17270 const char decimal_point =
'\0';
17273 std::array<char, 512> string_buffer{{}};
17276 const char indent_char;
17278 string_t indent_string;
17281 const error_handler_t error_handler;
17293 #include <functional>
17294 #include <initializer_list>
17295 #include <iterator>
17297 #include <stdexcept>
17298 #include <type_traits>
17310 template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
17311 class Allocator = std::allocator<std::pair<const Key, T>>>
17316 using Container = std::vector<std::pair<const Key, T>, Allocator>;
17317 using typename Container::iterator;
17318 using typename Container::const_iterator;
17319 using typename Container::size_type;
17320 using typename Container::value_type;
17325 template <
class It>
17328 ordered_map(std::initializer_list<T> init,
const Allocator& alloc = Allocator() )
17333 for (
auto it = this->begin(); it != this->end(); ++it)
17335 if (it->first == key)
17337 return {it,
false};
17340 Container::emplace_back(key, t);
17341 return {--this->end(),
true};
17346 return emplace(key, T{}).first->second;
17356 for (
auto it = this->begin(); it != this->end(); ++it)
17358 if (it->first == key)
17364 JSON_THROW(std::out_of_range(
"key not found"));
17367 const T&
at(
const Key& key)
const
17369 for (
auto it = this->begin(); it != this->end(); ++it)
17371 if (it->first == key)
17377 JSON_THROW(std::out_of_range(
"key not found"));
17382 for (
auto it = this->begin(); it != this->end(); ++it)
17384 if (it->first == key)
17387 for (
auto next = it; ++next != this->end(); ++it)
17390 new (&*it) value_type{std::move(*next)};
17392 Container::pop_back();
17404 for (
auto next = it; ++next != this->end(); ++it)
17407 new (&*it) value_type{std::move(*next)};
17409 Container::pop_back();
17415 for (
auto it = this->begin(); it != this->end(); ++it)
17417 if (it->first == key)
17427 for (
auto it = this->begin(); it != this->end(); ++it)
17429 if (it->first == key)
17434 return Container::end();
17437 const_iterator
find(
const Key& key)
const
17439 for (
auto it = this->begin(); it != this->end(); ++it)
17441 if (it->first == key)
17446 return Container::end();
17449 std::pair<iterator, bool>
insert( value_type&& value )
17451 return emplace(value.first, std::move(value.second));
17454 std::pair<iterator, bool>
insert(
const value_type& value )
17456 for (
auto it = this->begin(); it != this->end(); ++it)
17458 if (it->first == value.first)
17460 return {it,
false};
17463 Container::push_back(value);
17464 return {--this->end(),
true};
17467 template<
typename InputIt>
17468 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
17469 std::input_iterator_tag>::value>::type;
17471 template<
typename InputIt,
typename = require_input_iter<InputIt>>
17474 for (
auto it = first; it != last; ++it)
17484 #if defined(JSON_HAS_CPP_17)
17485 #include <string_view>
17580 NLOHMANN_BASIC_JSON_TPL_DECLARATION
17585 friend ::nlohmann::json_pointer<basic_json>;
17587 template<
typename BasicJsonType,
typename InputType>
17588 friend class ::nlohmann::detail::parser;
17589 friend ::nlohmann::detail::serializer<basic_json>;
17590 template<
typename BasicJsonType>
17591 friend class ::nlohmann::detail::iter_impl;
17592 template<
typename BasicJsonType,
typename CharType>
17593 friend class ::nlohmann::detail::binary_writer;
17594 template<
typename BasicJsonType,
typename InputType,
typename SAX>
17595 friend class ::nlohmann::detail::binary_reader;
17596 template<
typename BasicJsonType>
17597 friend class ::nlohmann::detail::json_sax_dom_parser;
17598 template<
typename BasicJsonType>
17599 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17600 friend class ::nlohmann::detail::exception;
17603 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
17605 JSON_PRIVATE_UNLESS_TESTED:
17607 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
17609 template<
typename InputAdapterType>
17610 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17611 InputAdapterType adapter,
17612 detail::parser_callback_t<basic_json>cb =
nullptr,
17613 const bool allow_exceptions =
true,
17614 const bool ignore_comments =
false
17617 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17618 std::move(cb), allow_exceptions, ignore_comments);
17622 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
17623 template<
typename BasicJsonType>
17624 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
17625 template<
typename BasicJsonType>
17626 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
17627 template<
typename Iterator>
17628 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
17629 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
17631 template<
typename CharType>
17632 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
17634 template<
typename InputType>
17635 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
17636 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
17638 JSON_PRIVATE_UNLESS_TESTED:
17639 using serializer = ::nlohmann::detail::serializer<basic_json>;
17642 using value_t = detail::value_t;
17645 template<
typename T,
typename SFINAE>
17648 using error_handler_t = detail::error_handler_t;
17650 using cbor_tag_handler_t = detail::cbor_tag_handler_t;
17654 using input_format_t = detail::input_format_t;
17708 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
17710 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
17763 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
17764 result[
"name"] =
"JSON for Modern C++";
17765 result[
"url"] =
"https://github.com/nlohmann/json";
17766 result[
"version"][
"string"] =
17767 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
17768 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
17769 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
17770 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
17771 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
17772 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
17775 result[
"platform"] =
"win32";
17776 #elif defined __linux__
17777 result[
"platform"] =
"linux";
17778 #elif defined __APPLE__
17779 result[
"platform"] =
"apple";
17780 #elif defined __unix__
17781 result[
"platform"] =
"unix";
17783 result[
"platform"] =
"unknown";
17786 #if defined(__ICC) || defined(__INTEL_COMPILER)
17787 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
17788 #elif defined(__clang__)
17789 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
17790 #elif defined(__GNUC__) || defined(__GNUG__)
17791 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
17792 #elif defined(__HP_cc) || defined(__HP_aCC)
17793 result[
"compiler"] =
"hp"
17794 #elif defined(__IBMCPP__)
17795 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
17796 #elif defined(_MSC_VER)
17797 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
17798 #elif defined(__PGI)
17799 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
17800 #elif defined(__SUNPRO_CC)
17801 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
17803 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
17807 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
17809 result[
"compiler"][
"c++"] =
"unknown";
17824 #if defined(JSON_HAS_CPP_14)
17918 AllocatorType<std::pair<
const StringType,
17965 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
18332 template<
typename T,
typename... Args>
18334 static T* create(Args&& ... args)
18336 AllocatorType<T> alloc;
18337 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
18339 auto deleter = [&](T * obj)
18341 AllocatorTraits::deallocate(alloc, obj, 1);
18343 std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
18344 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
18345 JSON_ASSERT(obj !=
nullptr);
18346 return obj.release();
18353 JSON_PRIVATE_UNLESS_TESTED:
18399 json_value() =
default;
18401 json_value(
boolean_t v) noexcept : boolean(v) {}
18413 case value_t::object:
18415 object = create<object_t>();
18419 case value_t::array:
18421 array = create<array_t>();
18425 case value_t::string:
18427 string = create<string_t>(
"");
18431 case value_t::binary:
18433 binary = create<binary_t>();
18437 case value_t::boolean:
18443 case value_t::number_integer:
18449 case value_t::number_unsigned:
18455 case value_t::number_float:
18461 case value_t::null:
18467 case value_t::discarded:
18471 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
18473 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.10.2",
basic_json()));
18483 string = create<string_t>(
value);
18489 string = create<string_t>(std::move(
value));
18495 object = create<object_t>(
value);
18501 object = create<object_t>(std::move(
value));
18507 array = create<array_t>(
value);
18513 array = create<array_t>(std::move(
value));
18519 binary = create<binary_t>(
value);
18525 binary = create<binary_t>(std::move(
value));
18531 binary = create<binary_t>(
value);
18537 binary = create<binary_t>(std::move(
value));
18542 if (t == value_t::array || t == value_t::object)
18545 std::vector<basic_json> stack;
18548 if (t == value_t::array)
18550 stack.reserve(array->size());
18551 std::move(array->begin(), array->end(), std::back_inserter(stack));
18556 for (
auto&& it : *
object)
18558 stack.push_back(std::move(it.second));
18562 while (!stack.empty())
18565 basic_json current_item(std::move(stack.back()));
18570 if (current_item.is_array())
18572 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack));
18574 current_item.m_value.array->clear();
18576 else if (current_item.is_object())
18578 for (
auto&& it : *current_item.m_value.object)
18580 stack.push_back(std::move(it.second));
18583 current_item.m_value.object->clear();
18593 case value_t::object:
18595 AllocatorType<object_t> alloc;
18596 std::allocator_traits<decltype(alloc)>::destroy(alloc,
object);
18597 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
object, 1);
18601 case value_t::array:
18603 AllocatorType<array_t> alloc;
18604 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
18605 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
18609 case value_t::string:
18611 AllocatorType<string_t> alloc;
18612 std::allocator_traits<decltype(alloc)>::destroy(alloc,
string);
18613 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
string, 1);
18617 case value_t::binary:
18619 AllocatorType<binary_t> alloc;
18620 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
18621 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18625 case value_t::null:
18626 case value_t::boolean:
18627 case value_t::number_integer:
18628 case value_t::number_unsigned:
18629 case value_t::number_float:
18630 case value_t::discarded:
18658 void assert_invariant(
bool check_parents =
true) const noexcept
18660 JSON_ASSERT(m_type != value_t::object ||
m_value.object !=
nullptr);
18661 JSON_ASSERT(m_type != value_t::array ||
m_value.array !=
nullptr);
18662 JSON_ASSERT(m_type != value_t::string ||
m_value.string !=
nullptr);
18663 JSON_ASSERT(m_type != value_t::binary ||
m_value.binary !=
nullptr);
18665 #if JSON_DIAGNOSTICS
18671 return j.m_parent ==
this;
18676 static_cast<void>(check_parents);
18681 #if JSON_DIAGNOSTICS
18684 case value_t::array:
18686 for (
auto& element : *
m_value.array)
18688 element.m_parent =
this;
18693 case value_t::object:
18695 for (
auto& element : *
m_value.object)
18697 element.second.m_parent =
this;
18702 case value_t::null:
18703 case value_t::string:
18704 case value_t::boolean:
18705 case value_t::number_integer:
18706 case value_t::number_unsigned:
18707 case value_t::number_float:
18708 case value_t::binary:
18709 case value_t::discarded:
18718 #if JSON_DIAGNOSTICS
18719 for (
typename iterator::difference_type i = 0; i <
count; ++i)
18721 (it + i)->m_parent =
this;
18724 static_cast<void>(
count);
18731 #if JSON_DIAGNOSTICS
18732 if (old_capacity != std::size_t(-1))
18735 JSON_ASSERT(
type() == value_t::array);
18736 if (JSON_HEDLEY_UNLIKELY(
m_value.array->capacity() != old_capacity))
18746 #ifdef JSON_HEDLEY_MSVC_VERSION
18747 #pragma warning(push )
18748 #pragma warning(disable : 4127)
18750 if (detail::is_ordered_map<object_t>::value)
18755 #ifdef JSON_HEDLEY_MSVC_VERSION
18756 #pragma warning( pop )
18761 static_cast<void>(j);
18762 static_cast<void>(old_capacity);
18787 using parse_event_t = detail::parse_event_t;
18882 assert_invariant();
18906 assert_invariant();
18971 template <
typename CompatibleType,
18972 typename U = detail::uncvref_t<CompatibleType>,
18973 detail::enable_if_t <
18974 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
18976 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18977 std::forward<CompatibleType>(val))))
18979 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
18981 assert_invariant();
19010 template <
typename BasicJsonType,
19011 detail::enable_if_t <
19012 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
19015 using other_boolean_t =
typename BasicJsonType::boolean_t;
19016 using other_number_float_t =
typename BasicJsonType::number_float_t;
19017 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
19018 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
19019 using other_string_t =
typename BasicJsonType::string_t;
19020 using other_object_t =
typename BasicJsonType::object_t;
19021 using other_array_t =
typename BasicJsonType::array_t;
19022 using other_binary_t =
typename BasicJsonType::binary_t;
19024 switch (val.type())
19026 case value_t::boolean:
19027 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
19029 case value_t::number_float:
19030 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
19032 case value_t::number_integer:
19033 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
19035 case value_t::number_unsigned:
19036 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
19038 case value_t::string:
19039 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
19041 case value_t::object:
19042 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
19044 case value_t::array:
19045 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
19047 case value_t::binary:
19048 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
19050 case value_t::null:
19053 case value_t::discarded:
19054 m_type = value_t::discarded;
19057 JSON_ASSERT(
false);
19060 assert_invariant();
19138 bool type_deduction =
true,
19139 value_t manual_type = value_t::array)
19143 bool is_an_object = std::all_of(init.begin(), init.end(),
19144 [](
const detail::json_ref<basic_json>& element_ref)
19146 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
19150 if (!type_deduction)
19153 if (manual_type == value_t::array)
19155 is_an_object =
false;
19159 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
19161 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
19168 m_type = value_t::object;
19171 for (
auto& element_ref : init)
19173 auto element = element_ref.moved_or_copied();
19175 std::move(*((*element.m_value.array)[0].m_value.string)),
19176 std::move((*element.m_value.array)[1]));
19182 m_type = value_t::array;
19183 m_value.array = create<array_t>(init.begin(), init.end());
19187 assert_invariant();
19221 res.m_type = value_t::binary;
19222 res.m_value = init;
19258 res.m_type = value_t::binary;
19259 res.m_value =
binary_t(init, subtype);
19268 res.m_type = value_t::binary;
19269 res.m_value = std::move(init);
19278 res.m_type = value_t::binary;
19279 res.m_value =
binary_t(std::move(init), subtype);
19323 return basic_json(init,
false, value_t::array);
19367 return basic_json(init,
false, value_t::object);
19393 : m_type(value_t::array)
19395 m_value.array = create<array_t>(cnt, val);
19397 assert_invariant();
19455 template <
class InputIT,
typename std::enable_if <
19456 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
19457 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
19460 JSON_ASSERT(first.m_object !=
nullptr);
19461 JSON_ASSERT(last.m_object !=
nullptr);
19464 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19466 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
19470 m_type = first.m_object->m_type;
19475 case value_t::boolean:
19476 case value_t::number_float:
19477 case value_t::number_integer:
19478 case value_t::number_unsigned:
19479 case value_t::string:
19481 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
19482 || !last.m_it.primitive_iterator.is_end()))
19484 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
19489 case value_t::null:
19490 case value_t::object:
19491 case value_t::array:
19492 case value_t::binary:
19493 case value_t::discarded:
19500 case value_t::number_integer:
19502 m_value.number_integer = first.m_object->m_value.number_integer;
19506 case value_t::number_unsigned:
19508 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
19512 case value_t::number_float:
19514 m_value.number_float = first.m_object->m_value.number_float;
19518 case value_t::boolean:
19520 m_value.boolean = first.m_object->m_value.boolean;
19524 case value_t::string:
19526 m_value = *first.m_object->m_value.string;
19530 case value_t::object:
19532 m_value.object = create<object_t>(first.m_it.object_iterator,
19533 last.m_it.object_iterator);
19537 case value_t::array:
19539 m_value.array = create<array_t>(first.m_it.array_iterator,
19540 last.m_it.array_iterator);
19544 case value_t::binary:
19546 m_value = *first.m_object->m_value.binary;
19550 case value_t::null:
19551 case value_t::discarded:
19553 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
19557 assert_invariant();
19565 template<
typename JsonRef,
19566 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
19567 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
19596 : m_type(other.m_type)
19599 other.assert_invariant();
19603 case value_t::object:
19609 case value_t::array:
19615 case value_t::string:
19621 case value_t::boolean:
19627 case value_t::number_integer:
19633 case value_t::number_unsigned:
19639 case value_t::number_float:
19645 case value_t::binary:
19651 case value_t::null:
19652 case value_t::discarded:
19658 assert_invariant();
19688 : m_type(std::move(other.m_type)),
19689 m_value(std::move(other.m_value))
19692 other.assert_invariant(
false);
19695 other.m_type = value_t::null;
19696 other.m_value = {};
19699 assert_invariant();
19726 std::is_nothrow_move_constructible<value_t>::value&&
19727 std::is_nothrow_move_assignable<value_t>::value&&
19728 std::is_nothrow_move_constructible<json_value>::value&&
19729 std::is_nothrow_move_assignable<json_value>::value
19733 other.assert_invariant();
19736 swap(m_type, other.m_type);
19740 assert_invariant();
19761 assert_invariant(
false);
19824 const char indent_char =
' ',
19825 const bool ensure_ascii =
false,
19826 const error_handler_t error_handler = error_handler_t::strict)
const
19829 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19833 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
19837 s.dump(*
this,
false, ensure_ascii, 0);
19876 constexpr value_t
type() const noexcept
19958 return m_type == value_t::null;
19980 return m_type == value_t::boolean;
20039 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
20067 return m_type == value_t::number_unsigned;
20095 return m_type == value_t::number_float;
20117 return m_type == value_t::object;
20139 return m_type == value_t::array;
20161 return m_type == value_t::string;
20183 return m_type == value_t::binary;
20210 return m_type == value_t::discarded;
20254 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
20276 constexpr
const array_t* get_impl_ptr(
const array_t* )
const noexcept
20364 template<
typename ReferenceType,
typename ThisType>
20365 static ReferenceType get_ref_impl(ThisType& obj)
20368 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
20370 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
20375 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
20409 template<
typename PointerType,
typename std::enable_if<
20410 std::is_pointer<PointerType>::value,
int>
::type = 0>
20411 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20414 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20421 template <
typename PointerType,
typename std::enable_if <
20422 std::is_pointer<PointerType>::value&&
20423 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
20424 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
20427 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20469 template <
typename ValueType,
20470 detail::enable_if_t <
20471 detail::is_default_constructible<ValueType>::value&&
20472 detail::has_from_json<basic_json_t, ValueType>::value,
20474 ValueType get_impl(detail::priority_tag<0> )
const noexcept(noexcept(
20475 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20478 JSONSerializer<ValueType>::from_json(*
this, ret);
20512 template <
typename ValueType,
20513 detail::enable_if_t <
20514 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
20516 ValueType get_impl(detail::priority_tag<1> )
const noexcept(noexcept(
20517 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20519 return JSONSerializer<ValueType>::from_json(*
this);
20537 template <
typename BasicJsonType,
20538 detail::enable_if_t <
20539 detail::is_basic_json<BasicJsonType>::value,
20541 BasicJsonType get_impl(detail::priority_tag<2> )
const
20560 template<
typename BasicJsonType,
20561 detail::enable_if_t<
20562 std::is_same<BasicJsonType, basic_json_t>::value,
20564 basic_json get_impl(detail::priority_tag<3> )
const
20573 template<
typename PointerType,
20574 detail::enable_if_t<
20575 std::is_pointer<PointerType>::value,
20577 constexpr
auto get_impl(detail::priority_tag<4> )
const noexcept
20578 -> decltype(std::declval<const basic_json_t&>().
template get_ptr<PointerType>())
20581 return get_ptr<PointerType>();
20608 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20609 #if defined(JSON_HAS_CPP_14)
20613 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
20614 -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
20619 static_assert(!std::is_reference<ValueTypeCV>::value,
20620 "get() cannot be used with reference types, you might want to use get_ref()");
20621 return get_impl<ValueType>(detail::priority_tag<4> {});
20651 template<
typename PointerType,
typename std::enable_if<
20652 std::is_pointer<PointerType>::value,
int>
::type = 0>
20653 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
20656 return get_ptr<PointerType>();
20692 template <
typename ValueType,
20693 detail::enable_if_t <
20694 !detail::is_basic_json<ValueType>::value&&
20695 detail::has_from_json<basic_json_t, ValueType>::value,
20697 ValueType &
get_to(ValueType& v)
const noexcept(noexcept(
20698 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
20700 JSONSerializer<ValueType>::from_json(*
this, v);
20706 template<
typename ValueType,
20707 detail::enable_if_t <
20708 detail::is_basic_json<ValueType>::value,
20717 typename T, std::size_t N,
20718 typename Array = T (&)[N],
20719 detail::enable_if_t <
20720 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
20722 noexcept(noexcept(JSONSerializer<Array>::from_json(
20723 std::declval<const basic_json_t&>(), v)))
20725 JSONSerializer<Array>::from_json(*
this, v);
20755 template<
typename ReferenceType,
typename std::enable_if<
20756 std::is_reference<ReferenceType>::value,
int>
::type = 0>
20760 return get_ref_impl<ReferenceType>(*
this);
20767 template <
typename ReferenceType,
typename std::enable_if <
20768 std::is_reference<ReferenceType>::value&&
20769 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
20773 return get_ref_impl<ReferenceType>(*
this);
20805 template <
typename ValueType,
typename std::enable_if <
20806 detail::conjunction <
20807 detail::negation<std::is_pointer<ValueType>>,
20808 detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
20809 detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
20810 detail::negation<detail::is_basic_json<ValueType>>,
20811 detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
20813 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20814 detail::negation<std::is_same<ValueType, std::string_view>>,
20816 detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
20818 JSON_EXPLICIT
operator ValueType()
const
20821 return get<ValueType>();
20837 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20840 return *get_ptr<binary_t*>();
20848 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20851 return *get_ptr<const binary_t*>();
20894 if (JSON_HEDLEY_LIKELY(
is_array()))
20898 return set_parent(
m_value.array->at(idx));
20900 JSON_CATCH (std::out_of_range&)
20903 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20908 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20941 if (JSON_HEDLEY_LIKELY(
is_array()))
20945 return m_value.array->at(idx);
20947 JSON_CATCH (std::out_of_range&)
20950 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20955 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20989 reference at(
const typename object_t::key_type& key)
20996 return set_parent(
m_value.object->at(key));
20998 JSON_CATCH (std::out_of_range&)
21001 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21006 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21047 return m_value.object->at(key);
21049 JSON_CATCH (std::out_of_range&)
21052 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
21057 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
21091 m_type = value_t::array;
21092 m_value.array = create<array_t>();
21093 assert_invariant();
21097 if (JSON_HEDLEY_LIKELY(
is_array()))
21100 if (idx >=
m_value.array->size())
21102 #if JSON_DIAGNOSTICS
21104 const auto previous_size =
m_value.array->size();
21106 m_value.array->resize(idx + 1);
21108 #if JSON_DIAGNOSTICS
21110 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(previous_size),
static_cast<typename iterator::difference_type
>(idx + 1 - previous_size));
21114 return m_value.array->operator[](idx);
21117 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21142 if (JSON_HEDLEY_LIKELY(
is_array()))
21144 return m_value.array->operator[](idx);
21147 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
21182 m_type = value_t::object;
21183 m_value.object = create<object_t>();
21184 assert_invariant();
21190 return set_parent(
m_value.object->operator[](key));
21193 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21231 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
21232 return m_value.object->find(key)->second;
21235 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21265 template<
typename T>
21266 JSON_HEDLEY_NON_NULL(2)
21272 m_type = value_t::object;
21274 assert_invariant();
21280 return set_parent(
m_value.object->operator[](key));
21283 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
21316 template<
typename T>
21317 JSON_HEDLEY_NON_NULL(2)
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));
21381 template <
class ValueType,
typename std::enable_if <
21382 detail::is_getable<basic_json_t, ValueType>::value
21383 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
21384 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
21390 const auto it =
find(key);
21393 return it->template get<ValueType>();
21396 return default_value;
21399 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21406 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
21454 template<
class ValueType,
typename std::enable_if<
21455 detail::is_getable<basic_json_t, ValueType>::value,
int>
::type = 0>
21464 return ptr.get_checked(
this).template get<ValueType>();
21468 return default_value;
21472 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21479 JSON_HEDLEY_NON_NULL(3)
21617 template <
class IteratorType,
typename std::enable_if <
21618 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21619 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21621 IteratorType
erase(IteratorType pos)
21624 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21626 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
21629 IteratorType result =
end();
21633 case value_t::boolean:
21634 case value_t::number_float:
21635 case value_t::number_integer:
21636 case value_t::number_unsigned:
21637 case value_t::string:
21638 case value_t::binary:
21640 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21642 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
21647 AllocatorType<string_t> alloc;
21648 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
21649 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21654 AllocatorType<binary_t> alloc;
21655 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
21656 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21660 m_type = value_t::null;
21661 assert_invariant();
21665 case value_t::object:
21667 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
21671 case value_t::array:
21673 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
21677 case value_t::null:
21678 case value_t::discarded:
21680 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21732 template <
class IteratorType,
typename std::enable_if <
21733 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21734 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21736 IteratorType
erase(IteratorType first, IteratorType last)
21739 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21741 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
21744 IteratorType result =
end();
21748 case value_t::boolean:
21749 case value_t::number_float:
21750 case value_t::number_integer:
21751 case value_t::number_unsigned:
21752 case value_t::string:
21753 case value_t::binary:
21755 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21756 || !last.m_it.primitive_iterator.is_end()))
21758 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
21763 AllocatorType<string_t> alloc;
21764 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
21765 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21770 AllocatorType<binary_t> alloc;
21771 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
21772 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21776 m_type = value_t::null;
21777 assert_invariant();
21781 case value_t::object:
21783 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
21784 last.m_it.object_iterator);
21788 case value_t::array:
21790 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
21791 last.m_it.array_iterator);
21795 case value_t::null:
21796 case value_t::discarded:
21798 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21838 return m_value.object->erase(key);
21841 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21871 if (JSON_HEDLEY_LIKELY(
is_array()))
21873 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
21875 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21882 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21920 template<
typename KeyT>
21923 auto result =
end();
21927 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21937 template<
typename KeyT>
21940 auto result =
cend();
21944 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21971 template<
typename KeyT>
22003 template <
typename KeyT,
typename std::enable_if <
22038 return ptr.contains(
this);
22078 result.set_begin();
22118 result.set_begin();
22382 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22385 return ref.items();
22391 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
22394 return ref.items();
22465 iteration_proxy<iterator>
items() noexcept
22467 return iteration_proxy<iterator>(*
this);
22473 iteration_proxy<const_iterator>
items() const noexcept
22475 return iteration_proxy<const_iterator>(*
this);
22530 bool empty() const noexcept
22534 case value_t::null:
22540 case value_t::array:
22543 return m_value.array->empty();
22546 case value_t::object:
22549 return m_value.object->empty();
22552 case value_t::string:
22553 case value_t::boolean:
22554 case value_t::number_integer:
22555 case value_t::number_unsigned:
22556 case value_t::number_float:
22557 case value_t::binary:
22558 case value_t::discarded:
22614 case value_t::null:
22620 case value_t::array:
22623 return m_value.array->size();
22626 case value_t::object:
22629 return m_value.object->size();
22632 case value_t::string:
22633 case value_t::boolean:
22634 case value_t::number_integer:
22635 case value_t::number_unsigned:
22636 case value_t::number_float:
22637 case value_t::binary:
22638 case value_t::discarded:
22692 case value_t::array:
22695 return m_value.array->max_size();
22698 case value_t::object:
22701 return m_value.object->max_size();
22704 case value_t::null:
22705 case value_t::string:
22706 case value_t::boolean:
22707 case value_t::number_integer:
22708 case value_t::number_unsigned:
22709 case value_t::number_float:
22710 case value_t::binary:
22711 case value_t::discarded:
22767 void clear() noexcept
22771 case value_t::number_integer:
22777 case value_t::number_unsigned:
22783 case value_t::number_float:
22789 case value_t::boolean:
22795 case value_t::string:
22801 case value_t::binary:
22807 case value_t::array:
22813 case value_t::object:
22819 case value_t::null:
22820 case value_t::discarded:
22851 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22857 m_type = value_t::array;
22859 assert_invariant();
22863 const auto old_capacity =
m_value.array->capacity();
22864 m_value.array->push_back(std::move(val));
22865 set_parent(
m_value.array->back(), old_capacity);
22888 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22894 m_type = value_t::array;
22896 assert_invariant();
22900 const auto old_capacity =
m_value.array->capacity();
22901 m_value.array->push_back(val);
22902 set_parent(
m_value.array->back(), old_capacity);
22935 void push_back(
const typename object_t::value_type& val)
22940 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22946 m_type = value_t::object;
22948 assert_invariant();
22952 auto res =
m_value.object->insert(val);
22953 set_parent(res.first->second);
22993 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
22995 basic_json&& key = init.begin()->moved_or_copied();
22996 push_back(
typename object_t::value_type(
22997 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
23038 template<
class... Args>
23044 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
23050 m_type = value_t::array;
23052 assert_invariant();
23056 const auto old_capacity =
m_value.array->capacity();
23057 m_value.array->emplace_back(std::forward<Args>(args)...);
23058 return set_parent(
m_value.array->back(), old_capacity);
23088 template<
class... Args>
23089 std::pair<iterator, bool>
emplace(Args&& ... args)
23094 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
23100 m_type = value_t::object;
23102 assert_invariant();
23106 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
23107 set_parent(res.first->second);
23111 it.m_it.object_iterator = res.first;
23114 return {it, res.second};
23120 template<
typename... Args>
23124 JSON_ASSERT(
m_value.array !=
nullptr);
23126 auto insert_pos = std::distance(
m_value.array->begin(), pos.m_it.array_iterator);
23127 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
23128 result.m_it.array_iterator =
m_value.array->begin() + insert_pos;
23163 if (JSON_HEDLEY_LIKELY(
is_array()))
23166 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23168 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23175 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23184 return insert(pos, val);
23214 if (JSON_HEDLEY_LIKELY(
is_array()))
23217 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23219 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23226 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23262 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23264 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23268 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23270 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23274 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23276 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23279 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
23281 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
23285 return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator);
23315 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
23317 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23321 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
23323 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
23356 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
23358 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
23362 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23364 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23368 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
23370 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23373 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
23400 m_type = value_t::object;
23401 m_value.object = create<object_t>();
23402 assert_invariant();
23407 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23409 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
23411 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name()), *
this));
23414 for (
auto it = j.cbegin(); it != j.cend(); ++it)
23416 m_value.object->operator[](it.key()) = it.value();
23451 m_type = value_t::object;
23452 m_value.object = create<object_t>();
23453 assert_invariant();
23458 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
23462 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
23464 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
23468 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
23469 || !last.m_object->is_object()))
23471 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
23474 for (
auto it = first; it != last; ++it)
23476 m_value.object->operator[](it.key()) = it.value();
23498 std::is_nothrow_move_constructible<value_t>::value&&
23499 std::is_nothrow_move_assignable<value_t>::value&&
23500 std::is_nothrow_move_constructible<json_value>::value&&
23501 std::is_nothrow_move_assignable<json_value>::value
23504 std::swap(m_type, other.m_type);
23505 std::swap(
m_value, other.m_value);
23508 other.set_parents();
23509 assert_invariant();
23531 std::is_nothrow_move_constructible<value_t>::value&&
23532 std::is_nothrow_move_assignable<value_t>::value&&
23533 std::is_nothrow_move_constructible<json_value>::value&&
23534 std::is_nothrow_move_assignable<json_value>::value
23563 if (JSON_HEDLEY_LIKELY(
is_array()))
23565 std::swap(*(
m_value.array), other);
23569 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23598 std::swap(*(
m_value.object), other);
23602 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23631 std::swap(*(
m_value.string), other);
23635 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23664 std::swap(*(
m_value.binary), other);
23668 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23678 std::swap(*(
m_value.binary), other);
23682 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23754 #pragma GCC diagnostic push
23755 #pragma GCC diagnostic ignored "-Wfloat-equal"
23757 const auto lhs_type = lhs.type();
23758 const auto rhs_type = rhs.type();
23760 if (lhs_type == rhs_type)
23764 case value_t::array:
23765 return *lhs.m_value.array == *rhs.m_value.array;
23767 case value_t::object:
23768 return *lhs.m_value.object == *rhs.m_value.object;
23770 case value_t::null:
23773 case value_t::string:
23774 return *lhs.m_value.string == *rhs.m_value.string;
23776 case value_t::boolean:
23777 return lhs.m_value.boolean == rhs.m_value.boolean;
23779 case value_t::number_integer:
23780 return lhs.m_value.number_integer == rhs.m_value.number_integer;
23782 case value_t::number_unsigned:
23783 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23785 case value_t::number_float:
23786 return lhs.m_value.number_float == rhs.m_value.number_float;
23788 case value_t::binary:
23789 return *lhs.m_value.binary == *rhs.m_value.binary;
23791 case value_t::discarded:
23796 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23798 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23800 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23802 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
23804 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23806 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23808 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23810 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23812 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23814 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23816 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23818 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23823 #pragma GCC diagnostic pop
23831 template<
typename ScalarType,
typename std::enable_if<
23832 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23842 template<
typename ScalarType,
typename std::enable_if<
23843 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23869 return !(lhs == rhs);
23876 template<
typename ScalarType,
typename std::enable_if<
23877 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23887 template<
typename ScalarType,
typename std::enable_if<
23888 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23922 const auto lhs_type = lhs.type();
23923 const auto rhs_type = rhs.type();
23925 if (lhs_type == rhs_type)
23929 case value_t::array:
23932 return (*lhs.m_value.array) < (*rhs.m_value.array);
23934 case value_t::object:
23935 return (*lhs.m_value.object) < (*rhs.m_value.object);
23937 case value_t::null:
23940 case value_t::string:
23941 return (*lhs.m_value.string) < (*rhs.m_value.string);
23943 case value_t::boolean:
23944 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
23946 case value_t::number_integer:
23947 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
23949 case value_t::number_unsigned:
23950 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
23952 case value_t::number_float:
23953 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
23955 case value_t::binary:
23956 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
23958 case value_t::discarded:
23963 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23965 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
23967 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23969 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
23971 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23973 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
23975 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23977 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23979 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23981 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23983 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23985 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
23998 template<
typename ScalarType,
typename std::enable_if<
23999 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24009 template<
typename ScalarType,
typename std::enable_if<
24010 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24037 return !(rhs < lhs);
24044 template<
typename ScalarType,
typename std::enable_if<
24045 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24055 template<
typename ScalarType,
typename std::enable_if<
24056 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24083 return !(lhs <= rhs);
24090 template<
typename ScalarType,
typename std::enable_if<
24091 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24101 template<
typename ScalarType,
typename std::enable_if<
24102 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24129 return !(lhs < rhs);
24136 template<
typename ScalarType,
typename std::enable_if<
24137 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24147 template<
typename ScalarType,
typename std::enable_if<
24148 std::is_scalar<ScalarType>::value,
int>
::type = 0>
24197 const bool pretty_print = o.width() > 0;
24198 const auto indentation = pretty_print ? o.width() : 0;
24204 serializer s(detail::output_adapter<char>(o), o.fill());
24205 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
24217 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
24284 template<
typename InputType>
24288 const bool allow_exceptions =
true,
24289 const bool ignore_comments =
false)
24292 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24322 template<
typename IteratorType>
24327 const bool allow_exceptions =
true,
24328 const bool ignore_comments =
false)
24331 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
24336 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
24339 const bool allow_exceptions =
true,
24340 const bool ignore_comments =
false)
24343 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
24377 template<
typename InputType>
24378 static bool accept(InputType&& i,
24379 const bool ignore_comments =
false)
24381 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
24384 template<
typename IteratorType>
24385 static bool accept(IteratorType first, IteratorType last,
24386 const bool ignore_comments =
false)
24388 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
24392 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
24393 static bool accept(detail::span_input_adapter&& i,
24394 const bool ignore_comments =
false)
24396 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
24439 template <
typename InputType,
typename SAX>
24440 JSON_HEDLEY_NON_NULL(2)
24441 static
bool sax_parse(InputType&& i, SAX* sax,
24443 const
bool strict = true,
24444 const
bool ignore_comments = false)
24446 auto ia = detail::input_adapter(std::forward<InputType>(i));
24447 return format == input_format_t::json
24448 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24449 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24452 template<
class IteratorType,
class SAX>
24453 JSON_HEDLEY_NON_NULL(3)
24454 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
24455 input_format_t format = input_format_t::
json,
24456 const
bool strict = true,
24457 const
bool ignore_comments = false)
24459 auto ia = detail::input_adapter(std::move(first), std::move(last));
24460 return format == input_format_t::json
24461 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24462 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24465 template <
typename SAX>
24466 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
24467 JSON_HEDLEY_NON_NULL(2)
24468 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
24469 input_format_t format = input_format_t::
json,
24470 const
bool strict = true,
24471 const
bool ignore_comments = false)
24474 return format == input_format_t::json
24476 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
24478 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24489 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24522 parser(detail::input_adapter(i)).parse(
false, j);
24569 case value_t::null:
24571 case value_t::object:
24573 case value_t::array:
24575 case value_t::string:
24577 case value_t::boolean:
24579 case value_t::binary:
24581 case value_t::discarded:
24582 return "discarded";
24583 case value_t::number_integer:
24584 case value_t::number_unsigned:
24585 case value_t::number_float:
24593 JSON_PRIVATE_UNLESS_TESTED:
24599 value_t m_type = value_t::null;
24604 #if JSON_DIAGNOSTICS
24717 std::vector<std::uint8_t> result;
24722 static void to_cbor(
const basic_json& j, detail::output_adapter<std::uint8_t> o)
24724 binary_writer<std::uint8_t>(o).write_cbor(j);
24729 binary_writer<char>(o).write_cbor(j);
24812 std::vector<std::uint8_t> result;
24819 binary_writer<std::uint8_t>(o).write_msgpack(j);
24824 binary_writer<char>(o).write_msgpack(j);
24914 const bool use_size =
false,
24915 const bool use_type =
false)
24917 std::vector<std::uint8_t> result;
24918 to_ubjson(j, result, use_size, use_type);
24923 const bool use_size =
false,
const bool use_type =
false)
24925 binary_writer<std::uint8_t>(o).write_ubjson(j, use_size, use_type);
24929 const bool use_size =
false,
const bool use_type =
false)
24931 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24993 std::vector<std::uint8_t> result;
25006 static void to_bson(
const basic_json& j, detail::output_adapter<std::uint8_t> o)
25008 binary_writer<std::uint8_t>(o).write_bson(j);
25016 binary_writer<char>(o).write_bson(j);
25122 template<
typename InputType>
25125 const bool strict =
true,
25126 const bool allow_exceptions =
true,
25130 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25131 auto ia = detail::input_adapter(std::forward<InputType>(i));
25132 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25133 return res ? result :
basic_json(value_t::discarded);
25139 template<
typename IteratorType>
25142 const bool strict =
true,
25143 const bool allow_exceptions =
true,
25147 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25148 auto ia = detail::input_adapter(std::move(first), std::move(last));
25149 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25150 return res ? result :
basic_json(value_t::discarded);
25153 template<
typename T>
25155 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
25157 const bool strict =
true,
25158 const bool allow_exceptions =
true,
25161 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
25168 const bool strict =
true,
25169 const bool allow_exceptions =
true,
25170 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
25173 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25176 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
25266 template<
typename InputType>
25269 const bool strict =
true,
25270 const bool allow_exceptions =
true)
25273 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25274 auto ia = detail::input_adapter(std::forward<InputType>(i));
25275 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25276 return res ? result :
basic_json(value_t::discarded);
25282 template<
typename IteratorType>
25285 const bool strict =
true,
25286 const bool allow_exceptions =
true)
25289 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25290 auto ia = detail::input_adapter(std::move(first), std::move(last));
25291 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25292 return res ? result :
basic_json(value_t::discarded);
25296 template<
typename T>
25298 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25300 const bool strict =
true,
25301 const bool allow_exceptions =
true)
25303 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
25307 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
25309 const bool strict =
true,
25310 const bool allow_exceptions =
true)
25313 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25316 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
25317 return res ? result :
basic_json(value_t::discarded);
25383 template<
typename InputType>
25386 const bool strict =
true,
25387 const bool allow_exceptions =
true)
25390 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25391 auto ia = detail::input_adapter(std::forward<InputType>(i));
25392 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25393 return res ? result :
basic_json(value_t::discarded);
25399 template<
typename IteratorType>
25402 const bool strict =
true,
25403 const bool allow_exceptions =
true)
25406 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25407 auto ia = detail::input_adapter(std::move(first), std::move(last));
25408 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25409 return res ? result :
basic_json(value_t::discarded);
25412 template<
typename T>
25414 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25416 const bool strict =
true,
25417 const bool allow_exceptions =
true)
25419 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
25423 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
25425 const bool strict =
true,
25426 const bool allow_exceptions =
true)
25429 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25432 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
25433 return res ? result :
basic_json(value_t::discarded);
25497 template<
typename InputType>
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::forward<InputType>(i));
25506 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25507 return res ? result :
basic_json(value_t::discarded);
25513 template<
typename IteratorType>
25516 const bool strict =
true,
25517 const bool allow_exceptions =
true)
25520 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25521 auto ia = detail::input_adapter(std::move(first), std::move(last));
25522 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25523 return res ? result :
basic_json(value_t::discarded);
25526 template<
typename T>
25528 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25530 const bool strict =
true,
25531 const bool allow_exceptions =
true)
25533 return from_bson(ptr, ptr + len, strict, allow_exceptions);
25537 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25539 const bool strict =
true,
25540 const bool allow_exceptions =
true)
25543 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25546 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25547 return res ? result :
basic_json(value_t::discarded);
25593 return ptr.get_unchecked(
this);
25621 return ptr.get_unchecked(
this);
25664 return ptr.get_checked(
this);
25707 return ptr.get_checked(
this);
25735 json_pointer::flatten(
"", *
this, result);
25771 return json_pointer::unflatten(*
this);
25836 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25838 const auto get_op = [](
const std::string & op)
25842 return patch_operations::add;
25844 if (op ==
"remove")
25846 return patch_operations::remove;
25848 if (op ==
"replace")
25850 return patch_operations::replace;
25854 return patch_operations::move;
25858 return patch_operations::copy;
25862 return patch_operations::test;
25865 return patch_operations::invalid;
25880 if (top_pointer != ptr)
25882 result.
at(top_pointer);
25886 const auto last_path = ptr.
back();
25890 switch (parent.m_type)
25892 case value_t::null:
25893 case value_t::object:
25896 parent[last_path] = val;
25900 case value_t::array:
25902 if (last_path ==
"-")
25909 const auto idx = json_pointer::array_index(last_path);
25910 if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
25913 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
25917 parent.insert(parent.begin() +
static_cast<difference_type>(idx), val);
25923 case value_t::string:
25924 case value_t::boolean:
25925 case value_t::number_integer:
25926 case value_t::number_unsigned:
25927 case value_t::number_float:
25928 case value_t::binary:
25929 case value_t::discarded:
25931 JSON_ASSERT(
false);
25936 const auto operation_remove = [
this, &result](
json_pointer & ptr)
25939 const auto last_path = ptr.back();
25944 if (parent.is_object())
25947 auto it = parent.
find(last_path);
25948 if (JSON_HEDLEY_LIKELY(it != parent.end()))
25954 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
25957 else if (parent.is_array())
25960 parent.erase(json_pointer::array_index(last_path));
25965 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
25967 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
25971 for (
const auto& val : json_patch)
25974 const auto get_value = [&val](
const std::string & op,
25975 const std::string & member,
25979 auto it = val.m_value.object->find(member);
25982 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
25985 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
25988 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
25992 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25995 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
26003 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
26005 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", val));
26009 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
26010 const auto path = get_value(op,
"path",
true).template get<std::string>();
26013 switch (get_op(op))
26015 case patch_operations::add:
26017 operation_add(ptr, get_value(
"add",
"value",
false));
26021 case patch_operations::remove:
26023 operation_remove(ptr);
26027 case patch_operations::replace:
26030 result.
at(ptr) = get_value(
"replace",
"value",
false);
26034 case patch_operations::move:
26036 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
26046 operation_remove(from_ptr);
26047 operation_add(ptr, v);
26051 case patch_operations::copy:
26053 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
26062 operation_add(ptr, v);
26066 case patch_operations::test:
26068 bool success =
false;
26073 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
26081 if (JSON_HEDLEY_UNLIKELY(!success))
26083 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
26089 case patch_operations::invalid:
26094 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid", val));
26137 const std::string& path =
"")
26143 if (source == target)
26148 if (source.type() != target.type())
26153 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26158 switch (source.type())
26160 case value_t::array:
26164 while (i < source.size() && i < target.size())
26167 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
26168 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26177 while (i < source.size())
26184 {
"path", path +
"/" + std::to_string(i)}
26190 while (i < target.size())
26195 {
"path", path +
"/-"},
26196 {
"value", target[i]}
26204 case value_t::object:
26207 for (
auto it = source.cbegin(); it != source.cend(); ++it)
26210 const auto path_key = path +
"/" + detail::escape(it.key());
26212 if (target.find(it.key()) != target.end())
26215 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
26216 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
26223 {
"op",
"remove"}, {
"path", path_key}
26229 for (
auto it = target.cbegin(); it != target.cend(); ++it)
26231 if (source.find(it.key()) == source.end())
26234 const auto path_key = path +
"/" + detail::escape(it.key());
26237 {
"op",
"add"}, {
"path", path_key},
26238 {
"value", it.value()}
26246 case value_t::null:
26247 case value_t::string:
26248 case value_t::boolean:
26249 case value_t::number_integer:
26250 case value_t::number_unsigned:
26251 case value_t::number_float:
26252 case value_t::binary:
26253 case value_t::discarded:
26259 {
"op",
"replace"}, {
"path", path}, {
"value", target}
26321 if (apply_patch.is_object())
26327 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
26329 if (it.value().is_null())
26341 *
this = apply_patch;
26357 NLOHMANN_BASIC_JSON_TPL_DECLARATION
26358 std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
26383 return nlohmann::detail::hash(j);
26391 struct less<::nlohmann::detail::value_t>
26397 bool operator()(nlohmann::detail::value_t lhs,
26398 nlohmann::detail::value_t rhs)
const noexcept
26400 return nlohmann::detail::operator<(lhs, rhs);
26405 #ifndef JSON_HAS_CPP_20
26414 is_nothrow_move_constructible<nlohmann::json>::value&&
26415 is_nothrow_move_assignable<nlohmann::json>::value
26438 JSON_HEDLEY_NON_NULL(1)
26439 inline
nlohmann::json operator "" _json(const
char* s, std::
size_t n)
26457 JSON_HEDLEY_NON_NULL(1)
26458 inline
nlohmann::json::json_pointer operator "" _json_pointer(const
char* s, std::
size_t n)
26467 #if defined(__clang__)
26468 #pragma clang diagnostic pop
26473 #undef JSON_INTERNAL_CATCH
26477 #undef JSON_PRIVATE_UNLESS_TESTED
26478 #undef JSON_HAS_CPP_11
26479 #undef JSON_HAS_CPP_14
26480 #undef JSON_HAS_CPP_17
26481 #undef JSON_HAS_CPP_20
26482 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
26483 #undef NLOHMANN_BASIC_JSON_TPL
26484 #undef JSON_EXPLICIT
26489 #undef JSON_HEDLEY_ALWAYS_INLINE
26490 #undef JSON_HEDLEY_ARM_VERSION
26491 #undef JSON_HEDLEY_ARM_VERSION_CHECK
26492 #undef JSON_HEDLEY_ARRAY_PARAM
26493 #undef JSON_HEDLEY_ASSUME
26494 #undef JSON_HEDLEY_BEGIN_C_DECLS
26495 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
26496 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
26497 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
26498 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
26499 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
26500 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
26501 #undef JSON_HEDLEY_CLANG_HAS_WARNING
26502 #undef JSON_HEDLEY_COMPCERT_VERSION
26503 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
26504 #undef JSON_HEDLEY_CONCAT
26505 #undef JSON_HEDLEY_CONCAT3
26506 #undef JSON_HEDLEY_CONCAT3_EX
26507 #undef JSON_HEDLEY_CONCAT_EX
26508 #undef JSON_HEDLEY_CONST
26509 #undef JSON_HEDLEY_CONSTEXPR
26510 #undef JSON_HEDLEY_CONST_CAST
26511 #undef JSON_HEDLEY_CPP_CAST
26512 #undef JSON_HEDLEY_CRAY_VERSION
26513 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
26514 #undef JSON_HEDLEY_C_DECL
26515 #undef JSON_HEDLEY_DEPRECATED
26516 #undef JSON_HEDLEY_DEPRECATED_FOR
26517 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
26518 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
26519 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
26520 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
26521 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
26522 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
26523 #undef JSON_HEDLEY_DIAGNOSTIC_POP
26524 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
26525 #undef JSON_HEDLEY_DMC_VERSION
26526 #undef JSON_HEDLEY_DMC_VERSION_CHECK
26527 #undef JSON_HEDLEY_EMPTY_BASES
26528 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
26529 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
26530 #undef JSON_HEDLEY_END_C_DECLS
26531 #undef JSON_HEDLEY_FLAGS
26532 #undef JSON_HEDLEY_FLAGS_CAST
26533 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
26534 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
26535 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
26536 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
26537 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
26538 #undef JSON_HEDLEY_GCC_HAS_FEATURE
26539 #undef JSON_HEDLEY_GCC_HAS_WARNING
26540 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
26541 #undef JSON_HEDLEY_GCC_VERSION
26542 #undef JSON_HEDLEY_GCC_VERSION_CHECK
26543 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
26544 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
26545 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
26546 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
26547 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
26548 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
26549 #undef JSON_HEDLEY_GNUC_HAS_WARNING
26550 #undef JSON_HEDLEY_GNUC_VERSION
26551 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
26552 #undef JSON_HEDLEY_HAS_ATTRIBUTE
26553 #undef JSON_HEDLEY_HAS_BUILTIN
26554 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
26555 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
26556 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
26557 #undef JSON_HEDLEY_HAS_EXTENSION
26558 #undef JSON_HEDLEY_HAS_FEATURE
26559 #undef JSON_HEDLEY_HAS_WARNING
26560 #undef JSON_HEDLEY_IAR_VERSION
26561 #undef JSON_HEDLEY_IAR_VERSION_CHECK
26562 #undef JSON_HEDLEY_IBM_VERSION
26563 #undef JSON_HEDLEY_IBM_VERSION_CHECK
26564 #undef JSON_HEDLEY_IMPORT
26565 #undef JSON_HEDLEY_INLINE
26566 #undef JSON_HEDLEY_INTEL_CL_VERSION
26567 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
26568 #undef JSON_HEDLEY_INTEL_VERSION
26569 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
26570 #undef JSON_HEDLEY_IS_CONSTANT
26571 #undef JSON_HEDLEY_IS_CONSTEXPR_
26572 #undef JSON_HEDLEY_LIKELY
26573 #undef JSON_HEDLEY_MALLOC
26574 #undef JSON_HEDLEY_MCST_LCC_VERSION
26575 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
26576 #undef JSON_HEDLEY_MESSAGE
26577 #undef JSON_HEDLEY_MSVC_VERSION
26578 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
26579 #undef JSON_HEDLEY_NEVER_INLINE
26580 #undef JSON_HEDLEY_NON_NULL
26581 #undef JSON_HEDLEY_NO_ESCAPE
26582 #undef JSON_HEDLEY_NO_RETURN
26583 #undef JSON_HEDLEY_NO_THROW
26584 #undef JSON_HEDLEY_NULL
26585 #undef JSON_HEDLEY_PELLES_VERSION
26586 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
26587 #undef JSON_HEDLEY_PGI_VERSION
26588 #undef JSON_HEDLEY_PGI_VERSION_CHECK
26589 #undef JSON_HEDLEY_PREDICT
26590 #undef JSON_HEDLEY_PRINTF_FORMAT
26591 #undef JSON_HEDLEY_PRIVATE
26592 #undef JSON_HEDLEY_PUBLIC
26593 #undef JSON_HEDLEY_PURE
26594 #undef JSON_HEDLEY_REINTERPRET_CAST
26595 #undef JSON_HEDLEY_REQUIRE
26596 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
26597 #undef JSON_HEDLEY_REQUIRE_MSG
26598 #undef JSON_HEDLEY_RESTRICT
26600 #undef JSON_HEDLEY_SENTINEL
26601 #undef JSON_HEDLEY_STATIC_ASSERT
26602 #undef JSON_HEDLEY_STATIC_CAST
26603 #undef JSON_HEDLEY_STRINGIFY
26604 #undef JSON_HEDLEY_STRINGIFY_EX
26605 #undef JSON_HEDLEY_SUNPRO_VERSION
26606 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
26607 #undef JSON_HEDLEY_TINYC_VERSION
26608 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
26609 #undef JSON_HEDLEY_TI_ARMCL_VERSION
26610 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
26611 #undef JSON_HEDLEY_TI_CL2000_VERSION
26612 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
26613 #undef JSON_HEDLEY_TI_CL430_VERSION
26614 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
26615 #undef JSON_HEDLEY_TI_CL6X_VERSION
26616 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
26617 #undef JSON_HEDLEY_TI_CL7X_VERSION
26618 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
26619 #undef JSON_HEDLEY_TI_CLPRU_VERSION
26620 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
26621 #undef JSON_HEDLEY_TI_VERSION
26622 #undef JSON_HEDLEY_TI_VERSION_CHECK
26623 #undef JSON_HEDLEY_UNAVAILABLE
26624 #undef JSON_HEDLEY_UNLIKELY
26625 #undef JSON_HEDLEY_UNPREDICTABLE
26626 #undef JSON_HEDLEY_UNREACHABLE
26627 #undef JSON_HEDLEY_UNREACHABLE_RETURN
26628 #undef JSON_HEDLEY_VERSION
26629 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
26630 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
26631 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
26632 #undef JSON_HEDLEY_VERSION_ENCODE
26633 #undef JSON_HEDLEY_WARNING
26636 #undef JSON_HEDLEY_FALL_THROUGH
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
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
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
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
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
static iteration_proxy< iterator > iterator_wrapper(reference ref) noexcept
wrapper to access iterator member functions in range-based for
iterator begin() noexcept
returns an iterator to the first element
basic_json(InputIT first, InputIT last)
construct a JSON container given an iterator range
basic_json(const JsonRef &ref)
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
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
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
friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
serialize to stream
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
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
const char * type_name() const noexcept
return the type as string
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
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...
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 bool operator<=(const_reference lhs, const_reference rhs) noexcept
comparison: less than or equal
bool empty() const noexcept
checks whether the container is empty.
friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
serialize to stream
basic_json(const basic_json &other)
copy constructor
~basic_json() noexcept
destructor
friend struct detail::external_constructor
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 std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
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
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
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
ValueType & get_to(ValueType &v) const noexcept(noexcept(JSONSerializer< ValueType >::from_json(std::declval< const basic_json_t & >(), v)))
get a value (explicit)
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 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
const binary_t & get_binary() const
constexpr bool is_number() const noexcept
return whether value is a number
std::less< StringType > object_comparator_t
std::pair< iterator, bool > emplace(Args &&... args)
add an object to an object if key does not exist
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
ValueType & get_to(ValueType &v) const
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)
static std::vector< std::uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
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)
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
const std::string & back() const
return last reference token
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
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 & operator/=(const json_pointer &ptr)
append another JSON pointer at the end of this JSON pointer
json_pointer & operator/=(std::size_t array_idx)
append an array index at the end of this JSON 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
json_pointer & operator/=(std::string token)
append an unescaped reference token at the end of this JSON pointer
void push_back(std::string &&token)
append an unescaped token at the end of the reference 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
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
json_sax & operator=(const json_sax &)=default
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
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
std::pair< iterator, bool > insert(const value_type &value)
ordered_map(std::initializer_list< T > init, const Allocator &alloc=Allocator())
std::vector< std::pair< const Key, T >, Allocator > Container
iterator find(const Key &key)
iterator erase(iterator pos)
void insert(InputIt first, InputIt last)
std::pair< iterator, bool > emplace(const key_type &key, T &&t)
const_iterator find(const Key &key) const
std::pair< iterator, bool > insert(value_type &&value)
size_type erase(const Key &key)
const T & operator[](const Key &key) const
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
const T & at(const Key &key) const
ordered_map(It first, It last, const Allocator &alloc=Allocator())
T & operator[](const Key &key)
size_type count(const Key &key) const