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 9
35 #define NLOHMANN_JSON_VERSION_PATCH 1
40 #include <initializer_list>
52 #include <type_traits>
60 #include <forward_list>
65 #include <type_traits>
66 #include <unordered_map>
118 enum class value_t : std::uint8_t
145 inline bool operator<(
const value_t lhs,
const value_t rhs) noexcept
147 static constexpr std::array<std::uint8_t, 9> order = {{
154 const auto l_index =
static_cast<std::size_t
>(lhs);
155 const auto r_index =
static_cast<std::size_t
>(rhs);
156 return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index];
184 #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15)
185 #if defined(JSON_HEDLEY_VERSION)
186 #undef JSON_HEDLEY_VERSION
188 #define JSON_HEDLEY_VERSION 15
190 #if defined(JSON_HEDLEY_STRINGIFY_EX)
191 #undef JSON_HEDLEY_STRINGIFY_EX
193 #define JSON_HEDLEY_STRINGIFY_EX(x) #x
195 #if defined(JSON_HEDLEY_STRINGIFY)
196 #undef JSON_HEDLEY_STRINGIFY
198 #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x)
200 #if defined(JSON_HEDLEY_CONCAT_EX)
201 #undef JSON_HEDLEY_CONCAT_EX
203 #define JSON_HEDLEY_CONCAT_EX(a,b) a##b
205 #if defined(JSON_HEDLEY_CONCAT)
206 #undef JSON_HEDLEY_CONCAT
208 #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b)
210 #if defined(JSON_HEDLEY_CONCAT3_EX)
211 #undef JSON_HEDLEY_CONCAT3_EX
213 #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c
215 #if defined(JSON_HEDLEY_CONCAT3)
216 #undef JSON_HEDLEY_CONCAT3
218 #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c)
220 #if defined(JSON_HEDLEY_VERSION_ENCODE)
221 #undef JSON_HEDLEY_VERSION_ENCODE
223 #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision))
225 #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR)
226 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
228 #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000)
230 #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR)
231 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
233 #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000)
235 #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION)
236 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
238 #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000)
240 #if defined(JSON_HEDLEY_GNUC_VERSION)
241 #undef JSON_HEDLEY_GNUC_VERSION
243 #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
244 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
245 #elif defined(__GNUC__)
246 #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0)
249 #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK)
250 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
252 #if defined(JSON_HEDLEY_GNUC_VERSION)
253 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
255 #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0)
258 #if defined(JSON_HEDLEY_MSVC_VERSION)
259 #undef JSON_HEDLEY_MSVC_VERSION
261 #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL)
262 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100)
263 #elif defined(_MSC_FULL_VER) && !defined(__ICL)
264 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10)
265 #elif defined(_MSC_VER) && !defined(__ICL)
266 #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0)
269 #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK)
270 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
272 #if !defined(JSON_HEDLEY_MSVC_VERSION)
273 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0)
274 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
275 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
276 #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
277 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
279 #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor)))
282 #if defined(JSON_HEDLEY_INTEL_VERSION)
283 #undef JSON_HEDLEY_INTEL_VERSION
285 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL)
286 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE)
287 #elif defined(__INTEL_COMPILER) && !defined(__ICL)
288 #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
291 #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK)
292 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
294 #if defined(JSON_HEDLEY_INTEL_VERSION)
295 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
297 #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0)
300 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
301 #undef JSON_HEDLEY_INTEL_CL_VERSION
303 #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL)
304 #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0)
307 #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK)
308 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
310 #if defined(JSON_HEDLEY_INTEL_CL_VERSION)
311 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
313 #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0)
316 #if defined(JSON_HEDLEY_PGI_VERSION)
317 #undef JSON_HEDLEY_PGI_VERSION
319 #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
320 #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
323 #if defined(JSON_HEDLEY_PGI_VERSION_CHECK)
324 #undef JSON_HEDLEY_PGI_VERSION_CHECK
326 #if defined(JSON_HEDLEY_PGI_VERSION)
327 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
329 #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0)
332 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
333 #undef JSON_HEDLEY_SUNPRO_VERSION
335 #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
336 #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)
337 #elif defined(__SUNPRO_C)
338 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf)
339 #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
340 #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)
341 #elif defined(__SUNPRO_CC)
342 #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf)
345 #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK)
346 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
348 #if defined(JSON_HEDLEY_SUNPRO_VERSION)
349 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
351 #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0)
354 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
355 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
357 #if defined(__EMSCRIPTEN__)
358 #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__)
361 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK)
362 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
364 #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION)
365 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
367 #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0)
370 #if defined(JSON_HEDLEY_ARM_VERSION)
371 #undef JSON_HEDLEY_ARM_VERSION
373 #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
374 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100)
375 #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
376 #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100)
379 #if defined(JSON_HEDLEY_ARM_VERSION_CHECK)
380 #undef JSON_HEDLEY_ARM_VERSION_CHECK
382 #if defined(JSON_HEDLEY_ARM_VERSION)
383 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
385 #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0)
388 #if defined(JSON_HEDLEY_IBM_VERSION)
389 #undef JSON_HEDLEY_IBM_VERSION
391 #if defined(__ibmxl__)
392 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__)
393 #elif defined(__xlC__) && defined(__xlC_ver__)
394 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
395 #elif defined(__xlC__)
396 #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0)
399 #if defined(JSON_HEDLEY_IBM_VERSION_CHECK)
400 #undef JSON_HEDLEY_IBM_VERSION_CHECK
402 #if defined(JSON_HEDLEY_IBM_VERSION)
403 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
405 #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0)
408 #if defined(JSON_HEDLEY_TI_VERSION)
409 #undef JSON_HEDLEY_TI_VERSION
412 defined(__TI_COMPILER_VERSION__) && \
414 defined(__TMS470__) || defined(__TI_ARM__) || \
415 defined(__MSP430__) || \
416 defined(__TMS320C2000__) \
418 #if (__TI_COMPILER_VERSION__ >= 16000000)
419 #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
423 #if defined(JSON_HEDLEY_TI_VERSION_CHECK)
424 #undef JSON_HEDLEY_TI_VERSION_CHECK
426 #if defined(JSON_HEDLEY_TI_VERSION)
427 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
429 #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0)
432 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
433 #undef JSON_HEDLEY_TI_CL2000_VERSION
435 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
436 #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
439 #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK)
440 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
442 #if defined(JSON_HEDLEY_TI_CL2000_VERSION)
443 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
445 #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0)
448 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
449 #undef JSON_HEDLEY_TI_CL430_VERSION
451 #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__)
452 #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
455 #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK)
456 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
458 #if defined(JSON_HEDLEY_TI_CL430_VERSION)
459 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
461 #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0)
464 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
465 #undef JSON_HEDLEY_TI_ARMCL_VERSION
467 #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__))
468 #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
471 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK)
472 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
474 #if defined(JSON_HEDLEY_TI_ARMCL_VERSION)
475 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
477 #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0)
480 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
481 #undef JSON_HEDLEY_TI_CL6X_VERSION
483 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__)
484 #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
487 #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK)
488 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
490 #if defined(JSON_HEDLEY_TI_CL6X_VERSION)
491 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
493 #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0)
496 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
497 #undef JSON_HEDLEY_TI_CL7X_VERSION
499 #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__)
500 #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
503 #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK)
504 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
506 #if defined(JSON_HEDLEY_TI_CL7X_VERSION)
507 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
509 #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0)
512 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
513 #undef JSON_HEDLEY_TI_CLPRU_VERSION
515 #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__)
516 #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000))
519 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK)
520 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
522 #if defined(JSON_HEDLEY_TI_CLPRU_VERSION)
523 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
525 #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0)
528 #if defined(JSON_HEDLEY_CRAY_VERSION)
529 #undef JSON_HEDLEY_CRAY_VERSION
532 #if defined(_RELEASE_PATCHLEVEL)
533 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL)
535 #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0)
539 #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK)
540 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
542 #if defined(JSON_HEDLEY_CRAY_VERSION)
543 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
545 #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0)
548 #if defined(JSON_HEDLEY_IAR_VERSION)
549 #undef JSON_HEDLEY_IAR_VERSION
551 #if defined(__IAR_SYSTEMS_ICC__)
553 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000))
555 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0)
559 #if defined(JSON_HEDLEY_IAR_VERSION_CHECK)
560 #undef JSON_HEDLEY_IAR_VERSION_CHECK
562 #if defined(JSON_HEDLEY_IAR_VERSION)
563 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
565 #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0)
568 #if defined(JSON_HEDLEY_TINYC_VERSION)
569 #undef JSON_HEDLEY_TINYC_VERSION
571 #if defined(__TINYC__)
572 #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
575 #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK)
576 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
578 #if defined(JSON_HEDLEY_TINYC_VERSION)
579 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
581 #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0)
584 #if defined(JSON_HEDLEY_DMC_VERSION)
585 #undef JSON_HEDLEY_DMC_VERSION
588 #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf)
591 #if defined(JSON_HEDLEY_DMC_VERSION_CHECK)
592 #undef JSON_HEDLEY_DMC_VERSION_CHECK
594 #if defined(JSON_HEDLEY_DMC_VERSION)
595 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
597 #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0)
600 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
601 #undef JSON_HEDLEY_COMPCERT_VERSION
603 #if defined(__COMPCERT_VERSION__)
604 #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100)
607 #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK)
608 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
610 #if defined(JSON_HEDLEY_COMPCERT_VERSION)
611 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
613 #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0)
616 #if defined(JSON_HEDLEY_PELLES_VERSION)
617 #undef JSON_HEDLEY_PELLES_VERSION
619 #if defined(__POCC__)
620 #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0)
623 #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK)
624 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
626 #if defined(JSON_HEDLEY_PELLES_VERSION)
627 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
629 #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0)
632 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
633 #undef JSON_HEDLEY_MCST_LCC_VERSION
635 #if defined(__LCC__) && defined(__LCC_MINOR__)
636 #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__)
639 #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK)
640 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
642 #if defined(JSON_HEDLEY_MCST_LCC_VERSION)
643 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
645 #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0)
648 #if defined(JSON_HEDLEY_GCC_VERSION)
649 #undef JSON_HEDLEY_GCC_VERSION
652 defined(JSON_HEDLEY_GNUC_VERSION) && \
653 !defined(__clang__) && \
654 !defined(JSON_HEDLEY_INTEL_VERSION) && \
655 !defined(JSON_HEDLEY_PGI_VERSION) && \
656 !defined(JSON_HEDLEY_ARM_VERSION) && \
657 !defined(JSON_HEDLEY_CRAY_VERSION) && \
658 !defined(JSON_HEDLEY_TI_VERSION) && \
659 !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \
660 !defined(JSON_HEDLEY_TI_CL430_VERSION) && \
661 !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \
662 !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \
663 !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \
664 !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \
665 !defined(__COMPCERT__) && \
666 !defined(JSON_HEDLEY_MCST_LCC_VERSION)
667 #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION
670 #if defined(JSON_HEDLEY_GCC_VERSION_CHECK)
671 #undef JSON_HEDLEY_GCC_VERSION_CHECK
673 #if defined(JSON_HEDLEY_GCC_VERSION)
674 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch))
676 #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0)
679 #if defined(JSON_HEDLEY_HAS_ATTRIBUTE)
680 #undef JSON_HEDLEY_HAS_ATTRIBUTE
683 defined(__has_attribute) && \
685 (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \
687 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute)
689 # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0)
692 #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE)
693 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
695 #if defined(__has_attribute)
696 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
698 #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
701 #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE)
702 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
704 #if defined(__has_attribute)
705 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
707 #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
710 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE)
711 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
714 defined(__has_cpp_attribute) && \
715 defined(__cplusplus) && \
716 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0))
717 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute)
719 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0)
722 #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS)
723 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
725 #if !defined(__cplusplus) || !defined(__has_cpp_attribute)
726 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
728 !defined(JSON_HEDLEY_PGI_VERSION) && \
729 !defined(JSON_HEDLEY_IAR_VERSION) && \
730 (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \
731 (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0))
732 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute)
734 #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0)
737 #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE)
738 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
740 #if defined(__has_cpp_attribute) && defined(__cplusplus)
741 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
743 #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
746 #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE)
747 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
749 #if defined(__has_cpp_attribute) && defined(__cplusplus)
750 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute)
752 #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
755 #if defined(JSON_HEDLEY_HAS_BUILTIN)
756 #undef JSON_HEDLEY_HAS_BUILTIN
758 #if defined(__has_builtin)
759 #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin)
761 #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0)
764 #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN)
765 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
767 #if defined(__has_builtin)
768 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
770 #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
773 #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN)
774 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
776 #if defined(__has_builtin)
777 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin)
779 #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
782 #if defined(JSON_HEDLEY_HAS_FEATURE)
783 #undef JSON_HEDLEY_HAS_FEATURE
785 #if defined(__has_feature)
786 #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature)
788 #define JSON_HEDLEY_HAS_FEATURE(feature) (0)
791 #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE)
792 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
794 #if defined(__has_feature)
795 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
797 #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
800 #if defined(JSON_HEDLEY_GCC_HAS_FEATURE)
801 #undef JSON_HEDLEY_GCC_HAS_FEATURE
803 #if defined(__has_feature)
804 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature)
806 #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
809 #if defined(JSON_HEDLEY_HAS_EXTENSION)
810 #undef JSON_HEDLEY_HAS_EXTENSION
812 #if defined(__has_extension)
813 #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension)
815 #define JSON_HEDLEY_HAS_EXTENSION(extension) (0)
818 #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION)
819 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
821 #if defined(__has_extension)
822 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
824 #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
827 #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION)
828 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
830 #if defined(__has_extension)
831 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension)
833 #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
836 #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE)
837 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
839 #if defined(__has_declspec_attribute)
840 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute)
842 #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0)
845 #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE)
846 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
848 #if defined(__has_declspec_attribute)
849 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
851 #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
854 #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE)
855 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
857 #if defined(__has_declspec_attribute)
858 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute)
860 #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
863 #if defined(JSON_HEDLEY_HAS_WARNING)
864 #undef JSON_HEDLEY_HAS_WARNING
866 #if defined(__has_warning)
867 #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning)
869 #define JSON_HEDLEY_HAS_WARNING(warning) (0)
872 #if defined(JSON_HEDLEY_GNUC_HAS_WARNING)
873 #undef JSON_HEDLEY_GNUC_HAS_WARNING
875 #if defined(__has_warning)
876 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
878 #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch)
881 #if defined(JSON_HEDLEY_GCC_HAS_WARNING)
882 #undef JSON_HEDLEY_GCC_HAS_WARNING
884 #if defined(__has_warning)
885 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning)
887 #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
891 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
892 defined(__clang__) || \
893 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
894 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
895 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
896 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
897 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
898 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
899 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
900 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
901 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
902 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \
903 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
904 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
905 JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \
906 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \
907 JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \
908 (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR))
909 #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value)
910 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
911 #define JSON_HEDLEY_PRAGMA(value) __pragma(value)
913 #define JSON_HEDLEY_PRAGMA(value)
916 #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH)
917 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
919 #if defined(JSON_HEDLEY_DIAGNOSTIC_POP)
920 #undef JSON_HEDLEY_DIAGNOSTIC_POP
922 #if defined(__clang__)
923 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
924 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
925 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
926 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
927 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
928 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
929 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
930 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
932 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
933 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
934 #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push))
935 #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop))
936 #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0)
937 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push")
938 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop")
940 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
941 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
942 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \
943 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
944 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
945 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
946 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push")
947 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop")
948 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
949 #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)")
950 #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)")
952 #define JSON_HEDLEY_DIAGNOSTIC_PUSH
953 #define JSON_HEDLEY_DIAGNOSTIC_POP
958 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
959 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
961 #if defined(__cplusplus)
962 # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat")
963 # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions")
964 # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions")
965 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
966 JSON_HEDLEY_DIAGNOSTIC_PUSH \
967 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
968 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
969 _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \
971 JSON_HEDLEY_DIAGNOSTIC_POP
973 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
974 JSON_HEDLEY_DIAGNOSTIC_PUSH \
975 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
976 _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \
978 JSON_HEDLEY_DIAGNOSTIC_POP
981 # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \
982 JSON_HEDLEY_DIAGNOSTIC_PUSH \
983 _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \
985 JSON_HEDLEY_DIAGNOSTIC_POP
989 #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_)
990 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x
993 #if defined(JSON_HEDLEY_CONST_CAST)
994 #undef JSON_HEDLEY_CONST_CAST
996 #if defined(__cplusplus)
997 # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast<T>(expr))
999 JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \
1000 JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \
1001 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1002 # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \
1003 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1004 JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \
1006 JSON_HEDLEY_DIAGNOSTIC_POP \
1009 # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr))
1012 #if defined(JSON_HEDLEY_REINTERPRET_CAST)
1013 #undef JSON_HEDLEY_REINTERPRET_CAST
1015 #if defined(__cplusplus)
1016 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast<T>(expr))
1018 #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr))
1021 #if defined(JSON_HEDLEY_STATIC_CAST)
1022 #undef JSON_HEDLEY_STATIC_CAST
1024 #if defined(__cplusplus)
1025 #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast<T>(expr))
1027 #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr))
1030 #if defined(JSON_HEDLEY_CPP_CAST)
1031 #undef JSON_HEDLEY_CPP_CAST
1033 #if defined(__cplusplus)
1034 # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast")
1035 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1036 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1037 _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \
1039 JSON_HEDLEY_DIAGNOSTIC_POP
1040 # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0)
1041 # define JSON_HEDLEY_CPP_CAST(T, expr) \
1042 JSON_HEDLEY_DIAGNOSTIC_PUSH \
1043 _Pragma("diag_suppress=Pe137") \
1044 JSON_HEDLEY_DIAGNOSTIC_POP
1046 # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr))
1049 # define JSON_HEDLEY_CPP_CAST(T, expr) (expr)
1052 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED)
1053 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1055 #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations")
1056 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
1057 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1058 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)")
1059 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1060 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786))
1061 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1062 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445")
1063 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1064 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1065 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1066 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1067 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1068 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996))
1069 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1070 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444")
1072 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1073 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1074 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1075 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1076 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1077 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1078 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1079 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1080 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1081 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1082 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0)
1083 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718")
1084 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus)
1085 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)")
1086 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus)
1087 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)")
1088 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1089 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215")
1090 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0)
1091 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)")
1093 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
1096 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS)
1097 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1099 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
1100 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"")
1101 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1102 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)")
1103 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1104 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161))
1105 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1106 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675")
1107 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0)
1108 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"")
1109 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0)
1110 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068))
1112 JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \
1113 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1114 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1115 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0)
1116 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1117 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0)
1118 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163")
1119 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1120 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161")
1121 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1122 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161")
1124 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
1127 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES)
1128 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1130 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes")
1131 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"")
1132 #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0)
1133 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
1134 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0)
1135 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)")
1136 #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1137 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292))
1138 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0)
1139 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030))
1140 #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0)
1141 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098")
1142 #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0)
1143 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1144 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)
1145 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)")
1147 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1148 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1149 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0)
1150 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173")
1151 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1152 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097")
1153 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1154 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097")
1156 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
1159 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL)
1160 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1162 #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual")
1163 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
1164 #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
1165 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)")
1166 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0)
1167 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
1169 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
1172 #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION)
1173 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1175 #if JSON_HEDLEY_HAS_WARNING("-Wunused-function")
1176 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"")
1177 #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0)
1178 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"")
1179 #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0)
1180 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505))
1181 #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1182 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142")
1184 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
1187 #if defined(JSON_HEDLEY_DEPRECATED)
1188 #undef JSON_HEDLEY_DEPRECATED
1190 #if defined(JSON_HEDLEY_DEPRECATED_FOR)
1191 #undef JSON_HEDLEY_DEPRECATED_FOR
1194 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1195 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1196 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since))
1197 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement))
1199 (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1200 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1201 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1202 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1203 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \
1204 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1205 JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \
1206 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \
1207 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \
1208 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1209 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \
1210 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1211 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since)))
1212 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement)))
1213 #elif defined(__cplusplus) && (__cplusplus >= 201402L)
1214 #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]])
1215 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]])
1217 JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \
1218 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1219 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1220 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1221 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1222 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1223 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1224 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1225 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1226 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1227 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1228 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1229 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1230 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1231 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1232 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1233 #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__))
1234 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__))
1236 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1237 JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \
1238 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1239 #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated)
1240 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated)
1241 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1242 #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated")
1243 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated")
1245 #define JSON_HEDLEY_DEPRECATED(since)
1246 #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement)
1249 #if defined(JSON_HEDLEY_UNAVAILABLE)
1250 #undef JSON_HEDLEY_UNAVAILABLE
1253 JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \
1254 JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \
1255 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1256 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1257 #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since)))
1259 #define JSON_HEDLEY_UNAVAILABLE(available_since)
1269 JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \
1270 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1271 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1272 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1273 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1274 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1275 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1276 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1277 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1278 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1279 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1280 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1281 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1282 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1283 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1284 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1285 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1286 #define __attribute__((__warn_unused_result__))
1287 #define _MSG(msg) __attribute__((__warn_unused_result__))
1288 #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L)
1289 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1290 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]])
1291 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard)
1292 #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1293 #define _MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]])
1294 #elif defined(_Check_return_)
1295 #define _Check_return_
1296 #define _MSG(msg) _Check_return_
1302 #if defined(JSON_HEDLEY_SENTINEL)
1303 #undef JSON_HEDLEY_SENTINEL
1306 JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \
1307 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1308 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1309 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1310 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1311 #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position)))
1313 #define JSON_HEDLEY_SENTINEL(position)
1316 #if defined(JSON_HEDLEY_NO_RETURN)
1317 #undef JSON_HEDLEY_NO_RETURN
1319 #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1320 #define JSON_HEDLEY_NO_RETURN __noreturn
1322 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1323 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1324 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1325 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
1326 #define JSON_HEDLEY_NO_RETURN _Noreturn
1327 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1328 #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]])
1330 JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \
1331 JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \
1332 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1333 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1334 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1335 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1336 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1337 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1338 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1339 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1340 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1341 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1342 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1343 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1344 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1345 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1346 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1347 #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__))
1348 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1349 #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return")
1351 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1352 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1353 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1354 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1355 #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;")
1356 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1357 #define JSON_HEDLEY_NO_RETURN __attribute((noreturn))
1358 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1359 #define JSON_HEDLEY_NO_RETURN __declspec(noreturn)
1361 #define JSON_HEDLEY_NO_RETURN
1364 #if defined(JSON_HEDLEY_NO_ESCAPE)
1365 #undef JSON_HEDLEY_NO_ESCAPE
1367 #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape)
1368 #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__))
1370 #define JSON_HEDLEY_NO_ESCAPE
1373 #if defined(JSON_HEDLEY_UNREACHABLE)
1374 #undef JSON_HEDLEY_UNREACHABLE
1376 #if defined(JSON_HEDLEY_UNREACHABLE_RETURN)
1377 #undef JSON_HEDLEY_UNREACHABLE_RETURN
1379 #if defined(JSON_HEDLEY_ASSUME)
1380 #undef JSON_HEDLEY_ASSUME
1383 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1384 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1385 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1386 #define JSON_HEDLEY_ASSUME(expr) __assume(expr)
1387 #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume)
1388 #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr)
1390 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1391 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1392 #if defined(__cplusplus)
1393 #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr)
1395 #define JSON_HEDLEY_ASSUME(expr) _nassert(expr)
1399 (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \
1400 JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \
1401 JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \
1402 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1403 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \
1404 JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \
1405 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1406 #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable()
1407 #elif defined(JSON_HEDLEY_ASSUME)
1408 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1410 #if !defined(JSON_HEDLEY_ASSUME)
1411 #if defined(JSON_HEDLEY_UNREACHABLE)
1412 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1)))
1414 #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr)
1417 #if defined(JSON_HEDLEY_UNREACHABLE)
1419 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1420 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0)
1421 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value))
1423 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE()
1426 #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value)
1428 #if !defined(JSON_HEDLEY_UNREACHABLE)
1429 #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0)
1432 JSON_HEDLEY_DIAGNOSTIC_PUSH
1433 #if JSON_HEDLEY_HAS_WARNING("-Wpedantic")
1434 #pragma clang diagnostic ignored "-Wpedantic"
1436 #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus)
1437 #pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
1439 #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0)
1440 #if defined(__clang__)
1441 #pragma clang diagnostic ignored "-Wvariadic-macros"
1442 #elif defined(JSON_HEDLEY_GCC_VERSION)
1443 #pragma GCC diagnostic ignored "-Wvariadic-macros"
1446 #if defined(JSON_HEDLEY_NON_NULL)
1447 #undef JSON_HEDLEY_NON_NULL
1450 JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \
1451 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1452 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1453 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1454 #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
1456 #define JSON_HEDLEY_NON_NULL(...)
1458 JSON_HEDLEY_DIAGNOSTIC_POP
1460 #if defined(JSON_HEDLEY_PRINTF_FORMAT)
1461 #undef JSON_HEDLEY_PRINTF_FORMAT
1463 #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO)
1464 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check)))
1465 #elif 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__(gnu_printf, string_idx, first_to_check)))
1468 JSON_HEDLEY_HAS_ATTRIBUTE(format) || \
1469 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1470 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1471 JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \
1472 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1473 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1474 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1475 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1476 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1477 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1478 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1479 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1480 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1481 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1482 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1483 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1484 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1485 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check)))
1486 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0)
1487 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check))
1489 #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check)
1492 #if defined(JSON_HEDLEY_CONSTEXPR)
1493 #undef JSON_HEDLEY_CONSTEXPR
1495 #if defined(__cplusplus)
1496 #if __cplusplus >= 201103L
1497 #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr)
1500 #if !defined(JSON_HEDLEY_CONSTEXPR)
1501 #define JSON_HEDLEY_CONSTEXPR
1504 #if defined(JSON_HEDLEY_PREDICT)
1505 #undef JSON_HEDLEY_PREDICT
1507 #if defined(JSON_HEDLEY_LIKELY)
1508 #undef JSON_HEDLEY_LIKELY
1510 #if defined(JSON_HEDLEY_UNLIKELY)
1511 #undef JSON_HEDLEY_UNLIKELY
1513 #if defined(JSON_HEDLEY_UNPREDICTABLE)
1514 #undef JSON_HEDLEY_UNPREDICTABLE
1516 #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable)
1517 #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr))
1520 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \
1521 JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \
1522 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1523 # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability))
1524 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability))
1525 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability))
1526 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 )
1527 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 )
1529 (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
1530 JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \
1531 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1532 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \
1533 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1534 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1535 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1536 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \
1537 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1538 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \
1539 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1540 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1541 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1542 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \
1543 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1544 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1545 # define JSON_HEDLEY_PREDICT(expr, expected, probability) \
1546 (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)))
1547 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \
1549 double hedley_probability_ = (probability); \
1550 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \
1552 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \
1554 double hedley_probability_ = (probability); \
1555 ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \
1557 # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1)
1558 # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
1560 # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))
1561 # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr))
1562 # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr))
1563 # define JSON_HEDLEY_LIKELY(expr) (!!(expr))
1564 # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr))
1566 #if !defined(JSON_HEDLEY_UNPREDICTABLE)
1567 #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5)
1570 #if defined(JSON_HEDLEY_MALLOC)
1571 #undef JSON_HEDLEY_MALLOC
1574 JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \
1575 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1576 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1577 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1578 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1579 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1580 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1581 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1582 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1583 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1584 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1585 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1586 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1587 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1588 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1589 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1590 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1591 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1592 #define JSON_HEDLEY_MALLOC __attribute__((__malloc__))
1593 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1594 #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory")
1596 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1597 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1598 #define JSON_HEDLEY_MALLOC __declspec(restrict)
1600 #define JSON_HEDLEY_MALLOC
1603 #if defined(JSON_HEDLEY_PURE)
1604 #undef JSON_HEDLEY_PURE
1607 JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \
1608 JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \
1609 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1610 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1611 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1612 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1613 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1614 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1615 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1616 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1617 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1618 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1619 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1620 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1621 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1622 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1623 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1624 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1625 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1626 # define JSON_HEDLEY_PURE __attribute__((__pure__))
1627 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1628 # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data")
1629 #elif defined(__cplusplus) && \
1631 JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \
1632 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \
1633 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \
1635 # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;")
1637 # define JSON_HEDLEY_PURE
1640 #if defined(JSON_HEDLEY_CONST)
1641 #undef JSON_HEDLEY_CONST
1644 JSON_HEDLEY_HAS_ATTRIBUTE(const) || \
1645 JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \
1646 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1647 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1648 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1649 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1650 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1651 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1652 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1653 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1654 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1655 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1656 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1657 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1658 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1659 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1660 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1661 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1662 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1663 #define JSON_HEDLEY_CONST __attribute__((__const__))
1665 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0)
1666 #define JSON_HEDLEY_CONST _Pragma("no_side_effect")
1668 #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE
1671 #if defined(JSON_HEDLEY_RESTRICT)
1672 #undef JSON_HEDLEY_RESTRICT
1674 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
1675 #define JSON_HEDLEY_RESTRICT restrict
1677 JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \
1678 JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \
1679 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1680 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1681 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1682 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1683 JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \
1684 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1685 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \
1686 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \
1687 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1688 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \
1689 JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \
1690 defined(__clang__) || \
1691 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1692 #define JSON_HEDLEY_RESTRICT __restrict
1693 #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus)
1694 #define JSON_HEDLEY_RESTRICT _Restrict
1696 #define JSON_HEDLEY_RESTRICT
1699 #if defined(JSON_HEDLEY_INLINE)
1700 #undef JSON_HEDLEY_INLINE
1703 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \
1704 (defined(__cplusplus) && (__cplusplus >= 199711L))
1705 #define JSON_HEDLEY_INLINE inline
1707 defined(JSON_HEDLEY_GCC_VERSION) || \
1708 JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0)
1709 #define JSON_HEDLEY_INLINE __inline__
1711 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1712 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1713 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1714 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \
1715 JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \
1716 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \
1717 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \
1718 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1719 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1720 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1721 #define JSON_HEDLEY_INLINE __inline
1723 #define JSON_HEDLEY_INLINE
1726 #if defined(JSON_HEDLEY_ALWAYS_INLINE)
1727 #undef JSON_HEDLEY_ALWAYS_INLINE
1730 JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \
1731 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1732 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1733 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1734 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1735 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1736 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1737 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1738 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1739 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1740 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1741 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1742 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1743 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1744 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1745 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1746 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1747 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1748 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1749 # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE
1751 JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \
1752 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1753 # define JSON_HEDLEY_ALWAYS_INLINE __forceinline
1754 #elif defined(__cplusplus) && \
1756 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1757 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1758 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1759 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1760 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1761 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \
1763 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;")
1764 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1765 # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced")
1767 # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE
1770 #if defined(JSON_HEDLEY_NEVER_INLINE)
1771 #undef JSON_HEDLEY_NEVER_INLINE
1774 JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \
1775 JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \
1776 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1777 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1778 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1779 JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \
1780 JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \
1781 (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1782 JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \
1783 (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1784 JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \
1785 (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1786 JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \
1787 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1788 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \
1789 JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \
1790 JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \
1791 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \
1792 JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0)
1793 #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__))
1795 JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \
1796 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
1797 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1798 #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0)
1799 #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline")
1800 #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus)
1801 #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;")
1802 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
1803 #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never")
1804 #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0)
1805 #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline))
1806 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0)
1807 #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline)
1809 #define JSON_HEDLEY_NEVER_INLINE
1812 #if defined(JSON_HEDLEY_PRIVATE)
1813 #undef JSON_HEDLEY_PRIVATE
1815 #if defined(JSON_HEDLEY_PUBLIC)
1816 #undef JSON_HEDLEY_PUBLIC
1818 #if defined(JSON_HEDLEY_IMPORT)
1819 #undef JSON_HEDLEY_IMPORT
1821 #if defined(_WIN32) || defined(__CYGWIN__)
1822 # define JSON_HEDLEY_PRIVATE
1823 # define JSON_HEDLEY_PUBLIC __declspec(dllexport)
1824 # define JSON_HEDLEY_IMPORT __declspec(dllimport)
1827 JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \
1828 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1829 JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \
1830 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1831 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1832 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1834 defined(__TI_EABI__) && \
1836 (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \
1837 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \
1840 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1841 # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden")))
1842 # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default")))
1844 # define JSON_HEDLEY_PRIVATE
1845 # define JSON_HEDLEY_PUBLIC
1847 # define JSON_HEDLEY_IMPORT extern
1850 #if defined(JSON_HEDLEY_NO_THROW)
1851 #undef JSON_HEDLEY_NO_THROW
1854 JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \
1855 JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \
1856 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1857 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1858 #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__))
1860 JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \
1861 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \
1862 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0)
1863 #define JSON_HEDLEY_NO_THROW __declspec(nothrow)
1865 #define JSON_HEDLEY_NO_THROW
1868 #if defined(JSON_HEDLEY_FALL_THROUGH)
1869 #undef JSON_HEDLEY_FALL_THROUGH
1872 JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \
1873 JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \
1874 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1875 #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__))
1876 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough)
1877 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]])
1878 #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough)
1879 #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]])
1880 #elif defined(__fallthrough)
1881 #define JSON_HEDLEY_FALL_THROUGH __fallthrough
1883 #define JSON_HEDLEY_FALL_THROUGH
1890 JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \
1891 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1892 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1893 #define __attribute__((__returns_nonnull__))
1894 #elif defined(_Ret_notnull_)
1895 #define _Ret_notnull_
1900 #if defined(JSON_HEDLEY_ARRAY_PARAM)
1901 #undef JSON_HEDLEY_ARRAY_PARAM
1904 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1905 !defined(__STDC_NO_VLA__) && \
1906 !defined(__cplusplus) && \
1907 !defined(JSON_HEDLEY_PGI_VERSION) && \
1908 !defined(JSON_HEDLEY_TINYC_VERSION)
1909 #define JSON_HEDLEY_ARRAY_PARAM(name) (name)
1911 #define JSON_HEDLEY_ARRAY_PARAM(name)
1914 #if defined(JSON_HEDLEY_IS_CONSTANT)
1915 #undef JSON_HEDLEY_IS_CONSTANT
1917 #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR)
1918 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
1922 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1923 #undef JSON_HEDLEY_IS_CONSTEXPR_
1926 JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \
1927 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1928 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1929 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \
1930 JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \
1931 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1932 JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \
1933 (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \
1934 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1935 JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10)
1936 #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr)
1938 #if !defined(__cplusplus)
1940 JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \
1941 JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \
1942 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
1943 JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \
1944 JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \
1945 JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \
1946 JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24)
1947 #if defined(__INTPTR_TYPE__)
1948 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*)
1951 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*)
1955 defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \
1956 !defined(JSON_HEDLEY_SUNPRO_VERSION) && \
1957 !defined(JSON_HEDLEY_PGI_VERSION) && \
1958 !defined(JSON_HEDLEY_IAR_VERSION)) || \
1959 (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \
1960 JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \
1961 JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \
1962 JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \
1963 JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0)
1964 #if defined(__INTPTR_TYPE__)
1965 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0)
1968 #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0)
1971 defined(JSON_HEDLEY_GCC_VERSION) || \
1972 defined(JSON_HEDLEY_INTEL_VERSION) || \
1973 defined(JSON_HEDLEY_TINYC_VERSION) || \
1974 defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \
1975 JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \
1976 defined(JSON_HEDLEY_TI_CL2000_VERSION) || \
1977 defined(JSON_HEDLEY_TI_CL6X_VERSION) || \
1978 defined(JSON_HEDLEY_TI_CL7X_VERSION) || \
1979 defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \
1981 # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \
1985 ((void*) ((expr) * 0L) ) : \
1986 ((struct { char v[sizeof(void) * 2]; } *) 1) \
1992 #if defined(JSON_HEDLEY_IS_CONSTEXPR_)
1993 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1994 #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr)
1996 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1))
1998 #if !defined(JSON_HEDLEY_IS_CONSTANT)
1999 #define JSON_HEDLEY_IS_CONSTANT(expr) (0)
2001 #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr)
2004 #if defined(JSON_HEDLEY_BEGIN_C_DECLS)
2005 #undef JSON_HEDLEY_BEGIN_C_DECLS
2007 #if defined(JSON_HEDLEY_END_C_DECLS)
2008 #undef JSON_HEDLEY_END_C_DECLS
2010 #if defined(JSON_HEDLEY_C_DECL)
2011 #undef JSON_HEDLEY_C_DECL
2013 #if defined(__cplusplus)
2014 #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" {
2015 #define JSON_HEDLEY_END_C_DECLS }
2016 #define JSON_HEDLEY_C_DECL extern "C"
2018 #define JSON_HEDLEY_BEGIN_C_DECLS
2019 #define JSON_HEDLEY_END_C_DECLS
2020 #define JSON_HEDLEY_C_DECL
2023 #if defined(JSON_HEDLEY_STATIC_ASSERT)
2024 #undef JSON_HEDLEY_STATIC_ASSERT
2027 !defined(__cplusplus) && ( \
2028 (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \
2029 (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \
2030 JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \
2031 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \
2032 defined(_Static_assert) \
2034 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message)
2036 (defined(__cplusplus) && (__cplusplus >= 201103L)) || \
2037 JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \
2038 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2039 # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message))
2041 # define JSON_HEDLEY_STATIC_ASSERT(expr, message)
2044 #if defined(JSON_HEDLEY_NULL)
2045 #undef JSON_HEDLEY_NULL
2047 #if defined(__cplusplus)
2048 #if __cplusplus >= 201103L
2049 #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr)
2051 #define JSON_HEDLEY_NULL NULL
2053 #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0)
2056 #define JSON_HEDLEY_NULL NULL
2058 #define JSON_HEDLEY_NULL ((void*) 0)
2061 #if defined(JSON_HEDLEY_MESSAGE)
2062 #undef JSON_HEDLEY_MESSAGE
2064 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2065 # define JSON_HEDLEY_MESSAGE(msg) \
2066 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2067 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2068 JSON_HEDLEY_PRAGMA(message msg) \
2069 JSON_HEDLEY_DIAGNOSTIC_POP
2071 JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \
2072 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2073 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg)
2074 #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0)
2075 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg)
2076 #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0)
2077 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2078 #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0)
2079 # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg))
2081 # define JSON_HEDLEY_MESSAGE(msg)
2084 #if defined(JSON_HEDLEY_WARNING)
2085 #undef JSON_HEDLEY_WARNING
2087 #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas")
2088 # define JSON_HEDLEY_WARNING(msg) \
2089 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2090 JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \
2091 JSON_HEDLEY_PRAGMA(clang warning msg) \
2092 JSON_HEDLEY_DIAGNOSTIC_POP
2094 JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \
2095 JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \
2096 JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0)
2097 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg)
2099 JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \
2100 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2101 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg))
2103 # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg)
2106 #if defined(JSON_HEDLEY_REQUIRE)
2107 #undef JSON_HEDLEY_REQUIRE
2109 #if defined(JSON_HEDLEY_REQUIRE_MSG)
2110 #undef JSON_HEDLEY_REQUIRE_MSG
2112 #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if)
2113 # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat")
2114 # define JSON_HEDLEY_REQUIRE(expr) \
2115 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2116 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2117 __attribute__((diagnose_if(!(expr), #expr, "error"))) \
2118 JSON_HEDLEY_DIAGNOSTIC_POP
2119 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \
2120 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2121 _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \
2122 __attribute__((diagnose_if(!(expr), msg, "error"))) \
2123 JSON_HEDLEY_DIAGNOSTIC_POP
2125 # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error")))
2126 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error")))
2129 # define JSON_HEDLEY_REQUIRE(expr)
2130 # define JSON_HEDLEY_REQUIRE_MSG(expr,msg)
2133 #if defined(JSON_HEDLEY_FLAGS)
2134 #undef JSON_HEDLEY_FLAGS
2136 #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion"))
2137 #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__))
2139 #define JSON_HEDLEY_FLAGS
2142 #if defined(JSON_HEDLEY_FLAGS_CAST)
2143 #undef JSON_HEDLEY_FLAGS_CAST
2145 #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0)
2146 # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \
2147 JSON_HEDLEY_DIAGNOSTIC_PUSH \
2148 _Pragma("warning(disable:188)") \
2150 JSON_HEDLEY_DIAGNOSTIC_POP \
2153 # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr)
2156 #if defined(JSON_HEDLEY_EMPTY_BASES)
2157 #undef JSON_HEDLEY_EMPTY_BASES
2160 (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \
2161 JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0)
2162 #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases)
2164 #define JSON_HEDLEY_EMPTY_BASES
2169 #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK)
2170 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
2172 #if defined(__clang__)
2173 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0)
2175 #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch)
2178 #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE)
2179 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
2181 #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute)
2183 #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE)
2184 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
2186 #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute)
2188 #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN)
2189 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
2191 #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin)
2193 #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE)
2194 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
2196 #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature)
2198 #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION)
2199 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
2201 #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension)
2203 #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE)
2204 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
2206 #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute)
2208 #if defined(JSON_HEDLEY_CLANG_HAS_WARNING)
2209 #undef JSON_HEDLEY_CLANG_HAS_WARNING
2211 #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning)
2220 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
2221 #if defined(__clang__)
2222 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400
2223 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
2225 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
2226 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
2227 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
2233 #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
2234 #define JSON_HAS_CPP_20
2235 #define JSON_HAS_CPP_17
2236 #define JSON_HAS_CPP_14
2237 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1)
2238 #define JSON_HAS_CPP_17
2239 #define JSON_HAS_CPP_14
2240 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
2241 #define JSON_HAS_CPP_14
2245 #if defined(__clang__)
2246 #pragma GCC diagnostic push
2247 #pragma GCC diagnostic ignored "-Wdocumentation"
2251 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
2252 #define JSON_THROW(exception) throw exception
2253 #define JSON_TRY try
2254 #define JSON_CATCH(exception) catch(exception)
2255 #define JSON_INTERNAL_CATCH(exception) catch(exception)
2258 #define JSON_THROW(exception) std::abort()
2259 #define JSON_TRY if(true)
2260 #define JSON_CATCH(exception) if(false)
2261 #define JSON_INTERNAL_CATCH(exception) if(false)
2265 #if defined(JSON_THROW_USER)
2267 #define JSON_THROW JSON_THROW_USER
2269 #if defined(JSON_TRY_USER)
2271 #define JSON_TRY JSON_TRY_USER
2273 #if defined(JSON_CATCH_USER)
2275 #define JSON_CATCH JSON_CATCH_USER
2276 #undef JSON_INTERNAL_CATCH
2277 #define JSON_INTERNAL_CATCH JSON_CATCH_USER
2279 #if defined(JSON_INTERNAL_CATCH_USER)
2280 #undef JSON_INTERNAL_CATCH
2281 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
2285 #if !defined(JSON_ASSERT)
2287 #define JSON_ASSERT(x) assert(x)
2291 #if defined(JSON_TESTS_PRIVATE)
2292 #define JSON_PRIVATE_UNLESS_TESTED public
2294 #define JSON_PRIVATE_UNLESS_TESTED private
2302 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \
2303 template<typename BasicJsonType> \
2304 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \
2306 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2307 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2308 auto it = std::find_if(std::begin(m), std::end(m), \
2309 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2311 return ej_pair.first == e; \
2313 j = ((it != std::end(m)) ? it : std::begin(m))->second; \
2315 template<typename BasicJsonType> \
2316 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \
2318 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \
2319 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \
2320 auto it = std::find_if(std::begin(m), std::end(m), \
2321 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \
2323 return ej_pair.second == j; \
2325 e = ((it != std::end(m)) ? it : std::begin(m))->first; \
2331 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
2332 template<template<typename, typename, typename...> class ObjectType, \
2333 template<typename, typename...> class ArrayType, \
2334 class StringType, class BooleanType, class NumberIntegerType, \
2335 class NumberUnsignedType, class NumberFloatType, \
2336 template<typename> class AllocatorType, \
2337 template<typename, typename = void> class JSONSerializer, \
2340 #define NLOHMANN_BASIC_JSON_TPL \
2341 basic_json<ObjectType, ArrayType, StringType, BooleanType, \
2342 NumberIntegerType, NumberUnsignedType, NumberFloatType, \
2343 AllocatorType, JSONSerializer, BinaryType>
2347 #define NLOHMANN_JSON_EXPAND( x ) x
2348 #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
2349 #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \
2350 NLOHMANN_JSON_PASTE64, \
2351 NLOHMANN_JSON_PASTE63, \
2352 NLOHMANN_JSON_PASTE62, \
2353 NLOHMANN_JSON_PASTE61, \
2354 NLOHMANN_JSON_PASTE60, \
2355 NLOHMANN_JSON_PASTE59, \
2356 NLOHMANN_JSON_PASTE58, \
2357 NLOHMANN_JSON_PASTE57, \
2358 NLOHMANN_JSON_PASTE56, \
2359 NLOHMANN_JSON_PASTE55, \
2360 NLOHMANN_JSON_PASTE54, \
2361 NLOHMANN_JSON_PASTE53, \
2362 NLOHMANN_JSON_PASTE52, \
2363 NLOHMANN_JSON_PASTE51, \
2364 NLOHMANN_JSON_PASTE50, \
2365 NLOHMANN_JSON_PASTE49, \
2366 NLOHMANN_JSON_PASTE48, \
2367 NLOHMANN_JSON_PASTE47, \
2368 NLOHMANN_JSON_PASTE46, \
2369 NLOHMANN_JSON_PASTE45, \
2370 NLOHMANN_JSON_PASTE44, \
2371 NLOHMANN_JSON_PASTE43, \
2372 NLOHMANN_JSON_PASTE42, \
2373 NLOHMANN_JSON_PASTE41, \
2374 NLOHMANN_JSON_PASTE40, \
2375 NLOHMANN_JSON_PASTE39, \
2376 NLOHMANN_JSON_PASTE38, \
2377 NLOHMANN_JSON_PASTE37, \
2378 NLOHMANN_JSON_PASTE36, \
2379 NLOHMANN_JSON_PASTE35, \
2380 NLOHMANN_JSON_PASTE34, \
2381 NLOHMANN_JSON_PASTE33, \
2382 NLOHMANN_JSON_PASTE32, \
2383 NLOHMANN_JSON_PASTE31, \
2384 NLOHMANN_JSON_PASTE30, \
2385 NLOHMANN_JSON_PASTE29, \
2386 NLOHMANN_JSON_PASTE28, \
2387 NLOHMANN_JSON_PASTE27, \
2388 NLOHMANN_JSON_PASTE26, \
2389 NLOHMANN_JSON_PASTE25, \
2390 NLOHMANN_JSON_PASTE24, \
2391 NLOHMANN_JSON_PASTE23, \
2392 NLOHMANN_JSON_PASTE22, \
2393 NLOHMANN_JSON_PASTE21, \
2394 NLOHMANN_JSON_PASTE20, \
2395 NLOHMANN_JSON_PASTE19, \
2396 NLOHMANN_JSON_PASTE18, \
2397 NLOHMANN_JSON_PASTE17, \
2398 NLOHMANN_JSON_PASTE16, \
2399 NLOHMANN_JSON_PASTE15, \
2400 NLOHMANN_JSON_PASTE14, \
2401 NLOHMANN_JSON_PASTE13, \
2402 NLOHMANN_JSON_PASTE12, \
2403 NLOHMANN_JSON_PASTE11, \
2404 NLOHMANN_JSON_PASTE10, \
2405 NLOHMANN_JSON_PASTE9, \
2406 NLOHMANN_JSON_PASTE8, \
2407 NLOHMANN_JSON_PASTE7, \
2408 NLOHMANN_JSON_PASTE6, \
2409 NLOHMANN_JSON_PASTE5, \
2410 NLOHMANN_JSON_PASTE4, \
2411 NLOHMANN_JSON_PASTE3, \
2412 NLOHMANN_JSON_PASTE2, \
2413 NLOHMANN_JSON_PASTE1)(__VA_ARGS__))
2414 #define NLOHMANN_JSON_PASTE2(func, v1) func(v1)
2415 #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2)
2416 #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3)
2417 #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4)
2418 #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5)
2419 #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)
2420 #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)
2421 #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)
2422 #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)
2423 #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)
2424 #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)
2425 #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)
2426 #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)
2427 #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)
2428 #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)
2429 #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)
2430 #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)
2431 #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)
2432 #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)
2433 #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)
2434 #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)
2435 #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)
2436 #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)
2437 #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)
2438 #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)
2439 #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)
2440 #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)
2441 #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)
2442 #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)
2443 #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)
2444 #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)
2445 #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)
2446 #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)
2447 #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)
2448 #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)
2449 #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)
2450 #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)
2451 #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)
2452 #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)
2453 #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)
2454 #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)
2455 #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)
2456 #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)
2457 #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)
2458 #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)
2459 #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)
2460 #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)
2461 #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)
2462 #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)
2463 #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)
2464 #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)
2465 #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)
2466 #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)
2467 #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)
2468 #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)
2469 #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)
2470 #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)
2471 #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)
2472 #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)
2473 #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)
2474 #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)
2475 #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)
2476 #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)
2478 #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1;
2479 #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1);
2486 #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \
2487 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__)) } \
2488 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__)) }
2495 #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \
2496 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__)) } \
2497 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__)) }
2499 #ifndef JSON_USE_IMPLICIT_CONVERSIONS
2500 #define JSON_USE_IMPLICIT_CONVERSIONS 1
2503 #if JSON_USE_IMPLICIT_CONVERSIONS
2504 #define JSON_EXPLICIT
2506 #define JSON_EXPLICIT explicit
2528 inline void replace_substring(std::string& s,
const std::string& f,
2529 const std::string& t)
2531 JSON_ASSERT(!f.empty());
2532 for (
auto pos = s.find(f);
2533 pos != std::string::npos;
2534 s.replace(pos, f.size(), t),
2535 pos = s.find(f, pos + t.size()))
2546 inline std::string escape(std::string s)
2548 replace_substring(s,
"~",
"~0");
2549 replace_substring(s,
"/",
"~1");
2560 static void unescape(std::string& s)
2562 replace_substring(s,
"~1",
"/");
2563 replace_substring(s,
"~0",
"~");
2582 std::size_t chars_read_total = 0;
2584 std::size_t chars_read_current_line = 0;
2586 std::size_t lines_read = 0;
2589 constexpr
operator size_t()
const
2591 return chars_read_total;
2637 class exception :
public std::exception
2641 const char* what() const noexcept
override
2650 JSON_HEDLEY_NON_NULL(3)
2651 exception(
int id_, const
char* what_arg) :
id(id_), m(what_arg) {}
2653 static std::string name(
const std::string& ename,
int id_)
2655 return "[json.exception." + ename +
"." + std::to_string(id_) +
"] ";
2658 template<
typename BasicJsonType>
2659 static std::string diagnostics(
const BasicJsonType& leaf_element)
2661 #if JSON_DIAGNOSTICS
2662 std::vector<std::string> tokens;
2663 for (
const auto* current = &leaf_element; current->m_parent !=
nullptr; current = current->m_parent)
2665 switch (current->m_parent->type())
2667 case value_t::array:
2669 for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
2671 if (¤t->m_parent->m_value.array->operator[](i) == current)
2673 tokens.emplace_back(std::to_string(i));
2680 case value_t::object:
2682 for (
const auto& element : *current->m_parent->m_value.object)
2684 if (&element.second == current)
2686 tokens.emplace_back(element.first.c_str());
2703 return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{},
2704 [](
const std::string & a,
const std::string & b)
2706 return a +
"/" + detail::escape(b);
2709 static_cast<void>(leaf_element);
2716 std::runtime_error m;
2764 class parse_error :
public exception
2776 template<
typename BasicJsonType>
2777 static parse_error create(
int id_,
const position_t& pos,
const std::string& what_arg,
const BasicJsonType& context)
2779 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2780 position_string(pos) +
": " + exception::diagnostics(context) + what_arg;
2781 return parse_error(id_, pos.chars_read_total, w.c_str());
2784 template<
typename BasicJsonType>
2785 static parse_error create(
int id_, std::size_t byte_,
const std::string& what_arg,
const BasicJsonType& context)
2787 std::string w = exception::name(
"parse_error", id_) +
"parse error" +
2788 (byte_ != 0 ? (
" at byte " + std::to_string(byte_)) :
"") +
2789 ": " + exception::diagnostics(context) + what_arg;
2790 return parse_error(id_, byte_, w.c_str());
2802 const std::size_t byte;
2805 parse_error(
int id_, std::size_t byte_,
const char* what_arg)
2806 : exception(id_, what_arg), byte(byte_) {}
2808 static std::string position_string(
const position_t& pos)
2810 return " at line " + std::to_string(pos.lines_read + 1) +
2811 ", column " + std::to_string(pos.chars_read_current_line);
2852 class invalid_iterator :
public exception
2855 template<
typename BasicJsonType>
2856 static invalid_iterator create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2858 std::string w = exception::name(
"invalid_iterator", id_) + exception::diagnostics(context) + what_arg;
2859 return invalid_iterator(id_, w.c_str());
2863 JSON_HEDLEY_NON_NULL(3)
2864 invalid_iterator(
int id_, const
char* what_arg)
2865 : exception(id_, what_arg) {}
2907 class type_error :
public exception
2910 template<
typename BasicJsonType>
2911 static type_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2913 std::string w = exception::name(
"type_error", id_) + exception::diagnostics(context) + what_arg;
2914 return type_error(id_, w.c_str());
2918 JSON_HEDLEY_NON_NULL(3)
2919 type_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2955 class out_of_range :
public exception
2958 template<
typename BasicJsonType>
2959 static out_of_range create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
2961 std::string w = exception::name(
"out_of_range", id_) + exception::diagnostics(context) + what_arg;
2962 return out_of_range(id_, w.c_str());
2966 JSON_HEDLEY_NON_NULL(3)
2967 out_of_range(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
2994 class other_error :
public exception
2997 template<
typename BasicJsonType>
2998 static other_error create(
int id_,
const std::string& what_arg,
const BasicJsonType& context)
3000 std::string w = exception::name(
"other_error", id_) + exception::diagnostics(context) + what_arg;
3001 return other_error(id_, w.c_str());
3005 JSON_HEDLEY_NON_NULL(3)
3006 other_error(
int id_, const
char* what_arg) : exception(id_, what_arg) {}
3017 #include <type_traits>
3028 template<
typename T>
3029 using uncvref_t =
typename std::remove_cv<typename std::remove_reference<T>::type>::type;
3031 #ifdef JSON_HAS_CPP_14
3034 using std::enable_if_t;
3035 using std::index_sequence;
3036 using std::make_index_sequence;
3037 using std::index_sequence_for;
3042 template<
bool B,
typename T =
void>
3043 using enable_if_t =
typename std::enable_if<B, T>::type;
3069 template <
typename T, T... Ints>
3070 struct integer_sequence
3072 using value_type = T;
3073 static constexpr std::size_t size() noexcept
3075 return sizeof...(Ints);
3084 template <
size_t... Ints>
3085 using index_sequence = integer_sequence<size_t, Ints...>;
3087 namespace utility_internal
3090 template <
typename Seq,
size_t SeqSize,
size_t Rem>
3094 template <
typename T, T... Ints,
size_t SeqSize>
3095 struct Extend<integer_sequence<T, Ints...>, SeqSize, 0>
3097 using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >;
3100 template <
typename T, T... Ints,
size_t SeqSize>
3101 struct Extend<integer_sequence<T, Ints...>, SeqSize, 1>
3103 using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >;
3108 template <
typename T,
size_t N>
3112 typename Extend <
typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type;
3115 template <
typename T>
3118 using type = integer_sequence<T>;
3130 template <
typename T, T N>
3131 using make_integer_sequence =
typename utility_internal::Gen<T, N>::type;
3139 using make_index_sequence = make_integer_sequence<size_t, N>;
3146 template <
typename... Ts>
3147 using index_sequence_for = make_index_sequence<
sizeof...(Ts)>;
3154 template<
unsigned N>
struct priority_tag : priority_tag < N - 1 > {};
3155 template<>
struct priority_tag<0> {};
3158 template<
typename T>
3161 static constexpr T value{};
3164 template<
typename T>
3165 constexpr T static_const<T>::value;
3178 template <
class T>
struct identity_tag {};
3186 #include <type_traits>
3202 template<
typename ...Ts>
struct make_void
3206 template<
typename ...Ts>
using void_t =
typename make_void<Ts...>::type;
3217 template<
typename It,
typename =
void>
3218 struct iterator_types {};
3220 template<
typename It>
3221 struct iterator_types <
3223 void_t<typename It::difference_type, typename It::value_type, typename It::pointer,
3224 typename It::reference, typename It::iterator_category >>
3226 using difference_type =
typename It::difference_type;
3227 using value_type =
typename It::value_type;
3228 using pointer =
typename It::pointer;
3229 using reference =
typename It::reference;
3230 using iterator_category =
typename It::iterator_category;
3235 template<
typename T,
typename =
void>
3236 struct iterator_traits
3240 template<
typename T>
3241 struct iterator_traits < T, enable_if_t < !std::is_pointer<T>::value >>
3246 template<
typename T>
3247 struct iterator_traits<T*, enable_if_t<std::is_object<T>::value>>
3249 using iterator_category = std::random_access_iterator_tag;
3250 using value_type = T;
3251 using difference_type = ptrdiff_t;
3253 using reference = T&;
3265 #include <type_traits>
3277 nonesuch() =
delete;
3278 ~nonesuch() =
delete;
3279 nonesuch(nonesuch
const&) =
delete;
3280 nonesuch(nonesuch
const&&) =
delete;
3281 void operator=(nonesuch
const&) =
delete;
3282 void operator=(nonesuch&&) =
delete;
3285 template<
class Default,
3287 template<
class...>
class Op,
3291 using value_t = std::false_type;
3292 using type = Default;
3295 template<
class Default,
template<
class...>
class Op,
class... Args>
3296 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
3298 using value_t = std::true_type;
3299 using type = Op<Args...>;
3302 template<
template<
class...>
class Op,
class... Args>
3303 using is_detected =
typename detector<nonesuch, void, Op, Args...>::value_t;
3305 template<
template<
class...>
class Op,
class... Args>
3306 using detected_t =
typename detector<nonesuch, void, Op, Args...>::type;
3308 template<
class Default,
template<
class...>
class Op,
class... Args>
3309 using detected_or = detector<Default, void, Op, Args...>;
3311 template<
class Default,
template<
class...>
class Op,
class... Args>
3312 using detected_or_t =
typename detected_or<Default, Op, Args...>::type;
3314 template<
class Expected,
template<
class...>
class Op,
class... Args>
3315 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
3317 template<
class To,
template<
class...>
class Op,
class... Args>
3318 using is_detected_convertible =
3319 std::is_convertible<detected_t<Op, Args...>, To>;
3324 #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
3325 #define INCLUDE_NLOHMANN_JSON_FWD_HPP_
3347 template<
typename T =
void,
typename SFINAE =
void>
3348 struct adl_serializer;
3350 template<
template<
typename U,
typename V,
typename... Args>
class ObjectType =
3352 template<
typename U,
typename... Args>
class ArrayType = std::vector,
3353 class StringType = std::string,
class BooleanType = bool,
3354 class NumberIntegerType = std::int64_t,
3355 class NumberUnsignedType = std::uint64_t,
3356 class NumberFloatType = double,
3357 template<
typename U>
class AllocatorType = std::allocator,
3358 template<
typename T,
typename SFINAE =
void>
class JSONSerializer =
3360 class BinaryType = std::vector<std::uint8_t>>
3374 template<
typename BasicJsonType>
3387 template<
class Key,
class T,
class IgnoredLess,
class Allocator>
3429 template<
typename>
struct is_basic_json : std::false_type {};
3431 NLOHMANN_BASIC_JSON_TPL_DECLARATION
3432 struct is_basic_json<NLOHMANN_BASIC_JSON_TPL> : std::true_type {};
3442 struct is_json_ref : std::false_type {};
3444 template<
typename T>
3445 struct is_json_ref<json_ref<T>> : std::true_type {};
3451 template<
typename T>
3452 using mapped_type_t =
typename T::mapped_type;
3454 template<
typename T>
3455 using key_type_t =
typename T::key_type;
3457 template<
typename T>
3458 using value_type_t =
typename T::value_type;
3460 template<
typename T>
3461 using difference_type_t =
typename T::difference_type;
3463 template<
typename T>
3464 using pointer_t =
typename T::pointer;
3466 template<
typename T>
3467 using reference_t =
typename T::reference;
3469 template<
typename T>
3470 using iterator_category_t =
typename T::iterator_category;
3472 template<
typename T>
3473 using iterator_t =
typename T::iterator;
3475 template<
typename T,
typename... Args>
3476 using to_json_function = decltype(T::to_json(std::declval<Args>()...));
3478 template<
typename T,
typename... Args>
3479 using from_json_function = decltype(T::from_json(std::declval<Args>()...));
3481 template<
typename T,
typename U>
3482 using get_template_function = decltype(std::declval<T>().
template get<U>());
3485 template<
typename BasicJsonType,
typename T,
typename =
void>
3486 struct has_from_json : std::false_type {};
3492 template <
typename BasicJsonType,
typename T>
3495 static constexpr
bool value = is_detected<get_template_function, const BasicJsonType&, T>::value;
3498 template<
typename BasicJsonType,
typename T>
3499 struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3501 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3503 static constexpr
bool value =
3504 is_detected_exact<void, from_json_function, serializer,
3505 const BasicJsonType&, T&>::value;
3510 template<
typename BasicJsonType,
typename T,
typename =
void>
3511 struct has_non_default_from_json : std::false_type {};
3513 template<
typename BasicJsonType,
typename T>
3514 struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3516 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3518 static constexpr
bool value =
3519 is_detected_exact<T, from_json_function, serializer,
3520 const BasicJsonType&>::value;
3525 template<
typename BasicJsonType,
typename T,
typename =
void>
3526 struct has_to_json : std::false_type {};
3528 template<
typename BasicJsonType,
typename T>
3529 struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json<T>::value >>
3531 using serializer =
typename BasicJsonType::template json_serializer<T, void>;
3533 static constexpr
bool value =
3534 is_detected_exact<void, to_json_function, serializer, BasicJsonType&,
3544 template<
class...>
struct conjunction : std::true_type { };
3545 template<
class B1>
struct conjunction<B1> : B1 { };
3546 template<
class B1,
class... Bn>
3547 struct conjunction<B1, Bn...>
3548 : std::conditional<bool(B1::value), conjunction<Bn...>, B1>::type {};
3553 template <
typename T>
3554 struct is_default_constructible : std::is_default_constructible<T> {};
3556 template <
typename T1,
typename T2>
3557 struct is_default_constructible<std::pair<T1, T2>>
3558 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3560 template <
typename T1,
typename T2>
3561 struct is_default_constructible<const std::pair<T1, T2>>
3562 : conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
3564 template <
typename... Ts>
3565 struct is_default_constructible<std::tuple<Ts...>>
3566 : conjunction<is_default_constructible<Ts>...> {};
3568 template <
typename... Ts>
3569 struct is_default_constructible<const std::tuple<Ts...>>
3570 : conjunction<is_default_constructible<Ts>...> {};
3573 template <
typename T,
typename... Args>
3574 struct is_constructible : std::is_constructible<T, Args...> {};
3576 template <
typename T1,
typename T2>
3577 struct is_constructible<std::pair<T1, T2>> : is_default_constructible<std::pair<T1, T2>> {};
3579 template <
typename T1,
typename T2>
3580 struct is_constructible<const std::pair<T1, T2>> : is_default_constructible<const std::pair<T1, T2>> {};
3582 template <
typename... Ts>
3583 struct is_constructible<std::tuple<Ts...>> : is_default_constructible<std::tuple<Ts...>> {};
3585 template <
typename... Ts>
3586 struct is_constructible<const std::tuple<Ts...>> : is_default_constructible<const std::tuple<Ts...>> {};
3589 template<
typename T,
typename =
void>
3590 struct is_iterator_traits : std::false_type {};
3592 template<
typename T>
3593 struct is_iterator_traits<iterator_traits<T>>
3596 using traits = iterator_traits<T>;
3599 static constexpr
auto value =
3600 is_detected<value_type_t, traits>::value &&
3601 is_detected<difference_type_t, traits>::value &&
3602 is_detected<pointer_t, traits>::value &&
3603 is_detected<iterator_category_t, traits>::value &&
3604 is_detected<reference_t, traits>::value;
3611 template<
typename T,
typename =
void>
3612 struct is_complete_type : std::false_type {};
3614 template<
typename T>
3615 struct is_complete_type<T, decltype(void(sizeof(T)))> : std::true_type {};
3617 template<
typename BasicJsonType,
typename CompatibleObjectType,
3619 struct is_compatible_object_type_impl : std::false_type {};
3621 template<
typename BasicJsonType,
typename CompatibleObjectType>
3622 struct is_compatible_object_type_impl <
3623 BasicJsonType, CompatibleObjectType,
3624 enable_if_t < is_detected<mapped_type_t, CompatibleObjectType>::value&&
3625 is_detected<key_type_t, CompatibleObjectType>::value >>
3627 using object_t =
typename BasicJsonType::object_t;
3630 static constexpr
bool value =
3631 is_constructible<
typename object_t::key_type,
3632 typename CompatibleObjectType::key_type>::value &&
3633 is_constructible<
typename object_t::mapped_type,
3634 typename CompatibleObjectType::mapped_type>::value;
3637 template<
typename BasicJsonType,
typename CompatibleObjectType>
3638 struct is_compatible_object_type
3639 : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
3641 template<
typename BasicJsonType,
typename ConstructibleObjectType,
3643 struct is_constructible_object_type_impl : std::false_type {};
3645 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3646 struct is_constructible_object_type_impl <
3647 BasicJsonType, ConstructibleObjectType,
3648 enable_if_t < is_detected<mapped_type_t, ConstructibleObjectType>::value&&
3649 is_detected<key_type_t, ConstructibleObjectType>::value >>
3651 using object_t =
typename BasicJsonType::object_t;
3653 static constexpr
bool value =
3654 (is_default_constructible<ConstructibleObjectType>::value &&
3655 (std::is_move_assignable<ConstructibleObjectType>::value ||
3656 std::is_copy_assignable<ConstructibleObjectType>::value) &&
3657 (is_constructible<
typename ConstructibleObjectType::key_type,
3658 typename object_t::key_type>::value &&
3660 typename object_t::mapped_type,
3661 typename ConstructibleObjectType::mapped_type >::value)) ||
3662 (has_from_json<BasicJsonType,
3663 typename ConstructibleObjectType::mapped_type>::value ||
3664 has_non_default_from_json <
3666 typename ConstructibleObjectType::mapped_type >::value);
3669 template<
typename BasicJsonType,
typename ConstructibleObjectType>
3670 struct is_constructible_object_type
3671 : is_constructible_object_type_impl<BasicJsonType,
3672 ConstructibleObjectType> {};
3674 template<
typename BasicJsonType,
typename CompatibleStringType,
3676 struct is_compatible_string_type_impl : std::false_type {};
3678 template<
typename BasicJsonType,
typename CompatibleStringType>
3679 struct is_compatible_string_type_impl <
3680 BasicJsonType, CompatibleStringType,
3681 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3682 value_type_t, CompatibleStringType>::value >>
3684 static constexpr
auto value =
3685 is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value;
3688 template<
typename BasicJsonType,
typename ConstructibleStringType>
3689 struct is_compatible_string_type
3690 : is_compatible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3692 template<
typename BasicJsonType,
typename ConstructibleStringType,
3694 struct is_constructible_string_type_impl : std::false_type {};
3696 template<
typename BasicJsonType,
typename ConstructibleStringType>
3697 struct is_constructible_string_type_impl <
3698 BasicJsonType, ConstructibleStringType,
3699 enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type,
3700 value_type_t, ConstructibleStringType>::value >>
3702 static constexpr
auto value =
3703 is_constructible<ConstructibleStringType,
3704 typename BasicJsonType::string_t>::value;
3707 template<
typename BasicJsonType,
typename ConstructibleStringType>
3708 struct is_constructible_string_type
3709 : is_constructible_string_type_impl<BasicJsonType, ConstructibleStringType> {};
3711 template<
typename BasicJsonType,
typename CompatibleArrayType,
typename =
void>
3712 struct is_compatible_array_type_impl : std::false_type {};
3714 template<
typename BasicJsonType,
typename CompatibleArrayType>
3715 struct is_compatible_array_type_impl <
3716 BasicJsonType, CompatibleArrayType,
3717 enable_if_t < is_detected<value_type_t, CompatibleArrayType>::value&&
3718 is_detected<iterator_t, CompatibleArrayType>::value&&
3722 !is_iterator_traits <
3723 iterator_traits<CompatibleArrayType >>::value >>
3725 static constexpr
bool value =
3726 is_constructible<BasicJsonType,
3727 typename CompatibleArrayType::value_type>::value;
3730 template<
typename BasicJsonType,
typename CompatibleArrayType>
3731 struct is_compatible_array_type
3732 : is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
3734 template<
typename BasicJsonType,
typename ConstructibleArrayType,
typename =
void>
3735 struct is_constructible_array_type_impl : std::false_type {};
3737 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3738 struct is_constructible_array_type_impl <
3739 BasicJsonType, ConstructibleArrayType,
3740 enable_if_t<std::is_same<ConstructibleArrayType,
3741 typename BasicJsonType::value_type>::value >>
3742 : std::true_type {};
3744 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3745 struct is_constructible_array_type_impl <
3746 BasicJsonType, ConstructibleArrayType,
3747 enable_if_t < !std::is_same<ConstructibleArrayType,
3748 typename BasicJsonType::value_type>::value&&
3749 is_default_constructible<ConstructibleArrayType>::value&&
3750 (std::is_move_assignable<ConstructibleArrayType>::value ||
3751 std::is_copy_assignable<ConstructibleArrayType>::value)&&
3752 is_detected<value_type_t, ConstructibleArrayType>::value&&
3753 is_detected<iterator_t, ConstructibleArrayType>::value&&
3755 detected_t<value_type_t, ConstructibleArrayType >>::value >>
3757 static constexpr
bool value =
3763 !is_iterator_traits<iterator_traits<ConstructibleArrayType>>::value &&
3765 (std::is_same<
typename ConstructibleArrayType::value_type,
3766 typename BasicJsonType::array_t::value_type>::value ||
3767 has_from_json<BasicJsonType,
3768 typename ConstructibleArrayType::value_type>::value ||
3769 has_non_default_from_json <
3770 BasicJsonType,
typename ConstructibleArrayType::value_type >::value);
3773 template<
typename BasicJsonType,
typename ConstructibleArrayType>
3774 struct is_constructible_array_type
3775 : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
3777 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType,
3779 struct is_compatible_integer_type_impl : std::false_type {};
3781 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3782 struct is_compatible_integer_type_impl <
3783 RealIntegerType, CompatibleNumberIntegerType,
3784 enable_if_t < std::is_integral<RealIntegerType>::value&&
3785 std::is_integral<CompatibleNumberIntegerType>::value&&
3786 !std::is_same<bool, CompatibleNumberIntegerType>::value >>
3789 using RealLimits = std::numeric_limits<RealIntegerType>;
3790 using CompatibleLimits = std::numeric_limits<CompatibleNumberIntegerType>;
3792 static constexpr
auto value =
3793 is_constructible<RealIntegerType,
3794 CompatibleNumberIntegerType>::value &&
3795 CompatibleLimits::is_integer &&
3796 RealLimits::is_signed == CompatibleLimits::is_signed;
3799 template<
typename RealIntegerType,
typename CompatibleNumberIntegerType>
3800 struct is_compatible_integer_type
3801 : is_compatible_integer_type_impl<RealIntegerType,
3802 CompatibleNumberIntegerType> {};
3804 template<
typename BasicJsonType,
typename CompatibleType,
typename =
void>
3805 struct is_compatible_type_impl: std::false_type {};
3807 template<
typename BasicJsonType,
typename CompatibleType>
3808 struct is_compatible_type_impl <
3809 BasicJsonType, CompatibleType,
3810 enable_if_t<is_complete_type<CompatibleType>::value >>
3812 static constexpr
bool value =
3813 has_to_json<BasicJsonType, CompatibleType>::value;
3816 template<
typename BasicJsonType,
typename CompatibleType>
3817 struct is_compatible_type
3818 : is_compatible_type_impl<BasicJsonType, CompatibleType> {};
3820 template<
typename T1,
typename T2>
3821 struct is_constructible_tuple : std::false_type {};
3823 template<
typename T1,
typename... Args>
3824 struct is_constructible_tuple<T1, std::tuple<Args...>> : conjunction<is_constructible<T1, Args>...> {};
3835 template<
typename BasicJsonType>
3836 void from_json(
const BasicJsonType& j,
typename std::nullptr_t& n)
3838 if (JSON_HEDLEY_UNLIKELY(!j.is_null()))
3840 JSON_THROW(type_error::create(302,
"type must be null, but is " + std::string(j.type_name()), j));
3846 template <
typename BasicJsonType,
typename ArithmeticType,
3847 enable_if_t < std::is_arithmetic<ArithmeticType>::value&&
3848 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
3850 void get_arithmetic_value(
const BasicJsonType& j, ArithmeticType& val)
3852 switch (
static_cast<value_t
>(j))
3854 case value_t::number_unsigned:
3856 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
3859 case value_t::number_integer:
3861 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
3864 case value_t::number_float:
3866 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
3871 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
3875 template<
typename BasicJsonType>
3876 void from_json(
const BasicJsonType& j,
typename BasicJsonType::boolean_t& b)
3878 if (JSON_HEDLEY_UNLIKELY(!j.is_boolean()))
3880 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(j.type_name()), j));
3882 b = *j.template get_ptr<const typename BasicJsonType::boolean_t*>();
3885 template<
typename BasicJsonType>
3886 void from_json(
const BasicJsonType& j,
typename BasicJsonType::string_t& s)
3888 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3890 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3892 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3896 typename BasicJsonType,
typename ConstructibleStringType,
3898 is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value&&
3899 !std::is_same<
typename BasicJsonType::string_t,
3900 ConstructibleStringType>::value,
3902 void from_json(
const BasicJsonType& j, ConstructibleStringType& s)
3904 if (JSON_HEDLEY_UNLIKELY(!j.is_string()))
3906 JSON_THROW(type_error::create(302,
"type must be string, but is " + std::string(j.type_name()), j));
3909 s = *j.template get_ptr<const typename BasicJsonType::string_t*>();
3912 template<
typename BasicJsonType>
3913 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_float_t& val)
3915 get_arithmetic_value(j, val);
3918 template<
typename BasicJsonType>
3919 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_unsigned_t& val)
3921 get_arithmetic_value(j, val);
3924 template<
typename BasicJsonType>
3925 void from_json(
const BasicJsonType& j,
typename BasicJsonType::number_integer_t& val)
3927 get_arithmetic_value(j, val);
3930 template<
typename BasicJsonType,
typename EnumType,
3931 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
3932 void from_json(
const BasicJsonType& j, EnumType& e)
3934 typename std::underlying_type<EnumType>::type val;
3935 get_arithmetic_value(j, val);
3936 e =
static_cast<EnumType
>(val);
3940 template<
typename BasicJsonType,
typename T,
typename Allocator,
3941 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3942 void from_json(
const BasicJsonType& j, std::forward_list<T, Allocator>& l)
3944 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3946 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
3949 std::transform(j.rbegin(), j.rend(),
3950 std::front_inserter(l), [](
const BasicJsonType & i)
3952 return i.template get<T>();
3957 template<
typename BasicJsonType,
typename T,
3958 enable_if_t<is_getable<BasicJsonType, T>::value,
int> = 0>
3959 void from_json(
const BasicJsonType& j, std::valarray<T>& l)
3961 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
3963 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
3966 std::transform(j.begin(), j.end(), std::begin(l),
3967 [](
const BasicJsonType & elem)
3969 return elem.template get<T>();
3973 template<
typename BasicJsonType,
typename T, std::
size_t N>
3974 auto from_json(
const BasicJsonType& j, T (&arr)[N])
3975 -> decltype(j.template get<T>(),
void())
3977 for (std::size_t i = 0; i < N; ++i)
3979 arr[i] = j.at(i).template get<T>();
3983 template<
typename BasicJsonType>
3984 void from_json_array_impl(
const BasicJsonType& j,
typename BasicJsonType::array_t& arr, priority_tag<3> )
3986 arr = *j.template get_ptr<const typename BasicJsonType::array_t*>();
3989 template<
typename BasicJsonType,
typename T, std::
size_t N>
3990 auto from_json_array_impl(
const BasicJsonType& j, std::array<T, N>& arr,
3992 -> decltype(j.template get<T>(),
void())
3994 for (std::size_t i = 0; i < N; ++i)
3996 arr[i] = j.at(i).template get<T>();
4000 template<
typename BasicJsonType,
typename ConstructibleArrayType,
4002 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4004 auto from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> )
4006 arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()),
4007 j.template get<typename ConstructibleArrayType::value_type>(),
4012 ConstructibleArrayType ret;
4013 ret.reserve(j.size());
4014 std::transform(j.begin(), j.end(),
4015 std::inserter(ret, end(ret)), [](
const BasicJsonType & i)
4019 return i.template get<typename ConstructibleArrayType::value_type>();
4021 arr = std::move(ret);
4024 template<
typename BasicJsonType,
typename ConstructibleArrayType,
4026 std::is_assignable<ConstructibleArrayType&, ConstructibleArrayType>::value,
4028 void from_json_array_impl(
const BasicJsonType& j, ConstructibleArrayType& arr,
4033 ConstructibleArrayType ret;
4035 j.begin(), j.end(), std::inserter(ret, end(ret)),
4036 [](
const BasicJsonType & i)
4040 return i.template get<typename ConstructibleArrayType::value_type>();
4042 arr = std::move(ret);
4045 template <
typename BasicJsonType,
typename ConstructibleArrayType,
4047 is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value&&
4048 !is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value&&
4049 !is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value&&
4050 !std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value&&
4051 !is_basic_json<ConstructibleArrayType>::value,
4053 auto from_json(
const BasicJsonType& j, ConstructibleArrayType& arr)
4054 -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
4055 j.template get<typename ConstructibleArrayType::value_type>(),
4058 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4060 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4063 from_json_array_impl(j, arr, priority_tag<3> {});
4066 template <
typename BasicJsonType,
typename T, std::size_t... Idx >
4067 std::array<T,
sizeof...(Idx)> from_json_inplace_array_impl(BasicJsonType&& j,
4068 identity_tag<std::array<T,
sizeof...(Idx)>> , index_sequence<Idx...> )
4070 return { { std::forward<BasicJsonType>(j).at(Idx).template get<T>()... } };
4073 template <
typename BasicJsonType,
typename T, std::
size_t N >
4074 auto from_json(BasicJsonType&& j, identity_tag<std::array<T, N>> tag)
4075 -> decltype(from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {}))
4077 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4079 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4082 return from_json_inplace_array_impl(std::forward<BasicJsonType>(j), tag, make_index_sequence<N> {});
4085 template<
typename BasicJsonType>
4086 void from_json(
const BasicJsonType& j,
typename BasicJsonType::binary_t& bin)
4088 if (JSON_HEDLEY_UNLIKELY(!j.is_binary()))
4090 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(j.type_name()), j));
4093 bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
4096 template<
typename BasicJsonType,
typename ConstructibleObjectType,
4097 enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value,
int> = 0>
4098 void from_json(
const BasicJsonType& j, ConstructibleObjectType& obj)
4100 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
4102 JSON_THROW(type_error::create(302,
"type must be object, but is " + std::string(j.type_name()), j));
4105 ConstructibleObjectType ret;
4106 const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
4107 using value_type =
typename ConstructibleObjectType::value_type;
4109 inner_object->begin(), inner_object->end(),
4110 std::inserter(ret, ret.begin()),
4111 [](
typename BasicJsonType::object_t::value_type
const & p)
4113 return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>());
4115 obj = std::move(ret);
4122 template <
typename BasicJsonType,
typename ArithmeticType,
4124 std::is_arithmetic<ArithmeticType>::value&&
4125 !std::is_same<ArithmeticType, typename BasicJsonType::number_unsigned_t>::value&&
4126 !std::is_same<ArithmeticType, typename BasicJsonType::number_integer_t>::value&&
4127 !std::is_same<ArithmeticType, typename BasicJsonType::number_float_t>::value&&
4128 !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
4130 void from_json(
const BasicJsonType& j, ArithmeticType& val)
4132 switch (
static_cast<value_t
>(j))
4134 case value_t::number_unsigned:
4136 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_unsigned_t*>());
4139 case value_t::number_integer:
4141 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_integer_t*>());
4144 case value_t::number_float:
4146 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::number_float_t*>());
4149 case value_t::boolean:
4151 val =
static_cast<ArithmeticType
>(*j.template get_ptr<const typename BasicJsonType::boolean_t*>());
4156 JSON_THROW(type_error::create(302,
"type must be number, but is " + std::string(j.type_name()), j));
4160 template<
typename BasicJsonType,
typename... Args, std::size_t... Idx>
4161 std::tuple<Args...> from_json_tuple_impl_base(BasicJsonType&& j, index_sequence<Idx...> )
4163 return std::make_tuple(std::forward<BasicJsonType>(j).at(Idx).
template get<Args>()...);
4166 template <
typename BasicJsonType,
class A1,
class A2 >
4167 std::pair<A1, A2> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::pair<A1, A2>> , priority_tag<0> )
4169 return {std::forward<BasicJsonType>(j).at(0).template get<A1>(),
4170 std::forward<BasicJsonType>(j).at(1).template get<A2>()};
4173 template<
typename BasicJsonType,
typename A1,
typename A2>
4174 void from_json_tuple_impl(BasicJsonType&& j, std::pair<A1, A2>& p, priority_tag<1> )
4176 p = from_json_tuple_impl(std::forward<BasicJsonType>(j), identity_tag<std::pair<A1, A2>> {}, priority_tag<0> {});
4179 template<
typename BasicJsonType,
typename... Args>
4180 std::tuple<Args...> from_json_tuple_impl(BasicJsonType&& j, identity_tag<std::tuple<Args...>> , priority_tag<2> )
4182 return from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4185 template<
typename BasicJsonType,
typename... Args>
4186 void from_json_tuple_impl(BasicJsonType&& j, std::tuple<Args...>& t, priority_tag<3> )
4188 t = from_json_tuple_impl_base<BasicJsonType, Args...>(std::forward<BasicJsonType>(j), index_sequence_for<Args...> {});
4191 template<
typename BasicJsonType,
typename TupleRelated>
4192 auto from_json(BasicJsonType&& j, TupleRelated&& t)
4193 -> decltype(from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {}))
4195 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4197 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4200 return from_json_tuple_impl(std::forward<BasicJsonType>(j), std::forward<TupleRelated>(t), priority_tag<3> {});
4203 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Compare,
typename Allocator,
4204 typename = enable_if_t < !std::is_constructible <
4205 typename BasicJsonType::string_t, Key >::value >>
4206 void from_json(
const BasicJsonType& j, std::map<Key, Value, Compare, Allocator>& m)
4208 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4210 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4213 for (
const auto& p : j)
4215 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4217 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4219 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4223 template <
typename BasicJsonType,
typename Key,
typename Value,
typename Hash,
typename KeyEqual,
typename Allocator,
4224 typename = enable_if_t < !std::is_constructible <
4225 typename BasicJsonType::string_t, Key >::value >>
4226 void from_json(
const BasicJsonType& j, std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>& m)
4228 if (JSON_HEDLEY_UNLIKELY(!j.is_array()))
4230 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(j.type_name()), j));
4233 for (
const auto& p : j)
4235 if (JSON_HEDLEY_UNLIKELY(!p.is_array()))
4237 JSON_THROW(type_error::create(302,
"type must be array, but is " + std::string(p.type_name()), j));
4239 m.emplace(p.at(0).template get<Key>(), p.at(1).template get<Value>());
4245 template<
typename BasicJsonType,
typename T>
4246 auto operator()(
const BasicJsonType& j, T&& val)
const
4247 noexcept(noexcept(
from_json(j, std::forward<T>(val))))
4248 -> decltype(
from_json(j, std::forward<T>(val)))
4250 return from_json(j, std::forward<T>(val));
4260 constexpr
const auto&
from_json = detail::static_const<detail::from_json_fn>::value;
4267 #include <algorithm>
4271 #include <type_traits>
4294 template<
typename string_type>
4295 void int_to_string( string_type& target, std::size_t value )
4298 using std::to_string;
4301 template<
typename IteratorType>
class iteration_proxy_value
4304 using difference_type = std::ptrdiff_t;
4305 using value_type = iteration_proxy_value;
4306 using pointer = value_type * ;
4307 using reference = value_type & ;
4308 using iterator_category = std::input_iterator_tag;
4309 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
4313 IteratorType anchor;
4315 std::size_t array_index = 0;
4317 mutable std::size_t array_index_last = 0;
4319 mutable string_type array_index_str =
"0";
4321 const string_type empty_str{};
4324 explicit iteration_proxy_value(IteratorType it) noexcept
4325 : anchor(std::move(it))
4329 iteration_proxy_value& operator*()
4335 iteration_proxy_value& operator++()
4344 bool operator==(
const iteration_proxy_value& o)
const
4346 return anchor == o.anchor;
4350 bool operator!=(
const iteration_proxy_value& o)
const
4352 return anchor != o.anchor;
4356 const string_type& key()
const
4358 JSON_ASSERT(anchor.m_object !=
nullptr);
4360 switch (anchor.m_object->type())
4363 case value_t::array:
4365 if (array_index != array_index_last)
4367 int_to_string( array_index_str, array_index );
4368 array_index_last = array_index;
4370 return array_index_str;
4374 case value_t::object:
4375 return anchor.key();
4384 typename IteratorType::reference value()
const
4386 return anchor.value();
4391 template<
typename IteratorType>
class iteration_proxy
4395 typename IteratorType::reference container;
4399 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
4400 : container(cont) {}
4403 iteration_proxy_value<IteratorType> begin() noexcept
4405 return iteration_proxy_value<IteratorType>(container.begin());
4409 iteration_proxy_value<IteratorType> end() noexcept
4411 return iteration_proxy_value<IteratorType>(container.end());
4417 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
4418 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.key())
4425 template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
4426 auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) -> decltype(i.value())
4439 #if defined(__clang__)
4441 #pragma clang diagnostic push
4442 #pragma clang diagnostic ignored "-Wmismatched-tags"
4444 template<
typename IteratorType>
4445 class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
4446 :
public std::integral_constant<std::size_t, 2> {};
4448 template<std::
size_t N,
typename IteratorType>
4449 class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
4452 using type = decltype(
4453 get<N>(std::declval <
4454 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
4456 #if defined(__clang__)
4457 #pragma clang diagnostic pop
4476 template<value_t>
struct external_constructor;
4479 struct external_constructor<value_t::boolean>
4481 template<
typename BasicJsonType>
4482 static void construct(BasicJsonType& j,
typename BasicJsonType::boolean_t b) noexcept
4484 j.m_type = value_t::boolean;
4486 j.assert_invariant();
4491 struct external_constructor<value_t::string>
4493 template<
typename BasicJsonType>
4494 static void construct(BasicJsonType& j,
const typename BasicJsonType::string_t& s)
4496 j.m_type = value_t::string;
4498 j.assert_invariant();
4501 template<
typename BasicJsonType>
4502 static void construct(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4504 j.m_type = value_t::string;
4505 j.m_value = std::move(s);
4506 j.assert_invariant();
4509 template <
typename BasicJsonType,
typename CompatibleStringType,
4510 enable_if_t < !std::is_same<CompatibleStringType, typename BasicJsonType::string_t>::value,
4512 static void construct(BasicJsonType& j,
const CompatibleStringType& str)
4514 j.m_type = value_t::string;
4515 j.m_value.string = j.template create<typename BasicJsonType::string_t>(str);
4516 j.assert_invariant();
4521 struct external_constructor<value_t::binary>
4523 template<
typename BasicJsonType>
4524 static void construct(BasicJsonType& j,
const typename BasicJsonType::binary_t& b)
4526 j.m_type = value_t::binary;
4527 j.m_value =
typename BasicJsonType::binary_t(b);
4528 j.assert_invariant();
4531 template<
typename BasicJsonType>
4532 static void construct(BasicJsonType& j,
typename BasicJsonType::binary_t&& b)
4534 j.m_type = value_t::binary;
4535 j.m_value =
typename BasicJsonType::binary_t(std::move(b));;
4536 j.assert_invariant();
4541 struct external_constructor<value_t::number_float>
4543 template<
typename BasicJsonType>
4544 static void construct(BasicJsonType& j,
typename BasicJsonType::number_float_t val) noexcept
4546 j.m_type = value_t::number_float;
4548 j.assert_invariant();
4553 struct external_constructor<value_t::number_unsigned>
4555 template<
typename BasicJsonType>
4556 static void construct(BasicJsonType& j,
typename BasicJsonType::number_unsigned_t val) noexcept
4558 j.m_type = value_t::number_unsigned;
4560 j.assert_invariant();
4565 struct external_constructor<value_t::number_integer>
4567 template<
typename BasicJsonType>
4568 static void construct(BasicJsonType& j,
typename BasicJsonType::number_integer_t val) noexcept
4570 j.m_type = value_t::number_integer;
4572 j.assert_invariant();
4577 struct external_constructor<value_t::array>
4579 template<
typename BasicJsonType>
4580 static void construct(BasicJsonType& j,
const typename BasicJsonType::array_t& arr)
4582 j.m_type = value_t::array;
4585 j.assert_invariant();
4588 template<
typename BasicJsonType>
4589 static void construct(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4591 j.m_type = value_t::array;
4592 j.m_value = std::move(arr);
4594 j.assert_invariant();
4597 template <
typename BasicJsonType,
typename CompatibleArrayType,
4598 enable_if_t < !std::is_same<CompatibleArrayType, typename BasicJsonType::array_t>::value,
4600 static void construct(BasicJsonType& j,
const CompatibleArrayType& arr)
4604 j.m_type = value_t::array;
4605 j.m_value.array = j.template create<typename BasicJsonType::array_t>(begin(arr), end(arr));
4607 j.assert_invariant();
4610 template<
typename BasicJsonType>
4611 static void construct(BasicJsonType& j,
const std::vector<bool>& arr)
4613 j.m_type = value_t::array;
4614 j.m_value = value_t::array;
4615 j.m_value.array->reserve(arr.size());
4616 for (
const bool x : arr)
4618 j.m_value.array->push_back(x);
4619 j.set_parent(j.m_value.array->back());
4621 j.assert_invariant();
4624 template<
typename BasicJsonType,
typename T,
4625 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4626 static void construct(BasicJsonType& j,
const std::valarray<T>& arr)
4628 j.m_type = value_t::array;
4629 j.m_value = value_t::array;
4630 j.m_value.array->resize(arr.size());
4633 std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin());
4636 j.assert_invariant();
4641 struct external_constructor<value_t::object>
4643 template<
typename BasicJsonType>
4644 static void construct(BasicJsonType& j,
const typename BasicJsonType::object_t& obj)
4646 j.m_type = value_t::object;
4649 j.assert_invariant();
4652 template<
typename BasicJsonType>
4653 static void construct(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4655 j.m_type = value_t::object;
4656 j.m_value = std::move(obj);
4658 j.assert_invariant();
4661 template <
typename BasicJsonType,
typename CompatibleObjectType,
4662 enable_if_t < !std::is_same<CompatibleObjectType, typename BasicJsonType::object_t>::value,
int > = 0 >
4663 static void construct(BasicJsonType& j,
const CompatibleObjectType& obj)
4668 j.m_type = value_t::object;
4669 j.m_value.object = j.template create<typename BasicJsonType::object_t>(begin(obj), end(obj));
4671 j.assert_invariant();
4679 template<
typename BasicJsonType,
typename T,
4680 enable_if_t<std::is_same<T, typename BasicJsonType::boolean_t>::value,
int> = 0>
4681 void to_json(BasicJsonType& j, T b) noexcept
4683 external_constructor<value_t::boolean>::construct(j, b);
4686 template<
typename BasicJsonType,
typename CompatibleString,
4687 enable_if_t<std::is_constructible<typename BasicJsonType::string_t, CompatibleString>::value,
int> = 0>
4688 void to_json(BasicJsonType& j,
const CompatibleString& s)
4690 external_constructor<value_t::string>::construct(j, s);
4693 template<
typename BasicJsonType>
4694 void to_json(BasicJsonType& j,
typename BasicJsonType::string_t&& s)
4696 external_constructor<value_t::string>::construct(j, std::move(s));
4699 template<
typename BasicJsonType,
typename FloatType,
4700 enable_if_t<std::is_floating_point<FloatType>::value,
int> = 0>
4701 void to_json(BasicJsonType& j, FloatType val) noexcept
4703 external_constructor<value_t::number_float>::construct(j,
static_cast<typename BasicJsonType::number_float_t
>(val));
4706 template<
typename BasicJsonType,
typename CompatibleNumberUnsignedType,
4707 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_unsigned_t, CompatibleNumberUnsignedType>::value,
int> = 0>
4708 void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept
4710 external_constructor<value_t::number_unsigned>::construct(j,
static_cast<typename BasicJsonType::number_unsigned_t
>(val));
4713 template<
typename BasicJsonType,
typename CompatibleNumberIntegerType,
4714 enable_if_t<is_compatible_integer_type<typename BasicJsonType::number_integer_t, CompatibleNumberIntegerType>::value,
int> = 0>
4715 void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept
4717 external_constructor<value_t::number_integer>::construct(j,
static_cast<typename BasicJsonType::number_integer_t
>(val));
4720 template<
typename BasicJsonType,
typename EnumType,
4721 enable_if_t<std::is_enum<EnumType>::value,
int> = 0>
4722 void to_json(BasicJsonType& j, EnumType e) noexcept
4724 using underlying_type =
typename std::underlying_type<EnumType>::type;
4725 external_constructor<value_t::number_integer>::construct(j,
static_cast<underlying_type
>(e));
4728 template<
typename BasicJsonType>
4729 void to_json(BasicJsonType& j,
const std::vector<bool>& e)
4731 external_constructor<value_t::array>::construct(j, e);
4734 template <
typename BasicJsonType,
typename CompatibleArrayType,
4735 enable_if_t < is_compatible_array_type<BasicJsonType,
4736 CompatibleArrayType>::value&&
4737 !is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
4738 !is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
4739 !std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
4740 !is_basic_json<CompatibleArrayType>::value,
4742 void to_json(BasicJsonType& j,
const CompatibleArrayType& arr)
4744 external_constructor<value_t::array>::construct(j, arr);
4747 template<
typename BasicJsonType>
4748 void to_json(BasicJsonType& j,
const typename BasicJsonType::binary_t& bin)
4750 external_constructor<value_t::binary>::construct(j, bin);
4753 template<
typename BasicJsonType,
typename T,
4754 enable_if_t<std::is_convertible<T, BasicJsonType>::value,
int> = 0>
4755 void to_json(BasicJsonType& j,
const std::valarray<T>& arr)
4757 external_constructor<value_t::array>::construct(j, std::move(arr));
4760 template<
typename BasicJsonType>
4761 void to_json(BasicJsonType& j,
typename BasicJsonType::array_t&& arr)
4763 external_constructor<value_t::array>::construct(j, std::move(arr));
4766 template <
typename BasicJsonType,
typename CompatibleObjectType,
4767 enable_if_t < is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value&& !is_basic_json<CompatibleObjectType>::value,
int > = 0 >
4768 void to_json(BasicJsonType& j,
const CompatibleObjectType& obj)
4770 external_constructor<value_t::object>::construct(j, obj);
4773 template<
typename BasicJsonType>
4774 void to_json(BasicJsonType& j,
typename BasicJsonType::object_t&& obj)
4776 external_constructor<value_t::object>::construct(j, std::move(obj));
4780 typename BasicJsonType,
typename T, std::size_t N,
4781 enable_if_t < !std::is_constructible<
typename BasicJsonType::string_t,
4782 const T(&)[N]>::value,
4784 void to_json(BasicJsonType& j,
const T(&arr)[N])
4786 external_constructor<value_t::array>::construct(j, arr);
4789 template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible<BasicJsonType, T1>::value&& std::is_constructible<BasicJsonType, T2>::value,
int > = 0 >
4790 void to_json(BasicJsonType& j,
const std::pair<T1, T2>& p)
4792 j = { p.first, p.second };
4796 template<
typename BasicJsonType,
typename T,
4797 enable_if_t<std::is_same<T, iteration_proxy_value<typename BasicJsonType::iterator>>::value,
int> = 0>
4798 void to_json(BasicJsonType& j,
const T& b)
4800 j = { {b.key(), b.value()} };
4803 template<
typename BasicJsonType,
typename Tuple, std::size_t... Idx>
4804 void to_json_tuple_impl(BasicJsonType& j,
const Tuple& t, index_sequence<Idx...> )
4806 j = { std::get<Idx>(t)... };
4809 template<typename BasicJsonType, typename T, enable_if_t<is_constructible_tuple<BasicJsonType, T>::value,
int > = 0>
4810 void to_json(BasicJsonType& j,
const T& t)
4812 to_json_tuple_impl(j, t, make_index_sequence<std::tuple_size<T>::value> {});
4817 template<
typename BasicJsonType,
typename T>
4818 auto operator()(BasicJsonType& j, T&& val)
const noexcept(noexcept(
to_json(j, std::forward<T>(val))))
4819 -> decltype(
to_json(j, std::forward<T>(val)),
void())
4821 return to_json(j, std::forward<T>(val));
4831 constexpr
const auto&
to_json = detail::static_const<detail::to_json_fn>::value;
4843 template<
typename ValueType,
typename>
4857 template<
typename BasicJsonType,
typename TargetType = ValueType>
4858 static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
4859 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
4860 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val),
void())
4862 ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
4877 template<
typename BasicJsonType,
typename TargetType = ValueType>
4879 noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
4880 -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
4882 return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
4894 template<
typename BasicJsonType,
typename TargetType = ValueType>
4895 static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
4896 noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
4897 -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)),
void())
4899 ::nlohmann::to_json(j, std::forward<TargetType>(val));
4927 template<
typename BinaryType>
4948 , m_subtype(subtype_)
4949 , m_has_subtype(true)
4954 , m_subtype(subtype_)
4955 , m_has_subtype(true)
4960 return std::tie(
static_cast<const BinaryType&
>(*
this), m_subtype, m_has_subtype) ==
4961 std::tie(
static_cast<const BinaryType&
>(rhs), rhs.m_subtype, rhs.m_has_subtype);
4966 return !(rhs == *
this);
4989 m_subtype = subtype_;
4990 m_has_subtype =
true;
5037 return m_has_subtype;
5062 m_has_subtype =
false;
5066 std::uint8_t m_subtype = 0;
5067 bool m_has_subtype =
false;
5083 #include <functional>
5094 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
5096 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
5111 template<
typename BasicJsonType>
5112 std::size_t hash(
const BasicJsonType& j)
5114 using string_t =
typename BasicJsonType::string_t;
5115 using number_integer_t =
typename BasicJsonType::number_integer_t;
5116 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
5117 using number_float_t =
typename BasicJsonType::number_float_t;
5119 const auto type =
static_cast<std::size_t
>(j.type());
5122 case BasicJsonType::value_t::null:
5123 case BasicJsonType::value_t::discarded:
5125 return combine(type, 0);
5128 case BasicJsonType::value_t::object:
5130 auto seed = combine(type, j.size());
5131 for (
const auto& element : j.items())
5133 const auto h = std::hash<string_t> {}(element.key());
5134 seed = combine(seed, h);
5135 seed = combine(seed, hash(element.value()));
5140 case BasicJsonType::value_t::array:
5142 auto seed = combine(type, j.size());
5143 for (
const auto& element : j)
5145 seed = combine(seed, hash(element));
5150 case BasicJsonType::value_t::string:
5152 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
5153 return combine(type, h);
5156 case BasicJsonType::value_t::boolean:
5158 const auto h = std::hash<bool> {}(j.template get<bool>());
5159 return combine(type, h);
5162 case BasicJsonType::value_t::number_integer:
5164 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
5165 return combine(type, h);
5168 case BasicJsonType::value_t::number_unsigned:
5170 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
5171 return combine(type, h);
5174 case BasicJsonType::value_t::number_float:
5176 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
5177 return combine(type, h);
5180 case BasicJsonType::value_t::binary:
5182 auto seed = combine(type, j.get_binary().size());
5183 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
5184 seed = combine(seed, h);
5185 seed = combine(seed, j.get_binary().subtype());
5186 for (
const auto byte : j.get_binary())
5188 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
5205 #include <algorithm>
5232 #include <type_traits>
5245 enum class input_format_t {
json, cbor, msgpack, ubjson, bson };
5255 class file_input_adapter
5258 using char_type = char;
5260 JSON_HEDLEY_NON_NULL(2)
5261 explicit file_input_adapter(std::FILE* f) noexcept
5266 file_input_adapter(
const file_input_adapter&) =
delete;
5267 file_input_adapter(file_input_adapter&&) noexcept = default;
5268 file_input_adapter& operator=(const file_input_adapter&) = delete;
5269 file_input_adapter& operator=(file_input_adapter&&) = delete;
5270 ~file_input_adapter() = default;
5272 std::char_traits<
char>::int_type get_character() noexcept
5274 return std::fgetc(m_file);
5292 class input_stream_adapter
5295 using char_type = char;
5297 ~input_stream_adapter()
5303 is->clear(is->rdstate() & std::ios::eofbit);
5307 explicit input_stream_adapter(std::istream& i)
5308 : is(&i), sb(i.rdbuf())
5312 input_stream_adapter(
const input_stream_adapter&) =
delete;
5313 input_stream_adapter& operator=(input_stream_adapter&) =
delete;
5314 input_stream_adapter& operator=(input_stream_adapter&&) =
delete;
5316 input_stream_adapter(input_stream_adapter&& rhs) noexcept
5317 : is(rhs.is), sb(rhs.sb)
5326 std::char_traits<char>::int_type get_character()
5328 auto res = sb->sbumpc();
5330 if (JSON_HEDLEY_UNLIKELY(res == EOF))
5332 is->clear(is->rdstate() | std::ios::eofbit);
5339 std::istream* is =
nullptr;
5340 std::streambuf* sb =
nullptr;
5345 template<
typename IteratorType>
5346 class iterator_input_adapter
5349 using char_type =
typename std::iterator_traits<IteratorType>::value_type;
5351 iterator_input_adapter(IteratorType first, IteratorType last)
5352 : current(std::move(first)), end(std::move(last))
5355 typename std::char_traits<char_type>::int_type get_character()
5357 if (JSON_HEDLEY_LIKELY(current != end))
5359 auto result = std::char_traits<char_type>::to_int_type(*current);
5360 std::advance(current, 1);
5364 return std::char_traits<char_type>::eof();
5368 IteratorType current;
5371 template<
typename BaseInputAdapter,
size_t T>
5372 friend struct wide_string_input_helper;
5376 return current == end;
5381 template<
typename BaseInputAdapter,
size_t T>
5382 struct wide_string_input_helper;
5384 template<
typename BaseInputAdapter>
5385 struct wide_string_input_helper<BaseInputAdapter, 4>
5388 static void fill_buffer(BaseInputAdapter& input,
5389 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5390 size_t& utf8_bytes_index,
5391 size_t& utf8_bytes_filled)
5393 utf8_bytes_index = 0;
5395 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5397 utf8_bytes[0] = std::char_traits<char>::eof();
5398 utf8_bytes_filled = 1;
5403 const auto wc = input.get_character();
5408 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5409 utf8_bytes_filled = 1;
5411 else if (wc <= 0x7FF)
5413 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x1Fu));
5414 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5415 utf8_bytes_filled = 2;
5417 else if (wc <= 0xFFFF)
5419 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x0Fu));
5420 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5421 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5422 utf8_bytes_filled = 3;
5424 else if (wc <= 0x10FFFF)
5426 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | ((
static_cast<unsigned int>(wc) >> 18u) & 0x07u));
5427 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 12u) & 0x3Fu));
5428 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5429 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5430 utf8_bytes_filled = 4;
5435 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5436 utf8_bytes_filled = 1;
5442 template<
typename BaseInputAdapter>
5443 struct wide_string_input_helper<BaseInputAdapter, 2>
5446 static void fill_buffer(BaseInputAdapter& input,
5447 std::array<std::char_traits<char>::int_type, 4>& utf8_bytes,
5448 size_t& utf8_bytes_index,
5449 size_t& utf8_bytes_filled)
5451 utf8_bytes_index = 0;
5453 if (JSON_HEDLEY_UNLIKELY(input.empty()))
5455 utf8_bytes[0] = std::char_traits<char>::eof();
5456 utf8_bytes_filled = 1;
5461 const auto wc = input.get_character();
5466 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5467 utf8_bytes_filled = 1;
5469 else if (wc <= 0x7FF)
5471 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xC0u | ((
static_cast<unsigned int>(wc) >> 6u)));
5472 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5473 utf8_bytes_filled = 2;
5475 else if (0xD800 > wc || wc >= 0xE000)
5477 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xE0u | ((
static_cast<unsigned int>(wc) >> 12u)));
5478 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((
static_cast<unsigned int>(wc) >> 6u) & 0x3Fu));
5479 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (
static_cast<unsigned int>(wc) & 0x3Fu));
5480 utf8_bytes_filled = 3;
5484 if (JSON_HEDLEY_UNLIKELY(!input.empty()))
5486 const auto wc2 =
static_cast<unsigned int>(input.get_character());
5487 const auto charcode = 0x10000u + (((
static_cast<unsigned int>(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu));
5488 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(0xF0u | (charcode >> 18u));
5489 utf8_bytes[1] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 12u) & 0x3Fu));
5490 utf8_bytes[2] =
static_cast<std::char_traits<char>::int_type
>(0x80u | ((charcode >> 6u) & 0x3Fu));
5491 utf8_bytes[3] =
static_cast<std::char_traits<char>::int_type
>(0x80u | (charcode & 0x3Fu));
5492 utf8_bytes_filled = 4;
5496 utf8_bytes[0] =
static_cast<std::char_traits<char>::int_type
>(wc);
5497 utf8_bytes_filled = 1;
5505 template<
typename BaseInputAdapter,
typename W
ideCharType>
5506 class wide_string_input_adapter
5509 using char_type = char;
5511 wide_string_input_adapter(BaseInputAdapter base)
5512 : base_adapter(base) {}
5514 typename std::char_traits<char>::int_type get_character() noexcept
5517 if (utf8_bytes_index == utf8_bytes_filled)
5519 fill_buffer<sizeof(WideCharType)>();
5521 JSON_ASSERT(utf8_bytes_filled > 0);
5522 JSON_ASSERT(utf8_bytes_index == 0);
5526 JSON_ASSERT(utf8_bytes_filled > 0);
5527 JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled);
5528 return utf8_bytes[utf8_bytes_index++];
5532 BaseInputAdapter base_adapter;
5537 wide_string_input_helper<BaseInputAdapter, T>::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled);
5541 std::array<std::char_traits<char>::int_type, 4> utf8_bytes = {{0, 0, 0, 0}};
5544 std::size_t utf8_bytes_index = 0;
5546 std::size_t utf8_bytes_filled = 0;
5550 template<
typename IteratorType,
typename Enable =
void>
5551 struct iterator_input_adapter_factory
5553 using iterator_type = IteratorType;
5554 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5555 using adapter_type = iterator_input_adapter<iterator_type>;
5557 static adapter_type create(IteratorType first, IteratorType last)
5559 return adapter_type(std::move(first), std::move(last));
5563 template<
typename T>
5564 struct is_iterator_of_multibyte
5566 using value_type =
typename std::iterator_traits<T>::value_type;
5569 value =
sizeof(value_type) > 1
5573 template<
typename IteratorType>
5574 struct iterator_input_adapter_factory<IteratorType, enable_if_t<is_iterator_of_multibyte<IteratorType>::value>>
5576 using iterator_type = IteratorType;
5577 using char_type =
typename std::iterator_traits<iterator_type>::value_type;
5578 using base_adapter_type = iterator_input_adapter<iterator_type>;
5579 using adapter_type = wide_string_input_adapter<base_adapter_type, char_type>;
5581 static adapter_type create(IteratorType first, IteratorType last)
5583 return adapter_type(base_adapter_type(std::move(first), std::move(last)));
5588 template<
typename IteratorType>
5589 typename iterator_input_adapter_factory<IteratorType>::adapter_type input_adapter(IteratorType first, IteratorType last)
5591 using factory_type = iterator_input_adapter_factory<IteratorType>;
5592 return factory_type::create(first, last);
5599 namespace container_input_adapter_factory_impl
5605 template<
typename ContainerType,
typename Enable =
void>
5606 struct container_input_adapter_factory {};
5608 template<
typename ContainerType>
5609 struct container_input_adapter_factory< ContainerType,
5610 void_t<decltype(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>()))>>
5612 using adapter_type = decltype(input_adapter(begin(std::declval<ContainerType>()), end(std::declval<ContainerType>())));
5614 static adapter_type create(
const ContainerType& container)
5616 return input_adapter(begin(container), end(container));
5622 template<
typename ContainerType>
5623 typename container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::adapter_type input_adapter(
const ContainerType& container)
5625 return container_input_adapter_factory_impl::container_input_adapter_factory<ContainerType>::create(container);
5629 inline file_input_adapter input_adapter(std::FILE* file)
5631 return file_input_adapter(file);
5634 inline input_stream_adapter input_adapter(std::istream& stream)
5636 return input_stream_adapter(stream);
5639 inline input_stream_adapter input_adapter(std::istream&& stream)
5641 return input_stream_adapter(stream);
5644 using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval<const char*>(), std::declval<const char*>()));
5647 template <
typename CharT,
5648 typename std::enable_if <
5649 std::is_pointer<CharT>::value&&
5650 !std::is_array<CharT>::value&&
5651 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5652 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5654 contiguous_bytes_input_adapter input_adapter(CharT b)
5656 auto length = std::strlen(
reinterpret_cast<const char*
>(b));
5657 const auto* ptr =
reinterpret_cast<const char*
>(b);
5658 return input_adapter(ptr, ptr + length);
5661 template<
typename T, std::
size_t N>
5662 auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N))
5664 return input_adapter(array, array + N);
5670 class span_input_adapter
5673 template <
typename CharT,
5674 typename std::enable_if <
5675 std::is_pointer<CharT>::value&&
5676 std::is_integral<typename std::remove_pointer<CharT>::type>::value&&
5677 sizeof(
typename std::remove_pointer<CharT>::type) == 1,
5679 span_input_adapter(CharT b, std::size_t l)
5680 : ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
5682 template<
class IteratorType,
5683 typename std::enable_if<
5684 std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
5686 span_input_adapter(IteratorType first, IteratorType last)
5687 : ia(input_adapter(first, last)) {}
5689 contiguous_bytes_input_adapter&& get()
5691 return std::move(ia);
5695 contiguous_bytes_input_adapter ia;
5724 template<
typename BasicJsonType>
5737 virtual bool null() = 0;
5828 const std::string& last_token,
5829 const detail::exception& ex) = 0;
5855 template<
typename BasicJsonType>
5856 class json_sax_dom_parser
5862 using string_t =
typename BasicJsonType::string_t;
5863 using binary_t =
typename BasicJsonType::binary_t;
5870 explicit json_sax_dom_parser(BasicJsonType& r,
const bool allow_exceptions_ =
true)
5871 : root(r), allow_exceptions(allow_exceptions_)
5875 json_sax_dom_parser(
const json_sax_dom_parser&) =
delete;
5876 json_sax_dom_parser(json_sax_dom_parser&&) =
default;
5877 json_sax_dom_parser&
operator=(
const json_sax_dom_parser&) =
delete;
5878 json_sax_dom_parser&
operator=(json_sax_dom_parser&&) =
default;
5879 ~json_sax_dom_parser() =
default;
5883 handle_value(
nullptr);
5919 handle_value(std::move(val));
5925 ref_stack.push_back(handle_value(BasicJsonType::value_t::object));
5927 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5929 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
5938 object_element = &(ref_stack.back()->m_value.object->operator[](val));
5944 ref_stack.back()->set_parents();
5945 ref_stack.pop_back();
5951 ref_stack.push_back(handle_value(BasicJsonType::value_t::array));
5953 if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
5955 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
5963 ref_stack.back()->set_parents();
5964 ref_stack.pop_back();
5968 template<
class Exception>
5969 bool parse_error(std::size_t ,
const std::string& ,
5970 const Exception& ex)
5973 static_cast<void>(ex);
5974 if (allow_exceptions)
5981 constexpr
bool is_errored()
const
5993 template<
typename Value>
5995 BasicJsonType* handle_value(Value&& v)
5997 if (ref_stack.empty())
5999 root = BasicJsonType(std::forward<Value>(v));
6003 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6005 if (ref_stack.back()->is_array())
6007 ref_stack.back()->m_value.array->emplace_back(std::forward<Value>(v));
6008 return &(ref_stack.back()->m_value.array->back());
6011 JSON_ASSERT(ref_stack.back()->is_object());
6012 JSON_ASSERT(object_element);
6013 *object_element = BasicJsonType(std::forward<Value>(v));
6014 return object_element;
6018 BasicJsonType& root;
6020 std::vector<BasicJsonType*> ref_stack {};
6022 BasicJsonType* object_element =
nullptr;
6024 bool errored =
false;
6026 const bool allow_exceptions =
true;
6029 template<
typename BasicJsonType>
6030 class json_sax_dom_callback_parser
6036 using string_t =
typename BasicJsonType::string_t;
6037 using binary_t =
typename BasicJsonType::binary_t;
6038 using parser_callback_t =
typename BasicJsonType::parser_callback_t;
6039 using parse_event_t =
typename BasicJsonType::parse_event_t;
6041 json_sax_dom_callback_parser(BasicJsonType& r,
6042 const parser_callback_t cb,
6043 const bool allow_exceptions_ =
true)
6044 : root(r), callback(cb), allow_exceptions(allow_exceptions_)
6046 keep_stack.push_back(
true);
6050 json_sax_dom_callback_parser(
const json_sax_dom_callback_parser&) =
delete;
6051 json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) =
default;
6052 json_sax_dom_callback_parser&
operator=(
const json_sax_dom_callback_parser&) =
delete;
6053 json_sax_dom_callback_parser&
operator=(json_sax_dom_callback_parser&&) =
default;
6054 ~json_sax_dom_callback_parser() =
default;
6058 handle_value(
nullptr);
6094 handle_value(std::move(val));
6101 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::object_start, discarded);
6102 keep_stack.push_back(keep);
6104 auto val = handle_value(BasicJsonType::value_t::object,
true);
6105 ref_stack.push_back(val.second);
6108 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6110 JSON_THROW(out_of_range::create(408,
"excessive object size: " + std::to_string(len), *ref_stack.back()));
6118 BasicJsonType k = BasicJsonType(val);
6121 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::key, k);
6122 key_keep_stack.push_back(keep);
6125 if (keep && ref_stack.back())
6127 object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded);
6135 if (ref_stack.back())
6137 if (!callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back()))
6140 *ref_stack.back() = discarded;
6144 ref_stack.back()->set_parents();
6148 JSON_ASSERT(!ref_stack.empty());
6149 JSON_ASSERT(!keep_stack.empty());
6150 ref_stack.pop_back();
6151 keep_stack.pop_back();
6153 if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured())
6156 for (
auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it)
6158 if (it->is_discarded())
6160 ref_stack.back()->erase(it);
6171 const bool keep = callback(
static_cast<int>(ref_stack.size()), parse_event_t::array_start, discarded);
6172 keep_stack.push_back(keep);
6174 auto val = handle_value(BasicJsonType::value_t::array,
true);
6175 ref_stack.push_back(val.second);
6178 if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size()))
6180 JSON_THROW(out_of_range::create(408,
"excessive array size: " + std::to_string(len), *ref_stack.back()));
6190 if (ref_stack.back())
6192 keep = callback(
static_cast<int>(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back());
6195 ref_stack.back()->set_parents();
6200 *ref_stack.back() = discarded;
6204 JSON_ASSERT(!ref_stack.empty());
6205 JSON_ASSERT(!keep_stack.empty());
6206 ref_stack.pop_back();
6207 keep_stack.pop_back();
6210 if (!keep && !ref_stack.empty() && ref_stack.back()->is_array())
6212 ref_stack.back()->m_value.array->pop_back();
6218 template<
class Exception>
6219 bool parse_error(std::size_t ,
const std::string& ,
6220 const Exception& ex)
6223 static_cast<void>(ex);
6224 if (allow_exceptions)
6231 constexpr
bool is_errored()
const
6252 template<
typename Value>
6253 std::pair<bool, BasicJsonType*> handle_value(Value&& v,
const bool skip_callback =
false)
6255 JSON_ASSERT(!keep_stack.empty());
6259 if (!keep_stack.back())
6261 return {
false,
nullptr};
6265 auto value = BasicJsonType(std::forward<Value>(v));
6268 const bool keep = skip_callback || callback(
static_cast<int>(ref_stack.size()), parse_event_t::value, value);
6273 return {
false,
nullptr};
6276 if (ref_stack.empty())
6278 root = std::move(value);
6279 return {
true, &root};
6284 if (!ref_stack.back())
6286 return {
false,
nullptr};
6290 JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object());
6293 if (ref_stack.back()->is_array())
6295 ref_stack.back()->m_value.array->emplace_back(std::move(value));
6296 return {
true, &(ref_stack.back()->m_value.array->back())};
6300 JSON_ASSERT(ref_stack.back()->is_object());
6302 JSON_ASSERT(!key_keep_stack.empty());
6303 const bool store_element = key_keep_stack.back();
6304 key_keep_stack.pop_back();
6308 return {
false,
nullptr};
6311 JSON_ASSERT(object_element);
6312 *object_element = std::move(value);
6313 return {
true, object_element};
6317 BasicJsonType& root;
6319 std::vector<BasicJsonType*> ref_stack {};
6321 std::vector<bool> keep_stack {};
6323 std::vector<bool> key_keep_stack {};
6325 BasicJsonType* object_element =
nullptr;
6327 bool errored =
false;
6329 const parser_callback_t callback =
nullptr;
6331 const bool allow_exceptions =
true;
6333 BasicJsonType discarded = BasicJsonType::value_t::discarded;
6336 template<
typename BasicJsonType>
6337 class json_sax_acceptor
6343 using string_t =
typename BasicJsonType::string_t;
6344 using binary_t =
typename BasicJsonType::binary_t;
6406 bool parse_error(std::size_t ,
const std::string& ,
const detail::exception& )
6423 #include <initializer_list>
6443 template<
typename BasicJsonType>
6448 enum class token_type
6472 static const char* token_type_name(
const token_type t) noexcept
6476 case token_type::uninitialized:
6477 return "<uninitialized>";
6478 case token_type::literal_true:
6479 return "true literal";
6480 case token_type::literal_false:
6481 return "false literal";
6482 case token_type::literal_null:
6483 return "null literal";
6484 case token_type::value_string:
6485 return "string literal";
6486 case token_type::value_unsigned:
6487 case token_type::value_integer:
6488 case token_type::value_float:
6489 return "number literal";
6490 case token_type::begin_array:
6492 case token_type::begin_object:
6494 case token_type::end_array:
6496 case token_type::end_object:
6498 case token_type::name_separator:
6500 case token_type::value_separator:
6502 case token_type::parse_error:
6503 return "<parse error>";
6504 case token_type::end_of_input:
6505 return "end of input";
6506 case token_type::literal_or_value:
6507 return "'[', '{', or a literal";
6510 return "unknown token";
6520 template<
typename BasicJsonType,
typename InputAdapterType>
6521 class lexer :
public lexer_base<BasicJsonType>
6523 using number_integer_t =
typename BasicJsonType::number_integer_t;
6524 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
6525 using number_float_t =
typename BasicJsonType::number_float_t;
6526 using string_t =
typename BasicJsonType::string_t;
6527 using char_type =
typename InputAdapterType::char_type;
6528 using char_int_type =
typename std::char_traits<char_type>::int_type;
6531 using token_type =
typename lexer_base<BasicJsonType>::token_type;
6533 explicit lexer(InputAdapterType&& adapter,
bool ignore_comments_ =
false) noexcept
6534 : ia(std::move(adapter))
6535 , ignore_comments(ignore_comments_)
6536 , decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
6540 lexer(
const lexer&) =
delete;
6541 lexer(lexer&&) =
default;
6542 lexer& operator=(lexer&) =
delete;
6543 lexer& operator=(lexer&&) =
default;
6553 static char get_decimal_point() noexcept
6555 const auto* loc = localeconv();
6556 JSON_ASSERT(loc !=
nullptr);
6557 return (loc->decimal_point ==
nullptr) ?
'.' : *(loc->decimal_point);
6582 JSON_ASSERT(current ==
'u');
6585 const auto factors = { 12u, 8u, 4u, 0u };
6586 for (
const auto factor : factors)
6590 if (current >=
'0' && current <=
'9')
6592 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x30u) << factor);
6594 else if (current >=
'A' && current <=
'F')
6596 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x37u) << factor);
6598 else if (current >=
'a' && current <=
'f')
6600 codepoint +=
static_cast<int>((
static_cast<unsigned int>(current) - 0x57u) << factor);
6608 JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF);
6627 bool next_byte_in_range(std::initializer_list<char_int_type> ranges)
6629 JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6);
6632 for (
auto range = ranges.begin(); range != ranges.end(); ++range)
6635 if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range)))
6641 error_message =
"invalid string: ill-formed UTF-8 byte";
6664 token_type scan_string()
6670 JSON_ASSERT(current ==
'\"');
6678 case std::char_traits<char_type>::eof():
6680 error_message =
"invalid string: missing closing quote";
6681 return token_type::parse_error;
6687 return token_type::value_string;
6731 const int codepoint1 = get_codepoint();
6732 int codepoint = codepoint1;
6734 if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1))
6736 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6737 return token_type::parse_error;
6741 if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF)
6744 if (JSON_HEDLEY_LIKELY(get() ==
'\\' && get() ==
'u'))
6746 const int codepoint2 = get_codepoint();
6748 if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1))
6750 error_message =
"invalid string: '\\u' must be followed by 4 hex digits";
6751 return token_type::parse_error;
6755 if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF))
6758 codepoint =
static_cast<int>(
6760 (
static_cast<unsigned int>(codepoint1) << 10u)
6762 +
static_cast<unsigned int>(codepoint2)
6770 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6771 return token_type::parse_error;
6776 error_message =
"invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF";
6777 return token_type::parse_error;
6782 if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF))
6784 error_message =
"invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF";
6785 return token_type::parse_error;
6790 JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF);
6793 if (codepoint < 0x80)
6796 add(
static_cast<char_int_type
>(codepoint));
6798 else if (codepoint <= 0x7FF)
6801 add(
static_cast<char_int_type
>(0xC0u | (
static_cast<unsigned int>(codepoint) >> 6u)));
6802 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6804 else if (codepoint <= 0xFFFF)
6807 add(
static_cast<char_int_type
>(0xE0u | (
static_cast<unsigned int>(codepoint) >> 12u)));
6808 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6809 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6814 add(
static_cast<char_int_type
>(0xF0u | (
static_cast<unsigned int>(codepoint) >> 18u)));
6815 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 12u) & 0x3Fu)));
6816 add(
static_cast<char_int_type
>(0x80u | ((
static_cast<unsigned int>(codepoint) >> 6u) & 0x3Fu)));
6817 add(
static_cast<char_int_type
>(0x80u | (
static_cast<unsigned int>(codepoint) & 0x3Fu)));
6825 error_message =
"invalid string: forbidden character after backslash";
6826 return token_type::parse_error;
6835 error_message =
"invalid string: control character U+0000 (NUL) must be escaped to \\u0000";
6836 return token_type::parse_error;
6841 error_message =
"invalid string: control character U+0001 (SOH) must be escaped to \\u0001";
6842 return token_type::parse_error;
6847 error_message =
"invalid string: control character U+0002 (STX) must be escaped to \\u0002";
6848 return token_type::parse_error;
6853 error_message =
"invalid string: control character U+0003 (ETX) must be escaped to \\u0003";
6854 return token_type::parse_error;
6859 error_message =
"invalid string: control character U+0004 (EOT) must be escaped to \\u0004";
6860 return token_type::parse_error;
6865 error_message =
"invalid string: control character U+0005 (ENQ) must be escaped to \\u0005";
6866 return token_type::parse_error;
6871 error_message =
"invalid string: control character U+0006 (ACK) must be escaped to \\u0006";
6872 return token_type::parse_error;
6877 error_message =
"invalid string: control character U+0007 (BEL) must be escaped to \\u0007";
6878 return token_type::parse_error;
6883 error_message =
"invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b";
6884 return token_type::parse_error;
6889 error_message =
"invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t";
6890 return token_type::parse_error;
6895 error_message =
"invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n";
6896 return token_type::parse_error;
6901 error_message =
"invalid string: control character U+000B (VT) must be escaped to \\u000B";
6902 return token_type::parse_error;
6907 error_message =
"invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f";
6908 return token_type::parse_error;
6913 error_message =
"invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r";
6914 return token_type::parse_error;
6919 error_message =
"invalid string: control character U+000E (SO) must be escaped to \\u000E";
6920 return token_type::parse_error;
6925 error_message =
"invalid string: control character U+000F (SI) must be escaped to \\u000F";
6926 return token_type::parse_error;
6931 error_message =
"invalid string: control character U+0010 (DLE) must be escaped to \\u0010";
6932 return token_type::parse_error;
6937 error_message =
"invalid string: control character U+0011 (DC1) must be escaped to \\u0011";
6938 return token_type::parse_error;
6943 error_message =
"invalid string: control character U+0012 (DC2) must be escaped to \\u0012";
6944 return token_type::parse_error;
6949 error_message =
"invalid string: control character U+0013 (DC3) must be escaped to \\u0013";
6950 return token_type::parse_error;
6955 error_message =
"invalid string: control character U+0014 (DC4) must be escaped to \\u0014";
6956 return token_type::parse_error;
6961 error_message =
"invalid string: control character U+0015 (NAK) must be escaped to \\u0015";
6962 return token_type::parse_error;
6967 error_message =
"invalid string: control character U+0016 (SYN) must be escaped to \\u0016";
6968 return token_type::parse_error;
6973 error_message =
"invalid string: control character U+0017 (ETB) must be escaped to \\u0017";
6974 return token_type::parse_error;
6979 error_message =
"invalid string: control character U+0018 (CAN) must be escaped to \\u0018";
6980 return token_type::parse_error;
6985 error_message =
"invalid string: control character U+0019 (EM) must be escaped to \\u0019";
6986 return token_type::parse_error;
6991 error_message =
"invalid string: control character U+001A (SUB) must be escaped to \\u001A";
6992 return token_type::parse_error;
6997 error_message =
"invalid string: control character U+001B (ESC) must be escaped to \\u001B";
6998 return token_type::parse_error;
7003 error_message =
"invalid string: control character U+001C (FS) must be escaped to \\u001C";
7004 return token_type::parse_error;
7009 error_message =
"invalid string: control character U+001D (GS) must be escaped to \\u001D";
7010 return token_type::parse_error;
7015 error_message =
"invalid string: control character U+001E (RS) must be escaped to \\u001E";
7016 return token_type::parse_error;
7021 error_message =
"invalid string: control character U+001F (US) must be escaped to \\u001F";
7022 return token_type::parse_error;
7157 if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF})))
7159 return token_type::parse_error;
7167 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF}))))
7169 return token_type::parse_error;
7191 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF}))))
7193 return token_type::parse_error;
7201 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF}))))
7203 return token_type::parse_error;
7211 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7213 return token_type::parse_error;
7223 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF}))))
7225 return token_type::parse_error;
7233 if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF}))))
7235 return token_type::parse_error;
7243 error_message =
"invalid string: ill-formed UTF-8 byte";
7244 return token_type::parse_error;
7267 case std::char_traits<char_type>::eof():
7284 case std::char_traits<char_type>::eof():
7287 error_message =
"invalid comment; missing closing '*/'";
7315 error_message =
"invalid comment; expecting '/' or '*' after '/'";
7321 JSON_HEDLEY_NON_NULL(2)
7322 static
void strtof(
float& f, const
char* str,
char** endptr) noexcept
7324 f = std::strtof(str, endptr);
7327 JSON_HEDLEY_NON_NULL(2)
7328 static
void strtof(
double& f, const
char* str,
char** endptr) noexcept
7330 f = std::strtod(str, endptr);
7333 JSON_HEDLEY_NON_NULL(2)
7334 static
void strtof(
long double& f, const
char* str,
char** endptr) noexcept
7336 f = std::strtold(str, endptr);
7379 token_type scan_number()
7386 token_type number_type = token_type::value_unsigned;
7394 goto scan_number_minus;
7400 goto scan_number_zero;
7414 goto scan_number_any1;
7424 number_type = token_type::value_integer;
7430 goto scan_number_zero;
7444 goto scan_number_any1;
7449 error_message =
"invalid number; expected digit after '-'";
7450 return token_type::parse_error;
7460 add(decimal_point_char);
7461 goto scan_number_decimal1;
7468 goto scan_number_exponent;
7472 goto scan_number_done;
7491 goto scan_number_any1;
7496 add(decimal_point_char);
7497 goto scan_number_decimal1;
7504 goto scan_number_exponent;
7508 goto scan_number_done;
7511 scan_number_decimal1:
7513 number_type = token_type::value_float;
7528 goto scan_number_decimal2;
7533 error_message =
"invalid number; expected digit after '.'";
7534 return token_type::parse_error;
7538 scan_number_decimal2:
7554 goto scan_number_decimal2;
7561 goto scan_number_exponent;
7565 goto scan_number_done;
7568 scan_number_exponent:
7570 number_type = token_type::value_float;
7577 goto scan_number_sign;
7592 goto scan_number_any2;
7598 "invalid number; expected '+', '-', or digit after exponent";
7599 return token_type::parse_error;
7619 goto scan_number_any2;
7624 error_message =
"invalid number; expected digit after exponent sign";
7625 return token_type::parse_error;
7645 goto scan_number_any2;
7649 goto scan_number_done;
7657 char* endptr =
nullptr;
7661 if (number_type == token_type::value_unsigned)
7663 const auto x = std::strtoull(token_buffer.data(), &endptr, 10);
7666 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7670 value_unsigned =
static_cast<number_unsigned_t
>(x);
7671 if (value_unsigned == x)
7673 return token_type::value_unsigned;
7677 else if (number_type == token_type::value_integer)
7679 const auto x = std::strtoll(token_buffer.data(), &endptr, 10);
7682 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7686 value_integer =
static_cast<number_integer_t
>(x);
7687 if (value_integer == x)
7689 return token_type::value_integer;
7696 strtof(value_float, token_buffer.data(), &endptr);
7699 JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size());
7701 return token_type::value_float;
7709 JSON_HEDLEY_NON_NULL(2)
7710 token_type scan_literal(const char_type* literal_text, const std::
size_t length,
7711 token_type return_type)
7713 JSON_ASSERT(std::char_traits<char_type>::to_char_type(current) == literal_text[0]);
7714 for (std::size_t i = 1; i < length; ++i)
7716 if (JSON_HEDLEY_UNLIKELY(std::char_traits<char_type>::to_char_type(get()) != literal_text[i]))
7718 error_message =
"invalid literal";
7719 return token_type::parse_error;
7730 void reset() noexcept
7732 token_buffer.clear();
7733 token_string.clear();
7734 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7749 ++position.chars_read_total;
7750 ++position.chars_read_current_line;
7759 current = ia.get_character();
7762 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7764 token_string.push_back(std::char_traits<char_type>::to_char_type(current));
7767 if (current ==
'\n')
7769 ++position.lines_read;
7770 position.chars_read_current_line = 0;
7788 --position.chars_read_total;
7791 if (position.chars_read_current_line == 0)
7793 if (position.lines_read > 0)
7795 --position.lines_read;
7800 --position.chars_read_current_line;
7803 if (JSON_HEDLEY_LIKELY(current != std::char_traits<char_type>::eof()))
7805 JSON_ASSERT(!token_string.empty());
7806 token_string.pop_back();
7811 void add(char_int_type c)
7813 token_buffer.push_back(
static_cast<typename string_t::value_type
>(c));
7822 constexpr number_integer_t get_number_integer() const noexcept
7824 return value_integer;
7828 constexpr number_unsigned_t get_number_unsigned() const noexcept
7830 return value_unsigned;
7834 constexpr number_float_t get_number_float() const noexcept
7840 string_t& get_string()
7842 return token_buffer;
7850 constexpr position_t get_position() const noexcept
7858 std::string get_token_string()
const
7862 for (
const auto c : token_string)
7864 if (
static_cast<unsigned char>(c) <=
'\x1F')
7867 std::array<char, 9> cs{{}};
7868 (std::snprintf)(cs.data(), cs.size(),
"<U+%.4X>",
static_cast<unsigned char>(c));
7869 result += cs.data();
7874 result.push_back(
static_cast<std::string::value_type
>(c));
7883 constexpr
const char* get_error_message() const noexcept
7885 return error_message;
7901 return get() == 0xBB && get() == 0xBF;
7910 void skip_whitespace()
7916 while (current ==
' ' || current ==
'\t' || current ==
'\n' || current ==
'\r');
7922 if (position.chars_read_total == 0 && !skip_bom())
7924 error_message =
"invalid BOM; must be 0xEF 0xBB 0xBF if given";
7925 return token_type::parse_error;
7932 while (ignore_comments && current ==
'/')
7934 if (!scan_comment())
7936 return token_type::parse_error;
7947 return token_type::begin_array;
7949 return token_type::end_array;
7951 return token_type::begin_object;
7953 return token_type::end_object;
7955 return token_type::name_separator;
7957 return token_type::value_separator;
7962 std::array<char_type, 4> true_literal = {{char_type(
't'), char_type(
'r'), char_type(
'u'), char_type(
'e')}};
7963 return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true);
7967 std::array<char_type, 5> false_literal = {{char_type(
'f'), char_type(
'a'), char_type(
'l'), char_type(
's'), char_type(
'e')}};
7968 return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false);
7972 std::array<char_type, 4> null_literal = {{char_type(
'n'), char_type(
'u'), char_type(
'l'), char_type(
'l')}};
7973 return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null);
7978 return scan_string();
7992 return scan_number();
7997 case std::char_traits<char_type>::eof():
7998 return token_type::end_of_input;
8002 error_message =
"invalid literal";
8003 return token_type::parse_error;
8009 InputAdapterType ia;
8012 const bool ignore_comments =
false;
8015 char_int_type current = std::char_traits<char_type>::eof();
8018 bool next_unget =
false;
8021 position_t position {};
8024 std::vector<char_type> token_string {};
8027 string_t token_buffer {};
8030 const char* error_message =
"";
8033 number_integer_t value_integer = 0;
8034 number_unsigned_t value_unsigned = 0;
8035 number_float_t value_float = 0;
8038 const char_int_type decimal_point_char =
'.';
8061 template<
typename T>
8062 using null_function_t = decltype(std::declval<T&>().
null());
8064 template<
typename T>
8065 using boolean_function_t =
8066 decltype(std::declval<T&>().
boolean(std::declval<bool>()));
8068 template<
typename T,
typename Integer>
8069 using number_integer_function_t =
8070 decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
8072 template<
typename T,
typename Un
signed>
8073 using number_unsigned_function_t =
8074 decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
8076 template<
typename T,
typename Float,
typename String>
8077 using number_float_function_t = decltype(std::declval<T&>().number_float(
8078 std::declval<Float>(), std::declval<const String&>()));
8080 template<
typename T,
typename String>
8081 using string_function_t =
8082 decltype(std::declval<T&>().
string(std::declval<String&>()));
8084 template<
typename T,
typename Binary>
8085 using binary_function_t =
8086 decltype(std::declval<T&>().binary(std::declval<Binary&>()));
8088 template<
typename T>
8089 using start_object_function_t =
8090 decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
8092 template<
typename T,
typename String>
8093 using key_function_t =
8094 decltype(std::declval<T&>().key(std::declval<String&>()));
8096 template<
typename T>
8097 using end_object_function_t = decltype(std::declval<T&>().end_object());
8099 template<
typename T>
8100 using start_array_function_t =
8101 decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
8103 template<
typename T>
8104 using end_array_function_t = decltype(std::declval<T&>().end_array());
8106 template<
typename T,
typename Exception>
8107 using parse_error_function_t = decltype(std::declval<T&>().parse_error(
8108 std::declval<std::size_t>(), std::declval<const std::string&>(),
8109 std::declval<const Exception&>()));
8111 template<
typename SAX,
typename BasicJsonType>
8115 static_assert(is_basic_json<BasicJsonType>::value,
8116 "BasicJsonType must be of type basic_json<...>");
8118 using number_integer_t =
typename BasicJsonType::number_integer_t;
8119 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8120 using number_float_t =
typename BasicJsonType::number_float_t;
8121 using string_t =
typename BasicJsonType::string_t;
8122 using binary_t =
typename BasicJsonType::binary_t;
8123 using exception_t =
typename BasicJsonType::exception;
8126 static constexpr
bool value =
8127 is_detected_exact<bool, null_function_t, SAX>::value &&
8128 is_detected_exact<bool, boolean_function_t, SAX>::value &&
8129 is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value &&
8130 is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value &&
8131 is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value &&
8132 is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
8133 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value &&
8134 is_detected_exact<bool, start_object_function_t, SAX>::value &&
8135 is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
8136 is_detected_exact<bool, end_object_function_t, SAX>::value &&
8137 is_detected_exact<bool, start_array_function_t, SAX>::value &&
8138 is_detected_exact<bool, end_array_function_t, SAX>::value &&
8139 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
8142 template<
typename SAX,
typename BasicJsonType>
8143 struct is_sax_static_asserts
8146 static_assert(is_basic_json<BasicJsonType>::value,
8147 "BasicJsonType must be of type basic_json<...>");
8149 using number_integer_t =
typename BasicJsonType::number_integer_t;
8150 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8151 using number_float_t =
typename BasicJsonType::number_float_t;
8152 using string_t =
typename BasicJsonType::string_t;
8153 using binary_t =
typename BasicJsonType::binary_t;
8154 using exception_t =
typename BasicJsonType::exception;
8157 static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
8158 "Missing/invalid function: bool null()");
8159 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8160 "Missing/invalid function: bool boolean(bool)");
8161 static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
8162 "Missing/invalid function: bool boolean(bool)");
8164 is_detected_exact<
bool, number_integer_function_t, SAX,
8165 number_integer_t>::value,
8166 "Missing/invalid function: bool number_integer(number_integer_t)");
8168 is_detected_exact<
bool, number_unsigned_function_t, SAX,
8169 number_unsigned_t>::value,
8170 "Missing/invalid function: bool number_unsigned(number_unsigned_t)");
8171 static_assert(is_detected_exact<
bool, number_float_function_t, SAX,
8172 number_float_t, string_t>::value,
8173 "Missing/invalid function: bool number_float(number_float_t, const string_t&)");
8175 is_detected_exact<bool, string_function_t, SAX, string_t>::value,
8176 "Missing/invalid function: bool string(string_t&)");
8178 is_detected_exact<bool, binary_function_t, SAX, binary_t>::value,
8179 "Missing/invalid function: bool binary(binary_t&)");
8180 static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
8181 "Missing/invalid function: bool start_object(std::size_t)");
8182 static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
8183 "Missing/invalid function: bool key(string_t&)");
8184 static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
8185 "Missing/invalid function: bool end_object()");
8186 static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
8187 "Missing/invalid function: bool start_array(std::size_t)");
8188 static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
8189 "Missing/invalid function: bool end_array()");
8191 is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
8192 "Missing/invalid function: bool parse_error(std::size_t, const "
8193 "std::string&, const exception&)");
8207 enum class cbor_tag_handler_t
8220 static inline bool little_endianess(
int num = 1) noexcept
8222 return *
reinterpret_cast<char*
>(&num) == 1;
8233 template<
typename BasicJsonType,
typename InputAdapterType,
typename SAX = json_sax_dom_parser<BasicJsonType>>
8236 using number_integer_t =
typename BasicJsonType::number_integer_t;
8237 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
8238 using number_float_t =
typename BasicJsonType::number_float_t;
8239 using string_t =
typename BasicJsonType::string_t;
8240 using binary_t =
typename BasicJsonType::binary_t;
8241 using json_sax_t = SAX;
8242 using char_type =
typename InputAdapterType::char_type;
8243 using char_int_type =
typename std::char_traits<char_type>::int_type;
8251 explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter))
8253 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
8257 binary_reader(
const binary_reader&) =
delete;
8258 binary_reader(binary_reader&&) =
default;
8259 binary_reader& operator=(
const binary_reader&) =
delete;
8260 binary_reader& operator=(binary_reader&&) =
default;
8261 ~binary_reader() =
default;
8271 JSON_HEDLEY_NON_NULL(3)
8272 bool sax_parse(const input_format_t format,
8274 const
bool strict = true,
8275 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
8278 bool result =
false;
8282 case input_format_t::bson:
8283 result = parse_bson_internal();
8286 case input_format_t::cbor:
8287 result = parse_cbor_internal(
true, tag_handler);
8290 case input_format_t::msgpack:
8291 result = parse_msgpack_internal();
8294 case input_format_t::ubjson:
8295 result = parse_ubjson_internal();
8303 if (result && strict)
8305 if (format == input_format_t::ubjson)
8314 if (JSON_HEDLEY_UNLIKELY(current != std::char_traits<char_type>::eof()))
8316 return sax->parse_error(chars_read, get_token_string(),
8317 parse_error::create(110, chars_read, exception_message(format,
"expected end of input; last byte: 0x" + get_token_string(),
"value"), BasicJsonType()));
8333 bool parse_bson_internal()
8335 std::int32_t document_size{};
8336 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8338 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
8343 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
false)))
8348 return sax->end_object();
8358 bool get_bson_cstr(string_t& result)
8360 auto out = std::back_inserter(result);
8364 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"cstring")))
8368 if (current == 0x00)
8372 *out++ =
static_cast<typename string_t::value_type
>(current);
8387 template<
typename NumberType>
8388 bool get_bson_string(
const NumberType len, string_t& result)
8390 if (JSON_HEDLEY_UNLIKELY(len < 1))
8392 auto last_token = get_token_string();
8393 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()));
8396 return get_string(input_format_t::bson, len -
static_cast<NumberType
>(1), result) && get() != std::char_traits<char_type>::eof();
8408 template<
typename NumberType>
8409 bool get_bson_binary(
const NumberType len, binary_t& result)
8411 if (JSON_HEDLEY_UNLIKELY(len < 0))
8413 auto last_token = get_token_string();
8414 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()));
8418 std::uint8_t subtype{};
8419 get_number<std::uint8_t>(input_format_t::bson, subtype);
8420 result.set_subtype(subtype);
8422 return get_binary(input_format_t::bson, len, result);
8435 bool parse_bson_element_internal(
const char_int_type element_type,
8436 const std::size_t element_type_parse_position)
8438 switch (element_type)
8443 return get_number<double, true>(input_format_t::bson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
8450 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value);
8455 return parse_bson_internal();
8460 return parse_bson_array();
8467 return get_number<std::int32_t, true>(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value);
8472 return sax->boolean(get() != 0);
8482 std::int32_t value{};
8483 return get_number<std::int32_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8488 std::int64_t value{};
8489 return get_number<std::int64_t, true>(input_format_t::bson, value) && sax->number_integer(value);
8494 std::array<char, 3> cr{{}};
8495 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(element_type));
8496 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()));
8513 bool parse_bson_element_list(
const bool is_array)
8517 while (
auto element_type = get())
8519 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson,
"element list")))
8524 const std::size_t element_type_parse_position = chars_read;
8525 if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key)))
8530 if (!is_array && !sax->key(key))
8535 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position)))
8551 bool parse_bson_array()
8553 std::int32_t document_size{};
8554 get_number<std::int32_t, true>(input_format_t::bson, document_size);
8556 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
8561 if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(
true)))
8566 return sax->end_array();
8581 bool parse_cbor_internal(
const bool get_char,
8582 const cbor_tag_handler_t tag_handler)
8584 switch (get_char ? get() : current)
8587 case std::char_traits<char_type>::eof():
8588 return unexpect_eof(input_format_t::cbor,
"value");
8615 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
8619 std::uint8_t number{};
8620 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8625 std::uint16_t number{};
8626 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8631 std::uint32_t number{};
8632 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8637 std::uint64_t number{};
8638 return get_number(input_format_t::cbor, number) && sax->number_unsigned(number);
8666 return sax->number_integer(
static_cast<std::int8_t
>(0x20 - 1 - current));
8670 std::uint8_t number{};
8671 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8676 std::uint16_t number{};
8677 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8682 std::uint32_t number{};
8683 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1) - number);
8688 std::uint64_t number{};
8689 return get_number(input_format_t::cbor, number) && sax->number_integer(
static_cast<number_integer_t
>(-1)
8690 -
static_cast<number_integer_t
>(number));
8725 return get_cbor_binary(b) && sax->binary(b);
8760 return get_cbor_string(s) && sax->string(s);
8788 return get_cbor_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8793 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8798 std::uint16_t len{};
8799 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8804 std::uint32_t len{};
8805 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8810 std::uint64_t len{};
8811 return get_number(input_format_t::cbor, len) && get_cbor_array(
static_cast<std::size_t
>(len), tag_handler);
8815 return get_cbor_array(std::size_t(-1), tag_handler);
8842 return get_cbor_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x1Fu), tag_handler);
8847 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8852 std::uint16_t len{};
8853 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8858 std::uint32_t len{};
8859 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8864 std::uint64_t len{};
8865 return get_number(input_format_t::cbor, len) && get_cbor_object(
static_cast<std::size_t
>(len), tag_handler);
8869 return get_cbor_object(std::size_t(-1), tag_handler);
8891 switch (tag_handler)
8893 case cbor_tag_handler_t::error:
8895 auto last_token = get_token_string();
8896 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()));
8899 case cbor_tag_handler_t::ignore:
8906 get_number(input_format_t::cbor, len);
8911 std::uint16_t len{};
8912 get_number(input_format_t::cbor, len);
8917 std::uint32_t len{};
8918 get_number(input_format_t::cbor, len);
8923 std::uint64_t len{};
8924 get_number(input_format_t::cbor, len);
8930 return parse_cbor_internal(
true, tag_handler);
8940 return sax->boolean(
false);
8943 return sax->boolean(
true);
8950 const auto byte1_raw = get();
8951 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8955 const auto byte2_raw = get();
8956 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"number")))
8961 const auto byte1 =
static_cast<unsigned char>(byte1_raw);
8962 const auto byte2 =
static_cast<unsigned char>(byte2_raw);
8972 const auto half =
static_cast<unsigned int>((byte1 << 8u) + byte2);
8973 const double val = [&half]
8975 const int exp = (half >> 10u) & 0x1Fu;
8976 const unsigned int mant = half & 0x3FFu;
8977 JSON_ASSERT(0 <= exp&& exp <= 32);
8978 JSON_ASSERT(mant <= 1024);
8982 return std::ldexp(mant, -24);
8985 ? std::numeric_limits<double>::infinity()
8986 : std::numeric_limits<double>::quiet_NaN();
8988 return std::ldexp(mant + 1024, exp - 25);
8991 return sax->number_float((half & 0x8000u) != 0
8992 ?
static_cast<number_float_t
>(-val)
8993 :
static_cast<number_float_t
>(val),
"");
8999 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9005 return get_number(input_format_t::cbor, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9010 auto last_token = get_token_string();
9011 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()));
9027 bool get_cbor_string(string_t& result)
9029 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"string")))
9062 return get_string(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9068 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9073 std::uint16_t len{};
9074 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9079 std::uint32_t len{};
9080 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9085 std::uint64_t len{};
9086 return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result);
9091 while (get() != 0xFF)
9094 if (!get_cbor_string(chunk))
9098 result.append(chunk);
9105 auto last_token = get_token_string();
9106 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()));
9122 bool get_cbor_binary(binary_t& result)
9124 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor,
"binary")))
9157 return get_binary(input_format_t::cbor,
static_cast<unsigned int>(current) & 0x1Fu, result);
9163 return get_number(input_format_t::cbor, len) &&
9164 get_binary(input_format_t::cbor, len, result);
9169 std::uint16_t len{};
9170 return get_number(input_format_t::cbor, len) &&
9171 get_binary(input_format_t::cbor, len, result);
9176 std::uint32_t len{};
9177 return get_number(input_format_t::cbor, len) &&
9178 get_binary(input_format_t::cbor, len, result);
9183 std::uint64_t len{};
9184 return get_number(input_format_t::cbor, len) &&
9185 get_binary(input_format_t::cbor, len, result);
9190 while (get() != 0xFF)
9193 if (!get_cbor_binary(chunk))
9197 result.insert(result.end(), chunk.begin(), chunk.end());
9204 auto last_token = get_token_string();
9205 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()));
9216 bool get_cbor_array(
const std::size_t len,
9217 const cbor_tag_handler_t tag_handler)
9219 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9224 if (len != std::size_t(-1))
9226 for (std::size_t i = 0; i < len; ++i)
9228 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9236 while (get() != 0xFF)
9238 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
false, tag_handler)))
9245 return sax->end_array();
9254 bool get_cbor_object(
const std::size_t len,
9255 const cbor_tag_handler_t tag_handler)
9257 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9263 if (len != std::size_t(-1))
9265 for (std::size_t i = 0; i < len; ++i)
9268 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9273 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9282 while (get() != 0xFF)
9284 if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key)))
9289 if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(
true, tag_handler)))
9297 return sax->end_object();
9307 bool parse_msgpack_internal()
9312 case std::char_traits<char_type>::eof():
9313 return unexpect_eof(input_format_t::msgpack,
"value");
9444 return sax->number_unsigned(
static_cast<number_unsigned_t
>(current));
9463 return get_msgpack_object(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9482 return get_msgpack_array(
static_cast<std::size_t
>(
static_cast<unsigned int>(current) & 0x0Fu));
9522 return get_msgpack_string(s) && sax->string(s);
9529 return sax->boolean(
false);
9532 return sax->boolean(
true);
9547 return get_msgpack_binary(b) && sax->binary(b);
9553 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9559 return get_number(input_format_t::msgpack, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
9564 std::uint8_t number{};
9565 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9570 std::uint16_t number{};
9571 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9576 std::uint32_t number{};
9577 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9582 std::uint64_t number{};
9583 return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number);
9588 std::int8_t number{};
9589 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9594 std::int16_t number{};
9595 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9600 std::int32_t number{};
9601 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9606 std::int64_t number{};
9607 return get_number(input_format_t::msgpack, number) && sax->number_integer(number);
9612 std::uint16_t len{};
9613 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9618 std::uint32_t len{};
9619 return get_number(input_format_t::msgpack, len) && get_msgpack_array(
static_cast<std::size_t
>(len));
9624 std::uint16_t len{};
9625 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9630 std::uint32_t len{};
9631 return get_number(input_format_t::msgpack, len) && get_msgpack_object(
static_cast<std::size_t
>(len));
9667 return sax->number_integer(
static_cast<std::int8_t
>(current));
9671 auto last_token = get_token_string();
9672 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()));
9687 bool get_msgpack_string(string_t& result)
9689 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack,
"string")))
9730 return get_string(input_format_t::msgpack,
static_cast<unsigned int>(current) & 0x1Fu, result);
9736 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9741 std::uint16_t len{};
9742 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9747 std::uint32_t len{};
9748 return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result);
9753 auto last_token = get_token_string();
9754 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()));
9769 bool get_msgpack_binary(binary_t& result)
9772 auto assign_and_return_true = [&result](std::int8_t subtype)
9774 result.set_subtype(
static_cast<std::uint8_t
>(subtype));
9783 return get_number(input_format_t::msgpack, len) &&
9784 get_binary(input_format_t::msgpack, len, result);
9789 std::uint16_t len{};
9790 return get_number(input_format_t::msgpack, len) &&
9791 get_binary(input_format_t::msgpack, len, result);
9796 std::uint32_t len{};
9797 return get_number(input_format_t::msgpack, len) &&
9798 get_binary(input_format_t::msgpack, len, result);
9804 std::int8_t subtype{};
9805 return get_number(input_format_t::msgpack, len) &&
9806 get_number(input_format_t::msgpack, subtype) &&
9807 get_binary(input_format_t::msgpack, len, result) &&
9808 assign_and_return_true(subtype);
9813 std::uint16_t len{};
9814 std::int8_t subtype{};
9815 return get_number(input_format_t::msgpack, len) &&
9816 get_number(input_format_t::msgpack, subtype) &&
9817 get_binary(input_format_t::msgpack, len, result) &&
9818 assign_and_return_true(subtype);
9823 std::uint32_t len{};
9824 std::int8_t subtype{};
9825 return get_number(input_format_t::msgpack, len) &&
9826 get_number(input_format_t::msgpack, subtype) &&
9827 get_binary(input_format_t::msgpack, len, result) &&
9828 assign_and_return_true(subtype);
9833 std::int8_t subtype{};
9834 return get_number(input_format_t::msgpack, subtype) &&
9835 get_binary(input_format_t::msgpack, 1, result) &&
9836 assign_and_return_true(subtype);
9841 std::int8_t subtype{};
9842 return get_number(input_format_t::msgpack, subtype) &&
9843 get_binary(input_format_t::msgpack, 2, result) &&
9844 assign_and_return_true(subtype);
9849 std::int8_t subtype{};
9850 return get_number(input_format_t::msgpack, subtype) &&
9851 get_binary(input_format_t::msgpack, 4, result) &&
9852 assign_and_return_true(subtype);
9857 std::int8_t subtype{};
9858 return get_number(input_format_t::msgpack, subtype) &&
9859 get_binary(input_format_t::msgpack, 8, result) &&
9860 assign_and_return_true(subtype);
9865 std::int8_t subtype{};
9866 return get_number(input_format_t::msgpack, subtype) &&
9867 get_binary(input_format_t::msgpack, 16, result) &&
9868 assign_and_return_true(subtype);
9880 bool get_msgpack_array(
const std::size_t len)
9882 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len)))
9887 for (std::size_t i = 0; i < len; ++i)
9889 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9895 return sax->end_array();
9902 bool get_msgpack_object(
const std::size_t len)
9904 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len)))
9910 for (std::size_t i = 0; i < len; ++i)
9913 if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key)))
9918 if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal()))
9925 return sax->end_object();
9939 bool parse_ubjson_internal(
const bool get_char =
true)
9941 return get_ubjson_value(get_char ? get_ignore_noop() : current);
9958 bool get_ubjson_string(string_t& result,
const bool get_char =
true)
9965 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
9975 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9981 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9987 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9993 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
9999 return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result);
10003 auto last_token = get_token_string();
10004 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()));
10012 bool get_ubjson_size_value(std::size_t& result)
10014 switch (get_ignore_noop())
10018 std::uint8_t number{};
10019 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10023 result =
static_cast<std::size_t
>(number);
10029 std::int8_t number{};
10030 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10034 result =
static_cast<std::size_t
>(number);
10040 std::int16_t number{};
10041 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10045 result =
static_cast<std::size_t
>(number);
10051 std::int32_t number{};
10052 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10056 result =
static_cast<std::size_t
>(number);
10062 std::int64_t number{};
10063 if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number)))
10067 result =
static_cast<std::size_t
>(number);
10073 auto last_token = get_token_string();
10074 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()));
10089 bool get_ubjson_size_type(std::pair<std::size_t, char_int_type>& result)
10091 result.first = string_t::npos;
10096 if (current ==
'$')
10098 result.second = get();
10099 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"type")))
10105 if (JSON_HEDLEY_UNLIKELY(current !=
'#'))
10107 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"value")))
10111 auto last_token = get_token_string();
10112 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()));
10115 return get_ubjson_size_value(result.first);
10118 if (current ==
'#')
10120 return get_ubjson_size_value(result.first);
10130 bool get_ubjson_value(
const char_int_type prefix)
10134 case std::char_traits<char_type>::eof():
10135 return unexpect_eof(input_format_t::ubjson,
"value");
10138 return sax->boolean(
true);
10140 return sax->boolean(
false);
10143 return sax->null();
10147 std::uint8_t number{};
10148 return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number);
10153 std::int8_t number{};
10154 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10159 std::int16_t number{};
10160 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10165 std::int32_t number{};
10166 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10171 std::int64_t number{};
10172 return get_number(input_format_t::ubjson, number) && sax->number_integer(number);
10178 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10184 return get_number(input_format_t::ubjson, number) && sax->number_float(
static_cast<number_float_t
>(number),
"");
10189 return get_ubjson_high_precision_number();
10195 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"char")))
10199 if (JSON_HEDLEY_UNLIKELY(current > 127))
10201 auto last_token = get_token_string();
10202 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()));
10204 string_t s(1,
static_cast<typename string_t::value_type
>(current));
10205 return sax->string(s);
10211 return get_ubjson_string(s) && sax->string(s);
10215 return get_ubjson_array();
10218 return get_ubjson_object();
10222 auto last_token = get_token_string();
10223 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()));
10231 bool get_ubjson_array()
10233 std::pair<std::size_t, char_int_type> size_and_type;
10234 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10239 if (size_and_type.first != string_t::npos)
10241 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first)))
10246 if (size_and_type.second != 0)
10248 if (size_and_type.second !=
'N')
10250 for (std::size_t i = 0; i < size_and_type.first; ++i)
10252 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10261 for (std::size_t i = 0; i < size_and_type.first; ++i)
10263 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10272 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10277 while (current !=
']')
10279 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(
false)))
10287 return sax->end_array();
10293 bool get_ubjson_object()
10295 std::pair<std::size_t, char_int_type> size_and_type;
10296 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type)))
10302 if (size_and_type.first != string_t::npos)
10304 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first)))
10309 if (size_and_type.second != 0)
10311 for (std::size_t i = 0; i < size_and_type.first; ++i)
10313 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10317 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second)))
10326 for (std::size_t i = 0; i < size_and_type.first; ++i)
10328 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key)))
10332 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10342 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10347 while (current !=
'}')
10349 if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key,
false) || !sax->key(key)))
10353 if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal()))
10362 return sax->end_object();
10368 bool get_ubjson_high_precision_number()
10371 std::size_t size{};
10372 auto res = get_ubjson_size_value(size);
10373 if (JSON_HEDLEY_UNLIKELY(!res))
10379 std::vector<char> number_vector;
10380 for (std::size_t i = 0; i < size; ++i)
10383 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson,
"number")))
10387 number_vector.push_back(
static_cast<char>(current));
10391 using ia_type = decltype(detail::input_adapter(number_vector));
10392 auto number_lexer = detail::lexer<BasicJsonType, ia_type>(detail::input_adapter(number_vector),
false);
10393 const auto result_number = number_lexer.scan();
10394 const auto number_string = number_lexer.get_token_string();
10395 const auto result_remainder = number_lexer.scan();
10397 using token_type =
typename detail::lexer_base<BasicJsonType>::token_type;
10399 if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input))
10401 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()));
10404 switch (result_number)
10406 case token_type::value_integer:
10407 return sax->number_integer(number_lexer.get_number_integer());
10408 case token_type::value_unsigned:
10409 return sax->number_unsigned(number_lexer.get_number_unsigned());
10410 case token_type::value_float:
10411 return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
10413 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()));
10430 char_int_type get()
10433 return current = ia.get_character();
10439 char_int_type get_ignore_noop()
10445 while (current ==
'N');
10463 template<
typename NumberType,
bool InputIsLittleEndian = false>
10464 bool get_number(
const input_format_t format, NumberType& result)
10467 std::array<std::uint8_t,
sizeof(NumberType)> vec{};
10468 for (std::size_t i = 0; i <
sizeof(NumberType); ++i)
10471 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"number")))
10477 if (is_little_endian != InputIsLittleEndian)
10479 vec[
sizeof(NumberType) - i - 1] =
static_cast<std::uint8_t
>(current);
10483 vec[i] =
static_cast<std::uint8_t
>(current);
10488 std::memcpy(&result, vec.data(),
sizeof(NumberType));
10506 template<
typename NumberType>
10507 bool get_string(
const input_format_t format,
10508 const NumberType len,
10511 bool success =
true;
10512 for (NumberType i = 0; i < len; i++)
10515 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"string")))
10520 result.push_back(
static_cast<typename string_t::value_type
>(current));
10539 template<
typename NumberType>
10540 bool get_binary(
const input_format_t format,
10541 const NumberType len,
10544 bool success =
true;
10545 for (NumberType i = 0; i < len; i++)
10548 if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format,
"binary")))
10553 result.push_back(
static_cast<std::uint8_t
>(current));
10563 JSON_HEDLEY_NON_NULL(3)
10564 bool unexpect_eof(const input_format_t format, const
char* context)
const
10566 if (JSON_HEDLEY_UNLIKELY(current == std::char_traits<char_type>::eof()))
10568 return sax->parse_error(chars_read,
"<end of file>",
10569 parse_error::create(110, chars_read, exception_message(format,
"unexpected end of input", context), BasicJsonType()));
10577 std::string get_token_string()
const
10579 std::array<char, 3> cr{{}};
10580 (std::snprintf)(cr.data(), cr.size(),
"%.2hhX",
static_cast<unsigned char>(current));
10581 return std::string{cr.data()};
10590 std::string exception_message(
const input_format_t format,
10591 const std::string& detail,
10592 const std::string& context)
const
10594 std::string error_msg =
"syntax error while parsing ";
10598 case input_format_t::cbor:
10599 error_msg +=
"CBOR";
10602 case input_format_t::msgpack:
10603 error_msg +=
"MessagePack";
10606 case input_format_t::ubjson:
10607 error_msg +=
"UBJSON";
10610 case input_format_t::bson:
10611 error_msg +=
"BSON";
10615 JSON_ASSERT(
false);
10618 return error_msg +
" " + context +
": " + detail;
10623 InputAdapterType ia;
10626 char_int_type current = std::char_traits<char_type>::eof();
10629 std::size_t chars_read = 0;
10632 const bool is_little_endian = little_endianess();
10635 json_sax_t* sax =
nullptr;
10649 #include <functional>
10677 enum class parse_event_t : uint8_t
10693 template<
typename BasicJsonType>
10694 using parser_callback_t =
10695 std::function<bool(
int , parse_event_t , BasicJsonType& )>;
10702 template<
typename BasicJsonType,
typename InputAdapterType>
10705 using number_integer_t =
typename BasicJsonType::number_integer_t;
10706 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
10707 using number_float_t =
typename BasicJsonType::number_float_t;
10708 using string_t =
typename BasicJsonType::string_t;
10709 using lexer_t = lexer<BasicJsonType, InputAdapterType>;
10710 using token_type =
typename lexer_t::token_type;
10714 explicit parser(InputAdapterType&& adapter,
10715 const parser_callback_t<BasicJsonType> cb =
nullptr,
10716 const bool allow_exceptions_ =
true,
10717 const bool skip_comments =
false)
10719 , m_lexer(std::move(adapter), skip_comments)
10720 , allow_exceptions(allow_exceptions_)
10736 void parse(
const bool strict, BasicJsonType& result)
10740 json_sax_dom_callback_parser<BasicJsonType> sdp(result, callback, allow_exceptions);
10741 sax_parse_internal(&sdp);
10744 if (strict && (get_token() != token_type::end_of_input))
10746 sdp.parse_error(m_lexer.get_position(),
10747 m_lexer.get_token_string(),
10748 parse_error::create(101, m_lexer.get_position(),
10749 exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10753 if (sdp.is_errored())
10755 result = value_t::discarded;
10761 if (result.is_discarded())
10768 json_sax_dom_parser<BasicJsonType> sdp(result, allow_exceptions);
10769 sax_parse_internal(&sdp);
10772 if (strict && (get_token() != token_type::end_of_input))
10774 sdp.parse_error(m_lexer.get_position(),
10775 m_lexer.get_token_string(),
10776 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10780 if (sdp.is_errored())
10782 result = value_t::discarded;
10787 result.assert_invariant();
10796 bool accept(
const bool strict =
true)
10798 json_sax_acceptor<BasicJsonType> sax_acceptor;
10799 return sax_parse(&sax_acceptor, strict);
10802 template<
typename SAX>
10803 JSON_HEDLEY_NON_NULL(2)
10804 bool sax_parse(SAX* sax, const
bool strict = true)
10806 (void)detail::is_sax_static_asserts<SAX, BasicJsonType> {};
10807 const bool result = sax_parse_internal(sax);
10810 if (result && strict && (get_token() != token_type::end_of_input))
10812 return sax->parse_error(m_lexer.get_position(),
10813 m_lexer.get_token_string(),
10814 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input,
"value"), BasicJsonType()));
10821 template<
typename SAX>
10822 JSON_HEDLEY_NON_NULL(2)
10823 bool sax_parse_internal(SAX* sax)
10827 std::vector<bool> states;
10829 bool skip_to_state_evaluation =
false;
10833 if (!skip_to_state_evaluation)
10836 switch (last_token)
10838 case token_type::begin_object:
10840 if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1))))
10846 if (get_token() == token_type::end_object)
10848 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
10856 if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string))
10858 return sax->parse_error(m_lexer.get_position(),
10859 m_lexer.get_token_string(),
10860 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
10862 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
10868 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
10870 return sax->parse_error(m_lexer.get_position(),
10871 m_lexer.get_token_string(),
10872 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
10876 states.push_back(
false);
10883 case token_type::begin_array:
10885 if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1))))
10891 if (get_token() == token_type::end_array)
10893 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
10901 states.push_back(
true);
10907 case token_type::value_float:
10909 const auto res = m_lexer.get_number_float();
10911 if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res)))
10913 return sax->parse_error(m_lexer.get_position(),
10914 m_lexer.get_token_string(),
10915 out_of_range::create(406,
"number overflow parsing '" + m_lexer.get_token_string() +
"'", BasicJsonType()));
10918 if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string())))
10926 case token_type::literal_false:
10928 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
false)))
10935 case token_type::literal_null:
10937 if (JSON_HEDLEY_UNLIKELY(!sax->null()))
10944 case token_type::literal_true:
10946 if (JSON_HEDLEY_UNLIKELY(!sax->boolean(
true)))
10953 case token_type::value_integer:
10955 if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer())))
10962 case token_type::value_string:
10964 if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string())))
10971 case token_type::value_unsigned:
10973 if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned())))
10980 case token_type::parse_error:
10983 return sax->parse_error(m_lexer.get_position(),
10984 m_lexer.get_token_string(),
10985 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized,
"value"), BasicJsonType()));
10990 return sax->parse_error(m_lexer.get_position(),
10991 m_lexer.get_token_string(),
10992 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value,
"value"), BasicJsonType()));
10998 skip_to_state_evaluation =
false;
11002 if (states.empty())
11011 if (get_token() == token_type::value_separator)
11019 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array))
11021 if (JSON_HEDLEY_UNLIKELY(!sax->end_array()))
11030 JSON_ASSERT(!states.empty());
11032 skip_to_state_evaluation =
true;
11036 return sax->parse_error(m_lexer.get_position(),
11037 m_lexer.get_token_string(),
11038 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array,
"array"), BasicJsonType()));
11044 if (get_token() == token_type::value_separator)
11047 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string))
11049 return sax->parse_error(m_lexer.get_position(),
11050 m_lexer.get_token_string(),
11051 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string,
"object key"), BasicJsonType()));
11054 if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string())))
11060 if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator))
11062 return sax->parse_error(m_lexer.get_position(),
11063 m_lexer.get_token_string(),
11064 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator,
"object separator"), BasicJsonType()));
11073 if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object))
11075 if (JSON_HEDLEY_UNLIKELY(!sax->end_object()))
11084 JSON_ASSERT(!states.empty());
11086 skip_to_state_evaluation =
true;
11090 return sax->parse_error(m_lexer.get_position(),
11091 m_lexer.get_token_string(),
11092 parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object,
"object"), BasicJsonType()));
11097 token_type get_token()
11099 return last_token = m_lexer.scan();
11102 std::string exception_message(
const token_type expected,
const std::string& context)
11104 std::string error_msg =
"syntax error ";
11106 if (!context.empty())
11108 error_msg +=
"while parsing " + context +
" ";
11113 if (last_token == token_type::parse_error)
11115 error_msg += std::string(m_lexer.get_error_message()) +
"; last read: '" +
11116 m_lexer.get_token_string() +
"'";
11120 error_msg +=
"unexpected " + std::string(lexer_t::token_type_name(last_token));
11123 if (expected != token_type::uninitialized)
11125 error_msg +=
"; expected " + std::string(lexer_t::token_type_name(expected));
11133 const parser_callback_t<BasicJsonType> callback =
nullptr;
11135 token_type last_token = token_type::uninitialized;
11139 const bool allow_exceptions =
true;
11170 class primitive_iterator_t
11173 using difference_type = std::ptrdiff_t;
11174 static constexpr difference_type begin_value = 0;
11175 static constexpr difference_type end_value = begin_value + 1;
11177 JSON_PRIVATE_UNLESS_TESTED:
11179 difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
11182 constexpr difference_type get_value() const noexcept
11188 void set_begin() noexcept
11190 m_it = begin_value;
11194 void set_end() noexcept
11200 constexpr
bool is_begin() const noexcept
11202 return m_it == begin_value;
11206 constexpr
bool is_end() const noexcept
11208 return m_it == end_value;
11211 friend constexpr
bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11213 return lhs.m_it == rhs.m_it;
11216 friend constexpr
bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11218 return lhs.m_it < rhs.m_it;
11221 primitive_iterator_t operator+(difference_type n) noexcept
11223 auto result = *
this;
11228 friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
11230 return lhs.m_it - rhs.m_it;
11233 primitive_iterator_t& operator++() noexcept
11239 primitive_iterator_t
const operator++(
int) noexcept
11241 auto result = *
this;
11246 primitive_iterator_t& operator--() noexcept
11252 primitive_iterator_t
const operator--(
int) noexcept
11254 auto result = *
this;
11259 primitive_iterator_t& operator+=(difference_type n) noexcept
11265 primitive_iterator_t& operator-=(difference_type n) noexcept
11285 template<
typename BasicJsonType>
struct internal_iterator
11288 typename BasicJsonType::object_t::iterator object_iterator {};
11290 typename BasicJsonType::array_t::iterator array_iterator {};
11292 primitive_iterator_t primitive_iterator {};
11300 #include <iterator>
11301 #include <type_traits>
11323 template<
typename IteratorType>
class iteration_proxy;
11324 template<
typename IteratorType>
class iteration_proxy_value;
11342 template<
typename BasicJsonType>
11346 using other_iter_impl = iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value,
typename std::remove_const<BasicJsonType>::type,
const BasicJsonType>::type>;
11348 friend other_iter_impl;
11349 friend BasicJsonType;
11350 friend iteration_proxy<iter_impl>;
11351 friend iteration_proxy_value<iter_impl>;
11353 using object_t =
typename BasicJsonType::object_t;
11354 using array_t =
typename BasicJsonType::array_t;
11356 static_assert(is_basic_json<
typename std::remove_const<BasicJsonType>::type>::value,
11357 "iter_impl only accepts (const) basic_json");
11366 using iterator_category = std::bidirectional_iterator_tag;
11369 using value_type =
typename BasicJsonType::value_type;
11371 using difference_type =
typename BasicJsonType::difference_type;
11373 using pointer =
typename std::conditional<std::is_const<BasicJsonType>::value,
11374 typename BasicJsonType::const_pointer,
11375 typename BasicJsonType::pointer>::type;
11378 typename std::conditional<std::is_const<BasicJsonType>::value,
11379 typename BasicJsonType::const_reference,
11380 typename BasicJsonType::reference>::type;
11382 iter_impl() =
default;
11383 ~iter_impl() =
default;
11384 iter_impl(iter_impl&&) noexcept = default;
11385 iter_impl& operator=(iter_impl&&) noexcept = default;
11393 explicit iter_impl(pointer
object) noexcept : m_object(
object)
11395 JSON_ASSERT(m_object !=
nullptr);
11397 switch (m_object->m_type)
11399 case value_t::object:
11401 m_it.object_iterator =
typename object_t::iterator();
11405 case value_t::array:
11407 m_it.array_iterator =
typename array_t::iterator();
11413 m_it.primitive_iterator = primitive_iterator_t();
11435 iter_impl(
const iter_impl<const BasicJsonType>& other) noexcept
11436 : m_object(other.m_object), m_it(other.m_it)
11445 iter_impl& operator=(
const iter_impl<const BasicJsonType>& other) noexcept
11447 if (&other !=
this)
11449 m_object = other.m_object;
11460 iter_impl(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11461 : m_object(other.m_object), m_it(other.m_it)
11470 iter_impl& operator=(
const iter_impl<
typename std::remove_const<BasicJsonType>::type>& other) noexcept
11472 m_object = other.m_object;
11477 JSON_PRIVATE_UNLESS_TESTED:
11482 void set_begin() noexcept
11484 JSON_ASSERT(m_object !=
nullptr);
11486 switch (m_object->m_type)
11488 case value_t::object:
11490 m_it.object_iterator = m_object->m_value.object->begin();
11494 case value_t::array:
11496 m_it.array_iterator = m_object->m_value.array->begin();
11500 case value_t::null:
11503 m_it.primitive_iterator.set_end();
11509 m_it.primitive_iterator.set_begin();
11519 void set_end() noexcept
11521 JSON_ASSERT(m_object !=
nullptr);
11523 switch (m_object->m_type)
11525 case value_t::object:
11527 m_it.object_iterator = m_object->m_value.object->end();
11531 case value_t::array:
11533 m_it.array_iterator = m_object->m_value.array->end();
11539 m_it.primitive_iterator.set_end();
11550 reference operator*()
const
11552 JSON_ASSERT(m_object !=
nullptr);
11554 switch (m_object->m_type)
11556 case value_t::object:
11558 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11559 return m_it.object_iterator->second;
11562 case value_t::array:
11564 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11565 return *m_it.array_iterator;
11568 case value_t::null:
11569 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11573 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11578 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11587 pointer operator->()
const
11589 JSON_ASSERT(m_object !=
nullptr);
11591 switch (m_object->m_type)
11593 case value_t::object:
11595 JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end());
11596 return &(m_it.object_iterator->second);
11599 case value_t::array:
11601 JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end());
11602 return &*m_it.array_iterator;
11607 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin()))
11612 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11621 iter_impl
const operator++(
int)
11623 auto result = *
this;
11632 iter_impl& operator++()
11634 JSON_ASSERT(m_object !=
nullptr);
11636 switch (m_object->m_type)
11638 case value_t::object:
11640 std::advance(m_it.object_iterator, 1);
11644 case value_t::array:
11646 std::advance(m_it.array_iterator, 1);
11652 ++m_it.primitive_iterator;
11664 iter_impl
const operator--(
int)
11666 auto result = *
this;
11675 iter_impl& operator--()
11677 JSON_ASSERT(m_object !=
nullptr);
11679 switch (m_object->m_type)
11681 case value_t::object:
11683 std::advance(m_it.object_iterator, -1);
11687 case value_t::array:
11689 std::advance(m_it.array_iterator, -1);
11695 --m_it.primitive_iterator;
11707 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 >
11708 bool operator==(
const IterImpl& other)
const
11711 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11713 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
11716 JSON_ASSERT(m_object !=
nullptr);
11718 switch (m_object->m_type)
11720 case value_t::object:
11721 return (m_it.object_iterator == other.m_it.object_iterator);
11723 case value_t::array:
11724 return (m_it.array_iterator == other.m_it.array_iterator);
11727 return (m_it.primitive_iterator == other.m_it.primitive_iterator);
11735 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 >
11736 bool operator!=(
const IterImpl& other)
const
11738 return !operator==(other);
11745 bool operator<(
const iter_impl& other)
const
11748 if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object))
11750 JSON_THROW(invalid_iterator::create(212,
"cannot compare iterators of different containers", *m_object));
11753 JSON_ASSERT(m_object !=
nullptr);
11755 switch (m_object->m_type)
11757 case value_t::object:
11758 JSON_THROW(invalid_iterator::create(213,
"cannot compare order of object iterators", *m_object));
11760 case value_t::array:
11761 return (m_it.array_iterator < other.m_it.array_iterator);
11764 return (m_it.primitive_iterator < other.m_it.primitive_iterator);
11772 bool operator<=(
const iter_impl& other)
const
11774 return !other.operator < (*this);
11781 bool operator>(
const iter_impl& other)
const
11783 return !operator<=(other);
11790 bool operator>=(
const iter_impl& other)
const
11792 return !operator<(other);
11799 iter_impl& operator+=(difference_type i)
11801 JSON_ASSERT(m_object !=
nullptr);
11803 switch (m_object->m_type)
11805 case value_t::object:
11806 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
11808 case value_t::array:
11810 std::advance(m_it.array_iterator, i);
11816 m_it.primitive_iterator += i;
11828 iter_impl& operator-=(difference_type i)
11830 return operator+=(-i);
11837 iter_impl operator+(difference_type i)
const
11839 auto result = *
this;
11848 friend iter_impl operator+(difference_type i,
const iter_impl& it)
11859 iter_impl operator-(difference_type i)
const
11861 auto result = *
this;
11870 difference_type operator-(
const iter_impl& other)
const
11872 JSON_ASSERT(m_object !=
nullptr);
11874 switch (m_object->m_type)
11876 case value_t::object:
11877 JSON_THROW(invalid_iterator::create(209,
"cannot use offsets with object iterators", *m_object));
11879 case value_t::array:
11880 return m_it.array_iterator - other.m_it.array_iterator;
11883 return m_it.primitive_iterator - other.m_it.primitive_iterator;
11891 reference operator[](difference_type n)
const
11893 JSON_ASSERT(m_object !=
nullptr);
11895 switch (m_object->m_type)
11897 case value_t::object:
11898 JSON_THROW(invalid_iterator::create(208,
"cannot use operator[] for object iterators", *m_object));
11900 case value_t::array:
11901 return *std::next(m_it.array_iterator, n);
11903 case value_t::null:
11904 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11908 if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n))
11913 JSON_THROW(invalid_iterator::create(214,
"cannot get value", *m_object));
11922 const typename object_t::key_type& key()
const
11924 JSON_ASSERT(m_object !=
nullptr);
11926 if (JSON_HEDLEY_LIKELY(m_object->is_object()))
11928 return m_it.object_iterator->first;
11931 JSON_THROW(invalid_iterator::create(207,
"cannot use key() for non-object iterators", *m_object));
11938 reference value()
const
11940 return operator*();
11943 JSON_PRIVATE_UNLESS_TESTED:
11945 pointer m_object =
nullptr;
11947 internal_iterator<typename std::remove_const<BasicJsonType>::type> m_it {};
11958 #include <iterator>
11987 template<
typename Base>
11988 class json_reverse_iterator :
public std::reverse_iterator<Base>
11991 using difference_type = std::ptrdiff_t;
11993 using base_iterator = std::reverse_iterator<Base>;
11995 using reference =
typename Base::reference;
11998 explicit json_reverse_iterator(
const typename base_iterator::iterator_type& it) noexcept
11999 : base_iterator(it) {}
12002 explicit json_reverse_iterator(
const base_iterator& it) noexcept : base_iterator(it) {}
12005 json_reverse_iterator
const operator++(
int)
12007 return static_cast<json_reverse_iterator
>(base_iterator::operator++(1));
12011 json_reverse_iterator& operator++()
12013 return static_cast<json_reverse_iterator&
>(base_iterator::operator++());
12017 json_reverse_iterator
const operator--(
int)
12019 return static_cast<json_reverse_iterator
>(base_iterator::operator--(1));
12023 json_reverse_iterator& operator--()
12025 return static_cast<json_reverse_iterator&
>(base_iterator::operator--());
12029 json_reverse_iterator& operator+=(difference_type i)
12031 return static_cast<json_reverse_iterator&
>(base_iterator::operator+=(i));
12035 json_reverse_iterator operator+(difference_type i)
const
12037 return static_cast<json_reverse_iterator
>(base_iterator::operator+(i));
12041 json_reverse_iterator operator-(difference_type i)
const
12043 return static_cast<json_reverse_iterator
>(base_iterator::operator-(i));
12047 difference_type operator-(
const json_reverse_iterator& other)
const
12049 return base_iterator(*
this) - base_iterator(other);
12053 reference operator[](difference_type n)
const
12055 return *(this->operator+(n));
12059 auto key() const -> decltype(std::declval<Base>().key())
12061 auto it = --this->base();
12066 reference value()
const
12068 auto it = --this->base();
12069 return it.operator * ();
12080 #include <algorithm>
12099 template<
typename BasicJsonType>
12103 NLOHMANN_BASIC_JSON_TPL_DECLARATION
12129 : reference_tokens(split(s))
12148 return std::accumulate(reference_tokens.begin(), reference_tokens.end(),
12150 [](
const std::string & a,
const std::string & b)
12152 return a +
"/" + detail::escape(b);
12157 operator std::string()
const
12180 reference_tokens.insert(reference_tokens.end(),
12181 ptr.reference_tokens.begin(),
12182 ptr.reference_tokens.end());
12226 return *
this /= std::to_string(array_idx);
12330 if (JSON_HEDLEY_UNLIKELY(
empty()))
12332 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12335 reference_tokens.pop_back();
12354 if (JSON_HEDLEY_UNLIKELY(
empty()))
12356 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12359 return reference_tokens.back();
12376 reference_tokens.push_back(token);
12382 reference_tokens.push_back(std::move(token));
12401 return reference_tokens.empty();
12415 static typename BasicJsonType::size_type array_index(
const std::string& s)
12417 using size_type =
typename BasicJsonType::size_type;
12420 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] ==
'0'))
12422 JSON_THROW(detail::parse_error::create(106, 0,
"array index '" + s +
"' must not begin with '0'", BasicJsonType()));
12426 if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >=
'1' && s[0] <=
'9')))
12428 JSON_THROW(detail::parse_error::create(109, 0,
"array index '" + s +
"' is not a number", BasicJsonType()));
12431 std::size_t processed_chars = 0;
12432 unsigned long long res = 0;
12435 res = std::stoull(s, &processed_chars);
12437 JSON_CATCH(std::out_of_range&)
12439 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12443 if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size()))
12445 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + s +
"'", BasicJsonType()));
12450 if (res >=
static_cast<unsigned long long>((std::numeric_limits<size_type>::max)()))
12452 JSON_THROW(detail::out_of_range::create(410,
"array index " + s +
" exceeds size_type", BasicJsonType()));
12455 return static_cast<size_type
>(res);
12458 JSON_PRIVATE_UNLESS_TESTED:
12461 if (JSON_HEDLEY_UNLIKELY(
empty()))
12463 JSON_THROW(detail::out_of_range::create(405,
"JSON pointer has no parent", BasicJsonType()));
12467 result.reference_tokens = {reference_tokens[0]};
12480 BasicJsonType& get_and_create(BasicJsonType& j)
const
12486 for (
const auto& reference_token : reference_tokens)
12488 switch (result->type())
12490 case detail::value_t::null:
12492 if (reference_token ==
"0")
12495 result = &result->operator[](0);
12500 result = &result->operator[](reference_token);
12505 case detail::value_t::object:
12508 result = &result->operator[](reference_token);
12512 case detail::value_t::array:
12515 result = &result->operator[](array_index(reference_token));
12526 JSON_THROW(detail::type_error::create(313,
"invalid value to unflatten", j));
12552 BasicJsonType& get_unchecked(BasicJsonType* ptr)
const
12554 for (
const auto& reference_token : reference_tokens)
12557 if (ptr->is_null())
12561 std::all_of(reference_token.begin(), reference_token.end(),
12562 [](
const unsigned char x)
12564 return std::isdigit(x);
12568 *ptr = (nums || reference_token ==
"-")
12569 ? detail::value_t::array
12570 : detail::value_t::object;
12573 switch (ptr->type())
12575 case detail::value_t::object:
12578 ptr = &ptr->operator[](reference_token);
12582 case detail::value_t::array:
12584 if (reference_token ==
"-")
12587 ptr = &ptr->operator[](ptr->m_value.array->size());
12592 ptr = &ptr->operator[](array_index(reference_token));
12598 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12611 BasicJsonType& get_checked(BasicJsonType* ptr)
const
12613 for (
const auto& reference_token : reference_tokens)
12615 switch (ptr->type())
12617 case detail::value_t::object:
12620 ptr = &ptr->at(reference_token);
12624 case detail::value_t::array:
12626 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12629 JSON_THROW(detail::out_of_range::create(402,
12630 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12631 ") is out of range", *ptr));
12635 ptr = &ptr->at(array_index(reference_token));
12640 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12660 const BasicJsonType& get_unchecked(
const BasicJsonType* ptr)
const
12662 for (
const auto& reference_token : reference_tokens)
12664 switch (ptr->type())
12666 case detail::value_t::object:
12669 ptr = &ptr->operator[](reference_token);
12673 case detail::value_t::array:
12675 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12678 JSON_THROW(detail::out_of_range::create(402,
"array index '-' (" + std::to_string(ptr->m_value.array->size()) +
") is out of range", *ptr));
12682 ptr = &ptr->operator[](array_index(reference_token));
12687 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12700 const BasicJsonType& get_checked(
const BasicJsonType* ptr)
const
12702 for (
const auto& reference_token : reference_tokens)
12704 switch (ptr->type())
12706 case detail::value_t::object:
12709 ptr = &ptr->at(reference_token);
12713 case detail::value_t::array:
12715 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12718 JSON_THROW(detail::out_of_range::create(402,
12719 "array index '-' (" + std::to_string(ptr->m_value.array->size()) +
12720 ") is out of range", *ptr));
12724 ptr = &ptr->at(array_index(reference_token));
12729 JSON_THROW(detail::out_of_range::create(404,
"unresolved reference token '" + reference_token +
"'", *ptr));
12740 bool contains(
const BasicJsonType* ptr)
const
12742 for (
const auto& reference_token : reference_tokens)
12744 switch (ptr->type())
12746 case detail::value_t::object:
12748 if (!ptr->contains(reference_token))
12754 ptr = &ptr->operator[](reference_token);
12758 case detail::value_t::array:
12760 if (JSON_HEDLEY_UNLIKELY(reference_token ==
"-"))
12765 if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !(
"0" <= reference_token && reference_token <=
"9")))
12770 if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1))
12772 if (JSON_HEDLEY_UNLIKELY(!(
'1' <= reference_token[0] && reference_token[0] <=
'9')))
12777 for (std::size_t i = 1; i < reference_token.size(); i++)
12779 if (JSON_HEDLEY_UNLIKELY(!(
'0' <= reference_token[i] && reference_token[i] <=
'9')))
12787 const auto idx = array_index(reference_token);
12788 if (idx >= ptr->size())
12794 ptr = &ptr->operator[](idx);
12820 static std::vector<std::string> split(
const std::string& reference_string)
12822 std::vector<std::string> result;
12825 if (reference_string.empty())
12831 if (JSON_HEDLEY_UNLIKELY(reference_string[0] !=
'/'))
12833 JSON_THROW(detail::parse_error::create(107, 1,
"JSON pointer must be empty or begin with '/' - was: '" + reference_string +
"'", BasicJsonType()));
12841 std::size_t slash = reference_string.find_first_of(
'/', 1),
12848 start = (slash == std::string::npos) ? 0 : slash + 1,
12850 slash = reference_string.find_first_of(
'/', start))
12854 auto reference_token = reference_string.substr(start, slash - start);
12857 for (std::size_t pos = reference_token.find_first_of(
'~');
12858 pos != std::string::npos;
12859 pos = reference_token.find_first_of(
'~', pos + 1))
12861 JSON_ASSERT(reference_token[pos] ==
'~');
12864 if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 ||
12865 (reference_token[pos + 1] !=
'0' &&
12866 reference_token[pos + 1] !=
'1')))
12868 JSON_THROW(detail::parse_error::create(108, 0,
"escape character '~' must be followed with '0' or '1'", BasicJsonType()));
12873 detail::unescape(reference_token);
12874 result.push_back(reference_token);
12888 static void flatten(
const std::string& reference_string,
12889 const BasicJsonType& value,
12890 BasicJsonType& result)
12892 switch (value.type())
12894 case detail::value_t::array:
12896 if (value.m_value.array->empty())
12899 result[reference_string] =
nullptr;
12904 for (std::size_t i = 0; i < value.m_value.array->size(); ++i)
12906 flatten(reference_string +
"/" + std::to_string(i),
12907 value.m_value.array->operator[](i), result);
12913 case detail::value_t::object:
12915 if (value.m_value.object->empty())
12918 result[reference_string] =
nullptr;
12923 for (
const auto& element : *value.m_value.object)
12925 flatten(reference_string +
"/" + detail::escape(element.first), element.second, result);
12934 result[reference_string] = value;
12950 static BasicJsonType
12951 unflatten(
const BasicJsonType& value)
12953 if (JSON_HEDLEY_UNLIKELY(!value.is_object()))
12955 JSON_THROW(detail::type_error::create(314,
"only objects can be unflattened", value));
12958 BasicJsonType result;
12961 for (
const auto& element : *value.m_value.object)
12963 if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive()))
12965 JSON_THROW(detail::type_error::create(315,
"values in object must be primitive", element.second));
12972 json_pointer(element.first).get_and_create(result) = element.second;
12992 return lhs.reference_tokens == rhs.reference_tokens;
13009 return !(lhs == rhs);
13013 std::vector<std::string> reference_tokens;
13020 #include <initializer_list>
13030 template<
typename BasicJsonType>
13034 using value_type = BasicJsonType;
13036 json_ref(value_type&& value)
13037 : owned_value(std::move(value))
13040 json_ref(
const value_type& value)
13041 : value_ref(&value)
13044 json_ref(std::initializer_list<json_ref> init)
13045 : owned_value(init)
13050 enable_if_t<std::is_constructible<value_type, Args...>::value,
int> = 0 >
13051 json_ref(Args && ... args)
13052 : owned_value(std::forward<Args>(args)...)
13056 json_ref(json_ref&&) noexcept = default;
13057 json_ref(const json_ref&) = delete;
13058 json_ref& operator=(const json_ref&) = delete;
13059 json_ref& operator=(json_ref&&) = delete;
13060 ~json_ref() = default;
13062 value_type moved_or_copied()
const
13064 if (value_ref ==
nullptr)
13066 return std::move(owned_value);
13071 value_type
const& operator*()
const
13073 return value_ref ? *value_ref : owned_value;
13076 value_type
const* operator->()
const
13082 mutable value_type owned_value =
nullptr;
13083 value_type
const* value_ref =
nullptr;
13099 #include <algorithm>
13115 #include <algorithm>
13118 #include <iterator>
13131 template<
typename CharType>
struct output_adapter_protocol
13133 virtual void write_character(CharType c) = 0;
13134 virtual void write_characters(
const CharType* s, std::size_t length) = 0;
13135 virtual ~output_adapter_protocol() =
default;
13137 output_adapter_protocol() =
default;
13138 output_adapter_protocol(
const output_adapter_protocol&) =
default;
13139 output_adapter_protocol(output_adapter_protocol&&) noexcept = default;
13140 output_adapter_protocol& operator=(const output_adapter_protocol&) = default;
13141 output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default;
13145 template<typename CharType>
13146 using output_adapter_t = std::shared_ptr<output_adapter_protocol<CharType>>;
13149 template<typename CharType>
13150 class output_vector_adapter : public output_adapter_protocol<CharType>
13153 explicit output_vector_adapter(std::vector<CharType>& vec) noexcept
13157 void write_character(CharType c)
override
13162 JSON_HEDLEY_NON_NULL(2)
13163 void write_characters(const CharType* s, std::
size_t length)
override
13165 std::copy(s, s + length, std::back_inserter(v));
13169 std::vector<CharType>& v;
13173 template<
typename CharType>
13174 class output_stream_adapter :
public output_adapter_protocol<CharType>
13177 explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
13181 void write_character(CharType c)
override
13186 JSON_HEDLEY_NON_NULL(2)
13187 void write_characters(const CharType* s, std::
size_t length)
override
13189 stream.write(s,
static_cast<std::streamsize
>(length));
13193 std::basic_ostream<CharType>& stream;
13197 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13198 class output_string_adapter :
public output_adapter_protocol<CharType>
13201 explicit output_string_adapter(StringType& s) noexcept
13205 void write_character(CharType c)
override
13210 JSON_HEDLEY_NON_NULL(2)
13211 void write_characters(const CharType* s, std::
size_t length)
override
13213 str.append(s, length);
13220 template<
typename CharType,
typename StringType = std::basic_
string<CharType>>
13221 class output_adapter
13224 output_adapter(std::vector<CharType>& vec)
13225 : oa(std::make_shared<output_vector_adapter<CharType>>(vec)) {}
13227 output_adapter(std::basic_ostream<CharType>& s)
13228 : oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
13230 output_adapter(StringType& s)
13231 : oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
13233 operator output_adapter_t<CharType>()
13239 output_adapter_t<CharType> oa =
nullptr;
13256 template<
typename BasicJsonType,
typename CharType>
13257 class binary_writer
13259 using string_t =
typename BasicJsonType::string_t;
13260 using binary_t =
typename BasicJsonType::binary_t;
13261 using number_float_t =
typename BasicJsonType::number_float_t;
13269 explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
13278 void write_bson(
const BasicJsonType& j)
13282 case value_t::object:
13284 write_bson_object(*j.m_value.object);
13290 JSON_THROW(type_error::create(317,
"to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j));;
13298 void write_cbor(
const BasicJsonType& j)
13302 case value_t::null:
13304 oa->write_character(to_char_type(0xF6));
13308 case value_t::boolean:
13310 oa->write_character(j.m_value.boolean
13311 ? to_char_type(0xF5)
13312 : to_char_type(0xF4));
13316 case value_t::number_integer:
13318 if (j.m_value.number_integer >= 0)
13323 if (j.m_value.number_integer <= 0x17)
13325 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13327 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint8_t>::max)())
13329 oa->write_character(to_char_type(0x18));
13330 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13332 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint16_t>::max)())
13334 oa->write_character(to_char_type(0x19));
13335 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13337 else if (j.m_value.number_integer <= (std::numeric_limits<std::uint32_t>::max)())
13339 oa->write_character(to_char_type(0x1A));
13340 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13344 oa->write_character(to_char_type(0x1B));
13345 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13352 const auto positive_number = -1 - j.m_value.number_integer;
13353 if (j.m_value.number_integer >= -24)
13355 write_number(
static_cast<std::uint8_t
>(0x20 + positive_number));
13357 else if (positive_number <= (std::numeric_limits<std::uint8_t>::max)())
13359 oa->write_character(to_char_type(0x38));
13360 write_number(
static_cast<std::uint8_t
>(positive_number));
13362 else if (positive_number <= (std::numeric_limits<std::uint16_t>::max)())
13364 oa->write_character(to_char_type(0x39));
13365 write_number(
static_cast<std::uint16_t
>(positive_number));
13367 else if (positive_number <= (std::numeric_limits<std::uint32_t>::max)())
13369 oa->write_character(to_char_type(0x3A));
13370 write_number(
static_cast<std::uint32_t
>(positive_number));
13374 oa->write_character(to_char_type(0x3B));
13375 write_number(
static_cast<std::uint64_t
>(positive_number));
13381 case value_t::number_unsigned:
13383 if (j.m_value.number_unsigned <= 0x17)
13385 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13387 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13389 oa->write_character(to_char_type(0x18));
13390 write_number(
static_cast<std::uint8_t
>(j.m_value.number_unsigned));
13392 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13394 oa->write_character(to_char_type(0x19));
13395 write_number(
static_cast<std::uint16_t
>(j.m_value.number_unsigned));
13397 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13399 oa->write_character(to_char_type(0x1A));
13400 write_number(
static_cast<std::uint32_t
>(j.m_value.number_unsigned));
13404 oa->write_character(to_char_type(0x1B));
13405 write_number(
static_cast<std::uint64_t
>(j.m_value.number_unsigned));
13410 case value_t::number_float:
13412 if (std::isnan(j.m_value.number_float))
13415 oa->write_character(to_char_type(0xF9));
13416 oa->write_character(to_char_type(0x7E));
13417 oa->write_character(to_char_type(0x00));
13419 else if (std::isinf(j.m_value.number_float))
13422 oa->write_character(to_char_type(0xf9));
13423 oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC));
13424 oa->write_character(to_char_type(0x00));
13428 write_compact_float(j.m_value.number_float, detail::input_format_t::cbor);
13433 case value_t::string:
13436 const auto N = j.m_value.string->size();
13439 write_number(
static_cast<std::uint8_t
>(0x60 + N));
13441 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13443 oa->write_character(to_char_type(0x78));
13444 write_number(
static_cast<std::uint8_t
>(N));
13446 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13448 oa->write_character(to_char_type(0x79));
13449 write_number(
static_cast<std::uint16_t
>(N));
13451 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13453 oa->write_character(to_char_type(0x7A));
13454 write_number(
static_cast<std::uint32_t
>(N));
13457 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13459 oa->write_character(to_char_type(0x7B));
13460 write_number(
static_cast<std::uint64_t
>(N));
13465 oa->write_characters(
13466 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13467 j.m_value.string->size());
13471 case value_t::array:
13474 const auto N = j.m_value.array->size();
13477 write_number(
static_cast<std::uint8_t
>(0x80 + N));
13479 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13481 oa->write_character(to_char_type(0x98));
13482 write_number(
static_cast<std::uint8_t
>(N));
13484 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13486 oa->write_character(to_char_type(0x99));
13487 write_number(
static_cast<std::uint16_t
>(N));
13489 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13491 oa->write_character(to_char_type(0x9A));
13492 write_number(
static_cast<std::uint32_t
>(N));
13495 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13497 oa->write_character(to_char_type(0x9B));
13498 write_number(
static_cast<std::uint64_t
>(N));
13503 for (
const auto& el : *j.m_value.array)
13510 case value_t::binary:
13512 if (j.m_value.binary->has_subtype())
13514 write_number(
static_cast<std::uint8_t
>(0xd8));
13515 write_number(j.m_value.binary->subtype());
13519 const auto N = j.m_value.binary->size();
13522 write_number(
static_cast<std::uint8_t
>(0x40 + N));
13524 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13526 oa->write_character(to_char_type(0x58));
13527 write_number(
static_cast<std::uint8_t
>(N));
13529 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13531 oa->write_character(to_char_type(0x59));
13532 write_number(
static_cast<std::uint16_t
>(N));
13534 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13536 oa->write_character(to_char_type(0x5A));
13537 write_number(
static_cast<std::uint32_t
>(N));
13540 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13542 oa->write_character(to_char_type(0x5B));
13543 write_number(
static_cast<std::uint64_t
>(N));
13548 oa->write_characters(
13549 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13555 case value_t::object:
13558 const auto N = j.m_value.object->size();
13561 write_number(
static_cast<std::uint8_t
>(0xA0 + N));
13563 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13565 oa->write_character(to_char_type(0xB8));
13566 write_number(
static_cast<std::uint8_t
>(N));
13568 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13570 oa->write_character(to_char_type(0xB9));
13571 write_number(
static_cast<std::uint16_t
>(N));
13573 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13575 oa->write_character(to_char_type(0xBA));
13576 write_number(
static_cast<std::uint32_t
>(N));
13579 else if (N <= (std::numeric_limits<std::uint64_t>::max)())
13581 oa->write_character(to_char_type(0xBB));
13582 write_number(
static_cast<std::uint64_t
>(N));
13587 for (
const auto& el : *j.m_value.object)
13589 write_cbor(el.first);
13590 write_cbor(el.second);
13603 void write_msgpack(
const BasicJsonType& j)
13607 case value_t::null:
13609 oa->write_character(to_char_type(0xC0));
13613 case value_t::boolean:
13615 oa->write_character(j.m_value.boolean
13616 ? to_char_type(0xC3)
13617 : to_char_type(0xC2));
13621 case value_t::number_integer:
13623 if (j.m_value.number_integer >= 0)
13628 if (j.m_value.number_unsigned < 128)
13631 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13633 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13636 oa->write_character(to_char_type(0xCC));
13637 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13639 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13642 oa->write_character(to_char_type(0xCD));
13643 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13645 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13648 oa->write_character(to_char_type(0xCE));
13649 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13651 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13654 oa->write_character(to_char_type(0xCF));
13655 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13660 if (j.m_value.number_integer >= -32)
13663 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13665 else if (j.m_value.number_integer >= (std::numeric_limits<std::int8_t>::min)() &&
13666 j.m_value.number_integer <= (std::numeric_limits<std::int8_t>::max)())
13669 oa->write_character(to_char_type(0xD0));
13670 write_number(
static_cast<std::int8_t
>(j.m_value.number_integer));
13672 else if (j.m_value.number_integer >= (std::numeric_limits<std::int16_t>::min)() &&
13673 j.m_value.number_integer <= (std::numeric_limits<std::int16_t>::max)())
13676 oa->write_character(to_char_type(0xD1));
13677 write_number(
static_cast<std::int16_t
>(j.m_value.number_integer));
13679 else if (j.m_value.number_integer >= (std::numeric_limits<std::int32_t>::min)() &&
13680 j.m_value.number_integer <= (std::numeric_limits<std::int32_t>::max)())
13683 oa->write_character(to_char_type(0xD2));
13684 write_number(
static_cast<std::int32_t
>(j.m_value.number_integer));
13686 else if (j.m_value.number_integer >= (std::numeric_limits<std::int64_t>::min)() &&
13687 j.m_value.number_integer <= (std::numeric_limits<std::int64_t>::max)())
13690 oa->write_character(to_char_type(0xD3));
13691 write_number(
static_cast<std::int64_t
>(j.m_value.number_integer));
13697 case value_t::number_unsigned:
13699 if (j.m_value.number_unsigned < 128)
13702 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13704 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint8_t>::max)())
13707 oa->write_character(to_char_type(0xCC));
13708 write_number(
static_cast<std::uint8_t
>(j.m_value.number_integer));
13710 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint16_t>::max)())
13713 oa->write_character(to_char_type(0xCD));
13714 write_number(
static_cast<std::uint16_t
>(j.m_value.number_integer));
13716 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint32_t>::max)())
13719 oa->write_character(to_char_type(0xCE));
13720 write_number(
static_cast<std::uint32_t
>(j.m_value.number_integer));
13722 else if (j.m_value.number_unsigned <= (std::numeric_limits<std::uint64_t>::max)())
13725 oa->write_character(to_char_type(0xCF));
13726 write_number(
static_cast<std::uint64_t
>(j.m_value.number_integer));
13731 case value_t::number_float:
13733 write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack);
13737 case value_t::string:
13740 const auto N = j.m_value.string->size();
13744 write_number(
static_cast<std::uint8_t
>(0xA0 | N));
13746 else if (N <= (std::numeric_limits<std::uint8_t>::max)())
13749 oa->write_character(to_char_type(0xD9));
13750 write_number(
static_cast<std::uint8_t
>(N));
13752 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13755 oa->write_character(to_char_type(0xDA));
13756 write_number(
static_cast<std::uint16_t
>(N));
13758 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13761 oa->write_character(to_char_type(0xDB));
13762 write_number(
static_cast<std::uint32_t
>(N));
13766 oa->write_characters(
13767 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13768 j.m_value.string->size());
13772 case value_t::array:
13775 const auto N = j.m_value.array->size();
13779 write_number(
static_cast<std::uint8_t
>(0x90 | N));
13781 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13784 oa->write_character(to_char_type(0xDC));
13785 write_number(
static_cast<std::uint16_t
>(N));
13787 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13790 oa->write_character(to_char_type(0xDD));
13791 write_number(
static_cast<std::uint32_t
>(N));
13795 for (
const auto& el : *j.m_value.array)
13802 case value_t::binary:
13806 const bool use_ext = j.m_value.binary->has_subtype();
13809 const auto N = j.m_value.binary->size();
13810 if (N <= (std::numeric_limits<std::uint8_t>::max)())
13812 std::uint8_t output_type{};
13819 output_type = 0xD4;
13822 output_type = 0xD5;
13825 output_type = 0xD6;
13828 output_type = 0xD7;
13831 output_type = 0xD8;
13834 output_type = 0xC7;
13842 output_type = 0xC4;
13846 oa->write_character(to_char_type(output_type));
13849 write_number(
static_cast<std::uint8_t
>(N));
13852 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13854 std::uint8_t output_type = use_ext
13858 oa->write_character(to_char_type(output_type));
13859 write_number(
static_cast<std::uint16_t
>(N));
13861 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13863 std::uint8_t output_type = use_ext
13867 oa->write_character(to_char_type(output_type));
13868 write_number(
static_cast<std::uint32_t
>(N));
13874 write_number(
static_cast<std::int8_t
>(j.m_value.binary->subtype()));
13878 oa->write_characters(
13879 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
13885 case value_t::object:
13888 const auto N = j.m_value.object->size();
13892 write_number(
static_cast<std::uint8_t
>(0x80 | (N & 0xF)));
13894 else if (N <= (std::numeric_limits<std::uint16_t>::max)())
13897 oa->write_character(to_char_type(0xDE));
13898 write_number(
static_cast<std::uint16_t
>(N));
13900 else if (N <= (std::numeric_limits<std::uint32_t>::max)())
13903 oa->write_character(to_char_type(0xDF));
13904 write_number(
static_cast<std::uint32_t
>(N));
13908 for (
const auto& el : *j.m_value.object)
13910 write_msgpack(el.first);
13911 write_msgpack(el.second);
13927 void write_ubjson(
const BasicJsonType& j,
const bool use_count,
13928 const bool use_type,
const bool add_prefix =
true)
13932 case value_t::null:
13936 oa->write_character(to_char_type(
'Z'));
13941 case value_t::boolean:
13945 oa->write_character(j.m_value.boolean
13946 ? to_char_type(
'T')
13947 : to_char_type(
'F'));
13952 case value_t::number_integer:
13954 write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix);
13958 case value_t::number_unsigned:
13960 write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix);
13964 case value_t::number_float:
13966 write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix);
13970 case value_t::string:
13974 oa->write_character(to_char_type(
'S'));
13976 write_number_with_ubjson_prefix(j.m_value.string->size(),
true);
13977 oa->write_characters(
13978 reinterpret_cast<const CharType*
>(j.m_value.string->c_str()),
13979 j.m_value.string->size());
13983 case value_t::array:
13987 oa->write_character(to_char_type(
'['));
13990 bool prefix_required =
true;
13991 if (use_type && !j.m_value.array->empty())
13993 JSON_ASSERT(use_count);
13994 const CharType first_prefix = ubjson_prefix(j.front());
13995 const bool same_prefix = std::all_of(j.begin() + 1, j.end(),
13996 [
this, first_prefix](
const BasicJsonType & v)
13998 return ubjson_prefix(v) == first_prefix;
14003 prefix_required =
false;
14004 oa->write_character(to_char_type(
'$'));
14005 oa->write_character(first_prefix);
14011 oa->write_character(to_char_type(
'#'));
14012 write_number_with_ubjson_prefix(j.m_value.array->size(),
true);
14015 for (
const auto& el : *j.m_value.array)
14017 write_ubjson(el, use_count, use_type, prefix_required);
14022 oa->write_character(to_char_type(
']'));
14028 case value_t::binary:
14032 oa->write_character(to_char_type(
'['));
14035 if (use_type && !j.m_value.binary->empty())
14037 JSON_ASSERT(use_count);
14038 oa->write_character(to_char_type(
'$'));
14039 oa->write_character(
'U');
14044 oa->write_character(to_char_type(
'#'));
14045 write_number_with_ubjson_prefix(j.m_value.binary->size(),
true);
14050 oa->write_characters(
14051 reinterpret_cast<const CharType*
>(j.m_value.binary->data()),
14052 j.m_value.binary->size());
14056 for (
size_t i = 0; i < j.m_value.binary->size(); ++i)
14058 oa->write_character(to_char_type(
'U'));
14059 oa->write_character(j.m_value.binary->data()[i]);
14065 oa->write_character(to_char_type(
']'));
14071 case value_t::object:
14075 oa->write_character(to_char_type(
'{'));
14078 bool prefix_required =
true;
14079 if (use_type && !j.m_value.object->empty())
14081 JSON_ASSERT(use_count);
14082 const CharType first_prefix = ubjson_prefix(j.front());
14083 const bool same_prefix = std::all_of(j.begin(), j.end(),
14084 [
this, first_prefix](
const BasicJsonType & v)
14086 return ubjson_prefix(v) == first_prefix;
14091 prefix_required =
false;
14092 oa->write_character(to_char_type(
'$'));
14093 oa->write_character(first_prefix);
14099 oa->write_character(to_char_type(
'#'));
14100 write_number_with_ubjson_prefix(j.m_value.object->size(),
true);
14103 for (
const auto& el : *j.m_value.object)
14105 write_number_with_ubjson_prefix(el.first.size(),
true);
14106 oa->write_characters(
14107 reinterpret_cast<const CharType*
>(el.first.c_str()),
14109 write_ubjson(el.second, use_count, use_type, prefix_required);
14114 oa->write_character(to_char_type(
'}'));
14134 static std::size_t calc_bson_entry_header_size(
const string_t& name,
const BasicJsonType& j)
14136 const auto it = name.find(
static_cast<typename string_t::value_type
>(0));
14137 if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos))
14139 JSON_THROW(out_of_range::create(409,
"BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) +
")", j));
14142 return 1ul + name.size() + 1u;
14148 void write_bson_entry_header(
const string_t& name,
14149 const std::uint8_t element_type)
14151 oa->write_character(to_char_type(element_type));
14152 oa->write_characters(
14153 reinterpret_cast<const CharType*
>(name.c_str()),
14160 void write_bson_boolean(
const string_t& name,
14163 write_bson_entry_header(name, 0x08);
14164 oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00));
14170 void write_bson_double(
const string_t& name,
14171 const double value)
14173 write_bson_entry_header(name, 0x01);
14174 write_number<double, true>(value);
14180 static std::size_t calc_bson_string_size(
const string_t& value)
14182 return sizeof(std::int32_t) + value.size() + 1ul;
14188 void write_bson_string(
const string_t& name,
14189 const string_t& value)
14191 write_bson_entry_header(name, 0x02);
14193 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size() + 1ul));
14194 oa->write_characters(
14195 reinterpret_cast<const CharType*
>(value.c_str()),
14202 void write_bson_null(
const string_t& name)
14204 write_bson_entry_header(name, 0x0A);
14210 static std::size_t calc_bson_integer_size(
const std::int64_t value)
14212 return (std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)()
14213 ?
sizeof(std::int32_t)
14214 :
sizeof(std::int64_t);
14220 void write_bson_integer(
const string_t& name,
14221 const std::int64_t value)
14223 if ((std::numeric_limits<std::int32_t>::min)() <= value && value <= (std::numeric_limits<std::int32_t>::max)())
14225 write_bson_entry_header(name, 0x10);
14226 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value));
14230 write_bson_entry_header(name, 0x12);
14231 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(value));
14238 static constexpr std::size_t calc_bson_unsigned_size(
const std::uint64_t value) noexcept
14240 return (value <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14241 ?
sizeof(std::int32_t)
14242 :
sizeof(std::int64_t);
14248 void write_bson_unsigned(
const string_t& name,
14249 const BasicJsonType& j)
14251 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14253 write_bson_entry_header(name, 0x10 );
14254 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(j.m_value.number_unsigned));
14256 else if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14258 write_bson_entry_header(name, 0x12 );
14259 write_number<std::int64_t, true>(
static_cast<std::int64_t
>(j.m_value.number_unsigned));
14263 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));
14270 void write_bson_object_entry(
const string_t& name,
14271 const typename BasicJsonType::object_t& value)
14273 write_bson_entry_header(name, 0x03);
14274 write_bson_object(value);
14280 static std::size_t calc_bson_array_size(
const typename BasicJsonType::array_t& value)
14282 std::size_t array_index = 0ul;
14284 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)
14286 return result + calc_bson_element_size(std::to_string(array_index++), el);
14289 return sizeof(std::int32_t) + embedded_document_size + 1ul;
14295 static std::size_t calc_bson_binary_size(
const typename BasicJsonType::binary_t& value)
14297 return sizeof(std::int32_t) + value.size() + 1ul;
14303 void write_bson_array(
const string_t& name,
14304 const typename BasicJsonType::array_t& value)
14306 write_bson_entry_header(name, 0x04);
14307 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_array_size(value)));
14309 std::size_t array_index = 0ul;
14311 for (
const auto& el : value)
14313 write_bson_element(std::to_string(array_index++), el);
14316 oa->write_character(to_char_type(0x00));
14322 void write_bson_binary(
const string_t& name,
14323 const binary_t& value)
14325 write_bson_entry_header(name, 0x05);
14327 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(value.size()));
14328 write_number(value.has_subtype() ? value.subtype() : std::uint8_t(0x00));
14330 oa->write_characters(
reinterpret_cast<const CharType*
>(value.data()), value.size());
14337 static std::size_t calc_bson_element_size(
const string_t& name,
14338 const BasicJsonType& j)
14340 const auto header_size = calc_bson_entry_header_size(name, j);
14343 case value_t::object:
14344 return header_size + calc_bson_object_size(*j.m_value.object);
14346 case value_t::array:
14347 return header_size + calc_bson_array_size(*j.m_value.array);
14349 case value_t::binary:
14350 return header_size + calc_bson_binary_size(*j.m_value.binary);
14352 case value_t::boolean:
14353 return header_size + 1ul;
14355 case value_t::number_float:
14356 return header_size + 8ul;
14358 case value_t::number_integer:
14359 return header_size + calc_bson_integer_size(j.m_value.number_integer);
14361 case value_t::number_unsigned:
14362 return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned);
14364 case value_t::string:
14365 return header_size + calc_bson_string_size(*j.m_value.string);
14367 case value_t::null:
14368 return header_size + 0ul;
14372 JSON_ASSERT(
false);
14384 void write_bson_element(
const string_t& name,
14385 const BasicJsonType& j)
14389 case value_t::object:
14390 return write_bson_object_entry(name, *j.m_value.object);
14392 case value_t::array:
14393 return write_bson_array(name, *j.m_value.array);
14395 case value_t::binary:
14396 return write_bson_binary(name, *j.m_value.binary);
14398 case value_t::boolean:
14399 return write_bson_boolean(name, j.m_value.boolean);
14401 case value_t::number_float:
14402 return write_bson_double(name, j.m_value.number_float);
14404 case value_t::number_integer:
14405 return write_bson_integer(name, j.m_value.number_integer);
14407 case value_t::number_unsigned:
14408 return write_bson_unsigned(name, j);
14410 case value_t::string:
14411 return write_bson_string(name, *j.m_value.string);
14413 case value_t::null:
14414 return write_bson_null(name);
14418 JSON_ASSERT(
false);
14430 static std::size_t calc_bson_object_size(
const typename BasicJsonType::object_t& value)
14432 std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0),
14433 [](
size_t result,
const typename BasicJsonType::object_t::value_type & el)
14435 return result += calc_bson_element_size(el.first, el.second);
14438 return sizeof(std::int32_t) + document_size + 1ul;
14445 void write_bson_object(
const typename BasicJsonType::object_t& value)
14447 write_number<std::int32_t, true>(
static_cast<std::int32_t
>(calc_bson_object_size(value)));
14449 for (
const auto& el : value)
14451 write_bson_element(el.first, el.second);
14454 oa->write_character(to_char_type(0x00));
14461 static constexpr CharType get_cbor_float_prefix(
float )
14463 return to_char_type(0xFA);
14466 static constexpr CharType get_cbor_float_prefix(
double )
14468 return to_char_type(0xFB);
14475 static constexpr CharType get_msgpack_float_prefix(
float )
14477 return to_char_type(0xCA);
14480 static constexpr CharType get_msgpack_float_prefix(
double )
14482 return to_char_type(0xCB);
14490 template<
typename NumberType,
typename std::enable_if<
14491 std::is_floating_point<NumberType>::value,
int>::type = 0>
14492 void write_number_with_ubjson_prefix(
const NumberType n,
14493 const bool add_prefix)
14497 oa->write_character(get_ubjson_float_prefix(n));
14503 template<
typename NumberType,
typename std::enable_if<
14504 std::is_unsigned<NumberType>::value,
int>::type = 0>
14505 void write_number_with_ubjson_prefix(
const NumberType n,
14506 const bool add_prefix)
14508 if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14512 oa->write_character(to_char_type(
'i'));
14514 write_number(
static_cast<std::uint8_t
>(n));
14516 else if (n <= (std::numeric_limits<std::uint8_t>::max)())
14520 oa->write_character(to_char_type(
'U'));
14522 write_number(
static_cast<std::uint8_t
>(n));
14524 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14528 oa->write_character(to_char_type(
'I'));
14530 write_number(
static_cast<std::int16_t
>(n));
14532 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14536 oa->write_character(to_char_type(
'l'));
14538 write_number(
static_cast<std::int32_t
>(n));
14540 else if (n <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14544 oa->write_character(to_char_type(
'L'));
14546 write_number(
static_cast<std::int64_t
>(n));
14552 oa->write_character(to_char_type(
'H'));
14555 const auto number = BasicJsonType(n).dump();
14556 write_number_with_ubjson_prefix(number.size(),
true);
14557 for (std::size_t i = 0; i < number.size(); ++i)
14559 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14565 template <
typename NumberType,
typename std::enable_if <
14566 std::is_signed<NumberType>::value&&
14567 !std::is_floating_point<NumberType>::value,
int >::type = 0 >
14568 void write_number_with_ubjson_prefix(
const NumberType n,
14569 const bool add_prefix)
14571 if ((std::numeric_limits<std::int8_t>::min)() <= n && n <= (std::numeric_limits<std::int8_t>::max)())
14575 oa->write_character(to_char_type(
'i'));
14577 write_number(
static_cast<std::int8_t
>(n));
14579 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)()))
14583 oa->write_character(to_char_type(
'U'));
14585 write_number(
static_cast<std::uint8_t
>(n));
14587 else if ((std::numeric_limits<std::int16_t>::min)() <= n && n <= (std::numeric_limits<std::int16_t>::max)())
14591 oa->write_character(to_char_type(
'I'));
14593 write_number(
static_cast<std::int16_t
>(n));
14595 else if ((std::numeric_limits<std::int32_t>::min)() <= n && n <= (std::numeric_limits<std::int32_t>::max)())
14599 oa->write_character(to_char_type(
'l'));
14601 write_number(
static_cast<std::int32_t
>(n));
14603 else if ((std::numeric_limits<std::int64_t>::min)() <= n && n <= (std::numeric_limits<std::int64_t>::max)())
14607 oa->write_character(to_char_type(
'L'));
14609 write_number(
static_cast<std::int64_t
>(n));
14616 oa->write_character(to_char_type(
'H'));
14619 const auto number = BasicJsonType(n).dump();
14620 write_number_with_ubjson_prefix(number.size(),
true);
14621 for (std::size_t i = 0; i < number.size(); ++i)
14623 oa->write_character(to_char_type(
static_cast<std::uint8_t
>(number[i])));
14632 CharType ubjson_prefix(
const BasicJsonType& j)
const noexcept
14636 case value_t::null:
14639 case value_t::boolean:
14640 return j.m_value.boolean ?
'T' :
'F';
14642 case value_t::number_integer:
14644 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)())
14648 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)())
14652 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)())
14656 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)())
14660 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)())
14668 case value_t::number_unsigned:
14670 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int8_t>::max)()))
14674 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::uint8_t>::max)()))
14678 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int16_t>::max)()))
14682 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int32_t>::max)()))
14686 if (j.m_value.number_unsigned <=
static_cast<std::uint64_t
>((std::numeric_limits<std::int64_t>::max)()))
14694 case value_t::number_float:
14695 return get_ubjson_float_prefix(j.m_value.number_float);
14697 case value_t::string:
14700 case value_t::array:
14701 case value_t::binary:
14704 case value_t::object:
14712 static constexpr CharType get_ubjson_float_prefix(
float )
14717 static constexpr CharType get_ubjson_float_prefix(
double )
14737 template<
typename NumberType,
bool OutputIsLittleEndian = false>
14738 void write_number(
const NumberType n)
14741 std::array<CharType,
sizeof(NumberType)> vec{};
14742 std::memcpy(vec.data(), &n,
sizeof(NumberType));
14745 if (is_little_endian != OutputIsLittleEndian)
14748 std::reverse(vec.begin(), vec.end());
14751 oa->write_characters(vec.data(),
sizeof(NumberType));
14754 void write_compact_float(
const number_float_t n, detail::input_format_t format)
14756 if (
static_cast<double>(n) >=
static_cast<double>(std::numeric_limits<float>::lowest()) &&
14757 static_cast<double>(n) <=
static_cast<double>((std::numeric_limits<float>::max)()) &&
14758 static_cast<double>(
static_cast<float>(n)) ==
static_cast<double>(n))
14760 oa->write_character(format == detail::input_format_t::cbor
14761 ? get_cbor_float_prefix(
static_cast<float>(n))
14762 : get_msgpack_float_prefix(
static_cast<float>(n)));
14763 write_number(
static_cast<float>(n));
14767 oa->write_character(format == detail::input_format_t::cbor
14768 ? get_cbor_float_prefix(n)
14769 : get_msgpack_float_prefix(n));
14779 template <
typename C = CharType,
14780 enable_if_t < std::is_signed<C>::value && std::is_signed<char>::value > * =
nullptr >
14781 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14783 return *
reinterpret_cast<char*
>(&x);
14786 template <
typename C = CharType,
14787 enable_if_t < std::is_signed<C>::value && std::is_unsigned<char>::value > * =
nullptr >
14788 static CharType to_char_type(std::uint8_t x) noexcept
14790 static_assert(
sizeof(std::uint8_t) ==
sizeof(CharType),
"size of CharType must be equal to std::uint8_t");
14791 static_assert(std::is_trivial<CharType>::value,
"CharType must be trivial");
14793 std::memcpy(&result, &x,
sizeof(x));
14797 template<
typename C = CharType,
14798 enable_if_t<std::is_unsigned<C>::value>* =
nullptr>
14799 static constexpr CharType to_char_type(std::uint8_t x) noexcept
14804 template <
typename InputCharType,
typename C = CharType,
14806 std::is_signed<C>::value &&
14807 std::is_signed<char>::value &&
14808 std::is_same<char, typename std::remove_cv<InputCharType>::type>::value
14810 static constexpr CharType to_char_type(InputCharType x) noexcept
14817 const bool is_little_endian = little_endianess();
14820 output_adapter_t<CharType> oa =
nullptr;
14830 #include <algorithm>
14839 #include <type_traits>
14850 #include <type_traits>
14879 namespace dtoa_impl
14882 template<
typename Target,
typename Source>
14883 Target reinterpret_bits(
const Source source)
14885 static_assert(
sizeof(Target) ==
sizeof(Source),
"size mismatch");
14888 std::memcpy(&target, &source,
sizeof(Source));
14894 static constexpr
int kPrecision = 64;
14896 std::uint64_t f = 0;
14899 constexpr diyfp(std::uint64_t f_,
int e_) noexcept : f(f_), e(e_) {}
14905 static diyfp sub(
const diyfp& x,
const diyfp& y) noexcept
14907 JSON_ASSERT(x.e == y.e);
14908 JSON_ASSERT(x.f >= y.f);
14910 return {x.f - y.f, x.e};
14917 static diyfp mul(
const diyfp& x,
const diyfp& y) noexcept
14919 static_assert(kPrecision == 64,
"internal error");
14944 const std::uint64_t u_lo = x.f & 0xFFFFFFFFu;
14945 const std::uint64_t u_hi = x.f >> 32u;
14946 const std::uint64_t v_lo = y.f & 0xFFFFFFFFu;
14947 const std::uint64_t v_hi = y.f >> 32u;
14949 const std::uint64_t p0 = u_lo * v_lo;
14950 const std::uint64_t p1 = u_lo * v_hi;
14951 const std::uint64_t p2 = u_hi * v_lo;
14952 const std::uint64_t p3 = u_hi * v_hi;
14954 const std::uint64_t p0_hi = p0 >> 32u;
14955 const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu;
14956 const std::uint64_t p1_hi = p1 >> 32u;
14957 const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu;
14958 const std::uint64_t p2_hi = p2 >> 32u;
14960 std::uint64_t Q = p0_hi + p1_lo + p2_lo;
14971 Q += std::uint64_t{1} << (64u - 32u - 1u);
14973 const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u);
14975 return {h, x.e + y.e + 64};
14982 static diyfp normalize(diyfp x) noexcept
14984 JSON_ASSERT(x.f != 0);
14986 while ((x.f >> 63u) == 0)
14999 static diyfp normalize_to(
const diyfp& x,
const int target_exponent) noexcept
15001 const int delta = x.e - target_exponent;
15003 JSON_ASSERT(delta >= 0);
15004 JSON_ASSERT(((x.f << delta) >> delta) == x.f);
15006 return {x.f << delta, target_exponent};
15023 template<
typename FloatType>
15024 boundaries compute_boundaries(FloatType value)
15026 JSON_ASSERT(std::isfinite(value));
15027 JSON_ASSERT(value > 0);
15036 static_assert(std::numeric_limits<FloatType>::is_iec559,
15037 "internal error: dtoa_short requires an IEEE-754 floating-point implementation");
15039 constexpr
int kPrecision = std::numeric_limits<FloatType>::digits;
15040 constexpr
int kBias = std::numeric_limits<FloatType>::max_exponent - 1 + (kPrecision - 1);
15041 constexpr
int kMinExp = 1 - kBias;
15042 constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1);
15044 using bits_type =
typename std::conditional<kPrecision == 24, std::uint32_t, std::uint64_t >::type;
15046 const auto bits =
static_cast<std::uint64_t
>(reinterpret_bits<bits_type>(value));
15047 const std::uint64_t E = bits >> (kPrecision - 1);
15048 const std::uint64_t F = bits & (kHiddenBit - 1);
15050 const bool is_denormal = E == 0;
15051 const diyfp v = is_denormal
15052 ? diyfp(F, kMinExp)
15053 : diyfp(F + kHiddenBit, static_cast<int>(E) - kBias);
15076 const bool lower_boundary_is_closer = F == 0 && E > 1;
15077 const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1);
15078 const diyfp m_minus = lower_boundary_is_closer
15079 ? diyfp(4 * v.f - 1, v.e - 2)
15080 : diyfp(2 * v.f - 1, v.e - 1);
15083 const diyfp w_plus = diyfp::normalize(m_plus);
15086 const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e);
15088 return {diyfp::normalize(v), w_minus, w_plus};
15146 constexpr
int kAlpha = -60;
15147 constexpr
int kGamma = -32;
15149 struct cached_power
15163 inline cached_power get_cached_power_for_binary_exponent(
int e)
15215 constexpr
int kCachedPowersMinDecExp = -300;
15216 constexpr
int kCachedPowersDecStep = 8;
15218 static constexpr std::array<cached_power, 79> kCachedPowers =
15221 { 0xAB70FE17C79AC6CA, -1060, -300 },
15222 { 0xFF77B1FCBEBCDC4F, -1034, -292 },
15223 { 0xBE5691EF416BD60C, -1007, -284 },
15224 { 0x8DD01FAD907FFC3C, -980, -276 },
15225 { 0xD3515C2831559A83, -954, -268 },
15226 { 0x9D71AC8FADA6C9B5, -927, -260 },
15227 { 0xEA9C227723EE8BCB, -901, -252 },
15228 { 0xAECC49914078536D, -874, -244 },
15229 { 0x823C12795DB6CE57, -847, -236 },
15230 { 0xC21094364DFB5637, -821, -228 },
15231 { 0x9096EA6F3848984F, -794, -220 },
15232 { 0xD77485CB25823AC7, -768, -212 },
15233 { 0xA086CFCD97BF97F4, -741, -204 },
15234 { 0xEF340A98172AACE5, -715, -196 },
15235 { 0xB23867FB2A35B28E, -688, -188 },
15236 { 0x84C8D4DFD2C63F3B, -661, -180 },
15237 { 0xC5DD44271AD3CDBA, -635, -172 },
15238 { 0x936B9FCEBB25C996, -608, -164 },
15239 { 0xDBAC6C247D62A584, -582, -156 },
15240 { 0xA3AB66580D5FDAF6, -555, -148 },
15241 { 0xF3E2F893DEC3F126, -529, -140 },
15242 { 0xB5B5ADA8AAFF80B8, -502, -132 },
15243 { 0x87625F056C7C4A8B, -475, -124 },
15244 { 0xC9BCFF6034C13053, -449, -116 },
15245 { 0x964E858C91BA2655, -422, -108 },
15246 { 0xDFF9772470297EBD, -396, -100 },
15247 { 0xA6DFBD9FB8E5B88F, -369, -92 },
15248 { 0xF8A95FCF88747D94, -343, -84 },
15249 { 0xB94470938FA89BCF, -316, -76 },
15250 { 0x8A08F0F8BF0F156B, -289, -68 },
15251 { 0xCDB02555653131B6, -263, -60 },
15252 { 0x993FE2C6D07B7FAC, -236, -52 },
15253 { 0xE45C10C42A2B3B06, -210, -44 },
15254 { 0xAA242499697392D3, -183, -36 },
15255 { 0xFD87B5F28300CA0E, -157, -28 },
15256 { 0xBCE5086492111AEB, -130, -20 },
15257 { 0x8CBCCC096F5088CC, -103, -12 },
15258 { 0xD1B71758E219652C, -77, -4 },
15259 { 0x9C40000000000000, -50, 4 },
15260 { 0xE8D4A51000000000, -24, 12 },
15261 { 0xAD78EBC5AC620000, 3, 20 },
15262 { 0x813F3978F8940984, 30, 28 },
15263 { 0xC097CE7BC90715B3, 56, 36 },
15264 { 0x8F7E32CE7BEA5C70, 83, 44 },
15265 { 0xD5D238A4ABE98068, 109, 52 },
15266 { 0x9F4F2726179A2245, 136, 60 },
15267 { 0xED63A231D4C4FB27, 162, 68 },
15268 { 0xB0DE65388CC8ADA8, 189, 76 },
15269 { 0x83C7088E1AAB65DB, 216, 84 },
15270 { 0xC45D1DF942711D9A, 242, 92 },
15271 { 0x924D692CA61BE758, 269, 100 },
15272 { 0xDA01EE641A708DEA, 295, 108 },
15273 { 0xA26DA3999AEF774A, 322, 116 },
15274 { 0xF209787BB47D6B85, 348, 124 },
15275 { 0xB454E4A179DD1877, 375, 132 },
15276 { 0x865B86925B9BC5C2, 402, 140 },
15277 { 0xC83553C5C8965D3D, 428, 148 },
15278 { 0x952AB45CFA97A0B3, 455, 156 },
15279 { 0xDE469FBD99A05FE3, 481, 164 },
15280 { 0xA59BC234DB398C25, 508, 172 },
15281 { 0xF6C69A72A3989F5C, 534, 180 },
15282 { 0xB7DCBF5354E9BECE, 561, 188 },
15283 { 0x88FCF317F22241E2, 588, 196 },
15284 { 0xCC20CE9BD35C78A5, 614, 204 },
15285 { 0x98165AF37B2153DF, 641, 212 },
15286 { 0xE2A0B5DC971F303A, 667, 220 },
15287 { 0xA8D9D1535CE3B396, 694, 228 },
15288 { 0xFB9B7CD9A4A7443C, 720, 236 },
15289 { 0xBB764C4CA7A44410, 747, 244 },
15290 { 0x8BAB8EEFB6409C1A, 774, 252 },
15291 { 0xD01FEF10A657842C, 800, 260 },
15292 { 0x9B10A4E5E9913129, 827, 268 },
15293 { 0xE7109BFBA19C0C9D, 853, 276 },
15294 { 0xAC2820D9623BF429, 880, 284 },
15295 { 0x80444B5E7AA7CF85, 907, 292 },
15296 { 0xBF21E44003ACDD2D, 933, 300 },
15297 { 0x8E679C2F5E44FF8F, 960, 308 },
15298 { 0xD433179D9C8CB841, 986, 316 },
15299 { 0x9E19DB92B4E31BA9, 1013, 324 },
15307 JSON_ASSERT(e >= -1500);
15308 JSON_ASSERT(e <= 1500);
15309 const int f = kAlpha - e - 1;
15310 const int k = (f * 78913) / (1 << 18) +
static_cast<int>(f > 0);
15312 const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep;
15313 JSON_ASSERT(index >= 0);
15314 JSON_ASSERT(
static_cast<std::size_t
>(index) < kCachedPowers.size());
15316 const cached_power cached = kCachedPowers[
static_cast<std::size_t
>(index)];
15317 JSON_ASSERT(kAlpha <= cached.e + e + 64);
15318 JSON_ASSERT(kGamma >= cached.e + e + 64);
15327 inline int find_largest_pow10(
const std::uint32_t n, std::uint32_t& pow10)
15330 if (n >= 1000000000)
15332 pow10 = 1000000000;
15336 if (n >= 100000000)
15381 inline void grisu2_round(
char* buf,
int len, std::uint64_t dist, std::uint64_t delta,
15382 std::uint64_t rest, std::uint64_t ten_k)
15384 JSON_ASSERT(len >= 1);
15385 JSON_ASSERT(dist <= delta);
15386 JSON_ASSERT(rest <= delta);
15387 JSON_ASSERT(ten_k > 0);
15409 && delta - rest >= ten_k
15410 && (rest + ten_k < dist || dist - rest > rest + ten_k - dist))
15412 JSON_ASSERT(buf[len - 1] !=
'0');
15422 inline void grisu2_digit_gen(
char* buffer,
int& length,
int& decimal_exponent,
15423 diyfp M_minus, diyfp w, diyfp M_plus)
15425 static_assert(kAlpha >= -60,
"internal error");
15426 static_assert(kGamma <= -32,
"internal error");
15440 JSON_ASSERT(M_plus.e >= kAlpha);
15441 JSON_ASSERT(M_plus.e <= kGamma);
15443 std::uint64_t delta = diyfp::sub(M_plus, M_minus).f;
15444 std::uint64_t dist = diyfp::sub(M_plus, w ).f;
15453 const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e);
15455 auto p1 =
static_cast<std::uint32_t
>(M_plus.f >> -one.e);
15456 std::uint64_t p2 = M_plus.f & (one.f - 1);
15462 JSON_ASSERT(p1 > 0);
15464 std::uint32_t pow10{};
15465 const int k = find_largest_pow10(p1, pow10);
15492 const std::uint32_t d = p1 / pow10;
15493 const std::uint32_t r = p1 % pow10;
15498 JSON_ASSERT(d <= 9);
15499 buffer[length++] =
static_cast<char>(
'0' + d);
15518 const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2;
15523 decimal_exponent += n;
15534 const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e;
15535 grisu2_round(buffer, length, dist, delta, rest, ten_n);
15585 JSON_ASSERT(p2 > delta);
15596 JSON_ASSERT(p2 <= (std::numeric_limits<std::uint64_t>::max)() / 10);
15598 const std::uint64_t d = p2 >> -one.e;
15599 const std::uint64_t r = p2 & (one.f - 1);
15605 JSON_ASSERT(d <= 9);
15606 buffer[length++] =
static_cast<char>(
'0' + d);
15631 decimal_exponent -= m;
15639 const std::uint64_t ten_m = one.f;
15640 grisu2_round(buffer, length, dist, delta, p2, ten_m);
15662 JSON_HEDLEY_NON_NULL(1)
15663 inline
void grisu2(
char* buf,
int& len,
int& decimal_exponent,
15664 diyfp m_minus, diyfp v, diyfp m_plus)
15666 JSON_ASSERT(m_plus.e == m_minus.e);
15667 JSON_ASSERT(m_plus.e == v.e);
15678 const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e);
15680 const diyfp c_minus_k(cached.f, cached.e);
15683 const diyfp w = diyfp::mul(v, c_minus_k);
15684 const diyfp w_minus = diyfp::mul(m_minus, c_minus_k);
15685 const diyfp w_plus = diyfp::mul(m_plus, c_minus_k);
15708 const diyfp M_minus(w_minus.f + 1, w_minus.e);
15709 const diyfp M_plus (w_plus.f - 1, w_plus.e );
15711 decimal_exponent = -cached.k;
15713 grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus);
15721 template<
typename FloatType>
15722 JSON_HEDLEY_NON_NULL(1)
15723 void grisu2(
char* buf,
int& len,
int& decimal_exponent, FloatType value)
15725 static_assert(diyfp::kPrecision >= std::numeric_limits<FloatType>::digits + 3,
15726 "internal error: not enough precision");
15728 JSON_ASSERT(std::isfinite(value));
15729 JSON_ASSERT(value > 0);
15748 const boundaries w = compute_boundaries(
static_cast<double>(value));
15750 const boundaries w = compute_boundaries(value);
15753 grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus);
15761 JSON_HEDLEY_NON_NULL(1)
15763 inline
char* append_exponent(
char* buf,
int e)
15765 JSON_ASSERT(e > -1000);
15766 JSON_ASSERT(e < 1000);
15778 auto k =
static_cast<std::uint32_t
>(e);
15784 *buf++ =
static_cast<char>(
'0' + k);
15788 *buf++ =
static_cast<char>(
'0' + k / 10);
15790 *buf++ =
static_cast<char>(
'0' + k);
15794 *buf++ =
static_cast<char>(
'0' + k / 100);
15796 *buf++ =
static_cast<char>(
'0' + k / 10);
15798 *buf++ =
static_cast<char>(
'0' + k);
15813 JSON_HEDLEY_NON_NULL(1)
15815 inline
char* format_buffer(
char* buf,
int len,
int decimal_exponent,
15816 int min_exp,
int max_exp)
15818 JSON_ASSERT(min_exp < 0);
15819 JSON_ASSERT(max_exp > 0);
15822 const int n = len + decimal_exponent;
15828 if (k <= n && n <= max_exp)
15833 std::memset(buf + k,
'0',
static_cast<size_t>(n) -
static_cast<size_t>(k));
15837 return buf + (
static_cast<size_t>(n) + 2);
15840 if (0 < n && n <= max_exp)
15845 JSON_ASSERT(k > n);
15847 std::memmove(buf + (
static_cast<size_t>(n) + 1), buf + n,
static_cast<size_t>(k) -
static_cast<size_t>(n));
15849 return buf + (
static_cast<size_t>(k) + 1U);
15852 if (min_exp < n && n <= 0)
15857 std::memmove(buf + (2 +
static_cast<size_t>(-n)), buf,
static_cast<size_t>(k));
15860 std::memset(buf + 2,
'0',
static_cast<size_t>(-n));
15861 return buf + (2U +
static_cast<size_t>(-n) +
static_cast<size_t>(k));
15876 std::memmove(buf + 2, buf + 1,
static_cast<size_t>(k) - 1);
15878 buf += 1 +
static_cast<size_t>(k);
15882 return append_exponent(buf, n - 1);
15897 template<
typename FloatType>
15898 JSON_HEDLEY_NON_NULL(1, 2)
15900 char* to_chars(
char* first, const
char* last, FloatType value)
15902 static_cast<void>(last);
15903 JSON_ASSERT(std::isfinite(value));
15906 if (std::signbit(value))
15921 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10);
15928 int decimal_exponent = 0;
15929 dtoa_impl::grisu2(first, len, decimal_exponent, value);
15931 JSON_ASSERT(len <= std::numeric_limits<FloatType>::max_digits10);
15934 constexpr
int kMinExp = -4;
15936 constexpr
int kMaxExp = std::numeric_limits<FloatType>::digits10;
15938 JSON_ASSERT(last - first >= kMaxExp + 2);
15939 JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits<FloatType>::max_digits10);
15940 JSON_ASSERT(last - first >= std::numeric_limits<FloatType>::max_digits10 + 6);
15942 return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp);
15970 enum class error_handler_t
15977 template<
typename BasicJsonType>
15980 using string_t =
typename BasicJsonType::string_t;
15981 using number_float_t =
typename BasicJsonType::number_float_t;
15982 using number_integer_t =
typename BasicJsonType::number_integer_t;
15983 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
15984 using binary_char_t =
typename BasicJsonType::binary_t::value_type;
15985 static constexpr std::uint8_t UTF8_ACCEPT = 0;
15986 static constexpr std::uint8_t UTF8_REJECT = 1;
15994 serializer(output_adapter_t<char> s,
const char ichar,
15995 error_handler_t error_handler_ = error_handler_t::strict)
15997 , loc(std::localeconv())
15998 , thousands_sep(loc->thousands_sep == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->thousands_sep)))
15999 , decimal_point(loc->decimal_point == nullptr ?
'\0' : std::char_traits<char>::to_char_type(* (loc->decimal_point)))
16000 , indent_char(ichar)
16001 , indent_string(512, indent_char)
16002 , error_handler(error_handler_)
16006 serializer(
const serializer&) =
delete;
16007 serializer& operator=(
const serializer&) =
delete;
16008 serializer(serializer&&) =
delete;
16009 serializer& operator=(serializer&&) =
delete;
16010 ~serializer() =
default;
16034 void dump(
const BasicJsonType& val,
16035 const bool pretty_print,
16036 const bool ensure_ascii,
16037 const unsigned int indent_step,
16038 const unsigned int current_indent = 0)
16040 switch (val.m_type)
16042 case value_t::object:
16044 if (val.m_value.object->empty())
16046 o->write_characters(
"{}", 2);
16052 o->write_characters(
"{\n", 2);
16055 const auto new_indent = current_indent + indent_step;
16056 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16058 indent_string.resize(indent_string.size() * 2,
' ');
16062 auto i = val.m_value.object->cbegin();
16063 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16065 o->write_characters(indent_string.c_str(), new_indent);
16066 o->write_character(
'\"');
16067 dump_escaped(i->first, ensure_ascii);
16068 o->write_characters(
"\": ", 3);
16069 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16070 o->write_characters(
",\n", 2);
16074 JSON_ASSERT(i != val.m_value.object->cend());
16075 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16076 o->write_characters(indent_string.c_str(), new_indent);
16077 o->write_character(
'\"');
16078 dump_escaped(i->first, ensure_ascii);
16079 o->write_characters(
"\": ", 3);
16080 dump(i->second,
true, ensure_ascii, indent_step, new_indent);
16082 o->write_character(
'\n');
16083 o->write_characters(indent_string.c_str(), current_indent);
16084 o->write_character(
'}');
16088 o->write_character(
'{');
16091 auto i = val.m_value.object->cbegin();
16092 for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
16094 o->write_character(
'\"');
16095 dump_escaped(i->first, ensure_ascii);
16096 o->write_characters(
"\":", 2);
16097 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16098 o->write_character(
',');
16102 JSON_ASSERT(i != val.m_value.object->cend());
16103 JSON_ASSERT(std::next(i) == val.m_value.object->cend());
16104 o->write_character(
'\"');
16105 dump_escaped(i->first, ensure_ascii);
16106 o->write_characters(
"\":", 2);
16107 dump(i->second,
false, ensure_ascii, indent_step, current_indent);
16109 o->write_character(
'}');
16115 case value_t::array:
16117 if (val.m_value.array->empty())
16119 o->write_characters(
"[]", 2);
16125 o->write_characters(
"[\n", 2);
16128 const auto new_indent = current_indent + indent_step;
16129 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16131 indent_string.resize(indent_string.size() * 2,
' ');
16135 for (
auto i = val.m_value.array->cbegin();
16136 i != val.m_value.array->cend() - 1; ++i)
16138 o->write_characters(indent_string.c_str(), new_indent);
16139 dump(*i,
true, ensure_ascii, indent_step, new_indent);
16140 o->write_characters(
",\n", 2);
16144 JSON_ASSERT(!val.m_value.array->empty());
16145 o->write_characters(indent_string.c_str(), new_indent);
16146 dump(val.m_value.array->back(),
true, ensure_ascii, indent_step, new_indent);
16148 o->write_character(
'\n');
16149 o->write_characters(indent_string.c_str(), current_indent);
16150 o->write_character(
']');
16154 o->write_character(
'[');
16157 for (
auto i = val.m_value.array->cbegin();
16158 i != val.m_value.array->cend() - 1; ++i)
16160 dump(*i,
false, ensure_ascii, indent_step, current_indent);
16161 o->write_character(
',');
16165 JSON_ASSERT(!val.m_value.array->empty());
16166 dump(val.m_value.array->back(),
false, ensure_ascii, indent_step, current_indent);
16168 o->write_character(
']');
16174 case value_t::string:
16176 o->write_character(
'\"');
16177 dump_escaped(*val.m_value.string, ensure_ascii);
16178 o->write_character(
'\"');
16182 case value_t::binary:
16186 o->write_characters(
"{\n", 2);
16189 const auto new_indent = current_indent + indent_step;
16190 if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
16192 indent_string.resize(indent_string.size() * 2,
' ');
16195 o->write_characters(indent_string.c_str(), new_indent);
16197 o->write_characters(
"\"bytes\": [", 10);
16199 if (!val.m_value.binary->empty())
16201 for (
auto i = val.m_value.binary->cbegin();
16202 i != val.m_value.binary->cend() - 1; ++i)
16205 o->write_characters(
", ", 2);
16207 dump_integer(val.m_value.binary->back());
16210 o->write_characters(
"],\n", 3);
16211 o->write_characters(indent_string.c_str(), new_indent);
16213 o->write_characters(
"\"subtype\": ", 11);
16214 if (val.m_value.binary->has_subtype())
16216 dump_integer(val.m_value.binary->subtype());
16220 o->write_characters(
"null", 4);
16222 o->write_character(
'\n');
16223 o->write_characters(indent_string.c_str(), current_indent);
16224 o->write_character(
'}');
16228 o->write_characters(
"{\"bytes\":[", 10);
16230 if (!val.m_value.binary->empty())
16232 for (
auto i = val.m_value.binary->cbegin();
16233 i != val.m_value.binary->cend() - 1; ++i)
16236 o->write_character(
',');
16238 dump_integer(val.m_value.binary->back());
16241 o->write_characters(
"],\"subtype\":", 12);
16242 if (val.m_value.binary->has_subtype())
16244 dump_integer(val.m_value.binary->subtype());
16245 o->write_character(
'}');
16249 o->write_characters(
"null}", 5);
16255 case value_t::boolean:
16257 if (val.m_value.boolean)
16259 o->write_characters(
"true", 4);
16263 o->write_characters(
"false", 5);
16268 case value_t::number_integer:
16270 dump_integer(val.m_value.number_integer);
16274 case value_t::number_unsigned:
16276 dump_integer(val.m_value.number_unsigned);
16280 case value_t::number_float:
16282 dump_float(val.m_value.number_float);
16286 case value_t::discarded:
16288 o->write_characters(
"<discarded>", 11);
16292 case value_t::null:
16294 o->write_characters(
"null", 4);
16299 JSON_ASSERT(
false);
16303 JSON_PRIVATE_UNLESS_TESTED:
16318 void dump_escaped(
const string_t& s,
const bool ensure_ascii)
16320 std::uint32_t codepoint{};
16321 std::uint8_t state = UTF8_ACCEPT;
16322 std::size_t bytes = 0;
16325 std::size_t bytes_after_last_accept = 0;
16326 std::size_t undumped_chars = 0;
16328 for (std::size_t i = 0; i < s.size(); ++i)
16330 const auto byte =
static_cast<uint8_t
>(s[i]);
16332 switch (decode(state, codepoint,
byte))
16340 string_buffer[bytes++] =
'\\';
16341 string_buffer[bytes++] =
'b';
16347 string_buffer[bytes++] =
'\\';
16348 string_buffer[bytes++] =
't';
16354 string_buffer[bytes++] =
'\\';
16355 string_buffer[bytes++] =
'n';
16361 string_buffer[bytes++] =
'\\';
16362 string_buffer[bytes++] =
'f';
16368 string_buffer[bytes++] =
'\\';
16369 string_buffer[bytes++] =
'r';
16375 string_buffer[bytes++] =
'\\';
16376 string_buffer[bytes++] =
'\"';
16382 string_buffer[bytes++] =
'\\';
16383 string_buffer[bytes++] =
'\\';
16391 if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F)))
16393 if (codepoint <= 0xFFFF)
16396 (std::snprintf)(string_buffer.data() + bytes, 7,
"\\u%04x",
16397 static_cast<std::uint16_t
>(codepoint));
16403 (std::snprintf)(string_buffer.data() + bytes, 13,
"\\u%04x\\u%04x",
16404 static_cast<std::uint16_t
>(0xD7C0u + (codepoint >> 10u)),
16405 static_cast<std::uint16_t
>(0xDC00u + (codepoint & 0x3FFu)));
16413 string_buffer[bytes++] = s[i];
16422 if (string_buffer.size() - bytes < 13)
16424 o->write_characters(string_buffer.data(), bytes);
16429 bytes_after_last_accept = bytes;
16430 undumped_chars = 0;
16436 switch (error_handler)
16438 case error_handler_t::strict:
16440 std::string sn(3,
'\0');
16442 (std::snprintf)(&sn[0], sn.size(),
"%.2X", byte);
16443 JSON_THROW(type_error::create(316,
"invalid UTF-8 byte at index " + std::to_string(i) +
": 0x" + sn, BasicJsonType()));
16446 case error_handler_t::ignore:
16447 case error_handler_t::replace:
16453 if (undumped_chars > 0)
16460 bytes = bytes_after_last_accept;
16462 if (error_handler == error_handler_t::replace)
16467 string_buffer[bytes++] =
'\\';
16468 string_buffer[bytes++] =
'u';
16469 string_buffer[bytes++] =
'f';
16470 string_buffer[bytes++] =
'f';
16471 string_buffer[bytes++] =
'f';
16472 string_buffer[bytes++] =
'd';
16476 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xEF');
16477 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBF');
16478 string_buffer[bytes++] = detail::binary_writer<BasicJsonType, char>::to_char_type(
'\xBD');
16484 if (string_buffer.size() - bytes < 13)
16486 o->write_characters(string_buffer.data(), bytes);
16490 bytes_after_last_accept = bytes;
16493 undumped_chars = 0;
16496 state = UTF8_ACCEPT;
16501 JSON_ASSERT(
false);
16511 string_buffer[bytes++] = s[i];
16520 if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
16525 o->write_characters(string_buffer.data(), bytes);
16531 switch (error_handler)
16533 case error_handler_t::strict:
16535 std::string sn(3,
'\0');
16537 (std::snprintf)(&sn[0], sn.size(),
"%.2X",
static_cast<std::uint8_t
>(s.back()));
16538 JSON_THROW(type_error::create(316,
"incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType()));
16541 case error_handler_t::ignore:
16544 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16548 case error_handler_t::replace:
16551 o->write_characters(string_buffer.data(), bytes_after_last_accept);
16555 o->write_characters(
"\\ufffd", 6);
16559 o->write_characters(
"\xEF\xBF\xBD", 3);
16565 JSON_ASSERT(
false);
16579 inline unsigned int count_digits(number_unsigned_t x) noexcept
16581 unsigned int n_digits = 1;
16590 return n_digits + 1;
16594 return n_digits + 2;
16598 return n_digits + 3;
16614 template <
typename NumberType, detail::enable_if_t <
16615 std::is_same<NumberType, number_unsigned_t>::value ||
16616 std::is_same<NumberType, number_integer_t>::value ||
16617 std::is_same<NumberType, binary_char_t>::value,
16619 void dump_integer(NumberType x)
16621 static constexpr std::array<std::array<char, 2>, 100> digits_to_99
16624 {{
'0',
'0'}}, {{
'0',
'1'}}, {{
'0',
'2'}}, {{
'0',
'3'}}, {{
'0',
'4'}}, {{
'0',
'5'}}, {{
'0',
'6'}}, {{
'0',
'7'}}, {{
'0',
'8'}}, {{
'0',
'9'}},
16625 {{
'1',
'0'}}, {{
'1',
'1'}}, {{
'1',
'2'}}, {{
'1',
'3'}}, {{
'1',
'4'}}, {{
'1',
'5'}}, {{
'1',
'6'}}, {{
'1',
'7'}}, {{
'1',
'8'}}, {{
'1',
'9'}},
16626 {{
'2',
'0'}}, {{
'2',
'1'}}, {{
'2',
'2'}}, {{
'2',
'3'}}, {{
'2',
'4'}}, {{
'2',
'5'}}, {{
'2',
'6'}}, {{
'2',
'7'}}, {{
'2',
'8'}}, {{
'2',
'9'}},
16627 {{
'3',
'0'}}, {{
'3',
'1'}}, {{
'3',
'2'}}, {{
'3',
'3'}}, {{
'3',
'4'}}, {{
'3',
'5'}}, {{
'3',
'6'}}, {{
'3',
'7'}}, {{
'3',
'8'}}, {{
'3',
'9'}},
16628 {{
'4',
'0'}}, {{
'4',
'1'}}, {{
'4',
'2'}}, {{
'4',
'3'}}, {{
'4',
'4'}}, {{
'4',
'5'}}, {{
'4',
'6'}}, {{
'4',
'7'}}, {{
'4',
'8'}}, {{
'4',
'9'}},
16629 {{
'5',
'0'}}, {{
'5',
'1'}}, {{
'5',
'2'}}, {{
'5',
'3'}}, {{
'5',
'4'}}, {{
'5',
'5'}}, {{
'5',
'6'}}, {{
'5',
'7'}}, {{
'5',
'8'}}, {{
'5',
'9'}},
16630 {{
'6',
'0'}}, {{
'6',
'1'}}, {{
'6',
'2'}}, {{
'6',
'3'}}, {{
'6',
'4'}}, {{
'6',
'5'}}, {{
'6',
'6'}}, {{
'6',
'7'}}, {{
'6',
'8'}}, {{
'6',
'9'}},
16631 {{
'7',
'0'}}, {{
'7',
'1'}}, {{
'7',
'2'}}, {{
'7',
'3'}}, {{
'7',
'4'}}, {{
'7',
'5'}}, {{
'7',
'6'}}, {{
'7',
'7'}}, {{
'7',
'8'}}, {{
'7',
'9'}},
16632 {{
'8',
'0'}}, {{
'8',
'1'}}, {{
'8',
'2'}}, {{
'8',
'3'}}, {{
'8',
'4'}}, {{
'8',
'5'}}, {{
'8',
'6'}}, {{
'8',
'7'}}, {{
'8',
'8'}}, {{
'8',
'9'}},
16633 {{
'9',
'0'}}, {{
'9',
'1'}}, {{
'9',
'2'}}, {{
'9',
'3'}}, {{
'9',
'4'}}, {{
'9',
'5'}}, {{
'9',
'6'}}, {{
'9',
'7'}}, {{
'9',
'8'}}, {{
'9',
'9'}},
16640 o->write_character(
'0');
16645 auto buffer_ptr = number_buffer.begin();
16647 const bool is_negative = std::is_same<NumberType, number_integer_t>::value && !(x >= 0);
16648 number_unsigned_t abs_value;
16650 unsigned int n_chars{};
16655 abs_value = remove_sign(
static_cast<number_integer_t
>(x));
16658 n_chars = 1 + count_digits(abs_value);
16662 abs_value =
static_cast<number_unsigned_t
>(x);
16663 n_chars = count_digits(abs_value);
16667 JSON_ASSERT(n_chars < number_buffer.size() - 1);
16671 buffer_ptr += n_chars;
16675 while (abs_value >= 100)
16677 const auto digits_index =
static_cast<unsigned>((abs_value % 100));
16679 *(--buffer_ptr) = digits_to_99[digits_index][1];
16680 *(--buffer_ptr) = digits_to_99[digits_index][0];
16683 if (abs_value >= 10)
16685 const auto digits_index =
static_cast<unsigned>(abs_value);
16686 *(--buffer_ptr) = digits_to_99[digits_index][1];
16687 *(--buffer_ptr) = digits_to_99[digits_index][0];
16691 *(--buffer_ptr) =
static_cast<char>(
'0' + abs_value);
16694 o->write_characters(number_buffer.data(), n_chars);
16705 void dump_float(number_float_t x)
16708 if (!std::isfinite(x))
16710 o->write_characters(
"null", 4);
16719 static constexpr
bool is_ieee_single_or_double
16720 = (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) ||
16721 (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);
16723 dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
16726 void dump_float(number_float_t x, std::true_type )
16728 auto* begin = number_buffer.data();
16729 auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
16731 o->write_characters(begin,
static_cast<size_t>(end - begin));
16734 void dump_float(number_float_t x, std::false_type )
16737 static constexpr
auto d = std::numeric_limits<number_float_t>::max_digits10;
16741 std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(),
"%.*g", d, x);
16744 JSON_ASSERT(len > 0);
16746 JSON_ASSERT(
static_cast<std::size_t
>(len) < number_buffer.size());
16749 if (thousands_sep !=
'\0')
16751 auto*
const end = std::remove(number_buffer.begin(),
16752 number_buffer.begin() + len, thousands_sep);
16753 std::fill(end, number_buffer.end(),
'\0');
16754 JSON_ASSERT((end - number_buffer.begin()) <= len);
16755 len = (end - number_buffer.begin());
16759 if (decimal_point !=
'\0' && decimal_point !=
'.')
16761 auto*
const dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
16762 if (dec_pos != number_buffer.end())
16768 o->write_characters(number_buffer.data(),
static_cast<std::size_t
>(len));
16771 const bool value_is_int_like =
16772 std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
16775 return c ==
'.' || c ==
'e';
16778 if (value_is_int_like)
16780 o->write_characters(
".0", 2);
16805 static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep,
const std::uint8_t
byte) noexcept
16807 static const std::array<std::uint8_t, 400> utf8d =
16810 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,
16811 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,
16812 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,
16813 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,
16814 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,
16815 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,
16816 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,
16817 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3,
16818 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8,
16819 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1,
16820 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,
16821 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,
16822 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,
16823 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
16827 JSON_ASSERT(
byte < utf8d.size());
16828 const std::uint8_t type = utf8d[byte];
16830 codep = (state != UTF8_ACCEPT)
16831 ? (
byte & 0x3fu) | (codep << 6u)
16832 : (0xFFu >> type) & (byte);
16834 std::size_t index = 256u +
static_cast<size_t>(state) * 16u +
static_cast<size_t>(type);
16835 JSON_ASSERT(index < 400);
16836 state = utf8d[index];
16845 number_unsigned_t remove_sign(number_unsigned_t x)
16847 JSON_ASSERT(
false);
16860 inline number_unsigned_t remove_sign(number_integer_t x) noexcept
16862 JSON_ASSERT(x < 0 && x < (std::numeric_limits<number_integer_t>::max)());
16863 return static_cast<number_unsigned_t
>(-(x + 1)) + 1;
16868 output_adapter_t<char> o =
nullptr;
16871 std::array<char, 64> number_buffer{{}};
16874 const std::lconv* loc =
nullptr;
16876 const char thousands_sep =
'\0';
16878 const char decimal_point =
'\0';
16881 std::array<char, 512> string_buffer{{}};
16884 const char indent_char;
16886 string_t indent_string;
16889 const error_handler_t error_handler;
16901 #include <functional>
16902 #include <initializer_list>
16903 #include <iterator>
16905 #include <stdexcept>
16906 #include <type_traits>
16918 template <
class Key,
class T,
class IgnoredLess = std::less<Key>,
16919 class Allocator = std::allocator<std::pair<const Key, T>>>
16924 using Container = std::vector<std::pair<const Key, T>, Allocator>;
16925 using typename Container::iterator;
16926 using typename Container::const_iterator;
16927 using typename Container::size_type;
16928 using typename Container::value_type;
16933 template <
class It>
16936 ordered_map(std::initializer_list<T> init,
const Allocator& alloc = Allocator() )
16941 for (
auto it = this->begin(); it != this->end(); ++it)
16943 if (it->first == key)
16945 return {it,
false};
16948 Container::emplace_back(key, t);
16949 return {--this->end(),
true};
16954 return emplace(key, T{}).first->second;
16964 for (
auto it = this->begin(); it != this->end(); ++it)
16966 if (it->first == key)
16972 JSON_THROW(std::out_of_range(
"key not found"));
16975 const T&
at(
const Key& key)
const
16977 for (
auto it = this->begin(); it != this->end(); ++it)
16979 if (it->first == key)
16985 JSON_THROW(std::out_of_range(
"key not found"));
16990 for (
auto it = this->begin(); it != this->end(); ++it)
16992 if (it->first == key)
16995 for (
auto next = it; ++next != this->end(); ++it)
16998 new (&*it) value_type{std::move(*next)};
17000 Container::pop_back();
17012 for (
auto next = it; ++next != this->end(); ++it)
17015 new (&*it) value_type{std::move(*next)};
17017 Container::pop_back();
17023 for (
auto it = this->begin(); it != this->end(); ++it)
17025 if (it->first == key)
17035 for (
auto it = this->begin(); it != this->end(); ++it)
17037 if (it->first == key)
17042 return Container::end();
17045 const_iterator
find(
const Key& key)
const
17047 for (
auto it = this->begin(); it != this->end(); ++it)
17049 if (it->first == key)
17054 return Container::end();
17057 std::pair<iterator, bool>
insert( value_type&& value )
17059 return emplace(value.first, std::move(value.second));
17062 std::pair<iterator, bool>
insert(
const value_type& value )
17064 for (
auto it = this->begin(); it != this->end(); ++it)
17066 if (it->first == value.first)
17068 return {it,
false};
17071 Container::push_back(value);
17072 return {--this->end(),
true};
17075 template<
typename InputIt>
17076 using require_input_iter =
typename std::enable_if<std::is_convertible<typename std::iterator_traits<InputIt>::iterator_category,
17077 std::input_iterator_tag>::value>::type;
17079 template<
typename InputIt,
typename = require_input_iter<InputIt>>
17082 for (
auto it = first; it != last; ++it)
17092 #if defined(JSON_HAS_CPP_17)
17093 #include <string_view>
17188 NLOHMANN_BASIC_JSON_TPL_DECLARATION
17193 friend ::nlohmann::json_pointer<basic_json>;
17195 template<
typename BasicJsonType,
typename InputType>
17196 friend class ::nlohmann::detail::parser;
17197 friend ::nlohmann::detail::serializer<basic_json>;
17198 template<
typename BasicJsonType>
17199 friend class ::nlohmann::detail::iter_impl;
17200 template<
typename BasicJsonType,
typename CharType>
17201 friend class ::nlohmann::detail::binary_writer;
17202 template<
typename BasicJsonType,
typename InputType,
typename SAX>
17203 friend class ::nlohmann::detail::binary_reader;
17204 template<
typename BasicJsonType>
17205 friend class ::nlohmann::detail::json_sax_dom_parser;
17206 template<
typename BasicJsonType>
17207 friend class ::nlohmann::detail::json_sax_dom_callback_parser;
17208 friend class ::nlohmann::detail::exception;
17211 using basic_json_t = NLOHMANN_BASIC_JSON_TPL;
17213 JSON_PRIVATE_UNLESS_TESTED:
17215 using lexer = ::nlohmann::detail::lexer_base<basic_json>;
17217 template<
typename InputAdapterType>
17218 static ::nlohmann::detail::parser<basic_json, InputAdapterType> parser(
17219 InputAdapterType adapter,
17220 detail::parser_callback_t<basic_json>cb =
nullptr,
17221 const bool allow_exceptions =
true,
17222 const bool ignore_comments =
false
17225 return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
17226 std::move(cb), allow_exceptions, ignore_comments);
17230 using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t;
17231 template<
typename BasicJsonType>
17232 using internal_iterator = ::nlohmann::detail::internal_iterator<BasicJsonType>;
17233 template<
typename BasicJsonType>
17234 using iter_impl = ::nlohmann::detail::iter_impl<BasicJsonType>;
17235 template<
typename Iterator>
17236 using iteration_proxy = ::nlohmann::detail::iteration_proxy<Iterator>;
17237 template<
typename Base>
using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator<Base>;
17239 template<
typename CharType>
17240 using output_adapter_t = ::nlohmann::detail::output_adapter_t<CharType>;
17242 template<
typename InputType>
17243 using binary_reader = ::nlohmann::detail::binary_reader<basic_json, InputType>;
17244 template<
typename CharType>
using binary_writer = ::nlohmann::detail::binary_writer<basic_json, CharType>;
17246 JSON_PRIVATE_UNLESS_TESTED:
17247 using serializer = ::nlohmann::detail::serializer<basic_json>;
17250 using value_t = detail::value_t;
17253 template<
typename T,
typename SFINAE>
17256 using error_handler_t = detail::error_handler_t;
17258 using cbor_tag_handler_t = detail::cbor_tag_handler_t;
17262 using input_format_t = detail::input_format_t;
17316 using pointer =
typename std::allocator_traits<allocator_type>::pointer;
17318 using const_pointer =
typename std::allocator_traits<allocator_type>::const_pointer;
17371 result[
"copyright"] =
"(C) 2013-2021 Niels Lohmann";
17372 result[
"name"] =
"JSON for Modern C++";
17373 result[
"url"] =
"https://github.com/nlohmann/json";
17374 result[
"version"][
"string"] =
17375 std::to_string(NLOHMANN_JSON_VERSION_MAJOR) +
"." +
17376 std::to_string(NLOHMANN_JSON_VERSION_MINOR) +
"." +
17377 std::to_string(NLOHMANN_JSON_VERSION_PATCH);
17378 result[
"version"][
"major"] = NLOHMANN_JSON_VERSION_MAJOR;
17379 result[
"version"][
"minor"] = NLOHMANN_JSON_VERSION_MINOR;
17380 result[
"version"][
"patch"] = NLOHMANN_JSON_VERSION_PATCH;
17383 result[
"platform"] =
"win32";
17384 #elif defined __linux__
17385 result[
"platform"] =
"linux";
17386 #elif defined __APPLE__
17387 result[
"platform"] =
"apple";
17388 #elif defined __unix__
17389 result[
"platform"] =
"unix";
17391 result[
"platform"] =
"unknown";
17394 #if defined(__ICC) || defined(__INTEL_COMPILER)
17395 result[
"compiler"] = {{
"family",
"icc"}, {
"version", __INTEL_COMPILER}};
17396 #elif defined(__clang__)
17397 result[
"compiler"] = {{
"family",
"clang"}, {
"version", __clang_version__}};
17398 #elif defined(__GNUC__) || defined(__GNUG__)
17399 result[
"compiler"] = {{
"family",
"gcc"}, {
"version", std::to_string(__GNUC__) +
"." + std::to_string(__GNUC_MINOR__) +
"." + std::to_string(__GNUC_PATCHLEVEL__)}};
17400 #elif defined(__HP_cc) || defined(__HP_aCC)
17401 result[
"compiler"] =
"hp"
17402 #elif defined(__IBMCPP__)
17403 result[
"compiler"] = {{
"family",
"ilecpp"}, {
"version", __IBMCPP__}};
17404 #elif defined(_MSC_VER)
17405 result[
"compiler"] = {{
"family",
"msvc"}, {
"version", _MSC_VER}};
17406 #elif defined(__PGI)
17407 result[
"compiler"] = {{
"family",
"pgcpp"}, {
"version", __PGI}};
17408 #elif defined(__SUNPRO_CC)
17409 result[
"compiler"] = {{
"family",
"sunpro"}, {
"version", __SUNPRO_CC}};
17411 result[
"compiler"] = {{
"family",
"unknown"}, {
"version",
"unknown"}};
17415 result[
"compiler"][
"c++"] = std::to_string(__cplusplus);
17417 result[
"compiler"][
"c++"] =
"unknown";
17432 #if defined(JSON_HAS_CPP_14)
17526 AllocatorType<std::pair<
const StringType,
17573 using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
17940 template<
typename T,
typename... Args>
17942 static T* create(Args&& ... args)
17944 AllocatorType<T> alloc;
17945 using AllocatorTraits = std::allocator_traits<AllocatorType<T>>;
17947 auto deleter = [&](T * obj)
17949 AllocatorTraits::deallocate(alloc, obj, 1);
17951 std::unique_ptr<T, decltype(deleter)> obj(AllocatorTraits::allocate(alloc, 1), deleter);
17952 AllocatorTraits::construct(alloc, obj.get(), std::forward<Args>(args)...);
17953 JSON_ASSERT(obj !=
nullptr);
17954 return obj.release();
17961 JSON_PRIVATE_UNLESS_TESTED:
18007 json_value() =
default;
18009 json_value(
boolean_t v) noexcept : boolean(v) {}
18021 case value_t::object:
18023 object = create<object_t>();
18027 case value_t::array:
18029 array = create<array_t>();
18033 case value_t::string:
18035 string = create<string_t>(
"");
18039 case value_t::binary:
18041 binary = create<binary_t>();
18045 case value_t::boolean:
18051 case value_t::number_integer:
18057 case value_t::number_unsigned:
18063 case value_t::number_float:
18069 case value_t::null:
18078 if (JSON_HEDLEY_UNLIKELY(t == value_t::null))
18080 JSON_THROW(other_error::create(500,
"961c151d2e87f2686a955a9be24d316f1362bf21 3.9.1",
basic_json()));
18090 string = create<string_t>(
value);
18096 string = create<string_t>(std::move(
value));
18102 object = create<object_t>(
value);
18108 object = create<object_t>(std::move(
value));
18114 array = create<array_t>(
value);
18120 array = create<array_t>(std::move(
value));
18126 binary = create<binary_t>(
value);
18132 binary = create<binary_t>(std::move(
value));
18138 binary = create<binary_t>(
value);
18144 binary = create<binary_t>(std::move(
value));
18147 void destroy(
value_t t) noexcept
18150 std::vector<basic_json> stack;
18153 if (t == value_t::array)
18155 stack.reserve(array->size());
18156 std::move(array->begin(), array->end(), std::back_inserter(stack));
18158 else if (t == value_t::object)
18161 for (
auto&& it : *
object)
18163 stack.push_back(std::move(it.second));
18167 while (!stack.empty())
18170 basic_json current_item(std::move(stack.back()));
18175 if (current_item.is_array())
18177 std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(),
18178 std::back_inserter(stack));
18180 current_item.m_value.array->clear();
18182 else if (current_item.is_object())
18184 for (
auto&& it : *current_item.m_value.object)
18186 stack.push_back(std::move(it.second));
18189 current_item.m_value.object->clear();
18198 case value_t::object:
18200 AllocatorType<object_t> alloc;
18201 std::allocator_traits<decltype(alloc)>::destroy(alloc,
object);
18202 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
object, 1);
18206 case value_t::array:
18208 AllocatorType<array_t> alloc;
18209 std::allocator_traits<decltype(alloc)>::destroy(alloc, array);
18210 std::allocator_traits<decltype(alloc)>::deallocate(alloc, array, 1);
18214 case value_t::string:
18216 AllocatorType<string_t> alloc;
18217 std::allocator_traits<decltype(alloc)>::destroy(alloc,
string);
18218 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
string, 1);
18222 case value_t::binary:
18224 AllocatorType<binary_t> alloc;
18225 std::allocator_traits<decltype(alloc)>::destroy(alloc, binary);
18226 std::allocator_traits<decltype(alloc)>::deallocate(alloc, binary, 1);
18257 void assert_invariant(
bool check_parents =
true) const noexcept
18259 JSON_ASSERT(m_type != value_t::object ||
m_value.object !=
nullptr);
18260 JSON_ASSERT(m_type != value_t::array ||
m_value.array !=
nullptr);
18261 JSON_ASSERT(m_type != value_t::string ||
m_value.string !=
nullptr);
18262 JSON_ASSERT(m_type != value_t::binary ||
m_value.binary !=
nullptr);
18264 #if JSON_DIAGNOSTICS
18270 return j.m_parent ==
this;
18275 static_cast<void>(check_parents);
18280 #if JSON_DIAGNOSTICS
18283 case value_t::array:
18285 for (
auto& element : *
m_value.array)
18287 element.m_parent =
this;
18292 case value_t::object:
18294 for (
auto& element : *
m_value.object)
18296 element.second.m_parent =
this;
18309 #if JSON_DIAGNOSTICS
18310 for (
typename iterator::difference_type i = 0; i <
count; ++i)
18312 (it + i)->m_parent =
this;
18315 static_cast<void>(
count);
18322 #if JSON_DIAGNOSTICS
18325 static_cast<void>(j);
18350 using parse_event_t = detail::parse_event_t;
18445 assert_invariant();
18469 assert_invariant();
18534 template <
typename CompatibleType,
18535 typename U = detail::uncvref_t<CompatibleType>,
18536 detail::enable_if_t <
18537 !detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value,
int > = 0 >
18539 JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
18540 std::forward<CompatibleType>(val))))
18542 JSONSerializer<U>::to_json(*
this, std::forward<CompatibleType>(val));
18544 assert_invariant();
18573 template <
typename BasicJsonType,
18574 detail::enable_if_t <
18575 detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value,
int > = 0 >
18578 using other_boolean_t =
typename BasicJsonType::boolean_t;
18579 using other_number_float_t =
typename BasicJsonType::number_float_t;
18580 using other_number_integer_t =
typename BasicJsonType::number_integer_t;
18581 using other_number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
18582 using other_string_t =
typename BasicJsonType::string_t;
18583 using other_object_t =
typename BasicJsonType::object_t;
18584 using other_array_t =
typename BasicJsonType::array_t;
18585 using other_binary_t =
typename BasicJsonType::binary_t;
18587 switch (val.type())
18589 case value_t::boolean:
18590 JSONSerializer<other_boolean_t>::to_json(*
this, val.template get<other_boolean_t>());
18592 case value_t::number_float:
18593 JSONSerializer<other_number_float_t>::to_json(*
this, val.template get<other_number_float_t>());
18595 case value_t::number_integer:
18596 JSONSerializer<other_number_integer_t>::to_json(*
this, val.template get<other_number_integer_t>());
18598 case value_t::number_unsigned:
18599 JSONSerializer<other_number_unsigned_t>::to_json(*
this, val.template get<other_number_unsigned_t>());
18601 case value_t::string:
18602 JSONSerializer<other_string_t>::to_json(*
this, val.template get_ref<const other_string_t&>());
18604 case value_t::object:
18605 JSONSerializer<other_object_t>::to_json(*
this, val.template get_ref<const other_object_t&>());
18607 case value_t::array:
18608 JSONSerializer<other_array_t>::to_json(*
this, val.template get_ref<const other_array_t&>());
18610 case value_t::binary:
18611 JSONSerializer<other_binary_t>::to_json(*
this, val.template get_ref<const other_binary_t&>());
18613 case value_t::null:
18616 case value_t::discarded:
18617 m_type = value_t::discarded;
18620 JSON_ASSERT(
false);
18623 assert_invariant();
18701 bool type_deduction =
true,
18702 value_t manual_type = value_t::array)
18706 bool is_an_object = std::all_of(init.begin(), init.end(),
18707 [](
const detail::json_ref<basic_json>& element_ref)
18709 return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string();
18713 if (!type_deduction)
18716 if (manual_type == value_t::array)
18718 is_an_object =
false;
18722 if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object))
18724 JSON_THROW(type_error::create(301,
"cannot create object from initializer list",
basic_json()));
18731 m_type = value_t::object;
18734 for (
auto& element_ref : init)
18736 auto element = element_ref.moved_or_copied();
18738 std::move(*((*element.m_value.array)[0].m_value.string)),
18739 std::move((*element.m_value.array)[1]));
18745 m_type = value_t::array;
18746 m_value.array = create<array_t>(init.begin(), init.end());
18750 assert_invariant();
18784 res.m_type = value_t::binary;
18785 res.m_value = init;
18821 res.m_type = value_t::binary;
18822 res.m_value =
binary_t(init, subtype);
18831 res.m_type = value_t::binary;
18832 res.m_value = std::move(init);
18841 res.m_type = value_t::binary;
18842 res.m_value =
binary_t(std::move(init), subtype);
18886 return basic_json(init,
false, value_t::array);
18930 return basic_json(init,
false, value_t::object);
18956 : m_type(value_t::array)
18958 m_value.array = create<array_t>(cnt, val);
18960 assert_invariant();
19018 template <
class InputIT,
typename std::enable_if <
19019 std::is_same<InputIT, typename basic_json_t::iterator>::value ||
19020 std::is_same<InputIT, typename basic_json_t::const_iterator>::value,
int >
::type = 0 >
19023 JSON_ASSERT(first.m_object !=
nullptr);
19024 JSON_ASSERT(last.m_object !=
nullptr);
19027 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
19029 JSON_THROW(invalid_iterator::create(201,
"iterators are not compatible",
basic_json()));
19033 m_type = first.m_object->m_type;
19038 case value_t::boolean:
19039 case value_t::number_float:
19040 case value_t::number_integer:
19041 case value_t::number_unsigned:
19042 case value_t::string:
19044 if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin()
19045 || !last.m_it.primitive_iterator.is_end()))
19047 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *first.m_object));
19058 case value_t::number_integer:
19060 m_value.number_integer = first.m_object->m_value.number_integer;
19064 case value_t::number_unsigned:
19066 m_value.number_unsigned = first.m_object->m_value.number_unsigned;
19070 case value_t::number_float:
19072 m_value.number_float = first.m_object->m_value.number_float;
19076 case value_t::boolean:
19078 m_value.boolean = first.m_object->m_value.boolean;
19082 case value_t::string:
19084 m_value = *first.m_object->m_value.string;
19088 case value_t::object:
19090 m_value.object = create<object_t>(first.m_it.object_iterator,
19091 last.m_it.object_iterator);
19095 case value_t::array:
19097 m_value.array = create<array_t>(first.m_it.array_iterator,
19098 last.m_it.array_iterator);
19102 case value_t::binary:
19104 m_value = *first.m_object->m_value.binary;
19109 JSON_THROW(invalid_iterator::create(206,
"cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object));
19113 assert_invariant();
19121 template<
typename JsonRef,
19122 detail::enable_if_t<detail::conjunction<detail::is_json_ref<JsonRef>,
19123 std::is_same<typename JsonRef::value_type, basic_json>>
::value,
int> = 0 >
19152 : m_type(other.m_type)
19155 other.assert_invariant();
19159 case value_t::object:
19165 case value_t::array:
19171 case value_t::string:
19177 case value_t::boolean:
19183 case value_t::number_integer:
19189 case value_t::number_unsigned:
19195 case value_t::number_float:
19201 case value_t::binary:
19212 assert_invariant();
19242 : m_type(std::move(other.m_type)),
19243 m_value(std::move(other.m_value))
19246 other.assert_invariant(
false);
19249 other.m_type = value_t::null;
19250 other.m_value = {};
19253 assert_invariant();
19280 std::is_nothrow_move_constructible<value_t>::value&&
19281 std::is_nothrow_move_assignable<value_t>::value&&
19282 std::is_nothrow_move_constructible<json_value>::value&&
19283 std::is_nothrow_move_assignable<json_value>::value
19287 other.assert_invariant();
19290 swap(m_type, other.m_type);
19294 assert_invariant();
19315 assert_invariant(
false);
19378 const char indent_char =
' ',
19379 const bool ensure_ascii =
false,
19380 const error_handler_t error_handler = error_handler_t::strict)
const
19383 serializer s(detail::output_adapter<char, string_t>(result), indent_char, error_handler);
19387 s.dump(*
this,
true, ensure_ascii,
static_cast<unsigned int>(indent));
19391 s.dump(*
this,
false, ensure_ascii, 0);
19430 constexpr value_t
type() const noexcept
19512 return m_type == value_t::null;
19534 return m_type == value_t::boolean;
19593 return m_type == value_t::number_integer || m_type == value_t::number_unsigned;
19621 return m_type == value_t::number_unsigned;
19649 return m_type == value_t::number_float;
19671 return m_type == value_t::object;
19693 return m_type == value_t::array;
19715 return m_type == value_t::string;
19737 return m_type == value_t::binary;
19764 return m_type == value_t::discarded;
19808 JSON_THROW(type_error::create(302,
"type must be boolean, but is " + std::string(
type_name()), *
this));
19830 constexpr
const array_t* get_impl_ptr(
const array_t* )
const noexcept
19918 template<
typename ReferenceType,
typename ThisType>
19919 static ReferenceType get_ref_impl(ThisType& obj)
19922 auto* ptr = obj.template get_ptr<typename std::add_pointer<ReferenceType>::type>();
19924 if (JSON_HEDLEY_LIKELY(ptr !=
nullptr))
19929 JSON_THROW(type_error::create(303,
"incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj));
19963 template<
typename PointerType,
typename std::enable_if<
19964 std::is_pointer<PointerType>::value,
int>
::type = 0>
19965 auto get_ptr() noexcept -> decltype(std::declval<basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19968 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
19975 template <
typename PointerType,
typename std::enable_if <
19976 std::is_pointer<PointerType>::value&&
19977 std::is_const<typename std::remove_pointer<PointerType>::type>
::value,
int >
::type = 0 >
19978 constexpr
auto get_ptr() const noexcept -> decltype(std::declval<const basic_json_t&>().get_impl_ptr(std::declval<PointerType>()))
19981 return get_impl_ptr(
static_cast<PointerType
>(
nullptr));
20023 template <
typename ValueType,
20024 detail::enable_if_t <
20025 detail::is_default_constructible<ValueType>::value&&
20026 detail::has_from_json<basic_json_t, ValueType>::value,
20028 ValueType get_impl(detail::priority_tag<0> )
const noexcept(noexcept(
20029 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
20032 JSONSerializer<ValueType>::from_json(*
this, ret);
20066 template <
typename ValueType,
20067 detail::enable_if_t <
20068 detail::has_non_default_from_json<basic_json_t, ValueType>::value,
20070 ValueType get_impl(detail::priority_tag<1> )
const noexcept(noexcept(
20071 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
20073 return JSONSerializer<ValueType>::from_json(*
this);
20091 template <
typename BasicJsonType,
20092 detail::enable_if_t <
20093 detail::is_basic_json<BasicJsonType>::value,
20095 BasicJsonType get_impl(detail::priority_tag<2> )
const
20114 template<
typename BasicJsonType,
20115 detail::enable_if_t<
20116 std::is_same<BasicJsonType, basic_json_t>::value,
20118 basic_json get_impl(detail::priority_tag<3> )
const
20127 template<
typename PointerType,
20128 detail::enable_if_t<
20129 std::is_pointer<PointerType>::value,
20131 constexpr
auto get_impl(detail::priority_tag<4> )
const noexcept
20132 -> decltype(std::declval<const basic_json_t&>().
template get_ptr<PointerType>())
20135 return get_ptr<PointerType>();
20162 template <
typename ValueTypeCV,
typename ValueType = detail::uncvref_t<ValueTypeCV>>
20163 #if defined(JSON_HAS_CPP_14)
20167 noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
20168 -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
20173 static_assert(!std::is_reference<ValueTypeCV>::value,
20174 "get() cannot be used with reference types, you might want to use get_ref()");
20175 return get_impl<ValueType>(detail::priority_tag<4> {});
20205 template<
typename PointerType,
typename std::enable_if<
20206 std::is_pointer<PointerType>::value,
int>
::type = 0>
20207 auto get() noexcept -> decltype(std::declval<basic_json_t&>().template
get_ptr<PointerType>())
20210 return get_ptr<PointerType>();
20246 template <
typename ValueType,
20247 detail::enable_if_t <
20248 !detail::is_basic_json<ValueType>::value&&
20249 detail::has_from_json<basic_json_t, ValueType>::value,
20251 ValueType &
get_to(ValueType& v)
const noexcept(noexcept(
20252 JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
20254 JSONSerializer<ValueType>::from_json(*
this, v);
20260 template<
typename ValueType,
20261 detail::enable_if_t <
20262 detail::is_basic_json<ValueType>::value,
20271 typename T, std::size_t N,
20272 typename Array = T (&)[N],
20273 detail::enable_if_t <
20274 detail::has_from_json<basic_json_t, Array>::value,
int > = 0 >
20276 noexcept(noexcept(JSONSerializer<Array>::from_json(
20277 std::declval<const basic_json_t&>(), v)))
20279 JSONSerializer<Array>::from_json(*
this, v);
20309 template<
typename ReferenceType,
typename std::enable_if<
20310 std::is_reference<ReferenceType>::value,
int>
::type = 0>
20314 return get_ref_impl<ReferenceType>(*
this);
20321 template <
typename ReferenceType,
typename std::enable_if <
20322 std::is_reference<ReferenceType>::value&&
20323 std::is_const<typename std::remove_reference<ReferenceType>::type>
::value,
int >
::type = 0 >
20327 return get_ref_impl<ReferenceType>(*
this);
20359 template <
typename ValueType,
typename std::enable_if <
20360 !std::is_pointer<ValueType>::value&&
20361 !std::is_same<ValueType, detail::json_ref<basic_json>>
::value&&
20362 !std::is_same<ValueType, typename string_t::value_type>::value&&
20363 !detail::is_basic_json<ValueType>::value
20364 && !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>
::value
20365 #if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
20366 && !std::is_same<ValueType, typename std::string_view>::value
20368 && detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
20370 JSON_EXPLICIT
operator ValueType()
const
20373 return get<ValueType>();
20389 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20392 return *get_ptr<binary_t*>();
20400 JSON_THROW(type_error::create(302,
"type must be binary, but is " + std::string(
type_name()), *
this));
20403 return *get_ptr<const binary_t*>();
20446 if (JSON_HEDLEY_LIKELY(
is_array()))
20450 return set_parent(
m_value.array->at(idx));
20452 JSON_CATCH (std::out_of_range&)
20455 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20460 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20493 if (JSON_HEDLEY_LIKELY(
is_array()))
20497 return m_value.array->at(idx);
20499 JSON_CATCH (std::out_of_range&)
20502 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
20507 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20541 reference at(
const typename object_t::key_type& key)
20548 return set_parent(
m_value.object->at(key));
20550 JSON_CATCH (std::out_of_range&)
20553 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
20558 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20599 return m_value.object->at(key);
20601 JSON_CATCH (std::out_of_range&)
20604 JSON_THROW(out_of_range::create(403,
"key '" + key +
"' not found", *
this));
20609 JSON_THROW(type_error::create(304,
"cannot use at() with " + std::string(
type_name()), *
this));
20643 m_type = value_t::array;
20644 m_value.array = create<array_t>();
20645 assert_invariant();
20649 if (JSON_HEDLEY_LIKELY(
is_array()))
20652 if (idx >=
m_value.array->size())
20654 #if JSON_DIAGNOSTICS
20656 const auto previous_size =
m_value.array->size();
20658 m_value.array->resize(idx + 1);
20660 #if JSON_DIAGNOSTICS
20662 set_parents(
begin() +
static_cast<typename iterator::difference_type
>(previous_size),
static_cast<typename iterator::difference_type
>(idx + 1 - previous_size));
20666 return m_value.array->operator[](idx);
20669 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
20694 if (JSON_HEDLEY_LIKELY(
is_array()))
20696 return m_value.array->operator[](idx);
20699 JSON_THROW(type_error::create(305,
"cannot use operator[] with a numeric argument with " + std::string(
type_name()), *
this));
20734 m_type = value_t::object;
20735 m_value.object = create<object_t>();
20736 assert_invariant();
20742 return set_parent(
m_value.object->operator[](key));
20745 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20783 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20784 return m_value.object->find(key)->second;
20787 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20817 template<
typename T>
20818 JSON_HEDLEY_NON_NULL(2)
20824 m_type = value_t::object;
20826 assert_invariant();
20832 return set_parent(
m_value.object->operator[](key));
20835 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20868 template<
typename T>
20869 JSON_HEDLEY_NON_NULL(2)
20875 JSON_ASSERT(
m_value.object->find(key) !=
m_value.object->end());
20876 return m_value.object->find(key)->second;
20879 JSON_THROW(type_error::create(305,
"cannot use operator[] with a string argument with " + std::string(
type_name()), *
this));
20933 template <
class ValueType,
typename std::enable_if <
20934 detail::is_getable<basic_json_t, ValueType>::value
20935 && !std::is_same<value_t, ValueType>::value,
int >
::type = 0 >
20936 ValueType
value(
const typename object_t::key_type& key,
const ValueType& default_value)
const
20942 const auto it =
find(key);
20945 return it->template get<ValueType>();
20948 return default_value;
20951 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
20958 string_t value(
const typename object_t::key_type& key,
const char* default_value)
const
21006 template<
class ValueType,
typename std::enable_if<
21007 detail::is_getable<basic_json_t, ValueType>::value,
int>
::type = 0>
21016 return ptr.get_checked(
this).template get<ValueType>();
21020 return default_value;
21024 JSON_THROW(type_error::create(306,
"cannot use value() with " + std::string(
type_name()), *
this));
21031 JSON_HEDLEY_NON_NULL(3)
21169 template <
class IteratorType,
typename std::enable_if <
21170 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21171 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21173 IteratorType
erase(IteratorType pos)
21176 if (JSON_HEDLEY_UNLIKELY(
this != pos.m_object))
21178 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
21181 IteratorType result =
end();
21185 case value_t::boolean:
21186 case value_t::number_float:
21187 case value_t::number_integer:
21188 case value_t::number_unsigned:
21189 case value_t::string:
21190 case value_t::binary:
21192 if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin()))
21194 JSON_THROW(invalid_iterator::create(205,
"iterator out of range", *
this));
21199 AllocatorType<string_t> alloc;
21200 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
21201 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21206 AllocatorType<binary_t> alloc;
21207 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
21208 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21212 m_type = value_t::null;
21213 assert_invariant();
21217 case value_t::object:
21219 result.m_it.object_iterator =
m_value.object->erase(pos.m_it.object_iterator);
21223 case value_t::array:
21225 result.m_it.array_iterator =
m_value.array->erase(pos.m_it.array_iterator);
21230 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21282 template <
class IteratorType,
typename std::enable_if <
21283 std::is_same<IteratorType, typename basic_json_t::iterator>::value ||
21284 std::is_same<IteratorType, typename basic_json_t::const_iterator>::value,
int >
::type
21286 IteratorType
erase(IteratorType first, IteratorType last)
21289 if (JSON_HEDLEY_UNLIKELY(
this != first.m_object ||
this != last.m_object))
21291 JSON_THROW(invalid_iterator::create(203,
"iterators do not fit current value", *
this));
21294 IteratorType result =
end();
21298 case value_t::boolean:
21299 case value_t::number_float:
21300 case value_t::number_integer:
21301 case value_t::number_unsigned:
21302 case value_t::string:
21303 case value_t::binary:
21305 if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin()
21306 || !last.m_it.primitive_iterator.is_end()))
21308 JSON_THROW(invalid_iterator::create(204,
"iterators out of range", *
this));
21313 AllocatorType<string_t> alloc;
21314 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.string);
21315 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.string, 1);
21320 AllocatorType<binary_t> alloc;
21321 std::allocator_traits<decltype(alloc)>::destroy(alloc,
m_value.binary);
21322 std::allocator_traits<decltype(alloc)>::deallocate(alloc,
m_value.binary, 1);
21326 m_type = value_t::null;
21327 assert_invariant();
21331 case value_t::object:
21333 result.m_it.object_iterator =
m_value.object->erase(first.m_it.object_iterator,
21334 last.m_it.object_iterator);
21338 case value_t::array:
21340 result.m_it.array_iterator =
m_value.array->erase(first.m_it.array_iterator,
21341 last.m_it.array_iterator);
21346 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21386 return m_value.object->erase(key);
21389 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21419 if (JSON_HEDLEY_LIKELY(
is_array()))
21421 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
21423 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", *
this));
21430 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
21468 template<
typename KeyT>
21471 auto result =
end();
21475 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21485 template<
typename KeyT>
21488 auto result =
cend();
21492 result.m_it.object_iterator =
m_value.object->find(std::forward<KeyT>(key));
21519 template<
typename KeyT>
21551 template <
typename KeyT,
typename std::enable_if <
21586 return ptr.contains(
this);
21626 result.set_begin();
21666 result.set_begin();
21930 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21933 return ref.items();
21939 JSON_HEDLEY_DEPRECATED_FOR(3.1.0,
items())
21942 return ref.items();
22013 iteration_proxy<iterator>
items() noexcept
22015 return iteration_proxy<iterator>(*
this);
22021 iteration_proxy<const_iterator>
items() const noexcept
22023 return iteration_proxy<const_iterator>(*
this);
22078 bool empty() const noexcept
22082 case value_t::null:
22088 case value_t::array:
22091 return m_value.array->empty();
22094 case value_t::object:
22097 return m_value.object->empty();
22155 case value_t::null:
22161 case value_t::array:
22164 return m_value.array->size();
22167 case value_t::object:
22170 return m_value.object->size();
22226 case value_t::array:
22229 return m_value.array->max_size();
22232 case value_t::object:
22235 return m_value.object->max_size();
22293 void clear() noexcept
22297 case value_t::number_integer:
22303 case value_t::number_unsigned:
22309 case value_t::number_float:
22315 case value_t::boolean:
22321 case value_t::string:
22327 case value_t::binary:
22333 case value_t::array:
22339 case value_t::object:
22375 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22381 m_type = value_t::array;
22383 assert_invariant();
22387 m_value.array->push_back(std::move(val));
22388 set_parent(
m_value.array->back());
22411 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22417 m_type = value_t::array;
22419 assert_invariant();
22423 m_value.array->push_back(val);
22424 set_parent(
m_value.array->back());
22457 void push_back(
const typename object_t::value_type& val)
22462 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
22468 m_type = value_t::object;
22470 assert_invariant();
22474 auto res =
m_value.object->insert(val);
22475 set_parent(res.first->second);
22515 if (
is_object() && init.size() == 2 && (*init.begin())->is_string())
22517 basic_json&& key = init.begin()->moved_or_copied();
22518 push_back(
typename object_t::value_type(
22519 std::move(key.get_ref<
string_t&>()), (init.begin() + 1)->moved_or_copied()));
22560 template<
class... Args>
22566 JSON_THROW(type_error::create(311,
"cannot use emplace_back() with " + std::string(
type_name()), *
this));
22572 m_type = value_t::array;
22574 assert_invariant();
22578 #ifdef JSON_HAS_CPP_17
22579 return set_parent(
m_value.array->emplace_back(std::forward<Args>(args)...));
22581 m_value.array->emplace_back(std::forward<Args>(args)...);
22582 return set_parent(
m_value.array->back());
22613 template<
class... Args>
22614 std::pair<iterator, bool>
emplace(Args&& ... args)
22619 JSON_THROW(type_error::create(311,
"cannot use emplace() with " + std::string(
type_name()), *
this));
22625 m_type = value_t::object;
22627 assert_invariant();
22631 auto res =
m_value.object->emplace(std::forward<Args>(args)...);
22632 set_parent(res.first->second);
22636 it.m_it.object_iterator = res.first;
22639 return {it, res.second};
22645 template<
typename... Args>
22649 JSON_ASSERT(
m_value.array !=
nullptr);
22651 auto insert_pos = std::distance(
m_value.array->begin(), pos.m_it.array_iterator);
22652 m_value.array->insert(pos.m_it.array_iterator, std::forward<Args>(args)...);
22653 result.m_it.array_iterator =
m_value.array->begin() + insert_pos;
22687 if (JSON_HEDLEY_LIKELY(
is_array()))
22690 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22692 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22696 return set_parents(
insert_iterator(pos, val),
static_cast<typename iterator::difference_type
>(1));
22699 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22708 return insert(pos, val);
22738 if (JSON_HEDLEY_LIKELY(
is_array()))
22741 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22743 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22747 return set_parents(
insert_iterator(pos, cnt, val),
static_cast<typename iterator::difference_type
>(cnt));
22750 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22786 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22788 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22792 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22794 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22798 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22800 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22803 if (JSON_HEDLEY_UNLIKELY(first.m_object ==
this))
22805 JSON_THROW(invalid_iterator::create(211,
"passed iterators may not belong to container", *
this));
22809 return set_parents(
insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator), std::distance(first, last));
22839 if (JSON_HEDLEY_UNLIKELY(!
is_array()))
22841 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22845 if (JSON_HEDLEY_UNLIKELY(pos.m_object !=
this))
22847 JSON_THROW(invalid_iterator::create(202,
"iterator does not fit current value", *
this));
22851 return set_parents(
insert_iterator(pos, ilist.begin(), ilist.end()),
static_cast<typename iterator::difference_type
>(ilist.size()));
22880 if (JSON_HEDLEY_UNLIKELY(!
is_object()))
22882 JSON_THROW(type_error::create(309,
"cannot use insert() with " + std::string(
type_name()), *
this));
22886 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22888 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22892 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()))
22894 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
22897 m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator);
22924 m_type = value_t::object;
22925 m_value.object = create<object_t>();
22926 assert_invariant();
22931 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
22933 if (JSON_HEDLEY_UNLIKELY(!j.is_object()))
22935 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(j.type_name()), *
this));
22938 for (
auto it = j.cbegin(); it != j.cend(); ++it)
22940 m_value.object->operator[](it.key()) = it.value();
22975 m_type = value_t::object;
22976 m_value.object = create<object_t>();
22977 assert_invariant();
22982 JSON_THROW(type_error::create(312,
"cannot use update() with " + std::string(
type_name()), *
this));
22986 if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object))
22988 JSON_THROW(invalid_iterator::create(210,
"iterators do not fit", *
this));
22992 if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object()
22993 || !last.m_object->is_object()))
22995 JSON_THROW(invalid_iterator::create(202,
"iterators first and last must point to objects", *
this));
22998 for (
auto it = first; it != last; ++it)
23000 m_value.object->operator[](it.key()) = it.value();
23022 std::is_nothrow_move_constructible<value_t>::value&&
23023 std::is_nothrow_move_assignable<value_t>::value&&
23024 std::is_nothrow_move_constructible<json_value>::value&&
23025 std::is_nothrow_move_assignable<json_value>::value
23028 std::swap(m_type, other.m_type);
23029 std::swap(
m_value, other.m_value);
23032 other.set_parents();
23033 assert_invariant();
23055 std::is_nothrow_move_constructible<value_t>::value&&
23056 std::is_nothrow_move_assignable<value_t>::value&&
23057 std::is_nothrow_move_constructible<json_value>::value&&
23058 std::is_nothrow_move_assignable<json_value>::value
23087 if (JSON_HEDLEY_LIKELY(
is_array()))
23089 std::swap(*(
m_value.array), other);
23093 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23122 std::swap(*(
m_value.object), other);
23126 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23155 std::swap(*(
m_value.string), other);
23159 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23188 std::swap(*(
m_value.binary), other);
23192 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23202 std::swap(*(
m_value.binary), other);
23206 JSON_THROW(type_error::create(310,
"cannot use swap() with " + std::string(
type_name()), *
this));
23277 const auto lhs_type = lhs.type();
23278 const auto rhs_type = rhs.type();
23280 if (lhs_type == rhs_type)
23284 case value_t::array:
23285 return *lhs.m_value.array == *rhs.m_value.array;
23287 case value_t::object:
23288 return *lhs.m_value.object == *rhs.m_value.object;
23290 case value_t::null:
23293 case value_t::string:
23294 return *lhs.m_value.string == *rhs.m_value.string;
23296 case value_t::boolean:
23297 return lhs.m_value.boolean == rhs.m_value.boolean;
23299 case value_t::number_integer:
23300 return lhs.m_value.number_integer == rhs.m_value.number_integer;
23302 case value_t::number_unsigned:
23303 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
23305 case value_t::number_float:
23306 return lhs.m_value.number_float == rhs.m_value.number_float;
23308 case value_t::binary:
23309 return *lhs.m_value.binary == *rhs.m_value.binary;
23315 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23317 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
23319 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23321 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_integer);
23323 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23325 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
23327 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23329 return lhs.m_value.number_float ==
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23331 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23333 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
23335 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23337 return lhs.m_value.number_integer ==
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23347 template<
typename ScalarType,
typename std::enable_if<
23348 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23358 template<
typename ScalarType,
typename std::enable_if<
23359 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23385 return !(lhs == rhs);
23392 template<
typename ScalarType,
typename std::enable_if<
23393 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23403 template<
typename ScalarType,
typename std::enable_if<
23404 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23438 const auto lhs_type = lhs.type();
23439 const auto rhs_type = rhs.type();
23441 if (lhs_type == rhs_type)
23445 case value_t::array:
23448 return (*lhs.m_value.array) < (*rhs.m_value.array);
23450 case value_t::object:
23451 return (*lhs.m_value.object) < (*rhs.m_value.object);
23453 case value_t::null:
23456 case value_t::string:
23457 return (*lhs.m_value.string) < (*rhs.m_value.string);
23459 case value_t::boolean:
23460 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
23462 case value_t::number_integer:
23463 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
23465 case value_t::number_unsigned:
23466 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
23468 case value_t::number_float:
23469 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
23471 case value_t::binary:
23472 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
23478 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
23480 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
23482 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
23484 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_integer);
23486 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
23488 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
23490 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
23492 return lhs.m_value.number_float <
static_cast<number_float_t>(rhs.m_value.number_unsigned);
23494 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
23496 return lhs.m_value.number_integer <
static_cast<number_integer_t>(rhs.m_value.number_unsigned);
23498 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
23500 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
23513 template<
typename ScalarType,
typename std::enable_if<
23514 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23524 template<
typename ScalarType,
typename std::enable_if<
23525 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23552 return !(rhs < lhs);
23559 template<
typename ScalarType,
typename std::enable_if<
23560 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23570 template<
typename ScalarType,
typename std::enable_if<
23571 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23598 return !(lhs <= rhs);
23605 template<
typename ScalarType,
typename std::enable_if<
23606 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23616 template<
typename ScalarType,
typename std::enable_if<
23617 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23644 return !(lhs < rhs);
23651 template<
typename ScalarType,
typename std::enable_if<
23652 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23662 template<
typename ScalarType,
typename std::enable_if<
23663 std::is_scalar<ScalarType>::value,
int>
::type = 0>
23712 const bool pretty_print = o.width() > 0;
23713 const auto indentation = pretty_print ? o.width() : 0;
23719 serializer s(detail::output_adapter<char>(o), o.fill());
23720 s.dump(j, pretty_print,
false,
static_cast<unsigned int>(indentation));
23732 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator<<(std::ostream&,
const basic_json&))
23799 template<
typename InputType>
23803 const bool allow_exceptions =
true,
23804 const bool ignore_comments =
false)
23807 parser(detail::input_adapter(std::forward<InputType>(i)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23837 template<
typename IteratorType>
23842 const bool allow_exceptions =
true,
23843 const bool ignore_comments =
false)
23846 parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(
true, result);
23851 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
parse(ptr, ptr + len))
23854 const bool allow_exceptions =
true,
23855 const bool ignore_comments =
false)
23858 parser(i.get(), cb, allow_exceptions, ignore_comments).parse(
true, result);
23892 template<
typename InputType>
23893 static bool accept(InputType&& i,
23894 const bool ignore_comments =
false)
23896 return parser(detail::input_adapter(std::forward<InputType>(i)),
nullptr,
false, ignore_comments).accept(
true);
23899 template<
typename IteratorType>
23900 static bool accept(IteratorType first, IteratorType last,
23901 const bool ignore_comments =
false)
23903 return parser(detail::input_adapter(std::move(first), std::move(last)),
nullptr,
false, ignore_comments).accept(
true);
23907 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
accept(ptr, ptr + len))
23908 static bool accept(detail::span_input_adapter&& i,
23909 const bool ignore_comments =
false)
23911 return parser(i.get(),
nullptr,
false, ignore_comments).accept(
true);
23954 template <
typename InputType,
typename SAX>
23955 JSON_HEDLEY_NON_NULL(2)
23956 static
bool sax_parse(InputType&& i, SAX* sax,
23958 const
bool strict = true,
23959 const
bool ignore_comments = false)
23961 auto ia = detail::input_adapter(std::forward<InputType>(i));
23962 return format == input_format_t::json
23963 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23964 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23967 template<
class IteratorType,
class SAX>
23968 JSON_HEDLEY_NON_NULL(3)
23969 static
bool sax_parse(IteratorType first, IteratorType last, SAX* sax,
23970 input_format_t format = input_format_t::
json,
23971 const
bool strict = true,
23972 const
bool ignore_comments = false)
23974 auto ia = detail::input_adapter(std::move(first), std::move(last));
23975 return format == input_format_t::json
23976 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23977 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
23980 template <
typename SAX>
23981 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
sax_parse(ptr, ptr + len, ...))
23982 JSON_HEDLEY_NON_NULL(2)
23983 static
bool sax_parse(detail::span_input_adapter&& i, SAX* sax,
23984 input_format_t format = input_format_t::
json,
23985 const
bool strict = true,
23986 const
bool ignore_comments = false)
23989 return format == input_format_t::json
23991 ? parser(std::move(ia),
nullptr,
true, ignore_comments).sax_parse(sax, strict)
23993 : detail::binary_reader<basic_json, decltype(ia), SAX>(std::move(ia)).sax_parse(format, sax, strict);
24004 JSON_HEDLEY_DEPRECATED_FOR(3.0.0,
operator>>(std::istream&,
basic_json&))
24037 parser(detail::input_adapter(i)).parse(
false, j);
24084 case value_t::null:
24086 case value_t::object:
24088 case value_t::array:
24090 case value_t::string:
24092 case value_t::boolean:
24094 case value_t::binary:
24096 case value_t::discarded:
24097 return "discarded";
24105 JSON_PRIVATE_UNLESS_TESTED:
24111 value_t m_type = value_t::null;
24116 #if JSON_DIAGNOSTICS
24225 std::vector<uint8_t> result;
24232 binary_writer<uint8_t>(o).write_cbor(j);
24237 binary_writer<char>(o).write_cbor(j);
24320 std::vector<uint8_t> result;
24327 binary_writer<uint8_t>(o).write_msgpack(j);
24332 binary_writer<char>(o).write_msgpack(j);
24422 const bool use_size =
false,
24423 const bool use_type =
false)
24425 std::vector<uint8_t> result;
24426 to_ubjson(j, result, use_size, use_type);
24431 const bool use_size =
false,
const bool use_type =
false)
24433 binary_writer<uint8_t>(o).write_ubjson(j, use_size, use_type);
24437 const bool use_size =
false,
const bool use_type =
false)
24439 binary_writer<char>(o).write_ubjson(j, use_size, use_type);
24501 std::vector<uint8_t> result;
24516 binary_writer<uint8_t>(o).write_bson(j);
24524 binary_writer<char>(o).write_bson(j);
24630 template<
typename InputType>
24633 const bool strict =
true,
24634 const bool allow_exceptions =
true,
24638 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24639 auto ia = detail::input_adapter(std::forward<InputType>(i));
24640 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24641 return res ? result :
basic_json(value_t::discarded);
24647 template<
typename IteratorType>
24650 const bool strict =
true,
24651 const bool allow_exceptions =
true,
24655 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24656 auto ia = detail::input_adapter(std::move(first), std::move(last));
24657 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24658 return res ? result :
basic_json(value_t::discarded);
24661 template<
typename T>
24663 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_cbor(ptr, ptr + len))
24665 const bool strict =
true,
24666 const bool allow_exceptions =
true,
24669 return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler);
24676 const bool strict =
true,
24677 const bool allow_exceptions =
true,
24678 const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error)
24681 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24684 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
24774 template<
typename InputType>
24777 const bool strict =
true,
24778 const bool allow_exceptions =
true)
24781 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24782 auto ia = detail::input_adapter(std::forward<InputType>(i));
24783 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24784 return res ? result :
basic_json(value_t::discarded);
24790 template<
typename IteratorType>
24793 const bool strict =
true,
24794 const bool allow_exceptions =
true)
24797 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24798 auto ia = detail::input_adapter(std::move(first), std::move(last));
24799 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24800 return res ? result :
basic_json(value_t::discarded);
24804 template<
typename T>
24806 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24808 const bool strict =
true,
24809 const bool allow_exceptions =
true)
24811 return from_msgpack(ptr, ptr + len, strict, allow_exceptions);
24815 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_msgpack(ptr, ptr + len))
24817 const bool strict =
true,
24818 const bool allow_exceptions =
true)
24821 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24824 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict);
24825 return res ? result :
basic_json(value_t::discarded);
24891 template<
typename InputType>
24894 const bool strict =
true,
24895 const bool allow_exceptions =
true)
24898 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24899 auto ia = detail::input_adapter(std::forward<InputType>(i));
24900 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24901 return res ? result :
basic_json(value_t::discarded);
24907 template<
typename IteratorType>
24910 const bool strict =
true,
24911 const bool allow_exceptions =
true)
24914 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24915 auto ia = detail::input_adapter(std::move(first), std::move(last));
24916 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24917 return res ? result :
basic_json(value_t::discarded);
24920 template<
typename T>
24922 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24924 const bool strict =
true,
24925 const bool allow_exceptions =
true)
24927 return from_ubjson(ptr, ptr + len, strict, allow_exceptions);
24931 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_ubjson(ptr, ptr + len))
24933 const bool strict =
true,
24934 const bool allow_exceptions =
true)
24937 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
24940 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict);
24941 return res ? result :
basic_json(value_t::discarded);
25005 template<
typename InputType>
25008 const bool strict =
true,
25009 const bool allow_exceptions =
true)
25012 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25013 auto ia = detail::input_adapter(std::forward<InputType>(i));
25014 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25015 return res ? result :
basic_json(value_t::discarded);
25021 template<
typename IteratorType>
25024 const bool strict =
true,
25025 const bool allow_exceptions =
true)
25028 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25029 auto ia = detail::input_adapter(std::move(first), std::move(last));
25030 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25031 return res ? result :
basic_json(value_t::discarded);
25034 template<
typename T>
25036 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25038 const bool strict =
true,
25039 const bool allow_exceptions =
true)
25041 return from_bson(ptr, ptr + len, strict, allow_exceptions);
25045 JSON_HEDLEY_DEPRECATED_FOR(3.8.0,
from_bson(ptr, ptr + len))
25047 const bool strict =
true,
25048 const bool allow_exceptions =
true)
25051 detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
25054 const bool res = binary_reader<decltype(ia)>(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict);
25055 return res ? result :
basic_json(value_t::discarded);
25101 return ptr.get_unchecked(
this);
25129 return ptr.get_unchecked(
this);
25172 return ptr.get_checked(
this);
25215 return ptr.get_checked(
this);
25243 json_pointer::flatten(
"", *
this, result);
25279 return json_pointer::unflatten(*
this);
25344 enum class patch_operations {add, remove, replace, move, copy, test, invalid};
25346 const auto get_op = [](
const std::string & op)
25350 return patch_operations::add;
25352 if (op ==
"remove")
25354 return patch_operations::remove;
25356 if (op ==
"replace")
25358 return patch_operations::replace;
25362 return patch_operations::move;
25366 return patch_operations::copy;
25370 return patch_operations::test;
25373 return patch_operations::invalid;
25388 if (top_pointer != ptr)
25390 result.
at(top_pointer);
25394 const auto last_path = ptr.
back();
25398 switch (parent.m_type)
25400 case value_t::null:
25401 case value_t::object:
25404 parent[last_path] = val;
25408 case value_t::array:
25410 if (last_path ==
"-")
25417 const auto idx = json_pointer::array_index(last_path);
25418 if (JSON_HEDLEY_UNLIKELY(idx > parent.size()))
25421 JSON_THROW(out_of_range::create(401,
"array index " + std::to_string(idx) +
" is out of range", parent));
25425 parent.insert(parent.begin() +
static_cast<difference_type>(idx), val);
25432 JSON_ASSERT(
false);
25437 const auto operation_remove = [
this, &result](
json_pointer & ptr)
25440 const auto last_path = ptr.back();
25445 if (parent.is_object())
25448 auto it = parent.
find(last_path);
25449 if (JSON_HEDLEY_LIKELY(it != parent.end()))
25455 JSON_THROW(out_of_range::create(403,
"key '" + last_path +
"' not found", *
this));
25458 else if (parent.is_array())
25461 parent.erase(json_pointer::array_index(last_path));
25466 if (JSON_HEDLEY_UNLIKELY(!json_patch.
is_array()))
25468 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", json_patch));
25472 for (
const auto& val : json_patch)
25475 const auto get_value = [&val](
const std::string & op,
25476 const std::string & member,
25480 auto it = val.m_value.object->find(member);
25483 const auto error_msg = (op ==
"op") ?
"operation" :
"operation '" + op +
"'";
25486 if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end()))
25489 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have member '" + member +
"'", val));
25493 if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string()))
25496 JSON_THROW(parse_error::create(105, 0, error_msg +
" must have string member '" + member +
"'", val));
25504 if (JSON_HEDLEY_UNLIKELY(!val.is_object()))
25506 JSON_THROW(parse_error::create(104, 0,
"JSON patch must be an array of objects", val));
25510 const auto op = get_value(
"op",
"op",
true).template get<std::string>();
25511 const auto path = get_value(op,
"path",
true).template get<std::string>();
25514 switch (get_op(op))
25516 case patch_operations::add:
25518 operation_add(ptr, get_value(
"add",
"value",
false));
25522 case patch_operations::remove:
25524 operation_remove(ptr);
25528 case patch_operations::replace:
25531 result.
at(ptr) = get_value(
"replace",
"value",
false);
25535 case patch_operations::move:
25537 const auto from_path = get_value(
"move",
"from",
true).template get<std::string>();
25547 operation_remove(from_ptr);
25548 operation_add(ptr, v);
25552 case patch_operations::copy:
25554 const auto from_path = get_value(
"copy",
"from",
true).template get<std::string>();
25563 operation_add(ptr, v);
25567 case patch_operations::test:
25569 bool success =
false;
25574 success = (result.
at(ptr) == get_value(
"test",
"value",
false));
25582 if (JSON_HEDLEY_UNLIKELY(!success))
25584 JSON_THROW(other_error::create(501,
"unsuccessful: " + val.dump(), val));
25594 JSON_THROW(parse_error::create(105, 0,
"operation value '" + op +
"' is invalid", val));
25637 const std::string& path =
"")
25643 if (source == target)
25648 if (source.type() != target.type())
25653 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25658 switch (source.type())
25660 case value_t::array:
25664 while (i < source.size() && i < target.size())
25667 auto temp_diff =
diff(source[i], target[i], path +
"/" + std::to_string(i));
25668 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25677 while (i < source.size())
25684 {
"path", path +
"/" + std::to_string(i)}
25690 while (i < target.size())
25695 {
"path", path +
"/-"},
25696 {
"value", target[i]}
25704 case value_t::object:
25707 for (
auto it = source.cbegin(); it != source.cend(); ++it)
25710 const auto path_key = path +
"/" + detail::escape(it.key());
25712 if (target.find(it.key()) != target.end())
25715 auto temp_diff =
diff(it.value(), target[it.key()], path_key);
25716 result.
insert(result.
end(), temp_diff.begin(), temp_diff.end());
25723 {
"op",
"remove"}, {
"path", path_key}
25729 for (
auto it = target.cbegin(); it != target.cend(); ++it)
25731 if (source.find(it.key()) == source.end())
25734 const auto path_key = path +
"/" + detail::escape(it.key());
25737 {
"op",
"add"}, {
"path", path_key},
25738 {
"value", it.value()}
25751 {
"op",
"replace"}, {
"path", path}, {
"value", target}
25813 if (apply_patch.is_object())
25819 for (
auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
25821 if (it.value().is_null())
25833 *
this = apply_patch;
25849 NLOHMANN_BASIC_JSON_TPL_DECLARATION
25850 std::string
to_string(
const NLOHMANN_BASIC_JSON_TPL& j)
25875 return nlohmann::detail::hash(j);
25883 struct less<::nlohmann::detail::value_t>
25889 bool operator()(nlohmann::detail::value_t lhs,
25890 nlohmann::detail::value_t rhs)
const noexcept
25892 return nlohmann::detail::operator<(lhs, rhs);
25897 #ifndef JSON_HAS_CPP_20
25906 is_nothrow_move_constructible<nlohmann::json>::value&&
25907 is_nothrow_move_assignable<nlohmann::json>::value
25930 JSON_HEDLEY_NON_NULL(1)
25931 inline
nlohmann::json operator "" _json(const
char* s, std::
size_t n)
25949 JSON_HEDLEY_NON_NULL(1)
25950 inline
nlohmann::json::json_pointer operator "" _json_pointer(const
char* s, std::
size_t n)
25959 #if defined(__clang__)
25960 #pragma GCC diagnostic pop
25965 #undef JSON_INTERNAL_CATCH
25969 #undef JSON_PRIVATE_UNLESS_TESTED
25970 #undef JSON_HAS_CPP_14
25971 #undef JSON_HAS_CPP_17
25972 #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
25973 #undef NLOHMANN_BASIC_JSON_TPL
25974 #undef JSON_EXPLICIT
25979 #undef JSON_HEDLEY_ALWAYS_INLINE
25980 #undef JSON_HEDLEY_ARM_VERSION
25981 #undef JSON_HEDLEY_ARM_VERSION_CHECK
25982 #undef JSON_HEDLEY_ARRAY_PARAM
25983 #undef JSON_HEDLEY_ASSUME
25984 #undef JSON_HEDLEY_BEGIN_C_DECLS
25985 #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE
25986 #undef JSON_HEDLEY_CLANG_HAS_BUILTIN
25987 #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE
25988 #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE
25989 #undef JSON_HEDLEY_CLANG_HAS_EXTENSION
25990 #undef JSON_HEDLEY_CLANG_HAS_FEATURE
25991 #undef JSON_HEDLEY_CLANG_HAS_WARNING
25992 #undef JSON_HEDLEY_COMPCERT_VERSION
25993 #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK
25994 #undef JSON_HEDLEY_CONCAT
25995 #undef JSON_HEDLEY_CONCAT3
25996 #undef JSON_HEDLEY_CONCAT3_EX
25997 #undef JSON_HEDLEY_CONCAT_EX
25998 #undef JSON_HEDLEY_CONST
25999 #undef JSON_HEDLEY_CONSTEXPR
26000 #undef JSON_HEDLEY_CONST_CAST
26001 #undef JSON_HEDLEY_CPP_CAST
26002 #undef JSON_HEDLEY_CRAY_VERSION
26003 #undef JSON_HEDLEY_CRAY_VERSION_CHECK
26004 #undef JSON_HEDLEY_C_DECL
26005 #undef JSON_HEDLEY_DEPRECATED
26006 #undef JSON_HEDLEY_DEPRECATED_FOR
26007 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL
26008 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_
26009 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED
26010 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES
26011 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS
26012 #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION
26013 #undef JSON_HEDLEY_DIAGNOSTIC_POP
26014 #undef JSON_HEDLEY_DIAGNOSTIC_PUSH
26015 #undef JSON_HEDLEY_DMC_VERSION
26016 #undef JSON_HEDLEY_DMC_VERSION_CHECK
26017 #undef JSON_HEDLEY_EMPTY_BASES
26018 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION
26019 #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK
26020 #undef JSON_HEDLEY_END_C_DECLS
26021 #undef JSON_HEDLEY_FLAGS
26022 #undef JSON_HEDLEY_FLAGS_CAST
26023 #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE
26024 #undef JSON_HEDLEY_GCC_HAS_BUILTIN
26025 #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE
26026 #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE
26027 #undef JSON_HEDLEY_GCC_HAS_EXTENSION
26028 #undef JSON_HEDLEY_GCC_HAS_FEATURE
26029 #undef JSON_HEDLEY_GCC_HAS_WARNING
26030 #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK
26031 #undef JSON_HEDLEY_GCC_VERSION
26032 #undef JSON_HEDLEY_GCC_VERSION_CHECK
26033 #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE
26034 #undef JSON_HEDLEY_GNUC_HAS_BUILTIN
26035 #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE
26036 #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE
26037 #undef JSON_HEDLEY_GNUC_HAS_EXTENSION
26038 #undef JSON_HEDLEY_GNUC_HAS_FEATURE
26039 #undef JSON_HEDLEY_GNUC_HAS_WARNING
26040 #undef JSON_HEDLEY_GNUC_VERSION
26041 #undef JSON_HEDLEY_GNUC_VERSION_CHECK
26042 #undef JSON_HEDLEY_HAS_ATTRIBUTE
26043 #undef JSON_HEDLEY_HAS_BUILTIN
26044 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE
26045 #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS
26046 #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE
26047 #undef JSON_HEDLEY_HAS_EXTENSION
26048 #undef JSON_HEDLEY_HAS_FEATURE
26049 #undef JSON_HEDLEY_HAS_WARNING
26050 #undef JSON_HEDLEY_IAR_VERSION
26051 #undef JSON_HEDLEY_IAR_VERSION_CHECK
26052 #undef JSON_HEDLEY_IBM_VERSION
26053 #undef JSON_HEDLEY_IBM_VERSION_CHECK
26054 #undef JSON_HEDLEY_IMPORT
26055 #undef JSON_HEDLEY_INLINE
26056 #undef JSON_HEDLEY_INTEL_CL_VERSION
26057 #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK
26058 #undef JSON_HEDLEY_INTEL_VERSION
26059 #undef JSON_HEDLEY_INTEL_VERSION_CHECK
26060 #undef JSON_HEDLEY_IS_CONSTANT
26061 #undef JSON_HEDLEY_IS_CONSTEXPR_
26062 #undef JSON_HEDLEY_LIKELY
26063 #undef JSON_HEDLEY_MALLOC
26064 #undef JSON_HEDLEY_MCST_LCC_VERSION
26065 #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK
26066 #undef JSON_HEDLEY_MESSAGE
26067 #undef JSON_HEDLEY_MSVC_VERSION
26068 #undef JSON_HEDLEY_MSVC_VERSION_CHECK
26069 #undef JSON_HEDLEY_NEVER_INLINE
26070 #undef JSON_HEDLEY_NON_NULL
26071 #undef JSON_HEDLEY_NO_ESCAPE
26072 #undef JSON_HEDLEY_NO_RETURN
26073 #undef JSON_HEDLEY_NO_THROW
26074 #undef JSON_HEDLEY_NULL
26075 #undef JSON_HEDLEY_PELLES_VERSION
26076 #undef JSON_HEDLEY_PELLES_VERSION_CHECK
26077 #undef JSON_HEDLEY_PGI_VERSION
26078 #undef JSON_HEDLEY_PGI_VERSION_CHECK
26079 #undef JSON_HEDLEY_PREDICT
26080 #undef JSON_HEDLEY_PRINTF_FORMAT
26081 #undef JSON_HEDLEY_PRIVATE
26082 #undef JSON_HEDLEY_PUBLIC
26083 #undef JSON_HEDLEY_PURE
26084 #undef JSON_HEDLEY_REINTERPRET_CAST
26085 #undef JSON_HEDLEY_REQUIRE
26086 #undef JSON_HEDLEY_REQUIRE_CONSTEXPR
26087 #undef JSON_HEDLEY_REQUIRE_MSG
26088 #undef JSON_HEDLEY_RESTRICT
26090 #undef JSON_HEDLEY_SENTINEL
26091 #undef JSON_HEDLEY_STATIC_ASSERT
26092 #undef JSON_HEDLEY_STATIC_CAST
26093 #undef JSON_HEDLEY_STRINGIFY
26094 #undef JSON_HEDLEY_STRINGIFY_EX
26095 #undef JSON_HEDLEY_SUNPRO_VERSION
26096 #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK
26097 #undef JSON_HEDLEY_TINYC_VERSION
26098 #undef JSON_HEDLEY_TINYC_VERSION_CHECK
26099 #undef JSON_HEDLEY_TI_ARMCL_VERSION
26100 #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK
26101 #undef JSON_HEDLEY_TI_CL2000_VERSION
26102 #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK
26103 #undef JSON_HEDLEY_TI_CL430_VERSION
26104 #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK
26105 #undef JSON_HEDLEY_TI_CL6X_VERSION
26106 #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK
26107 #undef JSON_HEDLEY_TI_CL7X_VERSION
26108 #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK
26109 #undef JSON_HEDLEY_TI_CLPRU_VERSION
26110 #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK
26111 #undef JSON_HEDLEY_TI_VERSION
26112 #undef JSON_HEDLEY_TI_VERSION_CHECK
26113 #undef JSON_HEDLEY_UNAVAILABLE
26114 #undef JSON_HEDLEY_UNLIKELY
26115 #undef JSON_HEDLEY_UNPREDICTABLE
26116 #undef JSON_HEDLEY_UNREACHABLE
26117 #undef JSON_HEDLEY_UNREACHABLE_RETURN
26118 #undef JSON_HEDLEY_VERSION
26119 #undef JSON_HEDLEY_VERSION_DECODE_MAJOR
26120 #undef JSON_HEDLEY_VERSION_DECODE_MINOR
26121 #undef JSON_HEDLEY_VERSION_DECODE_REVISION
26122 #undef JSON_HEDLEY_VERSION_ENCODE
26123 #undef JSON_HEDLEY_WARNING
26126 #undef JSON_HEDLEY_FALL_THROUGH
static basic_json binary(typename binary_t::container_type &&init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
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
static std::vector< uint8_t > to_ubjson(const basic_json &j, const bool use_size=false, const bool use_type=false)
create a UBJSON serialization of a given JSON value
basic_json(const JsonRef &ref)
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
reference front()
access the first element
constexpr bool is_primitive() const noexcept
return whether type is primitive
constexpr bool is_number_unsigned() const noexcept
return whether value is an unsigned integer number
detail::cbor_tag_handler_t cbor_tag_handler_t
how to treat CBOR tags
detail::parse_error parse_error
exception indicating a parse error
constexpr bool is_object() const noexcept
return whether value is an object
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
NumberFloatType number_float_t
a type for a number (floating-point)
json_reverse_iterator< typename basic_json::iterator > reverse_iterator
a reverse iterator for a basic_json container
friend 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
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 std::vector< uint8_t > to_msgpack(const basic_json &j)
create a MessagePack serialization of a given JSON value
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
static std::vector< 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...
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
static basic_json binary(const typename binary_t::container_type &init, std::uint8_t subtype)
explicitly create a binary array (with subtype)
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 std::vector< uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
static basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
basic_json(CompatibleType &&val) noexcept(noexcept(//NOLINT(bugprone-forwarding-reference-overload, bugprone-exception-escape) JSONSerializer< U >::to_json(std::declval< basic_json_t & >(), std::forward< CompatibleType >(val))))
create a JSON value
basic_json unflatten() const
unflatten a previously flattened JSON value
NumberUnsignedType number_unsigned_t
a type for a number (unsigned)
const_iterator cbegin() const noexcept
returns a const iterator to the first element
basic_json(initializer_list_t init, bool type_deduction=true, value_t manual_type=value_t::array)
create a container (array or object) from an initializer list
iterator insert(const_iterator pos, const basic_json &val)
inserts element
iter_impl< const basic_json > const_iterator
a const iterator for a basic_json container
constexpr bool is_discarded() const noexcept
return whether value is discarded
constexpr bool is_null() const noexcept
return whether value is null
ObjectType< StringType, basic_json, object_comparator_t, AllocatorType< std::pair< const StringType, basic_json > >> object_t
a type for an object
auto get() const noexcept(noexcept(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))) -> decltype(std::declval< const basic_json_t & >().template get_impl< ValueType >(detail::priority_tag< 4 > {}))
get a (pointer) value (explicit)
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
BinaryType container_type
the type of the underlying container
void set_subtype(std::uint8_t subtype_) noexcept
sets the binary subtype
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(const container_type &b, std::uint8_t subtype_) noexcept(noexcept(container_type(b)))
constexpr bool has_subtype() const noexcept
return whether the value has a subtype
byte_container_with_subtype(container_type &&b, std::uint8_t subtype_) noexcept(noexcept(container_type(std::move(b))))
constexpr std::uint8_t subtype() const noexcept
return the binary 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