diff --git a/Nodes.xml b/Nodes.xml index cdc78c50b..cc041899d 100644 --- a/Nodes.xml +++ b/Nodes.xml @@ -827,6 +827,16 @@ classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html a234f03dce002783748ca401a42bc6472 + + get_ref + classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html + a1b058496e6a67565a096233cd113505b + + + get_ref + classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html + a2f1f7ca08995781acb63bd66b26ad1c1 + insert classnlohmann_1_1basic__json_af7d0adc984d04fc70c3d29fcd63e096a.html diff --git a/Tokens.xml b/Tokens.xml index 0fa28543a..0a5661b94 100644 --- a/Tokens.xml +++ b/Tokens.xml @@ -760,6 +760,30 @@ get a pointer value (implicit) json.hpp + + + get_ref + cpp + instm + nlohmann::basic_json + + classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html + a1b058496e6a67565a096233cd113505b + get a reference value (implicit) + json.hpp + + + + get_ref + cpp + instm + nlohmann::basic_json + + classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html + a2f1f7ca08995781acb63bd66b26ad1c1 + get a reference value (implicit) + json.hpp + operator ValueType diff --git a/annotated.html b/annotated.html index 324f45828..d58d642de 100644 --- a/annotated.html +++ b/annotated.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classes.html b/classes.html index 1643e7e80..0ae73d80d 100644 --- a/classes.html +++ b/classes.html @@ -103,7 +103,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json-members.html b/classnlohmann_1_1basic__json-members.html index e5d7b34cf..42be24f8f 100644 --- a/classnlohmann_1_1basic__json-members.html +++ b/classnlohmann_1_1basic__json-members.html @@ -155,6 +155,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator()nlohmann::basic_jsoninlinestatic get_ptr() noexceptnlohmann::basic_jsoninline get_ptr() const noexceptnlohmann::basic_jsoninline + get_ref()nlohmann::basic_jsoninline + get_ref() const nlohmann::basic_jsoninline insert(const_iterator pos, const basic_json &val)nlohmann::basic_jsoninline insert(const_iterator pos, basic_json &&val)nlohmann::basic_jsoninline insert(const_iterator pos, size_type cnt, const basic_json &val)nlohmann::basic_jsoninline @@ -236,7 +238,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json.html b/classnlohmann_1_1basic__json.html index ddde2d6cb..fb9a3e9cd 100644 --- a/classnlohmann_1_1basic__json.html +++ b/classnlohmann_1_1basic__json.html @@ -358,6 +358,14 @@ value access const PointerType get_ptr () const noexcept  get a pointer value (implicit) More...
  +template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value , int >::type = 0> +ReferenceType get_ref () + get a reference value (implicit) More...
+  +template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value and std::is_const< typename std::remove_reference< ReferenceType >::type >::value , int >::type = 0> +ReferenceType get_ref () const + get a reference value (implicit) More...
+  template<typename ValueType , typename std::enable_if< not std::is_pointer< ValueType >::value and not std::is_same< ValueType, typename string_t::value_type >::value and not std::is_same< ValueType, std::initializer_list< typename string_t::value_type >>::value , int >::type = 0>  operator ValueType () const  get a value (implicit) More...
@@ -662,7 +670,7 @@ class nlohmann::basic_json diff --git a/classnlohmann_1_1basic__json_1_1const__iterator-members.html b/classnlohmann_1_1basic__json_1_1const__iterator-members.html index 66126cd71..959f8848b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator-members.html @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1const__iterator.html b/classnlohmann_1_1basic__json_1_1const__iterator.html index 7e8d84f55..02fe77f70 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator.html @@ -215,11 +215,11 @@ class nlohmann::basic_json::const_iterator
Since
version 1.0.0
-

Definition at line 5686 of file json.hpp.

+

Definition at line 5766 of file json.hpp.

diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a019087161350d393f3e4ac841cdd3dbd.html b/classnlohmann_1_1basic__json_1_1const__iterator_a019087161350d393f3e4ac841cdd3dbd.html index 58a7fa00d..09de0b7a3 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a019087161350d393f3e4ac841cdd3dbd.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a019087161350d393f3e4ac841cdd3dbd.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5958 of file json.hpp.

+

Definition at line 6038 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a17e5f5d3598e6901f3c1c1f7dc60589f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a17e5f5d3598e6901f3c1c1f7dc60589f.html index d1618c90e..421ad6078 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a17e5f5d3598e6901f3c1c1f7dc60589f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a17e5f5d3598e6901f3c1c1f7dc60589f.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6067 of file json.hpp.

+

Definition at line 6147 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a1cba94e5a67ee52bc66b898a4e08359d.html b/classnlohmann_1_1basic__json_1_1const__iterator_a1cba94e5a67ee52bc66b898a4e08359d.html index 1f2b115fb..8594721ac 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a1cba94e5a67ee52bc66b898a4e08359d.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a1cba94e5a67ee52bc66b898a4e08359d.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6153 of file json.hpp.

+

Definition at line 6233 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a211523a57024a43965862b497b89ab91.html b/classnlohmann_1_1basic__json_1_1const__iterator_a211523a57024a43965862b497b89ab91.html index d70647bd2..b27391a46 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a211523a57024a43965862b497b89ab91.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a211523a57024a43965862b497b89ab91.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5766 of file json.hpp.

+

Definition at line 5846 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a301749e9779adafd395369ac36df93df.html b/classnlohmann_1_1basic__json_1_1const__iterator_a301749e9779adafd395369ac36df93df.html index 19f7f49a0..3619ca0a1 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a301749e9779adafd395369ac36df93df.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a301749e9779adafd395369ac36df93df.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5886 of file json.hpp.

+

Definition at line 5966 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a36086a699b95e06976c11367b7d6ba53.html b/classnlohmann_1_1basic__json_1_1const__iterator_a36086a699b95e06976c11367b7d6ba53.html index f0c584ba7..a97a7aca1 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a36086a699b95e06976c11367b7d6ba53.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a36086a699b95e06976c11367b7d6ba53.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5995 of file json.hpp.

+

Definition at line 6075 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a4632d8307fc315f21e2ecc9ba5aa6346.html b/classnlohmann_1_1basic__json_1_1const__iterator_a4632d8307fc315f21e2ecc9ba5aa6346.html index 23d08369d..f59b57599 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a4632d8307fc315f21e2ecc9ba5aa6346.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a4632d8307fc315f21e2ecc9ba5aa6346.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5846 of file json.hpp.

+

Definition at line 5926 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a4f7ac43b0ab34c387b1ae1a8e9c08467.html b/classnlohmann_1_1basic__json_1_1const__iterator_a4f7ac43b0ab34c387b1ae1a8e9c08467.html index 812db7a66..03e1c606d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a4f7ac43b0ab34c387b1ae1a8e9c08467.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a4f7ac43b0ab34c387b1ae1a8e9c08467.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5697 of file json.hpp.

+

Definition at line 5777 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5aff013c03c1bdc248346c249bec7b67.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5aff013c03c1bdc248346c249bec7b67.html index fc49fbb9c..000b15091 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5aff013c03c1bdc248346c249bec7b67.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5aff013c03c1bdc248346c249bec7b67.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5734 of file json.hpp.

+

Definition at line 5814 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a62cad59e006eb7fa594c2c5b65a76610.html b/classnlohmann_1_1basic__json_1_1const__iterator_a62cad59e006eb7fa594c2c5b65a76610.html index 3508c1e5a..bf9148ed8 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a62cad59e006eb7fa594c2c5b65a76610.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a62cad59e006eb7fa594c2c5b65a76610.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6121 of file json.hpp.

+

Definition at line 6201 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a67848d4b7bfa576434ad9807147b5870.html b/classnlohmann_1_1basic__json_1_1const__iterator_a67848d4b7bfa576434ad9807147b5870.html index a35a4f42f..9d3f82b86 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a67848d4b7bfa576434ad9807147b5870.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a67848d4b7bfa576434ad9807147b5870.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5693 of file json.hpp.

+

Definition at line 5773 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6b3e43d2f45fa611825dbdf4e88fffe2.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6b3e43d2f45fa611825dbdf4e88fffe2.html index 5818774c0..e2932acd6 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6b3e43d2f45fa611825dbdf4e88fffe2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6b3e43d2f45fa611825dbdf4e88fffe2.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6073 of file json.hpp.

+

Definition at line 6153 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a83454954e4e16be3d5316f9322e91a34.html b/classnlohmann_1_1basic__json_1_1const__iterator_a83454954e4e16be3d5316f9322e91a34.html index d782e9c6d..a91aca028 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a83454954e4e16be3d5316f9322e91a34.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a83454954e4e16be3d5316f9322e91a34.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5707 of file json.hpp.

+

Definition at line 5787 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a86a1771e6658d0b14868df6c197d2353.html b/classnlohmann_1_1basic__json_1_1const__iterator_a86a1771e6658d0b14868df6c197d2353.html index 4d9705df1..d6769e74d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a86a1771e6658d0b14868df6c197d2353.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a86a1771e6658d0b14868df6c197d2353.html @@ -150,7 +150,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8d024cbc99db0d8106899f9fd9973735.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8d024cbc99db0d8106899f9fd9973735.html index 0d6e9f9b0..0e90b7c1a 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8d024cbc99db0d8106899f9fd9973735.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8d024cbc99db0d8106899f9fd9973735.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6189 of file json.hpp.

+

Definition at line 6269 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab74b39747a9dad60650a57133fca85b3.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab74b39747a9dad60650a57133fca85b3.html index 772e5a1dc..b188aa72a 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab74b39747a9dad60650a57133fca85b3.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab74b39747a9dad60650a57133fca85b3.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6079 of file json.hpp.

+

Definition at line 6159 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab7dacd8e3ee9b3756bfcdb87dd55a515.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab7dacd8e3ee9b3756bfcdb87dd55a515.html index 4cb99ab92..24bdba3be 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab7dacd8e3ee9b3756bfcdb87dd55a515.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab7dacd8e3ee9b3756bfcdb87dd55a515.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6204 of file json.hpp.

+

Definition at line 6284 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab9d31bf0d0b4d7310c858a04ce84a52f.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab9d31bf0d0b4d7310c858a04ce84a52f.html index b3d1b2556..fba416eec 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab9d31bf0d0b4d7310c858a04ce84a52f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab9d31bf0d0b4d7310c858a04ce84a52f.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6025 of file json.hpp.

+

Definition at line 6105 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abb1921cbf0ad4036c83bc6303e22171f.html b/classnlohmann_1_1basic__json_1_1const__iterator_abb1921cbf0ad4036c83bc6303e22171f.html index 33bc62ada..3463102b7 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abb1921cbf0ad4036c83bc6303e22171f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abb1921cbf0ad4036c83bc6303e22171f.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5966 of file json.hpp.

+

Definition at line 6046 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abbacd95955c602efc9a58ed1ffdb46c4.html b/classnlohmann_1_1basic__json_1_1const__iterator_abbacd95955c602efc9a58ed1ffdb46c4.html index c1e480898..98ef59cb2 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abbacd95955c602efc9a58ed1ffdb46c4.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abbacd95955c602efc9a58ed1ffdb46c4.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5929 of file json.hpp.

+

Definition at line 6009 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac36b9187de43721a4bf1b052578bb80b.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac36b9187de43721a4bf1b052578bb80b.html index 8001ee200..7b2c3255f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac36b9187de43721a4bf1b052578bb80b.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac36b9187de43721a4bf1b052578bb80b.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5695 of file json.hpp.

+

Definition at line 5775 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac634a659837f5aebc97125e031de23b5.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac634a659837f5aebc97125e031de23b5.html index b3440c006..bb77df581 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac634a659837f5aebc97125e031de23b5.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac634a659837f5aebc97125e031de23b5.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6113 of file json.hpp.

+

Definition at line 6193 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_acea5b75d1087e2a92833946d9dc547ff.html b/classnlohmann_1_1basic__json_1_1const__iterator_acea5b75d1087e2a92833946d9dc547ff.html index 5393563d4..a5e91cf25 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_acea5b75d1087e2a92833946d9dc547ff.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_acea5b75d1087e2a92833946d9dc547ff.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6031 of file json.hpp.

+

Definition at line 6111 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html index ec3953baa..80ea012b1 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html @@ -139,7 +139,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5689 of file json.hpp.

+

Definition at line 5769 of file json.hpp.

@@ -149,7 +149,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adb50d6043ace464d9f694869724d7fb2.html b/classnlohmann_1_1basic__json_1_1const__iterator_adb50d6043ace464d9f694869724d7fb2.html index 48ab872e3..6d93d5190 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adb50d6043ace464d9f694869724d7fb2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adb50d6043ace464d9f694869724d7fb2.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5699 of file json.hpp.

+

Definition at line 5779 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adda9a4bd7f0edb9cb39dc0dca3d4a286.html b/classnlohmann_1_1basic__json_1_1const__iterator_adda9a4bd7f0edb9cb39dc0dca3d4a286.html index 6cd3c8236..560ed8aae 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adda9a4bd7f0edb9cb39dc0dca3d4a286.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adda9a4bd7f0edb9cb39dc0dca3d4a286.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6129 of file json.hpp.

+

Definition at line 6209 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adf6f9d3f8f8d8b1ccedabb4f04c098ad.html b/classnlohmann_1_1basic__json_1_1const__iterator_adf6f9d3f8f8d8b1ccedabb4f04c098ad.html index 55dce7f30..5d5eb9310 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adf6f9d3f8f8d8b1ccedabb4f04c098ad.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adf6f9d3f8f8d8b1ccedabb4f04c098ad.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5921 of file json.hpp.

+

Definition at line 6001 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ae480d5c86e5e1129d53d1e19782017a6.html b/classnlohmann_1_1basic__json_1_1const__iterator_ae480d5c86e5e1129d53d1e19782017a6.html index 10ea13c1f..87c582571 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ae480d5c86e5e1129d53d1e19782017a6.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ae480d5c86e5e1129d53d1e19782017a6.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5701 of file json.hpp.

+

Definition at line 5781 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aebd099d9a70ffe760242ef24046c9002.html b/classnlohmann_1_1basic__json_1_1const__iterator_aebd099d9a70ffe760242ef24046c9002.html index 612f9140a..0ff6d1a51 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aebd099d9a70ffe760242ef24046c9002.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aebd099d9a70ffe760242ef24046c9002.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6061 of file json.hpp.

+

Definition at line 6141 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_af34f68f1ce670e7f25ce267b2b1e64ab.html b/classnlohmann_1_1basic__json_1_1const__iterator_af34f68f1ce670e7f25ce267b2b1e64ab.html index f0fcd56ad..e0f91828b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_af34f68f1ce670e7f25ce267b2b1e64ab.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_af34f68f1ce670e7f25ce267b2b1e64ab.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6107 of file json.hpp.

+

Definition at line 6187 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_af55564e391b23e41abe78bc4bbe4edcb.html b/classnlohmann_1_1basic__json_1_1const__iterator_af55564e391b23e41abe78bc4bbe4edcb.html index b7c70ea00..dd2bbc03f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_af55564e391b23e41abe78bc4bbe4edcb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_af55564e391b23e41abe78bc4bbe4edcb.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 5761 of file json.hpp.

+

Definition at line 5841 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator-members.html b/classnlohmann_1_1basic__json_1_1iterator-members.html index 72f28711f..fa1b6c825 100644 --- a/classnlohmann_1_1basic__json_1_1iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1iterator-members.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1iterator.html b/classnlohmann_1_1basic__json_1_1iterator.html index 98335732e..3b37900f0 100644 --- a/classnlohmann_1_1basic__json_1_1iterator.html +++ b/classnlohmann_1_1basic__json_1_1iterator.html @@ -266,11 +266,11 @@ class nlohmann::basic_json::iterator
Since
version 1.0.0
-

Definition at line 6228 of file json.hpp.

+

Definition at line 6308 of file json.hpp.

diff --git a/classnlohmann_1_1basic__json_1_1iterator_a037e5f3de196ff4cea8a95a8a4e35882.html b/classnlohmann_1_1basic__json_1_1iterator_a037e5f3de196ff4cea8a95a8a4e35882.html index 2acb400d2..bce462ea9 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a037e5f3de196ff4cea8a95a8a4e35882.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a037e5f3de196ff4cea8a95a8a4e35882.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6281 of file json.hpp.

+

Definition at line 6361 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a0a43bd93e6e46645ed0b93d3af7bfe22.html b/classnlohmann_1_1basic__json_1_1iterator_a0a43bd93e6e46645ed0b93d3af7bfe22.html index 9b6f14017..30ce1c629 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a0a43bd93e6e46645ed0b93d3af7bfe22.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a0a43bd93e6e46645ed0b93d3af7bfe22.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6310 of file json.hpp.

+

Definition at line 6390 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a0c0acb68cc2a50a0e8782f860184883f.html b/classnlohmann_1_1basic__json_1_1iterator_a0c0acb68cc2a50a0e8782f860184883f.html index d814784ad..f34564583 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a0c0acb68cc2a50a0e8782f860184883f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a0c0acb68cc2a50a0e8782f860184883f.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6325 of file json.hpp.

+

Definition at line 6405 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a0eb7ac9b746fb6f931ae728f70f92a8e.html b/classnlohmann_1_1basic__json_1_1iterator_a0eb7ac9b746fb6f931ae728f70f92a8e.html index 8f10f30eb..17491c062 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a0eb7ac9b746fb6f931ae728f70f92a8e.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a0eb7ac9b746fb6f931ae728f70f92a8e.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6338 of file json.hpp.

+

Definition at line 6418 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a1220b360a07b0605f7d2f4b3cfd16736.html b/classnlohmann_1_1basic__json_1_1iterator_a1220b360a07b0605f7d2f4b3cfd16736.html index 913be87a7..baca0671c 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a1220b360a07b0605f7d2f4b3cfd16736.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a1220b360a07b0605f7d2f4b3cfd16736.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6267 of file json.hpp.

+

Definition at line 6347 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a21d32a4547ba4cbadd8b435a6a0d0e1b.html b/classnlohmann_1_1basic__json_1_1iterator_a21d32a4547ba4cbadd8b435a6a0d0e1b.html index 133d46d64..2c1b96946 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a21d32a4547ba4cbadd8b435a6a0d0e1b.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a21d32a4547ba4cbadd8b435a6a0d0e1b.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6296 of file json.hpp.

+

Definition at line 6376 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a302d810a0685f8d39368eaa65c833acf.html b/classnlohmann_1_1basic__json_1_1iterator_a302d810a0685f8d39368eaa65c833acf.html index 6c74a5b65..cf9e31515 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a302d810a0685f8d39368eaa65c833acf.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a302d810a0685f8d39368eaa65c833acf.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6332 of file json.hpp.

+

Definition at line 6412 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a33277dbf06ac5c1e7102e26f6b5e2c00.html b/classnlohmann_1_1basic__json_1_1iterator_a33277dbf06ac5c1e7102e26f6b5e2c00.html index 26cc392a4..005169cd8 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a33277dbf06ac5c1e7102e26f6b5e2c00.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a33277dbf06ac5c1e7102e26f6b5e2c00.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6261 of file json.hpp.

+

Definition at line 6341 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a4ae612fa9eb59784047b40f0419db65d.html b/classnlohmann_1_1basic__json_1_1iterator_a4ae612fa9eb59784047b40f0419db65d.html index 98758ce9a..781abb236 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a4ae612fa9eb59784047b40f0419db65d.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a4ae612fa9eb59784047b40f0419db65d.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6288 of file json.hpp.

+

Definition at line 6368 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a4f6e03ae3bb674ebf0b727f74957c12f.html b/classnlohmann_1_1basic__json_1_1iterator_a4f6e03ae3bb674ebf0b727f74957c12f.html index 7761dee33..2909baa33 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a4f6e03ae3bb674ebf0b727f74957c12f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a4f6e03ae3bb674ebf0b727f74957c12f.html @@ -139,7 +139,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a6e91e9d94a0e14d2fc28cfdf3beac2b1.html b/classnlohmann_1_1basic__json_1_1iterator_a6e91e9d94a0e14d2fc28cfdf3beac2b1.html index 7ae2aa31a..7346f2d0b 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a6e91e9d94a0e14d2fc28cfdf3beac2b1.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a6e91e9d94a0e14d2fc28cfdf3beac2b1.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6249 of file json.hpp.

+

Definition at line 6329 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a7031e759ee52d1283aada0ff81108a5e.html b/classnlohmann_1_1basic__json_1_1iterator_a7031e759ee52d1283aada0ff81108a5e.html index 90b4c1701..a0a636a08 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a7031e759ee52d1283aada0ff81108a5e.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a7031e759ee52d1283aada0ff81108a5e.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6303 of file json.hpp.

+

Definition at line 6383 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a94285e2ade0bfef829b81377bbbca6cf.html b/classnlohmann_1_1basic__json_1_1iterator_a94285e2ade0bfef829b81377bbbca6cf.html index ab9b12f50..910b59afb 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a94285e2ade0bfef829b81377bbbca6cf.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a94285e2ade0bfef829b81377bbbca6cf.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6244 of file json.hpp.

+

Definition at line 6324 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a9fcfda575b08d0c73b6274cdbbe7f184.html b/classnlohmann_1_1basic__json_1_1iterator_a9fcfda575b08d0c73b6274cdbbe7f184.html index 3931cb1c7..36e147b0f 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a9fcfda575b08d0c73b6274cdbbe7f184.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a9fcfda575b08d0c73b6274cdbbe7f184.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6273 of file json.hpp.

+

Definition at line 6353 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_aa2bd10afdcfc70acb8eaabbd2f6496f0.html b/classnlohmann_1_1basic__json_1_1iterator_aa2bd10afdcfc70acb8eaabbd2f6496f0.html index 650535bd2..4a833e3b8 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_aa2bd10afdcfc70acb8eaabbd2f6496f0.html +++ b/classnlohmann_1_1basic__json_1_1iterator_aa2bd10afdcfc70acb8eaabbd2f6496f0.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6233 of file json.hpp.

+

Definition at line 6313 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab220a0cc3fe410fbae4524208bd5834f.html b/classnlohmann_1_1basic__json_1_1iterator_ab220a0cc3fe410fbae4524208bd5834f.html index 8ee996d2f..8d11bddee 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab220a0cc3fe410fbae4524208bd5834f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab220a0cc3fe410fbae4524208bd5834f.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6239 of file json.hpp.

+

Definition at line 6319 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab5cf753cb2f8ce53b9f3e54c39e50ee3.html b/classnlohmann_1_1basic__json_1_1iterator_ab5cf753cb2f8ce53b9f3e54c39e50ee3.html index 8900949b9..a43d04e8e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab5cf753cb2f8ce53b9f3e54c39e50ee3.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab5cf753cb2f8ce53b9f3e54c39e50ee3.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6317 of file json.hpp.

+

Definition at line 6397 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_abaebf4e21956dd20d9f862fa5647d32d.html b/classnlohmann_1_1basic__json_1_1iterator_abaebf4e21956dd20d9f862fa5647d32d.html index 98719cae4..560871e05 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_abaebf4e21956dd20d9f862fa5647d32d.html +++ b/classnlohmann_1_1basic__json_1_1iterator_abaebf4e21956dd20d9f862fa5647d32d.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6231 of file json.hpp.

+

Definition at line 6311 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_af64127418c567660d92b1afdfe9676db.html b/classnlohmann_1_1basic__json_1_1iterator_af64127418c567660d92b1afdfe9676db.html index 97a654fa8..31fc5c285 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_af64127418c567660d92b1afdfe9676db.html +++ b/classnlohmann_1_1basic__json_1_1iterator_af64127418c567660d92b1afdfe9676db.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6344 of file json.hpp.

+

Definition at line 6424 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_afe65b5a0572c7bfdd7ccc942bb8e9fe2.html b/classnlohmann_1_1basic__json_1_1iterator_afe65b5a0572c7bfdd7ccc942bb8e9fe2.html index abe8b2d95..7f969eab5 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_afe65b5a0572c7bfdd7ccc942bb8e9fe2.html +++ b/classnlohmann_1_1basic__json_1_1iterator_afe65b5a0572c7bfdd7ccc942bb8e9fe2.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6232 of file json.hpp.

+

Definition at line 6312 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html index 0462ec51c..8a0958b57 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html @@ -112,7 +112,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html index d44c6d93b..00e8b0e4f 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html @@ -174,7 +174,7 @@ class nlohmann::basic_json::json_reverse_iterator< Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a03e542423284327d3801cf078f1c2b44.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a03e542423284327d3801cf078f1c2b44.html index 62f99899d..11df95cde 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a03e542423284327d3801cf078f1c2b44.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a03e542423284327d3801cf078f1c2b44.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6428 of file json.hpp.

+

Definition at line 6508 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a0b494ef7570d031216f907d2c85ec323.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a0b494ef7570d031216f907d2c85ec323.html index 423be1d9b..df05be1a4 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a0b494ef7570d031216f907d2c85ec323.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a0b494ef7570d031216f907d2c85ec323.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6377 of file json.hpp.

+

Definition at line 6457 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a15e9cf4c5a43238e82ab69c4a295c491.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a15e9cf4c5a43238e82ab69c4a295c491.html index fc4b9bee4..e5030a854 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a15e9cf4c5a43238e82ab69c4a295c491.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a15e9cf4c5a43238e82ab69c4a295c491.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 6393 of file json.hpp.

+

Definition at line 6473 of file json.hpp.

@@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a1c84e6d1f047ab4105fa665f455158a7.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a1c84e6d1f047ab4105fa665f455158a7.html index f3827efe1..ca8f6f4b3 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a1c84e6d1f047ab4105fa665f455158a7.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a1c84e6d1f047ab4105fa665f455158a7.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6420 of file json.hpp.

+

Definition at line 6500 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2a1dc92fbec862883c8b89755c787c99.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2a1dc92fbec862883c8b89755c787c99.html index 603fd3a41..212cbf5e6 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2a1dc92fbec862883c8b89755c787c99.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2a1dc92fbec862883c8b89755c787c99.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6413 of file json.hpp.

+

Definition at line 6493 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a5ee9ec91a6ddcd8d72278d681361626f.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a5ee9ec91a6ddcd8d72278d681361626f.html index 9fafa3c5b..9ca2ac02d 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a5ee9ec91a6ddcd8d72278d681361626f.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a5ee9ec91a6ddcd8d72278d681361626f.html @@ -117,7 +117,7 @@ template<typename Base >
-

Definition at line 6374 of file json.hpp.

+

Definition at line 6454 of file json.hpp.

@@ -127,7 +127,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a61d31531e0dfc5448e7fa15678b05bbe.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a61d31531e0dfc5448e7fa15678b05bbe.html index c6917fc4b..f17072e74 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a61d31531e0dfc5448e7fa15678b05bbe.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a61d31531e0dfc5448e7fa15678b05bbe.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 6455 of file json.hpp.

+

Definition at line 6535 of file json.hpp.

@@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a6bd38ed124df0332ba3263a9176b0101.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a6bd38ed124df0332ba3263a9176b0101.html index ee962222a..d98b2a32c 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a6bd38ed124df0332ba3263a9176b0101.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a6bd38ed124df0332ba3263a9176b0101.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6400 of file json.hpp.

+

Definition at line 6480 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a70086e392779ecbbc9e6845b2be126a0.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a70086e392779ecbbc9e6845b2be126a0.html index 93283cdc3..4ec7854e6 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a70086e392779ecbbc9e6845b2be126a0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a70086e392779ecbbc9e6845b2be126a0.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6382 of file json.hpp.

+

Definition at line 6462 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aa82b48aee07baee284f8340b37ec6864.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aa82b48aee07baee284f8340b37ec6864.html index 72cedb28b..7ef803c73 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aa82b48aee07baee284f8340b37ec6864.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aa82b48aee07baee284f8340b37ec6864.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6387 of file json.hpp.

+

Definition at line 6467 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ab6245ab29d8481ef2a2351c02cc31d4d.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ab6245ab29d8481ef2a2351c02cc31d4d.html index dc0aaf609..a10bae563 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ab6245ab29d8481ef2a2351c02cc31d4d.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ab6245ab29d8481ef2a2351c02cc31d4d.html @@ -117,7 +117,7 @@ template<typename Base >
-

Definition at line 6372 of file json.hpp.

+

Definition at line 6452 of file json.hpp.

@@ -127,7 +127,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac427d8f61858c13b7c16649bfbf75e76.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac427d8f61858c13b7c16649bfbf75e76.html index b82213221..943f780e4 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac427d8f61858c13b7c16649bfbf75e76.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac427d8f61858c13b7c16649bfbf75e76.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6436 of file json.hpp.

+

Definition at line 6516 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad3d6837b6f97065625c6c65f62f4b6d4.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad3d6837b6f97065625c6c65f62f4b6d4.html index 72654475c..b259349cb 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad3d6837b6f97065625c6c65f62f4b6d4.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad3d6837b6f97065625c6c65f62f4b6d4.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 6406 of file json.hpp.

+

Definition at line 6486 of file json.hpp.

@@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ae988bd36b7d098b1157871f83b2d6265.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ae988bd36b7d098b1157871f83b2d6265.html index 50a6efb24..b5f693beb 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ae988bd36b7d098b1157871f83b2d6265.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ae988bd36b7d098b1157871f83b2d6265.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 6442 of file json.hpp.

+

Definition at line 6522 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af972fce017b24906236ab235857a11a8.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af972fce017b24906236ab235857a11a8.html index cb76363b3..c81d98757 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af972fce017b24906236ab235857a11a8.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af972fce017b24906236ab235857a11a8.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 6448 of file json.hpp.

+

Definition at line 6528 of file json.hpp.

@@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_a01a2643289b69cd71d9b3f3fc209b748.html b/classnlohmann_1_1basic__json_a01a2643289b69cd71d9b3f3fc209b748.html index b6e82d9bd..e0a645e5a 100644 --- a/classnlohmann_1_1basic__json_a01a2643289b69cd71d9b3f3fc209b748.html +++ b/classnlohmann_1_1basic__json_a01a2643289b69cd71d9b3f3fc209b748.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -261,13 +263,13 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Logarithmic in the size of the JSON object.
Example
The example shows how count is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object
8  json j_object = {{"one", 1}, {"two", 2}};
9 
10  // call find
11  auto count_two = j_object.count("two");
12  auto count_three = j_object.count("three");
13 
14  // print values
15  std::cout << std::boolalpha;
16  std::cout << "number of elements with key \"two\": " << count_two << '\n';
17  std::cout << "number of elements with key \"three\": " << count_three << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
size_type count(typename object_t::key_type key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:3584
+
size_type count(typename object_t::key_type key) const
returns the number of occurrences of a key in a JSON object
Definition: json.hpp:3664
Output (play with this example online):
number of elements with key "two": 1
 number of elements with key "three": 0
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/count.cpp -o count 
Since
version 1.0.0
-

Definition at line 3584 of file json.hpp.

+

Definition at line 3664 of file json.hpp.

@@ -277,7 +279,7 @@ number of elements with key "three": 0 diff --git a/classnlohmann_1_1basic__json_a0703ae5cbd2daac5e6c0ae01d3a1b114.html b/classnlohmann_1_1basic__json_a0703ae5cbd2daac5e6c0ae01d3a1b114.html index 0956cf2de..a361c7628 100644 --- a/classnlohmann_1_1basic__json_a0703ae5cbd2daac5e6c0ae01d3a1b114.html +++ b/classnlohmann_1_1basic__json_a0703ae5cbd2daac5e6c0ae01d3a1b114.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Logarithmic in the size of the container, O(log(size())).
Example
The example shows how push_back and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json object = {{"one", 1}, {"two", 2}};
9  json null;
10 
11  // print values
12  std::cout << object << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  object.push_back(json::object_t::value_type("three", 3));
17  object += json::object_t::value_type("four", 4);
18  null += json::object_t::value_type("A", "a");
19  null += json::object_t::value_type("B", "b");
20 
21  // print values
22  std::cout << object << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
{"one":1,"two":2}
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back__object_t__value.cpp -o push_back__object_t__value 
Since
version 1.0.0
-

Definition at line 4253 of file json.hpp.

+

Definition at line 4333 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a07c9c38a1f01675759e05d5d34627343.html b/classnlohmann_1_1basic__json_a07c9c38a1f01675759e05d5d34627343.html index 711d89575..96d31ab10 100644 --- a/classnlohmann_1_1basic__json_a07c9c38a1f01675759e05d5d34627343.html +++ b/classnlohmann_1_1basic__json_a07c9c38a1f01675759e05d5d34627343.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,15 +280,15 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Constant plus linear in the distance between pos and end of the container.
Example
The example shows how insert is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json v = {1, 2, 3, 4};
9 
10  // insert number 10 before number 3
11  auto new_pos = v.insert(v.begin() + 2, 10);
12 
13  // output new array and result of insert call
14  std::cout << *new_pos << '\n';
15  std::cout << v << '\n';
16 }
a class to store JSON values
Definition: json.hpp:188
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
namespace for Niels Lohmann
Definition: json.hpp:79
-
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4281
+
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4361
Output (play with this example online):
10
 [1,2,10,3,4]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
Since
version 1.0.0
-

Definition at line 4308 of file json.hpp.

+

Definition at line 4388 of file json.hpp.

@@ -296,7 +298,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a088460b5d95f384a4f2ec9e52f4f66ba.html b/classnlohmann_1_1basic__json_a088460b5d95f384a4f2ec9e52f4f66ba.html index 925b5d91c..5e5735f06 100644 --- a/classnlohmann_1_1basic__json_a088460b5d95f384a4f2ec9e52f4f66ba.html +++ b/classnlohmann_1_1basic__json_a088460b5d95f384a4f2ec9e52f4f66ba.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ true diff --git a/classnlohmann_1_1basic__json_a0afa4512f03406db0d0432657e9c7361.html b/classnlohmann_1_1basic__json_a0afa4512f03406db0d0432657e9c7361.html index 145df4934..70a6692ed 100644 --- a/classnlohmann_1_1basic__json_a0afa4512f03406db0d0432657e9c7361.html +++ b/classnlohmann_1_1basic__json_a0afa4512f03406db0d0432657e9c7361.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -322,7 +324,7 @@ false diff --git a/classnlohmann_1_1basic__json_a114095c452ca2f4ba976548df3da68be.html b/classnlohmann_1_1basic__json_a114095c452ca2f4ba976548df3da68be.html index 5bf7038a6..3b887ec70 100644 --- a/classnlohmann_1_1basic__json_a114095c452ca2f4ba976548df3da68be.html +++ b/classnlohmann_1_1basic__json_a114095c452ca2f4ba976548df3da68be.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_a11c3dd843c21c58daa651e84046a82af.html b/classnlohmann_1_1basic__json_a11c3dd843c21c58daa651e84046a82af.html index 251bb47b3..ed593eeda 100644 --- a/classnlohmann_1_1basic__json_a11c3dd843c21c58daa651e84046a82af.html +++ b/classnlohmann_1_1basic__json_a11c3dd843c21c58daa651e84046a82af.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html index 66584499c..1eaaec5ba 100644 --- a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html +++ b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__equal.cpp -o operator__equal 
Since
version 1.0.0
-

Definition at line 4665 of file json.hpp.

+

Definition at line 4745 of file json.hpp.

@@ -293,7 +295,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a13e5642dbfa1602c937d295a085413cc.html b/classnlohmann_1_1basic__json_a13e5642dbfa1602c937d295a085413cc.html index 63ae5a814..ec912f4f6 100644 --- a/classnlohmann_1_1basic__json_a13e5642dbfa1602c937d295a085413cc.html +++ b/classnlohmann_1_1basic__json_a13e5642dbfa1602c937d295a085413cc.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a1683189bd539313b5559f07961166c8b.html b/classnlohmann_1_1basic__json_a1683189bd539313b5559f07961166c8b.html index 677da5540..f97a20d07 100644 --- a/classnlohmann_1_1basic__json_a1683189bd539313b5559f07961166c8b.html +++ b/classnlohmann_1_1basic__json_a1683189bd539313b5559f07961166c8b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a16a275d0201e9aedc87c933c764b8869.html b/classnlohmann_1_1basic__json_a16a275d0201e9aedc87c933c764b8869.html index 031c66d74..d06c2620a 100644 --- a/classnlohmann_1_1basic__json_a16a275d0201e9aedc87c933c764b8869.html +++ b/classnlohmann_1_1basic__json_a16a275d0201e9aedc87c933c764b8869.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,7 +269,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Logarithmic in the size of the container.
Example
The example below shows how object elements can be read using at.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON object
8  json object =
9  {
10  {"the good", "il buono"},
11  {"the bad", "il cativo"},
12  {"the ugly", "il brutto"}
13  };
14 
15  // output element with key "the ugly"
16  std::cout << object.at("the ugly") << '\n';
17 
18  // try to read from a nonexisting key
19  try
20  {
21  std::cout << object.at("the fast") << '\n';
22  }
23  catch (std::out_of_range)
24  {
25  std::cout << "out of range" << '\n';
26  }
27 }
a class to store JSON values
Definition: json.hpp:188
-
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2638
+
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2718
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"il brutto"
 out of range
@@ -277,7 +279,7 @@ out of range
 value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 2778 of file json.hpp.

+

Definition at line 2858 of file json.hpp.

@@ -287,7 +289,7 @@ out of range diff --git a/classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html b/classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html new file mode 100644 index 000000000..7d567201c --- /dev/null +++ b/classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html @@ -0,0 +1,297 @@ + + + + + + +JSON for Modern C++: nlohmann::basic_json::get_ref + + + + + + + + + + + +
+
+ + + + + + +
+
JSON for Modern C++ +  1.0.0 +
+
+
+ + + + + +
+
+ + +
+ +
+ + +
+
+ + + + + +
+ + + +
+
+
+template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
+
+template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value , int >::type = 0>
+ + + + + +
+ + + + + + + +
ReferenceType nlohmann::basic_json::get_ref ()
+
+inline
+
+

Implict reference access to the internally stored JSON value. No copies are made.

+
Warning
Writing data to the referee of the result yields an undefined state.
+
Template Parameters
+ + +
ReferenceTypereference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t.
+
+
+
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws std::domain_error otherwise
+
Exceptions
+ + +
std::domain_errorin case passed type ReferenceType is incompatible with the stored JSON value
+
+
+
Complexity
Constant.
+
Example
The example shows several calls to get_ref().
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting references
11  auto r1 = value.get_ref<const json::number_integer_t&>();
12  auto r2 = value.get_ref<json::number_integer_t&>();
13 
14  // print the values
15  std::cout << r1 << ' ' << r2 << '\n';
16 
17  // incompatible type throws exception
18  try
19  {
20  auto r3 = value.get_ref<json::number_float_t&>();
21  }
22  catch (std::domain_error& ex)
23  {
24  std::cout << ex.what() << '\n';
25  }
26 }
a class to store JSON values
Definition: json.hpp:188
+
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:2625
+
namespace for Niels Lohmann
Definition: json.hpp:79
+
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
+
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
+
Output (play with this example online):
17 17
+incompatible ReferenceType for get_ref, actual type is number
+
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/get_ref.cpp -o get_ref 
+
Since
version 1.0.1
+ +

Definition at line 2625 of file json.hpp.

+ +
+
+
+
+ + + + diff --git a/classnlohmann_1_1basic__json_a1dc0c521042807e216d11110d2f002ff.html b/classnlohmann_1_1basic__json_a1dc0c521042807e216d11110d2f002ff.html index ca929995f..3011b2377 100644 --- a/classnlohmann_1_1basic__json_a1dc0c521042807e216d11110d2f002ff.html +++ b/classnlohmann_1_1basic__json_a1dc0c521042807e216d11110d2f002ff.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -291,7 +293,7 @@ template<class CompatibleStringType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html index 72777a9f7..a66394ad1 100644 --- a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html +++ b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -285,7 +287,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html b/classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html index 518935692..3082dcc55 100644 --- a/classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html +++ b/classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<typename PointerType , typename std::enable_if<
Complexity
Constant.
Example
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting pointers
11  auto p1 = value.get_ptr<const json::number_integer_t*>();
12  auto p2 = value.get_ptr<json::number_integer_t*>();
13  auto p3 = value.get_ptr<json::number_integer_t* const>();
14  auto p4 = value.get_ptr<const json::number_integer_t* const>();
15  auto p5 = value.get_ptr<json::number_float_t*>();
16 
17  // print the pointees
18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
20 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.hpp:2545
+
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.hpp:2574
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
Output (play with this example online):
17 17 17 17
@@ -271,7 +273,7 @@ true
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/get_ptr.cpp -o get_ptr 
Since
version 1.0.0
-

Definition at line 2560 of file json.hpp.

+

Definition at line 2589 of file json.hpp.

@@ -281,7 +283,7 @@ true diff --git a/classnlohmann_1_1basic__json_a266c4dd24d11a86e4831523af5d9df4d.html b/classnlohmann_1_1basic__json_a266c4dd24d11a86e4831523af5d9df4d.html index 8c4f990a2..c25ba92ef 100644 --- a/classnlohmann_1_1basic__json_a266c4dd24d11a86e4831523af5d9df4d.html +++ b/classnlohmann_1_1basic__json_a266c4dd24d11a86e4831523af5d9df4d.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -297,7 +299,7 @@ This function is required for compatibility reasons with Clang. value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 3004 of file json.hpp.

+

Definition at line 3084 of file json.hpp.

@@ -307,7 +309,7 @@ This function is required for compatibility reasons with Clang. diff --git a/classnlohmann_1_1basic__json_a26b7e4876af25eae5800ce43f93aaef2.html b/classnlohmann_1_1basic__json_a26b7e4876af25eae5800ce43f93aaef2.html index 5cbca232c..6e9e32e1c 100644 --- a/classnlohmann_1_1basic__json_a26b7e4876af25eae5800ce43f93aaef2.html +++ b/classnlohmann_1_1basic__json_a26b7e4876af25eae5800ce43f93aaef2.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -289,7 +291,7 @@ value() with null"
Complexity
Logarithmic in the size of the container.
Example
The example below shows how object elements can be queried with a default value.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object with different entry types
8  json j =
9  {
10  {"integer", 1},
11  {"floating", 42.23},
12  {"string", "hello world"},
13  {"boolean", true},
14  {"object", {{"key1", 1}, {"key2", 2}}},
15  {"array", {1, 2, 3}}
16  };
17 
18  // access existing values
19  int v_integer = j.value("integer", 0);
20  double v_floating = j.value("floating", 47.11);
21 
22  // access nonexisting values and rely on default value
23  std::string v_string = j.value("nonexisting", "oops");
24  bool v_boolean = j.value("nonexisting", false);
25 
26  // output values
27  std::cout << std::boolalpha << v_integer << " " << v_floating
28  << " " << v_string << " " << v_boolean << "\n";
29 }
a class to store JSON values
Definition: json.hpp:188
-
ValueType value(const typename object_t::key_type &key, ValueType default_value) const
access specified object element with default value
Definition: json.hpp:3122
+
ValueType value(const typename object_t::key_type &key, ValueType default_value) const
access specified object element with default value
Definition: json.hpp:3202
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
1 42.23 oops false
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/basic_json__value.cpp -o basic_json__value 
@@ -298,7 +300,7 @@ value() with null" operator[](const typename object_t::key_type&) for unchecked access by reference
Since
version 1.0.0
-

Definition at line 3122 of file json.hpp.

+

Definition at line 3202 of file json.hpp.

@@ -308,7 +310,7 @@ value() with null" diff --git a/classnlohmann_1_1basic__json_a2adfc8d24bea3908398cbf325b5dc1d7.html b/classnlohmann_1_1basic__json_a2adfc8d24bea3908398cbf325b5dc1d7.html index f9e56181f..96e0fa55a 100644 --- a/classnlohmann_1_1basic__json_a2adfc8d24bea3908398cbf325b5dc1d7.html +++ b/classnlohmann_1_1basic__json_a2adfc8d24bea3908398cbf325b5dc1d7.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,13 +264,13 @@ Illustration from cppreference.com
Example
The following code shows an example for crbegin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-beginning
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
const_reverse_iterator crbegin() const
returns a const reverse iterator to the last element
Definition: json.hpp:3798
+
const_reverse_iterator crbegin() const
returns a const reverse iterator to the last element
Definition: json.hpp:3878
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/crbegin.cpp -o crbegin 
Since
version 1.0.0
-

Definition at line 3744 of file json.hpp.

+

Definition at line 3824 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a2f07bcf7e75c34396476dd1790f26ce8.html b/classnlohmann_1_1basic__json_a2f07bcf7e75c34396476dd1790f26ce8.html index 9016b12c1..81751bd87 100644 --- a/classnlohmann_1_1basic__json_a2f07bcf7e75c34396476dd1790f26ce8.html +++ b/classnlohmann_1_1basic__json_a2f07bcf7e75c34396476dd1790f26ce8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Logarithmic in the size of the container, O(log(size())).
Example
The example shows how push_back and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json object = {{"one", 1}, {"two", 2}};
9  json null;
10 
11  // print values
12  std::cout << object << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  object.push_back(json::object_t::value_type("three", 3));
17  object += json::object_t::value_type("four", 4);
18  null += json::object_t::value_type("A", "a");
19  null += json::object_t::value_type("B", "b");
20 
21  // print values
22  std::cout << object << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
{"one":1,"two":2}
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back__object_t__value.cpp -o push_back__object_t__value 
Since
version 1.0.0
-

Definition at line 4229 of file json.hpp.

+

Definition at line 4309 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html b/classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html new file mode 100644 index 000000000..e6fb407ad --- /dev/null +++ b/classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html @@ -0,0 +1,297 @@ + + + + + + +JSON for Modern C++: nlohmann::basic_json::get_ref + + + + + + + + + + + +
+
+ + + + + + +
+
JSON for Modern C++ +  1.0.0 +
+
+
+ + + + + +
+
+ + +
+ +
+ + +
+
+ + + + + +
+ + + +
+
+
+template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
+
+template<typename ReferenceType , typename std::enable_if< std::is_reference< ReferenceType >::value and std::is_const< typename std::remove_reference< ReferenceType >::type >::value , int >::type = 0>
+ + + + + +
+ + + + + + + +
ReferenceType nlohmann::basic_json::get_ref () const
+
+inline
+
+

get a reference value (implicit) Implict reference access to the internally stored JSON value. No copies are made.

+
Warning
Writing data to the referee of the result yields an undefined state.
+
Template Parameters
+ + +
ReferenceTypereference type; must be a reference to array_t, object_t, string_t, boolean_t, number_integer_t, or number_float_t.
+
+
+
Returns
reference to the internally stored JSON value if the requested reference type ReferenceType fits to the JSON value; throws std::domain_error otherwise
+
Exceptions
+ + +
std::domain_errorin case passed type ReferenceType is incompatible with the stored JSON value
+
+
+
Complexity
Constant.
+
Example
The example shows several calls to get_ref().
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting references
11  auto r1 = value.get_ref<const json::number_integer_t&>();
12  auto r2 = value.get_ref<json::number_integer_t&>();
13 
14  // print the values
15  std::cout << r1 << ' ' << r2 << '\n';
16 
17  // incompatible type throws exception
18  try
19  {
20  auto r3 = value.get_ref<json::number_float_t&>();
21  }
22  catch (std::domain_error& ex)
23  {
24  std::cout << ex.what() << '\n';
25  }
26 }
a class to store JSON values
Definition: json.hpp:188
+
ReferenceType get_ref()
get a reference value (implicit)
Definition: json.hpp:2625
+
namespace for Niels Lohmann
Definition: json.hpp:79
+
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
+
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
+
Output (play with this example online):
17 17
+incompatible ReferenceType for get_ref, actual type is number
+
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/get_ref.cpp -o get_ref 
+
Since
version 1.0.1
+ +

Definition at line 2640 of file json.hpp.

+ +
+
+
+
+ + + + diff --git a/classnlohmann_1_1basic__json_a3173944e7b1809a333def4078a0b92a3.html b/classnlohmann_1_1basic__json_a3173944e7b1809a333def4078a0b92a3.html index 29eb0e00a..289f04e29 100644 --- a/classnlohmann_1_1basic__json_a3173944e7b1809a333def4078a0b92a3.html +++ b/classnlohmann_1_1basic__json_a3173944e7b1809a333def4078a0b92a3.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Amortized constant.
Example
The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json array = {1, 2, 3, 4, 5};
9  json null;
10 
11  // print values
12  std::cout << array << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  array.push_back(6);
17  array += 7;
18  null += "first";
19  null += "second";
20 
21  // print values
22  std::cout << array << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
[1,2,3,4,5]
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back.cpp -o push_back 
Since
version 1.0.0
-

Definition at line 4169 of file json.hpp.

+

Definition at line 4249 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a317b01b0fba3ac458561f1634759ea3b.html b/classnlohmann_1_1basic__json_a317b01b0fba3ac458561f1634759ea3b.html index 8e78647b6..7e11abc18 100644 --- a/classnlohmann_1_1basic__json_a317b01b0fba3ac458561f1634759ea3b.html +++ b/classnlohmann_1_1basic__json_a317b01b0fba3ac458561f1634759ea3b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -253,7 +255,7 @@ template<template< typename U, typename V, typename...Args > class Obje

This function allows to access iterator::key() and iterator::value() during range-based for loops. In these loops, a reference to the JSON values is returned, so there is no access to the underlying iterator.

Note
The name of this function is not yet final and may change in the future.
-

Definition at line 3842 of file json.hpp.

+

Definition at line 3922 of file json.hpp.

@@ -263,7 +265,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a3287df6546c905fb0a5786deb4b1cf32.html b/classnlohmann_1_1basic__json_a3287df6546c905fb0a5786deb4b1cf32.html index adea66ad7..ebac2ee0c 100644 --- a/classnlohmann_1_1basic__json_a3287df6546c905fb0a5786deb4b1cf32.html +++ b/classnlohmann_1_1basic__json_a3287df6546c905fb0a5786deb4b1cf32.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -277,7 +279,7 @@ template<template< typename U, typename V, typename...Args > class Obje
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
array (ordered collection of values)
-
bool empty() const noexcept
checks whether the container is empty
Definition: json.hpp:3894
+
bool empty() const noexcept
checks whether the container is empty
Definition: json.hpp:3974
Output (play with this example online):
true
 false
 false
@@ -290,7 +292,7 @@ false
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/empty.cpp -o empty 
Since
version 1.0.0
-

Definition at line 3894 of file json.hpp.

+

Definition at line 3974 of file json.hpp.

@@ -300,7 +302,7 @@ false diff --git a/classnlohmann_1_1basic__json_a33f1632cfdbf460b4913f4e8a43dd9e4.html b/classnlohmann_1_1basic__json_a33f1632cfdbf460b4913f4e8a43dd9e4.html index 6f2058ca3..8e76d5f19 100644 --- a/classnlohmann_1_1basic__json_a33f1632cfdbf460b4913f4e8a43dd9e4.html +++ b/classnlohmann_1_1basic__json_a33f1632cfdbf460b4913f4e8a43dd9e4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -276,7 +278,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html index 0939c5e87..592442486 100644 --- a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html +++ b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -292,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator_serialize.cpp -o operator_serialize 
Since
version 1.0.0
-

Definition at line 5018 of file json.hpp.

+

Definition at line 5098 of file json.hpp.

@@ -302,7 +304,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a3d4e4bab95b24ccab42ed37e0ede2d98.html b/classnlohmann_1_1basic__json_a3d4e4bab95b24ccab42ed37e0ede2d98.html index 5f24a72c2..fe2b727f1 100644 --- a/classnlohmann_1_1basic__json_a3d4e4bab95b24ccab42ed37e0ede2d98.html +++ b/classnlohmann_1_1basic__json_a3d4e4bab95b24ccab42ed37e0ede2d98.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a42f9133f978dde4cce5851b2c2434a0c.html b/classnlohmann_1_1basic__json_a42f9133f978dde4cce5851b2c2434a0c.html index 3c783fb8c..0b347c161 100644 --- a/classnlohmann_1_1basic__json_a42f9133f978dde4cce5851b2c2434a0c.html +++ b/classnlohmann_1_1basic__json_a42f9133f978dde4cce5851b2c2434a0c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ true diff --git a/classnlohmann_1_1basic__json_a4361aa791f3980abb239e4155a3450cb.html b/classnlohmann_1_1basic__json_a4361aa791f3980abb239e4155a3450cb.html index a28df3bb3..e4f4aa118 100644 --- a/classnlohmann_1_1basic__json_a4361aa791f3980abb239e4155a3450cb.html +++ b/classnlohmann_1_1basic__json_a4361aa791f3980abb239e4155a3450cb.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,14 +264,14 @@ Illustration from cppreference.com
Example
The following code shows an example for cbegin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  const json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to the first element
11  json::const_iterator it = array.cbegin();
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
-
const_iterator cbegin() const
returns a const iterator to the first element
Definition: json.hpp:3653
+
const_iterator cbegin() const
returns a const iterator to the first element
Definition: json.hpp:3733
namespace for Niels Lohmann
Definition: json.hpp:79
-
a const random access iterator for the basic_json class
Definition: json.hpp:5686
+
a const random access iterator for the basic_json class
Definition: json.hpp:5766
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
Since
version 1.0.0
-

Definition at line 3629 of file json.hpp.

+

Definition at line 3709 of file json.hpp.

@@ -279,7 +281,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a457fec897d7b6283c60ca236ebb1f5e8.html b/classnlohmann_1_1basic__json_a457fec897d7b6283c60ca236ebb1f5e8.html index 42d16da66..e92e93625 100644 --- a/classnlohmann_1_1basic__json_a457fec897d7b6283c60ca236ebb1f5e8.html +++ b/classnlohmann_1_1basic__json_a457fec897d7b6283c60ca236ebb1f5e8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a48c8d153bc2fd1af655063a4b984feac.html b/classnlohmann_1_1basic__json_a48c8d153bc2fd1af655063a4b984feac.html index d633b1c1f..09338baa4 100644 --- a/classnlohmann_1_1basic__json_a48c8d153bc2fd1af655063a4b984feac.html +++ b/classnlohmann_1_1basic__json_a48c8d153bc2fd1af655063a4b984feac.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -284,7 +286,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a4943b7f16ddc4e0df33c0cae7ef14471.html b/classnlohmann_1_1basic__json_a4943b7f16ddc4e0df33c0cae7ef14471.html index 06cfd9e21..778099221 100644 --- a/classnlohmann_1_1basic__json_a4943b7f16ddc4e0df33c0cae7ef14471.html +++ b/classnlohmann_1_1basic__json_a4943b7f16ddc4e0df33c0cae7ef14471.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,13 +264,13 @@ Illustration from cppreference.com
Example
The following code shows an example for crend.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-end
12 
13  // increment the iterator to point to the first element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
const_reverse_iterator crend() const
returns a const reverse iterator to one before the first
Definition: json.hpp:3821
+
const_reverse_iterator crend() const
returns a const reverse iterator to one before the first
Definition: json.hpp:3901
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/crend.cpp -o crend 
Since
version 1.0.0
-

Definition at line 3821 of file json.hpp.

+

Definition at line 3901 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a4ad3f27ecece8f644e8dca69a97eb67f.html b/classnlohmann_1_1basic__json_a4ad3f27ecece8f644e8dca69a97eb67f.html index 553731bc5..7bffb021e 100644 --- a/classnlohmann_1_1basic__json_a4ad3f27ecece8f644e8dca69a97eb67f.html +++ b/classnlohmann_1_1basic__json_a4ad3f27ecece8f644e8dca69a97eb67f.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,13 +264,13 @@ Illustration from cppreference.com
Example
The following code shows an example for crend.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-end
12 
13  // increment the iterator to point to the first element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
const_reverse_iterator crend() const
returns a const reverse iterator to one before the first
Definition: json.hpp:3821
+
const_reverse_iterator crend() const
returns a const reverse iterator to one before the first
Definition: json.hpp:3901
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/crend.cpp -o crend 
Since
version 1.0.0
-

Definition at line 3775 of file json.hpp.

+

Definition at line 3855 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a4bf695ddf4a00ea8feea2c725ec847f1.html b/classnlohmann_1_1basic__json_a4bf695ddf4a00ea8feea2c725ec847f1.html index f5b6d378b..29dcc5389 100644 --- a/classnlohmann_1_1basic__json_a4bf695ddf4a00ea8feea2c725ec847f1.html +++ b/classnlohmann_1_1basic__json_a4bf695ddf4a00ea8feea2c725ec847f1.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,13 +269,13 @@ template<template< typename U, typename V, typename...Args > class Obje
Example
The example below shows how JSON values can be swapped.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON value
8  json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
9 
10  // create an object_t
11  json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
12 
13  // swap the object stored in the JSON value
14  value["translation"].swap(object);
15 
16  // output the values
17  std::cout << "value = " << value << '\n';
18  std::cout << "object = " << object << '\n';
19 }
a class to store JSON values
Definition: json.hpp:188
ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
a type for an object
Definition: json.hpp:341
namespace for Niels Lohmann
Definition: json.hpp:79
-
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4486
+
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4566
Output (play with this example online):
value = {"translation":{"cow":"Kuh","dog":"Hund"}}
 object = {"one":"eins","two":"zwei"}
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/swap__object_t.cpp -o swap__object_t 
Since
version 1.0.0
-

Definition at line 4551 of file json.hpp.

+

Definition at line 4631 of file json.hpp.

@@ -283,7 +285,7 @@ object = {"one":"eins","two":"zwei"} diff --git a/classnlohmann_1_1basic__json_a4d688b5ff534d3ab4e284b3191061529.html b/classnlohmann_1_1basic__json_a4d688b5ff534d3ab4e284b3191061529.html index f6e7a5a14..7b667d2ce 100644 --- a/classnlohmann_1_1basic__json_a4d688b5ff534d3ab4e284b3191061529.html +++ b/classnlohmann_1_1basic__json_a4d688b5ff534d3ab4e284b3191061529.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,13 +264,13 @@ Illustration from cppreference.com
Example
The following code shows an example for crbegin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-beginning
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
const_reverse_iterator crbegin() const
returns a const reverse iterator to the last element
Definition: json.hpp:3798
+
const_reverse_iterator crbegin() const
returns a const reverse iterator to the last element
Definition: json.hpp:3878
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/crbegin.cpp -o crbegin 
Since
version 1.0.0
-

Definition at line 3798 of file json.hpp.

+

Definition at line 3878 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a5114ed5eb394a2805da0bd1acba95ae2.html b/classnlohmann_1_1basic__json_a5114ed5eb394a2805da0bd1acba95ae2.html index 896332fbb..1cc904fc9 100644 --- a/classnlohmann_1_1basic__json_a5114ed5eb394a2805da0bd1acba95ae2.html +++ b/classnlohmann_1_1basic__json_a5114ed5eb394a2805da0bd1acba95ae2.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Amortized constant.
Example
The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json array = {1, 2, 3, 4, 5};
9  json null;
10 
11  // print values
12  std::cout << array << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  array.push_back(6);
17  array += 7;
18  null += "first";
19  null += "second";
20 
21  // print values
22  std::cout << array << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
[1,2,3,4,5]
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back.cpp -o push_back 
Since
version 1.0.0
-

Definition at line 4179 of file json.hpp.

+

Definition at line 4259 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a53a2abfdd4f72c7df5aba1155bf03e48.html b/classnlohmann_1_1basic__json_a53a2abfdd4f72c7df5aba1155bf03e48.html index 84fca78c8..1cd0cdf2d 100644 --- a/classnlohmann_1_1basic__json_a53a2abfdd4f72c7df5aba1155bf03e48.html +++ b/classnlohmann_1_1basic__json_a53a2abfdd4f72c7df5aba1155bf03e48.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -276,7 +278,7 @@ false diff --git a/classnlohmann_1_1basic__json_a57703688bee6b9736ab3a430d8d246f2.html b/classnlohmann_1_1basic__json_a57703688bee6b9736ab3a430d8d246f2.html index ec38c5a95..e78df104e 100644 --- a/classnlohmann_1_1basic__json_a57703688bee6b9736ab3a430d8d246f2.html +++ b/classnlohmann_1_1basic__json_a57703688bee6b9736ab3a430d8d246f2.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ use operator[] with null" The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operatorarray__size_type.cpp -o operatorarray__size_type 
Since
version 1.0.0
-

Definition at line 2825 of file json.hpp.

+

Definition at line 2905 of file json.hpp.

@@ -285,7 +287,7 @@ use operator[] with null" diff --git a/classnlohmann_1_1basic__json_a57a96ab3ff1ce7b48a754129fb12c982.html b/classnlohmann_1_1basic__json_a57a96ab3ff1ce7b48a754129fb12c982.html index cb9b68f43..244913a8a 100644 --- a/classnlohmann_1_1basic__json_a57a96ab3ff1ce7b48a754129fb12c982.html +++ b/classnlohmann_1_1basic__json_a57a96ab3ff1ce7b48a754129fb12c982.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,13 +270,13 @@ use swap() with boolean"
Example
The example below shows how JSON values can be swapped.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON value
8  json value = { "the good", "the bad", "the ugly" };
9 
10  // create string_t
11  json::string_t string = "the fast";
12 
13  // swap the object stored in the JSON value
14  value[1].swap(string);
15 
16  // output the values
17  std::cout << "value = " << value << '\n';
18  std::cout << "string = " << string << '\n';
19 }
StringType string_t
a type for a string
Definition: json.hpp:434
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4486
+
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4566
Output (play with this example online):
value = ["the good","the fast","the ugly"]
 string = the bad
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/swap__string_t.cpp -o swap__string_t 
Since
version 1.0.0
-

Definition at line 4585 of file json.hpp.

+

Definition at line 4665 of file json.hpp.

@@ -284,7 +286,7 @@ string = the bad diff --git a/classnlohmann_1_1basic__json_a5a2d4dbcdbc8ea065b87daf52cd786b9.html b/classnlohmann_1_1basic__json_a5a2d4dbcdbc8ea065b87daf52cd786b9.html index 8262b4ef2..5e553c8bc 100644 --- a/classnlohmann_1_1basic__json_a5a2d4dbcdbc8ea065b87daf52cd786b9.html +++ b/classnlohmann_1_1basic__json_a5a2d4dbcdbc8ea065b87daf52cd786b9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -271,7 +273,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html index 386a47d94..25d70861f 100644 --- a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html +++ b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__greater.cpp -o operator__greater 
Since
version 1.0.0
-

Definition at line 4919 of file json.hpp.

+

Definition at line 4999 of file json.hpp.

@@ -289,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a5d428360d75a52f6af74751d1cc912c6.html b/classnlohmann_1_1basic__json_a5d428360d75a52f6af74751d1cc912c6.html index 7c55d1325..adf02b93d 100644 --- a/classnlohmann_1_1basic__json_a5d428360d75a52f6af74751d1cc912c6.html +++ b/classnlohmann_1_1basic__json_a5d428360d75a52f6af74751d1cc912c6.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ true diff --git a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html index df12ba63b..ee93ff539 100644 --- a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html +++ b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -292,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator_serialize.cpp -o operator_serialize 
Since
version 1.0.0
-

Definition at line 5000 of file json.hpp.

+

Definition at line 5080 of file json.hpp.

@@ -302,7 +304,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html b/classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html index b2a3a57cd..187b3ef94 100644 --- a/classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html +++ b/classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,7 +270,7 @@ template<typename ValueType , typename std::enable_if<
Complexity
Linear in the size of the JSON value.
Example
The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard std::vector<short>, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string, json>.
1 #include <json.hpp>
2 #include <unordered_map>
3 
4 using namespace nlohmann;
5 
6 int main()
7 {
8  // create a JSON value with different types
9  json json_types =
10  {
11  {"boolean", true},
12  {
13  "number", {
14  {"integer", 42},
15  {"floating-point", 17.23}
16  }
17  },
18  {"string", "Hello, world!"},
19  {"array", {1, 2, 3, 4, 5}},
20  {"null", nullptr}
21  };
22 
23  // use explicit conversions
24  auto v1 = json_types["boolean"].get<bool>();
25  auto v2 = json_types["number"]["integer"].get<int>();
26  auto v3 = json_types["number"]["integer"].get<short>();
27  auto v4 = json_types["number"]["floating-point"].get<float>();
28  auto v5 = json_types["number"]["floating-point"].get<int>();
29  auto v6 = json_types["string"].get<std::string>();
30  auto v7 = json_types["array"].get<std::vector<short>>();
31  auto v8 = json_types.get<std::unordered_map<std::string, json>>();
32 
33  // print the conversion results
34  std::cout << v1 << '\n';
35  std::cout << v2 << ' ' << v3 << '\n';
36  std::cout << v4 << ' ' << v5 << '\n';
37  std::cout << v6 << '\n';
38 
39  for (auto i : v7)
40  {
41  std::cout << i << ' ';
42  }
43  std::cout << "\n\n";
44 
45  for (auto i : v8)
46  {
47  std::cout << i.first << ": " << i.second << '\n';
48  }
49 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
ValueType get() const
get a value (explicit)
Definition: json.hpp:2461
+
ValueType get() const
get a value (explicit)
Definition: json.hpp:2490
Output (play with this example online):
1
 42 42
 17.23 17
@@ -286,7 +288,7 @@ array: [1,2,3,4,5]
 get() for pointer-member access
Since
version 1.0.0
-

Definition at line 2461 of file json.hpp.

+

Definition at line 2490 of file json.hpp.

@@ -296,7 +298,7 @@ array: [1,2,3,4,5] diff --git a/classnlohmann_1_1basic__json_a5fd8b54389698edf0c08e2dd001f610b.html b/classnlohmann_1_1basic__json_a5fd8b54389698edf0c08e2dd001f610b.html index eb1f21ca9..0eed2ae84 100644 --- a/classnlohmann_1_1basic__json_a5fd8b54389698edf0c08e2dd001f610b.html +++ b/classnlohmann_1_1basic__json_a5fd8b54389698edf0c08e2dd001f610b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html index eee76e43a..9b71db585 100644 --- a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html +++ b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
See also
parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
Since
version 1.0.0
-

Definition at line 5122 of file json.hpp.

+

Definition at line 5202 of file json.hpp.

@@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a63691315292df8e1522b00d37ebb1ffc.html b/classnlohmann_1_1basic__json_a63691315292df8e1522b00d37ebb1ffc.html index ef88454af..dfafdf369 100644 --- a/classnlohmann_1_1basic__json_a63691315292df8e1522b00d37ebb1ffc.html +++ b/classnlohmann_1_1basic__json_a63691315292df8e1522b00d37ebb1ffc.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -280,7 +282,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a652414dd930cb3af3b6f454cc535a23e.html b/classnlohmann_1_1basic__json_a652414dd930cb3af3b6f454cc535a23e.html index f7fe2aea3..332f7bd3e 100644 --- a/classnlohmann_1_1basic__json_a652414dd930cb3af3b6f454cc535a23e.html +++ b/classnlohmann_1_1basic__json_a652414dd930cb3af3b6f454cc535a23e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,7 +269,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Logarithmic in the size of the container.
Example
The example below shows how object elements can be read and written using at.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON object
8  json object =
9  {
10  {"the good", "il buono"},
11  {"the bad", "il cativo"},
12  {"the ugly", "il brutto"}
13  };
14 
15  // output element with key "the ugly"
16  std::cout << object.at("the ugly") << '\n';
17 
18  // change element with key "the bad"
19  object.at("the bad") = "il cattivo";
20 
21  // output changed array
22  std::cout << object << '\n';
23 
24  // try to write at a nonexisting key
25  try
26  {
27  object.at("the fast") = "il rapido";
28  }
29  catch (std::out_of_range& e)
30  {
31  std::cout << "out of range: " << e.what() << '\n';
32  }
33 }
a class to store JSON values
Definition: json.hpp:188
-
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2638
+
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2718
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"il brutto"
 {"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
@@ -278,7 +280,7 @@ out of range: key 'the fast' not found
 value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 2730 of file json.hpp.

+

Definition at line 2810 of file json.hpp.

@@ -288,7 +290,7 @@ out of range: key 'the fast' not found diff --git a/classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html b/classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html index 6b8f622a5..524b9c014 100644 --- a/classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html +++ b/classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<typename PointerType , typename std::enable_if<
Complexity
Constant.
Example
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting pointers
11  auto p1 = value.get_ptr<const json::number_integer_t*>();
12  auto p2 = value.get_ptr<json::number_integer_t*>();
13  auto p3 = value.get_ptr<json::number_integer_t* const>();
14  auto p4 = value.get_ptr<const json::number_integer_t* const>();
15  auto p5 = value.get_ptr<json::number_float_t*>();
16 
17  // print the pointees
18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
20 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.hpp:2545
+
PointerType get_ptr() noexcept
get a pointer value (implicit)
Definition: json.hpp:2574
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
Output (play with this example online):
17 17 17 17
@@ -271,7 +273,7 @@ true
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/get_ptr.cpp -o get_ptr 
Since
version 1.0.0
-

Definition at line 2545 of file json.hpp.

+

Definition at line 2574 of file json.hpp.

@@ -281,7 +283,7 @@ true diff --git a/classnlohmann_1_1basic__json_a66f936cfbd252f85bd3dc2598e37a64b.html b/classnlohmann_1_1basic__json_a66f936cfbd252f85bd3dc2598e37a64b.html index 26d0ea6f6..a2426b2ff 100644 --- a/classnlohmann_1_1basic__json_a66f936cfbd252f85bd3dc2598e37a64b.html +++ b/classnlohmann_1_1basic__json_a66f936cfbd252f85bd3dc2598e37a64b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Amortized constant.
Example
The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json array = {1, 2, 3, 4, 5};
9  json null;
10 
11  // print values
12  std::cout << array << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  array.push_back(6);
17  array += 7;
18  null += "first";
19  null += "second";
20 
21  // print values
22  std::cout << array << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
[1,2,3,4,5]
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back.cpp -o push_back 
Since
version 1.0.0
-

Definition at line 4143 of file json.hpp.

+

Definition at line 4223 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a6944904b3b59769b1cf62ac2532cbe33.html b/classnlohmann_1_1basic__json_a6944904b3b59769b1cf62ac2532cbe33.html index cdc372d56..10d563f5d 100644 --- a/classnlohmann_1_1basic__json_a6944904b3b59769b1cf62ac2532cbe33.html +++ b/classnlohmann_1_1basic__json_a6944904b3b59769b1cf62ac2532cbe33.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -274,7 +276,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a696ced74d8edc0b63a000a72907ab109.html b/classnlohmann_1_1basic__json_a696ced74d8edc0b63a000a72907ab109.html index aeed004c4..139469d9e 100644 --- a/classnlohmann_1_1basic__json_a696ced74d8edc0b63a000a72907ab109.html +++ b/classnlohmann_1_1basic__json_a696ced74d8edc0b63a000a72907ab109.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,7 +280,7 @@ false diff --git a/classnlohmann_1_1basic__json_a6a7f45095675ac6fd1d018a0e41874be.html b/classnlohmann_1_1basic__json_a6a7f45095675ac6fd1d018a0e41874be.html index 223f13b11..5ed2da597 100644 --- a/classnlohmann_1_1basic__json_a6a7f45095675ac6fd1d018a0e41874be.html +++ b/classnlohmann_1_1basic__json_a6a7f45095675ac6fd1d018a0e41874be.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -292,9 +294,9 @@ construct with iterators from null"
Complexity
Linear in distance between first and last.
Example
The example below shows several ways to create JSON values by specifying a subrange with iterators.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
9  json j_number = 42;
10  json j_object = {{"one", "eins"}, {"two", "zwei"}};
11 
12  // create copies using iterators
13  json j_array_range(j_array.begin() + 1, j_array.end() - 2);
14  json j_number_range(j_number.begin(), j_number.end());
15  json j_object_range(j_object.begin(), j_object.find("two"));
16 
17  // serialize the values
18  std::cout << j_array_range << '\n';
19  std::cout << j_number_range << '\n';
20  std::cout << j_object_range << '\n';
21 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
-
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3536
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
+
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3616
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
["bravo","charly"]
 42
@@ -312,7 +314,7 @@ construct with iterators from null"
 
 
 
diff --git a/classnlohmann_1_1basic__json_a6b7428e8c1169497f47b81667001cbfb.html b/classnlohmann_1_1basic__json_a6b7428e8c1169497f47b81667001cbfb.html
index 84a3c527a..29618502e 100644
--- a/classnlohmann_1_1basic__json_a6b7428e8c1169497f47b81667001cbfb.html
+++ b/classnlohmann_1_1basic__json_a6b7428e8c1169497f47b81667001cbfb.html
@@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
           get_allocator
           get_ptr
           get_ptr
+          get_ref
+          get_ref
           insert
           insert
           insert
@@ -285,15 +287,15 @@ template<template< typename U, typename V, typename...Args > class Obje
 
Complexity
Linear in cnt plus linear in the distance between pos and end of the container.
Example
The example shows how insert is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json v = {1, 2, 3, 4};
9 
10  // insert number 7 copies of number 7 before number 3
11  auto new_pos = v.insert(v.begin() + 2, 7, 7);
12 
13  // output new array and result of insert call
14  std::cout << *new_pos << '\n';
15  std::cout << v << '\n';
16 }
a class to store JSON values
Definition: json.hpp:188
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
namespace for Niels Lohmann
Definition: json.hpp:79
-
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4281
+
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4361
Output (play with this example online):
7
 [1,2,7,7,7,7,7,7,7,3,4]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/insert__count.cpp -o insert__count 
Since
version 1.0.0
-

Definition at line 4337 of file json.hpp.

+

Definition at line 4417 of file json.hpp.

@@ -303,7 +305,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a6bbd3e72a870f1ba81ff6886b063b0fe.html b/classnlohmann_1_1basic__json_a6bbd3e72a870f1ba81ff6886b063b0fe.html index 47d84d85c..5f71e44a7 100644 --- a/classnlohmann_1_1basic__json_a6bbd3e72a870f1ba81ff6886b063b0fe.html +++ b/classnlohmann_1_1basic__json_a6bbd3e72a870f1ba81ff6886b063b0fe.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a6dff6a02a2be250b8f8dc2f47be65544.html b/classnlohmann_1_1basic__json_a6dff6a02a2be250b8f8dc2f47be65544.html index f37d6a889..1dcdf4112 100644 --- a/classnlohmann_1_1basic__json_a6dff6a02a2be250b8f8dc2f47be65544.html +++ b/classnlohmann_1_1basic__json_a6dff6a02a2be250b8f8dc2f47be65544.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,7 +270,7 @@ range"
Complexity
Linear in distance between idx and the end of the container.
Example
The example shows the effect of erase.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json j_array = {0, 1, 2, 3, 4, 5};
9 
10  // call erase
11  j_array.erase(2);
12 
13  // print values
14  std::cout << j_array << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3274
+
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3354
Output (play with this example online):
[0,1,3,4,5]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/erase__size_type.cpp -o erase__size_type 
See also
erase(InteratorType) – removes the element at a given position
@@ -278,7 +280,7 @@ range" erase(const typename object_t::key_type&) – removes the element from an object at the given key
Since
version 1.0.0
-

Definition at line 3500 of file json.hpp.

+

Definition at line 3580 of file json.hpp.

@@ -288,7 +290,7 @@ range" diff --git a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html index 71df57a3d..bf225d6e7 100644 --- a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html +++ b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__notequal.cpp -o operator__notequal 
Since
version 1.0.0
-

Definition at line 4775 of file json.hpp.

+

Definition at line 4855 of file json.hpp.

@@ -289,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a71eba33d906745e66f340952b79fbce3.html b/classnlohmann_1_1basic__json_a71eba33d906745e66f340952b79fbce3.html index 924c9c66a..05b7568f8 100644 --- a/classnlohmann_1_1basic__json_a71eba33d906745e66f340952b79fbce3.html +++ b/classnlohmann_1_1basic__json_a71eba33d906745e66f340952b79fbce3.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a72442ccbb378b4464a24a2da1e784041.html b/classnlohmann_1_1basic__json_a72442ccbb378b4464a24a2da1e784041.html index 9765141ab..465519151 100644 --- a/classnlohmann_1_1basic__json_a72442ccbb378b4464a24a2da1e784041.html +++ b/classnlohmann_1_1basic__json_a72442ccbb378b4464a24a2da1e784041.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -287,7 +289,7 @@ value() with null"
Complexity
Logarithmic in the size of the container.
Example
The example below shows how object elements can be queried with a default value.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object with different entry types
8  json j =
9  {
10  {"integer", 1},
11  {"floating", 42.23},
12  {"string", "hello world"},
13  {"boolean", true},
14  {"object", {{"key1", 1}, {"key2", 2}}},
15  {"array", {1, 2, 3}}
16  };
17 
18  // access existing values
19  int v_integer = j.value("integer", 0);
20  double v_floating = j.value("floating", 47.11);
21 
22  // access nonexisting values and rely on default value
23  std::string v_string = j.value("nonexisting", "oops");
24  bool v_boolean = j.value("nonexisting", false);
25 
26  // output values
27  std::cout << std::boolalpha << v_integer << " " << v_floating
28  << " " << v_string << " " << v_boolean << "\n";
29 }
a class to store JSON values
Definition: json.hpp:188
-
ValueType value(const typename object_t::key_type &key, ValueType default_value) const
access specified object element with default value
Definition: json.hpp:3122
+
ValueType value(const typename object_t::key_type &key, ValueType default_value) const
access specified object element with default value
Definition: json.hpp:3202
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
1 42.23 oops false
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/basic_json__value.cpp -o basic_json__value 
@@ -296,7 +298,7 @@ value() with null" operator[](const typename object_t::key_type&) for unchecked access by reference
Since
version 1.0.0
-

Definition at line 3148 of file json.hpp.

+

Definition at line 3228 of file json.hpp.

@@ -306,7 +308,7 @@ value() with null" diff --git a/classnlohmann_1_1basic__json_a72ba20783ecb3eec98bd6a3b870d565c.html b/classnlohmann_1_1basic__json_a72ba20783ecb3eec98bd6a3b870d565c.html index cfc1f032e..9b54a8857 100644 --- a/classnlohmann_1_1basic__json_a72ba20783ecb3eec98bd6a3b870d565c.html +++ b/classnlohmann_1_1basic__json_a72ba20783ecb3eec98bd6a3b870d565c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,14 +264,14 @@ Illustration from cppreference.com
Example
The following code shows an example for cend.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to one past the last element
11  json::const_iterator it = array.cend();
12 
13  // decrement the iterator to point to the last element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
-
const_iterator cend() const
returns a const iterator to one past the last element
Definition: json.hpp:3712
+
const_iterator cend() const
returns a const iterator to one past the last element
Definition: json.hpp:3792
namespace for Niels Lohmann
Definition: json.hpp:79
-
a const random access iterator for the basic_json class
Definition: json.hpp:5686
+
a const random access iterator for the basic_json class
Definition: json.hpp:5766
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
Since
version 1.0.0
-

Definition at line 3712 of file json.hpp.

+

Definition at line 3792 of file json.hpp.

@@ -279,7 +281,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a74472977b798c7b7989e6e7cb960ecff.html b/classnlohmann_1_1basic__json_a74472977b798c7b7989e6e7cb960ecff.html index d619e82ca..9f2d9e72a 100644 --- a/classnlohmann_1_1basic__json_a74472977b798c7b7989e6e7cb960ecff.html +++ b/classnlohmann_1_1basic__json_a74472977b798c7b7989e6e7cb960ecff.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ null diff --git a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html index 2556e1136..dcb835b21 100644 --- a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html +++ b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__greaterequal.cpp -o operator__greaterequal 
Since
version 1.0.0
-

Definition at line 4963 of file json.hpp.

+

Definition at line 5043 of file json.hpp.

@@ -289,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a74ccfa471a0c061876b247f820f3c741.html b/classnlohmann_1_1basic__json_a74ccfa471a0c061876b247f820f3c741.html index c42ccf93e..ebd505a12 100644 --- a/classnlohmann_1_1basic__json_a74ccfa471a0c061876b247f820f3c741.html +++ b/classnlohmann_1_1basic__json_a74ccfa471a0c061876b247f820f3c741.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -270,13 +272,13 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
result of the deserialization
Complexity
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
Note
A UTF-8 byte order mark is silently ignored.
-
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  auto text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // fill a stream with JSON text
26  std::stringstream ss;
27  ss << text;
28 
29  // parse and serialize JSON
30  json j_complete = json::parse(ss);
31  std::cout << std::setw(4) << j_complete << "\n\n";
32 
33 
34  // define parser callback
35  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
36  {
37  // skip object elements with key "Thumbnail"
38  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
39  {
40  return false;
41  }
42  else
43  {
44  return true;
45  }
46  };
47 
48  // fill a stream with JSON text
49  ss.clear();
50  ss << text;
51 
52  // parse (with callback) and serialize JSON
53  json j_filtered = json::parse(ss, cb);
54  std::cout << std::setw(4) << j_filtered << '\n';
55 }
basic_json<> json
default JSON class
Definition: json.hpp:7968
+
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  auto text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // fill a stream with JSON text
26  std::stringstream ss;
27  ss << text;
28 
29  // parse and serialize JSON
30  json j_complete = json::parse(ss);
31  std::cout << std::setw(4) << j_complete << "\n\n";
32 
33 
34  // define parser callback
35  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
36  {
37  // skip object elements with key "Thumbnail"
38  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
39  {
40  return false;
41  }
42  else
43  {
44  return true;
45  }
46  };
47 
48  // fill a stream with JSON text
49  ss.clear();
50  ss << text;
51 
52  // parse (with callback) and serialize JSON
53  json j_filtered = json::parse(ss, cb);
54  std::cout << std::setw(4) << j_filtered << '\n';
55 }
basic_json<> json
default JSON class
Definition: json.hpp:8048
a class to store JSON values
Definition: json.hpp:188
std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
per-element parser callback type
Definition: json.hpp:820
namespace for Niels Lohmann
Definition: json.hpp:79
-
void clear() noexcept
clears the contents
Definition: json.hpp:4073
+
void clear() noexcept
clears the contents
Definition: json.hpp:4153
the parser read a key of a value in an object
-
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5057
+
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5137
parse_event_t
JSON callback events.
Definition: json.hpp:755
Output (play with this example online):
{
     "Image": {
@@ -316,7 +318,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
See also
parse(const string_t&, parser_callback_t) for a version that reads from a string
Since
version 1.0.0
-

Definition at line 5086 of file json.hpp.

+

Definition at line 5166 of file json.hpp.

@@ -326,7 +328,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a75a1754e0d39f33095d3102a8bdb9881.html b/classnlohmann_1_1basic__json_a75a1754e0d39f33095d3102a8bdb9881.html index 3a0e287dd..dcf55b4ec 100644 --- a/classnlohmann_1_1basic__json_a75a1754e0d39f33095d3102a8bdb9881.html +++ b/classnlohmann_1_1basic__json_a75a1754e0d39f33095d3102a8bdb9881.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -285,10 +287,10 @@ of range"
Example
The example shows the result of erase for different JSON types.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_boolean = true;
9  json j_number_integer = 17;
10  json j_number_float = 23.42;
11  json j_object = {{"one", 1}, {"two", 2}};
12  json j_array = {1, 2, 4, 8, 16};
13  json j_string = "Hello, world";
14 
15  // call erase
16  j_boolean.erase(j_boolean.begin());
17  j_number_integer.erase(j_number_integer.begin());
18  j_number_float.erase(j_number_float.begin());
19  j_object.erase(j_object.find("two"));
20  j_array.erase(j_array.begin() + 2);
21  j_string.erase(j_string.begin());
22 
23  // print values
24  std::cout << j_boolean << '\n';
25  std::cout << j_number_integer << '\n';
26  std::cout << j_number_float << '\n';
27  std::cout << j_object << '\n';
28  std::cout << j_array << '\n';
29  std::cout << j_string << '\n';
30 }
a class to store JSON values
Definition: json.hpp:188
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
-
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3536
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
+
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3616
namespace for Niels Lohmann
Definition: json.hpp:79
-
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3274
+
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3354
Output (play with this example online):
null
 null
 null
@@ -303,7 +305,7 @@ null
 erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0
-

Definition at line 3274 of file json.hpp.

+

Definition at line 3354 of file json.hpp.

@@ -313,7 +315,7 @@ null diff --git a/classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html b/classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html index e59077e31..858e9b937 100644 --- a/classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html +++ b/classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<typename PointerType , typename std::enable_if<
Complexity
Constant.
Example
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting pointers
11  auto p1 = value.get<const json::number_integer_t*>();
12  auto p2 = value.get<json::number_integer_t*>();
13  auto p3 = value.get<json::number_integer_t* const>();
14  auto p4 = value.get<const json::number_integer_t* const>();
15  auto p5 = value.get<json::number_float_t*>();
16 
17  // print the pointees
18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
20 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
ValueType get() const
get a value (explicit)
Definition: json.hpp:2461
+
ValueType get() const
get a value (explicit)
Definition: json.hpp:2490
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
Output (play with this example online):
17 17 17 17
@@ -272,7 +274,7 @@ true
 
See also
get_ptr() for explicit pointer-member access
Since
version 1.0.0
-

Definition at line 2510 of file json.hpp.

+

Definition at line 2539 of file json.hpp.

@@ -282,7 +284,7 @@ true diff --git a/classnlohmann_1_1basic__json_a7c08f966200af98db0313a3b517ce0a9.html b/classnlohmann_1_1basic__json_a7c08f966200af98db0313a3b517ce0a9.html index ac9f46a64..d1123fcb3 100644 --- a/classnlohmann_1_1basic__json_a7c08f966200af98db0313a3b517ce0a9.html +++ b/classnlohmann_1_1basic__json_a7c08f966200af98db0313a3b517ce0a9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -261,14 +263,14 @@ Illustration from cppreference.com
Example
The following code shows an example for rend.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-end
11  json::reverse_iterator it = array.rend();
12 
13  // increment the iterator to point to the first element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
-
reverse_iterator rend()
returns an iterator to the reverse-end
Definition: json.hpp:3767
+
reverse_iterator rend()
returns an iterator to the reverse-end
Definition: json.hpp:3847
namespace for Niels Lohmann
Definition: json.hpp:79
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/rend.cpp -o rend 
Since
version 1.0.0
-

Definition at line 3767 of file json.hpp.

+

Definition at line 3847 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a7c19a5c3be6cc755377ee41eade78baf.html b/classnlohmann_1_1basic__json_a7c19a5c3be6cc755377ee41eade78baf.html index de655f8f7..df29fcb00 100644 --- a/classnlohmann_1_1basic__json_a7c19a5c3be6cc755377ee41eade78baf.html +++ b/classnlohmann_1_1basic__json_a7c19a5c3be6cc755377ee41eade78baf.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -260,8 +262,8 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
Iterator to an element with key equivalent to key. If no such element is found, past-the-end (see end()) iterator is returned.
Complexity
Logarithmic in the size of the JSON object.
Example
The example shows how find is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object
8  json j_object = {{"one", 1}, {"two", 2}};
9 
10  // call find
11  auto it_two = j_object.find("two");
12  auto it_three = j_object.find("three");
13 
14  // print values
15  std::cout << std::boolalpha;
16  std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n';
17  std::cout << "value at key \"two\": " << *it_two << '\n';
18  std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n';
19 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
-
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3536
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
+
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3616
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"two" was found: true
 value at key "two": 2
@@ -269,7 +271,7 @@ value at key "two": 2
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/find__key_type.cpp -o find__key_type 
Since
version 1.0.0
-

Definition at line 3553 of file json.hpp.

+

Definition at line 3633 of file json.hpp.

@@ -279,7 +281,7 @@ value at key "two": 2 diff --git a/classnlohmann_1_1basic__json_a7d0db3b728d820d4984df78d97d2b104.html b/classnlohmann_1_1basic__json_a7d0db3b728d820d4984df78d97d2b104.html index 2a0ae0059..564746b6d 100644 --- a/classnlohmann_1_1basic__json_a7d0db3b728d820d4984df78d97d2b104.html +++ b/classnlohmann_1_1basic__json_a7d0db3b728d820d4984df78d97d2b104.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7d1b990f2c12fecb57db1504fdadd0bb.html b/classnlohmann_1_1basic__json_a7d1b990f2c12fecb57db1504fdadd0bb.html index 2cf66d3a9..a49c228e6 100644 --- a/classnlohmann_1_1basic__json_a7d1b990f2c12fecb57db1504fdadd0bb.html +++ b/classnlohmann_1_1basic__json_a7d1b990f2c12fecb57db1504fdadd0bb.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,7 +269,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
log(size()) + count(key)
Example
The example shows the effect of erase.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object
8  json j_object = {{"one", 1}, {"two", 2}};
9 
10  // call erase
11  auto count_one = j_object.erase("one");
12  auto count_three = j_object.erase("three");
13 
14  // print values
15  std::cout << j_object << '\n';
16  std::cout << count_one << " " << count_three << '\n';
17 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3274
+
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3354
Output (play with this example online):
{"two":2}
 1 0
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/erase__key_type.cpp -o erase__key_type 
@@ -278,7 +280,7 @@ template<template< typename U, typename V, typename...Args > class Obje erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0
-

Definition at line 3462 of file json.hpp.

+

Definition at line 3542 of file json.hpp.

@@ -288,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7dab69b10b98e7bc694339720e37fb2b.html b/classnlohmann_1_1basic__json_a7dab69b10b98e7bc694339720e37fb2b.html index 4388eb890..1f4a32537 100644 --- a/classnlohmann_1_1basic__json_a7dab69b10b98e7bc694339720e37fb2b.html +++ b/classnlohmann_1_1basic__json_a7dab69b10b98e7bc694339720e37fb2b.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -260,8 +262,8 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
Iterator to an element with key equivalent to key. If no such element is found, past-the-end (see end()) iterator is returned.
Complexity
Logarithmic in the size of the JSON object.
Example
The example shows how find is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON object
8  json j_object = {{"one", 1}, {"two", 2}};
9 
10  // call find
11  auto it_two = j_object.find("two");
12  auto it_three = j_object.find("three");
13 
14  // print values
15  std::cout << std::boolalpha;
16  std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n';
17  std::cout << "value at key \"two\": " << *it_two << '\n';
18  std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n';
19 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
-
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3536
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
+
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3616
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"two" was found: true
 value at key "two": 2
@@ -269,7 +271,7 @@ value at key "two": 2
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/find__key_type.cpp -o find__key_type 
Since
version 1.0.0
-

Definition at line 3536 of file json.hpp.

+

Definition at line 3616 of file json.hpp.

@@ -279,7 +281,7 @@ value at key "two": 2 diff --git a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html index f6ed6db31..e433afb0b 100644 --- a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html +++ b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje null != nullptr false

The example code above can be translated with

g++ -std=c++11 -Isrc doc/examples/operator__notequal__nullptr_t.cpp -o operator__notequal__nullptr_t 
Since
version 1.0.0
-

Definition at line 4807 of file json.hpp.

+

Definition at line 4887 of file json.hpp.

@@ -289,7 +291,7 @@ null != nullptr false diff --git a/classnlohmann_1_1basic__json_a80ceaa3bdd346292273b309e08525c1c.html b/classnlohmann_1_1basic__json_a80ceaa3bdd346292273b309e08525c1c.html index 092078a92..019939701 100644 --- a/classnlohmann_1_1basic__json_a80ceaa3bdd346292273b309e08525c1c.html +++ b/classnlohmann_1_1basic__json_a80ceaa3bdd346292273b309e08525c1c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a83cbbfbf5d3ecbad6de8ece0be6b36c4.html b/classnlohmann_1_1basic__json_a83cbbfbf5d3ecbad6de8ece0be6b36c4.html index 5694f6ba9..b63b28170 100644 --- a/classnlohmann_1_1basic__json_a83cbbfbf5d3ecbad6de8ece0be6b36c4.html +++ b/classnlohmann_1_1basic__json_a83cbbfbf5d3ecbad6de8ece0be6b36c4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -259,7 +261,7 @@ template<template< typename U, typename V, typename...Args > class Obje -
Example
The following code shows an example for front.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_object_empty(json::value_t::object);
14  json j_array = {1, 2, 4, 8, 16};
15  json j_array_empty(json::value_t::array);
16  json j_string = "Hello, world";
17 
18  // call front()
19  //std::cout << j_null.front() << '\n'; // would throw
20  std::cout << j_boolean.front() << '\n';
21  std::cout << j_number_integer.front() << '\n';
22  std::cout << j_number_float.front() << '\n';
23  std::cout << j_object.front() << '\n';
24  //std::cout << j_object_empty.front() << '\n'; // would throw
25  std::cout << j_array.front() << '\n';
26  //std::cout << j_array_empty.front() << '\n'; // would throw
27  std::cout << j_string.front() << '\n';
28 }
reference front()
access the first element
Definition: json.hpp:3173
+
Example
The following code shows an example for front.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_object_empty(json::value_t::object);
14  json j_array = {1, 2, 4, 8, 16};
15  json j_array_empty(json::value_t::array);
16  json j_string = "Hello, world";
17 
18  // call front()
19  //std::cout << j_null.front() << '\n'; // would throw
20  std::cout << j_boolean.front() << '\n';
21  std::cout << j_number_integer.front() << '\n';
22  std::cout << j_number_float.front() << '\n';
23  std::cout << j_object.front() << '\n';
24  //std::cout << j_object_empty.front() << '\n'; // would throw
25  std::cout << j_array.front() << '\n';
26  //std::cout << j_array_empty.front() << '\n'; // would throw
27  std::cout << j_string.front() << '\n';
28 }
reference front()
access the first element
Definition: json.hpp:3253
a class to store JSON values
Definition: json.hpp:188
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
@@ -273,7 +275,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/front.cpp -o front 
Since
version 1.0.0
-

Definition at line 3173 of file json.hpp.

+

Definition at line 3253 of file json.hpp.

@@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html index b0f8e5297..866ee00fd 100644 --- a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html +++ b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__lessequal.cpp -o operator__lessequal 
Since
version 1.0.0
-

Definition at line 4941 of file json.hpp.

+

Definition at line 5021 of file json.hpp.

@@ -289,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a8b526709d395142b68d21abfbfff17c3.html b/classnlohmann_1_1basic__json_a8b526709d395142b68d21abfbfff17c3.html index 1e8309d3b..894dcb9c5 100644 --- a/classnlohmann_1_1basic__json_a8b526709d395142b68d21abfbfff17c3.html +++ b/classnlohmann_1_1basic__json_a8b526709d395142b68d21abfbfff17c3.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -259,7 +261,7 @@ template<template< typename U, typename V, typename...Args > class Obje -
Example
The following code shows an example for front.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_object_empty(json::value_t::object);
14  json j_array = {1, 2, 4, 8, 16};
15  json j_array_empty(json::value_t::array);
16  json j_string = "Hello, world";
17 
18  // call front()
19  //std::cout << j_null.front() << '\n'; // would throw
20  std::cout << j_boolean.front() << '\n';
21  std::cout << j_number_integer.front() << '\n';
22  std::cout << j_number_float.front() << '\n';
23  std::cout << j_object.front() << '\n';
24  //std::cout << j_object_empty.front() << '\n'; // would throw
25  std::cout << j_array.front() << '\n';
26  //std::cout << j_array_empty.front() << '\n'; // would throw
27  std::cout << j_string.front() << '\n';
28 }
reference front()
access the first element
Definition: json.hpp:3173
+
Example
The following code shows an example for front.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_object_empty(json::value_t::object);
14  json j_array = {1, 2, 4, 8, 16};
15  json j_array_empty(json::value_t::array);
16  json j_string = "Hello, world";
17 
18  // call front()
19  //std::cout << j_null.front() << '\n'; // would throw
20  std::cout << j_boolean.front() << '\n';
21  std::cout << j_number_integer.front() << '\n';
22  std::cout << j_number_float.front() << '\n';
23  std::cout << j_object.front() << '\n';
24  //std::cout << j_object_empty.front() << '\n'; // would throw
25  std::cout << j_array.front() << '\n';
26  //std::cout << j_array_empty.front() << '\n'; // would throw
27  std::cout << j_string.front() << '\n';
28 }
reference front()
access the first element
Definition: json.hpp:3253
a class to store JSON values
Definition: json.hpp:188
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
@@ -273,7 +275,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/front.cpp -o front 
Since
version 1.0.0
-

Definition at line 3181 of file json.hpp.

+

Definition at line 3261 of file json.hpp.

@@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a8c40cd9ead4de7c82f28268bdf0ec98a.html b/classnlohmann_1_1basic__json_a8c40cd9ead4de7c82f28268bdf0ec98a.html index 631eb112f..19af3a73f 100644 --- a/classnlohmann_1_1basic__json_a8c40cd9ead4de7c82f28268bdf0ec98a.html +++ b/classnlohmann_1_1basic__json_a8c40cd9ead4de7c82f28268bdf0ec98a.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Linear in the size of the JSON value.
Example
The example below shows the effect of clear to different JSON types.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_array = {1, 2, 4, 8, 16};
14  json j_string = "Hello, world";
15 
16  // call clear()
17  j_null.clear();
18  j_boolean.clear();
19  j_number_integer.clear();
20  j_number_float.clear();
21  j_object.clear();
22  j_array.clear();
23  j_string.clear();
24 
25  // serialize the cleared values()
26  std::cout << j_null << '\n';
27  std::cout << j_boolean << '\n';
28  std::cout << j_number_integer << '\n';
29  std::cout << j_number_float << '\n';
30  std::cout << j_object << '\n';
31  std::cout << j_array << '\n';
32  std::cout << j_string << '\n';
33 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
void clear() noexcept
clears the contents
Definition: json.hpp:4073
+
void clear() noexcept
clears the contents
Definition: json.hpp:4153
Output (play with this example online):
null
 false
 0
@@ -281,7 +283,7 @@ false
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/clear.cpp -o clear 
Since
version 1.0.0
-

Definition at line 4073 of file json.hpp.

+

Definition at line 4153 of file json.hpp.

@@ -291,7 +293,7 @@ false diff --git a/classnlohmann_1_1basic__json_a8e34088252a3ee6b2377f3a1f26dd1ba.html b/classnlohmann_1_1basic__json_a8e34088252a3ee6b2377f3a1f26dd1ba.html index b4a5a03d1..f88a02142 100644 --- a/classnlohmann_1_1basic__json_a8e34088252a3ee6b2377f3a1f26dd1ba.html +++ b/classnlohmann_1_1basic__json_a8e34088252a3ee6b2377f3a1f26dd1ba.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -276,7 +278,7 @@ operator[] with null" value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 2959 of file json.hpp.

+

Definition at line 3039 of file json.hpp.

@@ -286,7 +288,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_a8e4e11999b4e7faa8f31f21164ebd65a.html b/classnlohmann_1_1basic__json_a8e4e11999b4e7faa8f31f21164ebd65a.html index 190f1d967..eb4476b4f 100644 --- a/classnlohmann_1_1basic__json_a8e4e11999b4e7faa8f31f21164ebd65a.html +++ b/classnlohmann_1_1basic__json_a8e4e11999b4e7faa8f31f21164ebd65a.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -253,7 +255,7 @@ template<template< typename U, typename V, typename...Args > class Obje

This function allows to access iterator::key() and iterator::value() during range-based for loops. In these loops, a reference to the JSON values is returned, so there is no access to the underlying iterator.

Note
The name of this function is not yet final and may change in the future.
-

Definition at line 3850 of file json.hpp.

+

Definition at line 3930 of file json.hpp.

@@ -263,7 +265,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a8fa74698f4061e18ec664009f3af1ddf.html b/classnlohmann_1_1basic__json_a8fa74698f4061e18ec664009f3af1ddf.html index 52f8a0dff..aa09f1332 100644 --- a/classnlohmann_1_1basic__json_a8fa74698f4061e18ec664009f3af1ddf.html +++ b/classnlohmann_1_1basic__json_a8fa74698f4061e18ec664009f3af1ddf.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -288,16 +290,16 @@ belong to container"
Returns
iterator pointing to the first element inserted, or pos if first==last
Complexity
Linear in std::distance(first, last) plus linear in the distance between pos and end of the container.
Example
The example shows how insert is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json v = {1, 2, 3, 4};
9 
10  // create a JSON array to copy values from
11  json v2 = {"one", "two", "three", "four"};
12 
13  // insert range from v2 before the end of array v
14  auto new_pos = v.insert(v.end(), v2.begin(), v2.end());
15 
16  // output new array and result of insert call
17  std::cout << *new_pos << '\n';
18  std::cout << v << '\n';
19 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
namespace for Niels Lohmann
Definition: json.hpp:79
-
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4281
+
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4361
Output (play with this example online):
"one"
 [1,2,3,4,"one","two","three","four"]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/insert__range.cpp -o insert__range 
Since
version 1.0.0
-

Definition at line 4390 of file json.hpp.

+

Definition at line 4470 of file json.hpp.

@@ -307,7 +309,7 @@ belong to container" diff --git a/classnlohmann_1_1basic__json_a930e14150ffa067bcf56d35cb00271e1.html b/classnlohmann_1_1basic__json_a930e14150ffa067bcf56d35cb00271e1.html index 724c1a8e8..35e4b0a29 100644 --- a/classnlohmann_1_1basic__json_a930e14150ffa067bcf56d35cb00271e1.html +++ b/classnlohmann_1_1basic__json_a930e14150ffa067bcf56d35cb00271e1.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -269,7 +271,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a960962c683909619d1d2fbbe856c022e.html b/classnlohmann_1_1basic__json_a960962c683909619d1d2fbbe856c022e.html index 81a0600e7..0f9b5570b 100644 --- a/classnlohmann_1_1basic__json_a960962c683909619d1d2fbbe856c022e.html +++ b/classnlohmann_1_1basic__json_a960962c683909619d1d2fbbe856c022e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -265,7 +267,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Amortized constant.
Example
The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json array = {1, 2, 3, 4, 5};
9  json null;
10 
11  // print values
12  std::cout << array << '\n';
13  std::cout << null << '\n';
14 
15  // add values
16  array.push_back(6);
17  array += 7;
18  null += "first";
19  null += "second";
20 
21  // print values
22  std::cout << array << '\n';
23  std::cout << null << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
-
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4143
+
void push_back(basic_json &&val)
add an object to an array
Definition: json.hpp:4223
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
[1,2,3,4,5]
 null
@@ -274,7 +276,7 @@ null
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/push_back.cpp -o push_back 
Since
version 1.0.0
-

Definition at line 4203 of file json.hpp.

+

Definition at line 4283 of file json.hpp.

@@ -284,7 +286,7 @@ null diff --git a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html index c0ab66abd..20f9cdf95 100644 --- a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html +++ b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje null == nullptr true

The example code above can be translated with

g++ -std=c++11 -Isrc doc/examples/operator__equal__nullptr_t.cpp -o operator__equal__nullptr_t 
Since
version 1.0.0
-

Definition at line 4745 of file json.hpp.

+

Definition at line 4825 of file json.hpp.

@@ -289,7 +291,7 @@ null == nullptr true diff --git a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html index 703aaf7cf..09f35fa41 100644 --- a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html +++ b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje null == nullptr true

The example code above can be translated with

g++ -std=c++11 -Isrc doc/examples/operator__equal__nullptr_t.cpp -o operator__equal__nullptr_t 
Since
version 1.0.0
-

Definition at line 4754 of file json.hpp.

+

Definition at line 4834 of file json.hpp.

@@ -289,7 +291,7 @@ null == nullptr true diff --git a/classnlohmann_1_1basic__json_a9993148cb0473365e52998c7315f9ada.html b/classnlohmann_1_1basic__json_a9993148cb0473365e52998c7315f9ada.html index ce718e045..5fe31def9 100644 --- a/classnlohmann_1_1basic__json_a9993148cb0473365e52998c7315f9ada.html +++ b/classnlohmann_1_1basic__json_a9993148cb0473365e52998c7315f9ada.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,7 +280,7 @@ false diff --git a/classnlohmann_1_1basic__json_a9a73d1b71c9e913aa2888d8b40c72ee9.html b/classnlohmann_1_1basic__json_a9a73d1b71c9e913aa2888d8b40c72ee9.html index 8e9bdb0bc..4b9ba1ccd 100644 --- a/classnlohmann_1_1basic__json_a9a73d1b71c9e913aa2888d8b40c72ee9.html +++ b/classnlohmann_1_1basic__json_a9a73d1b71c9e913aa2888d8b40c72ee9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -269,7 +271,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Linear in cnt.
-
Example
The following code shows examples for the basic_json(size_type, const basic_json&) constructor.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array by creating copies of a JSON value
8  json value = "Hello";
9  json array_0 = json(0, value);
10  json array_1 = json(1, value);
11  json array_5 = json(5, value);
12 
13  // serialize the JSON arrays
14  std::cout << array_0 << '\n';
15  std::cout << array_1 << '\n';
16  std::cout << array_5 << '\n';
17 }
basic_json<> json
default JSON class
Definition: json.hpp:7968
+
Example
The following code shows examples for the basic_json(size_type, const basic_json&) constructor.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array by creating copies of a JSON value
8  json value = "Hello";
9  json array_0 = json(0, value);
10  json array_1 = json(1, value);
11  json array_5 = json(5, value);
12 
13  // serialize the JSON arrays
14  std::cout << array_0 << '\n';
15  std::cout << array_1 << '\n';
16  std::cout << array_5 << '\n';
17 }
basic_json<> json
default JSON class
Definition: json.hpp:8048
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
[]
@@ -288,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
diff --git a/classnlohmann_1_1basic__json_a9c26c5d0f4a519c7236149b9aeb3ef9e.html b/classnlohmann_1_1basic__json_a9c26c5d0f4a519c7236149b9aeb3ef9e.html index 01e2fcc8d..33083a696 100644 --- a/classnlohmann_1_1basic__json_a9c26c5d0f4a519c7236149b9aeb3ef9e.html +++ b/classnlohmann_1_1basic__json_a9c26c5d0f4a519c7236149b9aeb3ef9e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,7 +280,7 @@ false diff --git a/classnlohmann_1_1basic__json_a9daafb4c15ed5a008cb825bbd8c29d87.html b/classnlohmann_1_1basic__json_a9daafb4c15ed5a008cb825bbd8c29d87.html index 7fe1eb1cf..d66951f4f 100644 --- a/classnlohmann_1_1basic__json_a9daafb4c15ed5a008cb825bbd8c29d87.html +++ b/classnlohmann_1_1basic__json_a9daafb4c15ed5a008cb825bbd8c29d87.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ operator[] with null" value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 3055 of file json.hpp.

+

Definition at line 3135 of file json.hpp.

@@ -289,7 +291,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_a9f17a0690155e3a5603246ccec81499e.html b/classnlohmann_1_1basic__json_a9f17a0690155e3a5603246ccec81499e.html index dbf336f74..9759c570a 100644 --- a/classnlohmann_1_1basic__json_a9f17a0690155e3a5603246ccec81499e.html +++ b/classnlohmann_1_1basic__json_a9f17a0690155e3a5603246ccec81499e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ true diff --git a/classnlohmann_1_1basic__json_aa0422e861b4cbd7cdcaad7a11a1304a9.html b/classnlohmann_1_1basic__json_aa0422e861b4cbd7cdcaad7a11a1304a9.html index a3f06c1e1..bc5c27a4f 100644 --- a/classnlohmann_1_1basic__json_aa0422e861b4cbd7cdcaad7a11a1304a9.html +++ b/classnlohmann_1_1basic__json_aa0422e861b4cbd7cdcaad7a11a1304a9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -270,13 +272,13 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
result of the deserialization
Complexity
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
Note
A UTF-8 byte order mark is silently ignored.
-
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  auto text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // fill a stream with JSON text
26  std::stringstream ss;
27  ss << text;
28 
29  // parse and serialize JSON
30  json j_complete = json::parse(ss);
31  std::cout << std::setw(4) << j_complete << "\n\n";
32 
33 
34  // define parser callback
35  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
36  {
37  // skip object elements with key "Thumbnail"
38  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
39  {
40  return false;
41  }
42  else
43  {
44  return true;
45  }
46  };
47 
48  // fill a stream with JSON text
49  ss.clear();
50  ss << text;
51 
52  // parse (with callback) and serialize JSON
53  json j_filtered = json::parse(ss, cb);
54  std::cout << std::setw(4) << j_filtered << '\n';
55 }
basic_json<> json
default JSON class
Definition: json.hpp:7968
+
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  auto text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // fill a stream with JSON text
26  std::stringstream ss;
27  ss << text;
28 
29  // parse and serialize JSON
30  json j_complete = json::parse(ss);
31  std::cout << std::setw(4) << j_complete << "\n\n";
32 
33 
34  // define parser callback
35  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
36  {
37  // skip object elements with key "Thumbnail"
38  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
39  {
40  return false;
41  }
42  else
43  {
44  return true;
45  }
46  };
47 
48  // fill a stream with JSON text
49  ss.clear();
50  ss << text;
51 
52  // parse (with callback) and serialize JSON
53  json j_filtered = json::parse(ss, cb);
54  std::cout << std::setw(4) << j_filtered << '\n';
55 }
basic_json<> json
default JSON class
Definition: json.hpp:8048
a class to store JSON values
Definition: json.hpp:188
std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
per-element parser callback type
Definition: json.hpp:820
namespace for Niels Lohmann
Definition: json.hpp:79
-
void clear() noexcept
clears the contents
Definition: json.hpp:4073
+
void clear() noexcept
clears the contents
Definition: json.hpp:4153
the parser read a key of a value in an object
-
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5057
+
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5137
parse_event_t
JSON callback events.
Definition: json.hpp:755
Output (play with this example online):
{
     "Image": {
@@ -316,7 +318,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
See also
parse(const string_t&, parser_callback_t) for a version that reads from a string
Since
version 1.0.0
-

Definition at line 5094 of file json.hpp.

+

Definition at line 5174 of file json.hpp.

@@ -326,7 +328,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa1f3b3f1dca79392d6727b81f9668c6c.html b/classnlohmann_1_1basic__json_aa1f3b3f1dca79392d6727b81f9668c6c.html index 15c61ed91..e43ddbc95 100644 --- a/classnlohmann_1_1basic__json_aa1f3b3f1dca79392d6727b81f9668c6c.html +++ b/classnlohmann_1_1basic__json_aa1f3b3f1dca79392d6727b81f9668c6c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<template< typename U, typename V, typename...Args > class Obje
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
array (ordered collection of values)
-
reference back()
access the last element
Definition: json.hpp:3207
+
reference back()
access the last element
Definition: json.hpp:3287
Output (play with this example online):
true
 17
 23.42
@@ -273,7 +275,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/back.cpp -o back 
Since
version 1.0.0
-

Definition at line 3207 of file json.hpp.

+

Definition at line 3287 of file json.hpp.

@@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa5413178b8041f7ac685dec4b040dd2c.html b/classnlohmann_1_1basic__json_aa5413178b8041f7ac685dec4b040dd2c.html index a02910e97..77f55690d 100644 --- a/classnlohmann_1_1basic__json_aa5413178b8041f7ac685dec4b040dd2c.html +++ b/classnlohmann_1_1basic__json_aa5413178b8041f7ac685dec4b040dd2c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,14 +264,14 @@ Illustration from cppreference.com
Example
The following code shows an example for cend.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to one past the last element
11  json::const_iterator it = array.cend();
12 
13  // decrement the iterator to point to the last element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
-
const_iterator cend() const
returns a const iterator to one past the last element
Definition: json.hpp:3712
+
const_iterator cend() const
returns a const iterator to one past the last element
Definition: json.hpp:3792
namespace for Niels Lohmann
Definition: json.hpp:79
-
a const random access iterator for the basic_json class
Definition: json.hpp:5686
+
a const random access iterator for the basic_json class
Definition: json.hpp:5766
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
Since
version 1.0.0
-

Definition at line 3688 of file json.hpp.

+

Definition at line 3768 of file json.hpp.

@@ -279,7 +281,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_aa6a24b176f9599a21d662cc5f8e1ca76.html b/classnlohmann_1_1basic__json_aa6a24b176f9599a21d662cc5f8e1ca76.html index 6739f4f70..18e01402d 100644 --- a/classnlohmann_1_1basic__json_aa6a24b176f9599a21d662cc5f8e1ca76.html +++ b/classnlohmann_1_1basic__json_aa6a24b176f9599a21d662cc5f8e1ca76.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,7 +270,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa6c32f669a2e523666072003d0ea46f4.html b/classnlohmann_1_1basic__json_aa6c32f669a2e523666072003d0ea46f4.html index 1cd5f7ab4..0d8ce3bc4 100644 --- a/classnlohmann_1_1basic__json_aa6c32f669a2e523666072003d0ea46f4.html +++ b/classnlohmann_1_1basic__json_aa6c32f669a2e523666072003d0ea46f4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -292,7 +294,7 @@ template<class CompatibleObjectType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_aa71e977d31f470689883ac60d16ea4ac.html b/classnlohmann_1_1basic__json_aa71e977d31f470689883ac60d16ea4ac.html index 2c955e60c..d79b76f9e 100644 --- a/classnlohmann_1_1basic__json_aa71e977d31f470689883ac60d16ea4ac.html +++ b/classnlohmann_1_1basic__json_aa71e977d31f470689883ac60d16ea4ac.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,13 +270,13 @@ use swap() with string"
Example
The example below shows how JSON values can be swapped.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON value
8  json value = {{"array", {1, 2, 3, 4}}};
9 
10  // create an array_t
11  json::array_t array = {"Snap", "Crackle", "Pop"};
12 
13  // swap the array stored in the JSON value
14  value["array"].swap(array);
15 
16  // output the values
17  std::cout << "value = " << value << '\n';
18  std::cout << "array = " << array << '\n';
19 }
ArrayType< basic_json, AllocatorType< basic_json >> array_t
a type for an array
Definition: json.hpp:387
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4486
+
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4566
Output (play with this example online):
value = {"array":["Snap","Crackle","Pop"]}
 array = [1,2,3,4]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/swap__array_t.cpp -o swap__array_t 
Since
version 1.0.0
-

Definition at line 4517 of file json.hpp.

+

Definition at line 4597 of file json.hpp.

@@ -284,7 +286,7 @@ array = [1,2,3,4] diff --git a/classnlohmann_1_1basic__json_aabe4661644ea549089f0886c2551d2ac.html b/classnlohmann_1_1basic__json_aabe4661644ea549089f0886c2551d2ac.html index 158886a08..c0ac51518 100644 --- a/classnlohmann_1_1basic__json_aabe4661644ea549089f0886c2551d2ac.html +++ b/classnlohmann_1_1basic__json_aabe4661644ea549089f0886c2551d2ac.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html b/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html index 216bc3f51..0870ceee9 100644 --- a/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html +++ b/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -266,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Since
version 1.0.0
-

Definition at line 4619 of file json.hpp.

+

Definition at line 4699 of file json.hpp.

@@ -276,7 +278,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html index 60025dabe..60661ab9a 100644 --- a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html +++ b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__less.cpp -o operator__less 
Since
version 1.0.0
-

Definition at line 4836 of file json.hpp.

+

Definition at line 4916 of file json.hpp.

@@ -293,7 +295,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aacf6c869f6a9c66ac1bc99e93f310044.html b/classnlohmann_1_1basic__json_aacf6c869f6a9c66ac1bc99e93f310044.html index 6de2f60d8..cb01be24b 100644 --- a/classnlohmann_1_1basic__json_aacf6c869f6a9c66ac1bc99e93f310044.html +++ b/classnlohmann_1_1basic__json_aacf6c869f6a9c66ac1bc99e93f310044.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html index 299e7e392..d1d549aea 100644 --- a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html +++ b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
See also
parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
Since
version 1.0.0
-

Definition at line 5132 of file json.hpp.

+

Definition at line 5212 of file json.hpp.

@@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aafa839f2a74dc1b5060314b3423143b8.html b/classnlohmann_1_1basic__json_aafa839f2a74dc1b5060314b3423143b8.html index b496f6889..41429ce36 100644 --- a/classnlohmann_1_1basic__json_aafa839f2a74dc1b5060314b3423143b8.html +++ b/classnlohmann_1_1basic__json_aafa839f2a74dc1b5060314b3423143b8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -256,7 +258,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab14e3503305622fb5ab01a7f490916e8.html b/classnlohmann_1_1basic__json_ab14e3503305622fb5ab01a7f490916e8.html index af82a49cd..eea8e3ff4 100644 --- a/classnlohmann_1_1basic__json_ab14e3503305622fb5ab01a7f490916e8.html +++ b/classnlohmann_1_1basic__json_ab14e3503305622fb5ab01a7f490916e8.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,15 +280,15 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
iterator pointing to the first element inserted, or pos if ilist is empty
Complexity
Linear in ilist.size() plus linear in the distance between pos and end of the container.
Example
The example shows how insert is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json v = {1, 2, 3, 4};
9 
10  // insert range from v2 before the end of array v
11  auto new_pos = v.insert(v.end(), {7, 8, 9});
12 
13  // output new array and result of insert call
14  std::cout << *new_pos << '\n';
15  std::cout << v << '\n';
16 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
namespace for Niels Lohmann
Definition: json.hpp:79
-
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4281
+
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4361
Output (play with this example online):
7
 [1,2,3,4,7,8,9]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/insert__ilist.cpp -o insert__ilist 
Since
version 1.0.0
-

Definition at line 4448 of file json.hpp.

+

Definition at line 4528 of file json.hpp.

@@ -296,7 +298,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab2162bc76e10d8736cab9b2039956054.html b/classnlohmann_1_1basic__json_ab2162bc76e10d8736cab9b2039956054.html index 8cae69f32..0ace6a7a2 100644 --- a/classnlohmann_1_1basic__json_ab2162bc76e10d8736cab9b2039956054.html +++ b/classnlohmann_1_1basic__json_ab2162bc76e10d8736cab9b2039956054.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -261,14 +263,14 @@ Illustration from cppreference.com
Example
The following code shows an example for end.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to one past the last element
11  json::iterator it = array.end();
12 
13  // decrement the iterator to point to the last element
14  --it;
15 
16  // serialize the element that the iterator points to
17  std::cout << *it << '\n';
18 }
a class to store JSON values
Definition: json.hpp:188
-
a mutable random access iterator for the basic_json class
Definition: json.hpp:6228
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
+
a mutable random access iterator for the basic_json class
Definition: json.hpp:6308
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/end.cpp -o end 
Since
version 1.0.0
-

Definition at line 3678 of file json.hpp.

+

Definition at line 3758 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ab74b2398f29acc6ffbf48f1b8974a848.html b/classnlohmann_1_1basic__json_ab74b2398f29acc6ffbf48f1b8974a848.html index f45864b48..ab12eb212 100644 --- a/classnlohmann_1_1basic__json_ab74b2398f29acc6ffbf48f1b8974a848.html +++ b/classnlohmann_1_1basic__json_ab74b2398f29acc6ffbf48f1b8974a848.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -289,7 +291,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_ab7d60fb6cb8e8f5740e588f9dc953819.html b/classnlohmann_1_1basic__json_ab7d60fb6cb8e8f5740e588f9dc953819.html index e6fd7af2a..8d5f6a6b5 100644 --- a/classnlohmann_1_1basic__json_ab7d60fb6cb8e8f5740e588f9dc953819.html +++ b/classnlohmann_1_1basic__json_ab7d60fb6cb8e8f5740e588f9dc953819.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -297,7 +299,7 @@ template<class CompatibleArrayType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_ab9a20bd1d391e9cb968db50c246f728d.html b/classnlohmann_1_1basic__json_ab9a20bd1d391e9cb968db50c246f728d.html index b4440dc10..d544806ce 100644 --- a/classnlohmann_1_1basic__json_ab9a20bd1d391e9cb968db50c246f728d.html +++ b/classnlohmann_1_1basic__json_ab9a20bd1d391e9cb968db50c246f728d.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -274,7 +276,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Example
The following code calls size on the different value types.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_object_empty(json::value_t::object);
14  json j_array = {1, 2, 4, 8, 16};
15  json j_array_empty(json::value_t::array);
16  json j_string = "Hello, world";
17 
18  // call size()
19  std::cout << j_null.size() << '\n';
20  std::cout << j_boolean.size() << '\n';
21  std::cout << j_number_integer.size() << '\n';
22  std::cout << j_number_float.size() << '\n';
23  std::cout << j_object.size() << '\n';
24  std::cout << j_object_empty.size() << '\n';
25  std::cout << j_array.size() << '\n';
26  std::cout << j_array_empty.size() << '\n';
27  std::cout << j_string.size() << '\n';
28 }
a class to store JSON values
Definition: json.hpp:188
-
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:3952
+
size_type size() const noexcept
returns the number of elements
Definition: json.hpp:4032
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
array (ordered collection of values)
@@ -290,7 +292,7 @@ template<template< typename U, typename V, typename...Args > class Obje The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/size.cpp -o size 
Since
version 1.0.0
-

Definition at line 3952 of file json.hpp.

+

Definition at line 4032 of file json.hpp.

@@ -300,7 +302,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab9da2afc6f77295f25252725fde142a6.html b/classnlohmann_1_1basic__json_ab9da2afc6f77295f25252725fde142a6.html index 3abe5b868..19876338f 100644 --- a/classnlohmann_1_1basic__json_ab9da2afc6f77295f25252725fde142a6.html +++ b/classnlohmann_1_1basic__json_ab9da2afc6f77295f25252725fde142a6.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<template< typename U, typename V, typename...Args > class Obje
object (unordered set of name/value pairs)
namespace for Niels Lohmann
Definition: json.hpp:79
array (ordered collection of values)
-
reference back()
access the last element
Definition: json.hpp:3207
+
reference back()
access the last element
Definition: json.hpp:3287
Output (play with this example online):
true
 17
 23.42
@@ -273,7 +275,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/back.cpp -o back 
Since
version 1.0.0
-

Definition at line 3217 of file json.hpp.

+

Definition at line 3297 of file json.hpp.

@@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_abe8f3224ca4041908ddb466cb9caecf1.html b/classnlohmann_1_1basic__json_abe8f3224ca4041908ddb466cb9caecf1.html index b47479daf..3003c5c87 100644 --- a/classnlohmann_1_1basic__json_abe8f3224ca4041908ddb466cb9caecf1.html +++ b/classnlohmann_1_1basic__json_abe8f3224ca4041908ddb466cb9caecf1.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Example
The following code calls max_size on the different value types. Note the output is implementation specific.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_null;
9  json j_boolean = true;
10  json j_number_integer = 17;
11  json j_number_float = 23.42;
12  json j_object = {{"one", 1}, {"two", 2}};
13  json j_array = {1, 2, 4, 8, 16};
14  json j_string = "Hello, world";
15 
16  // call max_size()
17  std::cout << j_null.max_size() << '\n';
18  std::cout << j_boolean.max_size() << '\n';
19  std::cout << j_number_integer.max_size() << '\n';
20  std::cout << j_number_float.max_size() << '\n';
21  std::cout << j_object.max_size() << '\n';
22  std::cout << j_array.max_size() << '\n';
23  std::cout << j_string.max_size() << '\n';
24 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:4014
+
size_type max_size() const noexcept
returns the maximum possible number of elements
Definition: json.hpp:4094
Output (play with this example online):
0
 1
 1
@@ -286,7 +288,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/max_size.cpp -o max_size 
Since
version 1.0.0
-

Definition at line 4014 of file json.hpp.

+

Definition at line 4094 of file json.hpp.

@@ -296,7 +298,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac160789f17d206a5404981ca0957e303.html b/classnlohmann_1_1basic__json_ac160789f17d206a5404981ca0957e303.html index b6093c8ad..eb4655485 100644 --- a/classnlohmann_1_1basic__json_ac160789f17d206a5404981ca0957e303.html +++ b/classnlohmann_1_1basic__json_ac160789f17d206a5404981ca0957e303.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,7 +280,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac4011bd0781e51afe4994d2b09fd27e9.html b/classnlohmann_1_1basic__json_ac4011bd0781e51afe4994d2b09fd27e9.html index aa84f9617..fba2db6dd 100644 --- a/classnlohmann_1_1basic__json_ac4011bd0781e51afe4994d2b09fd27e9.html +++ b/classnlohmann_1_1basic__json_ac4011bd0781e51afe4994d2b09fd27e9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac8163abe518595f19dbee68db1caaaf7.html b/classnlohmann_1_1basic__json_ac8163abe518595f19dbee68db1caaaf7.html index 69b96c276..225d146aa 100644 --- a/classnlohmann_1_1basic__json_ac8163abe518595f19dbee68db1caaaf7.html +++ b/classnlohmann_1_1basic__json_ac8163abe518595f19dbee68db1caaaf7.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_ac82abedf356d252e0589850c3d8b35ba.html b/classnlohmann_1_1basic__json_ac82abedf356d252e0589850c3d8b35ba.html index 2d47dabc5..2f64a913a 100644 --- a/classnlohmann_1_1basic__json_ac82abedf356d252e0589850c3d8b35ba.html +++ b/classnlohmann_1_1basic__json_ac82abedf356d252e0589850c3d8b35ba.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -271,7 +273,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac943391891fcde0a71a15ce990e0f7f4.html b/classnlohmann_1_1basic__json_ac943391891fcde0a71a15ce990e0f7f4.html index 598c22c18..6b6414079 100644 --- a/classnlohmann_1_1basic__json_ac943391891fcde0a71a15ce990e0f7f4.html +++ b/classnlohmann_1_1basic__json_ac943391891fcde0a71a15ce990e0f7f4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -286,7 +288,7 @@ true diff --git a/classnlohmann_1_1basic__json_acd08f9179c8c1e9f2cd7575a724ce27e.html b/classnlohmann_1_1basic__json_acd08f9179c8c1e9f2cd7575a724ce27e.html index db6d7bbe0..c98612eef 100644 --- a/classnlohmann_1_1basic__json_acd08f9179c8c1e9f2cd7575a724ce27e.html +++ b/classnlohmann_1_1basic__json_acd08f9179c8c1e9f2cd7575a724ce27e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -287,7 +289,7 @@ template<typename T , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_acdf4445333649ec94198f09a62144884.html b/classnlohmann_1_1basic__json_acdf4445333649ec94198f09a62144884.html index 2958cb923..b6bcb289a 100644 --- a/classnlohmann_1_1basic__json_acdf4445333649ec94198f09a62144884.html +++ b/classnlohmann_1_1basic__json_acdf4445333649ec94198f09a62144884.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -261,14 +263,14 @@ Illustration from cppreference.com
Example
The following code shows an example for begin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to the first element
11  json::iterator it = array.begin();
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
-
a mutable random access iterator for the basic_json class
Definition: json.hpp:6228
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
+
a mutable random access iterator for the basic_json class
Definition: json.hpp:6308
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/begin.cpp -o begin 
Since
version 1.0.0
-

Definition at line 3619 of file json.hpp.

+

Definition at line 3699 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ace8338e57fdb11e1955c2a0c2d782069.html b/classnlohmann_1_1basic__json_ace8338e57fdb11e1955c2a0c2d782069.html index db907adab..767ebb8b5 100644 --- a/classnlohmann_1_1basic__json_ace8338e57fdb11e1955c2a0c2d782069.html +++ b/classnlohmann_1_1basic__json_ace8338e57fdb11e1955c2a0c2d782069.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -269,7 +271,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ad1f617d29e8923dd40c89153f792b1bc.html b/classnlohmann_1_1basic__json_ad1f617d29e8923dd40c89153f792b1bc.html index 01f03bcd2..afa5512ab 100644 --- a/classnlohmann_1_1basic__json_ad1f617d29e8923dd40c89153f792b1bc.html +++ b/classnlohmann_1_1basic__json_ad1f617d29e8923dd40c89153f792b1bc.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -288,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html b/classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html index 7044abb84..b2d19a56b 100644 --- a/classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html +++ b/classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -260,7 +262,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ad497cbc4f80c8d79662ee6e19bf145dd.html b/classnlohmann_1_1basic__json_ad497cbc4f80c8d79662ee6e19bf145dd.html index 2b127afb3..36ae4ab11 100644 --- a/classnlohmann_1_1basic__json_ad497cbc4f80c8d79662ee6e19bf145dd.html +++ b/classnlohmann_1_1basic__json_ad497cbc4f80c8d79662ee6e19bf145dd.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -295,11 +297,11 @@ erase() with null"
Example
The example shows the result of erase for different JSON types.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_boolean = true;
9  json j_number_integer = 17;
10  json j_number_float = 23.42;
11  json j_object = {{"one", 1}, {"two", 2}};
12  json j_array = {1, 2, 4, 8, 16};
13  json j_string = "Hello, world";
14 
15  // call erase
16  j_boolean.erase(j_boolean.begin(), j_boolean.end());
17  j_number_integer.erase(j_number_integer.begin(), j_number_integer.end());
18  j_number_float.erase(j_number_float.begin(), j_number_float.end());
19  j_object.erase(j_object.find("two"), j_object.end());
20  j_array.erase(j_array.begin() + 1, j_array.begin() + 3);
21  j_string.erase(j_string.begin(), j_string.end());
22 
23  // print values
24  std::cout << j_boolean << '\n';
25  std::cout << j_number_integer << '\n';
26  std::cout << j_number_float << '\n';
27  std::cout << j_object << '\n';
28  std::cout << j_array << '\n';
29  std::cout << j_string << '\n';
30 }
a class to store JSON values
Definition: json.hpp:188
-
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3678
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
-
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3536
+
iterator end()
returns an iterator to one past the last element
Definition: json.hpp:3758
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
+
iterator find(typename object_t::key_type key)
find an element in a JSON object
Definition: json.hpp:3616
namespace for Niels Lohmann
Definition: json.hpp:79
-
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3274
+
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:3354
Output (play with this example online):
null
 null
 null
@@ -314,7 +316,7 @@ null
 erase(const size_type) – removes the element from an array at the given index
Since
version 1.0.0
-

Definition at line 3379 of file json.hpp.

+

Definition at line 3459 of file json.hpp.

@@ -324,7 +326,7 @@ null diff --git a/classnlohmann_1_1basic__json_ad6734c2b91b1b77aa2b43b65c3619c05.html b/classnlohmann_1_1basic__json_ad6734c2b91b1b77aa2b43b65c3619c05.html index a2d9f5ba0..b7d14e761 100644 --- a/classnlohmann_1_1basic__json_ad6734c2b91b1b77aa2b43b65c3619c05.html +++ b/classnlohmann_1_1basic__json_ad6734c2b91b1b77aa2b43b65c3619c05.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -289,7 +291,7 @@ null diff --git a/classnlohmann_1_1basic__json_ad8e0c5d04f016d1b3ac7369e5c73bedf.html b/classnlohmann_1_1basic__json_ad8e0c5d04f016d1b3ac7369e5c73bedf.html index 729fda276..a8be688a1 100644 --- a/classnlohmann_1_1basic__json_ad8e0c5d04f016d1b3ac7369e5c73bedf.html +++ b/classnlohmann_1_1basic__json_ad8e0c5d04f016d1b3ac7369e5c73bedf.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,14 +264,14 @@ Illustration from cppreference.com
Example
The following code shows an example for cbegin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  const json array = {1, 2, 3, 4, 5};
9 
10  // get am iterator to the first element
11  json::const_iterator it = array.cbegin();
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
-
const_iterator cbegin() const
returns a const iterator to the first element
Definition: json.hpp:3653
+
const_iterator cbegin() const
returns a const iterator to the first element
Definition: json.hpp:3733
namespace for Niels Lohmann
Definition: json.hpp:79
-
a const random access iterator for the basic_json class
Definition: json.hpp:5686
+
a const random access iterator for the basic_json class
Definition: json.hpp:5766
Output (play with this example online):
1
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
Since
version 1.0.0
-

Definition at line 3653 of file json.hpp.

+

Definition at line 3733 of file json.hpp.

@@ -279,7 +281,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ada8e01109a60088e4db2a670d4903b54.html b/classnlohmann_1_1basic__json_ada8e01109a60088e4db2a670d4903b54.html index 732e84150..0d3ef93c5 100644 --- a/classnlohmann_1_1basic__json_ada8e01109a60088e4db2a670d4903b54.html +++ b/classnlohmann_1_1basic__json_ada8e01109a60088e4db2a670d4903b54.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -268,7 +270,7 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Constant.
Example
The example below shows how array elements can be read and written using at.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON array
8  json array = {"first", "2nd", "third", "fourth"};
9 
10  // output element at index 2 (third element)
11  std::cout << array.at(2) << '\n';
12 
13  // change element at index 1 (second element) to "second"
14  array.at(1) = "second";
15 
16  // output changed array
17  std::cout << array << '\n';
18 
19  // try to write beyond the array limit
20  try
21  {
22  array.at(5) = "sixth";
23  }
24  catch (std::out_of_range& e)
25  {
26  std::cout << "out of range: " << e.what() << '\n';
27  }
28 }
static basic_json array(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
explicitly create an array from an initializer list
Definition: json.hpp:1470
a class to store JSON values
Definition: json.hpp:188
-
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2638
+
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2718
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"third"
 ["first","second","third","fourth"]
@@ -276,7 +278,7 @@ out of range: array index 5 is out of range
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/at__size_type.cpp -o at__size_type 
Since
version 1.0.0
-

Definition at line 2638 of file json.hpp.

+

Definition at line 2718 of file json.hpp.

@@ -286,7 +288,7 @@ out of range: array index 5 is out of range diff --git a/classnlohmann_1_1basic__json_adbd4c16c9ac641b2a4736bc2c6787d83.html b/classnlohmann_1_1basic__json_adbd4c16c9ac641b2a4736bc2c6787d83.html index c628efb7d..9625093b7 100644 --- a/classnlohmann_1_1basic__json_adbd4c16c9ac641b2a4736bc2c6787d83.html +++ b/classnlohmann_1_1basic__json_adbd4c16c9ac641b2a4736bc2c6787d83.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ade7bd6e0fe221fec9d3fa9b430f5ce76.html b/classnlohmann_1_1basic__json_ade7bd6e0fe221fec9d3fa9b430f5ce76.html index b5513947f..708a12959 100644 --- a/classnlohmann_1_1basic__json_ade7bd6e0fe221fec9d3fa9b430f5ce76.html +++ b/classnlohmann_1_1basic__json_ade7bd6e0fe221fec9d3fa9b430f5ce76.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -310,7 +312,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_adeaef2ab021997a11a826c378c2365e1.html b/classnlohmann_1_1basic__json_adeaef2ab021997a11a826c378c2365e1.html index 55b66e5cb..4ffc54459 100644 --- a/classnlohmann_1_1basic__json_adeaef2ab021997a11a826c378c2365e1.html +++ b/classnlohmann_1_1basic__json_adeaef2ab021997a11a826c378c2365e1.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_adf5dea6fa9d7075ff89ca0796ab47a7e.html b/classnlohmann_1_1basic__json_adf5dea6fa9d7075ff89ca0796ab47a7e.html index f49bfca42..db48dd1b6 100644 --- a/classnlohmann_1_1basic__json_adf5dea6fa9d7075ff89ca0796ab47a7e.html +++ b/classnlohmann_1_1basic__json_adf5dea6fa9d7075ff89ca0796ab47a7e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html index ef489fa4e..e7c87e870 100644 --- a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html +++ b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje null != nullptr false

The example code above can be translated with

g++ -std=c++11 -Isrc doc/examples/operator__notequal__nullptr_t.cpp -o operator__notequal__nullptr_t 
Since
version 1.0.0
-

Definition at line 4798 of file json.hpp.

+

Definition at line 4878 of file json.hpp.

@@ -289,7 +291,7 @@ null != nullptr false diff --git a/classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html b/classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html index a080a977f..2722516b1 100644 --- a/classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html +++ b/classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -263,7 +265,7 @@ template<typename PointerType , typename std::enable_if<
Complexity
Constant.
Example
The example below shows how pointers to internal values of a JSON value can be requested. Note that no type conversions are made and a nullptr is returned if the value and the requested pointer type does not match.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON number
8  json value = 17;
9 
10  // explicitly getting pointers
11  auto p1 = value.get<const json::number_integer_t*>();
12  auto p2 = value.get<json::number_integer_t*>();
13  auto p3 = value.get<json::number_integer_t* const>();
14  auto p4 = value.get<const json::number_integer_t* const>();
15  auto p5 = value.get<json::number_float_t*>();
16 
17  // print the pointees
18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
20 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
ValueType get() const
get a value (explicit)
Definition: json.hpp:2461
+
ValueType get() const
get a value (explicit)
Definition: json.hpp:2490
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:528
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:593
Output (play with this example online):
17 17 17 17
@@ -272,7 +274,7 @@ true
 
See also
get_ptr() for explicit pointer-member access
Since
version 1.0.0
-

Definition at line 2496 of file json.hpp.

+

Definition at line 2525 of file json.hpp.

@@ -282,7 +284,7 @@ true diff --git a/classnlohmann_1_1basic__json_ae874cfc1746b560c53a03bcf5b7bbeed.html b/classnlohmann_1_1basic__json_ae874cfc1746b560c53a03bcf5b7bbeed.html index 5835b8611..c7fc76aa0 100644 --- a/classnlohmann_1_1basic__json_ae874cfc1746b560c53a03bcf5b7bbeed.html +++ b/classnlohmann_1_1basic__json_ae874cfc1746b560c53a03bcf5b7bbeed.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_ae928414b2805cf6ef56b4e4f8d235416.html b/classnlohmann_1_1basic__json_ae928414b2805cf6ef56b4e4f8d235416.html index 7dffe7b63..0801a33e8 100644 --- a/classnlohmann_1_1basic__json_ae928414b2805cf6ef56b4e4f8d235416.html +++ b/classnlohmann_1_1basic__json_ae928414b2805cf6ef56b4e4f8d235416.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -249,7 +251,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ae960d2d6bc7b94fe39cc5e9f106edfa9.html b/classnlohmann_1_1basic__json_ae960d2d6bc7b94fe39cc5e9f106edfa9.html index 4e69883c9..06a8eb27c 100644 --- a/classnlohmann_1_1basic__json_ae960d2d6bc7b94fe39cc5e9f106edfa9.html +++ b/classnlohmann_1_1basic__json_ae960d2d6bc7b94fe39cc5e9f106edfa9.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,13 +269,13 @@ operator[] with null"
Complexity
Constant.
Example
The example below shows how array elements can be read using the [] operator.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON array
8  json array = {"first", "2nd", "third", "fourth"};
9 
10  // output element at index 2 (third element)
11  std::cout << array.at(2) << '\n';
12 }
a class to store JSON values
Definition: json.hpp:188
-
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2638
+
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2718
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"third"
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operatorarray__size_type_const.cpp -o operatorarray__size_type_const 
Since
version 1.0.0
-

Definition at line 2870 of file json.hpp.

+

Definition at line 2950 of file json.hpp.

@@ -283,7 +285,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html index 6f99c134e..c34f850d5 100644 --- a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html +++ b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -279,7 +281,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af073eec08d2e68924098aef09e9a10ba.html b/classnlohmann_1_1basic__json_af073eec08d2e68924098aef09e9a10ba.html index 2a9aa7479..2fb0189b6 100644 --- a/classnlohmann_1_1basic__json_af073eec08d2e68924098aef09e9a10ba.html +++ b/classnlohmann_1_1basic__json_af073eec08d2e68924098aef09e9a10ba.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -260,13 +262,13 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Constant.
Example
The example below shows how JSON arrays can be swapped.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create two JSON values
8  json j1 = {1, 2, 3, 4, 5};
9  json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}};
10 
11  // swap the values
12  j1.swap(j2);
13 
14  // output the values
15  std::cout << "j1 = " << j1 << '\n';
16  std::cout << "j2 = " << j2 << '\n';
17 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4486
+
void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
exchanges the values
Definition: json.hpp:4566
Output (play with this example online):
j1 = {"e":2.71828182845905,"pi":3.14159265358979}
 j2 = [1,2,3,4,5]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/swap__reference.cpp -o swap__reference 
Since
version 1.0.0
-

Definition at line 4486 of file json.hpp.

+

Definition at line 4566 of file json.hpp.

@@ -276,7 +278,7 @@ j2 = [1,2,3,4,5] diff --git a/classnlohmann_1_1basic__json_af0ebd1757acb971a6504b4acabf88584.html b/classnlohmann_1_1basic__json_af0ebd1757acb971a6504b4acabf88584.html index 57ca73de3..f3597b501 100644 --- a/classnlohmann_1_1basic__json_af0ebd1757acb971a6504b4acabf88584.html +++ b/classnlohmann_1_1basic__json_af0ebd1757acb971a6504b4acabf88584.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -262,13 +264,13 @@ Illustration from cppreference.com
Example
The following code shows an example for rbegin.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create an array value
8  json array = {1, 2, 3, 4, 5};
9 
10  // get an iterator to the reverse-beginning
11  json::reverse_iterator it = array.rbegin();
12 
13  // serialize the element that the iterator points to
14  std::cout << *it << '\n';
15 }
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
-
reverse_iterator rbegin()
returns an iterator to the reverse-beginning
Definition: json.hpp:3736
+
reverse_iterator rbegin()
returns an iterator to the reverse-beginning
Definition: json.hpp:3816
a template for a reverse iterator class
Definition: json.hpp:233
Output (play with this example online):
5
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/rbegin.cpp -o rbegin 
Since
version 1.0.0
-

Definition at line 3736 of file json.hpp.

+

Definition at line 3816 of file json.hpp.

@@ -278,7 +280,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_af127fb69c580c17821da5f5be57e3585.html b/classnlohmann_1_1basic__json_af127fb69c580c17821da5f5be57e3585.html index 778c76c9c..0a410380a 100644 --- a/classnlohmann_1_1basic__json_af127fb69c580c17821da5f5be57e3585.html +++ b/classnlohmann_1_1basic__json_af127fb69c580c17821da5f5be57e3585.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af1e3f9e079136abca2530c8191c56292.html b/classnlohmann_1_1basic__json_af1e3f9e079136abca2530c8191c56292.html index 1b54b5f21..d43fd7258 100644 --- a/classnlohmann_1_1basic__json_af1e3f9e079136abca2530c8191c56292.html +++ b/classnlohmann_1_1basic__json_af1e3f9e079136abca2530c8191c56292.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -300,7 +302,7 @@ initializer list"
Complexity
Linear in the size of the initializer list init.
-
Example
The example below shows how JSON values are created from initializer lists
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_empty_init_list = json({});
9  json j_object = { {"one", 1}, {"two", 2} };
10  json j_array = {1, 2, 3, 4};
11  json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
12  json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
13 
14  // serialize the JSON value
15  std::cout << j_empty_init_list << '\n';
16  std::cout << j_object << '\n';
17  std::cout << j_array << '\n';
18  std::cout << j_nested_object << '\n';
19  std::cout << j_nested_array << '\n';
20 }
basic_json<> json
default JSON class
Definition: json.hpp:7968
+
Example
The example below shows how JSON values are created from initializer lists
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON values
8  json j_empty_init_list = json({});
9  json j_object = { {"one", 1}, {"two", 2} };
10  json j_array = {1, 2, 3, 4};
11  json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
12  json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
13 
14  // serialize the JSON value
15  std::cout << j_empty_init_list << '\n';
16  std::cout << j_object << '\n';
17  std::cout << j_array << '\n';
18  std::cout << j_nested_object << '\n';
19  std::cout << j_nested_array << '\n';
20 }
basic_json<> json
default JSON class
Definition: json.hpp:8048
a class to store JSON values
Definition: json.hpp:188
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
{}
@@ -324,7 +326,7 @@ initializer list"
 
diff --git a/classnlohmann_1_1basic__json_af2730bc8ffa6b28916875c13ee7b83f5.html b/classnlohmann_1_1basic__json_af2730bc8ffa6b28916875c13ee7b83f5.html index e4f1c0811..02cf008d2 100644 --- a/classnlohmann_1_1basic__json_af2730bc8ffa6b28916875c13ee7b83f5.html +++ b/classnlohmann_1_1basic__json_af2730bc8ffa6b28916875c13ee7b83f5.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -270,12 +272,12 @@ template<template< typename U, typename V, typename...Args > class Obje
Returns
result of the deserialization
Complexity
Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
Note
A UTF-8 byte order mark is silently ignored.
-
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  std::string text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // parse and serialize JSON
26  json j_complete = json::parse(text);
27  std::cout << std::setw(4) << j_complete << "\n\n";
28 
29 
30  // define parser callback
31  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
32  {
33  // skip object elements with key "Thumbnail"
34  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
35  {
36  return false;
37  }
38  else
39  {
40  return true;
41  }
42  };
43 
44  // parse (with callback) and serialize JSON
45  json j_filtered = json::parse(text, cb);
46  std::cout << std::setw(4) << j_filtered << '\n';
47 }
basic_json<> json
default JSON class
Definition: json.hpp:7968
+
Example
The example below demonstrates the parse function with and without callback function.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // a JSON text
8  std::string text = R"(
9  {
10  "Image": {
11  "Width": 800,
12  "Height": 600,
13  "Title": "View from 15th Floor",
14  "Thumbnail": {
15  "Url": "http://www.example.com/image/481989943",
16  "Height": 125,
17  "Width": 100
18  },
19  "Animated" : false,
20  "IDs": [116, 943, 234, 38793]
21  }
22  }
23  )";
24 
25  // parse and serialize JSON
26  json j_complete = json::parse(text);
27  std::cout << std::setw(4) << j_complete << "\n\n";
28 
29 
30  // define parser callback
31  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
32  {
33  // skip object elements with key "Thumbnail"
34  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
35  {
36  return false;
37  }
38  else
39  {
40  return true;
41  }
42  };
43 
44  // parse (with callback) and serialize JSON
45  json j_filtered = json::parse(text, cb);
46  std::cout << std::setw(4) << j_filtered << '\n';
47 }
basic_json<> json
default JSON class
Definition: json.hpp:8048
a class to store JSON values
Definition: json.hpp:188
std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
per-element parser callback type
Definition: json.hpp:820
namespace for Niels Lohmann
Definition: json.hpp:79
the parser read a key of a value in an object
-
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5057
+
static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
deserialize from string
Definition: json.hpp:5137
parse_event_t
JSON callback events.
Definition: json.hpp:755
Output (play with this example online):
{
     "Image": {
@@ -315,7 +317,7 @@ template<template< typename U, typename V, typename...Args > class Obje
 
See also
parse(std::istream&, parser_callback_t) for a version that reads from an input stream
Since
version 1.0.0
-

Definition at line 5057 of file json.hpp.

+

Definition at line 5137 of file json.hpp.

@@ -325,7 +327,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af661bc209bf22097e2f76607a11b56bf.html b/classnlohmann_1_1basic__json_af661bc209bf22097e2f76607a11b56bf.html index 60ed0df73..ee05b36c8 100644 --- a/classnlohmann_1_1basic__json_af661bc209bf22097e2f76607a11b56bf.html +++ b/classnlohmann_1_1basic__json_af661bc209bf22097e2f76607a11b56bf.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -275,7 +277,7 @@ false diff --git a/classnlohmann_1_1basic__json_af6b6050ccd906dddf7c9f47fe3ad62a5.html b/classnlohmann_1_1basic__json_af6b6050ccd906dddf7c9f47fe3ad62a5.html index 5de80626e..7fa515b07 100644 --- a/classnlohmann_1_1basic__json_af6b6050ccd906dddf7c9f47fe3ad62a5.html +++ b/classnlohmann_1_1basic__json_af6b6050ccd906dddf7c9f47fe3ad62a5.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -267,14 +269,14 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Constant.
Example
The example below shows how array elements can be read using at.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create JSON array
8  json array = {"first", "2nd", "third", "fourth"};
9 
10  // output element at index 2 (third element)
11  std::cout << array.at(2) << '\n';
12 
13  // try to read beyond the array limit
14  try
15  {
16  std::cout << array.at(5) << '\n';
17  }
18  catch (std::out_of_range)
19  {
20  std::cout << "out of range" << '\n';
21  }
22 }
a class to store JSON values
Definition: json.hpp:188
-
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2638
+
reference at(size_type idx)
access specified array element with bounds checking
Definition: json.hpp:2718
namespace for Niels Lohmann
Definition: json.hpp:79
Output (play with this example online):
"third"
 out of range
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/at__size_type_const.cpp -o at__size_type_const 
Since
version 1.0.0
-

Definition at line 2682 of file json.hpp.

+

Definition at line 2762 of file json.hpp.

@@ -284,7 +286,7 @@ out of range diff --git a/classnlohmann_1_1basic__json_af709c079de0ac3507143ea2c60699bd0.html b/classnlohmann_1_1basic__json_af709c079de0ac3507143ea2c60699bd0.html index fe94a8e33..6915ea21c 100644 --- a/classnlohmann_1_1basic__json_af709c079de0ac3507143ea2c60699bd0.html +++ b/classnlohmann_1_1basic__json_af709c079de0ac3507143ea2c60699bd0.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -282,7 +284,7 @@ array: [1,2,3,4,5] The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/operator__ValueType.cpp -o operator__ValueType 
Since
version 1.0.0
-

Definition at line 2600 of file json.hpp.

+

Definition at line 2680 of file json.hpp.

@@ -292,7 +294,7 @@ array: [1,2,3,4,5] diff --git a/classnlohmann_1_1basic__json_af74581d177dafc38df5a126ccd358999.html b/classnlohmann_1_1basic__json_af74581d177dafc38df5a126ccd358999.html index 22fc8ea96..9a431cb6c 100644 --- a/classnlohmann_1_1basic__json_af74581d177dafc38df5a126ccd358999.html +++ b/classnlohmann_1_1basic__json_af74581d177dafc38df5a126ccd358999.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -293,7 +295,7 @@ template<template< typename U, typename V, typename...Args > class Obje value() for access by value with a default value
Since
version 1.0.0
-

Definition at line 2911 of file json.hpp.

+

Definition at line 2991 of file json.hpp.

@@ -303,7 +305,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af7d0adc984d04fc70c3d29fcd63e096a.html b/classnlohmann_1_1basic__json_af7d0adc984d04fc70c3d29fcd63e096a.html index 81227fc77..3b653c90f 100644 --- a/classnlohmann_1_1basic__json_af7d0adc984d04fc70c3d29fcd63e096a.html +++ b/classnlohmann_1_1basic__json_af7d0adc984d04fc70c3d29fcd63e096a.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -278,15 +280,15 @@ template<template< typename U, typename V, typename...Args > class Obje
Complexity
Constant plus linear in the distance between pos and end of the container.
Example
The example shows how insert is used.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json v = {1, 2, 3, 4};
9 
10  // insert number 10 before number 3
11  auto new_pos = v.insert(v.begin() + 2, 10);
12 
13  // output new array and result of insert call
14  std::cout << *new_pos << '\n';
15  std::cout << v << '\n';
16 }
a class to store JSON values
Definition: json.hpp:188
-
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3619
+
iterator begin()
returns an iterator to the first element
Definition: json.hpp:3699
namespace for Niels Lohmann
Definition: json.hpp:79
-
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4281
+
iterator insert(const_iterator pos, const basic_json &val)
inserts element
Definition: json.hpp:4361
Output (play with this example online):
10
 [1,2,10,3,4]
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
Since
version 1.0.0
-

Definition at line 4281 of file json.hpp.

+

Definition at line 4361 of file json.hpp.

@@ -296,7 +298,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_afc4223b5ad03b1b76e925374a8fff98e.html b/classnlohmann_1_1basic__json_afc4223b5ad03b1b76e925374a8fff98e.html index 4131372e5..e9c924475 100644 --- a/classnlohmann_1_1basic__json_afc4223b5ad03b1b76e925374a8fff98e.html +++ b/classnlohmann_1_1basic__json_afc4223b5ad03b1b76e925374a8fff98e.html @@ -145,6 +145,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); get_allocator get_ptr get_ptr + get_ref + get_ref insert insert insert @@ -287,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 5638e5a92..d8664c8e1 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -92,7 +92,7 @@ Files diff --git a/functions.html b/functions.html index e8572c767..e2a7789cf 100644 --- a/functions.html +++ b/functions.html @@ -134,7 +134,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_0x7e.html b/functions_0x7e.html index 4c65ee6c2..60417f8cf 100644 --- a/functions_0x7e.html +++ b/functions_0x7e.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_b.html b/functions_b.html index 42cd465e5..9d7f5bff5 100644 --- a/functions_b.html +++ b/functions_b.html @@ -139,7 +139,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_c.html b/functions_c.html index 163ee4269..fec50f3f3 100644 --- a/functions_c.html +++ b/functions_c.html @@ -152,7 +152,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_d.html b/functions_d.html index 15fbdef57..1e4ea7b4c 100644 --- a/functions_d.html +++ b/functions_d.html @@ -129,7 +129,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_e.html b/functions_e.html index 0bbca6f7d..3bd93d598 100644 --- a/functions_e.html +++ b/functions_e.html @@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_enum.html b/functions_enum.html index 6be20735a..e79228c1c 100644 --- a/functions_enum.html +++ b/functions_enum.html @@ -103,7 +103,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_f.html b/functions_f.html index 03460aa20..d7e6f7c5b 100644 --- a/functions_f.html +++ b/functions_f.html @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_func.html b/functions_func.html index 8d2801006..6042e1603 100644 --- a/functions_func.html +++ b/functions_func.html @@ -204,6 +204,9 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
  • get_ptr() : nlohmann::basic_json
  • +
  • get_ref() +: nlohmann::basic_json +
  • @@ -413,7 +416,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_g.html b/functions_g.html index 7e61e58e4..642638b60 100644 --- a/functions_g.html +++ b/functions_g.html @@ -127,11 +127,14 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
  • get_ptr() : nlohmann::basic_json
  • +
  • get_ref() +: nlohmann::basic_json +
  • diff --git a/functions_i.html b/functions_i.html index fa60bd431..a1e5de506 100644 --- a/functions_i.html +++ b/functions_i.html @@ -167,7 +167,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_j.html b/functions_j.html index f7c7811a0..830788382 100644 --- a/functions_j.html +++ b/functions_j.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_k.html b/functions_k.html index 636790ce8..da8356fe4 100644 --- a/functions_k.html +++ b/functions_k.html @@ -126,7 +126,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_m.html b/functions_m.html index 9aea52950..2bcba0f90 100644 --- a/functions_m.html +++ b/functions_m.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_n.html b/functions_n.html index 24d121118..c805af5b6 100644 --- a/functions_n.html +++ b/functions_n.html @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_o.html b/functions_o.html index ecbfff57f..86e92979f 100644 --- a/functions_o.html +++ b/functions_o.html @@ -216,7 +216,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_p.html b/functions_p.html index 55c4b0bd9..5406ae006 100644 --- a/functions_p.html +++ b/functions_p.html @@ -139,7 +139,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_r.html b/functions_r.html index 15f20b103..493f6560f 100644 --- a/functions_r.html +++ b/functions_r.html @@ -137,7 +137,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_rela.html b/functions_rela.html index 0fdb3817f..093ebb34d 100644 --- a/functions_rela.html +++ b/functions_rela.html @@ -124,7 +124,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_s.html b/functions_s.html index c3a9a325c..8b1ec0c39 100644 --- a/functions_s.html +++ b/functions_s.html @@ -134,7 +134,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_t.html b/functions_t.html index d6343ee0b..fb9dd8fbf 100644 --- a/functions_t.html +++ b/functions_t.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_type.html b/functions_type.html index 476649591..bd497b418 100644 --- a/functions_type.html +++ b/functions_type.html @@ -162,7 +162,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_v.html b/functions_v.html index 37fb4301e..ac73f4287 100644 --- a/functions_v.html +++ b/functions_v.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/graph_legend.html b/graph_legend.html index 905e00f0f..17be06950 100644 --- a/graph_legend.html +++ b/graph_legend.html @@ -108,7 +108,7 @@ A yellow dashed arrow denotes a relation between a template instance and the tem diff --git a/hierarchy.html b/hierarchy.html index f4fc17db2..a8d6d202e 100644 --- a/hierarchy.html +++ b/hierarchy.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/index.html b/index.html index 12e9d4b21..e9f93b838 100644 --- a/index.html +++ b/index.html @@ -92,7 +92,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/json_8hpp_source.html b/json_8hpp_source.html index 6c0e0f674..47f2824cb 100644 --- a/json_8hpp_source.html +++ b/json_8hpp_source.html @@ -83,213 +83,215 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    json.hpp
    -
    1 
    38 #ifndef NLOHMANN_JSON_HPP
    39 #define NLOHMANN_JSON_HPP
    40 
    41 #include <algorithm>
    42 #include <array>
    43 #include <cassert>
    44 #include <ciso646>
    45 #include <cmath>
    46 #include <cstdio>
    47 #include <functional>
    48 #include <initializer_list>
    49 #include <iomanip>
    50 #include <iostream>
    51 #include <iterator>
    52 #include <limits>
    53 #include <map>
    54 #include <memory>
    55 #include <sstream>
    56 #include <string>
    57 #include <type_traits>
    58 #include <utility>
    59 #include <vector>
    60 
    61 // enable ssize_t on MinGW
    62 #ifdef __GNUC__
    63  #ifdef __MINGW32__
    64  #include <sys/types.h>
    65  #endif
    66 #endif
    67 
    68 // enable ssize_t for MSVC
    69 #ifdef _MSC_VER
    70  #include <basetsd.h>
    71  using ssize_t = SSIZE_T;
    72 #endif
    73 
    79 namespace nlohmann
    80 {
    81 
    82 
    87 namespace
    88 {
    93 template<typename T>
    94 struct has_mapped_type
    95 {
    96  private:
    97  template<typename C> static char test(typename C::mapped_type*);
    98  template<typename C> static char (&test(...))[2];
    99  public:
    100  static constexpr bool value = sizeof(test<T>(0)) == 1;
    101 };
    102 
    104 template<typename T>
    105 static bool approx(const T a, const T b)
    106 {
    107  return not (a > b or a < b);
    108 }
    109 }
    110 
    179 template <
    180  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    181  template<typename U, typename... Args> class ArrayType = std::vector,
    182  class StringType = std::string,
    183  class BooleanType = bool,
    184  class NumberIntegerType = int64_t,
    185  class NumberFloatType = double,
    186  template<typename U> class AllocatorType = std::allocator
    187  >
    189 {
    190  private:
    192  using basic_json_t = basic_json<ObjectType,
    193  ArrayType,
    194  StringType,
    195  BooleanType,
    196  NumberIntegerType,
    197  NumberFloatType,
    198  AllocatorType>;
    199 
    200  public:
    201 
    203  // container types //
    205 
    208 
    211 
    214 
    216  using const_reference = const value_type&;
    217 
    219  using difference_type = std::ptrdiff_t;
    220 
    222  using size_type = std::size_t;
    223 
    225  using allocator_type = AllocatorType<basic_json>;
    226 
    228  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    230  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    231 
    232  // forward declaration
    233  template<typename Base> class json_reverse_iterator;
    234 
    236  class iterator;
    238  class const_iterator;
    243 
    245 
    246 
    251  {
    252  return allocator_type();
    253  }
    254 
    255 
    257  // JSON value data types //
    259 
    262 
    337  using object_t = ObjectType<StringType,
    338  basic_json,
    339  std::less<StringType>,
    340  AllocatorType<std::pair<const StringType,
    341  basic_json>>>;
    342 
    387  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    388 
    434  using string_t = StringType;
    435 
    460  using boolean_t = BooleanType;
    461 
    528  using number_integer_t = NumberIntegerType;
    529 
    593  using number_float_t = NumberFloatType;
    594 
    596 
    597 
    599  // JSON type enumeration //
    601 
    612  enum class value_t : uint8_t
    613  {
    614  null,
    615  object,
    616  array,
    617  string,
    618  boolean,
    619  number_integer,
    620  number_float,
    621  discarded
    622  };
    623 
    624 
    625  private:
    627  template<typename T, typename... Args>
    628  static T* create(Args&& ... args)
    629  {
    630  AllocatorType<T> alloc;
    631  auto deleter = [&](T * object)
    632  {
    633  alloc.deallocate(object, 1);
    634  };
    635  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    636  alloc.construct(object.get(), std::forward<Args>(args)...);
    637  return object.release();
    638  }
    639 
    641  // JSON value storage //
    643 
    651  union json_value
    652  {
    654  object_t* object;
    656  array_t* array;
    658  string_t* string;
    660  boolean_t boolean;
    662  number_integer_t number_integer;
    664  number_float_t number_float;
    665 
    667  json_value() noexcept = default;
    669  json_value(boolean_t v) noexcept : boolean(v) {}
    671  json_value(number_integer_t v) noexcept : number_integer(v) {}
    673  json_value(number_float_t v) noexcept : number_float(v) {}
    675  json_value(value_t t)
    676  {
    677  switch (t)
    678  {
    679  case value_t::object:
    680  {
    681  object = create<object_t>();
    682  break;
    683  }
    684 
    685  case value_t::array:
    686  {
    687  array = create<array_t>();
    688  break;
    689  }
    690 
    691  case value_t::string:
    692  {
    693  string = create<string_t>("");
    694  break;
    695  }
    696 
    697  case value_t::boolean:
    698  {
    699  boolean = boolean_t(false);
    700  break;
    701  }
    702 
    703  case value_t::number_integer:
    704  {
    705  number_integer = number_integer_t(0);
    706  break;
    707  }
    708 
    709  case value_t::number_float:
    710  {
    711  number_float = number_float_t(0.0);
    712  break;
    713  }
    714 
    715  default:
    716  {
    717  break;
    718  }
    719  }
    720  }
    721 
    723  json_value(const string_t& value)
    724  {
    725  string = create<string_t>(value);
    726  }
    727 
    729  json_value(const object_t& value)
    730  {
    731  object = create<object_t>(value);
    732  }
    733 
    735  json_value(const array_t& value)
    736  {
    737  array = create<array_t>(value);
    738  }
    739  };
    740 
    741 
    742  public:
    744  // JSON parser callback //
    746 
    755  enum class parse_event_t : uint8_t
    756  {
    758  object_start,
    760  object_end,
    762  array_start,
    764  array_end,
    766  key,
    768  value
    769  };
    770 
    820  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    821 
    822 
    824  // constructors //
    826 
    829 
    868  : m_type(value_type), m_value(value_type)
    869  {}
    870 
    890  basic_json() noexcept = default;
    891 
    911  basic_json(std::nullptr_t) noexcept
    912  : basic_json(value_t::null)
    913  {}
    914 
    934  basic_json(const object_t& val)
    935  : m_type(value_t::object), m_value(val)
    936  {}
    937 
    961  template <class CompatibleObjectType, typename
    962  std::enable_if<
    963  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    964  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    965  = 0>
    966  basic_json(const CompatibleObjectType& val)
    967  : m_type(value_t::object)
    968  {
    969  using std::begin;
    970  using std::end;
    971  m_value.object = create<object_t>(begin(val), end(val));
    972  }
    973 
    993  basic_json(const array_t& val)
    994  : m_type(value_t::array), m_value(val)
    995  {}
    996 
    1020  template <class CompatibleArrayType, typename
    1021  std::enable_if<
    1022  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1023  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1024  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1025  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1026  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1027  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1028  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1029  = 0>
    1030  basic_json(const CompatibleArrayType& val)
    1031  : m_type(value_t::array)
    1032  {
    1033  using std::begin;
    1034  using std::end;
    1035  m_value.array = create<array_t>(begin(val), end(val));
    1036  }
    1037 
    1059  basic_json(const string_t& val)
    1060  : m_type(value_t::string), m_value(val)
    1061  {}
    1062 
    1083  basic_json(const typename string_t::value_type* val)
    1084  : basic_json(string_t(val))
    1085  {}
    1086 
    1110  template <class CompatibleStringType, typename
    1111  std::enable_if<
    1112  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1113  = 0>
    1114  basic_json(const CompatibleStringType& val)
    1115  : basic_json(string_t(val))
    1116  {}
    1117 
    1133  : m_type(value_t::boolean), m_value(val)
    1134  {}
    1135 
    1161  template<typename T,
    1162  typename std::enable_if<
    1163  not (std::is_same<T, int>::value)
    1164  and std::is_same<T, number_integer_t>::value
    1165  , int>::type = 0>
    1167  : m_type(value_t::number_integer), m_value(val)
    1168  {}
    1169 
    1195  basic_json(const int val)
    1196  : m_type(value_t::number_integer),
    1197  m_value(static_cast<number_integer_t>(val))
    1198  {}
    1199 
    1225  template<typename CompatibleNumberIntegerType, typename
    1226  std::enable_if<
    1227  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1228  std::numeric_limits<CompatibleNumberIntegerType>::is_integer, CompatibleNumberIntegerType>::type
    1229  = 0>
    1230  basic_json(const CompatibleNumberIntegerType val) noexcept
    1231  : m_type(value_t::number_integer),
    1232  m_value(static_cast<number_integer_t>(val))
    1233  {}
    1234 
    1260  : m_type(value_t::number_float), m_value(val)
    1261  {
    1262  // replace infinity and NAN by null
    1263  if (not std::isfinite(val))
    1264  {
    1265  m_type = value_t::null;
    1266  m_value = json_value();
    1267  }
    1268  }
    1269 
    1300  template<typename CompatibleNumberFloatType, typename = typename
    1301  std::enable_if<
    1302  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1303  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1304  >
    1305  basic_json(const CompatibleNumberFloatType val) noexcept
    1306  : basic_json(number_float_t(val))
    1307  {}
    1308 
    1378  basic_json(std::initializer_list<basic_json> init,
    1379  bool type_deduction = true,
    1380  value_t manual_type = value_t::array)
    1381  {
    1382  // the initializer list could describe an object
    1383  bool is_an_object = true;
    1384 
    1385  // check if each element is an array with two elements whose first
    1386  // element is a string
    1387  for (const auto& element : init)
    1388  {
    1389  if (not element.is_array() or element.size() != 2
    1390  or not element[0].is_string())
    1391  {
    1392  // we found an element that makes it impossible to use the
    1393  // initializer list as object
    1394  is_an_object = false;
    1395  break;
    1396  }
    1397  }
    1398 
    1399  // adjust type if type deduction is not wanted
    1400  if (not type_deduction)
    1401  {
    1402  // if array is wanted, do not create an object though possible
    1403  if (manual_type == value_t::array)
    1404  {
    1405  is_an_object = false;
    1406  }
    1407 
    1408  // if object is wanted but impossible, throw an exception
    1409  if (manual_type == value_t::object and not is_an_object)
    1410  {
    1411  throw std::domain_error("cannot create object from initializer list");
    1412  }
    1413  }
    1414 
    1415  if (is_an_object)
    1416  {
    1417  // the initializer list is a list of pairs -> create object
    1418  m_type = value_t::object;
    1419  m_value = value_t::object;
    1420 
    1421  assert(m_value.object != nullptr);
    1422 
    1423  for (auto& element : init)
    1424  {
    1425  m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
    1426  }
    1427  }
    1428  else
    1429  {
    1430  // the initializer list describes an array -> create array
    1431  m_type = value_t::array;
    1432  m_value.array = create<array_t>(std::move(init));
    1433  }
    1434  }
    1435 
    1470  static basic_json array(std::initializer_list<basic_json> init =
    1471  std::initializer_list<basic_json>())
    1472  {
    1473  return basic_json(init, false, value_t::array);
    1474  }
    1475 
    1510  static basic_json object(std::initializer_list<basic_json> init =
    1511  std::initializer_list<basic_json>())
    1512  {
    1513  return basic_json(init, false, value_t::object);
    1514  }
    1515 
    1534  basic_json(size_type cnt, const basic_json& val)
    1535  : m_type(value_t::array)
    1536  {
    1537  m_value.array = create<array_t>(cnt, val);
    1538  }
    1539 
    1574  template <class InputIT, typename
    1575  std::enable_if<
    1576  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1577  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1578  , int>::type
    1579  = 0>
    1580  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1581  {
    1582  // make sure iterator fits the current value
    1583  if (first.m_object != last.m_object)
    1584  {
    1585  throw std::domain_error("iterators are not compatible");
    1586  }
    1587 
    1588  // check if iterator range is complete for primitive values
    1589  switch (m_type)
    1590  {
    1591  case value_t::boolean:
    1592  case value_t::number_float:
    1593  case value_t::number_integer:
    1594  case value_t::string:
    1595  {
    1596  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1597  {
    1598  throw std::out_of_range("iterators out of range");
    1599  }
    1600  break;
    1601  }
    1602 
    1603  default:
    1604  {
    1605  break;
    1606  }
    1607  }
    1608 
    1609  switch (m_type)
    1610  {
    1611  case value_t::number_integer:
    1612  {
    1613  assert(first.m_object != nullptr);
    1614  m_value.number_integer = first.m_object->m_value.number_integer;
    1615  break;
    1616  }
    1617 
    1618  case value_t::number_float:
    1619  {
    1620  assert(first.m_object != nullptr);
    1621  m_value.number_float = first.m_object->m_value.number_float;
    1622  break;
    1623  }
    1624 
    1625  case value_t::boolean:
    1626  {
    1627  assert(first.m_object != nullptr);
    1628  m_value.boolean = first.m_object->m_value.boolean;
    1629  break;
    1630  }
    1631 
    1632  case value_t::string:
    1633  {
    1634  assert(first.m_object != nullptr);
    1635  m_value = *first.m_object->m_value.string;
    1636  break;
    1637  }
    1638 
    1639  case value_t::object:
    1640  {
    1641  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1642  break;
    1643  }
    1644 
    1645  case value_t::array:
    1646  {
    1647  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1648  break;
    1649  }
    1650 
    1651  default:
    1652  {
    1653  assert(first.m_object != nullptr);
    1654  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1655  }
    1656  }
    1657  }
    1658 
    1660  // other constructors and destructor //
    1662 
    1683  basic_json(const basic_json& other)
    1684  : m_type(other.m_type)
    1685  {
    1686  switch (m_type)
    1687  {
    1688  case value_t::object:
    1689  {
    1690  assert(other.m_value.object != nullptr);
    1691  m_value = *other.m_value.object;
    1692  break;
    1693  }
    1694 
    1695  case value_t::array:
    1696  {
    1697  assert(other.m_value.array != nullptr);
    1698  m_value = *other.m_value.array;
    1699  break;
    1700  }
    1701 
    1702  case value_t::string:
    1703  {
    1704  assert(other.m_value.string != nullptr);
    1705  m_value = *other.m_value.string;
    1706  break;
    1707  }
    1708 
    1709  case value_t::boolean:
    1710  {
    1711  m_value = other.m_value.boolean;
    1712  break;
    1713  }
    1714 
    1715  case value_t::number_integer:
    1716  {
    1717  m_value = other.m_value.number_integer;
    1718  break;
    1719  }
    1720 
    1721  case value_t::number_float:
    1722  {
    1723  m_value = other.m_value.number_float;
    1724  break;
    1725  }
    1726 
    1727  default:
    1728  {
    1729  break;
    1730  }
    1731  }
    1732  }
    1733 
    1752  basic_json(basic_json&& other) noexcept
    1753  : m_type(std::move(other.m_type)),
    1754  m_value(std::move(other.m_value))
    1755  {
    1756  // invalidate payload
    1757  other.m_type = value_t::null;
    1758  other.m_value = {};
    1759  }
    1760 
    1782  reference& operator=(basic_json other) noexcept (
    1783  std::is_nothrow_move_constructible<value_t>::value and
    1784  std::is_nothrow_move_assignable<value_t>::value and
    1785  std::is_nothrow_move_constructible<json_value>::value and
    1786  std::is_nothrow_move_assignable<json_value>::value
    1787  )
    1788  {
    1789  using std::swap;
    1790  swap(m_type, other.m_type);
    1791  swap(m_value, other.m_value);
    1792  return *this;
    1793  }
    1794 
    1809  {
    1810  switch (m_type)
    1811  {
    1812  case value_t::object:
    1813  {
    1814  AllocatorType<object_t> alloc;
    1815  alloc.destroy(m_value.object);
    1816  alloc.deallocate(m_value.object, 1);
    1817  break;
    1818  }
    1819 
    1820  case value_t::array:
    1821  {
    1822  AllocatorType<array_t> alloc;
    1823  alloc.destroy(m_value.array);
    1824  alloc.deallocate(m_value.array, 1);
    1825  break;
    1826  }
    1827 
    1828  case value_t::string:
    1829  {
    1830  AllocatorType<string_t> alloc;
    1831  alloc.destroy(m_value.string);
    1832  alloc.deallocate(m_value.string, 1);
    1833  break;
    1834  }
    1835 
    1836  default:
    1837  {
    1838  // all other types need no specific destructor
    1839  break;
    1840  }
    1841  }
    1842  }
    1843 
    1845 
    1846  public:
    1848  // object inspection //
    1850 
    1853 
    1877  string_t dump(const int indent = -1) const
    1878  {
    1879  std::stringstream ss;
    1880 
    1881  if (indent >= 0)
    1882  {
    1883  dump(ss, true, static_cast<unsigned int>(indent));
    1884  }
    1885  else
    1886  {
    1887  dump(ss, false, 0);
    1888  }
    1889 
    1890  return ss.str();
    1891  }
    1892 
    1908  value_t type() const noexcept
    1909  {
    1910  return m_type;
    1911  }
    1912 
    1929  bool is_primitive() const noexcept
    1930  {
    1931  return is_null() or is_string() or is_boolean() or is_number();
    1932  }
    1933 
    1949  bool is_structured() const noexcept
    1950  {
    1951  return is_array() or is_object();
    1952  }
    1953 
    1968  bool is_null() const noexcept
    1969  {
    1970  return m_type == value_t::null;
    1971  }
    1972 
    1987  bool is_boolean() const noexcept
    1988  {
    1989  return m_type == value_t::boolean;
    1990  }
    1991 
    2011  bool is_number() const noexcept
    2012  {
    2013  return is_number_integer() or is_number_float();
    2014  }
    2015 
    2034  bool is_number_integer() const noexcept
    2035  {
    2036  return m_type == value_t::number_integer;
    2037  }
    2038 
    2057  bool is_number_float() const noexcept
    2058  {
    2059  return m_type == value_t::number_float;
    2060  }
    2061 
    2076  bool is_object() const noexcept
    2077  {
    2078  return m_type == value_t::object;
    2079  }
    2080 
    2095  bool is_array() const noexcept
    2096  {
    2097  return m_type == value_t::array;
    2098  }
    2099 
    2114  bool is_string() const noexcept
    2115  {
    2116  return m_type == value_t::string;
    2117  }
    2118 
    2138  bool is_discarded() const noexcept
    2139  {
    2140  return m_type == value_t::discarded;
    2141  }
    2142 
    2158  operator value_t() const noexcept
    2159  {
    2160  return m_type;
    2161  }
    2162 
    2164 
    2165  private:
    2167  // value access //
    2169 
    2171  template <class T, typename
    2172  std::enable_if<
    2173  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2174  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2175  , int>::type = 0>
    2176  T get_impl(T*) const
    2177  {
    2178  if (is_object())
    2179  {
    2180  assert(m_value.object != nullptr);
    2181  return T(m_value.object->begin(), m_value.object->end());
    2182  }
    2183  else
    2184  {
    2185  throw std::domain_error("type must be object, but is " + type_name());
    2186  }
    2187  }
    2188 
    2190  object_t get_impl(object_t*) const
    2191  {
    2192  if (is_object())
    2193  {
    2194  assert(m_value.object != nullptr);
    2195  return *(m_value.object);
    2196  }
    2197  else
    2198  {
    2199  throw std::domain_error("type must be object, but is " + type_name());
    2200  }
    2201  }
    2202 
    2204  template <class T, typename
    2205  std::enable_if<
    2206  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2207  not std::is_same<basic_json_t, typename T::value_type>::value and
    2208  not std::is_arithmetic<T>::value and
    2209  not std::is_convertible<std::string, T>::value and
    2210  not has_mapped_type<T>::value
    2211  , int>::type = 0>
    2212  T get_impl(T*) const
    2213  {
    2214  if (is_array())
    2215  {
    2216  T to_vector;
    2217  assert(m_value.array != nullptr);
    2218  std::transform(m_value.array->begin(), m_value.array->end(),
    2219  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2220  {
    2221  return i.get<typename T::value_type>();
    2222  });
    2223  return to_vector;
    2224  }
    2225  else
    2226  {
    2227  throw std::domain_error("type must be array, but is " + type_name());
    2228  }
    2229  }
    2230 
    2232  template <class T, typename
    2233  std::enable_if<
    2234  std::is_convertible<basic_json_t, T>::value and
    2235  not std::is_same<basic_json_t, T>::value
    2236  , int>::type = 0>
    2237  std::vector<T> get_impl(std::vector<T>*) const
    2238  {
    2239  if (is_array())
    2240  {
    2241  std::vector<T> to_vector;
    2242  assert(m_value.array != nullptr);
    2243  to_vector.reserve(m_value.array->size());
    2244  std::transform(m_value.array->begin(), m_value.array->end(),
    2245  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2246  {
    2247  return i.get<T>();
    2248  });
    2249  return to_vector;
    2250  }
    2251  else
    2252  {
    2253  throw std::domain_error("type must be array, but is " + type_name());
    2254  }
    2255  }
    2256 
    2258  template <class T, typename
    2259  std::enable_if<
    2260  std::is_same<basic_json, typename T::value_type>::value and
    2261  not has_mapped_type<T>::value
    2262  , int>::type = 0>
    2263  T get_impl(T*) const
    2264  {
    2265  if (is_array())
    2266  {
    2267  assert(m_value.array != nullptr);
    2268  return T(m_value.array->begin(), m_value.array->end());
    2269  }
    2270  else
    2271  {
    2272  throw std::domain_error("type must be array, but is " + type_name());
    2273  }
    2274  }
    2275 
    2277  array_t get_impl(array_t*) const
    2278  {
    2279  if (is_array())
    2280  {
    2281  assert(m_value.array != nullptr);
    2282  return *(m_value.array);
    2283  }
    2284  else
    2285  {
    2286  throw std::domain_error("type must be array, but is " + type_name());
    2287  }
    2288  }
    2289 
    2291  template <typename T, typename
    2292  std::enable_if<
    2293  std::is_convertible<string_t, T>::value
    2294  , int>::type = 0>
    2295  T get_impl(T*) const
    2296  {
    2297  if (is_string())
    2298  {
    2299  assert(m_value.string != nullptr);
    2300  return *m_value.string;
    2301  }
    2302  else
    2303  {
    2304  throw std::domain_error("type must be string, but is " + type_name());
    2305  }
    2306  }
    2307 
    2309  template<typename T, typename
    2310  std::enable_if<
    2311  std::is_arithmetic<T>::value
    2312  , int>::type = 0>
    2313  T get_impl(T*) const
    2314  {
    2315  switch (m_type)
    2316  {
    2317  case value_t::number_integer:
    2318  {
    2319  return static_cast<T>(m_value.number_integer);
    2320  }
    2321 
    2322  case value_t::number_float:
    2323  {
    2324  return static_cast<T>(m_value.number_float);
    2325  }
    2326 
    2327  default:
    2328  {
    2329  throw std::domain_error("type must be number, but is " + type_name());
    2330  }
    2331  }
    2332  }
    2333 
    2335  boolean_t get_impl(boolean_t*) const
    2336  {
    2337  if (is_boolean())
    2338  {
    2339  return m_value.boolean;
    2340  }
    2341  else
    2342  {
    2343  throw std::domain_error("type must be boolean, but is " + type_name());
    2344  }
    2345  }
    2346 
    2348  object_t* get_impl_ptr(object_t*) noexcept
    2349  {
    2350  return is_object() ? m_value.object : nullptr;
    2351  }
    2352 
    2354  const object_t* get_impl_ptr(const object_t*) const noexcept
    2355  {
    2356  return is_object() ? m_value.object : nullptr;
    2357  }
    2358 
    2360  array_t* get_impl_ptr(array_t*) noexcept
    2361  {
    2362  return is_array() ? m_value.array : nullptr;
    2363  }
    2364 
    2366  const array_t* get_impl_ptr(const array_t*) const noexcept
    2367  {
    2368  return is_array() ? m_value.array : nullptr;
    2369  }
    2370 
    2372  string_t* get_impl_ptr(string_t*) noexcept
    2373  {
    2374  return is_string() ? m_value.string : nullptr;
    2375  }
    2376 
    2378  const string_t* get_impl_ptr(const string_t*) const noexcept
    2379  {
    2380  return is_string() ? m_value.string : nullptr;
    2381  }
    2382 
    2384  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2385  {
    2386  return is_boolean() ? &m_value.boolean : nullptr;
    2387  }
    2388 
    2390  const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2391  {
    2392  return is_boolean() ? &m_value.boolean : nullptr;
    2393  }
    2394 
    2396  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2397  {
    2398  return is_number_integer() ? &m_value.number_integer : nullptr;
    2399  }
    2400 
    2402  const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2403  {
    2404  return is_number_integer() ? &m_value.number_integer : nullptr;
    2405  }
    2406 
    2408  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2409  {
    2410  return is_number_float() ? &m_value.number_float : nullptr;
    2411  }
    2412 
    2414  const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2415  {
    2416  return is_number_float() ? &m_value.number_float : nullptr;
    2417  }
    2418 
    2419  public:
    2420 
    2423 
    2457  template<typename ValueType, typename
    2458  std::enable_if<
    2459  not std::is_pointer<ValueType>::value
    2460  , int>::type = 0>
    2461  ValueType get() const
    2462  {
    2463  return get_impl(static_cast<ValueType*>(nullptr));
    2464  }
    2465 
    2492  template<typename PointerType, typename
    2493  std::enable_if<
    2494  std::is_pointer<PointerType>::value
    2495  , int>::type = 0>
    2496  PointerType get() noexcept
    2497  {
    2498  // delegate the call to get_ptr
    2499  return get_ptr<PointerType>();
    2500  }
    2501 
    2506  template<typename PointerType, typename
    2507  std::enable_if<
    2508  std::is_pointer<PointerType>::value
    2509  , int>::type = 0>
    2510  const PointerType get() const noexcept
    2511  {
    2512  // delegate the call to get_ptr
    2513  return get_ptr<PointerType>();
    2514  }
    2515 
    2541  template<typename PointerType, typename
    2542  std::enable_if<
    2543  std::is_pointer<PointerType>::value
    2544  , int>::type = 0>
    2545  PointerType get_ptr() noexcept
    2546  {
    2547  // delegate the call to get_impl_ptr<>()
    2548  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2549  }
    2550 
    2555  template<typename PointerType, typename
    2556  std::enable_if<
    2557  std::is_pointer<PointerType>::value
    2558  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2559  , int>::type = 0>
    2560  const PointerType get_ptr() const noexcept
    2561  {
    2562  // delegate the call to get_impl_ptr<>() const
    2563  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2564  }
    2565 
    2594  template<typename ValueType, typename
    2595  std::enable_if<
    2596  not std::is_pointer<ValueType>::value
    2597  and not std::is_same<ValueType, typename string_t::value_type>::value
    2598  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    2599  , int>::type = 0>
    2600  operator ValueType() const
    2601  {
    2602  // delegate the call to get<>() const
    2603  return get<ValueType>();
    2604  }
    2605 
    2607 
    2608 
    2610  // element access //
    2612 
    2615 
    2639  {
    2640  // at only works for arrays
    2641  if (is_array())
    2642  {
    2643  try
    2644  {
    2645  assert(m_value.array != nullptr);
    2646  return m_value.array->at(idx);
    2647  }
    2648  catch (std::out_of_range&)
    2649  {
    2650  // create better exception explanation
    2651  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2652  }
    2653  }
    2654  else
    2655  {
    2656  throw std::domain_error("cannot use at() with " + type_name());
    2657  }
    2658  }
    2659 
    2683  {
    2684  // at only works for arrays
    2685  if (is_array())
    2686  {
    2687  try
    2688  {
    2689  assert(m_value.array != nullptr);
    2690  return m_value.array->at(idx);
    2691  }
    2692  catch (std::out_of_range&)
    2693  {
    2694  // create better exception explanation
    2695  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2696  }
    2697  }
    2698  else
    2699  {
    2700  throw std::domain_error("cannot use at() with " + type_name());
    2701  }
    2702  }
    2703 
    2730  reference at(const typename object_t::key_type& key)
    2731  {
    2732  // at only works for objects
    2733  if (is_object())
    2734  {
    2735  try
    2736  {
    2737  assert(m_value.object != nullptr);
    2738  return m_value.object->at(key);
    2739  }
    2740  catch (std::out_of_range&)
    2741  {
    2742  // create better exception explanation
    2743  throw std::out_of_range("key '" + key + "' not found");
    2744  }
    2745  }
    2746  else
    2747  {
    2748  throw std::domain_error("cannot use at() with " + type_name());
    2749  }
    2750  }
    2751 
    2778  const_reference at(const typename object_t::key_type& key) const
    2779  {
    2780  // at only works for objects
    2781  if (is_object())
    2782  {
    2783  try
    2784  {
    2785  assert(m_value.object != nullptr);
    2786  return m_value.object->at(key);
    2787  }
    2788  catch (std::out_of_range&)
    2789  {
    2790  // create better exception explanation
    2791  throw std::out_of_range("key '" + key + "' not found");
    2792  }
    2793  }
    2794  else
    2795  {
    2796  throw std::domain_error("cannot use at() with " + type_name());
    2797  }
    2798  }
    2799 
    2826  {
    2827  // implicitly convert null to object
    2828  if (is_null())
    2829  {
    2830  m_type = value_t::array;
    2831  m_value.array = create<array_t>();
    2832  }
    2833 
    2834  // [] only works for arrays
    2835  if (is_array())
    2836  {
    2837  assert(m_value.array != nullptr);
    2838  for (size_t i = m_value.array->size(); i <= idx; ++i)
    2839  {
    2840  m_value.array->push_back(basic_json());
    2841  }
    2842 
    2843  return m_value.array->operator[](idx);
    2844  }
    2845  else
    2846  {
    2847  throw std::domain_error("cannot use operator[] with " + type_name());
    2848  }
    2849  }
    2850 
    2871  {
    2872  // at only works for arrays
    2873  if (is_array())
    2874  {
    2875  assert(m_value.array != nullptr);
    2876  return m_value.array->operator[](idx);
    2877  }
    2878  else
    2879  {
    2880  throw std::domain_error("cannot use operator[] with " + type_name());
    2881  }
    2882  }
    2883 
    2911  reference operator[](const typename object_t::key_type& key)
    2912  {
    2913  // implicitly convert null to object
    2914  if (is_null())
    2915  {
    2916  m_type = value_t::object;
    2917  m_value.object = create<object_t>();
    2918  }
    2919 
    2920  // [] only works for objects
    2921  if (is_object())
    2922  {
    2923  assert(m_value.object != nullptr);
    2924  return m_value.object->operator[](key);
    2925  }
    2926  else
    2927  {
    2928  throw std::domain_error("cannot use operator[] with " + type_name());
    2929  }
    2930  }
    2931 
    2959  const_reference operator[](const typename object_t::key_type& key) const
    2960  {
    2961  // [] only works for objects
    2962  if (is_object())
    2963  {
    2964  assert(m_value.object != nullptr);
    2965  assert(m_value.object->find(key) != m_value.object->end());
    2966  return m_value.object->find(key)->second;
    2967  }
    2968  else
    2969  {
    2970  throw std::domain_error("cannot use operator[] with " + type_name());
    2971  }
    2972  }
    2973 
    3003  template<typename T, std::size_t n>
    3004  reference operator[](const T (&key)[n])
    3005  {
    3006  // implicitly convert null to object
    3007  if (is_null())
    3008  {
    3009  m_type = value_t::object;
    3010  m_value = value_t::object;
    3011  }
    3012 
    3013  // at only works for objects
    3014  if (is_object())
    3015  {
    3016  assert(m_value.object != nullptr);
    3017  return m_value.object->operator[](key);
    3018  }
    3019  else
    3020  {
    3021  throw std::domain_error("cannot use operator[] with " + type_name());
    3022  }
    3023  }
    3024 
    3054  template<typename T, std::size_t n>
    3055  const_reference operator[](const T (&key)[n]) const
    3056  {
    3057  // at only works for objects
    3058  if (is_object())
    3059  {
    3060  assert(m_value.object != nullptr);
    3061  assert(m_value.object->find(key) != m_value.object->end());
    3062  return m_value.object->find(key)->second;
    3063  }
    3064  else
    3065  {
    3066  throw std::domain_error("cannot use operator[] with " + type_name());
    3067  }
    3068  }
    3069 
    3118  template <class ValueType, typename
    3119  std::enable_if<
    3120  std::is_convertible<basic_json_t, ValueType>::value
    3121  , int>::type = 0>
    3122  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3123  {
    3124  // at only works for objects
    3125  if (is_object())
    3126  {
    3127  // if key is found, return value and given default value otherwise
    3128  const auto it = find(key);
    3129  if (it != end())
    3130  {
    3131  return *it;
    3132  }
    3133  else
    3134  {
    3135  return default_value;
    3136  }
    3137  }
    3138  else
    3139  {
    3140  throw std::domain_error("cannot use value() with " + type_name());
    3141  }
    3142  }
    3143 
    3148  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3149  {
    3150  return value(key, string_t(default_value));
    3151  }
    3152 
    3174  {
    3175  return *begin();
    3176  }
    3177 
    3182  {
    3183  return *cbegin();
    3184  }
    3185 
    3208  {
    3209  auto tmp = end();
    3210  --tmp;
    3211  return *tmp;
    3212  }
    3213 
    3218  {
    3219  auto tmp = cend();
    3220  --tmp;
    3221  return *tmp;
    3222  }
    3223 
    3268  template <class InteratorType, typename
    3269  std::enable_if<
    3270  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3271  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3272  , int>::type
    3273  = 0>
    3274  InteratorType erase(InteratorType pos)
    3275  {
    3276  // make sure iterator fits the current value
    3277  if (this != pos.m_object)
    3278  {
    3279  throw std::domain_error("iterator does not fit current value");
    3280  }
    3281 
    3282  InteratorType result = end();
    3283 
    3284  switch (m_type)
    3285  {
    3286  case value_t::boolean:
    3287  case value_t::number_float:
    3288  case value_t::number_integer:
    3289  case value_t::string:
    3290  {
    3291  if (not pos.m_it.primitive_iterator.is_begin())
    3292  {
    3293  throw std::out_of_range("iterator out of range");
    3294  }
    3295 
    3296  if (is_string())
    3297  {
    3298  delete m_value.string;
    3299  m_value.string = nullptr;
    3300  }
    3301 
    3302  m_type = value_t::null;
    3303  break;
    3304  }
    3305 
    3306  case value_t::object:
    3307  {
    3308  assert(m_value.object != nullptr);
    3309  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3310  break;
    3311  }
    3312 
    3313  case value_t::array:
    3314  {
    3315  assert(m_value.array != nullptr);
    3316  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3317  break;
    3318  }
    3319 
    3320  default:
    3321  {
    3322  throw std::domain_error("cannot use erase() with " + type_name());
    3323  }
    3324  }
    3325 
    3326  return result;
    3327  }
    3328 
    3373  template <class InteratorType, typename
    3374  std::enable_if<
    3375  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3376  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3377  , int>::type
    3378  = 0>
    3379  InteratorType erase(InteratorType first, InteratorType last)
    3380  {
    3381  // make sure iterator fits the current value
    3382  if (this != first.m_object or this != last.m_object)
    3383  {
    3384  throw std::domain_error("iterators do not fit current value");
    3385  }
    3386 
    3387  InteratorType result = end();
    3388 
    3389  switch (m_type)
    3390  {
    3391  case value_t::boolean:
    3392  case value_t::number_float:
    3393  case value_t::number_integer:
    3394  case value_t::string:
    3395  {
    3396  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3397  {
    3398  throw std::out_of_range("iterators out of range");
    3399  }
    3400 
    3401  if (is_string())
    3402  {
    3403  delete m_value.string;
    3404  m_value.string = nullptr;
    3405  }
    3406 
    3407  m_type = value_t::null;
    3408  break;
    3409  }
    3410 
    3411  case value_t::object:
    3412  {
    3413  assert(m_value.object != nullptr);
    3414  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3415  last.m_it.object_iterator);
    3416  break;
    3417  }
    3418 
    3419  case value_t::array:
    3420  {
    3421  assert(m_value.array != nullptr);
    3422  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3423  last.m_it.array_iterator);
    3424  break;
    3425  }
    3426 
    3427  default:
    3428  {
    3429  throw std::domain_error("cannot use erase() with " + type_name());
    3430  }
    3431  }
    3432 
    3433  return result;
    3434  }
    3435 
    3462  size_type erase(const typename object_t::key_type& key)
    3463  {
    3464  // this erase only works for objects
    3465  if (is_object())
    3466  {
    3467  assert(m_value.object != nullptr);
    3468  return m_value.object->erase(key);
    3469  }
    3470  else
    3471  {
    3472  throw std::domain_error("cannot use erase() with " + type_name());
    3473  }
    3474  }
    3475 
    3500  void erase(const size_type idx)
    3501  {
    3502  // this erase only works for arrays
    3503  if (is_array())
    3504  {
    3505  if (idx >= size())
    3506  {
    3507  throw std::out_of_range("index out of range");
    3508  }
    3509 
    3510  assert(m_value.array != nullptr);
    3511  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    3512  }
    3513  else
    3514  {
    3515  throw std::domain_error("cannot use erase() with " + type_name());
    3516  }
    3517  }
    3518 
    3536  iterator find(typename object_t::key_type key)
    3537  {
    3538  auto result = end();
    3539 
    3540  if (is_object())
    3541  {
    3542  assert(m_value.object != nullptr);
    3543  result.m_it.object_iterator = m_value.object->find(key);
    3544  }
    3545 
    3546  return result;
    3547  }
    3548 
    3553  const_iterator find(typename object_t::key_type key) const
    3554  {
    3555  auto result = cend();
    3556 
    3557  if (is_object())
    3558  {
    3559  assert(m_value.object != nullptr);
    3560  result.m_it.object_iterator = m_value.object->find(key);
    3561  }
    3562 
    3563  return result;
    3564  }
    3565 
    3584  size_type count(typename object_t::key_type key) const
    3585  {
    3586  // return 0 for all nonobject types
    3587  assert(not is_object() or m_value.object != nullptr);
    3588  return is_object() ? m_value.object->count(key) : 0;
    3589  }
    3590 
    3592 
    3593 
    3595  // iterators //
    3597 
    3600 
    3620  {
    3621  iterator result(this);
    3622  result.set_begin();
    3623  return result;
    3624  }
    3625 
    3630  {
    3631  return cbegin();
    3632  }
    3633 
    3654  {
    3655  const_iterator result(this);
    3656  result.set_begin();
    3657  return result;
    3658  }
    3659 
    3679  {
    3680  iterator result(this);
    3681  result.set_end();
    3682  return result;
    3683  }
    3684 
    3689  {
    3690  return cend();
    3691  }
    3692 
    3713  {
    3714  const_iterator result(this);
    3715  result.set_end();
    3716  return result;
    3717  }
    3718 
    3737  {
    3738  return reverse_iterator(end());
    3739  }
    3740 
    3745  {
    3746  return crbegin();
    3747  }
    3748 
    3768  {
    3769  return reverse_iterator(begin());
    3770  }
    3771 
    3776  {
    3777  return crend();
    3778  }
    3779 
    3799  {
    3800  return const_reverse_iterator(cend());
    3801  }
    3802 
    3822  {
    3823  return const_reverse_iterator(cbegin());
    3824  }
    3825 
    3826  private:
    3827  // forward declaration
    3828  template<typename IteratorType> class iteration_proxy;
    3829 
    3830  public:
    3842  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    3843  {
    3844  return iteration_proxy<iterator>(cont);
    3845  }
    3846 
    3850  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    3851  {
    3852  return iteration_proxy<const_iterator>(cont);
    3853  }
    3854 
    3856 
    3857 
    3859  // capacity //
    3861 
    3864 
    3894  bool empty() const noexcept
    3895  {
    3896  switch (m_type)
    3897  {
    3898  case value_t::null:
    3899  {
    3900  // null values are empty
    3901  return true;
    3902  }
    3903 
    3904  case value_t::array:
    3905  {
    3906  assert(m_value.array != nullptr);
    3907  return m_value.array->empty();
    3908  }
    3909 
    3910  case value_t::object:
    3911  {
    3912  assert(m_value.object != nullptr);
    3913  return m_value.object->empty();
    3914  }
    3915 
    3916  default:
    3917  {
    3918  // all other types are nonempty
    3919  return false;
    3920  }
    3921  }
    3922  }
    3923 
    3952  size_type size() const noexcept
    3953  {
    3954  switch (m_type)
    3955  {
    3956  case value_t::null:
    3957  {
    3958  // null values are empty
    3959  return 0;
    3960  }
    3961 
    3962  case value_t::array:
    3963  {
    3964  assert(m_value.array != nullptr);
    3965  return m_value.array->size();
    3966  }
    3967 
    3968  case value_t::object:
    3969  {
    3970  assert(m_value.object != nullptr);
    3971  return m_value.object->size();
    3972  }
    3973 
    3974  default:
    3975  {
    3976  // all other types have size 1
    3977  return 1;
    3978  }
    3979  }
    3980  }
    3981 
    4014  size_type max_size() const noexcept
    4015  {
    4016  switch (m_type)
    4017  {
    4018  case value_t::array:
    4019  {
    4020  assert(m_value.array != nullptr);
    4021  return m_value.array->max_size();
    4022  }
    4023 
    4024  case value_t::object:
    4025  {
    4026  assert(m_value.object != nullptr);
    4027  return m_value.object->max_size();
    4028  }
    4029 
    4030  default:
    4031  {
    4032  // all other types have max_size() == size()
    4033  return size();
    4034  }
    4035  }
    4036  }
    4037 
    4039 
    4040 
    4042  // modifiers //
    4044 
    4047 
    4073  void clear() noexcept
    4074  {
    4075  switch (m_type)
    4076  {
    4077  case value_t::number_integer:
    4078  {
    4079  m_value.number_integer = 0;
    4080  break;
    4081  }
    4082 
    4083  case value_t::number_float:
    4084  {
    4085  m_value.number_float = 0.0;
    4086  break;
    4087  }
    4088 
    4089  case value_t::boolean:
    4090  {
    4091  m_value.boolean = false;
    4092  break;
    4093  }
    4094 
    4095  case value_t::string:
    4096  {
    4097  assert(m_value.string != nullptr);
    4098  m_value.string->clear();
    4099  break;
    4100  }
    4101 
    4102  case value_t::array:
    4103  {
    4104  assert(m_value.array != nullptr);
    4105  m_value.array->clear();
    4106  break;
    4107  }
    4108 
    4109  case value_t::object:
    4110  {
    4111  assert(m_value.object != nullptr);
    4112  m_value.object->clear();
    4113  break;
    4114  }
    4115 
    4116  default:
    4117  {
    4118  break;
    4119  }
    4120  }
    4121  }
    4122 
    4143  void push_back(basic_json&& val)
    4144  {
    4145  // push_back only works for null objects or arrays
    4146  if (not(is_null() or is_array()))
    4147  {
    4148  throw std::domain_error("cannot use push_back() with " + type_name());
    4149  }
    4150 
    4151  // transform null object into an array
    4152  if (is_null())
    4153  {
    4154  m_type = value_t::array;
    4155  m_value = value_t::array;
    4156  }
    4157 
    4158  // add element to array (move semantics)
    4159  assert(m_value.array != nullptr);
    4160  m_value.array->push_back(std::move(val));
    4161  // invalidate object
    4162  val.m_type = value_t::null;
    4163  }
    4164 
    4169  reference operator+=(basic_json&& val)
    4170  {
    4171  push_back(std::move(val));
    4172  return *this;
    4173  }
    4174 
    4179  void push_back(const basic_json& val)
    4180  {
    4181  // push_back only works for null objects or arrays
    4182  if (not(is_null() or is_array()))
    4183  {
    4184  throw std::domain_error("cannot use push_back() with " + type_name());
    4185  }
    4186 
    4187  // transform null object into an array
    4188  if (is_null())
    4189  {
    4190  m_type = value_t::array;
    4191  m_value = value_t::array;
    4192  }
    4193 
    4194  // add element to array
    4195  assert(m_value.array != nullptr);
    4196  m_value.array->push_back(val);
    4197  }
    4198 
    4203  reference operator+=(const basic_json& val)
    4204  {
    4205  push_back(val);
    4206  return *this;
    4207  }
    4208 
    4229  void push_back(const typename object_t::value_type& val)
    4230  {
    4231  // push_back only works for null objects or objects
    4232  if (not(is_null() or is_object()))
    4233  {
    4234  throw std::domain_error("cannot use push_back() with " + type_name());
    4235  }
    4236 
    4237  // transform null object into an object
    4238  if (is_null())
    4239  {
    4240  m_type = value_t::object;
    4241  m_value = value_t::object;
    4242  }
    4243 
    4244  // add element to array
    4245  assert(m_value.object != nullptr);
    4246  m_value.object->insert(val);
    4247  }
    4248 
    4253  reference operator+=(const typename object_t::value_type& val)
    4254  {
    4255  push_back(val);
    4256  return operator[](val.first);
    4257  }
    4258 
    4281  iterator insert(const_iterator pos, const basic_json& val)
    4282  {
    4283  // insert only works for arrays
    4284  if (is_array())
    4285  {
    4286  // check if iterator pos fits to this JSON value
    4287  if (pos.m_object != this)
    4288  {
    4289  throw std::domain_error("iterator does not fit current value");
    4290  }
    4291 
    4292  // insert to array and return iterator
    4293  iterator result(this);
    4294  assert(m_value.array != nullptr);
    4295  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4296  return result;
    4297  }
    4298  else
    4299  {
    4300  throw std::domain_error("cannot use insert() with " + type_name());
    4301  }
    4302  }
    4303 
    4308  iterator insert(const_iterator pos, basic_json&& val)
    4309  {
    4310  return insert(pos, val);
    4311  }
    4312 
    4337  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    4338  {
    4339  // insert only works for arrays
    4340  if (is_array())
    4341  {
    4342  // check if iterator pos fits to this JSON value
    4343  if (pos.m_object != this)
    4344  {
    4345  throw std::domain_error("iterator does not fit current value");
    4346  }
    4347 
    4348  // insert to array and return iterator
    4349  iterator result(this);
    4350  assert(m_value.array != nullptr);
    4351  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    4352  return result;
    4353  }
    4354  else
    4355  {
    4356  throw std::domain_error("cannot use insert() with " + type_name());
    4357  }
    4358  }
    4359 
    4391  {
    4392  // insert only works for arrays
    4393  if (not is_array())
    4394  {
    4395  throw std::domain_error("cannot use insert() with " + type_name());
    4396  }
    4397 
    4398  // check if iterator pos fits to this JSON value
    4399  if (pos.m_object != this)
    4400  {
    4401  throw std::domain_error("iterator does not fit current value");
    4402  }
    4403 
    4404  if (first.m_object != last.m_object)
    4405  {
    4406  throw std::domain_error("iterators do not fit");
    4407  }
    4408 
    4409  if (first.m_object == this or last.m_object == this)
    4410  {
    4411  throw std::domain_error("passed iterators may not belong to container");
    4412  }
    4413 
    4414  // insert to array and return iterator
    4415  iterator result(this);
    4416  assert(m_value.array != nullptr);
    4417  result.m_it.array_iterator = m_value.array->insert(
    4418  pos.m_it.array_iterator,
    4419  first.m_it.array_iterator,
    4420  last.m_it.array_iterator);
    4421  return result;
    4422  }
    4423 
    4448  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    4449  {
    4450  // insert only works for arrays
    4451  if (not is_array())
    4452  {
    4453  throw std::domain_error("cannot use insert() with " + type_name());
    4454  }
    4455 
    4456  // check if iterator pos fits to this JSON value
    4457  if (pos.m_object != this)
    4458  {
    4459  throw std::domain_error("iterator does not fit current value");
    4460  }
    4461 
    4462  // insert to array and return iterator
    4463  iterator result(this);
    4464  assert(m_value.array != nullptr);
    4465  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    4466  return result;
    4467  }
    4468 
    4486  void swap(reference other) noexcept (
    4487  std::is_nothrow_move_constructible<value_t>::value and
    4488  std::is_nothrow_move_assignable<value_t>::value and
    4489  std::is_nothrow_move_constructible<json_value>::value and
    4490  std::is_nothrow_move_assignable<json_value>::value
    4491  )
    4492  {
    4493  std::swap(m_type, other.m_type);
    4494  std::swap(m_value, other.m_value);
    4495  }
    4496 
    4517  void swap(array_t& other)
    4518  {
    4519  // swap only works for arrays
    4520  if (is_array())
    4521  {
    4522  assert(m_value.array != nullptr);
    4523  std::swap(*(m_value.array), other);
    4524  }
    4525  else
    4526  {
    4527  throw std::domain_error("cannot use swap() with " + type_name());
    4528  }
    4529  }
    4530 
    4551  void swap(object_t& other)
    4552  {
    4553  // swap only works for objects
    4554  if (is_object())
    4555  {
    4556  assert(m_value.object != nullptr);
    4557  std::swap(*(m_value.object), other);
    4558  }
    4559  else
    4560  {
    4561  throw std::domain_error("cannot use swap() with " + type_name());
    4562  }
    4563  }
    4564 
    4585  void swap(string_t& other)
    4586  {
    4587  // swap only works for strings
    4588  if (is_string())
    4589  {
    4590  assert(m_value.string != nullptr);
    4591  std::swap(*(m_value.string), other);
    4592  }
    4593  else
    4594  {
    4595  throw std::domain_error("cannot use swap() with " + type_name());
    4596  }
    4597  }
    4598 
    4600 
    4601 
    4603  // lexicographical comparison operators //
    4605 
    4608 
    4609  private:
    4619  friend bool operator<(const value_t lhs, const value_t rhs)
    4620  {
    4621  static constexpr std::array<uint8_t, 7> order = {{
    4622  0, // null
    4623  3, // object
    4624  4, // array
    4625  5, // string
    4626  1, // boolean
    4627  2, // integer
    4628  2 // float
    4629  }
    4630  };
    4631 
    4632  // discarded values are not comparable
    4633  if (lhs == value_t::discarded or rhs == value_t::discarded)
    4634  {
    4635  return false;
    4636  }
    4637 
    4638  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    4639  }
    4640 
    4641  public:
    4665  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    4666  {
    4667  const auto lhs_type = lhs.type();
    4668  const auto rhs_type = rhs.type();
    4669 
    4670  if (lhs_type == rhs_type)
    4671  {
    4672  switch (lhs_type)
    4673  {
    4674  case value_t::array:
    4675  {
    4676  assert(lhs.m_value.array != nullptr);
    4677  assert(rhs.m_value.array != nullptr);
    4678  return *lhs.m_value.array == *rhs.m_value.array;
    4679  }
    4680  case value_t::object:
    4681  {
    4682  assert(lhs.m_value.object != nullptr);
    4683  assert(rhs.m_value.object != nullptr);
    4684  return *lhs.m_value.object == *rhs.m_value.object;
    4685  }
    4686  case value_t::null:
    4687  {
    4688  return true;
    4689  }
    4690  case value_t::string:
    4691  {
    4692  assert(lhs.m_value.string != nullptr);
    4693  assert(rhs.m_value.string != nullptr);
    4694  return *lhs.m_value.string == *rhs.m_value.string;
    4695  }
    4696  case value_t::boolean:
    4697  {
    4698  return lhs.m_value.boolean == rhs.m_value.boolean;
    4699  }
    4700  case value_t::number_integer:
    4701  {
    4702  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    4703  }
    4704  case value_t::number_float:
    4705  {
    4706  return approx(lhs.m_value.number_float, rhs.m_value.number_float);
    4707  }
    4708  default:
    4709  {
    4710  return false;
    4711  }
    4712  }
    4713  }
    4714  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    4715  {
    4716  return approx(static_cast<number_float_t>(lhs.m_value.number_integer),
    4717  rhs.m_value.number_float);
    4718  }
    4719  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    4720  {
    4721  return approx(lhs.m_value.number_float,
    4722  static_cast<number_float_t>(rhs.m_value.number_integer));
    4723  }
    4724  return false;
    4725  }
    4726 
    4745  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    4746  {
    4747  return v.is_null();
    4748  }
    4749 
    4754  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    4755  {
    4756  return v.is_null();
    4757  }
    4758 
    4775  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    4776  {
    4777  return not (lhs == rhs);
    4778  }
    4779 
    4798  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    4799  {
    4800  return not v.is_null();
    4801  }
    4802 
    4807  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    4808  {
    4809  return not v.is_null();
    4810  }
    4811 
    4836  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    4837  {
    4838  const auto lhs_type = lhs.type();
    4839  const auto rhs_type = rhs.type();
    4840 
    4841  if (lhs_type == rhs_type)
    4842  {
    4843  switch (lhs_type)
    4844  {
    4845  case value_t::array:
    4846  {
    4847  assert(lhs.m_value.array != nullptr);
    4848  assert(rhs.m_value.array != nullptr);
    4849  return *lhs.m_value.array < *rhs.m_value.array;
    4850  }
    4851  case value_t::object:
    4852  {
    4853  assert(lhs.m_value.object != nullptr);
    4854  assert(rhs.m_value.object != nullptr);
    4855  return *lhs.m_value.object < *rhs.m_value.object;
    4856  }
    4857  case value_t::null:
    4858  {
    4859  return false;
    4860  }
    4861  case value_t::string:
    4862  {
    4863  assert(lhs.m_value.string != nullptr);
    4864  assert(rhs.m_value.string != nullptr);
    4865  return *lhs.m_value.string < *rhs.m_value.string;
    4866  }
    4867  case value_t::boolean:
    4868  {
    4869  return lhs.m_value.boolean < rhs.m_value.boolean;
    4870  }
    4871  case value_t::number_integer:
    4872  {
    4873  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    4874  }
    4875  case value_t::number_float:
    4876  {
    4877  return lhs.m_value.number_float < rhs.m_value.number_float;
    4878  }
    4879  default:
    4880  {
    4881  return false;
    4882  }
    4883  }
    4884  }
    4885  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    4886  {
    4887  return static_cast<number_float_t>(lhs.m_value.number_integer) <
    4888  rhs.m_value.number_float;
    4889  }
    4890  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    4891  {
    4892  return lhs.m_value.number_float <
    4893  static_cast<number_float_t>(rhs.m_value.number_integer);
    4894  }
    4895 
    4896  // We only reach this line if we cannot compare values. In that case,
    4897  // we compare types. Note we have to call the operator explicitly,
    4898  // because MSVC has problems otherwise.
    4899  return operator<(lhs_type, rhs_type);
    4900  }
    4901 
    4919  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    4920  {
    4921  return not (rhs < lhs);
    4922  }
    4923 
    4941  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    4942  {
    4943  return not (lhs <= rhs);
    4944  }
    4945 
    4963  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    4964  {
    4965  return not (lhs < rhs);
    4966  }
    4967 
    4969 
    4970 
    4972  // serialization //
    4974 
    4977 
    5000  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5001  {
    5002  // read width member and use it as indentation parameter if nonzero
    5003  const bool pretty_print = (o.width() > 0);
    5004  const auto indentation = (pretty_print ? o.width() : 0);
    5005 
    5006  // reset width to 0 for subsequent calls to this stream
    5007  o.width(0);
    5008 
    5009  // do the actual serialization
    5010  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5011  return o;
    5012  }
    5013 
    5018  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5019  {
    5020  return o << j;
    5021  }
    5022 
    5024 
    5025 
    5027  // deserialization //
    5029 
    5032 
    5057  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5058  {
    5059  return parser(s, cb).parse();
    5060  }
    5061 
    5086  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5087  {
    5088  return parser(i, cb).parse();
    5089  }
    5090 
    5094  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5095  {
    5096  return parser(i, cb).parse();
    5097  }
    5098 
    5122  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5123  {
    5124  j = parser(i).parse();
    5125  return i;
    5126  }
    5127 
    5132  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5133  {
    5134  j = parser(i).parse();
    5135  return i;
    5136  }
    5137 
    5139 
    5140 
    5141  private:
    5143  // convenience functions //
    5145 
    5147  string_t type_name() const
    5148  {
    5149  switch (m_type)
    5150  {
    5151  case value_t::null:
    5152  return "null";
    5153  case value_t::object:
    5154  return "object";
    5155  case value_t::array:
    5156  return "array";
    5157  case value_t::string:
    5158  return "string";
    5159  case value_t::boolean:
    5160  return "boolean";
    5161  case value_t::discarded:
    5162  return "discarded";
    5163  default:
    5164  return "number";
    5165  }
    5166  }
    5167 
    5176  static std::size_t extra_space(const string_t& s) noexcept
    5177  {
    5178  std::size_t result = 0;
    5179 
    5180  for (const auto& c : s)
    5181  {
    5182  switch (c)
    5183  {
    5184  case '"':
    5185  case '\\':
    5186  case '\b':
    5187  case '\f':
    5188  case '\n':
    5189  case '\r':
    5190  case '\t':
    5191  {
    5192  // from c (1 byte) to \x (2 bytes)
    5193  result += 1;
    5194  break;
    5195  }
    5196 
    5197  default:
    5198  {
    5199  if (c >= 0x00 and c <= 0x1f)
    5200  {
    5201  // from c (1 byte) to \uxxxx (6 bytes)
    5202  result += 5;
    5203  }
    5204  break;
    5205  }
    5206  }
    5207  }
    5208 
    5209  return result;
    5210  }
    5211 
    5225  static string_t escape_string(const string_t& s) noexcept
    5226  {
    5227  const auto space = extra_space(s);
    5228  if (space == 0)
    5229  {
    5230  return s;
    5231  }
    5232 
    5233  // create a result string of necessary size
    5234  string_t result(s.size() + space, '\\');
    5235  std::size_t pos = 0;
    5236 
    5237  for (const auto& c : s)
    5238  {
    5239  switch (c)
    5240  {
    5241  // quotation mark (0x22)
    5242  case '"':
    5243  {
    5244  result[pos + 1] = '"';
    5245  pos += 2;
    5246  break;
    5247  }
    5248 
    5249  // reverse solidus (0x5c)
    5250  case '\\':
    5251  {
    5252  // nothing to change
    5253  pos += 2;
    5254  break;
    5255  }
    5256 
    5257  // backspace (0x08)
    5258  case '\b':
    5259  {
    5260  result[pos + 1] = 'b';
    5261  pos += 2;
    5262  break;
    5263  }
    5264 
    5265  // formfeed (0x0c)
    5266  case '\f':
    5267  {
    5268  result[pos + 1] = 'f';
    5269  pos += 2;
    5270  break;
    5271  }
    5272 
    5273  // newline (0x0a)
    5274  case '\n':
    5275  {
    5276  result[pos + 1] = 'n';
    5277  pos += 2;
    5278  break;
    5279  }
    5280 
    5281  // carriage return (0x0d)
    5282  case '\r':
    5283  {
    5284  result[pos + 1] = 'r';
    5285  pos += 2;
    5286  break;
    5287  }
    5288 
    5289  // horizontal tab (0x09)
    5290  case '\t':
    5291  {
    5292  result[pos + 1] = 't';
    5293  pos += 2;
    5294  break;
    5295  }
    5296 
    5297  default:
    5298  {
    5299  if (c >= 0x00 and c <= 0x1f)
    5300  {
    5301  // convert a number 0..15 to its hex representation (0..f)
    5302  auto hexify = [](const char v) -> char
    5303  {
    5304  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    5305  };
    5306 
    5307  // print character c as \uxxxx
    5308  for (const char m :
    5309  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    5310  })
    5311  {
    5312  result[++pos] = m;
    5313  }
    5314 
    5315  ++pos;
    5316  }
    5317  else
    5318  {
    5319  // all other characters are added as-is
    5320  result[pos++] = c;
    5321  }
    5322  break;
    5323  }
    5324  }
    5325  }
    5326 
    5327  return result;
    5328  }
    5329 
    5347  void dump(std::ostream& o,
    5348  const bool pretty_print,
    5349  const unsigned int indent_step,
    5350  const unsigned int current_indent = 0) const
    5351  {
    5352  // variable to hold indentation for recursive calls
    5353  unsigned int new_indent = current_indent;
    5354 
    5355  switch (m_type)
    5356  {
    5357  case value_t::object:
    5358  {
    5359  assert(m_value.object != nullptr);
    5360 
    5361  if (m_value.object->empty())
    5362  {
    5363  o << "{}";
    5364  return;
    5365  }
    5366 
    5367  o << "{";
    5368 
    5369  // increase indentation
    5370  if (pretty_print)
    5371  {
    5372  new_indent += indent_step;
    5373  o << "\n";
    5374  }
    5375 
    5376  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    5377  {
    5378  if (i != m_value.object->cbegin())
    5379  {
    5380  o << (pretty_print ? ",\n" : ",");
    5381  }
    5382  o << string_t(new_indent, ' ') << "\""
    5383  << escape_string(i->first) << "\":"
    5384  << (pretty_print ? " " : "");
    5385  i->second.dump(o, pretty_print, indent_step, new_indent);
    5386  }
    5387 
    5388  // decrease indentation
    5389  if (pretty_print)
    5390  {
    5391  new_indent -= indent_step;
    5392  o << "\n";
    5393  }
    5394 
    5395  o << string_t(new_indent, ' ') + "}";
    5396  return;
    5397  }
    5398 
    5399  case value_t::array:
    5400  {
    5401  assert(m_value.array != nullptr);
    5402 
    5403  if (m_value.array->empty())
    5404  {
    5405  o << "[]";
    5406  return;
    5407  }
    5408 
    5409  o << "[";
    5410 
    5411  // increase indentation
    5412  if (pretty_print)
    5413  {
    5414  new_indent += indent_step;
    5415  o << "\n";
    5416  }
    5417 
    5418  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    5419  {
    5420  if (i != m_value.array->cbegin())
    5421  {
    5422  o << (pretty_print ? ",\n" : ",");
    5423  }
    5424  o << string_t(new_indent, ' ');
    5425  i->dump(o, pretty_print, indent_step, new_indent);
    5426  }
    5427 
    5428  // decrease indentation
    5429  if (pretty_print)
    5430  {
    5431  new_indent -= indent_step;
    5432  o << "\n";
    5433  }
    5434 
    5435  o << string_t(new_indent, ' ') << "]";
    5436  return;
    5437  }
    5438 
    5439  case value_t::string:
    5440  {
    5441  assert(m_value.string != nullptr);
    5442  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    5443  return;
    5444  }
    5445 
    5446  case value_t::boolean:
    5447  {
    5448  o << (m_value.boolean ? "true" : "false");
    5449  return;
    5450  }
    5451 
    5452  case value_t::number_integer:
    5453  {
    5454  o << m_value.number_integer;
    5455  return;
    5456  }
    5457 
    5458  case value_t::number_float:
    5459  {
    5460  // 15 digits of precision allows round-trip IEEE 754
    5461  // string->double->string; to be safe, we read this value from
    5462  // std::numeric_limits<number_float_t>::digits10
    5463  o << std::setprecision(std::numeric_limits<number_float_t>::digits10) << m_value.number_float;
    5464  return;
    5465  }
    5466 
    5467  case value_t::discarded:
    5468  {
    5469  o << "<discarded>";
    5470  return;
    5471  }
    5472 
    5473  case value_t::null:
    5474  {
    5475  o << "null";
    5476  return;
    5477  }
    5478  }
    5479  }
    5480 
    5481  private:
    5483  // member variables //
    5485 
    5487  value_t m_type = value_t::null;
    5488 
    5490  json_value m_value = {};
    5491 
    5492 
    5493  private:
    5495  // iterators //
    5497 
    5507  class primitive_iterator_t
    5508  {
    5509  public:
    5511  void set_begin()
    5512  {
    5513  m_it = begin_value;
    5514  }
    5515 
    5517  void set_end()
    5518  {
    5519  m_it = end_value;
    5520  }
    5521 
    5523  bool is_begin() const
    5524  {
    5525  return (m_it == begin_value);
    5526  }
    5527 
    5529  bool is_end() const
    5530  {
    5531  return (m_it == end_value);
    5532  }
    5533 
    5535  operator difference_type& ()
    5536  {
    5537  return m_it;
    5538  }
    5539 
    5541  operator difference_type () const
    5542  {
    5543  return m_it;
    5544  }
    5545 
    5546  private:
    5547  static constexpr difference_type begin_value = 0;
    5548  static constexpr difference_type end_value = begin_value + 1;
    5549 
    5551  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    5552  };
    5553 
    5561  struct internal_iterator
    5562  {
    5564  typename object_t::iterator object_iterator;
    5566  typename array_t::iterator array_iterator;
    5568  primitive_iterator_t primitive_iterator;
    5569 
    5571  internal_iterator()
    5572  : object_iterator(), array_iterator(), primitive_iterator()
    5573  {}
    5574  };
    5575 
    5577  template<typename IteratorType>
    5578  class iteration_proxy
    5579  {
    5580  private:
    5582  class iteration_proxy_internal
    5583  {
    5584  private:
    5586  IteratorType anchor;
    5588  size_t array_index = 0;
    5589 
    5590  public:
    5591  iteration_proxy_internal(IteratorType it)
    5592  : anchor(it)
    5593  {}
    5594 
    5596  iteration_proxy_internal& operator*()
    5597  {
    5598  return *this;
    5599  }
    5600 
    5602  iteration_proxy_internal& operator++()
    5603  {
    5604  ++anchor;
    5605  ++array_index;
    5606 
    5607  return *this;
    5608  }
    5609 
    5611  bool operator!= (const iteration_proxy_internal& o) const
    5612  {
    5613  return anchor != o.anchor;
    5614  }
    5615 
    5617  typename basic_json::string_t key() const
    5618  {
    5619  assert(anchor.m_object != nullptr);
    5620 
    5621  switch (anchor.m_object->type())
    5622  {
    5623  // use integer array index as key
    5624  case value_t::array:
    5625  {
    5626  return std::to_string(array_index);
    5627  }
    5628 
    5629  // use key from the object
    5630  case value_t::object:
    5631  {
    5632  return anchor.key();
    5633  }
    5634 
    5635  // use an empty key for all primitive types
    5636  default:
    5637  {
    5638  return "";
    5639  }
    5640  }
    5641  }
    5642 
    5644  typename IteratorType::reference value() const
    5645  {
    5646  return anchor.value();
    5647  }
    5648  };
    5649 
    5651  typename IteratorType::reference container;
    5652 
    5653  public:
    5655  iteration_proxy(typename IteratorType::reference cont)
    5656  : container(cont)
    5657  {}
    5658 
    5660  iteration_proxy_internal begin()
    5661  {
    5662  return iteration_proxy_internal(container.begin());
    5663  }
    5664 
    5666  iteration_proxy_internal end()
    5667  {
    5668  return iteration_proxy_internal(container.end());
    5669  }
    5670  };
    5671 
    5672  public:
    5686  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    5687  {
    5689  friend class basic_json;
    5690 
    5691  public:
    5701  using iterator_category = std::bidirectional_iterator_tag;
    5702 
    5704  const_iterator() = default;
    5705 
    5707  const_iterator(pointer object) : m_object(object)
    5708  {
    5709  assert(m_object != nullptr);
    5710 
    5711  switch (m_object->m_type)
    5712  {
    5714  {
    5715  m_it.object_iterator = typename object_t::iterator();
    5716  break;
    5717  }
    5718 
    5720  {
    5721  m_it.array_iterator = typename array_t::iterator();
    5722  break;
    5723  }
    5724 
    5725  default:
    5726  {
    5727  m_it.primitive_iterator = primitive_iterator_t();
    5728  break;
    5729  }
    5730  }
    5731  }
    5732 
    5734  const_iterator(const iterator& other) : m_object(other.m_object)
    5735  {
    5736  assert(m_object != nullptr);
    5737 
    5738  switch (m_object->m_type)
    5739  {
    5741  {
    5742  m_it.object_iterator = other.m_it.object_iterator;
    5743  break;
    5744  }
    5745 
    5747  {
    5748  m_it.array_iterator = other.m_it.array_iterator;
    5749  break;
    5750  }
    5751 
    5752  default:
    5753  {
    5754  m_it.primitive_iterator = other.m_it.primitive_iterator;
    5755  break;
    5756  }
    5757  }
    5758  }
    5759 
    5761  const_iterator(const const_iterator& other) noexcept
    5762  : m_object(other.m_object), m_it(other.m_it)
    5763  {}
    5764 
    5767  std::is_nothrow_move_constructible<pointer>::value and
    5768  std::is_nothrow_move_assignable<pointer>::value and
    5769  std::is_nothrow_move_constructible<internal_iterator>::value and
    5770  std::is_nothrow_move_assignable<internal_iterator>::value
    5771  )
    5772  {
    5773  std::swap(m_object, other.m_object);
    5774  std::swap(m_it, other.m_it);
    5775  return *this;
    5776  }
    5777 
    5778  private:
    5780  void set_begin()
    5781  {
    5782  assert(m_object != nullptr);
    5783 
    5784  switch (m_object->m_type)
    5785  {
    5787  {
    5788  assert(m_object->m_value.object != nullptr);
    5789  m_it.object_iterator = m_object->m_value.object->begin();
    5790  break;
    5791  }
    5792 
    5794  {
    5795  assert(m_object->m_value.array != nullptr);
    5796  m_it.array_iterator = m_object->m_value.array->begin();
    5797  break;
    5798  }
    5799 
    5801  {
    5802  // set to end so begin()==end() is true: null is empty
    5803  m_it.primitive_iterator.set_end();
    5804  break;
    5805  }
    5806 
    5807  default:
    5808  {
    5809  m_it.primitive_iterator.set_begin();
    5810  break;
    5811  }
    5812  }
    5813  }
    5814 
    5816  void set_end()
    5817  {
    5818  assert(m_object != nullptr);
    5819 
    5820  switch (m_object->m_type)
    5821  {
    5823  {
    5824  assert(m_object->m_value.object != nullptr);
    5825  m_it.object_iterator = m_object->m_value.object->end();
    5826  break;
    5827  }
    5828 
    5830  {
    5831  assert(m_object->m_value.array != nullptr);
    5832  m_it.array_iterator = m_object->m_value.array->end();
    5833  break;
    5834  }
    5835 
    5836  default:
    5837  {
    5838  m_it.primitive_iterator.set_end();
    5839  break;
    5840  }
    5841  }
    5842  }
    5843 
    5844  public:
    5847  {
    5848  assert(m_object != nullptr);
    5849 
    5850  switch (m_object->m_type)
    5851  {
    5853  {
    5854  assert(m_object->m_value.object);
    5855  assert(m_it.object_iterator != m_object->m_value.object->end());
    5856  return m_it.object_iterator->second;
    5857  }
    5858 
    5860  {
    5861  assert(m_object->m_value.array);
    5862  assert(m_it.array_iterator != m_object->m_value.array->end());
    5863  return *m_it.array_iterator;
    5864  }
    5865 
    5867  {
    5868  throw std::out_of_range("cannot get value");
    5869  }
    5870 
    5871  default:
    5872  {
    5873  if (m_it.primitive_iterator.is_begin())
    5874  {
    5875  return *m_object;
    5876  }
    5877  else
    5878  {
    5879  throw std::out_of_range("cannot get value");
    5880  }
    5881  }
    5882  }
    5883  }
    5884 
    5887  {
    5888  assert(m_object != nullptr);
    5889 
    5890  switch (m_object->m_type)
    5891  {
    5893  {
    5894  assert(m_object->m_value.object);
    5895  assert(m_it.object_iterator != m_object->m_value.object->end());
    5896  return &(m_it.object_iterator->second);
    5897  }
    5898 
    5900  {
    5901  assert(m_object->m_value.array);
    5902  assert(m_it.array_iterator != m_object->m_value.array->end());
    5903  return &*m_it.array_iterator;
    5904  }
    5905 
    5906  default:
    5907  {
    5908  if (m_it.primitive_iterator.is_begin())
    5909  {
    5910  return m_object;
    5911  }
    5912  else
    5913  {
    5914  throw std::out_of_range("cannot get value");
    5915  }
    5916  }
    5917  }
    5918  }
    5919 
    5922  {
    5923  auto result = *this;
    5924  ++(*this);
    5925  return result;
    5926  }
    5927 
    5930  {
    5931  assert(m_object != nullptr);
    5932 
    5933  switch (m_object->m_type)
    5934  {
    5936  {
    5937  ++m_it.object_iterator;
    5938  break;
    5939  }
    5940 
    5942  {
    5943  ++m_it.array_iterator;
    5944  break;
    5945  }
    5946 
    5947  default:
    5948  {
    5949  ++m_it.primitive_iterator;
    5950  break;
    5951  }
    5952  }
    5953 
    5954  return *this;
    5955  }
    5956 
    5959  {
    5960  auto result = *this;
    5961  --(*this);
    5962  return result;
    5963  }
    5964 
    5967  {
    5968  assert(m_object != nullptr);
    5969 
    5970  switch (m_object->m_type)
    5971  {
    5973  {
    5974  --m_it.object_iterator;
    5975  break;
    5976  }
    5977 
    5979  {
    5980  --m_it.array_iterator;
    5981  break;
    5982  }
    5983 
    5984  default:
    5985  {
    5986  --m_it.primitive_iterator;
    5987  break;
    5988  }
    5989  }
    5990 
    5991  return *this;
    5992  }
    5993 
    5995  bool operator==(const const_iterator& other) const
    5996  {
    5997  // if objects are not the same, the comparison is undefined
    5998  if (m_object != other.m_object)
    5999  {
    6000  throw std::domain_error("cannot compare iterators of different containers");
    6001  }
    6002 
    6003  assert(m_object != nullptr);
    6004 
    6005  switch (m_object->m_type)
    6006  {
    6008  {
    6009  return (m_it.object_iterator == other.m_it.object_iterator);
    6010  }
    6011 
    6013  {
    6014  return (m_it.array_iterator == other.m_it.array_iterator);
    6015  }
    6016 
    6017  default:
    6018  {
    6019  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6020  }
    6021  }
    6022  }
    6023 
    6025  bool operator!=(const const_iterator& other) const
    6026  {
    6027  return not operator==(other);
    6028  }
    6029 
    6031  bool operator<(const const_iterator& other) const
    6032  {
    6033  // if objects are not the same, the comparison is undefined
    6034  if (m_object != other.m_object)
    6035  {
    6036  throw std::domain_error("cannot compare iterators of different containers");
    6037  }
    6038 
    6039  assert(m_object != nullptr);
    6040 
    6041  switch (m_object->m_type)
    6042  {
    6044  {
    6045  throw std::domain_error("cannot compare order of object iterators");
    6046  }
    6047 
    6049  {
    6050  return (m_it.array_iterator < other.m_it.array_iterator);
    6051  }
    6052 
    6053  default:
    6054  {
    6055  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6056  }
    6057  }
    6058  }
    6059 
    6061  bool operator<=(const const_iterator& other) const
    6062  {
    6063  return not other.operator < (*this);
    6064  }
    6065 
    6067  bool operator>(const const_iterator& other) const
    6068  {
    6069  return not operator<=(other);
    6070  }
    6071 
    6073  bool operator>=(const const_iterator& other) const
    6074  {
    6075  return not operator<(other);
    6076  }
    6077 
    6080  {
    6081  assert(m_object != nullptr);
    6082 
    6083  switch (m_object->m_type)
    6084  {
    6086  {
    6087  throw std::domain_error("cannot use offsets with object iterators");
    6088  }
    6089 
    6091  {
    6092  m_it.array_iterator += i;
    6093  break;
    6094  }
    6095 
    6096  default:
    6097  {
    6098  m_it.primitive_iterator += i;
    6099  break;
    6100  }
    6101  }
    6102 
    6103  return *this;
    6104  }
    6105 
    6108  {
    6109  return operator+=(-i);
    6110  }
    6111 
    6114  {
    6115  auto result = *this;
    6116  result += i;
    6117  return result;
    6118  }
    6119 
    6122  {
    6123  auto result = *this;
    6124  result -= i;
    6125  return result;
    6126  }
    6127 
    6130  {
    6131  assert(m_object != nullptr);
    6132 
    6133  switch (m_object->m_type)
    6134  {
    6136  {
    6137  throw std::domain_error("cannot use offsets with object iterators");
    6138  }
    6139 
    6141  {
    6142  return m_it.array_iterator - other.m_it.array_iterator;
    6143  }
    6144 
    6145  default:
    6146  {
    6147  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6148  }
    6149  }
    6150  }
    6151 
    6154  {
    6155  assert(m_object != nullptr);
    6156 
    6157  switch (m_object->m_type)
    6158  {
    6160  {
    6161  throw std::domain_error("cannot use operator[] for object iterators");
    6162  }
    6163 
    6165  {
    6166  return *(m_it.array_iterator + n);
    6167  }
    6168 
    6170  {
    6171  throw std::out_of_range("cannot get value");
    6172  }
    6173 
    6174  default:
    6175  {
    6176  if (m_it.primitive_iterator == -n)
    6177  {
    6178  return *m_object;
    6179  }
    6180  else
    6181  {
    6182  throw std::out_of_range("cannot get value");
    6183  }
    6184  }
    6185  }
    6186  }
    6187 
    6189  typename object_t::key_type key() const
    6190  {
    6191  assert(m_object != nullptr);
    6192 
    6193  if (m_object->is_object())
    6194  {
    6195  return m_it.object_iterator->first;
    6196  }
    6197  else
    6198  {
    6199  throw std::domain_error("cannot use key() for non-object iterators");
    6200  }
    6201  }
    6202 
    6205  {
    6206  return operator*();
    6207  }
    6208 
    6209  private:
    6211  pointer m_object = nullptr;
    6213  internal_iterator m_it = internal_iterator();
    6214  };
    6215 
    6228  class iterator : public const_iterator
    6229  {
    6230  public:
    6232  using pointer = typename basic_json::pointer;
    6234 
    6236  iterator() = default;
    6237 
    6239  iterator(pointer object) noexcept
    6240  : base_iterator(object)
    6241  {}
    6242 
    6244  iterator(const iterator& other) noexcept
    6245  : base_iterator(other)
    6246  {}
    6247 
    6249  iterator& operator=(iterator other) noexcept(
    6250  std::is_nothrow_move_constructible<pointer>::value and
    6251  std::is_nothrow_move_assignable<pointer>::value and
    6252  std::is_nothrow_move_constructible<internal_iterator>::value and
    6253  std::is_nothrow_move_assignable<internal_iterator>::value
    6254  )
    6255  {
    6256  base_iterator::operator=(other);
    6257  return *this;
    6258  }
    6259 
    6262  {
    6263  return const_cast<reference>(base_iterator::operator*());
    6264  }
    6265 
    6268  {
    6269  return const_cast<pointer>(base_iterator::operator->());
    6270  }
    6271 
    6274  {
    6275  iterator result = *this;
    6276  base_iterator::operator++();
    6277  return result;
    6278  }
    6279 
    6282  {
    6283  base_iterator::operator++();
    6284  return *this;
    6285  }
    6286 
    6289  {
    6290  iterator result = *this;
    6291  base_iterator::operator--();
    6292  return result;
    6293  }
    6294 
    6297  {
    6298  base_iterator::operator--();
    6299  return *this;
    6300  }
    6301 
    6304  {
    6305  base_iterator::operator+=(i);
    6306  return *this;
    6307  }
    6308 
    6311  {
    6312  base_iterator::operator-=(i);
    6313  return *this;
    6314  }
    6315 
    6318  {
    6319  auto result = *this;
    6320  result += i;
    6321  return result;
    6322  }
    6323 
    6326  {
    6327  auto result = *this;
    6328  result -= i;
    6329  return result;
    6330  }
    6331 
    6332  difference_type operator-(const iterator& other) const
    6333  {
    6334  return base_iterator::operator-(other);
    6335  }
    6336 
    6339  {
    6340  return const_cast<reference>(base_iterator::operator[](n));
    6341  }
    6342 
    6345  {
    6346  return const_cast<reference>(base_iterator::value());
    6347  }
    6348  };
    6349 
    6367  template<typename Base>
    6368  class json_reverse_iterator : public std::reverse_iterator<Base>
    6369  {
    6370  public:
    6372  using base_iterator = std::reverse_iterator<Base>;
    6374  using reference = typename Base::reference;
    6375 
    6377  json_reverse_iterator(const typename base_iterator::iterator_type& it)
    6378  : base_iterator(it)
    6379  {}
    6380 
    6383  : base_iterator(it)
    6384  {}
    6385 
    6388  {
    6389  return base_iterator::operator++(1);
    6390  }
    6391 
    6394  {
    6395  base_iterator::operator++();
    6396  return *this;
    6397  }
    6398 
    6401  {
    6402  return base_iterator::operator--(1);
    6403  }
    6404 
    6407  {
    6408  base_iterator::operator--();
    6409  return *this;
    6410  }
    6411 
    6414  {
    6415  base_iterator::operator+=(i);
    6416  return *this;
    6417  }
    6418 
    6421  {
    6422  auto result = *this;
    6423  result += i;
    6424  return result;
    6425  }
    6426 
    6429  {
    6430  auto result = *this;
    6431  result -= i;
    6432  return result;
    6433  }
    6434 
    6437  {
    6438  return this->base() - other.base();
    6439  }
    6440 
    6443  {
    6444  return *(this->operator+(n));
    6445  }
    6446 
    6448  typename object_t::key_type key() const
    6449  {
    6450  auto it = --this->base();
    6451  return it.key();
    6452  }
    6453 
    6456  {
    6457  auto it = --this->base();
    6458  return it.operator * ();
    6459  }
    6460  };
    6461 
    6462 
    6463  private:
    6465  // lexer and parser //
    6467 
    6475  class lexer
    6476  {
    6477  public:
    6479  enum class token_type
    6480  {
    6481  uninitialized,
    6482  literal_true,
    6483  literal_false,
    6484  literal_null,
    6485  value_string,
    6486  value_number,
    6487  begin_array,
    6488  begin_object,
    6489  end_array,
    6490  end_object,
    6491  name_separator,
    6492  value_separator,
    6493  parse_error,
    6494  end_of_input
    6495  };
    6496 
    6498  using lexer_char_t = unsigned char;
    6499 
    6501  explicit lexer(const string_t& s) noexcept
    6502  : m_stream(nullptr), m_buffer(s)
    6503  {
    6504  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    6505  assert(m_content != nullptr);
    6506  m_start = m_cursor = m_content;
    6507  m_limit = m_content + s.size();
    6508  }
    6509 
    6511  explicit lexer(std::istream* s) noexcept
    6512  : m_stream(s), m_buffer()
    6513  {
    6514  assert(m_stream != nullptr);
    6515  getline(*m_stream, m_buffer);
    6516  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    6517  assert(m_content != nullptr);
    6518  m_start = m_cursor = m_content;
    6519  m_limit = m_content + m_buffer.size();
    6520  }
    6521 
    6523  lexer() = default;
    6524 
    6525  // switch off unwanted functions
    6526  lexer(const lexer&) = delete;
    6527  lexer operator=(const lexer&) = delete;
    6528 
    6544  static string_t to_unicode(const std::size_t codepoint1,
    6545  const std::size_t codepoint2 = 0)
    6546  {
    6547  string_t result;
    6548 
    6549  // calculate the codepoint from the given code points
    6550  std::size_t codepoint = codepoint1;
    6551 
    6552  // check if codepoint1 is a high surrogate
    6553  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    6554  {
    6555  // check if codepoint2 is a low surrogate
    6556  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    6557  {
    6558  codepoint =
    6559  // high surrogate occupies the most significant 22 bits
    6560  (codepoint1 << 10)
    6561  // low surrogate occupies the least significant 15 bits
    6562  + codepoint2
    6563  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    6564  // in the result so we have to subtract with:
    6565  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    6566  - 0x35FDC00;
    6567  }
    6568  else
    6569  {
    6570  throw std::invalid_argument("missing or wrong low surrogate");
    6571  }
    6572  }
    6573 
    6574  if (codepoint < 0x80)
    6575  {
    6576  // 1-byte characters: 0xxxxxxx (ASCII)
    6577  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    6578  }
    6579  else if (codepoint <= 0x7ff)
    6580  {
    6581  // 2-byte characters: 110xxxxx 10xxxxxx
    6582  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    6583  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6584  }
    6585  else if (codepoint <= 0xffff)
    6586  {
    6587  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    6588  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    6589  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    6590  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6591  }
    6592  else if (codepoint <= 0x10ffff)
    6593  {
    6594  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    6595  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    6596  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    6597  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    6598  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6599  }
    6600  else
    6601  {
    6602  throw std::out_of_range("code points above 0x10FFFF are invalid");
    6603  }
    6604 
    6605  return result;
    6606  }
    6607 
    6609  static std::string token_type_name(token_type t)
    6610  {
    6611  switch (t)
    6612  {
    6613  case token_type::uninitialized:
    6614  return "<uninitialized>";
    6615  case token_type::literal_true:
    6616  return "true literal";
    6617  case token_type::literal_false:
    6618  return "false literal";
    6619  case token_type::literal_null:
    6620  return "null literal";
    6621  case token_type::value_string:
    6622  return "string literal";
    6623  case token_type::value_number:
    6624  return "number literal";
    6625  case token_type::begin_array:
    6626  return "'['";
    6627  case token_type::begin_object:
    6628  return "'{'";
    6629  case token_type::end_array:
    6630  return "']'";
    6631  case token_type::end_object:
    6632  return "'}'";
    6633  case token_type::name_separator:
    6634  return "':'";
    6635  case token_type::value_separator:
    6636  return "','";
    6637  case token_type::parse_error:
    6638  return "<parse error>";
    6639  case token_type::end_of_input:
    6640  return "end of input";
    6641  default:
    6642  {
    6643  // catch non-enum values
    6644  return "unknown token"; // LCOV_EXCL_LINE
    6645  }
    6646  }
    6647  }
    6648 
    6659  token_type scan() noexcept
    6660  {
    6661  // pointer for backtracking information
    6662  m_marker = nullptr;
    6663 
    6664  // remember the begin of the token
    6665  m_start = m_cursor;
    6666  assert(m_start != nullptr);
    6667 
    6668 
    6669  {
    6670  lexer_char_t yych;
    6671  unsigned int yyaccept = 0;
    6672  static const unsigned char yybm[] =
    6673  {
    6674  0, 0, 0, 0, 0, 0, 0, 0,
    6675  0, 32, 32, 0, 0, 32, 0, 0,
    6676  64, 64, 64, 64, 64, 64, 64, 64,
    6677  64, 64, 64, 64, 64, 64, 64, 64,
    6678  96, 64, 0, 64, 64, 64, 64, 64,
    6679  64, 64, 64, 64, 64, 64, 64, 64,
    6680  192, 192, 192, 192, 192, 192, 192, 192,
    6681  192, 192, 64, 64, 64, 64, 64, 64,
    6682  64, 64, 64, 64, 64, 64, 64, 64,
    6683  64, 64, 64, 64, 64, 64, 64, 64,
    6684  64, 64, 64, 64, 64, 64, 64, 64,
    6685  64, 64, 64, 64, 0, 64, 64, 64,
    6686  64, 64, 64, 64, 64, 64, 64, 64,
    6687  64, 64, 64, 64, 64, 64, 64, 64,
    6688  64, 64, 64, 64, 64, 64, 64, 64,
    6689  64, 64, 64, 64, 64, 64, 64, 64,
    6690  64, 64, 64, 64, 64, 64, 64, 64,
    6691  64, 64, 64, 64, 64, 64, 64, 64,
    6692  64, 64, 64, 64, 64, 64, 64, 64,
    6693  64, 64, 64, 64, 64, 64, 64, 64,
    6694  64, 64, 64, 64, 64, 64, 64, 64,
    6695  64, 64, 64, 64, 64, 64, 64, 64,
    6696  64, 64, 64, 64, 64, 64, 64, 64,
    6697  64, 64, 64, 64, 64, 64, 64, 64,
    6698  64, 64, 64, 64, 64, 64, 64, 64,
    6699  64, 64, 64, 64, 64, 64, 64, 64,
    6700  64, 64, 64, 64, 64, 64, 64, 64,
    6701  64, 64, 64, 64, 64, 64, 64, 64,
    6702  64, 64, 64, 64, 64, 64, 64, 64,
    6703  64, 64, 64, 64, 64, 64, 64, 64,
    6704  64, 64, 64, 64, 64, 64, 64, 64,
    6705  64, 64, 64, 64, 64, 64, 64, 64,
    6706  };
    6707  if ((m_limit - m_cursor) < 5)
    6708  {
    6709  yyfill(); // LCOV_EXCL_LINE;
    6710  }
    6711  yych = *m_cursor;
    6712  if (yych <= ':')
    6713  {
    6714  if (yych <= ' ')
    6715  {
    6716  if (yych <= '\n')
    6717  {
    6718  if (yych <= 0x00)
    6719  {
    6720  goto basic_json_parser_28;
    6721  }
    6722  if (yych <= 0x08)
    6723  {
    6724  goto basic_json_parser_30;
    6725  }
    6726  if (yych >= '\n')
    6727  {
    6728  goto basic_json_parser_4;
    6729  }
    6730  }
    6731  else
    6732  {
    6733  if (yych == '\r')
    6734  {
    6735  goto basic_json_parser_2;
    6736  }
    6737  if (yych <= 0x1F)
    6738  {
    6739  goto basic_json_parser_30;
    6740  }
    6741  }
    6742  }
    6743  else
    6744  {
    6745  if (yych <= ',')
    6746  {
    6747  if (yych == '"')
    6748  {
    6749  goto basic_json_parser_27;
    6750  }
    6751  if (yych <= '+')
    6752  {
    6753  goto basic_json_parser_30;
    6754  }
    6755  goto basic_json_parser_16;
    6756  }
    6757  else
    6758  {
    6759  if (yych <= '/')
    6760  {
    6761  if (yych <= '-')
    6762  {
    6763  goto basic_json_parser_23;
    6764  }
    6765  goto basic_json_parser_30;
    6766  }
    6767  else
    6768  {
    6769  if (yych <= '0')
    6770  {
    6771  goto basic_json_parser_24;
    6772  }
    6773  if (yych <= '9')
    6774  {
    6775  goto basic_json_parser_26;
    6776  }
    6777  goto basic_json_parser_18;
    6778  }
    6779  }
    6780  }
    6781  }
    6782  else
    6783  {
    6784  if (yych <= 'n')
    6785  {
    6786  if (yych <= ']')
    6787  {
    6788  if (yych == '[')
    6789  {
    6790  goto basic_json_parser_8;
    6791  }
    6792  if (yych <= '\\')
    6793  {
    6794  goto basic_json_parser_30;
    6795  }
    6796  goto basic_json_parser_10;
    6797  }
    6798  else
    6799  {
    6800  if (yych == 'f')
    6801  {
    6802  goto basic_json_parser_22;
    6803  }
    6804  if (yych <= 'm')
    6805  {
    6806  goto basic_json_parser_30;
    6807  }
    6808  goto basic_json_parser_20;
    6809  }
    6810  }
    6811  else
    6812  {
    6813  if (yych <= '{')
    6814  {
    6815  if (yych == 't')
    6816  {
    6817  goto basic_json_parser_21;
    6818  }
    6819  if (yych <= 'z')
    6820  {
    6821  goto basic_json_parser_30;
    6822  }
    6823  goto basic_json_parser_12;
    6824  }
    6825  else
    6826  {
    6827  if (yych <= '}')
    6828  {
    6829  if (yych <= '|')
    6830  {
    6831  goto basic_json_parser_30;
    6832  }
    6833  goto basic_json_parser_14;
    6834  }
    6835  else
    6836  {
    6837  if (yych == 0xEF)
    6838  {
    6839  goto basic_json_parser_6;
    6840  }
    6841  goto basic_json_parser_30;
    6842  }
    6843  }
    6844  }
    6845  }
    6846 basic_json_parser_2:
    6847  ++m_cursor;
    6848  yych = *m_cursor;
    6849  goto basic_json_parser_5;
    6850 basic_json_parser_3:
    6851  {
    6852  return scan();
    6853  }
    6854 basic_json_parser_4:
    6855  ++m_cursor;
    6856  if (m_limit <= m_cursor)
    6857  {
    6858  yyfill(); // LCOV_EXCL_LINE;
    6859  }
    6860  yych = *m_cursor;
    6861 basic_json_parser_5:
    6862  if (yybm[0 + yych] & 32)
    6863  {
    6864  goto basic_json_parser_4;
    6865  }
    6866  goto basic_json_parser_3;
    6867 basic_json_parser_6:
    6868  yyaccept = 0;
    6869  yych = *(m_marker = ++m_cursor);
    6870  if (yych == 0xBB)
    6871  {
    6872  goto basic_json_parser_64;
    6873  }
    6874 basic_json_parser_7:
    6875  {
    6876  return token_type::parse_error;
    6877  }
    6878 basic_json_parser_8:
    6879  ++m_cursor;
    6880  {
    6881  return token_type::begin_array;
    6882  }
    6883 basic_json_parser_10:
    6884  ++m_cursor;
    6885  {
    6886  return token_type::end_array;
    6887  }
    6888 basic_json_parser_12:
    6889  ++m_cursor;
    6890  {
    6891  return token_type::begin_object;
    6892  }
    6893 basic_json_parser_14:
    6894  ++m_cursor;
    6895  {
    6896  return token_type::end_object;
    6897  }
    6898 basic_json_parser_16:
    6899  ++m_cursor;
    6900  {
    6901  return token_type::value_separator;
    6902  }
    6903 basic_json_parser_18:
    6904  ++m_cursor;
    6905  {
    6906  return token_type::name_separator;
    6907  }
    6908 basic_json_parser_20:
    6909  yyaccept = 0;
    6910  yych = *(m_marker = ++m_cursor);
    6911  if (yych == 'u')
    6912  {
    6913  goto basic_json_parser_60;
    6914  }
    6915  goto basic_json_parser_7;
    6916 basic_json_parser_21:
    6917  yyaccept = 0;
    6918  yych = *(m_marker = ++m_cursor);
    6919  if (yych == 'r')
    6920  {
    6921  goto basic_json_parser_56;
    6922  }
    6923  goto basic_json_parser_7;
    6924 basic_json_parser_22:
    6925  yyaccept = 0;
    6926  yych = *(m_marker = ++m_cursor);
    6927  if (yych == 'a')
    6928  {
    6929  goto basic_json_parser_51;
    6930  }
    6931  goto basic_json_parser_7;
    6932 basic_json_parser_23:
    6933  yych = *++m_cursor;
    6934  if (yych <= '/')
    6935  {
    6936  goto basic_json_parser_7;
    6937  }
    6938  if (yych <= '0')
    6939  {
    6940  goto basic_json_parser_50;
    6941  }
    6942  if (yych <= '9')
    6943  {
    6944  goto basic_json_parser_41;
    6945  }
    6946  goto basic_json_parser_7;
    6947 basic_json_parser_24:
    6948  yyaccept = 1;
    6949  yych = *(m_marker = ++m_cursor);
    6950  if (yych <= 'D')
    6951  {
    6952  if (yych == '.')
    6953  {
    6954  goto basic_json_parser_43;
    6955  }
    6956  }
    6957  else
    6958  {
    6959  if (yych <= 'E')
    6960  {
    6961  goto basic_json_parser_44;
    6962  }
    6963  if (yych == 'e')
    6964  {
    6965  goto basic_json_parser_44;
    6966  }
    6967  }
    6968 basic_json_parser_25:
    6969  {
    6970  return token_type::value_number;
    6971  }
    6972 basic_json_parser_26:
    6973  yyaccept = 1;
    6974  yych = *(m_marker = ++m_cursor);
    6975  goto basic_json_parser_42;
    6976 basic_json_parser_27:
    6977  yyaccept = 0;
    6978  yych = *(m_marker = ++m_cursor);
    6979  if (yych <= 0x0F)
    6980  {
    6981  goto basic_json_parser_7;
    6982  }
    6983  goto basic_json_parser_32;
    6984 basic_json_parser_28:
    6985  ++m_cursor;
    6986  {
    6987  return token_type::end_of_input;
    6988  }
    6989 basic_json_parser_30:
    6990  yych = *++m_cursor;
    6991  goto basic_json_parser_7;
    6992 basic_json_parser_31:
    6993  ++m_cursor;
    6994  if (m_limit <= m_cursor)
    6995  {
    6996  yyfill(); // LCOV_EXCL_LINE;
    6997  }
    6998  yych = *m_cursor;
    6999 basic_json_parser_32:
    7000  if (yybm[0 + yych] & 64)
    7001  {
    7002  goto basic_json_parser_31;
    7003  }
    7004  if (yych <= 0x0F)
    7005  {
    7006  goto basic_json_parser_33;
    7007  }
    7008  if (yych <= '"')
    7009  {
    7010  goto basic_json_parser_35;
    7011  }
    7012  goto basic_json_parser_34;
    7013 basic_json_parser_33:
    7014  m_cursor = m_marker;
    7015  if (yyaccept == 0)
    7016  {
    7017  goto basic_json_parser_7;
    7018  }
    7019  else
    7020  {
    7021  goto basic_json_parser_25;
    7022  }
    7023 basic_json_parser_34:
    7024  ++m_cursor;
    7025  if (m_limit <= m_cursor)
    7026  {
    7027  yyfill(); // LCOV_EXCL_LINE;
    7028  }
    7029  yych = *m_cursor;
    7030  if (yych <= 'e')
    7031  {
    7032  if (yych <= '/')
    7033  {
    7034  if (yych == '"')
    7035  {
    7036  goto basic_json_parser_31;
    7037  }
    7038  if (yych <= '.')
    7039  {
    7040  goto basic_json_parser_33;
    7041  }
    7042  goto basic_json_parser_31;
    7043  }
    7044  else
    7045  {
    7046  if (yych <= '\\')
    7047  {
    7048  if (yych <= '[')
    7049  {
    7050  goto basic_json_parser_33;
    7051  }
    7052  goto basic_json_parser_31;
    7053  }
    7054  else
    7055  {
    7056  if (yych == 'b')
    7057  {
    7058  goto basic_json_parser_31;
    7059  }
    7060  goto basic_json_parser_33;
    7061  }
    7062  }
    7063  }
    7064  else
    7065  {
    7066  if (yych <= 'q')
    7067  {
    7068  if (yych <= 'f')
    7069  {
    7070  goto basic_json_parser_31;
    7071  }
    7072  if (yych == 'n')
    7073  {
    7074  goto basic_json_parser_31;
    7075  }
    7076  goto basic_json_parser_33;
    7077  }
    7078  else
    7079  {
    7080  if (yych <= 's')
    7081  {
    7082  if (yych <= 'r')
    7083  {
    7084  goto basic_json_parser_31;
    7085  }
    7086  goto basic_json_parser_33;
    7087  }
    7088  else
    7089  {
    7090  if (yych <= 't')
    7091  {
    7092  goto basic_json_parser_31;
    7093  }
    7094  if (yych <= 'u')
    7095  {
    7096  goto basic_json_parser_37;
    7097  }
    7098  goto basic_json_parser_33;
    7099  }
    7100  }
    7101  }
    7102 basic_json_parser_35:
    7103  ++m_cursor;
    7104  {
    7105  return token_type::value_string;
    7106  }
    7107 basic_json_parser_37:
    7108  ++m_cursor;
    7109  if (m_limit <= m_cursor)
    7110  {
    7111  yyfill(); // LCOV_EXCL_LINE;
    7112  }
    7113  yych = *m_cursor;
    7114  if (yych <= '@')
    7115  {
    7116  if (yych <= '/')
    7117  {
    7118  goto basic_json_parser_33;
    7119  }
    7120  if (yych >= ':')
    7121  {
    7122  goto basic_json_parser_33;
    7123  }
    7124  }
    7125  else
    7126  {
    7127  if (yych <= 'F')
    7128  {
    7129  goto basic_json_parser_38;
    7130  }
    7131  if (yych <= '`')
    7132  {
    7133  goto basic_json_parser_33;
    7134  }
    7135  if (yych >= 'g')
    7136  {
    7137  goto basic_json_parser_33;
    7138  }
    7139  }
    7140 basic_json_parser_38:
    7141  ++m_cursor;
    7142  if (m_limit <= m_cursor)
    7143  {
    7144  yyfill(); // LCOV_EXCL_LINE;
    7145  }
    7146  yych = *m_cursor;
    7147  if (yych <= '@')
    7148  {
    7149  if (yych <= '/')
    7150  {
    7151  goto basic_json_parser_33;
    7152  }
    7153  if (yych >= ':')
    7154  {
    7155  goto basic_json_parser_33;
    7156  }
    7157  }
    7158  else
    7159  {
    7160  if (yych <= 'F')
    7161  {
    7162  goto basic_json_parser_39;
    7163  }
    7164  if (yych <= '`')
    7165  {
    7166  goto basic_json_parser_33;
    7167  }
    7168  if (yych >= 'g')
    7169  {
    7170  goto basic_json_parser_33;
    7171  }
    7172  }
    7173 basic_json_parser_39:
    7174  ++m_cursor;
    7175  if (m_limit <= m_cursor)
    7176  {
    7177  yyfill(); // LCOV_EXCL_LINE;
    7178  }
    7179  yych = *m_cursor;
    7180  if (yych <= '@')
    7181  {
    7182  if (yych <= '/')
    7183  {
    7184  goto basic_json_parser_33;
    7185  }
    7186  if (yych >= ':')
    7187  {
    7188  goto basic_json_parser_33;
    7189  }
    7190  }
    7191  else
    7192  {
    7193  if (yych <= 'F')
    7194  {
    7195  goto basic_json_parser_40;
    7196  }
    7197  if (yych <= '`')
    7198  {
    7199  goto basic_json_parser_33;
    7200  }
    7201  if (yych >= 'g')
    7202  {
    7203  goto basic_json_parser_33;
    7204  }
    7205  }
    7206 basic_json_parser_40:
    7207  ++m_cursor;
    7208  if (m_limit <= m_cursor)
    7209  {
    7210  yyfill(); // LCOV_EXCL_LINE;
    7211  }
    7212  yych = *m_cursor;
    7213  if (yych <= '@')
    7214  {
    7215  if (yych <= '/')
    7216  {
    7217  goto basic_json_parser_33;
    7218  }
    7219  if (yych <= '9')
    7220  {
    7221  goto basic_json_parser_31;
    7222  }
    7223  goto basic_json_parser_33;
    7224  }
    7225  else
    7226  {
    7227  if (yych <= 'F')
    7228  {
    7229  goto basic_json_parser_31;
    7230  }
    7231  if (yych <= '`')
    7232  {
    7233  goto basic_json_parser_33;
    7234  }
    7235  if (yych <= 'f')
    7236  {
    7237  goto basic_json_parser_31;
    7238  }
    7239  goto basic_json_parser_33;
    7240  }
    7241 basic_json_parser_41:
    7242  yyaccept = 1;
    7243  m_marker = ++m_cursor;
    7244  if ((m_limit - m_cursor) < 3)
    7245  {
    7246  yyfill(); // LCOV_EXCL_LINE;
    7247  }
    7248  yych = *m_cursor;
    7249 basic_json_parser_42:
    7250  if (yybm[0 + yych] & 128)
    7251  {
    7252  goto basic_json_parser_41;
    7253  }
    7254  if (yych <= 'D')
    7255  {
    7256  if (yych != '.')
    7257  {
    7258  goto basic_json_parser_25;
    7259  }
    7260  }
    7261  else
    7262  {
    7263  if (yych <= 'E')
    7264  {
    7265  goto basic_json_parser_44;
    7266  }
    7267  if (yych == 'e')
    7268  {
    7269  goto basic_json_parser_44;
    7270  }
    7271  goto basic_json_parser_25;
    7272  }
    7273 basic_json_parser_43:
    7274  yych = *++m_cursor;
    7275  if (yych <= '/')
    7276  {
    7277  goto basic_json_parser_33;
    7278  }
    7279  if (yych <= '9')
    7280  {
    7281  goto basic_json_parser_48;
    7282  }
    7283  goto basic_json_parser_33;
    7284 basic_json_parser_44:
    7285  yych = *++m_cursor;
    7286  if (yych <= ',')
    7287  {
    7288  if (yych != '+')
    7289  {
    7290  goto basic_json_parser_33;
    7291  }
    7292  }
    7293  else
    7294  {
    7295  if (yych <= '-')
    7296  {
    7297  goto basic_json_parser_45;
    7298  }
    7299  if (yych <= '/')
    7300  {
    7301  goto basic_json_parser_33;
    7302  }
    7303  if (yych <= '9')
    7304  {
    7305  goto basic_json_parser_46;
    7306  }
    7307  goto basic_json_parser_33;
    7308  }
    7309 basic_json_parser_45:
    7310  yych = *++m_cursor;
    7311  if (yych <= '/')
    7312  {
    7313  goto basic_json_parser_33;
    7314  }
    7315  if (yych >= ':')
    7316  {
    7317  goto basic_json_parser_33;
    7318  }
    7319 basic_json_parser_46:
    7320  ++m_cursor;
    7321  if (m_limit <= m_cursor)
    7322  {
    7323  yyfill(); // LCOV_EXCL_LINE;
    7324  }
    7325  yych = *m_cursor;
    7326  if (yych <= '/')
    7327  {
    7328  goto basic_json_parser_25;
    7329  }
    7330  if (yych <= '9')
    7331  {
    7332  goto basic_json_parser_46;
    7333  }
    7334  goto basic_json_parser_25;
    7335 basic_json_parser_48:
    7336  yyaccept = 1;
    7337  m_marker = ++m_cursor;
    7338  if ((m_limit - m_cursor) < 3)
    7339  {
    7340  yyfill(); // LCOV_EXCL_LINE;
    7341  }
    7342  yych = *m_cursor;
    7343  if (yych <= 'D')
    7344  {
    7345  if (yych <= '/')
    7346  {
    7347  goto basic_json_parser_25;
    7348  }
    7349  if (yych <= '9')
    7350  {
    7351  goto basic_json_parser_48;
    7352  }
    7353  goto basic_json_parser_25;
    7354  }
    7355  else
    7356  {
    7357  if (yych <= 'E')
    7358  {
    7359  goto basic_json_parser_44;
    7360  }
    7361  if (yych == 'e')
    7362  {
    7363  goto basic_json_parser_44;
    7364  }
    7365  goto basic_json_parser_25;
    7366  }
    7367 basic_json_parser_50:
    7368  yyaccept = 1;
    7369  yych = *(m_marker = ++m_cursor);
    7370  if (yych <= 'D')
    7371  {
    7372  if (yych == '.')
    7373  {
    7374  goto basic_json_parser_43;
    7375  }
    7376  goto basic_json_parser_25;
    7377  }
    7378  else
    7379  {
    7380  if (yych <= 'E')
    7381  {
    7382  goto basic_json_parser_44;
    7383  }
    7384  if (yych == 'e')
    7385  {
    7386  goto basic_json_parser_44;
    7387  }
    7388  goto basic_json_parser_25;
    7389  }
    7390 basic_json_parser_51:
    7391  yych = *++m_cursor;
    7392  if (yych != 'l')
    7393  {
    7394  goto basic_json_parser_33;
    7395  }
    7396  yych = *++m_cursor;
    7397  if (yych != 's')
    7398  {
    7399  goto basic_json_parser_33;
    7400  }
    7401  yych = *++m_cursor;
    7402  if (yych != 'e')
    7403  {
    7404  goto basic_json_parser_33;
    7405  }
    7406  ++m_cursor;
    7407  {
    7408  return token_type::literal_false;
    7409  }
    7410 basic_json_parser_56:
    7411  yych = *++m_cursor;
    7412  if (yych != 'u')
    7413  {
    7414  goto basic_json_parser_33;
    7415  }
    7416  yych = *++m_cursor;
    7417  if (yych != 'e')
    7418  {
    7419  goto basic_json_parser_33;
    7420  }
    7421  ++m_cursor;
    7422  {
    7423  return token_type::literal_true;
    7424  }
    7425 basic_json_parser_60:
    7426  yych = *++m_cursor;
    7427  if (yych != 'l')
    7428  {
    7429  goto basic_json_parser_33;
    7430  }
    7431  yych = *++m_cursor;
    7432  if (yych != 'l')
    7433  {
    7434  goto basic_json_parser_33;
    7435  }
    7436  ++m_cursor;
    7437  {
    7438  return token_type::literal_null;
    7439  }
    7440 basic_json_parser_64:
    7441  yych = *++m_cursor;
    7442  if (yych != 0xBF)
    7443  {
    7444  goto basic_json_parser_33;
    7445  }
    7446  ++m_cursor;
    7447  {
    7448  return scan();
    7449  }
    7450  }
    7451 
    7452 
    7453  }
    7454 
    7456  void yyfill() noexcept
    7457  {
    7458  if (m_stream == nullptr or not * m_stream)
    7459  {
    7460  return;
    7461  }
    7462 
    7463  const ssize_t offset_start = m_start - m_content;
    7464  const ssize_t offset_marker = m_marker - m_start;
    7465  const ssize_t offset_cursor = m_cursor - m_start;
    7466 
    7467  m_buffer.erase(0, static_cast<size_t>(offset_start));
    7468  std::string line;
    7469  assert(m_stream != nullptr);
    7470  std::getline(*m_stream, line);
    7471  m_buffer += "\n" + line; // add line with newline symbol
    7472 
    7473  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7474  assert(m_content != nullptr);
    7475  m_start = m_content;
    7476  m_marker = m_start + offset_marker;
    7477  m_cursor = m_start + offset_cursor;
    7478  m_limit = m_start + m_buffer.size() - 1;
    7479  }
    7480 
    7482  string_t get_token() const noexcept
    7483  {
    7484  assert(m_start != nullptr);
    7485  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7486  static_cast<size_t>(m_cursor - m_start));
    7487  }
    7488 
    7510  string_t get_string() const
    7511  {
    7512  string_t result;
    7513  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    7514 
    7515  // iterate the result between the quotes
    7516  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    7517  {
    7518  // process escaped characters
    7519  if (*i == '\\')
    7520  {
    7521  // read next character
    7522  ++i;
    7523 
    7524  switch (*i)
    7525  {
    7526  // the default escapes
    7527  case 't':
    7528  {
    7529  result += "\t";
    7530  break;
    7531  }
    7532  case 'b':
    7533  {
    7534  result += "\b";
    7535  break;
    7536  }
    7537  case 'f':
    7538  {
    7539  result += "\f";
    7540  break;
    7541  }
    7542  case 'n':
    7543  {
    7544  result += "\n";
    7545  break;
    7546  }
    7547  case 'r':
    7548  {
    7549  result += "\r";
    7550  break;
    7551  }
    7552  case '\\':
    7553  {
    7554  result += "\\";
    7555  break;
    7556  }
    7557  case '/':
    7558  {
    7559  result += "/";
    7560  break;
    7561  }
    7562  case '"':
    7563  {
    7564  result += "\"";
    7565  break;
    7566  }
    7567 
    7568  // unicode
    7569  case 'u':
    7570  {
    7571  // get code xxxx from uxxxx
    7572  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    7573  4).c_str(), nullptr, 16);
    7574 
    7575  // check if codepoint is a high surrogate
    7576  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    7577  {
    7578  // make sure there is a subsequent unicode
    7579  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    7580  {
    7581  throw std::invalid_argument("missing low surrogate");
    7582  }
    7583 
    7584  // get code yyyy from uxxxx\uyyyy
    7585  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    7586  (i + 7), 4).c_str(), nullptr, 16);
    7587  result += to_unicode(codepoint, codepoint2);
    7588  // skip the next 10 characters (xxxx\uyyyy)
    7589  i += 10;
    7590  }
    7591  else
    7592  {
    7593  // add unicode character(s)
    7594  result += to_unicode(codepoint);
    7595  // skip the next four characters (xxxx)
    7596  i += 4;
    7597  }
    7598  break;
    7599  }
    7600  }
    7601  }
    7602  else
    7603  {
    7604  // all other characters are just copied to the end of the
    7605  // string
    7606  result.append(1, static_cast<typename string_t::value_type>(*i));
    7607  }
    7608  }
    7609 
    7610  return result;
    7611  }
    7612 
    7630  long double get_number() const
    7631  {
    7632  // conversion
    7633  typename string_t::value_type* endptr;
    7634  assert(m_start != nullptr);
    7635  const auto float_val = std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7636  &endptr);
    7637 
    7638  // return float_val if the whole number was translated and NAN
    7639  // otherwise
    7640  return (reinterpret_cast<lexer_char_t*>(endptr) == m_cursor) ? float_val : NAN;
    7641  }
    7642 
    7643  private:
    7645  std::istream* m_stream = nullptr;
    7647  string_t m_buffer;
    7649  const lexer_char_t* m_content = nullptr;
    7651  const lexer_char_t* m_start = nullptr;
    7653  const lexer_char_t* m_marker = nullptr;
    7655  const lexer_char_t* m_cursor = nullptr;
    7657  const lexer_char_t* m_limit = nullptr;
    7658  };
    7659 
    7665  class parser
    7666  {
    7667  public:
    7669  parser(const string_t& s, parser_callback_t cb = nullptr)
    7670  : callback(cb), m_lexer(s)
    7671  {
    7672  // read first token
    7673  get_token();
    7674  }
    7675 
    7677  parser(std::istream& _is, parser_callback_t cb = nullptr)
    7678  : callback(cb), m_lexer(&_is)
    7679  {
    7680  // read first token
    7681  get_token();
    7682  }
    7683 
    7685  basic_json parse()
    7686  {
    7687  basic_json result = parse_internal(true);
    7688 
    7689  expect(lexer::token_type::end_of_input);
    7690 
    7691  // return parser result and replace it with null in case the
    7692  // top-level value was discarded by the callback function
    7693  return result.is_discarded() ? basic_json() : result;
    7694  }
    7695 
    7696  private:
    7698  basic_json parse_internal(bool keep)
    7699  {
    7700  auto result = basic_json(value_t::discarded);
    7701 
    7702  switch (last_token)
    7703  {
    7704  case lexer::token_type::begin_object:
    7705  {
    7706  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    7707  {
    7708  // explicitly set result to object to cope with {}
    7709  result.m_type = value_t::object;
    7710  result.m_value = json_value(value_t::object);
    7711  }
    7712 
    7713  // read next token
    7714  get_token();
    7715 
    7716  // closing } -> we are done
    7717  if (last_token == lexer::token_type::end_object)
    7718  {
    7719  get_token();
    7720  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    7721  {
    7722  result = basic_json(value_t::discarded);
    7723  }
    7724  return result;
    7725  }
    7726 
    7727  // no comma is expected here
    7728  unexpect(lexer::token_type::value_separator);
    7729 
    7730  // otherwise: parse key-value pairs
    7731  do
    7732  {
    7733  // ugly, but could be fixed with loop reorganization
    7734  if (last_token == lexer::token_type::value_separator)
    7735  {
    7736  get_token();
    7737  }
    7738 
    7739  // store key
    7740  expect(lexer::token_type::value_string);
    7741  const auto key = m_lexer.get_string();
    7742 
    7743  bool keep_tag = false;
    7744  if (keep)
    7745  {
    7746  if (callback)
    7747  {
    7748  basic_json k(key);
    7749  keep_tag = callback(depth, parse_event_t::key, k);
    7750  }
    7751  else
    7752  {
    7753  keep_tag = true;
    7754  }
    7755  }
    7756 
    7757  // parse separator (:)
    7758  get_token();
    7759  expect(lexer::token_type::name_separator);
    7760 
    7761  // parse and add value
    7762  get_token();
    7763  auto value = parse_internal(keep);
    7764  if (keep and keep_tag and not value.is_discarded())
    7765  {
    7766  result[key] = std::move(value);
    7767  }
    7768  }
    7769  while (last_token == lexer::token_type::value_separator);
    7770 
    7771  // closing }
    7772  expect(lexer::token_type::end_object);
    7773  get_token();
    7774  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    7775  {
    7776  result = basic_json(value_t::discarded);
    7777  }
    7778 
    7779  return result;
    7780  }
    7781 
    7782  case lexer::token_type::begin_array:
    7783  {
    7784  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    7785  {
    7786  // explicitly set result to object to cope with []
    7787  result.m_type = value_t::array;
    7788  result.m_value = json_value(value_t::array);
    7789  }
    7790 
    7791  // read next token
    7792  get_token();
    7793 
    7794  // closing ] -> we are done
    7795  if (last_token == lexer::token_type::end_array)
    7796  {
    7797  get_token();
    7798  if (callback and not callback(--depth, parse_event_t::array_end, result))
    7799  {
    7800  result = basic_json(value_t::discarded);
    7801  }
    7802  return result;
    7803  }
    7804 
    7805  // no comma is expected here
    7806  unexpect(lexer::token_type::value_separator);
    7807 
    7808  // otherwise: parse values
    7809  do
    7810  {
    7811  // ugly, but could be fixed with loop reorganization
    7812  if (last_token == lexer::token_type::value_separator)
    7813  {
    7814  get_token();
    7815  }
    7816 
    7817  // parse value
    7818  auto value = parse_internal(keep);
    7819  if (keep and not value.is_discarded())
    7820  {
    7821  result.push_back(std::move(value));
    7822  }
    7823  }
    7824  while (last_token == lexer::token_type::value_separator);
    7825 
    7826  // closing ]
    7827  expect(lexer::token_type::end_array);
    7828  get_token();
    7829  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    7830  {
    7831  result = basic_json(value_t::discarded);
    7832  }
    7833 
    7834  return result;
    7835  }
    7836 
    7837  case lexer::token_type::literal_null:
    7838  {
    7839  get_token();
    7840  result.m_type = value_t::null;
    7841  break;
    7842  }
    7843 
    7844  case lexer::token_type::value_string:
    7845  {
    7846  const auto s = m_lexer.get_string();
    7847  get_token();
    7848  result = basic_json(s);
    7849  break;
    7850  }
    7851 
    7852  case lexer::token_type::literal_true:
    7853  {
    7854  get_token();
    7855  result.m_type = value_t::boolean;
    7856  result.m_value = true;
    7857  break;
    7858  }
    7859 
    7860  case lexer::token_type::literal_false:
    7861  {
    7862  get_token();
    7863  result.m_type = value_t::boolean;
    7864  result.m_value = false;
    7865  break;
    7866  }
    7867 
    7868  case lexer::token_type::value_number:
    7869  {
    7870  auto float_val = m_lexer.get_number();
    7871 
    7872  // NAN is returned if token could not be translated
    7873  // completely
    7874  if (std::isnan(float_val))
    7875  {
    7876  throw std::invalid_argument(std::string("parse error - ") +
    7877  m_lexer.get_token() + " is not a number");
    7878  }
    7879 
    7880  get_token();
    7881 
    7882  // check if conversion loses precision
    7883  const auto int_val = static_cast<number_integer_t>(float_val);
    7884  if (approx(float_val, static_cast<long double>(int_val)))
    7885  {
    7886  // we would not lose precision -> return int
    7887  result.m_type = value_t::number_integer;
    7888  result.m_value = int_val;
    7889  }
    7890  else
    7891  {
    7892  // we would lose precision -> return float
    7893  result.m_type = value_t::number_float;
    7894  result.m_value = static_cast<number_float_t>(float_val);
    7895  }
    7896  break;
    7897  }
    7898 
    7899  default:
    7900  {
    7901  // the last token was unexpected
    7902  unexpect(last_token);
    7903  }
    7904  }
    7905 
    7906  if (keep and callback and not callback(depth, parse_event_t::value, result))
    7907  {
    7908  result = basic_json(value_t::discarded);
    7909  }
    7910  return result;
    7911  }
    7912 
    7914  typename lexer::token_type get_token()
    7915  {
    7916  last_token = m_lexer.scan();
    7917  return last_token;
    7918  }
    7919 
    7920  void expect(typename lexer::token_type t) const
    7921  {
    7922  if (t != last_token)
    7923  {
    7924  std::string error_msg = "parse error - unexpected ";
    7925  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    7926  lexer::token_type_name(last_token));
    7927  error_msg += "; expected " + lexer::token_type_name(t);
    7928  throw std::invalid_argument(error_msg);
    7929  }
    7930  }
    7931 
    7932  void unexpect(typename lexer::token_type t) const
    7933  {
    7934  if (t == last_token)
    7935  {
    7936  std::string error_msg = "parse error - unexpected ";
    7937  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    7938  lexer::token_type_name(last_token));
    7939  throw std::invalid_argument(error_msg);
    7940  }
    7941  }
    7942 
    7943  private:
    7945  int depth = 0;
    7947  parser_callback_t callback;
    7949  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    7951  lexer m_lexer;
    7952  };
    7953 };
    7954 
    7955 
    7957 // presets //
    7959 
    7969 }
    7970 
    7971 
    7973 // nonmember functions //
    7975 
    7976 // specialization of std::swap, and std::hash
    7977 namespace std
    7978 {
    7984 template <>
    7985 inline void swap(nlohmann::json& j1,
    7986  nlohmann::json& j2) noexcept(
    7987  is_nothrow_move_constructible<nlohmann::json>::value and
    7988  is_nothrow_move_assignable<nlohmann::json>::value
    7989  )
    7990 {
    7991  j1.swap(j2);
    7992 }
    7993 
    7995 template <>
    7996 struct hash<nlohmann::json>
    7997 {
    8003  std::size_t operator()(const nlohmann::json& j) const
    8004  {
    8005  // a naive hashing via the string representation
    8006  const auto& h = hash<nlohmann::json::string_t>();
    8007  return h(j.dump());
    8008  }
    8009 };
    8010 }
    8011 
    8024 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    8025 {
    8026  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    8027 }
    8028 
    8029 #endif
    bool operator!=(const const_iterator &other) const
    comparison: not equal
    Definition: json.hpp:6025
    -
    iterator insert(const_iterator pos, basic_json &&val)
    inserts element
    Definition: json.hpp:4308
    -
    iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6273
    -
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:4919
    +
    1 
    38 #ifndef NLOHMANN_JSON_HPP
    39 #define NLOHMANN_JSON_HPP
    40 
    41 #include <algorithm>
    42 #include <array>
    43 #include <cassert>
    44 #include <ciso646>
    45 #include <cmath>
    46 #include <cstdio>
    47 #include <functional>
    48 #include <initializer_list>
    49 #include <iomanip>
    50 #include <iostream>
    51 #include <iterator>
    52 #include <limits>
    53 #include <map>
    54 #include <memory>
    55 #include <sstream>
    56 #include <string>
    57 #include <type_traits>
    58 #include <utility>
    59 #include <vector>
    60 
    61 // enable ssize_t on MinGW
    62 #ifdef __GNUC__
    63  #ifdef __MINGW32__
    64  #include <sys/types.h>
    65  #endif
    66 #endif
    67 
    68 // enable ssize_t for MSVC
    69 #ifdef _MSC_VER
    70  #include <basetsd.h>
    71  using ssize_t = SSIZE_T;
    72 #endif
    73 
    79 namespace nlohmann
    80 {
    81 
    82 
    87 namespace
    88 {
    93 template<typename T>
    94 struct has_mapped_type
    95 {
    96  private:
    97  template<typename C> static char test(typename C::mapped_type*);
    98  template<typename C> static char (&test(...))[2];
    99  public:
    100  static constexpr bool value = sizeof(test<T>(0)) == 1;
    101 };
    102 
    104 template<typename T>
    105 static bool approx(const T a, const T b)
    106 {
    107  return not (a > b or a < b);
    108 }
    109 }
    110 
    179 template <
    180  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    181  template<typename U, typename... Args> class ArrayType = std::vector,
    182  class StringType = std::string,
    183  class BooleanType = bool,
    184  class NumberIntegerType = int64_t,
    185  class NumberFloatType = double,
    186  template<typename U> class AllocatorType = std::allocator
    187  >
    189 {
    190  private:
    192  using basic_json_t = basic_json<ObjectType,
    193  ArrayType,
    194  StringType,
    195  BooleanType,
    196  NumberIntegerType,
    197  NumberFloatType,
    198  AllocatorType>;
    199 
    200  public:
    201 
    203  // container types //
    205 
    208 
    211 
    214 
    216  using const_reference = const value_type&;
    217 
    219  using difference_type = std::ptrdiff_t;
    220 
    222  using size_type = std::size_t;
    223 
    225  using allocator_type = AllocatorType<basic_json>;
    226 
    228  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    230  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    231 
    232  // forward declaration
    233  template<typename Base> class json_reverse_iterator;
    234 
    236  class iterator;
    238  class const_iterator;
    243 
    245 
    246 
    251  {
    252  return allocator_type();
    253  }
    254 
    255 
    257  // JSON value data types //
    259 
    262 
    337  using object_t = ObjectType<StringType,
    338  basic_json,
    339  std::less<StringType>,
    340  AllocatorType<std::pair<const StringType,
    341  basic_json>>>;
    342 
    387  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    388 
    434  using string_t = StringType;
    435 
    460  using boolean_t = BooleanType;
    461 
    528  using number_integer_t = NumberIntegerType;
    529 
    593  using number_float_t = NumberFloatType;
    594 
    596 
    597 
    599  // JSON type enumeration //
    601 
    612  enum class value_t : uint8_t
    613  {
    614  null,
    615  object,
    616  array,
    617  string,
    618  boolean,
    619  number_integer,
    620  number_float,
    621  discarded
    622  };
    623 
    624 
    625  private:
    627  template<typename T, typename... Args>
    628  static T* create(Args&& ... args)
    629  {
    630  AllocatorType<T> alloc;
    631  auto deleter = [&](T * object)
    632  {
    633  alloc.deallocate(object, 1);
    634  };
    635  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    636  alloc.construct(object.get(), std::forward<Args>(args)...);
    637  return object.release();
    638  }
    639 
    641  // JSON value storage //
    643 
    651  union json_value
    652  {
    654  object_t* object;
    656  array_t* array;
    658  string_t* string;
    660  boolean_t boolean;
    662  number_integer_t number_integer;
    664  number_float_t number_float;
    665 
    667  json_value() noexcept = default;
    669  json_value(boolean_t v) noexcept : boolean(v) {}
    671  json_value(number_integer_t v) noexcept : number_integer(v) {}
    673  json_value(number_float_t v) noexcept : number_float(v) {}
    675  json_value(value_t t)
    676  {
    677  switch (t)
    678  {
    679  case value_t::object:
    680  {
    681  object = create<object_t>();
    682  break;
    683  }
    684 
    685  case value_t::array:
    686  {
    687  array = create<array_t>();
    688  break;
    689  }
    690 
    691  case value_t::string:
    692  {
    693  string = create<string_t>("");
    694  break;
    695  }
    696 
    697  case value_t::boolean:
    698  {
    699  boolean = boolean_t(false);
    700  break;
    701  }
    702 
    703  case value_t::number_integer:
    704  {
    705  number_integer = number_integer_t(0);
    706  break;
    707  }
    708 
    709  case value_t::number_float:
    710  {
    711  number_float = number_float_t(0.0);
    712  break;
    713  }
    714 
    715  default:
    716  {
    717  break;
    718  }
    719  }
    720  }
    721 
    723  json_value(const string_t& value)
    724  {
    725  string = create<string_t>(value);
    726  }
    727 
    729  json_value(const object_t& value)
    730  {
    731  object = create<object_t>(value);
    732  }
    733 
    735  json_value(const array_t& value)
    736  {
    737  array = create<array_t>(value);
    738  }
    739  };
    740 
    741 
    742  public:
    744  // JSON parser callback //
    746 
    755  enum class parse_event_t : uint8_t
    756  {
    758  object_start,
    760  object_end,
    762  array_start,
    764  array_end,
    766  key,
    768  value
    769  };
    770 
    820  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    821 
    822 
    824  // constructors //
    826 
    829 
    868  : m_type(value_type), m_value(value_type)
    869  {}
    870 
    890  basic_json() noexcept = default;
    891 
    911  basic_json(std::nullptr_t) noexcept
    912  : basic_json(value_t::null)
    913  {}
    914 
    934  basic_json(const object_t& val)
    935  : m_type(value_t::object), m_value(val)
    936  {}
    937 
    961  template <class CompatibleObjectType, typename
    962  std::enable_if<
    963  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    964  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    965  = 0>
    966  basic_json(const CompatibleObjectType& val)
    967  : m_type(value_t::object)
    968  {
    969  using std::begin;
    970  using std::end;
    971  m_value.object = create<object_t>(begin(val), end(val));
    972  }
    973 
    993  basic_json(const array_t& val)
    994  : m_type(value_t::array), m_value(val)
    995  {}
    996 
    1020  template <class CompatibleArrayType, typename
    1021  std::enable_if<
    1022  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1023  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1024  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1025  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1026  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1027  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1028  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1029  = 0>
    1030  basic_json(const CompatibleArrayType& val)
    1031  : m_type(value_t::array)
    1032  {
    1033  using std::begin;
    1034  using std::end;
    1035  m_value.array = create<array_t>(begin(val), end(val));
    1036  }
    1037 
    1059  basic_json(const string_t& val)
    1060  : m_type(value_t::string), m_value(val)
    1061  {}
    1062 
    1083  basic_json(const typename string_t::value_type* val)
    1084  : basic_json(string_t(val))
    1085  {}
    1086 
    1110  template <class CompatibleStringType, typename
    1111  std::enable_if<
    1112  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1113  = 0>
    1114  basic_json(const CompatibleStringType& val)
    1115  : basic_json(string_t(val))
    1116  {}
    1117 
    1133  : m_type(value_t::boolean), m_value(val)
    1134  {}
    1135 
    1161  template<typename T,
    1162  typename std::enable_if<
    1163  not (std::is_same<T, int>::value)
    1164  and std::is_same<T, number_integer_t>::value
    1165  , int>::type = 0>
    1167  : m_type(value_t::number_integer), m_value(val)
    1168  {}
    1169 
    1195  basic_json(const int val)
    1196  : m_type(value_t::number_integer),
    1197  m_value(static_cast<number_integer_t>(val))
    1198  {}
    1199 
    1225  template<typename CompatibleNumberIntegerType, typename
    1226  std::enable_if<
    1227  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1228  std::numeric_limits<CompatibleNumberIntegerType>::is_integer, CompatibleNumberIntegerType>::type
    1229  = 0>
    1230  basic_json(const CompatibleNumberIntegerType val) noexcept
    1231  : m_type(value_t::number_integer),
    1232  m_value(static_cast<number_integer_t>(val))
    1233  {}
    1234 
    1260  : m_type(value_t::number_float), m_value(val)
    1261  {
    1262  // replace infinity and NAN by null
    1263  if (not std::isfinite(val))
    1264  {
    1265  m_type = value_t::null;
    1266  m_value = json_value();
    1267  }
    1268  }
    1269 
    1300  template<typename CompatibleNumberFloatType, typename = typename
    1301  std::enable_if<
    1302  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1303  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1304  >
    1305  basic_json(const CompatibleNumberFloatType val) noexcept
    1306  : basic_json(number_float_t(val))
    1307  {}
    1308 
    1378  basic_json(std::initializer_list<basic_json> init,
    1379  bool type_deduction = true,
    1380  value_t manual_type = value_t::array)
    1381  {
    1382  // the initializer list could describe an object
    1383  bool is_an_object = true;
    1384 
    1385  // check if each element is an array with two elements whose first
    1386  // element is a string
    1387  for (const auto& element : init)
    1388  {
    1389  if (not element.is_array() or element.size() != 2
    1390  or not element[0].is_string())
    1391  {
    1392  // we found an element that makes it impossible to use the
    1393  // initializer list as object
    1394  is_an_object = false;
    1395  break;
    1396  }
    1397  }
    1398 
    1399  // adjust type if type deduction is not wanted
    1400  if (not type_deduction)
    1401  {
    1402  // if array is wanted, do not create an object though possible
    1403  if (manual_type == value_t::array)
    1404  {
    1405  is_an_object = false;
    1406  }
    1407 
    1408  // if object is wanted but impossible, throw an exception
    1409  if (manual_type == value_t::object and not is_an_object)
    1410  {
    1411  throw std::domain_error("cannot create object from initializer list");
    1412  }
    1413  }
    1414 
    1415  if (is_an_object)
    1416  {
    1417  // the initializer list is a list of pairs -> create object
    1418  m_type = value_t::object;
    1419  m_value = value_t::object;
    1420 
    1421  assert(m_value.object != nullptr);
    1422 
    1423  for (auto& element : init)
    1424  {
    1425  m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
    1426  }
    1427  }
    1428  else
    1429  {
    1430  // the initializer list describes an array -> create array
    1431  m_type = value_t::array;
    1432  m_value.array = create<array_t>(std::move(init));
    1433  }
    1434  }
    1435 
    1470  static basic_json array(std::initializer_list<basic_json> init =
    1471  std::initializer_list<basic_json>())
    1472  {
    1473  return basic_json(init, false, value_t::array);
    1474  }
    1475 
    1510  static basic_json object(std::initializer_list<basic_json> init =
    1511  std::initializer_list<basic_json>())
    1512  {
    1513  return basic_json(init, false, value_t::object);
    1514  }
    1515 
    1534  basic_json(size_type cnt, const basic_json& val)
    1535  : m_type(value_t::array)
    1536  {
    1537  m_value.array = create<array_t>(cnt, val);
    1538  }
    1539 
    1574  template <class InputIT, typename
    1575  std::enable_if<
    1576  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1577  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1578  , int>::type
    1579  = 0>
    1580  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1581  {
    1582  // make sure iterator fits the current value
    1583  if (first.m_object != last.m_object)
    1584  {
    1585  throw std::domain_error("iterators are not compatible");
    1586  }
    1587 
    1588  // check if iterator range is complete for primitive values
    1589  switch (m_type)
    1590  {
    1591  case value_t::boolean:
    1592  case value_t::number_float:
    1593  case value_t::number_integer:
    1594  case value_t::string:
    1595  {
    1596  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1597  {
    1598  throw std::out_of_range("iterators out of range");
    1599  }
    1600  break;
    1601  }
    1602 
    1603  default:
    1604  {
    1605  break;
    1606  }
    1607  }
    1608 
    1609  switch (m_type)
    1610  {
    1611  case value_t::number_integer:
    1612  {
    1613  assert(first.m_object != nullptr);
    1614  m_value.number_integer = first.m_object->m_value.number_integer;
    1615  break;
    1616  }
    1617 
    1618  case value_t::number_float:
    1619  {
    1620  assert(first.m_object != nullptr);
    1621  m_value.number_float = first.m_object->m_value.number_float;
    1622  break;
    1623  }
    1624 
    1625  case value_t::boolean:
    1626  {
    1627  assert(first.m_object != nullptr);
    1628  m_value.boolean = first.m_object->m_value.boolean;
    1629  break;
    1630  }
    1631 
    1632  case value_t::string:
    1633  {
    1634  assert(first.m_object != nullptr);
    1635  m_value = *first.m_object->m_value.string;
    1636  break;
    1637  }
    1638 
    1639  case value_t::object:
    1640  {
    1641  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1642  break;
    1643  }
    1644 
    1645  case value_t::array:
    1646  {
    1647  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1648  break;
    1649  }
    1650 
    1651  default:
    1652  {
    1653  assert(first.m_object != nullptr);
    1654  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1655  }
    1656  }
    1657  }
    1658 
    1660  // other constructors and destructor //
    1662 
    1683  basic_json(const basic_json& other)
    1684  : m_type(other.m_type)
    1685  {
    1686  switch (m_type)
    1687  {
    1688  case value_t::object:
    1689  {
    1690  assert(other.m_value.object != nullptr);
    1691  m_value = *other.m_value.object;
    1692  break;
    1693  }
    1694 
    1695  case value_t::array:
    1696  {
    1697  assert(other.m_value.array != nullptr);
    1698  m_value = *other.m_value.array;
    1699  break;
    1700  }
    1701 
    1702  case value_t::string:
    1703  {
    1704  assert(other.m_value.string != nullptr);
    1705  m_value = *other.m_value.string;
    1706  break;
    1707  }
    1708 
    1709  case value_t::boolean:
    1710  {
    1711  m_value = other.m_value.boolean;
    1712  break;
    1713  }
    1714 
    1715  case value_t::number_integer:
    1716  {
    1717  m_value = other.m_value.number_integer;
    1718  break;
    1719  }
    1720 
    1721  case value_t::number_float:
    1722  {
    1723  m_value = other.m_value.number_float;
    1724  break;
    1725  }
    1726 
    1727  default:
    1728  {
    1729  break;
    1730  }
    1731  }
    1732  }
    1733 
    1752  basic_json(basic_json&& other) noexcept
    1753  : m_type(std::move(other.m_type)),
    1754  m_value(std::move(other.m_value))
    1755  {
    1756  // invalidate payload
    1757  other.m_type = value_t::null;
    1758  other.m_value = {};
    1759  }
    1760 
    1782  reference& operator=(basic_json other) noexcept (
    1783  std::is_nothrow_move_constructible<value_t>::value and
    1784  std::is_nothrow_move_assignable<value_t>::value and
    1785  std::is_nothrow_move_constructible<json_value>::value and
    1786  std::is_nothrow_move_assignable<json_value>::value
    1787  )
    1788  {
    1789  using std::swap;
    1790  swap(m_type, other.m_type);
    1791  swap(m_value, other.m_value);
    1792  return *this;
    1793  }
    1794 
    1809  {
    1810  switch (m_type)
    1811  {
    1812  case value_t::object:
    1813  {
    1814  AllocatorType<object_t> alloc;
    1815  alloc.destroy(m_value.object);
    1816  alloc.deallocate(m_value.object, 1);
    1817  break;
    1818  }
    1819 
    1820  case value_t::array:
    1821  {
    1822  AllocatorType<array_t> alloc;
    1823  alloc.destroy(m_value.array);
    1824  alloc.deallocate(m_value.array, 1);
    1825  break;
    1826  }
    1827 
    1828  case value_t::string:
    1829  {
    1830  AllocatorType<string_t> alloc;
    1831  alloc.destroy(m_value.string);
    1832  alloc.deallocate(m_value.string, 1);
    1833  break;
    1834  }
    1835 
    1836  default:
    1837  {
    1838  // all other types need no specific destructor
    1839  break;
    1840  }
    1841  }
    1842  }
    1843 
    1845 
    1846  public:
    1848  // object inspection //
    1850 
    1853 
    1877  string_t dump(const int indent = -1) const
    1878  {
    1879  std::stringstream ss;
    1880 
    1881  if (indent >= 0)
    1882  {
    1883  dump(ss, true, static_cast<unsigned int>(indent));
    1884  }
    1885  else
    1886  {
    1887  dump(ss, false, 0);
    1888  }
    1889 
    1890  return ss.str();
    1891  }
    1892 
    1908  value_t type() const noexcept
    1909  {
    1910  return m_type;
    1911  }
    1912 
    1929  bool is_primitive() const noexcept
    1930  {
    1931  return is_null() or is_string() or is_boolean() or is_number();
    1932  }
    1933 
    1949  bool is_structured() const noexcept
    1950  {
    1951  return is_array() or is_object();
    1952  }
    1953 
    1968  bool is_null() const noexcept
    1969  {
    1970  return m_type == value_t::null;
    1971  }
    1972 
    1987  bool is_boolean() const noexcept
    1988  {
    1989  return m_type == value_t::boolean;
    1990  }
    1991 
    2011  bool is_number() const noexcept
    2012  {
    2013  return is_number_integer() or is_number_float();
    2014  }
    2015 
    2034  bool is_number_integer() const noexcept
    2035  {
    2036  return m_type == value_t::number_integer;
    2037  }
    2038 
    2057  bool is_number_float() const noexcept
    2058  {
    2059  return m_type == value_t::number_float;
    2060  }
    2061 
    2076  bool is_object() const noexcept
    2077  {
    2078  return m_type == value_t::object;
    2079  }
    2080 
    2095  bool is_array() const noexcept
    2096  {
    2097  return m_type == value_t::array;
    2098  }
    2099 
    2114  bool is_string() const noexcept
    2115  {
    2116  return m_type == value_t::string;
    2117  }
    2118 
    2138  bool is_discarded() const noexcept
    2139  {
    2140  return m_type == value_t::discarded;
    2141  }
    2142 
    2158  operator value_t() const noexcept
    2159  {
    2160  return m_type;
    2161  }
    2162 
    2164 
    2165  private:
    2167  // value access //
    2169 
    2171  template <class T, typename
    2172  std::enable_if<
    2173  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2174  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2175  , int>::type = 0>
    2176  T get_impl(T*) const
    2177  {
    2178  if (is_object())
    2179  {
    2180  assert(m_value.object != nullptr);
    2181  return T(m_value.object->begin(), m_value.object->end());
    2182  }
    2183  else
    2184  {
    2185  throw std::domain_error("type must be object, but is " + type_name());
    2186  }
    2187  }
    2188 
    2190  object_t get_impl(object_t*) const
    2191  {
    2192  if (is_object())
    2193  {
    2194  assert(m_value.object != nullptr);
    2195  return *(m_value.object);
    2196  }
    2197  else
    2198  {
    2199  throw std::domain_error("type must be object, but is " + type_name());
    2200  }
    2201  }
    2202 
    2204  template <class T, typename
    2205  std::enable_if<
    2206  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2207  not std::is_same<basic_json_t, typename T::value_type>::value and
    2208  not std::is_arithmetic<T>::value and
    2209  not std::is_convertible<std::string, T>::value and
    2210  not has_mapped_type<T>::value
    2211  , int>::type = 0>
    2212  T get_impl(T*) const
    2213  {
    2214  if (is_array())
    2215  {
    2216  T to_vector;
    2217  assert(m_value.array != nullptr);
    2218  std::transform(m_value.array->begin(), m_value.array->end(),
    2219  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2220  {
    2221  return i.get<typename T::value_type>();
    2222  });
    2223  return to_vector;
    2224  }
    2225  else
    2226  {
    2227  throw std::domain_error("type must be array, but is " + type_name());
    2228  }
    2229  }
    2230 
    2232  template <class T, typename
    2233  std::enable_if<
    2234  std::is_convertible<basic_json_t, T>::value and
    2235  not std::is_same<basic_json_t, T>::value
    2236  , int>::type = 0>
    2237  std::vector<T> get_impl(std::vector<T>*) const
    2238  {
    2239  if (is_array())
    2240  {
    2241  std::vector<T> to_vector;
    2242  assert(m_value.array != nullptr);
    2243  to_vector.reserve(m_value.array->size());
    2244  std::transform(m_value.array->begin(), m_value.array->end(),
    2245  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2246  {
    2247  return i.get<T>();
    2248  });
    2249  return to_vector;
    2250  }
    2251  else
    2252  {
    2253  throw std::domain_error("type must be array, but is " + type_name());
    2254  }
    2255  }
    2256 
    2258  template <class T, typename
    2259  std::enable_if<
    2260  std::is_same<basic_json, typename T::value_type>::value and
    2261  not has_mapped_type<T>::value
    2262  , int>::type = 0>
    2263  T get_impl(T*) const
    2264  {
    2265  if (is_array())
    2266  {
    2267  assert(m_value.array != nullptr);
    2268  return T(m_value.array->begin(), m_value.array->end());
    2269  }
    2270  else
    2271  {
    2272  throw std::domain_error("type must be array, but is " + type_name());
    2273  }
    2274  }
    2275 
    2277  array_t get_impl(array_t*) const
    2278  {
    2279  if (is_array())
    2280  {
    2281  assert(m_value.array != nullptr);
    2282  return *(m_value.array);
    2283  }
    2284  else
    2285  {
    2286  throw std::domain_error("type must be array, but is " + type_name());
    2287  }
    2288  }
    2289 
    2291  template <typename T, typename
    2292  std::enable_if<
    2293  std::is_convertible<string_t, T>::value
    2294  , int>::type = 0>
    2295  T get_impl(T*) const
    2296  {
    2297  if (is_string())
    2298  {
    2299  assert(m_value.string != nullptr);
    2300  return *m_value.string;
    2301  }
    2302  else
    2303  {
    2304  throw std::domain_error("type must be string, but is " + type_name());
    2305  }
    2306  }
    2307 
    2309  template<typename T, typename
    2310  std::enable_if<
    2311  std::is_arithmetic<T>::value
    2312  , int>::type = 0>
    2313  T get_impl(T*) const
    2314  {
    2315  switch (m_type)
    2316  {
    2317  case value_t::number_integer:
    2318  {
    2319  return static_cast<T>(m_value.number_integer);
    2320  }
    2321 
    2322  case value_t::number_float:
    2323  {
    2324  return static_cast<T>(m_value.number_float);
    2325  }
    2326 
    2327  default:
    2328  {
    2329  throw std::domain_error("type must be number, but is " + type_name());
    2330  }
    2331  }
    2332  }
    2333 
    2335  boolean_t get_impl(boolean_t*) const
    2336  {
    2337  if (is_boolean())
    2338  {
    2339  return m_value.boolean;
    2340  }
    2341  else
    2342  {
    2343  throw std::domain_error("type must be boolean, but is " + type_name());
    2344  }
    2345  }
    2346 
    2348  object_t* get_impl_ptr(object_t*) noexcept
    2349  {
    2350  return is_object() ? m_value.object : nullptr;
    2351  }
    2352 
    2354  const object_t* get_impl_ptr(const object_t*) const noexcept
    2355  {
    2356  return is_object() ? m_value.object : nullptr;
    2357  }
    2358 
    2360  array_t* get_impl_ptr(array_t*) noexcept
    2361  {
    2362  return is_array() ? m_value.array : nullptr;
    2363  }
    2364 
    2366  const array_t* get_impl_ptr(const array_t*) const noexcept
    2367  {
    2368  return is_array() ? m_value.array : nullptr;
    2369  }
    2370 
    2372  string_t* get_impl_ptr(string_t*) noexcept
    2373  {
    2374  return is_string() ? m_value.string : nullptr;
    2375  }
    2376 
    2378  const string_t* get_impl_ptr(const string_t*) const noexcept
    2379  {
    2380  return is_string() ? m_value.string : nullptr;
    2381  }
    2382 
    2384  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2385  {
    2386  return is_boolean() ? &m_value.boolean : nullptr;
    2387  }
    2388 
    2390  const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2391  {
    2392  return is_boolean() ? &m_value.boolean : nullptr;
    2393  }
    2394 
    2396  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2397  {
    2398  return is_number_integer() ? &m_value.number_integer : nullptr;
    2399  }
    2400 
    2402  const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2403  {
    2404  return is_number_integer() ? &m_value.number_integer : nullptr;
    2405  }
    2406 
    2408  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2409  {
    2410  return is_number_float() ? &m_value.number_float : nullptr;
    2411  }
    2412 
    2414  const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2415  {
    2416  return is_number_float() ? &m_value.number_float : nullptr;
    2417  }
    2418 
    2430  template<typename ReferenceType, typename ThisType>
    2431  static ReferenceType get_ref_impl(ThisType& obj)
    2432  {
    2433  // delegate the call to get_ptr<>()
    2434  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2435  auto ptr = obj.template get_ptr<PointerType>();
    2436 
    2437  if (ptr != nullptr)
    2438  {
    2439  return *ptr;
    2440  }
    2441  else
    2442  {
    2443  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2444  obj.type_name());
    2445  }
    2446  }
    2447 
    2448  public:
    2449 
    2452 
    2486  template<typename ValueType, typename
    2487  std::enable_if<
    2488  not std::is_pointer<ValueType>::value
    2489  , int>::type = 0>
    2490  ValueType get() const
    2491  {
    2492  return get_impl(static_cast<ValueType*>(nullptr));
    2493  }
    2494 
    2521  template<typename PointerType, typename
    2522  std::enable_if<
    2523  std::is_pointer<PointerType>::value
    2524  , int>::type = 0>
    2525  PointerType get() noexcept
    2526  {
    2527  // delegate the call to get_ptr
    2528  return get_ptr<PointerType>();
    2529  }
    2530 
    2535  template<typename PointerType, typename
    2536  std::enable_if<
    2537  std::is_pointer<PointerType>::value
    2538  , int>::type = 0>
    2539  const PointerType get() const noexcept
    2540  {
    2541  // delegate the call to get_ptr
    2542  return get_ptr<PointerType>();
    2543  }
    2544 
    2570  template<typename PointerType, typename
    2571  std::enable_if<
    2572  std::is_pointer<PointerType>::value
    2573  , int>::type = 0>
    2574  PointerType get_ptr() noexcept
    2575  {
    2576  // delegate the call to get_impl_ptr<>()
    2577  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2578  }
    2579 
    2584  template<typename PointerType, typename
    2585  std::enable_if<
    2586  std::is_pointer<PointerType>::value
    2587  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2588  , int>::type = 0>
    2589  const PointerType get_ptr() const noexcept
    2590  {
    2591  // delegate the call to get_impl_ptr<>() const
    2592  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2593  }
    2594 
    2621  template<typename ReferenceType, typename
    2622  std::enable_if<
    2623  std::is_reference<ReferenceType>::value
    2624  , int>::type = 0>
    2625  ReferenceType get_ref()
    2626  {
    2627  // delegate call to get_ref_impl
    2628  return get_ref_impl<ReferenceType>(*this);
    2629  }
    2630 
    2635  template<typename ReferenceType, typename
    2636  std::enable_if<
    2637  std::is_reference<ReferenceType>::value
    2638  and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
    2639  , int>::type = 0>
    2640  ReferenceType get_ref() const
    2641  {
    2642  // delegate call to get_ref_impl
    2643  return get_ref_impl<ReferenceType>(*this);
    2644  }
    2645 
    2674  template<typename ValueType, typename
    2675  std::enable_if<
    2676  not std::is_pointer<ValueType>::value
    2677  and not std::is_same<ValueType, typename string_t::value_type>::value
    2678  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    2679  , int>::type = 0>
    2680  operator ValueType() const
    2681  {
    2682  // delegate the call to get<>() const
    2683  return get<ValueType>();
    2684  }
    2685 
    2687 
    2688 
    2690  // element access //
    2692 
    2695 
    2719  {
    2720  // at only works for arrays
    2721  if (is_array())
    2722  {
    2723  try
    2724  {
    2725  assert(m_value.array != nullptr);
    2726  return m_value.array->at(idx);
    2727  }
    2728  catch (std::out_of_range&)
    2729  {
    2730  // create better exception explanation
    2731  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2732  }
    2733  }
    2734  else
    2735  {
    2736  throw std::domain_error("cannot use at() with " + type_name());
    2737  }
    2738  }
    2739 
    2763  {
    2764  // at only works for arrays
    2765  if (is_array())
    2766  {
    2767  try
    2768  {
    2769  assert(m_value.array != nullptr);
    2770  return m_value.array->at(idx);
    2771  }
    2772  catch (std::out_of_range&)
    2773  {
    2774  // create better exception explanation
    2775  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2776  }
    2777  }
    2778  else
    2779  {
    2780  throw std::domain_error("cannot use at() with " + type_name());
    2781  }
    2782  }
    2783 
    2810  reference at(const typename object_t::key_type& key)
    2811  {
    2812  // at only works for objects
    2813  if (is_object())
    2814  {
    2815  try
    2816  {
    2817  assert(m_value.object != nullptr);
    2818  return m_value.object->at(key);
    2819  }
    2820  catch (std::out_of_range&)
    2821  {
    2822  // create better exception explanation
    2823  throw std::out_of_range("key '" + key + "' not found");
    2824  }
    2825  }
    2826  else
    2827  {
    2828  throw std::domain_error("cannot use at() with " + type_name());
    2829  }
    2830  }
    2831 
    2858  const_reference at(const typename object_t::key_type& key) const
    2859  {
    2860  // at only works for objects
    2861  if (is_object())
    2862  {
    2863  try
    2864  {
    2865  assert(m_value.object != nullptr);
    2866  return m_value.object->at(key);
    2867  }
    2868  catch (std::out_of_range&)
    2869  {
    2870  // create better exception explanation
    2871  throw std::out_of_range("key '" + key + "' not found");
    2872  }
    2873  }
    2874  else
    2875  {
    2876  throw std::domain_error("cannot use at() with " + type_name());
    2877  }
    2878  }
    2879 
    2906  {
    2907  // implicitly convert null to object
    2908  if (is_null())
    2909  {
    2910  m_type = value_t::array;
    2911  m_value.array = create<array_t>();
    2912  }
    2913 
    2914  // [] only works for arrays
    2915  if (is_array())
    2916  {
    2917  assert(m_value.array != nullptr);
    2918  for (size_t i = m_value.array->size(); i <= idx; ++i)
    2919  {
    2920  m_value.array->push_back(basic_json());
    2921  }
    2922 
    2923  return m_value.array->operator[](idx);
    2924  }
    2925  else
    2926  {
    2927  throw std::domain_error("cannot use operator[] with " + type_name());
    2928  }
    2929  }
    2930 
    2951  {
    2952  // at only works for arrays
    2953  if (is_array())
    2954  {
    2955  assert(m_value.array != nullptr);
    2956  return m_value.array->operator[](idx);
    2957  }
    2958  else
    2959  {
    2960  throw std::domain_error("cannot use operator[] with " + type_name());
    2961  }
    2962  }
    2963 
    2991  reference operator[](const typename object_t::key_type& key)
    2992  {
    2993  // implicitly convert null to object
    2994  if (is_null())
    2995  {
    2996  m_type = value_t::object;
    2997  m_value.object = create<object_t>();
    2998  }
    2999 
    3000  // [] only works for objects
    3001  if (is_object())
    3002  {
    3003  assert(m_value.object != nullptr);
    3004  return m_value.object->operator[](key);
    3005  }
    3006  else
    3007  {
    3008  throw std::domain_error("cannot use operator[] with " + type_name());
    3009  }
    3010  }
    3011 
    3039  const_reference operator[](const typename object_t::key_type& key) const
    3040  {
    3041  // [] only works for objects
    3042  if (is_object())
    3043  {
    3044  assert(m_value.object != nullptr);
    3045  assert(m_value.object->find(key) != m_value.object->end());
    3046  return m_value.object->find(key)->second;
    3047  }
    3048  else
    3049  {
    3050  throw std::domain_error("cannot use operator[] with " + type_name());
    3051  }
    3052  }
    3053 
    3083  template<typename T, std::size_t n>
    3084  reference operator[](const T (&key)[n])
    3085  {
    3086  // implicitly convert null to object
    3087  if (is_null())
    3088  {
    3089  m_type = value_t::object;
    3090  m_value = value_t::object;
    3091  }
    3092 
    3093  // at only works for objects
    3094  if (is_object())
    3095  {
    3096  assert(m_value.object != nullptr);
    3097  return m_value.object->operator[](key);
    3098  }
    3099  else
    3100  {
    3101  throw std::domain_error("cannot use operator[] with " + type_name());
    3102  }
    3103  }
    3104 
    3134  template<typename T, std::size_t n>
    3135  const_reference operator[](const T (&key)[n]) const
    3136  {
    3137  // at only works for objects
    3138  if (is_object())
    3139  {
    3140  assert(m_value.object != nullptr);
    3141  assert(m_value.object->find(key) != m_value.object->end());
    3142  return m_value.object->find(key)->second;
    3143  }
    3144  else
    3145  {
    3146  throw std::domain_error("cannot use operator[] with " + type_name());
    3147  }
    3148  }
    3149 
    3198  template <class ValueType, typename
    3199  std::enable_if<
    3200  std::is_convertible<basic_json_t, ValueType>::value
    3201  , int>::type = 0>
    3202  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3203  {
    3204  // at only works for objects
    3205  if (is_object())
    3206  {
    3207  // if key is found, return value and given default value otherwise
    3208  const auto it = find(key);
    3209  if (it != end())
    3210  {
    3211  return *it;
    3212  }
    3213  else
    3214  {
    3215  return default_value;
    3216  }
    3217  }
    3218  else
    3219  {
    3220  throw std::domain_error("cannot use value() with " + type_name());
    3221  }
    3222  }
    3223 
    3228  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3229  {
    3230  return value(key, string_t(default_value));
    3231  }
    3232 
    3254  {
    3255  return *begin();
    3256  }
    3257 
    3262  {
    3263  return *cbegin();
    3264  }
    3265 
    3288  {
    3289  auto tmp = end();
    3290  --tmp;
    3291  return *tmp;
    3292  }
    3293 
    3298  {
    3299  auto tmp = cend();
    3300  --tmp;
    3301  return *tmp;
    3302  }
    3303 
    3348  template <class InteratorType, typename
    3349  std::enable_if<
    3350  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3351  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3352  , int>::type
    3353  = 0>
    3354  InteratorType erase(InteratorType pos)
    3355  {
    3356  // make sure iterator fits the current value
    3357  if (this != pos.m_object)
    3358  {
    3359  throw std::domain_error("iterator does not fit current value");
    3360  }
    3361 
    3362  InteratorType result = end();
    3363 
    3364  switch (m_type)
    3365  {
    3366  case value_t::boolean:
    3367  case value_t::number_float:
    3368  case value_t::number_integer:
    3369  case value_t::string:
    3370  {
    3371  if (not pos.m_it.primitive_iterator.is_begin())
    3372  {
    3373  throw std::out_of_range("iterator out of range");
    3374  }
    3375 
    3376  if (is_string())
    3377  {
    3378  delete m_value.string;
    3379  m_value.string = nullptr;
    3380  }
    3381 
    3382  m_type = value_t::null;
    3383  break;
    3384  }
    3385 
    3386  case value_t::object:
    3387  {
    3388  assert(m_value.object != nullptr);
    3389  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3390  break;
    3391  }
    3392 
    3393  case value_t::array:
    3394  {
    3395  assert(m_value.array != nullptr);
    3396  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3397  break;
    3398  }
    3399 
    3400  default:
    3401  {
    3402  throw std::domain_error("cannot use erase() with " + type_name());
    3403  }
    3404  }
    3405 
    3406  return result;
    3407  }
    3408 
    3453  template <class InteratorType, typename
    3454  std::enable_if<
    3455  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3456  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3457  , int>::type
    3458  = 0>
    3459  InteratorType erase(InteratorType first, InteratorType last)
    3460  {
    3461  // make sure iterator fits the current value
    3462  if (this != first.m_object or this != last.m_object)
    3463  {
    3464  throw std::domain_error("iterators do not fit current value");
    3465  }
    3466 
    3467  InteratorType result = end();
    3468 
    3469  switch (m_type)
    3470  {
    3471  case value_t::boolean:
    3472  case value_t::number_float:
    3473  case value_t::number_integer:
    3474  case value_t::string:
    3475  {
    3476  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3477  {
    3478  throw std::out_of_range("iterators out of range");
    3479  }
    3480 
    3481  if (is_string())
    3482  {
    3483  delete m_value.string;
    3484  m_value.string = nullptr;
    3485  }
    3486 
    3487  m_type = value_t::null;
    3488  break;
    3489  }
    3490 
    3491  case value_t::object:
    3492  {
    3493  assert(m_value.object != nullptr);
    3494  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3495  last.m_it.object_iterator);
    3496  break;
    3497  }
    3498 
    3499  case value_t::array:
    3500  {
    3501  assert(m_value.array != nullptr);
    3502  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3503  last.m_it.array_iterator);
    3504  break;
    3505  }
    3506 
    3507  default:
    3508  {
    3509  throw std::domain_error("cannot use erase() with " + type_name());
    3510  }
    3511  }
    3512 
    3513  return result;
    3514  }
    3515 
    3542  size_type erase(const typename object_t::key_type& key)
    3543  {
    3544  // this erase only works for objects
    3545  if (is_object())
    3546  {
    3547  assert(m_value.object != nullptr);
    3548  return m_value.object->erase(key);
    3549  }
    3550  else
    3551  {
    3552  throw std::domain_error("cannot use erase() with " + type_name());
    3553  }
    3554  }
    3555 
    3580  void erase(const size_type idx)
    3581  {
    3582  // this erase only works for arrays
    3583  if (is_array())
    3584  {
    3585  if (idx >= size())
    3586  {
    3587  throw std::out_of_range("index out of range");
    3588  }
    3589 
    3590  assert(m_value.array != nullptr);
    3591  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    3592  }
    3593  else
    3594  {
    3595  throw std::domain_error("cannot use erase() with " + type_name());
    3596  }
    3597  }
    3598 
    3616  iterator find(typename object_t::key_type key)
    3617  {
    3618  auto result = end();
    3619 
    3620  if (is_object())
    3621  {
    3622  assert(m_value.object != nullptr);
    3623  result.m_it.object_iterator = m_value.object->find(key);
    3624  }
    3625 
    3626  return result;
    3627  }
    3628 
    3633  const_iterator find(typename object_t::key_type key) const
    3634  {
    3635  auto result = cend();
    3636 
    3637  if (is_object())
    3638  {
    3639  assert(m_value.object != nullptr);
    3640  result.m_it.object_iterator = m_value.object->find(key);
    3641  }
    3642 
    3643  return result;
    3644  }
    3645 
    3664  size_type count(typename object_t::key_type key) const
    3665  {
    3666  // return 0 for all nonobject types
    3667  assert(not is_object() or m_value.object != nullptr);
    3668  return is_object() ? m_value.object->count(key) : 0;
    3669  }
    3670 
    3672 
    3673 
    3675  // iterators //
    3677 
    3680 
    3700  {
    3701  iterator result(this);
    3702  result.set_begin();
    3703  return result;
    3704  }
    3705 
    3710  {
    3711  return cbegin();
    3712  }
    3713 
    3734  {
    3735  const_iterator result(this);
    3736  result.set_begin();
    3737  return result;
    3738  }
    3739 
    3759  {
    3760  iterator result(this);
    3761  result.set_end();
    3762  return result;
    3763  }
    3764 
    3769  {
    3770  return cend();
    3771  }
    3772 
    3793  {
    3794  const_iterator result(this);
    3795  result.set_end();
    3796  return result;
    3797  }
    3798 
    3817  {
    3818  return reverse_iterator(end());
    3819  }
    3820 
    3825  {
    3826  return crbegin();
    3827  }
    3828 
    3848  {
    3849  return reverse_iterator(begin());
    3850  }
    3851 
    3856  {
    3857  return crend();
    3858  }
    3859 
    3879  {
    3880  return const_reverse_iterator(cend());
    3881  }
    3882 
    3902  {
    3903  return const_reverse_iterator(cbegin());
    3904  }
    3905 
    3906  private:
    3907  // forward declaration
    3908  template<typename IteratorType> class iteration_proxy;
    3909 
    3910  public:
    3922  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    3923  {
    3924  return iteration_proxy<iterator>(cont);
    3925  }
    3926 
    3930  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    3931  {
    3932  return iteration_proxy<const_iterator>(cont);
    3933  }
    3934 
    3936 
    3937 
    3939  // capacity //
    3941 
    3944 
    3974  bool empty() const noexcept
    3975  {
    3976  switch (m_type)
    3977  {
    3978  case value_t::null:
    3979  {
    3980  // null values are empty
    3981  return true;
    3982  }
    3983 
    3984  case value_t::array:
    3985  {
    3986  assert(m_value.array != nullptr);
    3987  return m_value.array->empty();
    3988  }
    3989 
    3990  case value_t::object:
    3991  {
    3992  assert(m_value.object != nullptr);
    3993  return m_value.object->empty();
    3994  }
    3995 
    3996  default:
    3997  {
    3998  // all other types are nonempty
    3999  return false;
    4000  }
    4001  }
    4002  }
    4003 
    4032  size_type size() const noexcept
    4033  {
    4034  switch (m_type)
    4035  {
    4036  case value_t::null:
    4037  {
    4038  // null values are empty
    4039  return 0;
    4040  }
    4041 
    4042  case value_t::array:
    4043  {
    4044  assert(m_value.array != nullptr);
    4045  return m_value.array->size();
    4046  }
    4047 
    4048  case value_t::object:
    4049  {
    4050  assert(m_value.object != nullptr);
    4051  return m_value.object->size();
    4052  }
    4053 
    4054  default:
    4055  {
    4056  // all other types have size 1
    4057  return 1;
    4058  }
    4059  }
    4060  }
    4061 
    4094  size_type max_size() const noexcept
    4095  {
    4096  switch (m_type)
    4097  {
    4098  case value_t::array:
    4099  {
    4100  assert(m_value.array != nullptr);
    4101  return m_value.array->max_size();
    4102  }
    4103 
    4104  case value_t::object:
    4105  {
    4106  assert(m_value.object != nullptr);
    4107  return m_value.object->max_size();
    4108  }
    4109 
    4110  default:
    4111  {
    4112  // all other types have max_size() == size()
    4113  return size();
    4114  }
    4115  }
    4116  }
    4117 
    4119 
    4120 
    4122  // modifiers //
    4124 
    4127 
    4153  void clear() noexcept
    4154  {
    4155  switch (m_type)
    4156  {
    4157  case value_t::number_integer:
    4158  {
    4159  m_value.number_integer = 0;
    4160  break;
    4161  }
    4162 
    4163  case value_t::number_float:
    4164  {
    4165  m_value.number_float = 0.0;
    4166  break;
    4167  }
    4168 
    4169  case value_t::boolean:
    4170  {
    4171  m_value.boolean = false;
    4172  break;
    4173  }
    4174 
    4175  case value_t::string:
    4176  {
    4177  assert(m_value.string != nullptr);
    4178  m_value.string->clear();
    4179  break;
    4180  }
    4181 
    4182  case value_t::array:
    4183  {
    4184  assert(m_value.array != nullptr);
    4185  m_value.array->clear();
    4186  break;
    4187  }
    4188 
    4189  case value_t::object:
    4190  {
    4191  assert(m_value.object != nullptr);
    4192  m_value.object->clear();
    4193  break;
    4194  }
    4195 
    4196  default:
    4197  {
    4198  break;
    4199  }
    4200  }
    4201  }
    4202 
    4223  void push_back(basic_json&& val)
    4224  {
    4225  // push_back only works for null objects or arrays
    4226  if (not(is_null() or is_array()))
    4227  {
    4228  throw std::domain_error("cannot use push_back() with " + type_name());
    4229  }
    4230 
    4231  // transform null object into an array
    4232  if (is_null())
    4233  {
    4234  m_type = value_t::array;
    4235  m_value = value_t::array;
    4236  }
    4237 
    4238  // add element to array (move semantics)
    4239  assert(m_value.array != nullptr);
    4240  m_value.array->push_back(std::move(val));
    4241  // invalidate object
    4242  val.m_type = value_t::null;
    4243  }
    4244 
    4249  reference operator+=(basic_json&& val)
    4250  {
    4251  push_back(std::move(val));
    4252  return *this;
    4253  }
    4254 
    4259  void push_back(const basic_json& val)
    4260  {
    4261  // push_back only works for null objects or arrays
    4262  if (not(is_null() or is_array()))
    4263  {
    4264  throw std::domain_error("cannot use push_back() with " + type_name());
    4265  }
    4266 
    4267  // transform null object into an array
    4268  if (is_null())
    4269  {
    4270  m_type = value_t::array;
    4271  m_value = value_t::array;
    4272  }
    4273 
    4274  // add element to array
    4275  assert(m_value.array != nullptr);
    4276  m_value.array->push_back(val);
    4277  }
    4278 
    4283  reference operator+=(const basic_json& val)
    4284  {
    4285  push_back(val);
    4286  return *this;
    4287  }
    4288 
    4309  void push_back(const typename object_t::value_type& val)
    4310  {
    4311  // push_back only works for null objects or objects
    4312  if (not(is_null() or is_object()))
    4313  {
    4314  throw std::domain_error("cannot use push_back() with " + type_name());
    4315  }
    4316 
    4317  // transform null object into an object
    4318  if (is_null())
    4319  {
    4320  m_type = value_t::object;
    4321  m_value = value_t::object;
    4322  }
    4323 
    4324  // add element to array
    4325  assert(m_value.object != nullptr);
    4326  m_value.object->insert(val);
    4327  }
    4328 
    4333  reference operator+=(const typename object_t::value_type& val)
    4334  {
    4335  push_back(val);
    4336  return operator[](val.first);
    4337  }
    4338 
    4361  iterator insert(const_iterator pos, const basic_json& val)
    4362  {
    4363  // insert only works for arrays
    4364  if (is_array())
    4365  {
    4366  // check if iterator pos fits to this JSON value
    4367  if (pos.m_object != this)
    4368  {
    4369  throw std::domain_error("iterator does not fit current value");
    4370  }
    4371 
    4372  // insert to array and return iterator
    4373  iterator result(this);
    4374  assert(m_value.array != nullptr);
    4375  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4376  return result;
    4377  }
    4378  else
    4379  {
    4380  throw std::domain_error("cannot use insert() with " + type_name());
    4381  }
    4382  }
    4383 
    4388  iterator insert(const_iterator pos, basic_json&& val)
    4389  {
    4390  return insert(pos, val);
    4391  }
    4392 
    4417  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    4418  {
    4419  // insert only works for arrays
    4420  if (is_array())
    4421  {
    4422  // check if iterator pos fits to this JSON value
    4423  if (pos.m_object != this)
    4424  {
    4425  throw std::domain_error("iterator does not fit current value");
    4426  }
    4427 
    4428  // insert to array and return iterator
    4429  iterator result(this);
    4430  assert(m_value.array != nullptr);
    4431  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    4432  return result;
    4433  }
    4434  else
    4435  {
    4436  throw std::domain_error("cannot use insert() with " + type_name());
    4437  }
    4438  }
    4439 
    4471  {
    4472  // insert only works for arrays
    4473  if (not is_array())
    4474  {
    4475  throw std::domain_error("cannot use insert() with " + type_name());
    4476  }
    4477 
    4478  // check if iterator pos fits to this JSON value
    4479  if (pos.m_object != this)
    4480  {
    4481  throw std::domain_error("iterator does not fit current value");
    4482  }
    4483 
    4484  if (first.m_object != last.m_object)
    4485  {
    4486  throw std::domain_error("iterators do not fit");
    4487  }
    4488 
    4489  if (first.m_object == this or last.m_object == this)
    4490  {
    4491  throw std::domain_error("passed iterators may not belong to container");
    4492  }
    4493 
    4494  // insert to array and return iterator
    4495  iterator result(this);
    4496  assert(m_value.array != nullptr);
    4497  result.m_it.array_iterator = m_value.array->insert(
    4498  pos.m_it.array_iterator,
    4499  first.m_it.array_iterator,
    4500  last.m_it.array_iterator);
    4501  return result;
    4502  }
    4503 
    4528  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    4529  {
    4530  // insert only works for arrays
    4531  if (not is_array())
    4532  {
    4533  throw std::domain_error("cannot use insert() with " + type_name());
    4534  }
    4535 
    4536  // check if iterator pos fits to this JSON value
    4537  if (pos.m_object != this)
    4538  {
    4539  throw std::domain_error("iterator does not fit current value");
    4540  }
    4541 
    4542  // insert to array and return iterator
    4543  iterator result(this);
    4544  assert(m_value.array != nullptr);
    4545  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    4546  return result;
    4547  }
    4548 
    4566  void swap(reference other) noexcept (
    4567  std::is_nothrow_move_constructible<value_t>::value and
    4568  std::is_nothrow_move_assignable<value_t>::value and
    4569  std::is_nothrow_move_constructible<json_value>::value and
    4570  std::is_nothrow_move_assignable<json_value>::value
    4571  )
    4572  {
    4573  std::swap(m_type, other.m_type);
    4574  std::swap(m_value, other.m_value);
    4575  }
    4576 
    4597  void swap(array_t& other)
    4598  {
    4599  // swap only works for arrays
    4600  if (is_array())
    4601  {
    4602  assert(m_value.array != nullptr);
    4603  std::swap(*(m_value.array), other);
    4604  }
    4605  else
    4606  {
    4607  throw std::domain_error("cannot use swap() with " + type_name());
    4608  }
    4609  }
    4610 
    4631  void swap(object_t& other)
    4632  {
    4633  // swap only works for objects
    4634  if (is_object())
    4635  {
    4636  assert(m_value.object != nullptr);
    4637  std::swap(*(m_value.object), other);
    4638  }
    4639  else
    4640  {
    4641  throw std::domain_error("cannot use swap() with " + type_name());
    4642  }
    4643  }
    4644 
    4665  void swap(string_t& other)
    4666  {
    4667  // swap only works for strings
    4668  if (is_string())
    4669  {
    4670  assert(m_value.string != nullptr);
    4671  std::swap(*(m_value.string), other);
    4672  }
    4673  else
    4674  {
    4675  throw std::domain_error("cannot use swap() with " + type_name());
    4676  }
    4677  }
    4678 
    4680 
    4681 
    4683  // lexicographical comparison operators //
    4685 
    4688 
    4689  private:
    4699  friend bool operator<(const value_t lhs, const value_t rhs)
    4700  {
    4701  static constexpr std::array<uint8_t, 7> order = {{
    4702  0, // null
    4703  3, // object
    4704  4, // array
    4705  5, // string
    4706  1, // boolean
    4707  2, // integer
    4708  2 // float
    4709  }
    4710  };
    4711 
    4712  // discarded values are not comparable
    4713  if (lhs == value_t::discarded or rhs == value_t::discarded)
    4714  {
    4715  return false;
    4716  }
    4717 
    4718  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    4719  }
    4720 
    4721  public:
    4745  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    4746  {
    4747  const auto lhs_type = lhs.type();
    4748  const auto rhs_type = rhs.type();
    4749 
    4750  if (lhs_type == rhs_type)
    4751  {
    4752  switch (lhs_type)
    4753  {
    4754  case value_t::array:
    4755  {
    4756  assert(lhs.m_value.array != nullptr);
    4757  assert(rhs.m_value.array != nullptr);
    4758  return *lhs.m_value.array == *rhs.m_value.array;
    4759  }
    4760  case value_t::object:
    4761  {
    4762  assert(lhs.m_value.object != nullptr);
    4763  assert(rhs.m_value.object != nullptr);
    4764  return *lhs.m_value.object == *rhs.m_value.object;
    4765  }
    4766  case value_t::null:
    4767  {
    4768  return true;
    4769  }
    4770  case value_t::string:
    4771  {
    4772  assert(lhs.m_value.string != nullptr);
    4773  assert(rhs.m_value.string != nullptr);
    4774  return *lhs.m_value.string == *rhs.m_value.string;
    4775  }
    4776  case value_t::boolean:
    4777  {
    4778  return lhs.m_value.boolean == rhs.m_value.boolean;
    4779  }
    4780  case value_t::number_integer:
    4781  {
    4782  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    4783  }
    4784  case value_t::number_float:
    4785  {
    4786  return approx(lhs.m_value.number_float, rhs.m_value.number_float);
    4787  }
    4788  default:
    4789  {
    4790  return false;
    4791  }
    4792  }
    4793  }
    4794  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    4795  {
    4796  return approx(static_cast<number_float_t>(lhs.m_value.number_integer),
    4797  rhs.m_value.number_float);
    4798  }
    4799  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    4800  {
    4801  return approx(lhs.m_value.number_float,
    4802  static_cast<number_float_t>(rhs.m_value.number_integer));
    4803  }
    4804  return false;
    4805  }
    4806 
    4825  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    4826  {
    4827  return v.is_null();
    4828  }
    4829 
    4834  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    4835  {
    4836  return v.is_null();
    4837  }
    4838 
    4855  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    4856  {
    4857  return not (lhs == rhs);
    4858  }
    4859 
    4878  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    4879  {
    4880  return not v.is_null();
    4881  }
    4882 
    4887  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    4888  {
    4889  return not v.is_null();
    4890  }
    4891 
    4916  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    4917  {
    4918  const auto lhs_type = lhs.type();
    4919  const auto rhs_type = rhs.type();
    4920 
    4921  if (lhs_type == rhs_type)
    4922  {
    4923  switch (lhs_type)
    4924  {
    4925  case value_t::array:
    4926  {
    4927  assert(lhs.m_value.array != nullptr);
    4928  assert(rhs.m_value.array != nullptr);
    4929  return *lhs.m_value.array < *rhs.m_value.array;
    4930  }
    4931  case value_t::object:
    4932  {
    4933  assert(lhs.m_value.object != nullptr);
    4934  assert(rhs.m_value.object != nullptr);
    4935  return *lhs.m_value.object < *rhs.m_value.object;
    4936  }
    4937  case value_t::null:
    4938  {
    4939  return false;
    4940  }
    4941  case value_t::string:
    4942  {
    4943  assert(lhs.m_value.string != nullptr);
    4944  assert(rhs.m_value.string != nullptr);
    4945  return *lhs.m_value.string < *rhs.m_value.string;
    4946  }
    4947  case value_t::boolean:
    4948  {
    4949  return lhs.m_value.boolean < rhs.m_value.boolean;
    4950  }
    4951  case value_t::number_integer:
    4952  {
    4953  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    4954  }
    4955  case value_t::number_float:
    4956  {
    4957  return lhs.m_value.number_float < rhs.m_value.number_float;
    4958  }
    4959  default:
    4960  {
    4961  return false;
    4962  }
    4963  }
    4964  }
    4965  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    4966  {
    4967  return static_cast<number_float_t>(lhs.m_value.number_integer) <
    4968  rhs.m_value.number_float;
    4969  }
    4970  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    4971  {
    4972  return lhs.m_value.number_float <
    4973  static_cast<number_float_t>(rhs.m_value.number_integer);
    4974  }
    4975 
    4976  // We only reach this line if we cannot compare values. In that case,
    4977  // we compare types. Note we have to call the operator explicitly,
    4978  // because MSVC has problems otherwise.
    4979  return operator<(lhs_type, rhs_type);
    4980  }
    4981 
    4999  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5000  {
    5001  return not (rhs < lhs);
    5002  }
    5003 
    5021  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5022  {
    5023  return not (lhs <= rhs);
    5024  }
    5025 
    5043  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5044  {
    5045  return not (lhs < rhs);
    5046  }
    5047 
    5049 
    5050 
    5052  // serialization //
    5054 
    5057 
    5080  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5081  {
    5082  // read width member and use it as indentation parameter if nonzero
    5083  const bool pretty_print = (o.width() > 0);
    5084  const auto indentation = (pretty_print ? o.width() : 0);
    5085 
    5086  // reset width to 0 for subsequent calls to this stream
    5087  o.width(0);
    5088 
    5089  // do the actual serialization
    5090  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5091  return o;
    5092  }
    5093 
    5098  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5099  {
    5100  return o << j;
    5101  }
    5102 
    5104 
    5105 
    5107  // deserialization //
    5109 
    5112 
    5137  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5138  {
    5139  return parser(s, cb).parse();
    5140  }
    5141 
    5166  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5167  {
    5168  return parser(i, cb).parse();
    5169  }
    5170 
    5174  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5175  {
    5176  return parser(i, cb).parse();
    5177  }
    5178 
    5202  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5203  {
    5204  j = parser(i).parse();
    5205  return i;
    5206  }
    5207 
    5212  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5213  {
    5214  j = parser(i).parse();
    5215  return i;
    5216  }
    5217 
    5219 
    5220 
    5221  private:
    5223  // convenience functions //
    5225 
    5227  string_t type_name() const
    5228  {
    5229  switch (m_type)
    5230  {
    5231  case value_t::null:
    5232  return "null";
    5233  case value_t::object:
    5234  return "object";
    5235  case value_t::array:
    5236  return "array";
    5237  case value_t::string:
    5238  return "string";
    5239  case value_t::boolean:
    5240  return "boolean";
    5241  case value_t::discarded:
    5242  return "discarded";
    5243  default:
    5244  return "number";
    5245  }
    5246  }
    5247 
    5256  static std::size_t extra_space(const string_t& s) noexcept
    5257  {
    5258  std::size_t result = 0;
    5259 
    5260  for (const auto& c : s)
    5261  {
    5262  switch (c)
    5263  {
    5264  case '"':
    5265  case '\\':
    5266  case '\b':
    5267  case '\f':
    5268  case '\n':
    5269  case '\r':
    5270  case '\t':
    5271  {
    5272  // from c (1 byte) to \x (2 bytes)
    5273  result += 1;
    5274  break;
    5275  }
    5276 
    5277  default:
    5278  {
    5279  if (c >= 0x00 and c <= 0x1f)
    5280  {
    5281  // from c (1 byte) to \uxxxx (6 bytes)
    5282  result += 5;
    5283  }
    5284  break;
    5285  }
    5286  }
    5287  }
    5288 
    5289  return result;
    5290  }
    5291 
    5305  static string_t escape_string(const string_t& s) noexcept
    5306  {
    5307  const auto space = extra_space(s);
    5308  if (space == 0)
    5309  {
    5310  return s;
    5311  }
    5312 
    5313  // create a result string of necessary size
    5314  string_t result(s.size() + space, '\\');
    5315  std::size_t pos = 0;
    5316 
    5317  for (const auto& c : s)
    5318  {
    5319  switch (c)
    5320  {
    5321  // quotation mark (0x22)
    5322  case '"':
    5323  {
    5324  result[pos + 1] = '"';
    5325  pos += 2;
    5326  break;
    5327  }
    5328 
    5329  // reverse solidus (0x5c)
    5330  case '\\':
    5331  {
    5332  // nothing to change
    5333  pos += 2;
    5334  break;
    5335  }
    5336 
    5337  // backspace (0x08)
    5338  case '\b':
    5339  {
    5340  result[pos + 1] = 'b';
    5341  pos += 2;
    5342  break;
    5343  }
    5344 
    5345  // formfeed (0x0c)
    5346  case '\f':
    5347  {
    5348  result[pos + 1] = 'f';
    5349  pos += 2;
    5350  break;
    5351  }
    5352 
    5353  // newline (0x0a)
    5354  case '\n':
    5355  {
    5356  result[pos + 1] = 'n';
    5357  pos += 2;
    5358  break;
    5359  }
    5360 
    5361  // carriage return (0x0d)
    5362  case '\r':
    5363  {
    5364  result[pos + 1] = 'r';
    5365  pos += 2;
    5366  break;
    5367  }
    5368 
    5369  // horizontal tab (0x09)
    5370  case '\t':
    5371  {
    5372  result[pos + 1] = 't';
    5373  pos += 2;
    5374  break;
    5375  }
    5376 
    5377  default:
    5378  {
    5379  if (c >= 0x00 and c <= 0x1f)
    5380  {
    5381  // convert a number 0..15 to its hex representation (0..f)
    5382  auto hexify = [](const char v) -> char
    5383  {
    5384  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    5385  };
    5386 
    5387  // print character c as \uxxxx
    5388  for (const char m :
    5389  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    5390  })
    5391  {
    5392  result[++pos] = m;
    5393  }
    5394 
    5395  ++pos;
    5396  }
    5397  else
    5398  {
    5399  // all other characters are added as-is
    5400  result[pos++] = c;
    5401  }
    5402  break;
    5403  }
    5404  }
    5405  }
    5406 
    5407  return result;
    5408  }
    5409 
    5427  void dump(std::ostream& o,
    5428  const bool pretty_print,
    5429  const unsigned int indent_step,
    5430  const unsigned int current_indent = 0) const
    5431  {
    5432  // variable to hold indentation for recursive calls
    5433  unsigned int new_indent = current_indent;
    5434 
    5435  switch (m_type)
    5436  {
    5437  case value_t::object:
    5438  {
    5439  assert(m_value.object != nullptr);
    5440 
    5441  if (m_value.object->empty())
    5442  {
    5443  o << "{}";
    5444  return;
    5445  }
    5446 
    5447  o << "{";
    5448 
    5449  // increase indentation
    5450  if (pretty_print)
    5451  {
    5452  new_indent += indent_step;
    5453  o << "\n";
    5454  }
    5455 
    5456  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    5457  {
    5458  if (i != m_value.object->cbegin())
    5459  {
    5460  o << (pretty_print ? ",\n" : ",");
    5461  }
    5462  o << string_t(new_indent, ' ') << "\""
    5463  << escape_string(i->first) << "\":"
    5464  << (pretty_print ? " " : "");
    5465  i->second.dump(o, pretty_print, indent_step, new_indent);
    5466  }
    5467 
    5468  // decrease indentation
    5469  if (pretty_print)
    5470  {
    5471  new_indent -= indent_step;
    5472  o << "\n";
    5473  }
    5474 
    5475  o << string_t(new_indent, ' ') + "}";
    5476  return;
    5477  }
    5478 
    5479  case value_t::array:
    5480  {
    5481  assert(m_value.array != nullptr);
    5482 
    5483  if (m_value.array->empty())
    5484  {
    5485  o << "[]";
    5486  return;
    5487  }
    5488 
    5489  o << "[";
    5490 
    5491  // increase indentation
    5492  if (pretty_print)
    5493  {
    5494  new_indent += indent_step;
    5495  o << "\n";
    5496  }
    5497 
    5498  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    5499  {
    5500  if (i != m_value.array->cbegin())
    5501  {
    5502  o << (pretty_print ? ",\n" : ",");
    5503  }
    5504  o << string_t(new_indent, ' ');
    5505  i->dump(o, pretty_print, indent_step, new_indent);
    5506  }
    5507 
    5508  // decrease indentation
    5509  if (pretty_print)
    5510  {
    5511  new_indent -= indent_step;
    5512  o << "\n";
    5513  }
    5514 
    5515  o << string_t(new_indent, ' ') << "]";
    5516  return;
    5517  }
    5518 
    5519  case value_t::string:
    5520  {
    5521  assert(m_value.string != nullptr);
    5522  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    5523  return;
    5524  }
    5525 
    5526  case value_t::boolean:
    5527  {
    5528  o << (m_value.boolean ? "true" : "false");
    5529  return;
    5530  }
    5531 
    5532  case value_t::number_integer:
    5533  {
    5534  o << m_value.number_integer;
    5535  return;
    5536  }
    5537 
    5538  case value_t::number_float:
    5539  {
    5540  // 15 digits of precision allows round-trip IEEE 754
    5541  // string->double->string; to be safe, we read this value from
    5542  // std::numeric_limits<number_float_t>::digits10
    5543  o << std::setprecision(std::numeric_limits<number_float_t>::digits10) << m_value.number_float;
    5544  return;
    5545  }
    5546 
    5547  case value_t::discarded:
    5548  {
    5549  o << "<discarded>";
    5550  return;
    5551  }
    5552 
    5553  case value_t::null:
    5554  {
    5555  o << "null";
    5556  return;
    5557  }
    5558  }
    5559  }
    5560 
    5561  private:
    5563  // member variables //
    5565 
    5567  value_t m_type = value_t::null;
    5568 
    5570  json_value m_value = {};
    5571 
    5572 
    5573  private:
    5575  // iterators //
    5577 
    5587  class primitive_iterator_t
    5588  {
    5589  public:
    5591  void set_begin()
    5592  {
    5593  m_it = begin_value;
    5594  }
    5595 
    5597  void set_end()
    5598  {
    5599  m_it = end_value;
    5600  }
    5601 
    5603  bool is_begin() const
    5604  {
    5605  return (m_it == begin_value);
    5606  }
    5607 
    5609  bool is_end() const
    5610  {
    5611  return (m_it == end_value);
    5612  }
    5613 
    5615  operator difference_type& ()
    5616  {
    5617  return m_it;
    5618  }
    5619 
    5621  operator difference_type () const
    5622  {
    5623  return m_it;
    5624  }
    5625 
    5626  private:
    5627  static constexpr difference_type begin_value = 0;
    5628  static constexpr difference_type end_value = begin_value + 1;
    5629 
    5631  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    5632  };
    5633 
    5641  struct internal_iterator
    5642  {
    5644  typename object_t::iterator object_iterator;
    5646  typename array_t::iterator array_iterator;
    5648  primitive_iterator_t primitive_iterator;
    5649 
    5651  internal_iterator()
    5652  : object_iterator(), array_iterator(), primitive_iterator()
    5653  {}
    5654  };
    5655 
    5657  template<typename IteratorType>
    5658  class iteration_proxy
    5659  {
    5660  private:
    5662  class iteration_proxy_internal
    5663  {
    5664  private:
    5666  IteratorType anchor;
    5668  size_t array_index = 0;
    5669 
    5670  public:
    5671  iteration_proxy_internal(IteratorType it)
    5672  : anchor(it)
    5673  {}
    5674 
    5676  iteration_proxy_internal& operator*()
    5677  {
    5678  return *this;
    5679  }
    5680 
    5682  iteration_proxy_internal& operator++()
    5683  {
    5684  ++anchor;
    5685  ++array_index;
    5686 
    5687  return *this;
    5688  }
    5689 
    5691  bool operator!= (const iteration_proxy_internal& o) const
    5692  {
    5693  return anchor != o.anchor;
    5694  }
    5695 
    5697  typename basic_json::string_t key() const
    5698  {
    5699  assert(anchor.m_object != nullptr);
    5700 
    5701  switch (anchor.m_object->type())
    5702  {
    5703  // use integer array index as key
    5704  case value_t::array:
    5705  {
    5706  return std::to_string(array_index);
    5707  }
    5708 
    5709  // use key from the object
    5710  case value_t::object:
    5711  {
    5712  return anchor.key();
    5713  }
    5714 
    5715  // use an empty key for all primitive types
    5716  default:
    5717  {
    5718  return "";
    5719  }
    5720  }
    5721  }
    5722 
    5724  typename IteratorType::reference value() const
    5725  {
    5726  return anchor.value();
    5727  }
    5728  };
    5729 
    5731  typename IteratorType::reference container;
    5732 
    5733  public:
    5735  iteration_proxy(typename IteratorType::reference cont)
    5736  : container(cont)
    5737  {}
    5738 
    5740  iteration_proxy_internal begin()
    5741  {
    5742  return iteration_proxy_internal(container.begin());
    5743  }
    5744 
    5746  iteration_proxy_internal end()
    5747  {
    5748  return iteration_proxy_internal(container.end());
    5749  }
    5750  };
    5751 
    5752  public:
    5766  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    5767  {
    5769  friend class basic_json;
    5770 
    5771  public:
    5781  using iterator_category = std::bidirectional_iterator_tag;
    5782 
    5784  const_iterator() = default;
    5785 
    5787  const_iterator(pointer object) : m_object(object)
    5788  {
    5789  assert(m_object != nullptr);
    5790 
    5791  switch (m_object->m_type)
    5792  {
    5794  {
    5795  m_it.object_iterator = typename object_t::iterator();
    5796  break;
    5797  }
    5798 
    5800  {
    5801  m_it.array_iterator = typename array_t::iterator();
    5802  break;
    5803  }
    5804 
    5805  default:
    5806  {
    5807  m_it.primitive_iterator = primitive_iterator_t();
    5808  break;
    5809  }
    5810  }
    5811  }
    5812 
    5814  const_iterator(const iterator& other) : m_object(other.m_object)
    5815  {
    5816  assert(m_object != nullptr);
    5817 
    5818  switch (m_object->m_type)
    5819  {
    5821  {
    5822  m_it.object_iterator = other.m_it.object_iterator;
    5823  break;
    5824  }
    5825 
    5827  {
    5828  m_it.array_iterator = other.m_it.array_iterator;
    5829  break;
    5830  }
    5831 
    5832  default:
    5833  {
    5834  m_it.primitive_iterator = other.m_it.primitive_iterator;
    5835  break;
    5836  }
    5837  }
    5838  }
    5839 
    5841  const_iterator(const const_iterator& other) noexcept
    5842  : m_object(other.m_object), m_it(other.m_it)
    5843  {}
    5844 
    5847  std::is_nothrow_move_constructible<pointer>::value and
    5848  std::is_nothrow_move_assignable<pointer>::value and
    5849  std::is_nothrow_move_constructible<internal_iterator>::value and
    5850  std::is_nothrow_move_assignable<internal_iterator>::value
    5851  )
    5852  {
    5853  std::swap(m_object, other.m_object);
    5854  std::swap(m_it, other.m_it);
    5855  return *this;
    5856  }
    5857 
    5858  private:
    5860  void set_begin()
    5861  {
    5862  assert(m_object != nullptr);
    5863 
    5864  switch (m_object->m_type)
    5865  {
    5867  {
    5868  assert(m_object->m_value.object != nullptr);
    5869  m_it.object_iterator = m_object->m_value.object->begin();
    5870  break;
    5871  }
    5872 
    5874  {
    5875  assert(m_object->m_value.array != nullptr);
    5876  m_it.array_iterator = m_object->m_value.array->begin();
    5877  break;
    5878  }
    5879 
    5881  {
    5882  // set to end so begin()==end() is true: null is empty
    5883  m_it.primitive_iterator.set_end();
    5884  break;
    5885  }
    5886 
    5887  default:
    5888  {
    5889  m_it.primitive_iterator.set_begin();
    5890  break;
    5891  }
    5892  }
    5893  }
    5894 
    5896  void set_end()
    5897  {
    5898  assert(m_object != nullptr);
    5899 
    5900  switch (m_object->m_type)
    5901  {
    5903  {
    5904  assert(m_object->m_value.object != nullptr);
    5905  m_it.object_iterator = m_object->m_value.object->end();
    5906  break;
    5907  }
    5908 
    5910  {
    5911  assert(m_object->m_value.array != nullptr);
    5912  m_it.array_iterator = m_object->m_value.array->end();
    5913  break;
    5914  }
    5915 
    5916  default:
    5917  {
    5918  m_it.primitive_iterator.set_end();
    5919  break;
    5920  }
    5921  }
    5922  }
    5923 
    5924  public:
    5927  {
    5928  assert(m_object != nullptr);
    5929 
    5930  switch (m_object->m_type)
    5931  {
    5933  {
    5934  assert(m_object->m_value.object);
    5935  assert(m_it.object_iterator != m_object->m_value.object->end());
    5936  return m_it.object_iterator->second;
    5937  }
    5938 
    5940  {
    5941  assert(m_object->m_value.array);
    5942  assert(m_it.array_iterator != m_object->m_value.array->end());
    5943  return *m_it.array_iterator;
    5944  }
    5945 
    5947  {
    5948  throw std::out_of_range("cannot get value");
    5949  }
    5950 
    5951  default:
    5952  {
    5953  if (m_it.primitive_iterator.is_begin())
    5954  {
    5955  return *m_object;
    5956  }
    5957  else
    5958  {
    5959  throw std::out_of_range("cannot get value");
    5960  }
    5961  }
    5962  }
    5963  }
    5964 
    5967  {
    5968  assert(m_object != nullptr);
    5969 
    5970  switch (m_object->m_type)
    5971  {
    5973  {
    5974  assert(m_object->m_value.object);
    5975  assert(m_it.object_iterator != m_object->m_value.object->end());
    5976  return &(m_it.object_iterator->second);
    5977  }
    5978 
    5980  {
    5981  assert(m_object->m_value.array);
    5982  assert(m_it.array_iterator != m_object->m_value.array->end());
    5983  return &*m_it.array_iterator;
    5984  }
    5985 
    5986  default:
    5987  {
    5988  if (m_it.primitive_iterator.is_begin())
    5989  {
    5990  return m_object;
    5991  }
    5992  else
    5993  {
    5994  throw std::out_of_range("cannot get value");
    5995  }
    5996  }
    5997  }
    5998  }
    5999 
    6002  {
    6003  auto result = *this;
    6004  ++(*this);
    6005  return result;
    6006  }
    6007 
    6010  {
    6011  assert(m_object != nullptr);
    6012 
    6013  switch (m_object->m_type)
    6014  {
    6016  {
    6017  ++m_it.object_iterator;
    6018  break;
    6019  }
    6020 
    6022  {
    6023  ++m_it.array_iterator;
    6024  break;
    6025  }
    6026 
    6027  default:
    6028  {
    6029  ++m_it.primitive_iterator;
    6030  break;
    6031  }
    6032  }
    6033 
    6034  return *this;
    6035  }
    6036 
    6039  {
    6040  auto result = *this;
    6041  --(*this);
    6042  return result;
    6043  }
    6044 
    6047  {
    6048  assert(m_object != nullptr);
    6049 
    6050  switch (m_object->m_type)
    6051  {
    6053  {
    6054  --m_it.object_iterator;
    6055  break;
    6056  }
    6057 
    6059  {
    6060  --m_it.array_iterator;
    6061  break;
    6062  }
    6063 
    6064  default:
    6065  {
    6066  --m_it.primitive_iterator;
    6067  break;
    6068  }
    6069  }
    6070 
    6071  return *this;
    6072  }
    6073 
    6075  bool operator==(const const_iterator& other) const
    6076  {
    6077  // if objects are not the same, the comparison is undefined
    6078  if (m_object != other.m_object)
    6079  {
    6080  throw std::domain_error("cannot compare iterators of different containers");
    6081  }
    6082 
    6083  assert(m_object != nullptr);
    6084 
    6085  switch (m_object->m_type)
    6086  {
    6088  {
    6089  return (m_it.object_iterator == other.m_it.object_iterator);
    6090  }
    6091 
    6093  {
    6094  return (m_it.array_iterator == other.m_it.array_iterator);
    6095  }
    6096 
    6097  default:
    6098  {
    6099  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6100  }
    6101  }
    6102  }
    6103 
    6105  bool operator!=(const const_iterator& other) const
    6106  {
    6107  return not operator==(other);
    6108  }
    6109 
    6111  bool operator<(const const_iterator& other) const
    6112  {
    6113  // if objects are not the same, the comparison is undefined
    6114  if (m_object != other.m_object)
    6115  {
    6116  throw std::domain_error("cannot compare iterators of different containers");
    6117  }
    6118 
    6119  assert(m_object != nullptr);
    6120 
    6121  switch (m_object->m_type)
    6122  {
    6124  {
    6125  throw std::domain_error("cannot compare order of object iterators");
    6126  }
    6127 
    6129  {
    6130  return (m_it.array_iterator < other.m_it.array_iterator);
    6131  }
    6132 
    6133  default:
    6134  {
    6135  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6136  }
    6137  }
    6138  }
    6139 
    6141  bool operator<=(const const_iterator& other) const
    6142  {
    6143  return not other.operator < (*this);
    6144  }
    6145 
    6147  bool operator>(const const_iterator& other) const
    6148  {
    6149  return not operator<=(other);
    6150  }
    6151 
    6153  bool operator>=(const const_iterator& other) const
    6154  {
    6155  return not operator<(other);
    6156  }
    6157 
    6160  {
    6161  assert(m_object != nullptr);
    6162 
    6163  switch (m_object->m_type)
    6164  {
    6166  {
    6167  throw std::domain_error("cannot use offsets with object iterators");
    6168  }
    6169 
    6171  {
    6172  m_it.array_iterator += i;
    6173  break;
    6174  }
    6175 
    6176  default:
    6177  {
    6178  m_it.primitive_iterator += i;
    6179  break;
    6180  }
    6181  }
    6182 
    6183  return *this;
    6184  }
    6185 
    6188  {
    6189  return operator+=(-i);
    6190  }
    6191 
    6194  {
    6195  auto result = *this;
    6196  result += i;
    6197  return result;
    6198  }
    6199 
    6202  {
    6203  auto result = *this;
    6204  result -= i;
    6205  return result;
    6206  }
    6207 
    6210  {
    6211  assert(m_object != nullptr);
    6212 
    6213  switch (m_object->m_type)
    6214  {
    6216  {
    6217  throw std::domain_error("cannot use offsets with object iterators");
    6218  }
    6219 
    6221  {
    6222  return m_it.array_iterator - other.m_it.array_iterator;
    6223  }
    6224 
    6225  default:
    6226  {
    6227  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6228  }
    6229  }
    6230  }
    6231 
    6234  {
    6235  assert(m_object != nullptr);
    6236 
    6237  switch (m_object->m_type)
    6238  {
    6240  {
    6241  throw std::domain_error("cannot use operator[] for object iterators");
    6242  }
    6243 
    6245  {
    6246  return *(m_it.array_iterator + n);
    6247  }
    6248 
    6250  {
    6251  throw std::out_of_range("cannot get value");
    6252  }
    6253 
    6254  default:
    6255  {
    6256  if (m_it.primitive_iterator == -n)
    6257  {
    6258  return *m_object;
    6259  }
    6260  else
    6261  {
    6262  throw std::out_of_range("cannot get value");
    6263  }
    6264  }
    6265  }
    6266  }
    6267 
    6269  typename object_t::key_type key() const
    6270  {
    6271  assert(m_object != nullptr);
    6272 
    6273  if (m_object->is_object())
    6274  {
    6275  return m_it.object_iterator->first;
    6276  }
    6277  else
    6278  {
    6279  throw std::domain_error("cannot use key() for non-object iterators");
    6280  }
    6281  }
    6282 
    6285  {
    6286  return operator*();
    6287  }
    6288 
    6289  private:
    6291  pointer m_object = nullptr;
    6293  internal_iterator m_it = internal_iterator();
    6294  };
    6295 
    6308  class iterator : public const_iterator
    6309  {
    6310  public:
    6312  using pointer = typename basic_json::pointer;
    6314 
    6316  iterator() = default;
    6317 
    6319  iterator(pointer object) noexcept
    6320  : base_iterator(object)
    6321  {}
    6322 
    6324  iterator(const iterator& other) noexcept
    6325  : base_iterator(other)
    6326  {}
    6327 
    6329  iterator& operator=(iterator other) noexcept(
    6330  std::is_nothrow_move_constructible<pointer>::value and
    6331  std::is_nothrow_move_assignable<pointer>::value and
    6332  std::is_nothrow_move_constructible<internal_iterator>::value and
    6333  std::is_nothrow_move_assignable<internal_iterator>::value
    6334  )
    6335  {
    6336  base_iterator::operator=(other);
    6337  return *this;
    6338  }
    6339 
    6342  {
    6343  return const_cast<reference>(base_iterator::operator*());
    6344  }
    6345 
    6348  {
    6349  return const_cast<pointer>(base_iterator::operator->());
    6350  }
    6351 
    6354  {
    6355  iterator result = *this;
    6356  base_iterator::operator++();
    6357  return result;
    6358  }
    6359 
    6362  {
    6363  base_iterator::operator++();
    6364  return *this;
    6365  }
    6366 
    6369  {
    6370  iterator result = *this;
    6371  base_iterator::operator--();
    6372  return result;
    6373  }
    6374 
    6377  {
    6378  base_iterator::operator--();
    6379  return *this;
    6380  }
    6381 
    6384  {
    6385  base_iterator::operator+=(i);
    6386  return *this;
    6387  }
    6388 
    6391  {
    6392  base_iterator::operator-=(i);
    6393  return *this;
    6394  }
    6395 
    6398  {
    6399  auto result = *this;
    6400  result += i;
    6401  return result;
    6402  }
    6403 
    6406  {
    6407  auto result = *this;
    6408  result -= i;
    6409  return result;
    6410  }
    6411 
    6412  difference_type operator-(const iterator& other) const
    6413  {
    6414  return base_iterator::operator-(other);
    6415  }
    6416 
    6419  {
    6420  return const_cast<reference>(base_iterator::operator[](n));
    6421  }
    6422 
    6425  {
    6426  return const_cast<reference>(base_iterator::value());
    6427  }
    6428  };
    6429 
    6447  template<typename Base>
    6448  class json_reverse_iterator : public std::reverse_iterator<Base>
    6449  {
    6450  public:
    6452  using base_iterator = std::reverse_iterator<Base>;
    6454  using reference = typename Base::reference;
    6455 
    6457  json_reverse_iterator(const typename base_iterator::iterator_type& it)
    6458  : base_iterator(it)
    6459  {}
    6460 
    6463  : base_iterator(it)
    6464  {}
    6465 
    6468  {
    6469  return base_iterator::operator++(1);
    6470  }
    6471 
    6474  {
    6475  base_iterator::operator++();
    6476  return *this;
    6477  }
    6478 
    6481  {
    6482  return base_iterator::operator--(1);
    6483  }
    6484 
    6487  {
    6488  base_iterator::operator--();
    6489  return *this;
    6490  }
    6491 
    6494  {
    6495  base_iterator::operator+=(i);
    6496  return *this;
    6497  }
    6498 
    6501  {
    6502  auto result = *this;
    6503  result += i;
    6504  return result;
    6505  }
    6506 
    6509  {
    6510  auto result = *this;
    6511  result -= i;
    6512  return result;
    6513  }
    6514 
    6517  {
    6518  return this->base() - other.base();
    6519  }
    6520 
    6523  {
    6524  return *(this->operator+(n));
    6525  }
    6526 
    6528  typename object_t::key_type key() const
    6529  {
    6530  auto it = --this->base();
    6531  return it.key();
    6532  }
    6533 
    6536  {
    6537  auto it = --this->base();
    6538  return it.operator * ();
    6539  }
    6540  };
    6541 
    6542 
    6543  private:
    6545  // lexer and parser //
    6547 
    6555  class lexer
    6556  {
    6557  public:
    6559  enum class token_type
    6560  {
    6561  uninitialized,
    6562  literal_true,
    6563  literal_false,
    6564  literal_null,
    6565  value_string,
    6566  value_number,
    6567  begin_array,
    6568  begin_object,
    6569  end_array,
    6570  end_object,
    6571  name_separator,
    6572  value_separator,
    6573  parse_error,
    6574  end_of_input
    6575  };
    6576 
    6578  using lexer_char_t = unsigned char;
    6579 
    6581  explicit lexer(const string_t& s) noexcept
    6582  : m_stream(nullptr), m_buffer(s)
    6583  {
    6584  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    6585  assert(m_content != nullptr);
    6586  m_start = m_cursor = m_content;
    6587  m_limit = m_content + s.size();
    6588  }
    6589 
    6591  explicit lexer(std::istream* s) noexcept
    6592  : m_stream(s), m_buffer()
    6593  {
    6594  assert(m_stream != nullptr);
    6595  getline(*m_stream, m_buffer);
    6596  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    6597  assert(m_content != nullptr);
    6598  m_start = m_cursor = m_content;
    6599  m_limit = m_content + m_buffer.size();
    6600  }
    6601 
    6603  lexer() = default;
    6604 
    6605  // switch off unwanted functions
    6606  lexer(const lexer&) = delete;
    6607  lexer operator=(const lexer&) = delete;
    6608 
    6624  static string_t to_unicode(const std::size_t codepoint1,
    6625  const std::size_t codepoint2 = 0)
    6626  {
    6627  string_t result;
    6628 
    6629  // calculate the codepoint from the given code points
    6630  std::size_t codepoint = codepoint1;
    6631 
    6632  // check if codepoint1 is a high surrogate
    6633  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    6634  {
    6635  // check if codepoint2 is a low surrogate
    6636  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    6637  {
    6638  codepoint =
    6639  // high surrogate occupies the most significant 22 bits
    6640  (codepoint1 << 10)
    6641  // low surrogate occupies the least significant 15 bits
    6642  + codepoint2
    6643  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    6644  // in the result so we have to subtract with:
    6645  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    6646  - 0x35FDC00;
    6647  }
    6648  else
    6649  {
    6650  throw std::invalid_argument("missing or wrong low surrogate");
    6651  }
    6652  }
    6653 
    6654  if (codepoint < 0x80)
    6655  {
    6656  // 1-byte characters: 0xxxxxxx (ASCII)
    6657  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    6658  }
    6659  else if (codepoint <= 0x7ff)
    6660  {
    6661  // 2-byte characters: 110xxxxx 10xxxxxx
    6662  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    6663  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6664  }
    6665  else if (codepoint <= 0xffff)
    6666  {
    6667  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    6668  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    6669  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    6670  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6671  }
    6672  else if (codepoint <= 0x10ffff)
    6673  {
    6674  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    6675  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    6676  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    6677  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    6678  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    6679  }
    6680  else
    6681  {
    6682  throw std::out_of_range("code points above 0x10FFFF are invalid");
    6683  }
    6684 
    6685  return result;
    6686  }
    6687 
    6689  static std::string token_type_name(token_type t)
    6690  {
    6691  switch (t)
    6692  {
    6693  case token_type::uninitialized:
    6694  return "<uninitialized>";
    6695  case token_type::literal_true:
    6696  return "true literal";
    6697  case token_type::literal_false:
    6698  return "false literal";
    6699  case token_type::literal_null:
    6700  return "null literal";
    6701  case token_type::value_string:
    6702  return "string literal";
    6703  case token_type::value_number:
    6704  return "number literal";
    6705  case token_type::begin_array:
    6706  return "'['";
    6707  case token_type::begin_object:
    6708  return "'{'";
    6709  case token_type::end_array:
    6710  return "']'";
    6711  case token_type::end_object:
    6712  return "'}'";
    6713  case token_type::name_separator:
    6714  return "':'";
    6715  case token_type::value_separator:
    6716  return "','";
    6717  case token_type::parse_error:
    6718  return "<parse error>";
    6719  case token_type::end_of_input:
    6720  return "end of input";
    6721  default:
    6722  {
    6723  // catch non-enum values
    6724  return "unknown token"; // LCOV_EXCL_LINE
    6725  }
    6726  }
    6727  }
    6728 
    6739  token_type scan() noexcept
    6740  {
    6741  // pointer for backtracking information
    6742  m_marker = nullptr;
    6743 
    6744  // remember the begin of the token
    6745  m_start = m_cursor;
    6746  assert(m_start != nullptr);
    6747 
    6748 
    6749  {
    6750  lexer_char_t yych;
    6751  unsigned int yyaccept = 0;
    6752  static const unsigned char yybm[] =
    6753  {
    6754  0, 0, 0, 0, 0, 0, 0, 0,
    6755  0, 32, 32, 0, 0, 32, 0, 0,
    6756  64, 64, 64, 64, 64, 64, 64, 64,
    6757  64, 64, 64, 64, 64, 64, 64, 64,
    6758  96, 64, 0, 64, 64, 64, 64, 64,
    6759  64, 64, 64, 64, 64, 64, 64, 64,
    6760  192, 192, 192, 192, 192, 192, 192, 192,
    6761  192, 192, 64, 64, 64, 64, 64, 64,
    6762  64, 64, 64, 64, 64, 64, 64, 64,
    6763  64, 64, 64, 64, 64, 64, 64, 64,
    6764  64, 64, 64, 64, 64, 64, 64, 64,
    6765  64, 64, 64, 64, 0, 64, 64, 64,
    6766  64, 64, 64, 64, 64, 64, 64, 64,
    6767  64, 64, 64, 64, 64, 64, 64, 64,
    6768  64, 64, 64, 64, 64, 64, 64, 64,
    6769  64, 64, 64, 64, 64, 64, 64, 64,
    6770  64, 64, 64, 64, 64, 64, 64, 64,
    6771  64, 64, 64, 64, 64, 64, 64, 64,
    6772  64, 64, 64, 64, 64, 64, 64, 64,
    6773  64, 64, 64, 64, 64, 64, 64, 64,
    6774  64, 64, 64, 64, 64, 64, 64, 64,
    6775  64, 64, 64, 64, 64, 64, 64, 64,
    6776  64, 64, 64, 64, 64, 64, 64, 64,
    6777  64, 64, 64, 64, 64, 64, 64, 64,
    6778  64, 64, 64, 64, 64, 64, 64, 64,
    6779  64, 64, 64, 64, 64, 64, 64, 64,
    6780  64, 64, 64, 64, 64, 64, 64, 64,
    6781  64, 64, 64, 64, 64, 64, 64, 64,
    6782  64, 64, 64, 64, 64, 64, 64, 64,
    6783  64, 64, 64, 64, 64, 64, 64, 64,
    6784  64, 64, 64, 64, 64, 64, 64, 64,
    6785  64, 64, 64, 64, 64, 64, 64, 64,
    6786  };
    6787  if ((m_limit - m_cursor) < 5)
    6788  {
    6789  yyfill(); // LCOV_EXCL_LINE;
    6790  }
    6791  yych = *m_cursor;
    6792  if (yych <= ':')
    6793  {
    6794  if (yych <= ' ')
    6795  {
    6796  if (yych <= '\n')
    6797  {
    6798  if (yych <= 0x00)
    6799  {
    6800  goto basic_json_parser_28;
    6801  }
    6802  if (yych <= 0x08)
    6803  {
    6804  goto basic_json_parser_30;
    6805  }
    6806  if (yych >= '\n')
    6807  {
    6808  goto basic_json_parser_4;
    6809  }
    6810  }
    6811  else
    6812  {
    6813  if (yych == '\r')
    6814  {
    6815  goto basic_json_parser_2;
    6816  }
    6817  if (yych <= 0x1F)
    6818  {
    6819  goto basic_json_parser_30;
    6820  }
    6821  }
    6822  }
    6823  else
    6824  {
    6825  if (yych <= ',')
    6826  {
    6827  if (yych == '"')
    6828  {
    6829  goto basic_json_parser_27;
    6830  }
    6831  if (yych <= '+')
    6832  {
    6833  goto basic_json_parser_30;
    6834  }
    6835  goto basic_json_parser_16;
    6836  }
    6837  else
    6838  {
    6839  if (yych <= '/')
    6840  {
    6841  if (yych <= '-')
    6842  {
    6843  goto basic_json_parser_23;
    6844  }
    6845  goto basic_json_parser_30;
    6846  }
    6847  else
    6848  {
    6849  if (yych <= '0')
    6850  {
    6851  goto basic_json_parser_24;
    6852  }
    6853  if (yych <= '9')
    6854  {
    6855  goto basic_json_parser_26;
    6856  }
    6857  goto basic_json_parser_18;
    6858  }
    6859  }
    6860  }
    6861  }
    6862  else
    6863  {
    6864  if (yych <= 'n')
    6865  {
    6866  if (yych <= ']')
    6867  {
    6868  if (yych == '[')
    6869  {
    6870  goto basic_json_parser_8;
    6871  }
    6872  if (yych <= '\\')
    6873  {
    6874  goto basic_json_parser_30;
    6875  }
    6876  goto basic_json_parser_10;
    6877  }
    6878  else
    6879  {
    6880  if (yych == 'f')
    6881  {
    6882  goto basic_json_parser_22;
    6883  }
    6884  if (yych <= 'm')
    6885  {
    6886  goto basic_json_parser_30;
    6887  }
    6888  goto basic_json_parser_20;
    6889  }
    6890  }
    6891  else
    6892  {
    6893  if (yych <= '{')
    6894  {
    6895  if (yych == 't')
    6896  {
    6897  goto basic_json_parser_21;
    6898  }
    6899  if (yych <= 'z')
    6900  {
    6901  goto basic_json_parser_30;
    6902  }
    6903  goto basic_json_parser_12;
    6904  }
    6905  else
    6906  {
    6907  if (yych <= '}')
    6908  {
    6909  if (yych <= '|')
    6910  {
    6911  goto basic_json_parser_30;
    6912  }
    6913  goto basic_json_parser_14;
    6914  }
    6915  else
    6916  {
    6917  if (yych == 0xEF)
    6918  {
    6919  goto basic_json_parser_6;
    6920  }
    6921  goto basic_json_parser_30;
    6922  }
    6923  }
    6924  }
    6925  }
    6926 basic_json_parser_2:
    6927  ++m_cursor;
    6928  yych = *m_cursor;
    6929  goto basic_json_parser_5;
    6930 basic_json_parser_3:
    6931  {
    6932  return scan();
    6933  }
    6934 basic_json_parser_4:
    6935  ++m_cursor;
    6936  if (m_limit <= m_cursor)
    6937  {
    6938  yyfill(); // LCOV_EXCL_LINE;
    6939  }
    6940  yych = *m_cursor;
    6941 basic_json_parser_5:
    6942  if (yybm[0 + yych] & 32)
    6943  {
    6944  goto basic_json_parser_4;
    6945  }
    6946  goto basic_json_parser_3;
    6947 basic_json_parser_6:
    6948  yyaccept = 0;
    6949  yych = *(m_marker = ++m_cursor);
    6950  if (yych == 0xBB)
    6951  {
    6952  goto basic_json_parser_64;
    6953  }
    6954 basic_json_parser_7:
    6955  {
    6956  return token_type::parse_error;
    6957  }
    6958 basic_json_parser_8:
    6959  ++m_cursor;
    6960  {
    6961  return token_type::begin_array;
    6962  }
    6963 basic_json_parser_10:
    6964  ++m_cursor;
    6965  {
    6966  return token_type::end_array;
    6967  }
    6968 basic_json_parser_12:
    6969  ++m_cursor;
    6970  {
    6971  return token_type::begin_object;
    6972  }
    6973 basic_json_parser_14:
    6974  ++m_cursor;
    6975  {
    6976  return token_type::end_object;
    6977  }
    6978 basic_json_parser_16:
    6979  ++m_cursor;
    6980  {
    6981  return token_type::value_separator;
    6982  }
    6983 basic_json_parser_18:
    6984  ++m_cursor;
    6985  {
    6986  return token_type::name_separator;
    6987  }
    6988 basic_json_parser_20:
    6989  yyaccept = 0;
    6990  yych = *(m_marker = ++m_cursor);
    6991  if (yych == 'u')
    6992  {
    6993  goto basic_json_parser_60;
    6994  }
    6995  goto basic_json_parser_7;
    6996 basic_json_parser_21:
    6997  yyaccept = 0;
    6998  yych = *(m_marker = ++m_cursor);
    6999  if (yych == 'r')
    7000  {
    7001  goto basic_json_parser_56;
    7002  }
    7003  goto basic_json_parser_7;
    7004 basic_json_parser_22:
    7005  yyaccept = 0;
    7006  yych = *(m_marker = ++m_cursor);
    7007  if (yych == 'a')
    7008  {
    7009  goto basic_json_parser_51;
    7010  }
    7011  goto basic_json_parser_7;
    7012 basic_json_parser_23:
    7013  yych = *++m_cursor;
    7014  if (yych <= '/')
    7015  {
    7016  goto basic_json_parser_7;
    7017  }
    7018  if (yych <= '0')
    7019  {
    7020  goto basic_json_parser_50;
    7021  }
    7022  if (yych <= '9')
    7023  {
    7024  goto basic_json_parser_41;
    7025  }
    7026  goto basic_json_parser_7;
    7027 basic_json_parser_24:
    7028  yyaccept = 1;
    7029  yych = *(m_marker = ++m_cursor);
    7030  if (yych <= 'D')
    7031  {
    7032  if (yych == '.')
    7033  {
    7034  goto basic_json_parser_43;
    7035  }
    7036  }
    7037  else
    7038  {
    7039  if (yych <= 'E')
    7040  {
    7041  goto basic_json_parser_44;
    7042  }
    7043  if (yych == 'e')
    7044  {
    7045  goto basic_json_parser_44;
    7046  }
    7047  }
    7048 basic_json_parser_25:
    7049  {
    7050  return token_type::value_number;
    7051  }
    7052 basic_json_parser_26:
    7053  yyaccept = 1;
    7054  yych = *(m_marker = ++m_cursor);
    7055  goto basic_json_parser_42;
    7056 basic_json_parser_27:
    7057  yyaccept = 0;
    7058  yych = *(m_marker = ++m_cursor);
    7059  if (yych <= 0x0F)
    7060  {
    7061  goto basic_json_parser_7;
    7062  }
    7063  goto basic_json_parser_32;
    7064 basic_json_parser_28:
    7065  ++m_cursor;
    7066  {
    7067  return token_type::end_of_input;
    7068  }
    7069 basic_json_parser_30:
    7070  yych = *++m_cursor;
    7071  goto basic_json_parser_7;
    7072 basic_json_parser_31:
    7073  ++m_cursor;
    7074  if (m_limit <= m_cursor)
    7075  {
    7076  yyfill(); // LCOV_EXCL_LINE;
    7077  }
    7078  yych = *m_cursor;
    7079 basic_json_parser_32:
    7080  if (yybm[0 + yych] & 64)
    7081  {
    7082  goto basic_json_parser_31;
    7083  }
    7084  if (yych <= 0x0F)
    7085  {
    7086  goto basic_json_parser_33;
    7087  }
    7088  if (yych <= '"')
    7089  {
    7090  goto basic_json_parser_35;
    7091  }
    7092  goto basic_json_parser_34;
    7093 basic_json_parser_33:
    7094  m_cursor = m_marker;
    7095  if (yyaccept == 0)
    7096  {
    7097  goto basic_json_parser_7;
    7098  }
    7099  else
    7100  {
    7101  goto basic_json_parser_25;
    7102  }
    7103 basic_json_parser_34:
    7104  ++m_cursor;
    7105  if (m_limit <= m_cursor)
    7106  {
    7107  yyfill(); // LCOV_EXCL_LINE;
    7108  }
    7109  yych = *m_cursor;
    7110  if (yych <= 'e')
    7111  {
    7112  if (yych <= '/')
    7113  {
    7114  if (yych == '"')
    7115  {
    7116  goto basic_json_parser_31;
    7117  }
    7118  if (yych <= '.')
    7119  {
    7120  goto basic_json_parser_33;
    7121  }
    7122  goto basic_json_parser_31;
    7123  }
    7124  else
    7125  {
    7126  if (yych <= '\\')
    7127  {
    7128  if (yych <= '[')
    7129  {
    7130  goto basic_json_parser_33;
    7131  }
    7132  goto basic_json_parser_31;
    7133  }
    7134  else
    7135  {
    7136  if (yych == 'b')
    7137  {
    7138  goto basic_json_parser_31;
    7139  }
    7140  goto basic_json_parser_33;
    7141  }
    7142  }
    7143  }
    7144  else
    7145  {
    7146  if (yych <= 'q')
    7147  {
    7148  if (yych <= 'f')
    7149  {
    7150  goto basic_json_parser_31;
    7151  }
    7152  if (yych == 'n')
    7153  {
    7154  goto basic_json_parser_31;
    7155  }
    7156  goto basic_json_parser_33;
    7157  }
    7158  else
    7159  {
    7160  if (yych <= 's')
    7161  {
    7162  if (yych <= 'r')
    7163  {
    7164  goto basic_json_parser_31;
    7165  }
    7166  goto basic_json_parser_33;
    7167  }
    7168  else
    7169  {
    7170  if (yych <= 't')
    7171  {
    7172  goto basic_json_parser_31;
    7173  }
    7174  if (yych <= 'u')
    7175  {
    7176  goto basic_json_parser_37;
    7177  }
    7178  goto basic_json_parser_33;
    7179  }
    7180  }
    7181  }
    7182 basic_json_parser_35:
    7183  ++m_cursor;
    7184  {
    7185  return token_type::value_string;
    7186  }
    7187 basic_json_parser_37:
    7188  ++m_cursor;
    7189  if (m_limit <= m_cursor)
    7190  {
    7191  yyfill(); // LCOV_EXCL_LINE;
    7192  }
    7193  yych = *m_cursor;
    7194  if (yych <= '@')
    7195  {
    7196  if (yych <= '/')
    7197  {
    7198  goto basic_json_parser_33;
    7199  }
    7200  if (yych >= ':')
    7201  {
    7202  goto basic_json_parser_33;
    7203  }
    7204  }
    7205  else
    7206  {
    7207  if (yych <= 'F')
    7208  {
    7209  goto basic_json_parser_38;
    7210  }
    7211  if (yych <= '`')
    7212  {
    7213  goto basic_json_parser_33;
    7214  }
    7215  if (yych >= 'g')
    7216  {
    7217  goto basic_json_parser_33;
    7218  }
    7219  }
    7220 basic_json_parser_38:
    7221  ++m_cursor;
    7222  if (m_limit <= m_cursor)
    7223  {
    7224  yyfill(); // LCOV_EXCL_LINE;
    7225  }
    7226  yych = *m_cursor;
    7227  if (yych <= '@')
    7228  {
    7229  if (yych <= '/')
    7230  {
    7231  goto basic_json_parser_33;
    7232  }
    7233  if (yych >= ':')
    7234  {
    7235  goto basic_json_parser_33;
    7236  }
    7237  }
    7238  else
    7239  {
    7240  if (yych <= 'F')
    7241  {
    7242  goto basic_json_parser_39;
    7243  }
    7244  if (yych <= '`')
    7245  {
    7246  goto basic_json_parser_33;
    7247  }
    7248  if (yych >= 'g')
    7249  {
    7250  goto basic_json_parser_33;
    7251  }
    7252  }
    7253 basic_json_parser_39:
    7254  ++m_cursor;
    7255  if (m_limit <= m_cursor)
    7256  {
    7257  yyfill(); // LCOV_EXCL_LINE;
    7258  }
    7259  yych = *m_cursor;
    7260  if (yych <= '@')
    7261  {
    7262  if (yych <= '/')
    7263  {
    7264  goto basic_json_parser_33;
    7265  }
    7266  if (yych >= ':')
    7267  {
    7268  goto basic_json_parser_33;
    7269  }
    7270  }
    7271  else
    7272  {
    7273  if (yych <= 'F')
    7274  {
    7275  goto basic_json_parser_40;
    7276  }
    7277  if (yych <= '`')
    7278  {
    7279  goto basic_json_parser_33;
    7280  }
    7281  if (yych >= 'g')
    7282  {
    7283  goto basic_json_parser_33;
    7284  }
    7285  }
    7286 basic_json_parser_40:
    7287  ++m_cursor;
    7288  if (m_limit <= m_cursor)
    7289  {
    7290  yyfill(); // LCOV_EXCL_LINE;
    7291  }
    7292  yych = *m_cursor;
    7293  if (yych <= '@')
    7294  {
    7295  if (yych <= '/')
    7296  {
    7297  goto basic_json_parser_33;
    7298  }
    7299  if (yych <= '9')
    7300  {
    7301  goto basic_json_parser_31;
    7302  }
    7303  goto basic_json_parser_33;
    7304  }
    7305  else
    7306  {
    7307  if (yych <= 'F')
    7308  {
    7309  goto basic_json_parser_31;
    7310  }
    7311  if (yych <= '`')
    7312  {
    7313  goto basic_json_parser_33;
    7314  }
    7315  if (yych <= 'f')
    7316  {
    7317  goto basic_json_parser_31;
    7318  }
    7319  goto basic_json_parser_33;
    7320  }
    7321 basic_json_parser_41:
    7322  yyaccept = 1;
    7323  m_marker = ++m_cursor;
    7324  if ((m_limit - m_cursor) < 3)
    7325  {
    7326  yyfill(); // LCOV_EXCL_LINE;
    7327  }
    7328  yych = *m_cursor;
    7329 basic_json_parser_42:
    7330  if (yybm[0 + yych] & 128)
    7331  {
    7332  goto basic_json_parser_41;
    7333  }
    7334  if (yych <= 'D')
    7335  {
    7336  if (yych != '.')
    7337  {
    7338  goto basic_json_parser_25;
    7339  }
    7340  }
    7341  else
    7342  {
    7343  if (yych <= 'E')
    7344  {
    7345  goto basic_json_parser_44;
    7346  }
    7347  if (yych == 'e')
    7348  {
    7349  goto basic_json_parser_44;
    7350  }
    7351  goto basic_json_parser_25;
    7352  }
    7353 basic_json_parser_43:
    7354  yych = *++m_cursor;
    7355  if (yych <= '/')
    7356  {
    7357  goto basic_json_parser_33;
    7358  }
    7359  if (yych <= '9')
    7360  {
    7361  goto basic_json_parser_48;
    7362  }
    7363  goto basic_json_parser_33;
    7364 basic_json_parser_44:
    7365  yych = *++m_cursor;
    7366  if (yych <= ',')
    7367  {
    7368  if (yych != '+')
    7369  {
    7370  goto basic_json_parser_33;
    7371  }
    7372  }
    7373  else
    7374  {
    7375  if (yych <= '-')
    7376  {
    7377  goto basic_json_parser_45;
    7378  }
    7379  if (yych <= '/')
    7380  {
    7381  goto basic_json_parser_33;
    7382  }
    7383  if (yych <= '9')
    7384  {
    7385  goto basic_json_parser_46;
    7386  }
    7387  goto basic_json_parser_33;
    7388  }
    7389 basic_json_parser_45:
    7390  yych = *++m_cursor;
    7391  if (yych <= '/')
    7392  {
    7393  goto basic_json_parser_33;
    7394  }
    7395  if (yych >= ':')
    7396  {
    7397  goto basic_json_parser_33;
    7398  }
    7399 basic_json_parser_46:
    7400  ++m_cursor;
    7401  if (m_limit <= m_cursor)
    7402  {
    7403  yyfill(); // LCOV_EXCL_LINE;
    7404  }
    7405  yych = *m_cursor;
    7406  if (yych <= '/')
    7407  {
    7408  goto basic_json_parser_25;
    7409  }
    7410  if (yych <= '9')
    7411  {
    7412  goto basic_json_parser_46;
    7413  }
    7414  goto basic_json_parser_25;
    7415 basic_json_parser_48:
    7416  yyaccept = 1;
    7417  m_marker = ++m_cursor;
    7418  if ((m_limit - m_cursor) < 3)
    7419  {
    7420  yyfill(); // LCOV_EXCL_LINE;
    7421  }
    7422  yych = *m_cursor;
    7423  if (yych <= 'D')
    7424  {
    7425  if (yych <= '/')
    7426  {
    7427  goto basic_json_parser_25;
    7428  }
    7429  if (yych <= '9')
    7430  {
    7431  goto basic_json_parser_48;
    7432  }
    7433  goto basic_json_parser_25;
    7434  }
    7435  else
    7436  {
    7437  if (yych <= 'E')
    7438  {
    7439  goto basic_json_parser_44;
    7440  }
    7441  if (yych == 'e')
    7442  {
    7443  goto basic_json_parser_44;
    7444  }
    7445  goto basic_json_parser_25;
    7446  }
    7447 basic_json_parser_50:
    7448  yyaccept = 1;
    7449  yych = *(m_marker = ++m_cursor);
    7450  if (yych <= 'D')
    7451  {
    7452  if (yych == '.')
    7453  {
    7454  goto basic_json_parser_43;
    7455  }
    7456  goto basic_json_parser_25;
    7457  }
    7458  else
    7459  {
    7460  if (yych <= 'E')
    7461  {
    7462  goto basic_json_parser_44;
    7463  }
    7464  if (yych == 'e')
    7465  {
    7466  goto basic_json_parser_44;
    7467  }
    7468  goto basic_json_parser_25;
    7469  }
    7470 basic_json_parser_51:
    7471  yych = *++m_cursor;
    7472  if (yych != 'l')
    7473  {
    7474  goto basic_json_parser_33;
    7475  }
    7476  yych = *++m_cursor;
    7477  if (yych != 's')
    7478  {
    7479  goto basic_json_parser_33;
    7480  }
    7481  yych = *++m_cursor;
    7482  if (yych != 'e')
    7483  {
    7484  goto basic_json_parser_33;
    7485  }
    7486  ++m_cursor;
    7487  {
    7488  return token_type::literal_false;
    7489  }
    7490 basic_json_parser_56:
    7491  yych = *++m_cursor;
    7492  if (yych != 'u')
    7493  {
    7494  goto basic_json_parser_33;
    7495  }
    7496  yych = *++m_cursor;
    7497  if (yych != 'e')
    7498  {
    7499  goto basic_json_parser_33;
    7500  }
    7501  ++m_cursor;
    7502  {
    7503  return token_type::literal_true;
    7504  }
    7505 basic_json_parser_60:
    7506  yych = *++m_cursor;
    7507  if (yych != 'l')
    7508  {
    7509  goto basic_json_parser_33;
    7510  }
    7511  yych = *++m_cursor;
    7512  if (yych != 'l')
    7513  {
    7514  goto basic_json_parser_33;
    7515  }
    7516  ++m_cursor;
    7517  {
    7518  return token_type::literal_null;
    7519  }
    7520 basic_json_parser_64:
    7521  yych = *++m_cursor;
    7522  if (yych != 0xBF)
    7523  {
    7524  goto basic_json_parser_33;
    7525  }
    7526  ++m_cursor;
    7527  {
    7528  return scan();
    7529  }
    7530  }
    7531 
    7532 
    7533  }
    7534 
    7536  void yyfill() noexcept
    7537  {
    7538  if (m_stream == nullptr or not * m_stream)
    7539  {
    7540  return;
    7541  }
    7542 
    7543  const ssize_t offset_start = m_start - m_content;
    7544  const ssize_t offset_marker = m_marker - m_start;
    7545  const ssize_t offset_cursor = m_cursor - m_start;
    7546 
    7547  m_buffer.erase(0, static_cast<size_t>(offset_start));
    7548  std::string line;
    7549  assert(m_stream != nullptr);
    7550  std::getline(*m_stream, line);
    7551  m_buffer += "\n" + line; // add line with newline symbol
    7552 
    7553  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7554  assert(m_content != nullptr);
    7555  m_start = m_content;
    7556  m_marker = m_start + offset_marker;
    7557  m_cursor = m_start + offset_cursor;
    7558  m_limit = m_start + m_buffer.size() - 1;
    7559  }
    7560 
    7562  string_t get_token() const noexcept
    7563  {
    7564  assert(m_start != nullptr);
    7565  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7566  static_cast<size_t>(m_cursor - m_start));
    7567  }
    7568 
    7590  string_t get_string() const
    7591  {
    7592  string_t result;
    7593  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    7594 
    7595  // iterate the result between the quotes
    7596  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    7597  {
    7598  // process escaped characters
    7599  if (*i == '\\')
    7600  {
    7601  // read next character
    7602  ++i;
    7603 
    7604  switch (*i)
    7605  {
    7606  // the default escapes
    7607  case 't':
    7608  {
    7609  result += "\t";
    7610  break;
    7611  }
    7612  case 'b':
    7613  {
    7614  result += "\b";
    7615  break;
    7616  }
    7617  case 'f':
    7618  {
    7619  result += "\f";
    7620  break;
    7621  }
    7622  case 'n':
    7623  {
    7624  result += "\n";
    7625  break;
    7626  }
    7627  case 'r':
    7628  {
    7629  result += "\r";
    7630  break;
    7631  }
    7632  case '\\':
    7633  {
    7634  result += "\\";
    7635  break;
    7636  }
    7637  case '/':
    7638  {
    7639  result += "/";
    7640  break;
    7641  }
    7642  case '"':
    7643  {
    7644  result += "\"";
    7645  break;
    7646  }
    7647 
    7648  // unicode
    7649  case 'u':
    7650  {
    7651  // get code xxxx from uxxxx
    7652  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    7653  4).c_str(), nullptr, 16);
    7654 
    7655  // check if codepoint is a high surrogate
    7656  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    7657  {
    7658  // make sure there is a subsequent unicode
    7659  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    7660  {
    7661  throw std::invalid_argument("missing low surrogate");
    7662  }
    7663 
    7664  // get code yyyy from uxxxx\uyyyy
    7665  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    7666  (i + 7), 4).c_str(), nullptr, 16);
    7667  result += to_unicode(codepoint, codepoint2);
    7668  // skip the next 10 characters (xxxx\uyyyy)
    7669  i += 10;
    7670  }
    7671  else
    7672  {
    7673  // add unicode character(s)
    7674  result += to_unicode(codepoint);
    7675  // skip the next four characters (xxxx)
    7676  i += 4;
    7677  }
    7678  break;
    7679  }
    7680  }
    7681  }
    7682  else
    7683  {
    7684  // all other characters are just copied to the end of the
    7685  // string
    7686  result.append(1, static_cast<typename string_t::value_type>(*i));
    7687  }
    7688  }
    7689 
    7690  return result;
    7691  }
    7692 
    7710  long double get_number() const
    7711  {
    7712  // conversion
    7713  typename string_t::value_type* endptr;
    7714  assert(m_start != nullptr);
    7715  const auto float_val = std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7716  &endptr);
    7717 
    7718  // return float_val if the whole number was translated and NAN
    7719  // otherwise
    7720  return (reinterpret_cast<lexer_char_t*>(endptr) == m_cursor) ? float_val : NAN;
    7721  }
    7722 
    7723  private:
    7725  std::istream* m_stream = nullptr;
    7727  string_t m_buffer;
    7729  const lexer_char_t* m_content = nullptr;
    7731  const lexer_char_t* m_start = nullptr;
    7733  const lexer_char_t* m_marker = nullptr;
    7735  const lexer_char_t* m_cursor = nullptr;
    7737  const lexer_char_t* m_limit = nullptr;
    7738  };
    7739 
    7745  class parser
    7746  {
    7747  public:
    7749  parser(const string_t& s, parser_callback_t cb = nullptr)
    7750  : callback(cb), m_lexer(s)
    7751  {
    7752  // read first token
    7753  get_token();
    7754  }
    7755 
    7757  parser(std::istream& _is, parser_callback_t cb = nullptr)
    7758  : callback(cb), m_lexer(&_is)
    7759  {
    7760  // read first token
    7761  get_token();
    7762  }
    7763 
    7765  basic_json parse()
    7766  {
    7767  basic_json result = parse_internal(true);
    7768 
    7769  expect(lexer::token_type::end_of_input);
    7770 
    7771  // return parser result and replace it with null in case the
    7772  // top-level value was discarded by the callback function
    7773  return result.is_discarded() ? basic_json() : result;
    7774  }
    7775 
    7776  private:
    7778  basic_json parse_internal(bool keep)
    7779  {
    7780  auto result = basic_json(value_t::discarded);
    7781 
    7782  switch (last_token)
    7783  {
    7784  case lexer::token_type::begin_object:
    7785  {
    7786  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    7787  {
    7788  // explicitly set result to object to cope with {}
    7789  result.m_type = value_t::object;
    7790  result.m_value = json_value(value_t::object);
    7791  }
    7792 
    7793  // read next token
    7794  get_token();
    7795 
    7796  // closing } -> we are done
    7797  if (last_token == lexer::token_type::end_object)
    7798  {
    7799  get_token();
    7800  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    7801  {
    7802  result = basic_json(value_t::discarded);
    7803  }
    7804  return result;
    7805  }
    7806 
    7807  // no comma is expected here
    7808  unexpect(lexer::token_type::value_separator);
    7809 
    7810  // otherwise: parse key-value pairs
    7811  do
    7812  {
    7813  // ugly, but could be fixed with loop reorganization
    7814  if (last_token == lexer::token_type::value_separator)
    7815  {
    7816  get_token();
    7817  }
    7818 
    7819  // store key
    7820  expect(lexer::token_type::value_string);
    7821  const auto key = m_lexer.get_string();
    7822 
    7823  bool keep_tag = false;
    7824  if (keep)
    7825  {
    7826  if (callback)
    7827  {
    7828  basic_json k(key);
    7829  keep_tag = callback(depth, parse_event_t::key, k);
    7830  }
    7831  else
    7832  {
    7833  keep_tag = true;
    7834  }
    7835  }
    7836 
    7837  // parse separator (:)
    7838  get_token();
    7839  expect(lexer::token_type::name_separator);
    7840 
    7841  // parse and add value
    7842  get_token();
    7843  auto value = parse_internal(keep);
    7844  if (keep and keep_tag and not value.is_discarded())
    7845  {
    7846  result[key] = std::move(value);
    7847  }
    7848  }
    7849  while (last_token == lexer::token_type::value_separator);
    7850 
    7851  // closing }
    7852  expect(lexer::token_type::end_object);
    7853  get_token();
    7854  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    7855  {
    7856  result = basic_json(value_t::discarded);
    7857  }
    7858 
    7859  return result;
    7860  }
    7861 
    7862  case lexer::token_type::begin_array:
    7863  {
    7864  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    7865  {
    7866  // explicitly set result to object to cope with []
    7867  result.m_type = value_t::array;
    7868  result.m_value = json_value(value_t::array);
    7869  }
    7870 
    7871  // read next token
    7872  get_token();
    7873 
    7874  // closing ] -> we are done
    7875  if (last_token == lexer::token_type::end_array)
    7876  {
    7877  get_token();
    7878  if (callback and not callback(--depth, parse_event_t::array_end, result))
    7879  {
    7880  result = basic_json(value_t::discarded);
    7881  }
    7882  return result;
    7883  }
    7884 
    7885  // no comma is expected here
    7886  unexpect(lexer::token_type::value_separator);
    7887 
    7888  // otherwise: parse values
    7889  do
    7890  {
    7891  // ugly, but could be fixed with loop reorganization
    7892  if (last_token == lexer::token_type::value_separator)
    7893  {
    7894  get_token();
    7895  }
    7896 
    7897  // parse value
    7898  auto value = parse_internal(keep);
    7899  if (keep and not value.is_discarded())
    7900  {
    7901  result.push_back(std::move(value));
    7902  }
    7903  }
    7904  while (last_token == lexer::token_type::value_separator);
    7905 
    7906  // closing ]
    7907  expect(lexer::token_type::end_array);
    7908  get_token();
    7909  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    7910  {
    7911  result = basic_json(value_t::discarded);
    7912  }
    7913 
    7914  return result;
    7915  }
    7916 
    7917  case lexer::token_type::literal_null:
    7918  {
    7919  get_token();
    7920  result.m_type = value_t::null;
    7921  break;
    7922  }
    7923 
    7924  case lexer::token_type::value_string:
    7925  {
    7926  const auto s = m_lexer.get_string();
    7927  get_token();
    7928  result = basic_json(s);
    7929  break;
    7930  }
    7931 
    7932  case lexer::token_type::literal_true:
    7933  {
    7934  get_token();
    7935  result.m_type = value_t::boolean;
    7936  result.m_value = true;
    7937  break;
    7938  }
    7939 
    7940  case lexer::token_type::literal_false:
    7941  {
    7942  get_token();
    7943  result.m_type = value_t::boolean;
    7944  result.m_value = false;
    7945  break;
    7946  }
    7947 
    7948  case lexer::token_type::value_number:
    7949  {
    7950  auto float_val = m_lexer.get_number();
    7951 
    7952  // NAN is returned if token could not be translated
    7953  // completely
    7954  if (std::isnan(float_val))
    7955  {
    7956  throw std::invalid_argument(std::string("parse error - ") +
    7957  m_lexer.get_token() + " is not a number");
    7958  }
    7959 
    7960  get_token();
    7961 
    7962  // check if conversion loses precision
    7963  const auto int_val = static_cast<number_integer_t>(float_val);
    7964  if (approx(float_val, static_cast<long double>(int_val)))
    7965  {
    7966  // we would not lose precision -> return int
    7967  result.m_type = value_t::number_integer;
    7968  result.m_value = int_val;
    7969  }
    7970  else
    7971  {
    7972  // we would lose precision -> return float
    7973  result.m_type = value_t::number_float;
    7974  result.m_value = static_cast<number_float_t>(float_val);
    7975  }
    7976  break;
    7977  }
    7978 
    7979  default:
    7980  {
    7981  // the last token was unexpected
    7982  unexpect(last_token);
    7983  }
    7984  }
    7985 
    7986  if (keep and callback and not callback(depth, parse_event_t::value, result))
    7987  {
    7988  result = basic_json(value_t::discarded);
    7989  }
    7990  return result;
    7991  }
    7992 
    7994  typename lexer::token_type get_token()
    7995  {
    7996  last_token = m_lexer.scan();
    7997  return last_token;
    7998  }
    7999 
    8000  void expect(typename lexer::token_type t) const
    8001  {
    8002  if (t != last_token)
    8003  {
    8004  std::string error_msg = "parse error - unexpected ";
    8005  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8006  lexer::token_type_name(last_token));
    8007  error_msg += "; expected " + lexer::token_type_name(t);
    8008  throw std::invalid_argument(error_msg);
    8009  }
    8010  }
    8011 
    8012  void unexpect(typename lexer::token_type t) const
    8013  {
    8014  if (t == last_token)
    8015  {
    8016  std::string error_msg = "parse error - unexpected ";
    8017  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8018  lexer::token_type_name(last_token));
    8019  throw std::invalid_argument(error_msg);
    8020  }
    8021  }
    8022 
    8023  private:
    8025  int depth = 0;
    8027  parser_callback_t callback;
    8029  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    8031  lexer m_lexer;
    8032  };
    8033 };
    8034 
    8035 
    8037 // presets //
    8039 
    8049 }
    8050 
    8051 
    8053 // nonmember functions //
    8055 
    8056 // specialization of std::swap, and std::hash
    8057 namespace std
    8058 {
    8064 template <>
    8065 inline void swap(nlohmann::json& j1,
    8066  nlohmann::json& j2) noexcept(
    8067  is_nothrow_move_constructible<nlohmann::json>::value and
    8068  is_nothrow_move_assignable<nlohmann::json>::value
    8069  )
    8070 {
    8071  j1.swap(j2);
    8072 }
    8073 
    8075 template <>
    8076 struct hash<nlohmann::json>
    8077 {
    8083  std::size_t operator()(const nlohmann::json& j) const
    8084  {
    8085  // a naive hashing via the string representation
    8086  const auto& h = hash<nlohmann::json::string_t>();
    8087  return h(j.dump());
    8088  }
    8089 };
    8090 }
    8091 
    8104 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    8105 {
    8106  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    8107 }
    8108 
    8109 #endif
    bool operator!=(const const_iterator &other) const
    comparison: not equal
    Definition: json.hpp:6105
    +
    iterator insert(const_iterator pos, basic_json &&val)
    inserts element
    Definition: json.hpp:4388
    +
    iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6353
    +
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:4999
    typename std::allocator_traits< allocator_type >::pointer pointer
    the type of an element pointer
    Definition: json.hpp:228
    -
    json_reverse_iterator operator-(difference_type i) const
    subtract from iterator
    Definition: json.hpp:6428
    +
    json_reverse_iterator operator-(difference_type i) const
    subtract from iterator
    Definition: json.hpp:6508
    static basic_json object(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
    explicitly create an object from an initializer list
    Definition: json.hpp:1510
    -
    const_reference operator[](size_type idx) const
    access specified array element
    Definition: json.hpp:2870
    -
    reference operator[](const T(&key)[n])
    access specified object element
    Definition: json.hpp:3004
    -
    typename basic_json::const_pointer pointer
    defines a pointer to the type iterated over (value_type)
    Definition: json.hpp:5697
    -
    static iteration_proxy< iterator > iterator_wrapper(reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:3842
    -
    const_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:5966
    -
    friend std::istream & operator>>(std::istream &i, basic_json &j)
    deserialize from stream
    Definition: json.hpp:5132
    -
    const_iterator & operator=(const_iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:5766
    -
    typename basic_json::value_type value_type
    the type of the values when the iterator is dereferenced
    Definition: json.hpp:5693
    +
    const_reference operator[](size_type idx) const
    access specified array element
    Definition: json.hpp:2950
    +
    reference operator[](const T(&key)[n])
    access specified object element
    Definition: json.hpp:3084
    +
    typename basic_json::const_pointer pointer
    defines a pointer to the type iterated over (value_type)
    Definition: json.hpp:5777
    +
    static iteration_proxy< iterator > iterator_wrapper(reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:3922
    +
    const_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6046
    +
    friend std::istream & operator>>(std::istream &i, basic_json &j)
    deserialize from stream
    Definition: json.hpp:5212
    +
    const_iterator & operator=(const_iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:5846
    +
    typename basic_json::value_type value_type
    the type of the values when the iterator is dereferenced
    Definition: json.hpp:5773
    reference & operator=(basic_json other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    copy assignment
    Definition: json.hpp:1782
    -
    iterator insert(const_iterator pos, const_iterator first, const_iterator last)
    inserts elements
    Definition: json.hpp:4390
    -
    iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
    inserts elements
    Definition: json.hpp:4337
    -
    json_reverse_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6400
    +
    iterator insert(const_iterator pos, const_iterator first, const_iterator last)
    inserts elements
    Definition: json.hpp:4470
    +
    iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
    inserts elements
    Definition: json.hpp:4417
    +
    json_reverse_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6480
    StringType string_t
    a type for a string
    Definition: json.hpp:434
    -
    void push_back(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4229
    +
    void push_back(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4309
    basic_json(boolean_t val)
    create a boolean (explicit)
    Definition: json.hpp:1132
    static basic_json array(std::initializer_list< basic_json > init=std::initializer_list< basic_json >())
    explicitly create an array from an initializer list
    Definition: json.hpp:1470
    -
    iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6281
    -
    friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    comparison: not equal
    Definition: json.hpp:4775
    +
    iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6361
    +
    friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    comparison: not equal
    Definition: json.hpp:4855
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:387
    -
    const_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:5929
    -
    difference_type operator-(const json_reverse_iterator &other) const
    return difference
    Definition: json.hpp:6436
    -
    basic_json<> json
    default JSON class
    Definition: json.hpp:7968
    -
    reference front()
    access the first element
    Definition: json.hpp:3173
    +
    const_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6009
    +
    difference_type operator-(const json_reverse_iterator &other) const
    return difference
    Definition: json.hpp:6516
    +
    basic_json<> json
    default JSON class
    Definition: json.hpp:8048
    +
    reference front()
    access the first element
    Definition: json.hpp:3253
    bool is_array() const noexcept
    return whether value is an array
    Definition: json.hpp:2095
    -
    const_iterator find(typename object_t::key_type key) const
    find an element in a JSON object
    Definition: json.hpp:3553
    -
    std::reverse_iterator< Base > base_iterator
    shortcut to the reverse iterator adaptor
    Definition: json.hpp:6372
    -
    json_reverse_iterator(const typename base_iterator::iterator_type &it)
    create reverse iterator from iterator
    Definition: json.hpp:6377
    +
    const_iterator find(typename object_t::key_type key) const
    find an element in a JSON object
    Definition: json.hpp:3633
    +
    std::reverse_iterator< Base > base_iterator
    shortcut to the reverse iterator adaptor
    Definition: json.hpp:6452
    +
    json_reverse_iterator(const typename base_iterator::iterator_type &it)
    create reverse iterator from iterator
    Definition: json.hpp:6457
    a class to store JSON values
    Definition: json.hpp:188
    -
    json_reverse_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6406
    +
    json_reverse_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6486
    basic_json(const object_t &val)
    create an object (explicit)
    Definition: json.hpp:934
    -
    friend bool operator==(std::nullptr_t, const_reference v) noexcept
    comparison: equal
    Definition: json.hpp:4754
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4143
    -
    const_iterator cbegin() const
    returns a const iterator to the first element
    Definition: json.hpp:3653
    +
    friend bool operator==(std::nullptr_t, const_reference v) noexcept
    comparison: equal
    Definition: json.hpp:4834
    +
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4223
    +
    const_iterator cbegin() const
    returns a const iterator to the first element
    Definition: json.hpp:3733
    bool is_string() const noexcept
    return whether value is a string
    Definition: json.hpp:2114
    -
    iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6303
    -
    const PointerType get_ptr() const noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2560
    +
    iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6383
    +
    const PointerType get_ptr() const noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2589
    basic_json(const CompatibleStringType &val)
    create a string (implicit)
    Definition: json.hpp:1114
    -
    reference operator+=(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4169
    +
    reference operator+=(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4249
    basic_json(size_type cnt, const basic_json &val)
    construct an array with count copies of given value
    Definition: json.hpp:1534
    -
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:6228
    -
    iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6310
    -
    static basic_json parse(std::istream &&i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5094
    -
    reference operator[](const typename object_t::key_type &key)
    access specified object element
    Definition: json.hpp:2911
    +
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:6308
    +
    iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6390
    +
    static basic_json parse(std::istream &&i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5174
    +
    reference operator[](const typename object_t::key_type &key)
    access specified object element
    Definition: json.hpp:2991
    STL namespace.
    -
    difference_type operator-(const iterator &other) const
    Definition: json.hpp:6332
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6204
    -
    static iteration_proxy< const_iterator > iterator_wrapper(const_reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:3850
    -
    const_iterator end() const
    returns a const iterator to one past the last element
    Definition: json.hpp:3688
    -
    const_iterator(const const_iterator &other) noexcept
    copy constructor
    Definition: json.hpp:5761
    -
    reference at(const typename object_t::key_type &key)
    access specified object element with bounds checking
    Definition: json.hpp:2730
    -
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6189
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:3678
    +
    difference_type operator-(const iterator &other) const
    Definition: json.hpp:6412
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6284
    +
    static iteration_proxy< const_iterator > iterator_wrapper(const_reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:3930
    +
    const_iterator end() const
    returns a const iterator to one past the last element
    Definition: json.hpp:3768
    +
    const_iterator(const const_iterator &other) noexcept
    copy constructor
    Definition: json.hpp:5841
    +
    reference at(const typename object_t::key_type &key)
    access specified object element with bounds checking
    Definition: json.hpp:2810
    +
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6269
    +
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:3758
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:341
    -
    reference operator*()
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:6261
    -
    reverse_iterator rend()
    returns an iterator to the reverse-end
    Definition: json.hpp:3767
    +
    reference operator*()
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:6341
    +
    reverse_iterator rend()
    returns an iterator to the reverse-end
    Definition: json.hpp:3847
    bool is_object() const noexcept
    return whether value is an object
    Definition: json.hpp:2076
    -
    const_iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6121
    +
    const_iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6201
    bool is_discarded() const noexcept
    return whether value is discarded
    Definition: json.hpp:2138
    basic_json(const CompatibleArrayType &val)
    create an array (implicit)
    Definition: json.hpp:1030
    -
    typename basic_json::const_reference reference
    defines a reference to the type iterated over (value_type)
    Definition: json.hpp:5699
    -
    const_reverse_iterator rend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:3775
    -
    size_type erase(const typename object_t::key_type &key)
    remove element from a JSON object given a key
    Definition: json.hpp:3462
    +
    typename basic_json::const_reference reference
    defines a reference to the type iterated over (value_type)
    Definition: json.hpp:5779
    +
    const_reverse_iterator rend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:3855
    +
    size_type erase(const typename object_t::key_type &key)
    remove element from a JSON object given a key
    Definition: json.hpp:3542
    bool is_boolean() const noexcept
    return whether value is a boolean
    Definition: json.hpp:1987
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3619
    -
    const_reference at(const typename object_t::key_type &key) const
    access specified object element with bounds checking
    Definition: json.hpp:2778
    -
    reference operator+=(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4203
    +
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3699
    +
    const_reference at(const typename object_t::key_type &key) const
    access specified object element with bounds checking
    Definition: json.hpp:2858
    +
    reference operator+=(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4283
    AllocatorType< basic_json > allocator_type
    the allocator type
    Definition: json.hpp:225
    basic_json(const number_float_t val)
    create a floating-point number (explicit)
    Definition: json.hpp:1259
    bool is_number_integer() const noexcept
    return whether value is an integer number
    Definition: json.hpp:2034
    -
    iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6317
    +
    iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6397
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:820
    basic_json(const typename string_t::value_type *val)
    create a string (explicit)
    Definition: json.hpp:1083
    -
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3536
    +
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3616
    basic_json(const value_t value_type)
    create an empty value with a given type
    Definition: json.hpp:867
    -
    friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than or equal
    Definition: json.hpp:4963
    -
    iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6296
    -
    friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    comparison: less than
    Definition: json.hpp:4836
    -
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:5886
    -
    const_reference operator[](const typename object_t::key_type &key) const
    read-only access specified object element
    Definition: json.hpp:2959
    -
    const_iterator cend() const
    returns a const iterator to one past the last element
    Definition: json.hpp:3712
    -
    typename Base::reference reference
    the reference type for the pointed-to element
    Definition: json.hpp:6374
    -
    size_type size() const noexcept
    returns the number of elements
    Definition: json.hpp:3952
    +
    friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than or equal
    Definition: json.hpp:5043
    +
    iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6376
    +
    friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    comparison: less than
    Definition: json.hpp:4916
    +
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:5966
    +
    const_reference operator[](const typename object_t::key_type &key) const
    read-only access specified object element
    Definition: json.hpp:3039
    +
    const_iterator cend() const
    returns a const iterator to one past the last element
    Definition: json.hpp:3792
    +
    typename Base::reference reference
    the reference type for the pointed-to element
    Definition: json.hpp:6454
    +
    size_type size() const noexcept
    returns the number of elements
    Definition: json.hpp:4032
    static allocator_type get_allocator()
    returns the allocator associated with the container
    Definition: json.hpp:250
    object (unordered set of name/value pairs)
    -
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2638
    -
    json_reverse_iterator(const base_iterator &it)
    create reverse iterator from base class
    Definition: json.hpp:6382
    +
    ReferenceType get_ref()
    get a reference value (implicit)
    Definition: json.hpp:2625
    +
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2718
    +
    json_reverse_iterator(const base_iterator &it)
    create reverse iterator from base class
    Definition: json.hpp:6462
    value_t type() const noexcept
    return the type of the JSON value (explicit)
    Definition: json.hpp:1908
    -
    friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
    serialize to stream
    Definition: json.hpp:5018
    -
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3122
    -
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6448
    +
    friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
    serialize to stream
    Definition: json.hpp:5098
    +
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3202
    +
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6528
    bool is_structured() const noexcept
    return whether type is structured
    Definition: json.hpp:1949
    namespace for Niels Lohmann
    Definition: json.hpp:79
    -
    typename basic_json::difference_type difference_type
    a type to represent differences between iterators
    Definition: json.hpp:5695
    -
    void swap(array_t &other)
    exchanges the values
    Definition: json.hpp:4517
    -
    reverse_iterator rbegin()
    returns an iterator to the reverse-beginning
    Definition: json.hpp:3736
    -
    reference operator+=(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4253
    +
    typename basic_json::difference_type difference_type
    a type to represent differences between iterators
    Definition: json.hpp:5775
    +
    void swap(array_t &other)
    exchanges the values
    Definition: json.hpp:4597
    +
    reverse_iterator rbegin()
    returns an iterator to the reverse-beginning
    Definition: json.hpp:3816
    +
    reference operator+=(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4333
    basic_json(const number_integer_t val)
    create an integer number (explicit)
    Definition: json.hpp:1166
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6338
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6418
    std::size_t size_type
    a type to represent container sizes
    Definition: json.hpp:222
    -
    const_reverse_iterator rbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:3744
    +
    const_reverse_iterator rbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:3824
    ~basic_json()
    destructor
    Definition: json.hpp:1808
    basic_json(const basic_json &other)
    copy constructor
    Definition: json.hpp:1683
    -
    const_iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6113
    +
    const_iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6193
    value_t
    the JSON type enumeration
    Definition: json.hpp:612
    const value_type & const_reference
    the type of an element const reference
    Definition: json.hpp:216
    basic_json(const CompatibleNumberIntegerType val) noexcept
    create an integer number (implicit)
    Definition: json.hpp:1230
    +
    ReferenceType get_ref() const
    get a reference value (implicit)
    Definition: json.hpp:2640
    bool is_null() const noexcept
    return whether value is null
    Definition: json.hpp:1968
    -
    void swap(string_t &other)
    exchanges the values
    Definition: json.hpp:4585
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6344
    -
    const_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:5958
    -
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2461
    -
    void erase(const size_type idx)
    remove element from a JSON array given an index
    Definition: json.hpp:3500
    -
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4073
    -
    pointer operator->()
    dereference the iterator
    Definition: json.hpp:6267
    +
    void swap(string_t &other)
    exchanges the values
    Definition: json.hpp:4665
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6424
    +
    const_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6038
    +
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2490
    +
    void erase(const size_type idx)
    remove element from a JSON array given an index
    Definition: json.hpp:3580
    +
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4153
    +
    pointer operator->()
    dereference the iterator
    Definition: json.hpp:6347
    basic_json value_type
    the type of elements in a basic_json container
    Definition: json.hpp:210
    array (ordered collection of values)
    -
    const_reference front() const
    access the first element
    Definition: json.hpp:3181
    -
    bool operator>=(const const_iterator &other) const
    comparison: greater than or equal
    Definition: json.hpp:6073
    -
    iterator insert(const_iterator pos, std::initializer_list< basic_json > ilist)
    inserts elements
    Definition: json.hpp:4448
    +
    const_reference front() const
    access the first element
    Definition: json.hpp:3261
    +
    bool operator>=(const const_iterator &other) const
    comparison: greater than or equal
    Definition: json.hpp:6153
    +
    iterator insert(const_iterator pos, std::initializer_list< basic_json > ilist)
    inserts elements
    Definition: json.hpp:4528
    std::ptrdiff_t difference_type
    a type to represent differences between iterators
    Definition: json.hpp:219
    -
    const_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6079
    +
    const_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6159
    basic_json(std::initializer_list< basic_json > init, bool type_deduction=true, value_t manual_type=value_t::array)
    create a container (array or object) from an initializer list
    Definition: json.hpp:1378
    -
    difference_type operator-(const const_iterator &other) const
    return difference
    Definition: json.hpp:6129
    -
    friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    comparison: equal
    Definition: json.hpp:4665
    +
    difference_type operator-(const const_iterator &other) const
    return difference
    Definition: json.hpp:6209
    +
    friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    comparison: equal
    Definition: json.hpp:4745
    bool is_number() const noexcept
    return whether value is a number
    Definition: json.hpp:2011
    BooleanType boolean_t
    a type for a boolean
    Definition: json.hpp:460
    -
    const_reverse_iterator crend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:3821
    -
    bool empty() const noexcept
    checks whether the container is empty
    Definition: json.hpp:3894
    -
    string_t value(const typename object_t::key_type &key, const char *default_value) const
    overload for a default value of type const char*
    Definition: json.hpp:3148
    -
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4486
    -
    const_reverse_iterator crbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:3798
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6455
    +
    const_reverse_iterator crend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:3901
    +
    bool empty() const noexcept
    checks whether the container is empty
    Definition: json.hpp:3974
    +
    string_t value(const typename object_t::key_type &key, const char *default_value) const
    overload for a default value of type const char*
    Definition: json.hpp:3228
    +
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4566
    +
    const_reverse_iterator crbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:3878
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6535
    -
    const_iterator(pointer object)
    constructor for a given JSON instance
    Definition: json.hpp:5707
    -
    friend bool operator<(const value_t lhs, const value_t rhs)
    comparison operator for JSON types
    Definition: json.hpp:4619
    -
    iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6239
    -
    bool operator<(const const_iterator &other) const
    comparison: smaller
    Definition: json.hpp:6031
    +
    const_iterator(pointer object)
    constructor for a given JSON instance
    Definition: json.hpp:5787
    +
    friend bool operator<(const value_t lhs, const value_t rhs)
    comparison operator for JSON types
    Definition: json.hpp:4699
    +
    iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6319
    +
    bool operator<(const const_iterator &other) const
    comparison: smaller
    Definition: json.hpp:6111
    string_t dump(const int indent=-1) const
    serialization
    Definition: json.hpp:1877
    -
    friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    comparison: not equal
    Definition: json.hpp:4798
    -
    const_iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6107
    +
    friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    comparison: not equal
    Definition: json.hpp:4878
    +
    const_iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6187
    basic_json(const int val)
    create an integer number from an enum type (explicit)
    Definition: json.hpp:1195
    basic_json(const array_t &val)
    create an array (explicit)
    Definition: json.hpp:993
    -
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5057
    -
    InteratorType erase(InteratorType first, InteratorType last)
    remove elements given an iterator range
    Definition: json.hpp:3379
    -
    json_reverse_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6387
    -
    PointerType get_ptr() noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2545
    -
    const_iterator(const iterator &other)
    copy constructor given a nonconst iterator
    Definition: json.hpp:5734
    -
    friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    comparison: not equal
    Definition: json.hpp:4807
    -
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3274
    -
    bool operator<=(const const_iterator &other) const
    comparison: less than or equal
    Definition: json.hpp:6061
    +
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5137
    +
    InteratorType erase(InteratorType first, InteratorType last)
    remove elements given an iterator range
    Definition: json.hpp:3459
    +
    json_reverse_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6467
    +
    PointerType get_ptr() noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2574
    +
    const_iterator(const iterator &other)
    copy constructor given a nonconst iterator
    Definition: json.hpp:5814
    +
    friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    comparison: not equal
    Definition: json.hpp:4887
    +
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3354
    +
    bool operator<=(const const_iterator &other) const
    comparison: less than or equal
    Definition: json.hpp:6141
    basic_json(const CompatibleNumberFloatType val) noexcept
    create an floating-point number (implicit)
    Definition: json.hpp:1305
    -
    reference back()
    access the last element
    Definition: json.hpp:3207
    +
    reference back()
    access the last element
    Definition: json.hpp:3287
    bool is_number_float() const noexcept
    return whether value is a floating-point number
    Definition: json.hpp:2057
    -
    const_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:5921
    +
    const_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6001
    typename std::allocator_traits< allocator_type >::const_pointer const_pointer
    the type of an element const pointer
    Definition: json.hpp:230
    basic_json(const string_t &val)
    create a string (explicit)
    Definition: json.hpp:1059
    -
    iterator(const iterator &other) noexcept
    copy constructor
    Definition: json.hpp:6244
    -
    const_reference back() const
    access the last element
    Definition: json.hpp:3217
    +
    iterator(const iterator &other) noexcept
    copy constructor
    Definition: json.hpp:6324
    +
    const_reference back() const
    access the last element
    Definition: json.hpp:3297
    basic_json(InputIT first, InputIT last)
    construct a JSON container given an iterator range
    Definition: json.hpp:1580
    -
    static basic_json parse(std::istream &i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5086
    -
    size_type count(typename object_t::key_type key) const
    returns the number of occurrences of a key in a JSON object
    Definition: json.hpp:3584
    -
    size_type max_size() const noexcept
    returns the maximum possible number of elements
    Definition: json.hpp:4014
    -
    void push_back(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4179
    -
    bool operator==(const const_iterator &other) const
    comparison: equal
    Definition: json.hpp:5995
    -
    json_reverse_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6393
    +
    static basic_json parse(std::istream &i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5166
    +
    size_type count(typename object_t::key_type key) const
    returns the number of occurrences of a key in a JSON object
    Definition: json.hpp:3664
    +
    size_type max_size() const noexcept
    returns the maximum possible number of elements
    Definition: json.hpp:4094
    +
    void push_back(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4259
    +
    bool operator==(const const_iterator &other) const
    comparison: equal
    Definition: json.hpp:6075
    +
    json_reverse_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6473
    basic_json(std::nullptr_t) noexcept
    create a null object (explicitly)
    Definition: json.hpp:911
    -
    bool operator>(const const_iterator &other) const
    comparison: greater than
    Definition: json.hpp:6067
    -
    friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than
    Definition: json.hpp:4941
    +
    bool operator>(const const_iterator &other) const
    comparison: greater than
    Definition: json.hpp:6147
    +
    friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than
    Definition: json.hpp:5021
    basic_json(basic_json &&other) noexcept
    move constructor
    Definition: json.hpp:1752
    -
    const_reference operator[](const T(&key)[n]) const
    read-only access specified object element
    Definition: json.hpp:3055
    -
    const_iterator begin() const
    returns a const iterator to the first element
    Definition: json.hpp:3629
    -
    const_reference at(size_type idx) const
    access specified array element with bounds checking
    Definition: json.hpp:2682
    -
    json_reverse_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6413
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:5686
    +
    const_reference operator[](const T(&key)[n]) const
    read-only access specified object element
    Definition: json.hpp:3135
    +
    const_iterator begin() const
    returns a const iterator to the first element
    Definition: json.hpp:3709
    +
    const_reference at(size_type idx) const
    access specified array element with bounds checking
    Definition: json.hpp:2762
    +
    json_reverse_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6493
    +
    a const random access iterator for the basic_json class
    Definition: json.hpp:5766
    a template for a reverse iterator class
    Definition: json.hpp:233
    -
    void swap(object_t &other)
    exchanges the values
    Definition: json.hpp:4551
    -
    std::bidirectional_iterator_tag iterator_category
    the category of the iterator
    Definition: json.hpp:5701
    +
    void swap(object_t &other)
    exchanges the values
    Definition: json.hpp:4631
    +
    std::bidirectional_iterator_tag iterator_category
    the category of the iterator
    Definition: json.hpp:5781
    bool is_primitive() const noexcept
    return whether type is primitive
    Definition: json.hpp:1929
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4281
    -
    friend bool operator==(const_reference v, std::nullptr_t) noexcept
    comparison: equal
    Definition: json.hpp:4745
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6442
    +
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4361
    +
    friend bool operator==(const_reference v, std::nullptr_t) noexcept
    comparison: equal
    Definition: json.hpp:4825
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6522
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:528
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6153
    -
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:5846
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6233
    +
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:5926
    value_type & reference
    the type of an element reference
    Definition: json.hpp:213
    -
    friend std::istream & operator<<(basic_json &j, std::istream &i)
    deserialize from stream
    Definition: json.hpp:5122
    +
    friend std::istream & operator<<(basic_json &j, std::istream &i)
    deserialize from stream
    Definition: json.hpp:5202
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:593
    -
    std::size_t operator()(const nlohmann::json &j) const
    return a hash value for a JSON object
    Definition: json.hpp:8003
    -
    friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
    serialize to stream
    Definition: json.hpp:5000
    -
    iterator & operator=(iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:6249
    +
    std::size_t operator()(const nlohmann::json &j) const
    return a hash value for a JSON object
    Definition: json.hpp:8083
    +
    friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
    serialize to stream
    Definition: json.hpp:5080
    +
    iterator & operator=(iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:6329
    basic_json(const CompatibleObjectType &val)
    create an object (implicit)
    Definition: json.hpp:966
    -
    reference operator[](size_type idx)
    access specified array element
    Definition: json.hpp:2825
    -
    iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6288
    -
    json_reverse_iterator operator+(difference_type i) const
    add to iterator
    Definition: json.hpp:6420
    +
    reference operator[](size_type idx)
    access specified array element
    Definition: json.hpp:2905
    +
    iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6368
    +
    json_reverse_iterator operator+(difference_type i) const
    add to iterator
    Definition: json.hpp:6500
    parse_event_t
    JSON callback events.
    Definition: json.hpp:755
    -
    iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6325
    +
    iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6405
    diff --git a/namespacemembers.html b/namespacemembers.html index 9a92a93c1..79c2f7bf1 100644 --- a/namespacemembers.html +++ b/namespacemembers.html @@ -94,7 +94,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    diff --git a/namespacemembers_type.html b/namespacemembers_type.html index fd3484121..158b14b2b 100644 --- a/namespacemembers_type.html +++ b/namespacemembers_type.html @@ -94,7 +94,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/namespacenlohmann.html b/namespacenlohmann.html index 3801342f2..7a782ffb6 100644 --- a/namespacenlohmann.html +++ b/namespacenlohmann.html @@ -116,7 +116,7 @@ Typedefs diff --git a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html index 1ac4a6140..39e60ce22 100644 --- a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html +++ b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html @@ -105,7 +105,7 @@ Classes diff --git a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html index 265812773..68ceb3258 100644 --- a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html +++ b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');

    This type is the default specialization of the basic_json class which uses the standard template types.

    Since
    version 1.0.0
    -

    Definition at line 7968 of file json.hpp.

    +

    Definition at line 8048 of file json.hpp.

    @@ -111,7 +111,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/search/all_6.js b/search/all_6.js index 9b4b8210b..ffd550d5d 100644 --- a/search/all_6.js +++ b/search/all_6.js @@ -2,5 +2,6 @@ var searchData= [ ['get',['get',['../classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html#a5f0aad50ed7e8aec3128fe018c18b3fe',1,'nlohmann::basic_json::get() const '],['../classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html#ae50f22a1c646b8627e88f1313cceffd4',1,'nlohmann::basic_json::get() noexcept'],['../classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html#a76cfc5062bf6223396ab82c753cd4634',1,'nlohmann::basic_json::get() const noexcept']]], ['get_5fallocator',['get_allocator',['../classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html#ad2c4513cef5d8db760c4b2d871eea42c',1,'nlohmann::basic_json']]], - ['get_5fptr',['get_ptr',['../classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html#a656939a3dc9a6047e4afacd9e11b83a6',1,'nlohmann::basic_json::get_ptr() noexcept'],['../classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html#a234f03dce002783748ca401a42bc6472',1,'nlohmann::basic_json::get_ptr() const noexcept']]] + ['get_5fptr',['get_ptr',['../classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html#a656939a3dc9a6047e4afacd9e11b83a6',1,'nlohmann::basic_json::get_ptr() noexcept'],['../classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html#a234f03dce002783748ca401a42bc6472',1,'nlohmann::basic_json::get_ptr() const noexcept']]], + ['get_5fref',['get_ref',['../classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html#a1b058496e6a67565a096233cd113505b',1,'nlohmann::basic_json::get_ref()'],['../classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html#a2f1f7ca08995781acb63bd66b26ad1c1',1,'nlohmann::basic_json::get_ref() const ']]] ]; diff --git a/search/functions_6.js b/search/functions_6.js index 9b4b8210b..ffd550d5d 100644 --- a/search/functions_6.js +++ b/search/functions_6.js @@ -2,5 +2,6 @@ var searchData= [ ['get',['get',['../classnlohmann_1_1basic__json_a5f0aad50ed7e8aec3128fe018c18b3fe.html#a5f0aad50ed7e8aec3128fe018c18b3fe',1,'nlohmann::basic_json::get() const '],['../classnlohmann_1_1basic__json_ae50f22a1c646b8627e88f1313cceffd4.html#ae50f22a1c646b8627e88f1313cceffd4',1,'nlohmann::basic_json::get() noexcept'],['../classnlohmann_1_1basic__json_a76cfc5062bf6223396ab82c753cd4634.html#a76cfc5062bf6223396ab82c753cd4634',1,'nlohmann::basic_json::get() const noexcept']]], ['get_5fallocator',['get_allocator',['../classnlohmann_1_1basic__json_ad2c4513cef5d8db760c4b2d871eea42c.html#ad2c4513cef5d8db760c4b2d871eea42c',1,'nlohmann::basic_json']]], - ['get_5fptr',['get_ptr',['../classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html#a656939a3dc9a6047e4afacd9e11b83a6',1,'nlohmann::basic_json::get_ptr() noexcept'],['../classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html#a234f03dce002783748ca401a42bc6472',1,'nlohmann::basic_json::get_ptr() const noexcept']]] + ['get_5fptr',['get_ptr',['../classnlohmann_1_1basic__json_a656939a3dc9a6047e4afacd9e11b83a6.html#a656939a3dc9a6047e4afacd9e11b83a6',1,'nlohmann::basic_json::get_ptr() noexcept'],['../classnlohmann_1_1basic__json_a234f03dce002783748ca401a42bc6472.html#a234f03dce002783748ca401a42bc6472',1,'nlohmann::basic_json::get_ptr() const noexcept']]], + ['get_5fref',['get_ref',['../classnlohmann_1_1basic__json_a1b058496e6a67565a096233cd113505b.html#a1b058496e6a67565a096233cd113505b',1,'nlohmann::basic_json::get_ref()'],['../classnlohmann_1_1basic__json_a2f1f7ca08995781acb63bd66b26ad1c1.html#a2f1f7ca08995781acb63bd66b26ad1c1',1,'nlohmann::basic_json::get_ref() const ']]] ]; diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html index 9e614ecbd..274d79462 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html @@ -98,7 +98,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html index ed2100829..0fabc26e8 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html @@ -111,11 +111,11 @@ Public Member Functions struct std::hash< nlohmann::json > -

    Definition at line 7996 of file json.hpp.

    +

    Definition at line 8076 of file json.hpp.

    diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html index 2d58c7132..5c11315a8 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html @@ -112,7 +112,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    Since
    version 1.0.0
    -

    Definition at line 8003 of file json.hpp.

    +

    Definition at line 8083 of file json.hpp.

    @@ -122,7 +122,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');