diff --git a/Info.plist b/Info.plist index 18eb29ec8..a7ea1acf5 100644 --- a/Info.plist +++ b/Info.plist @@ -8,7 +8,7 @@ CFBundleIdentifier me.nlohmann.json CFBundleVersion - 2.0.6 + 2.0.7 DocSetFeedName Doxygen generated docs DocSetPublisherIdentifier diff --git a/annotated.html b/annotated.html index 1eabd81d7..3fdce6ba2 100644 --- a/annotated.html +++ b/annotated.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -79,7 +79,7 @@ $(function() { diff --git a/classes.html b/classes.html index bb542c450..886b67a4c 100644 --- a/classes.html +++ b/classes.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -83,7 +83,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json-members.html b/classnlohmann_1_1basic__json-members.html index 210b1066b..bff41db58 100644 --- a/classnlohmann_1_1basic__json-members.html +++ b/classnlohmann_1_1basic__json-members.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -236,7 +236,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json.html b/classnlohmann_1_1basic__json.html index a61f119bd..9aebeaef8 100644 --- a/classnlohmann_1_1basic__json.html +++ b/classnlohmann_1_1basic__json.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -752,7 +752,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 bfd881cca..df77e026e 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator-members.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -105,7 +105,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json_1_1const__iterator.html b/classnlohmann_1_1basic__json_1_1const__iterator.html index b7afa2c59..bb16731de 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -197,7 +197,7 @@ class nlohmann::basic_json::const_iterator diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html index ec8caed69..7c5130931 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a0e717ab658d27f646a3c8602cac91d83.html b/classnlohmann_1_1basic__json_1_1const__iterator_a0e717ab658d27f646a3c8602cac91d83.html index b7b043f32..2e694e952 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a0e717ab658d27f646a3c8602cac91d83.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a0e717ab658d27f646a3c8602cac91d83.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a0f42e99f14ac0a46456cf96fb384f290.html b/classnlohmann_1_1basic__json_1_1const__iterator_a0f42e99f14ac0a46456cf96fb384f290.html index 79d43c49a..1d9d77868 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a0f42e99f14ac0a46456cf96fb384f290.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a0f42e99f14ac0a46456cf96fb384f290.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html index 17f43771e..3e29a863b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -147,7 +147,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html index 3a6760257..911bb12c7 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a1ed92c14d88b802345bd15417a417a5d.html b/classnlohmann_1_1basic__json_1_1const__iterator_a1ed92c14d88b802345bd15417a417a5d.html index 5c2ed0e5a..52d0d344b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a1ed92c14d88b802345bd15417a417a5d.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a1ed92c14d88b802345bd15417a417a5d.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html b/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html index 861f17f81..33a7962f3 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -148,7 +148,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a2b6561a7b39b9aa3a220aa3b6e2d9589.html b/classnlohmann_1_1basic__json_1_1const__iterator_a2b6561a7b39b9aa3a220aa3b6e2d9589.html index 702c670fc..bd8fb18ed 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a2b6561a7b39b9aa3a220aa3b6e2d9589.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a2b6561a7b39b9aa3a220aa3b6e2d9589.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -147,7 +147,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a2defc155f17e8325747d2f884bb60eab.html b/classnlohmann_1_1basic__json_1_1const__iterator_a2defc155f17e8325747d2f884bb60eab.html index 2541cac58..f712b975d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a2defc155f17e8325747d2f884bb60eab.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a2defc155f17e8325747d2f884bb60eab.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a3a7ed729e72bc7c1d0b75ed8cc2bd830.html b/classnlohmann_1_1basic__json_1_1const__iterator_a3a7ed729e72bc7c1d0b75ed8cc2bd830.html index 9070a9032..3789ec2ed 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a3a7ed729e72bc7c1d0b75ed8cc2bd830.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a3a7ed729e72bc7c1d0b75ed8cc2bd830.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html index 804acc4b2..804dc7654 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html index efba8d8c1..e84ad2df8 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -147,7 +147,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html index ff0c07f33..391a91599 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a70caca372e345c9c700ab849c3d9463b.html b/classnlohmann_1_1basic__json_1_1const__iterator_a70caca372e345c9c700ab849c3d9463b.html index 046edc952..751cd699c 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a70caca372e345c9c700ab849c3d9463b.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a70caca372e345c9c700ab849c3d9463b.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html index 1257cbec4..d4faf464a 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html index d2f6b524b..d6e166225 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html index 6514515c6..4c28bbb1a 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html index 5326335f0..a68990c5d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html index c00a2f010..53ee0a388 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab31ede5b25ad5e8a3bb06f6eadb50923.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab31ede5b25ad5e8a3bb06f6eadb50923.html index 33413e64b..2b3c6563c 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab31ede5b25ad5e8a3bb06f6eadb50923.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab31ede5b25ad5e8a3bb06f6eadb50923.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abae808b09a822cc3da4cef0efb89115d.html b/classnlohmann_1_1basic__json_1_1const__iterator_abae808b09a822cc3da4cef0efb89115d.html index baba8af9f..ba939db85 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abae808b09a822cc3da4cef0efb89115d.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abae808b09a822cc3da4cef0efb89115d.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html index 0961258b2..c53dad4a4 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html index cb8cff697..213ad97a3 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -137,7 +137,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_acf1fcb73ff770117446670cefc927dd2.html b/classnlohmann_1_1basic__json_1_1const__iterator_acf1fcb73ff770117446670cefc927dd2.html index f2fdf50f7..3dad205ca 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_acf1fcb73ff770117446670cefc927dd2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_acf1fcb73ff770117446670cefc927dd2.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_acfc918b6350449111ca58af5eb3da999.html b/classnlohmann_1_1basic__json_1_1const__iterator_acfc918b6350449111ca58af5eb3da999.html index daed84345..75fef0520 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_acfc918b6350449111ca58af5eb3da999.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_acfc918b6350449111ca58af5eb3da999.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html index ac62033bd..78d190ae0 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -136,7 +136,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html index 62d48f2f2..5037abe61 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -140,7 +140,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ae0f996eef6a970b2e654c4f6d33d6f9a.html b/classnlohmann_1_1basic__json_1_1const__iterator_ae0f996eef6a970b2e654c4f6d33d6f9a.html index 56d7a4829..4325a3d27 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ae0f996eef6a970b2e654c4f6d33d6f9a.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ae0f996eef6a970b2e654c4f6d33d6f9a.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html index fa1b8d0e3..56a863210 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html index 6e547f412..b1c1fce86 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_af3ef241a9e26398ea0cf45026287c2ed.html b/classnlohmann_1_1basic__json_1_1const__iterator_af3ef241a9e26398ea0cf45026287c2ed.html index 3e57b5a4b..0eb24786b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_af3ef241a9e26398ea0cf45026287c2ed.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_af3ef241a9e26398ea0cf45026287c2ed.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator-members.html b/classnlohmann_1_1basic__json_1_1iterator-members.html index 1f39403bc..e3f86c6fa 100644 --- a/classnlohmann_1_1basic__json_1_1iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1iterator-members.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -110,7 +110,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json_1_1iterator.html b/classnlohmann_1_1basic__json_1_1iterator.html index c4105fb8e..ba1baa3ad 100644 --- a/classnlohmann_1_1basic__json_1_1iterator.html +++ b/classnlohmann_1_1basic__json_1_1iterator.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -248,7 +248,7 @@ class nlohmann::basic_json::iterator diff --git a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html index bf936712a..9836c5c89 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html index 9a7bb9c57..f4788a24a 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a12c7f8236ffa08a5dd27cbd9888b74be.html b/classnlohmann_1_1basic__json_1_1iterator_a12c7f8236ffa08a5dd27cbd9888b74be.html index dcc184778..c6a969c59 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a12c7f8236ffa08a5dd27cbd9888b74be.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a12c7f8236ffa08a5dd27cbd9888b74be.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a1af28ba60302eb48edf4fdbc88e75903.html b/classnlohmann_1_1basic__json_1_1iterator_a1af28ba60302eb48edf4fdbc88e75903.html index 8b673a79e..3d08426e2 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a1af28ba60302eb48edf4fdbc88e75903.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a1af28ba60302eb48edf4fdbc88e75903.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html index 44e824d36..d1ea67ec9 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html index 35d6d2bc3..786e718eb 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a381124603cecc478e8746dcf4e11728c.html b/classnlohmann_1_1basic__json_1_1iterator_a381124603cecc478e8746dcf4e11728c.html index 00c0c9f31..e1a715852 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a381124603cecc478e8746dcf4e11728c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a381124603cecc478e8746dcf4e11728c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html index 0b453a09e..22b106ac0 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -117,7 +117,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html b/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html index 741346257..22bd3c6ce 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a51b0ed345317cfd1b2386f481d774477.html b/classnlohmann_1_1basic__json_1_1iterator_a51b0ed345317cfd1b2386f481d774477.html index 9d99a2172..4bfdf3d97 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a51b0ed345317cfd1b2386f481d774477.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a51b0ed345317cfd1b2386f481d774477.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html b/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html index 3ac2c3d31..1555587c6 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a72ce0abec8c72610925d83a9b309f3e4.html b/classnlohmann_1_1basic__json_1_1iterator_a72ce0abec8c72610925d83a9b309f3e4.html index c26097a86..cfb343d91 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a72ce0abec8c72610925d83a9b309f3e4.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a72ce0abec8c72610925d83a9b309f3e4.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html index 56c08c6f7..09cec6fff 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html index 71a601dc1..faa9e8ad4 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -117,7 +117,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html index 0dc8ccf52..f79383208 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html index 20f93153f..0f938984c 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html index 98e9105e6..8197965c6 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -117,7 +117,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_ac688806417f3b4e17c4eb1b661b522f1.html b/classnlohmann_1_1basic__json_1_1iterator_ac688806417f3b4e17c4eb1b661b522f1.html index 67df58893..a01cfca5d 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ac688806417f3b4e17c4eb1b661b522f1.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ac688806417f3b4e17c4eb1b661b522f1.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -128,7 +128,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html b/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html index 780a53288..c53a6159c 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html index a6f8fbdae..7bc371bc2 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -129,7 +129,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1json__pointer-members.html b/classnlohmann_1_1basic__json_1_1json__pointer-members.html index 411b99e4f..654501b63 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer-members.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer-members.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -78,7 +78,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json_1_1json__pointer.html b/classnlohmann_1_1basic__json_1_1json__pointer.html index dd2af1ab1..e559fe808 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -104,11 +104,11 @@ class nlohmann::basic_json::json_pointer
See also
RFC 6901
Since
version 2.0.0
-

Definition at line 9284 of file json.hpp.

+

Definition at line 9452 of file json.hpp.

diff --git a/classnlohmann_1_1basic__json_1_1json__pointer_a319e945a9349ed49fe3a62bc023c8d23.html b/classnlohmann_1_1basic__json_1_1json__pointer_a319e945a9349ed49fe3a62bc023c8d23.html index 12c0ee7cc..8a31cd08d 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer_a319e945a9349ed49fe3a62bc023c8d23.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer_a319e945a9349ed49fe3a62bc023c8d23.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -103,7 +103,7 @@ template<template< typename U, typename V, typename... Args > class Obj
Invariant
For each JSON pointer ptr, it holds:
ptr == json_pointer(ptr.to_string());
Returns
a string representation of the JSON pointer
-
Example
The example shows the result of to_string.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // different JSON Pointers
8  json::json_pointer ptr1("");
9  json::json_pointer ptr2("/foo");
10  json::json_pointer ptr3("/foo/0");
11  json::json_pointer ptr4("/");
12  json::json_pointer ptr5("/a~1b");
13  json::json_pointer ptr6("/c%d");
14  json::json_pointer ptr7("/e^f");
15  json::json_pointer ptr8("/g|h");
16  json::json_pointer ptr9("/i\\j");
17  json::json_pointer ptr10("/k\"l");
18  json::json_pointer ptr11("/ ");
19  json::json_pointer ptr12("/m~0n");
20 
21 
22  std::cout << ptr1.to_string() << '\n'
23  << ptr2.to_string() << '\n'
24  << ptr3.to_string() << '\n'
25  << ptr4.to_string() << '\n'
26  << ptr5.to_string() << '\n'
27  << ptr6.to_string() << '\n'
28  << ptr7.to_string() << '\n'
29  << ptr8.to_string() << '\n'
30  << ptr9.to_string() << '\n'
31  << ptr10.to_string() << '\n'
32  << ptr11.to_string() << '\n'
33  << ptr12.to_string() << std::endl;
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10545
+
Example
The example shows the result of to_string.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // different JSON Pointers
8  json::json_pointer ptr1("");
9  json::json_pointer ptr2("/foo");
10  json::json_pointer ptr3("/foo/0");
11  json::json_pointer ptr4("/");
12  json::json_pointer ptr5("/a~1b");
13  json::json_pointer ptr6("/c%d");
14  json::json_pointer ptr7("/e^f");
15  json::json_pointer ptr8("/g|h");
16  json::json_pointer ptr9("/i\\j");
17  json::json_pointer ptr10("/k\"l");
18  json::json_pointer ptr11("/ ");
19  json::json_pointer ptr12("/m~0n");
20 
21 
22  std::cout << ptr1.to_string() << '\n'
23  << ptr2.to_string() << '\n'
24  << ptr3.to_string() << '\n'
25  << ptr4.to_string() << '\n'
26  << ptr5.to_string() << '\n'
27  << ptr6.to_string() << '\n'
28  << ptr7.to_string() << '\n'
29  << ptr8.to_string() << '\n'
30  << ptr9.to_string() << '\n'
31  << ptr10.to_string() << '\n'
32  << ptr11.to_string() << '\n'
33  << ptr12.to_string() << std::endl;
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10713
Output (play with this example online):
 /foo
 /foo/0
@@ -121,7 +121,7 @@ json_pointer__to_string.cpp -o
 json_pointer__to_string 
Since
version 2.0.0
-

Definition at line 9346 of file json.hpp.

+

Definition at line 9514 of file json.hpp.

@@ -131,7 +131,7 @@ json_pointer__to_string diff --git a/classnlohmann_1_1basic__json_1_1json__pointer_a5670f575e57c3b1feb3e934a345d1aaa.html b/classnlohmann_1_1basic__json_1_1json__pointer_a5670f575e57c3b1feb3e934a345d1aaa.html index 2fdb65671..e42a5ca8a 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer_a5670f575e57c3b1feb3e934a345d1aaa.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer_a5670f575e57c3b1feb3e934a345d1aaa.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -103,7 +103,7 @@ template<template< typename U, typename V, typename... Args > class Obj
Invariant
For each JSON pointer ptr, it holds:
ptr == json_pointer(ptr.to_string());
Returns
a string representation of the JSON pointer
-
Example
The example shows the result of to_string.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // different JSON Pointers
8  json::json_pointer ptr1("");
9  json::json_pointer ptr2("/foo");
10  json::json_pointer ptr3("/foo/0");
11  json::json_pointer ptr4("/");
12  json::json_pointer ptr5("/a~1b");
13  json::json_pointer ptr6("/c%d");
14  json::json_pointer ptr7("/e^f");
15  json::json_pointer ptr8("/g|h");
16  json::json_pointer ptr9("/i\\j");
17  json::json_pointer ptr10("/k\"l");
18  json::json_pointer ptr11("/ ");
19  json::json_pointer ptr12("/m~0n");
20 
21 
22  std::cout << ptr1.to_string() << '\n'
23  << ptr2.to_string() << '\n'
24  << ptr3.to_string() << '\n'
25  << ptr4.to_string() << '\n'
26  << ptr5.to_string() << '\n'
27  << ptr6.to_string() << '\n'
28  << ptr7.to_string() << '\n'
29  << ptr8.to_string() << '\n'
30  << ptr9.to_string() << '\n'
31  << ptr10.to_string() << '\n'
32  << ptr11.to_string() << '\n'
33  << ptr12.to_string() << std::endl;
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10545
+
Example
The example shows the result of to_string.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // different JSON Pointers
8  json::json_pointer ptr1("");
9  json::json_pointer ptr2("/foo");
10  json::json_pointer ptr3("/foo/0");
11  json::json_pointer ptr4("/");
12  json::json_pointer ptr5("/a~1b");
13  json::json_pointer ptr6("/c%d");
14  json::json_pointer ptr7("/e^f");
15  json::json_pointer ptr8("/g|h");
16  json::json_pointer ptr9("/i\\j");
17  json::json_pointer ptr10("/k\"l");
18  json::json_pointer ptr11("/ ");
19  json::json_pointer ptr12("/m~0n");
20 
21 
22  std::cout << ptr1.to_string() << '\n'
23  << ptr2.to_string() << '\n'
24  << ptr3.to_string() << '\n'
25  << ptr4.to_string() << '\n'
26  << ptr5.to_string() << '\n'
27  << ptr6.to_string() << '\n'
28  << ptr7.to_string() << '\n'
29  << ptr8.to_string() << '\n'
30  << ptr9.to_string() << '\n'
31  << ptr10.to_string() << '\n'
32  << ptr11.to_string() << '\n'
33  << ptr12.to_string() << std::endl;
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10713
Output (play with this example online):
 /foo
 /foo/0
@@ -121,7 +121,7 @@ json_pointer__to_string.cpp -o
 json_pointer__to_string 
Since
version 2.0.0
-

Definition at line 9335 of file json.hpp.

+

Definition at line 9503 of file json.hpp.

@@ -131,7 +131,7 @@ json_pointer__to_string diff --git a/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html b/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html index b680e62a4..86d3a1c61 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -99,7 +99,7 @@ template<template< typename U, typename V, typename... Args > class Obj
-

Definition at line 9287 of file json.hpp.

+

Definition at line 9455 of file json.hpp.

@@ -109,7 +109,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_1_1json__pointer_ae12db117a2742d826465080979d7c835.html b/classnlohmann_1_1basic__json_1_1json__pointer_ae12db117a2742d826465080979d7c835.html index b19b572cb..95724aecd 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer_ae12db117a2742d826465080979d7c835.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer_ae12db117a2742d826465080979d7c835.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -118,14 +118,14 @@ begin with /" -
Example
The example shows the construction several valid JSON pointers as well as the exceptional behavior.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // correct JSON pointers
8  json::json_pointer p1;
9  json::json_pointer p2("");
10  json::json_pointer p3("/");
11  json::json_pointer p4("//");
12  json::json_pointer p5("/foo/bar");
13  json::json_pointer p6("/foo/bar/-");
14  json::json_pointer p7("/foo/~0");
15  json::json_pointer p8("/foo/~1");
16 
17  // error: JSON pointer does not begin with a slash
18  try
19  {
20  json::json_pointer p9("foo");
21  }
22  catch (std::domain_error& e)
23  {
24  std::cout << "domain_error: " << e.what() << '\n';
25  }
26 
27  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
28  try
29  {
30  json::json_pointer p10("/foo/~");
31  }
32  catch (std::domain_error& e)
33  {
34  std::cout << "domain_error: " << e.what() << '\n';
35  }
36 
37  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
38  try
39  {
40  json::json_pointer p11("/foo/~3");
41  }
42  catch (std::domain_error& e)
43  {
44  std::cout << "domain_error: " << e.what() << '\n';
45  }
46 }
basic_json<> json
default JSON class
Definition: json.hpp:10545
+
Example
The example shows the construction several valid JSON pointers as well as the exceptional behavior.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
4 
5 int main()
6 {
7  // correct JSON pointers
8  json::json_pointer p1;
9  json::json_pointer p2("");
10  json::json_pointer p3("/");
11  json::json_pointer p4("//");
12  json::json_pointer p5("/foo/bar");
13  json::json_pointer p6("/foo/bar/-");
14  json::json_pointer p7("/foo/~0");
15  json::json_pointer p8("/foo/~1");
16 
17  // error: JSON pointer does not begin with a slash
18  try
19  {
20  json::json_pointer p9("foo");
21  }
22  catch (std::domain_error& e)
23  {
24  std::cout << "domain_error: " << e.what() << '\n';
25  }
26 
27  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
28  try
29  {
30  json::json_pointer p10("/foo/~");
31  }
32  catch (std::domain_error& e)
33  {
34  std::cout << "domain_error: " << e.what() << '\n';
35  }
36 
37  // error: JSON pointer uses escape symbol ~ not followed by 0 or 1
38  try
39  {
40  json::json_pointer p11("/foo/~3");
41  }
42  catch (std::domain_error& e)
43  {
44  std::cout << "domain_error: " << e.what() << '\n';
45  }
46 }
basic_json<> json
default JSON class
Definition: json.hpp:10713
Output (play with this example online):
domain_error: JSON pointer must be empty or begin with '/'
 domain_error: escape error: '~' must be followed with '0' or '1'
 domain_error: escape error: '~' must be followed with '0' or '1'
 
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/json_pointer.cpp -o json_pointer 
Since
version 2.0.0
-

Definition at line 9312 of file json.hpp.

+

Definition at line 9480 of file json.hpp.

@@ -135,7 +135,7 @@ domain_error: escape error: '~' must be followed with '0' or '1' 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 b359e0faf..9e6815174 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -89,7 +89,7 @@ $(function() { diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html index 3a55b2c4a..cd13b432e 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -151,7 +151,7 @@ class nlohmann::basic_json::json_reverse_iterator< Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2f5d8a81d607f9222d1ade23f24cc093.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2f5d8a81d607f9222d1ade23f24cc093.html index 62905024b..4f30804ef 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2f5d8a81d607f9222d1ade23f24cc093.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a2f5d8a81d607f9222d1ade23f24cc093.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -125,7 +125,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a3697e7d404d29c4ecc142b531e80da1e.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a3697e7d404d29c4ecc142b531e80da1e.html index 1460e3872..658a7991a 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a3697e7d404d29c4ecc142b531e80da1e.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a3697e7d404d29c4ecc142b531e80da1e.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a405fe504aa2a804c9df1c22a1ebd1283.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a405fe504aa2a804c9df1c22a1ebd1283.html index 4e462a0f3..e2cd4e950 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a405fe504aa2a804c9df1c22a1ebd1283.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a405fe504aa2a804c9df1c22a1ebd1283.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html index 2ddc13340..326fb5679 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -125,7 +125,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html index 95fad1c9e..d6aa06639 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html index 0f42c2a0b..442e698fd 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html index 475343a68..fd8297275 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -125,7 +125,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html index d136dc32d..abd0710d2 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html index 79b694ee8..4cc4cf865 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -114,7 +114,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html index 17a563284..a0f3641fb 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html index 4e61ba224..844f3c51e 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html index 6c5043124..fe01766f3 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -114,7 +114,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acdfece338718749f2d0b19f77b867036.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acdfece338718749f2d0b19f77b867036.html index cdf6c6ff6..34d1d1311 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acdfece338718749f2d0b19f77b867036.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acdfece338718749f2d0b19f77b867036.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad51b38d5428a79fd6ef4fa221b242dcf.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad51b38d5428a79fd6ef4fa221b242dcf.html index db0a76543..158494dbf 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad51b38d5428a79fd6ef4fa221b242dcf.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad51b38d5428a79fd6ef4fa221b242dcf.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -126,7 +126,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af1c8b1f3be60159ae0829938a4e674fa.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af1c8b1f3be60159ae0829938a4e674fa.html index 8adfde9be..3362f35c7 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af1c8b1f3be60159ae0829938a4e674fa.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_af1c8b1f3be60159ae0829938a4e674fa.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -125,7 +125,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_a02397f02bb1182bf1e1bc7ecf7f2c227.html b/classnlohmann_1_1basic__json_a02397f02bb1182bf1e1bc7ecf7f2c227.html index 4e4232aad..a67f5499f 100644 --- a/classnlohmann_1_1basic__json_a02397f02bb1182bf1e1bc7ecf7f2c227.html +++ b/classnlohmann_1_1basic__json_a02397f02bb1182bf1e1bc7ecf7f2c227.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
Returns
the type of the JSON value
Complexity
Constant.
Exception safety
No-throw guarantee: this member function never throws exceptions.
-
Example
The following code exemplifies the value_t operator for all JSON types.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
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 operator value_t()
17  json::value_t t_null = j_null;
18  json::value_t t_boolean = j_boolean;
19  json::value_t t_number_integer = j_number_integer;
20  json::value_t t_number_float = j_number_float;
21  json::value_t t_object = j_object;
22  json::value_t t_array = j_array;
23  json::value_t t_string = j_string;
24 
25  // print types
26  std::cout << std::boolalpha;
27  std::cout << (t_null == json::value_t::null) << '\n';
28  std::cout << (t_boolean == json::value_t::boolean) << '\n';
29  std::cout << (t_number_integer == json::value_t::number_integer) << '\n';
30  std::cout << (t_number_float == json::value_t::number_float) << '\n';
31  std::cout << (t_object == json::value_t::object) << '\n';
32  std::cout << (t_array == json::value_t::array) << '\n';
33  std::cout << (t_string == json::value_t::string) << '\n';
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10545
+
Example
The following code exemplifies the value_t operator for all JSON types.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
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 operator value_t()
17  json::value_t t_null = j_null;
18  json::value_t t_boolean = j_boolean;
19  json::value_t t_number_integer = j_number_integer;
20  json::value_t t_number_float = j_number_float;
21  json::value_t t_object = j_object;
22  json::value_t t_array = j_array;
23  json::value_t t_string = j_string;
24 
25  // print types
26  std::cout << std::boolalpha;
27  std::cout << (t_null == json::value_t::null) << '\n';
28  std::cout << (t_boolean == json::value_t::boolean) << '\n';
29  std::cout << (t_number_integer == json::value_t::number_integer) << '\n';
30  std::cout << (t_number_float == json::value_t::number_float) << '\n';
31  std::cout << (t_object == json::value_t::object) << '\n';
32  std::cout << (t_array == json::value_t::array) << '\n';
33  std::cout << (t_string == json::value_t::string) << '\n';
34 }
basic_json<> json
default JSON class
Definition: json.hpp:10713
object (unordered set of name/value pairs)
value_t
the JSON type enumeration
Definition: json.hpp:756
@@ -292,7 +292,7 @@ true
diff --git a/classnlohmann_1_1basic__json_a0491b6739b54dcf83d5e10c4f604ca8f.html b/classnlohmann_1_1basic__json_a0491b6739b54dcf83d5e10c4f604ca8f.html index 52eb99849..b21f94b51 100644 --- a/classnlohmann_1_1basic__json_a0491b6739b54dcf83d5e10c4f604ca8f.html +++ b/classnlohmann_1_1basic__json_a0491b6739b54dcf83d5e10c4f604ca8f.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -296,7 +296,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 json = nlohmann::json;
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 }
basic_json<> json
default JSON class
Definition: json.hpp:10545
+
Example
The example below shows how object elements can be queried with a default value.
1 #include <json.hpp>
2 
3 using json = nlohmann::json;
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 }
basic_json<> json
default JSON class
Definition: json.hpp:10713
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 
See also
at(const typename object_t::key_type&) for access by reference with range checking
@@ -314,7 +314,7 @@ value() with null"
diff --git a/classnlohmann_1_1basic__json_a060b33f8f255986088652625f9d50681.html b/classnlohmann_1_1basic__json_a060b33f8f255986088652625f9d50681.html index 8d0662b9e..e1ad5457d 100644 --- a/classnlohmann_1_1basic__json_a060b33f8f255986088652625f9d50681.html +++ b/classnlohmann_1_1basic__json_a060b33f8f255986088652625f9d50681.html @@ -23,7 +23,7 @@
JSON for Modern C++ -  2.0.6 +  2.0.7
@@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().
  • -
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:285
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html b/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html index ff1482aaf..76cc7b33a 100644 --- a/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html +++ b/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a0923f9749409345a21f8cb15ee95fc0d.html b/classnlohmann_1_1basic__json_a0923f9749409345a21f8cb15ee95fc0d.html index 357dc79a6..b6fd33aea 100644 --- a/classnlohmann_1_1basic__json_a0923f9749409345a21f8cb15ee95fc0d.html +++ b/classnlohmann_1_1basic__json_a0923f9749409345a21f8cb15ee95fc0d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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:10545
    +
    Example
    The example below demonstrates the parse() function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:1016
    the parser read a key of a value in an object
    @@ -333,7 +333,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html index 4df9e6010..47fea00e5 100644 --- a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html +++ b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -291,7 +291,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html b/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html index bbd2743ea..7fbba4fb7 100644 --- a/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html +++ b/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<typename T , typename std::enable_if< not(std::is_same< T, int
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of an integer number value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON number from number_integer_t
    8  json::number_integer_t value = 42;
    9 
    10  json j(value);
    11 
    12  // serialize the JSON numbers
    13  std::cout << j << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the construction of an integer number value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON number from number_integer_t
    8  json::number_integer_t value = 42;
    9 
    10  json j(value);
    11 
    12  // serialize the JSON numbers
    13  std::cout << j << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    Output (play with this example online):
    42
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__number_integer_t.cpp -o basic_json__number_integer_t 
    @@ -295,7 +295,7 @@ template<typename T , typename std::enable_if< not(std::is_same< T, int
    diff --git a/classnlohmann_1_1basic__json_a0ea8a1ecca4b3cb0ba09ad7552c364b6.html b/classnlohmann_1_1basic__json_a0ea8a1ecca4b3cb0ba09ad7552c364b6.html index d070ba7c0..096a2d89a 100644 --- a/classnlohmann_1_1basic__json_a0ea8a1ecca4b3cb0ba09ad7552c364b6.html +++ b/classnlohmann_1_1basic__json_a0ea8a1ecca4b3cb0ba09ad7552c364b6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename... Args > class Obj
  • Has the semantics of std::distance(begin(), end()).
  • -
    Example
    The following code calls size() on the different value types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code calls size() on the different value types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    0
    @@ -312,7 +312,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a1002d187e05b5323bda5de124cbe95a8.html b/classnlohmann_1_1basic__json_a1002d187e05b5323bda5de124cbe95a8.html index d60767d6d..1cba344c1 100644 --- a/classnlohmann_1_1basic__json_a1002d187e05b5323bda5de124cbe95a8.html +++ b/classnlohmann_1_1basic__json_a1002d187e05b5323bda5de124cbe95a8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -264,7 +264,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is discarded, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_discarded() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_discarded()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_discarded() << '\n';
    20  std::cout << j_boolean.is_discarded() << '\n';
    21  std::cout << j_number_integer.is_discarded() << '\n';
    22  std::cout << j_number_unsigned_integer.is_discarded() << '\n';
    23  std::cout << j_number_float.is_discarded() << '\n';
    24  std::cout << j_object.is_discarded() << '\n';
    25  std::cout << j_array.is_discarded() << '\n';
    26  std::cout << j_string.is_discarded() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_discarded() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_discarded()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_discarded() << '\n';
    20  std::cout << j_boolean.is_discarded() << '\n';
    21  std::cout << j_number_integer.is_discarded() << '\n';
    22  std::cout << j_number_unsigned_integer.is_discarded() << '\n';
    23  std::cout << j_number_float.is_discarded() << '\n';
    24  std::cout << j_object.is_discarded() << '\n';
    25  std::cout << j_array.is_discarded() << '\n';
    26  std::cout << j_string.is_discarded() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -286,7 +286,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html index 9420f89e0..130a3d338 100644 --- a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html +++ b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -279,7 +279,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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:10545
    +
    Example
    The following code shows examples for the basic_json(size_type, const basic_json&) constructor.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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:10713
    Output (play with this example online):
    []
     ["Hello"]
     ["Hello","Hello","Hello","Hello","Hello"]
    @@ -296,7 +296,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html index 02df95f2f..c495daf18 100644 --- a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html +++ b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether the values lhs and rhs are equal
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.000000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.000000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 == array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 == object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 == number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 == string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
     {"A":"a","B":"b"} == {"A":"a","B":"b"} true
     17 == 17 true
    @@ -302,7 +302,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html b/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html index a83183e05..2458d4494 100644 --- a/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html +++ b/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • The complexity is constant.
  • -
    Example
    The following code shows an example for end().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for end().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    cend() – returns a const iterator to the end
    @@ -290,7 +290,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html index 88189868a..2ae8793dc 100644 --- a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html +++ b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ template<typename T , std::size_t n>
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
     {
    @@ -314,7 +314,7 @@ template<typename T , std::size_t n> 
    diff --git a/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html b/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html index e8c10dcfc..8b07e8b30 100644 --- a/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html +++ b/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a15e70a44e2a8db929694819fed256653.html b/classnlohmann_1_1basic__json_a15e70a44e2a8db929694819fed256653.html index a23ae6901..842004b24 100644 --- a/classnlohmann_1_1basic__json_a15e70a44e2a8db929694819fed256653.html +++ b/classnlohmann_1_1basic__json_a15e70a44e2a8db929694819fed256653.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().
  • -
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:285
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html index 829f1f279..ac6fa5103 100644 --- a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html +++ b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html index 014bb02ba..a1fbe3dac 100644 --- a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html +++ b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a1eb1a32bfce21629e64a510d945e01c5.html b/classnlohmann_1_1basic__json_a1eb1a32bfce21629e64a510d945e01c5.html index 42f92e303..a9713c6d8 100644 --- a/classnlohmann_1_1basic__json_a1eb1a32bfce21629e64a510d945e01c5.html +++ b/classnlohmann_1_1basic__json_a1eb1a32bfce21629e64a510d945e01c5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  const json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  const json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -285,7 +285,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorjson_pointer_const.cpp -o operatorjson_pointer_const 
    Since
    version 2.0.0
    -

    Definition at line 9943 of file json.hpp.

    +

    Definition at line 10111 of file json.hpp.

    @@ -295,7 +295,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a20d85eb83c2c0cfa0918f630b192635c.html b/classnlohmann_1_1basic__json_a20d85eb83c2c0cfa0918f630b192635c.html index e06523606..e12f84465 100644 --- a/classnlohmann_1_1basic__json_a20d85eb83c2c0cfa0918f630b192635c.html +++ b/classnlohmann_1_1basic__json_a20d85eb83c2c0cfa0918f630b192635c.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    Number of elements with key key. If the JSON value is not an object, the return value will be 0.
    Complexity
    Logarithmic in the size of the JSON object.
    -
    Example
    The example shows how count() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 << "number of elements with key \"two\": " << count_two << '\n';
    16  std::cout << "number of elements with key \"three\": " << count_three << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how count() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 << "number of elements with key \"two\": " << count_two << '\n';
    16  std::cout << "number of elements with key \"three\": " << count_three << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -285,7 +285,7 @@ number of elements with key "three": 0
    diff --git a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html index ecd91b957..a20731f6b 100644 --- a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html +++ b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read and written using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how array elements can be read and written using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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:1720
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:3151
    Output (play with this example online):
    "third"
    @@ -295,7 +295,7 @@ out of range: array index 5 is out of range
     
    diff --git a/classnlohmann_1_1basic__json_a2256d4912473af915739ddde259c7ca8.html b/classnlohmann_1_1basic__json_a2256d4912473af915739ddde259c7ca8.html index c53ba28e5..7e7c44b96 100644 --- a/classnlohmann_1_1basic__json_a2256d4912473af915739ddde259c7ca8.html +++ b/classnlohmann_1_1basic__json_a2256d4912473af915739ddde259c7ca8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -293,7 +293,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html index 3ebfb368b..79bd05d1b 100644 --- a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html +++ b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -291,7 +291,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html b/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html index 801b11e52..ecc6dd808 100644 --- a/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html +++ b/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -286,7 +286,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a256a4cef002023acab3c9d75b569f54a.html b/classnlohmann_1_1basic__json_a256a4cef002023acab3c9d75b569f54a.html index ee32db79c..b32c7d168 100644 --- a/classnlohmann_1_1basic__json_a256a4cef002023acab3c9d75b569f54a.html +++ b/classnlohmann_1_1basic__json_a256a4cef002023acab3c9d75b569f54a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is array, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_array() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_array()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_array() << '\n';
    20  std::cout << j_boolean.is_array() << '\n';
    21  std::cout << j_number_integer.is_array() << '\n';
    22  std::cout << j_number_unsigned_integer.is_array() << '\n';
    23  std::cout << j_number_float.is_array() << '\n';
    24  std::cout << j_object.is_array() << '\n';
    25  std::cout << j_array.is_array() << '\n';
    26  std::cout << j_string.is_array() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_array() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_array()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_array() << '\n';
    20  std::cout << j_boolean.is_array() << '\n';
    21  std::cout << j_number_integer.is_array() << '\n';
    22  std::cout << j_number_unsigned_integer.is_array() << '\n';
    23  std::cout << j_number_float.is_array() << '\n';
    24  std::cout << j_object.is_array() << '\n';
    25  std::cout << j_array.is_array() << '\n';
    26  std::cout << j_string.is_array() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -285,7 +285,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html b/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html index 307a36d55..5e0e8bebc 100644 --- a/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html +++ b/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -272,7 +272,7 @@ template<template< typename U, typename V, typename... Args > class Obj In case the parameter val is not a number, a JSON null value is created instead.
    Complexity
    Constant.
    -
    Example
    The following example creates several floating-point values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  json::number_float_t v_ok = 3.141592653589793;
    9  json::number_float_t v_nan = NAN;
    10  json::number_float_t v_infinity = INFINITY;
    11 
    12  // create JSON numbers
    13  json j_ok(v_ok);
    14  json j_nan(v_nan);
    15  json j_infinity(v_infinity);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j_ok << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j_infinity << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following example creates several floating-point values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  json::number_float_t v_ok = 3.141592653589793;
    9  json::number_float_t v_nan = NAN;
    10  json::number_float_t v_infinity = INFINITY;
    11 
    12  // create JSON numbers
    13  json j_ok(v_ok);
    14  json j_nan(v_nan);
    15  json j_infinity(v_infinity);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j_ok << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j_infinity << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    Output (play with this example online):
    3.14159265358979
     null
    @@ -291,7 +291,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a2dea7491d9fa709311459f87201e25aa.html b/classnlohmann_1_1basic__json_a2dea7491d9fa709311459f87201e25aa.html index abedb6e5a..79a1d64e8 100644 --- a/classnlohmann_1_1basic__json_a2dea7491d9fa709311459f87201e25aa.html +++ b/classnlohmann_1_1basic__json_a2dea7491d9fa709311459f87201e25aa.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ 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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how array elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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
    @@ -291,7 +291,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_a2dff00633c2e914fa464f23b4bce6bcb.html b/classnlohmann_1_1basic__json_a2dff00633c2e914fa464f23b4bce6bcb.html index d051b01d7..e48578f84 100644 --- a/classnlohmann_1_1basic__json_a2dff00633c2e914fa464f23b4bce6bcb.html +++ b/classnlohmann_1_1basic__json_a2dff00633c2e914fa464f23b4bce6bcb.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -294,7 +294,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 json = nlohmann::json;
    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"_json_pointer, 0);
    20  double v_floating = j.value("/floating"_json_pointer, 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("/nonexisting"_json_pointer, "oops");
    24  bool v_boolean = j.value("/nonexisting"_json_pointer, false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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"_json_pointer, 0);
    20  double v_floating = j.value("/floating"_json_pointer, 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("/nonexisting"_json_pointer, "oops");
    24  bool v_boolean = j.value("/nonexisting"_json_pointer, false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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_ptr.cpp -o basic_json__value_ptr 
    See also
    operator[](const json_pointer&) for unchecked access by reference
    @@ -310,7 +310,7 @@ value() with null"
    diff --git a/classnlohmann_1_1basic__json_a2ec9378f9545adf4b79099aa8f8a1673.html b/classnlohmann_1_1basic__json_a2ec9378f9545adf4b79099aa8f8a1673.html index eb7b3c851..9f55ad944 100644 --- a/classnlohmann_1_1basic__json_a2ec9378f9545adf4b79099aa8f8a1673.html +++ b/classnlohmann_1_1basic__json_a2ec9378f9545adf4b79099aa8f8a1673.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "il brutto"
     out of range
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at__object_t_key_type_const.cpp -o at__object_t_key_type_const 
    @@ -295,7 +295,7 @@ out of range
    diff --git a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html index f0828feec..1fdc9b808 100644 --- a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html +++ b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a2f774129440c427253dc97406e2d9010.html b/classnlohmann_1_1basic__json_a2f774129440c427253dc97406e2d9010.html index 111ce0841..131ce9409 100644 --- a/classnlohmann_1_1basic__json_a2f774129440c427253dc97406e2d9010.html +++ b/classnlohmann_1_1basic__json_a2f774129440c427253dc97406e2d9010.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -268,7 +268,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON values can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how JSON values can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -284,7 +284,7 @@ j2 = [1,2,3,4,5]
    diff --git a/classnlohmann_1_1basic__json_a32350263eb105764844c5a85e156a255.html b/classnlohmann_1_1basic__json_a32350263eb105764844c5a85e156a255.html index 7c0e26a05..8893de951 100644 --- a/classnlohmann_1_1basic__json_a32350263eb105764844c5a85e156a255.html +++ b/classnlohmann_1_1basic__json_a32350263eb105764844c5a85e156a255.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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.
    Deprecated:
    This constructor is deprecated and will be removed in version 3.0.0 to unify the interface of the library. Deserialization will be done by stream operators or by calling one of the parse functions, e.g. parse(std::istream&, const parser_callback_t). That is, calls like json j(i); for an input stream i need to be replaced by json j = json::parse(i);. See the example below.
    -
    Example
    The example below demonstrates constructing a JSON value from a std::stringstream with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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  // create JSON from stream
    30  json j_complete(ss); // deprecated!
    31  // shall be replaced by: json j_complete = json::parse(ss);
    32  std::cout << std::setw(4) << j_complete << "\n\n";
    33 
    34 
    35  // define parser callback
    36  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
    37  {
    38  // skip object elements with key "Thumbnail"
    39  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
    40  {
    41  return false;
    42  }
    43  else
    44  {
    45  return true;
    46  }
    47  };
    48 
    49  // fill a stream with JSON text
    50  ss.clear();
    51  ss << text;
    52 
    53  // create JSON from stream (with callback)
    54  json j_filtered(ss, cb);
    55  // shall be replaced by: json j_filtered = json::parse(ss, cb);
    56  std::cout << std::setw(4) << j_filtered << '\n';
    57 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below demonstrates constructing a JSON value from a std::stringstream with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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  // create JSON from stream
    30  json j_complete(ss); // deprecated!
    31  // shall be replaced by: json j_complete = json::parse(ss);
    32  std::cout << std::setw(4) << j_complete << "\n\n";
    33 
    34 
    35  // define parser callback
    36  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
    37  {
    38  // skip object elements with key "Thumbnail"
    39  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
    40  {
    41  return false;
    42  }
    43  else
    44  {
    45  return true;
    46  }
    47  };
    48 
    49  // fill a stream with JSON text
    50  ss.clear();
    51  ss << text;
    52 
    53  // create JSON from stream (with callback)
    54  json j_filtered(ss, cb);
    55  // shall be replaced by: json j_filtered = json::parse(ss, cb);
    56  std::cout << std::setw(4) << j_filtered << '\n';
    57 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:1016
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:946
    @@ -331,7 +331,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html index b6c8c44f9..2ca37098a 100644 --- a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html +++ b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -281,7 +281,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    the stream o
    Complexity
    Linear.
    -
    Example
    The example below shows the serialization with different parameters to width to adjust the indentation level.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // serialize without indentation
    12  std::cout << j_object << "\n\n";
    13  std::cout << j_array << "\n\n";
    14 
    15  // serialize with indentation
    16  std::cout << std::setw(4) << j_object << "\n\n";
    17  std::cout << std::setw(2) << j_array << "\n\n";
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the serialization with different parameters to width to adjust the indentation level.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // serialize without indentation
    12  std::cout << j_object << "\n\n";
    13  std::cout << j_array << "\n\n";
    14 
    15  // serialize with indentation
    16  std::cout << std::setw(4) << j_object << "\n\n";
    17  std::cout << std::setw(2) << j_array << "\n\n";
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
    @@ -312,7 +312,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html index 20f3b529c..dea694260 100644 --- a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html +++ b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows the constructor with string literal parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON string directly from a string literal
    8  json j("The quick brown fox jumps over the lazy doc");
    9 
    10  // serialize the JSON array
    11  std::cout << j << '\n';
    12 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with string literal parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON string directly from a string literal
    8  json j("The quick brown fox jumps over the lazy doc");
    9 
    10  // serialize the JSON array
    11  std::cout << j << '\n';
    12 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "The quick brown fox jumps over the lazy doc"
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__string_t_value_type.cpp -o basic_json__string_t_value_type 
    See also
    basic_json(const string_t&) – create a string value
    @@ -292,7 +292,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a36fda9749be288cac96cfd846cb62561.html b/classnlohmann_1_1basic__json_a36fda9749be288cac96cfd846cb62561.html index b8b9ba9c5..5a5878889 100644 --- a/classnlohmann_1_1basic__json_a36fda9749be288cac96cfd846cb62561.html +++ b/classnlohmann_1_1basic__json_a36fda9749be288cac96cfd846cb62561.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rend().
  • -
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crend();
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crend();
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:285
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html b/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html index 47bfd6c39..e92bd0bbc 100644 --- a/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html +++ b/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant.
    -
    Example
    The example below shows how objects can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how objects can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:395
    Output (play with this example online):
    value = {"translation":{"cow":"Kuh","dog":"Hund"}}
     object = {"one":"eins","two":"zwei"}
    @@ -291,7 +291,7 @@ object = {"one":"eins","two":"zwei"}
     
    diff --git a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html index fa184d50a..674c774ba 100644 --- a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html +++ b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows the constructor with an array_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array_t value
    8  json::array_t value = {"one", "two", 3, 4.5, false};
    9 
    10  // create a JSON array from the value
    11  json j(value);
    12 
    13  // serialize the JSON array
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with an array_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array_t value
    8  json::array_t value = {"one", "two", 3, 4.5, false};
    9 
    10  // create a JSON array from the value
    11  json j(value);
    12 
    13  // serialize the JSON array
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:441
    Output (play with this example online):
    ["one","two",3,4.5,false]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__array_t.cpp -o basic_json__array_t 
    @@ -291,7 +291,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html index 562064143..b43e44bb2 100644 --- a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html +++ b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ is out of 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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows the effect of erase().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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(IteratorType) – removes the element at a given position
    @@ -296,7 +296,7 @@ is out of range"
    diff --git a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html index 82f216bd5..89f12eed7 100644 --- a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html +++ b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a3f7029fe6d929cf2fa48df1233ccd761.html b/classnlohmann_1_1basic__json_a3f7029fe6d929cf2fa48df1233ccd761.html index e6339d6bd..ce0806902 100644 --- a/classnlohmann_1_1basic__json_a3f7029fe6d929cf2fa48df1233ccd761.html +++ b/classnlohmann_1_1basic__json_a3f7029fe6d929cf2fa48df1233ccd761.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how array elements can be read using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -292,7 +292,7 @@ out of range
    diff --git a/classnlohmann_1_1basic__json_a407e73a037e6e3067ef7aa2c25a79f39.html b/classnlohmann_1_1basic__json_a407e73a037e6e3067ef7aa2c25a79f39.html index 4d91f562e..d28f7b924 100644 --- a/classnlohmann_1_1basic__json_a407e73a037e6e3067ef7aa2c25a79f39.html +++ b/classnlohmann_1_1basic__json_a407e73a037e6e3067ef7aa2c25a79f39.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -298,7 +298,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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    at(const typename object_t::key_type&) for access by reference with range checking
    @@ -316,7 +316,7 @@ value() with null"
    diff --git a/classnlohmann_1_1basic__json_a409e854d754f5684b2cce74ee20dbc3b.html b/classnlohmann_1_1basic__json_a409e854d754f5684b2cce74ee20dbc3b.html index ee1882932..63a513053 100644 --- a/classnlohmann_1_1basic__json_a409e854d754f5684b2cce74ee20dbc3b.html +++ b/classnlohmann_1_1basic__json_a409e854d754f5684b2cce74ee20dbc3b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is string, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_string() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_string()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_string() << '\n';
    20  std::cout << j_boolean.is_string() << '\n';
    21  std::cout << j_number_integer.is_string() << '\n';
    22  std::cout << j_number_unsigned_integer.is_string() << '\n';
    23  std::cout << j_number_float.is_string() << '\n';
    24  std::cout << j_object.is_string() << '\n';
    25  std::cout << j_array.is_string() << '\n';
    26  std::cout << j_string.is_string() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_string() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_string()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_string() << '\n';
    20  std::cout << j_boolean.is_string() << '\n';
    21  std::cout << j_number_integer.is_string() << '\n';
    22  std::cout << j_number_unsigned_integer.is_string() << '\n';
    23  std::cout << j_number_float.is_string() << '\n';
    24  std::cout << j_object.is_string() << '\n';
    25  std::cout << j_array.is_string() << '\n';
    26  std::cout << j_string.is_string() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -285,7 +285,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_a41aa8439842493e0595928a3e2cb7106.html b/classnlohmann_1_1basic__json_a41aa8439842493e0595928a3e2cb7106.html index 6e8c115ff..d8f7e5954 100644 --- a/classnlohmann_1_1basic__json_a41aa8439842493e0595928a3e2cb7106.html +++ b/classnlohmann_1_1basic__json_a41aa8439842493e0595928a3e2cb7106.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how find() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
    @@ -286,7 +286,7 @@ value at key "two": 2
     
    diff --git a/classnlohmann_1_1basic__json_a435c93d06ef28f8003c31f62ffe4aed1.html b/classnlohmann_1_1basic__json_a435c93d06ef28f8003c31f62ffe4aed1.html index 32a3574f7..4cb3f5bd9 100644 --- a/classnlohmann_1_1basic__json_a435c93d06ef28f8003c31f62ffe4aed1.html +++ b/classnlohmann_1_1basic__json_a435c93d06ef28f8003c31f62ffe4aed1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is an integer or unsigned integer number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_integer() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_integer()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_integer() << '\n';
    20  std::cout << j_boolean.is_number_integer() << '\n';
    21  std::cout << j_number_integer.is_number_integer() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_integer() << '\n';
    23  std::cout << j_number_float.is_number_integer() << '\n';
    24  std::cout << j_object.is_number_integer() << '\n';
    25  std::cout << j_array.is_number_integer() << '\n';
    26  std::cout << j_string.is_number_integer() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_number_integer() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_integer()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_integer() << '\n';
    20  std::cout << j_boolean.is_number_integer() << '\n';
    21  std::cout << j_number_integer.is_number_integer() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_integer() << '\n';
    23  std::cout << j_number_float.is_number_integer() << '\n';
    24  std::cout << j_object.is_number_integer() << '\n';
    25  std::cout << j_array.is_number_integer() << '\n';
    26  std::cout << j_string.is_number_integer() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     true
    @@ -290,7 +290,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html index c7e1515c2..5c0ecd5a6 100644 --- a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html +++ b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html index b0fda7e82..259a78e16 100644 --- a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html +++ b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -279,7 +279,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows an example for the copy constructor.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json j1 = {"one", "two", 3, 4.5, false};
    9 
    10  // create a copy
    11  json j2(j1);
    12 
    13  // serialize the JSON array
    14  std::cout << j1 << " = " << j2 << '\n';
    15  std::cout << std::boolalpha << (j1 == j2) << '\n';
    16 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for the copy constructor.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json j1 = {"one", "two", 3, 4.5, false};
    9 
    10  // create a copy
    11  json j2(j1);
    12 
    13  // serialize the JSON array
    14  std::cout << j1 << " = " << j2 << '\n';
    15  std::cout << std::boolalpha << (j1 == j2) << '\n';
    16 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    ["one","two",3,4.5,false] = ["one","two",3,4.5,false]
     true
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__basic_json.cpp -o basic_json__basic_json 
    @@ -295,7 +295,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html index 29c06fc01..92a05700e 100644 --- a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html +++ b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<typename CompatibleNumberFloatType , typename = typename std::enabl In case the parameter val is not a number, a JSON null value is created instead.
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of several floating-point number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  float f42 = 42.23;
    9  float f_nan = 1.0f / 0.0f;
    10  double f23 = 23.42;
    11 
    12  // create JSON numbers
    13  json j42(f42);
    14  json j_nan(f_nan);
    15  json j23(f23);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j42 << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j23 << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the construction of several floating-point number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  float f42 = 42.23;
    9  float f_nan = 1.0f / 0.0f;
    10  double f23 = 23.42;
    11 
    12  // create JSON numbers
    13  json j42(f42);
    14  json j_nan(f_nan);
    15  json j23(f23);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j42 << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j23 << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    42.2299995422363
     null
     23.42
    @@ -298,7 +298,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html index b0e3ed191..275dddd4e 100644 --- a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html +++ b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<typename ReferenceType , typename std::enable_if< std::is_referen
    Complexity
    Constant.
    -
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    @@ -296,7 +296,7 @@ incompatible ReferenceType for get_ref, actual type is number
    diff --git a/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html b/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html index 1747bd4dc..8ac22f2ac 100644 --- a/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html +++ b/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a54d58e56e8a67aaf0c2f3a3a05a76bba.html b/classnlohmann_1_1basic__json_a54d58e56e8a67aaf0c2f3a3a05a76bba.html index f5735bcb4..697e16ba1 100644 --- a/classnlohmann_1_1basic__json_a54d58e56e8a67aaf0c2f3a3a05a76bba.html +++ b/classnlohmann_1_1basic__json_a54d58e56e8a67aaf0c2f3a3a05a76bba.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    an object that maps JSON pointers to primitve values
    Note
    Empty objects and arrays are flattened to null and will not be reconstructed correctly by the unflatten() function.
    Complexity
    Linear in the size the JSON value.
    -
    Example
    The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j =
    9  {
    10  {"pi", 3.141},
    11  {"happy", true},
    12  {"name", "Niels"},
    13  {"nothing", nullptr},
    14  {
    15  "answer", {
    16  {"everything", 42}
    17  }
    18  },
    19  {"list", {1, 0, 2}},
    20  {
    21  "object", {
    22  {"currency", "USD"},
    23  {"value", 42.99}
    24  }
    25  }
    26  };
    27 
    28  // call flatten()
    29  std::cout << std::setw(4) << j.flatten() << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j =
    9  {
    10  {"pi", 3.141},
    11  {"happy", true},
    12  {"name", "Niels"},
    13  {"nothing", nullptr},
    14  {
    15  "answer", {
    16  {"everything", 42}
    17  }
    18  },
    19  {"list", {1, 0, 2}},
    20  {
    21  "object", {
    22  {"currency", "USD"},
    23  {"value", 42.99}
    24  }
    25  }
    26  };
    27 
    28  // call flatten()
    29  std::cout << std::setw(4) << j.flatten() << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {
         "/answer/everything": 42,
         "/happy": true,
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    See also
    unflatten() for the reverse function
    Since
    version 2.0.0
    -

    Definition at line 10020 of file json.hpp.

    +

    Definition at line 10188 of file json.hpp.

    @@ -290,7 +290,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html index 0fadfface..299a51796 100644 --- a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html +++ b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    JSON array value
    Complexity
    Linear in the size of init.
    -
    Example
    The following code shows an example for the array function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON arrays
    8  json j_no_init_list = json::array();
    9  json j_empty_init_list = json::array({});
    10  json j_nonempty_init_list = json::array({1, 2, 3, 4});
    11  json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} });
    12 
    13  // serialize the JSON arrays
    14  std::cout << j_no_init_list << '\n';
    15  std::cout << j_empty_init_list << '\n';
    16  std::cout << j_nonempty_init_list << '\n';
    17  std::cout << j_list_of_pairs << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for the array function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON arrays
    8  json j_no_init_list = json::array();
    9  json j_empty_init_list = json::array({});
    10  json j_nonempty_init_list = json::array({1, 2, 3, 4});
    11  json j_list_of_pairs = json::array({ {"one", 1}, {"two", 2} });
    12 
    13  // serialize the JSON arrays
    14  std::cout << j_no_init_list << '\n';
    15  std::cout << j_empty_init_list << '\n';
    16  std::cout << j_nonempty_init_list << '\n';
    17  std::cout << j_list_of_pairs << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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:1720
    Output (play with this example online):
    []
     []
    @@ -296,7 +296,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a576ca17f297a7a43200088c24b8437e6.html b/classnlohmann_1_1basic__json_a576ca17f297a7a43200088c24b8437e6.html index 9922710c5..4c447da29 100644 --- a/classnlohmann_1_1basic__json_a576ca17f297a7a43200088c24b8437e6.html +++ b/classnlohmann_1_1basic__json_a576ca17f297a7a43200088c24b8437e6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -296,7 +296,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 json = nlohmann::json;
    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"_json_pointer, 0);
    20  double v_floating = j.value("/floating"_json_pointer, 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("/nonexisting"_json_pointer, "oops");
    24  bool v_boolean = j.value("/nonexisting"_json_pointer, false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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"_json_pointer, 0);
    20  double v_floating = j.value("/floating"_json_pointer, 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("/nonexisting"_json_pointer, "oops");
    24  bool v_boolean = j.value("/nonexisting"_json_pointer, false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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_ptr.cpp -o basic_json__value_ptr 
    See also
    operator[](const json_pointer&) for unchecked access by reference
    @@ -312,7 +312,7 @@ value() with null"
    diff --git a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html index f26ec8e09..4531ddc36 100644 --- a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html +++ b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant if idx is in the range of the array. Otherwise linear in idx - size().
    -
    Example
    The example below shows how array elements can be read and written using [] operator. Note the addition of null values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // output element at index 3 (fourth element)
    11  std::cout << array[3] << '\n';
    12 
    13  // change last element to 6
    14  array[array.size() - 1] = 6;
    15 
    16  // output changed array
    17  std::cout << array << '\n';
    18 
    19  // write beyond array limit
    20  array[10] = 11;
    21 
    22  // output changed array
    23  std::cout << array << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how array elements can be read and written using [] operator. Note the addition of null values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // output element at index 3 (fourth element)
    11  std::cout << array[3] << '\n';
    12 
    13  // change last element to 6
    14  array[array.size() - 1] = 6;
    15 
    16  // output changed array
    17  std::cout << array << '\n';
    18 
    19  // write beyond array limit
    20  array[10] = 11;
    21 
    22  // output changed array
    23  std::cout << array << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    4
     [1,2,3,4,6]
     [1,2,3,4,6,null,null,null,null,null,11]
    @@ -293,7 +293,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a5b3bd4f3fc1458835770c5a22cb74de1.html b/classnlohmann_1_1basic__json_a5b3bd4f3fc1458835770c5a22cb74de1.html index 895676009..436d58c19 100644 --- a/classnlohmann_1_1basic__json_a5b3bd4f3fc1458835770c5a22cb74de1.html +++ b/classnlohmann_1_1basic__json_a5b3bd4f3fc1458835770c5a22cb74de1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -292,7 +292,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html index aabd4ff64..d9812f0e2 100644 --- a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html +++ b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether lhs is less than or equal to rhs
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 > array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 > object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 > number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 > string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 > array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 > object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 > number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 > string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
     {"A":"a","B":"b"} == {"A":"a","B":"b"} false
     17 == 17.0000000000001 false
    @@ -298,7 +298,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a5d466b240d0ba9f648d7fd4ff42359f5.html b/classnlohmann_1_1basic__json_a5d466b240d0ba9f648d7fd4ff42359f5.html index 6e552e7d8..fd2e4bad2 100644 --- a/classnlohmann_1_1basic__json_a5d466b240d0ba9f648d7fd4ff42359f5.html +++ b/classnlohmann_1_1basic__json_a5d466b240d0ba9f648d7fd4ff42359f5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    the type of the JSON value
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies type() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 type()
    17  std::cout << std::boolalpha;
    18  std::cout << (j_null.type() == json::value_t::null) << '\n';
    19  std::cout << (j_boolean.type() == json::value_t::boolean) << '\n';
    20  std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n';
    21  std::cout << (j_number_float.type() == json::value_t::number_float) << '\n';
    22  std::cout << (j_object.type() == json::value_t::object) << '\n';
    23  std::cout << (j_array.type() == json::value_t::array) << '\n';
    24  std::cout << (j_string.type() == json::value_t::string) << '\n';
    25 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies type() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 type()
    17  std::cout << std::boolalpha;
    18  std::cout << (j_null.type() == json::value_t::null) << '\n';
    19  std::cout << (j_boolean.type() == json::value_t::boolean) << '\n';
    20  std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n';
    21  std::cout << (j_number_float.type() == json::value_t::number_float) << '\n';
    22  std::cout << (j_object.type() == json::value_t::object) << '\n';
    23  std::cout << (j_array.type() == json::value_t::array) << '\n';
    24  std::cout << (j_string.type() == json::value_t::string) << '\n';
    25 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    @@ -291,7 +291,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html index f5325b6cc..085b6b599 100644 --- a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html +++ b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -281,7 +281,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    the stream o
    Complexity
    Linear.
    -
    Example
    The example below shows the serialization with different parameters to width to adjust the indentation level.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // serialize without indentation
    12  std::cout << j_object << "\n\n";
    13  std::cout << j_array << "\n\n";
    14 
    15  // serialize with indentation
    16  std::cout << std::setw(4) << j_object << "\n\n";
    17  std::cout << std::setw(2) << j_array << "\n\n";
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the serialization with different parameters to width to adjust the indentation level.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // serialize without indentation
    12  std::cout << j_object << "\n\n";
    13  std::cout << j_array << "\n\n";
    14 
    15  // serialize with indentation
    16  std::cout << std::setw(4) << j_object << "\n\n";
    17  std::cout << std::setw(2) << j_array << "\n\n";
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
    @@ -312,7 +312,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a5ef1934868b90452a4a34695489c60cd.html b/classnlohmann_1_1basic__json_a5ef1934868b90452a4a34695489c60cd.html index d24d5f3b5..82471a04e 100644 --- a/classnlohmann_1_1basic__json_a5ef1934868b90452a4a34695489c60cd.html +++ b/classnlohmann_1_1basic__json_a5ef1934868b90452a4a34695489c60cd.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -289,9 +289,9 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    a JSON patch to convert the source to target
    Complexity
    Linear in the lengths of source and target.
    -
    Example
    The following code shows how a JSON patch is created as a diff for two JSON values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the source document
    8  json source = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the target document
    16  json target = R"(
    17  {
    18  "baz": "boo",
    19  "hello": [
    20  "world"
    21  ]
    22  }
    23  )"_json;
    24 
    25  // create the patch
    26  json patch = json::diff(source, target);
    27 
    28  // roundtrip
    29  json patched_source = source.patch(patch);
    30 
    31  // output patch and roundtrip result
    32  std::cout << std::setw(4) << patch << "\n\n"
    33  << std::setw(4) << patched_source << std::endl;
    34 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    -
    static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
    creates a diff as a JSON patch
    Definition: json.hpp:10397
    -
    basic_json patch(const basic_json &json_patch) const
    applies a JSON patch
    Definition: json.hpp:10104
    +
    Example
    The following code shows how a JSON patch is created as a diff for two JSON values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the source document
    8  json source = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the target document
    16  json target = R"(
    17  {
    18  "baz": "boo",
    19  "hello": [
    20  "world"
    21  ]
    22  }
    23  )"_json;
    24 
    25  // create the patch
    26  json patch = json::diff(source, target);
    27 
    28  // roundtrip
    29  json patched_source = source.patch(patch);
    30 
    31  // output patch and roundtrip result
    32  std::cout << std::setw(4) << patch << "\n\n"
    33  << std::setw(4) << patched_source << std::endl;
    34 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    +
    static basic_json diff(const basic_json &source, const basic_json &target, const std::string &path="")
    creates a diff as a JSON patch
    Definition: json.hpp:10565
    +
    basic_json patch(const basic_json &json_patch) const
    applies a JSON patch
    Definition: json.hpp:10272
    Output (play with this example online):
    [
         {
             "op": "replace",
    @@ -323,7 +323,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     RFC 6902 (JSON Patch)
    Since
    version 2.0.0
    -

    Definition at line 10397 of file json.hpp.

    +

    Definition at line 10565 of file json.hpp.

    @@ -333,7 +333,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html index 06d58de8e..6869be2e6 100644 --- a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html +++ b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -286,7 +286,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html index dbe669913..393c2afeb 100644 --- a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html +++ b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -286,7 +286,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Linear in the length of the input. The parser is a predictive LL(1) parser.
    Note
    A UTF-8 byte order mark is silently ignored.
    -
    Example
    The example below shows how a JSON value is constructed by reading a serialization from a stream.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create stream with serialized JSON
    8  std::stringstream ss;
    9  ss << R"({
    10  "number": 23,
    11  "string": "Hello, world!",
    12  "array": [1, 2, 3, 4, 5],
    13  "boolean": false,
    14  "null": null
    15  })";
    16 
    17  // create JSON value and read the serialization from the stream
    18  json j;
    19  j << ss;
    20 
    21  // serialize JSON
    22  std::cout << std::setw(2) << j << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how a JSON value is constructed by reading a serialization from a stream.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create stream with serialized JSON
    8  std::stringstream ss;
    9  ss << R"({
    10  "number": 23,
    11  "string": "Hello, world!",
    12  "array": [1, 2, 3, 4, 5],
    13  "boolean": false,
    14  "null": null
    15  })";
    16 
    17  // create JSON value and read the serialization from the stream
    18  json j;
    19  j << ss;
    20 
    21  // serialize JSON
    22  std::cout << std::setw(2) << j << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {
       "array": [
         1,
    @@ -314,7 +314,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html index c0af3f662..b94f15a54 100644 --- a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html +++ b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -294,7 +294,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -310,7 +310,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html b/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html index 7055f6ef1..4a90a51f7 100644 --- a/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html +++ b/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of reverse_iterator(end()).
  • -
    Example
    The following code shows an example for rbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for rbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:283
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html b/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html index 33682f42c..efa2deed9 100644 --- a/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html +++ b/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j.at("/string"_json_pointer) = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // change an array element
    32  j.at("/array/1"_json_pointer) = 21;
    33  // output the changed array
    34  std::cout << j["array"] << '\n';
    35 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j.at("/string"_json_pointer) = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // change an array element
    32  j.at("/array/1"_json_pointer) = 21;
    33  // output the changed array
    34  std::cout << j["array"] << '\n';
    35 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at_json_pointer.cpp -o at_json_pointer 
    Since
    version 2.0.0
    -

    Definition at line 9968 of file json.hpp.

    +

    Definition at line 10136 of file json.hpp.

    @@ -297,7 +297,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html index b0bc6825e..ec9518950 100644 --- a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html +++ b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -289,7 +289,7 @@ template<typename CompatibleNumberUnsignedType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html index 0e84896e2..aa9f43fe7 100644 --- a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html +++ b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether the values lhs and rhs are not equal
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.000000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 != array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 != object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 != number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 != string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.000000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 != array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 != object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 != number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 != string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
     {"A":"a","B":"b"} == {"A":"a","B":"b"} false
     17 == 17 false
    @@ -298,7 +298,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a6eb50ec247cc53bdd46fb13e38e0de04.html b/classnlohmann_1_1basic__json_a6eb50ec247cc53bdd46fb13e38e0de04.html index ae3c58f2e..ce79b222c 100644 --- a/classnlohmann_1_1basic__json_a6eb50ec247cc53bdd46fb13e38e0de04.html +++ b/classnlohmann_1_1basic__json_a6eb50ec247cc53bdd46fb13e38e0de04.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorarray__key_type_const.cpp -o operatorarray__key_type_const 
    See also
    at(const typename object_t::key_type&) for access by reference with range checking
    @@ -296,7 +296,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html index 64273d755..d2a7f315c 100644 --- a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html +++ b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html b/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html index 296969af8..79b729ab3 100644 --- a/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html +++ b/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Note
    This constructor allows to pass enums directly to a constructor. As C++ has no way of specifying the type of an anonymous enum explicitly, we can only rely on the fact that such values implicitly convert to int. As int may already be the same type of number_integer_t, we may need to switch off the constructor basic_json(const number_integer_t).
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of an integer number value from an anonymous enum.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // an anonymous enum
    8  enum { t = 17 };
    9 
    10  // create a JSON number from the enum
    11  json j(t);
    12 
    13  // serialize the JSON numbers
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the construction of an integer number value from an anonymous enum.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // an anonymous enum
    8  enum { t = 17 };
    9 
    10  // create a JSON number from the enum
    11  json j(t);
    12 
    13  // serialize the JSON numbers
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    17
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__const_int.cpp -o basic_json__const_int 
    See also
    basic_json(const number_integer_t) – create a number value (integer)
    @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html index ed28383bc..125852e2d 100644 --- a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html +++ b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -292,7 +292,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a7355a41b0033ff8a27d58550544d5a59.html b/classnlohmann_1_1basic__json_a7355a41b0033ff8a27d58550544d5a59.html index bec4d4345..669f097c8 100644 --- a/classnlohmann_1_1basic__json_a7355a41b0033ff8a27d58550544d5a59.html +++ b/classnlohmann_1_1basic__json_a7355a41b0033ff8a27d58550544d5a59.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).begin().
  • -
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    begin() – returns an iterator to the beginning
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html index c00f187b9..7b9d94b47 100644 --- a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html +++ b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Postcondition
    other is a JSON null value
    Complexity
    Constant.
    -
    Example
    The code below shows the move constructor explicitly called via std::move.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json a = 23;
    9 
    10  // move contents of a to b
    11  json b(std::move(a));
    12 
    13  // serialize the JSON arrays
    14  std::cout << a << '\n';
    15  std::cout << b << '\n';
    16 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The code below shows the move constructor explicitly called via std::move.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json a = 23;
    9 
    10  // move contents of a to b
    11  json b(std::move(a));
    12 
    13  // serialize the JSON arrays
    14  std::cout << a << '\n';
    15  std::cout << b << '\n';
    16 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    null
     23
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__moveconstructor.cpp -o basic_json__moveconstructor 
    @@ -285,7 +285,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html b/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html index 61837209d..6365a8133 100644 --- a/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html +++ b/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -282,7 +282,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html index 198a45da1..01533a94c 100644 --- a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html +++ b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether lhs is greater than or equal to rhs
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) << '\n';
    20  std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) << '\n';
    21  std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) << '\n';
    22  std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " >= " << array_2 << " " << (array_1 >= array_2) << '\n';
    20  std::cout << object_1 << " >= " << object_2 << " " << (object_1 >= object_2) << '\n';
    21  std::cout << number_1 << " >= " << number_2 << " " << (number_1 >= number_2) << '\n';
    22  std::cout << string_1 << " >= " << string_2 << " " << (string_1 >= string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] >= [1,2,4] false
     {"A":"a","B":"b"} >= {"A":"a","B":"b"} true
     17 >= 17.0000000000001 false
    @@ -298,7 +298,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html b/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html index 801cc3536..5a5db7ebf 100644 --- a/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html +++ b/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -282,7 +282,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j["/string"_json_pointer] = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // "change" a nonexisting object entry
    32  j["/boolean"_json_pointer] = true;
    33  // output the changed object
    34  std::cout << j << '\n';
    35 
    36  // change an array element
    37  j["/array/1"_json_pointer] = 21;
    38  // "change" an array element with nonexisting index
    39  j["/array/4"_json_pointer] = 44;
    40  // output the changed array
    41  std::cout << j["array"] << '\n';
    42 
    43  // "change" the array element past the end
    44  j["/array/-"_json_pointer] = 55;
    45  // output the changed array
    46  std::cout << j["array"] << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j["/string"_json_pointer] = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // "change" a nonexisting object entry
    32  j["/boolean"_json_pointer] = true;
    33  // output the changed object
    34  std::cout << j << '\n';
    35 
    36  // change an array element
    37  j["/array/1"_json_pointer] = 21;
    38  // "change" an array element with nonexisting index
    39  j["/array/4"_json_pointer] = 44;
    40  // output the changed array
    41  std::cout << j["array"] << '\n';
    42 
    43  // "change" the array element past the end
    44  j["/array/-"_json_pointer] = 55;
    45  // output the changed array
    46  std::cout << j["array"] << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -294,7 +294,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorjson_pointer.cpp -o operatorjson_pointer 
    Since
    version 2.0.0
    -

    Definition at line 9916 of file json.hpp.

    +

    Definition at line 10084 of file json.hpp.

    @@ -304,7 +304,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a7641371be8a347f3c1e05ac089a74c36.html b/classnlohmann_1_1basic__json_a7641371be8a347f3c1e05ac089a74c36.html index 9d2886e9e..31daba9f9 100644 --- a/classnlohmann_1_1basic__json_a7641371be8a347f3c1e05ac089a74c36.html +++ b/classnlohmann_1_1basic__json_a7641371be8a347f3c1e05ac089a74c36.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is a floating-point number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_float() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_float()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_float() << '\n';
    20  std::cout << j_boolean.is_number_float() << '\n';
    21  std::cout << j_number_integer.is_number_float() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_float() << '\n';
    23  std::cout << j_number_float.is_number_float() << '\n';
    24  std::cout << j_object.is_number_float() << '\n';
    25  std::cout << j_array.is_number_float() << '\n';
    26  std::cout << j_string.is_number_float() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_number_float() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_float()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_float() << '\n';
    20  std::cout << j_boolean.is_number_float() << '\n';
    21  std::cout << j_number_integer.is_number_float() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_float() << '\n';
    23  std::cout << j_number_float.is_number_float() << '\n';
    24  std::cout << j_object.is_number_float() << '\n';
    25  std::cout << j_array.is_number_float() << '\n';
    26  std::cout << j_string.is_number_float() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -290,7 +290,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a7936417b875b7ec737f77ef84bbf7871.html b/classnlohmann_1_1basic__json_a7936417b875b7ec737f77ef84bbf7871.html index 60b2f4fd2..8ca015962 100644 --- a/classnlohmann_1_1basic__json_a7936417b875b7ec737f77ef84bbf7871.html +++ b/classnlohmann_1_1basic__json_a7936417b875b7ec737f77ef84bbf7871.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -283,7 +283,7 @@ template<template< typename U, typename V, typename... Args > class Obj
  • Has the semantics of returning b.size() where b is the largest possible JSON value.
  • -
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    0
     1
     1
    @@ -305,7 +305,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html index 78c5a88c7..2a645af1f 100644 --- a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html +++ b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ template<typename PointerType , typename std::enable_if< std::is_pointer&l
    Returns
    pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    @@ -290,7 +290,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html index 0c0ec7bea..614f73d06 100644 --- a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html +++ b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read and written using at().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "il brutto"
     {"the bad":"il cattivo","the good":"il buono","the ugly":"il brutto"}
     out of range: key 'the fast' not found
    @@ -296,7 +296,7 @@ out of range: key 'the fast' not found
     
    diff --git a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html index 0d50d0445..e232a1fa9 100644 --- a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html +++ b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -303,7 +303,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html index 9eb0c7eeb..2f77bf797 100644 --- a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html +++ b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether v is not null
    Complexity
    Constant.
    Example
    The example compares several JSON types to the null pointer.
    -
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " != nullptr " << (array != nullptr) << '\n';
    17  std::cout << object << " != nullptr " << (object != nullptr) << '\n';
    18  std::cout << number << " != nullptr " << (number != nullptr) << '\n';
    19  std::cout << string << " != nullptr " << (string != nullptr) << '\n';
    20  std::cout << null << " != nullptr " << (null != nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " != nullptr " << (array != nullptr) << '\n';
    17  std::cout << object << " != nullptr " << (object != nullptr) << '\n';
    18  std::cout << number << " != nullptr " << (number != nullptr) << '\n';
    19  std::cout << string << " != nullptr " << (string != nullptr) << '\n';
    20  std::cout << null << " != nullptr " << (null != nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
    @@ -298,7 +298,7 @@ null != nullptr false
     
    diff --git a/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html b/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html index 42820e32d..d940001b8 100644 --- a/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html +++ b/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html index d37e0cecf..b48863eb1 100644 --- a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html +++ b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -282,7 +282,7 @@ template<class CompatibleArrayType , typename std::enable_if< not std::is_
    -
    Example
    The following code shows the constructor with several compatible array type parameters.
    1 #include <json.hpp>
    2 #include <deque>
    3 #include <list>
    4 #include <forward_list>
    5 #include <set>
    6 #include <unordered_set>
    7 
    8 using json = nlohmann::json;
    9 
    10 int main()
    11 {
    12  // create an array from std::vector
    13  std::vector<int> c_vector {1, 2, 3, 4};
    14  json j_vec(c_vector);
    15 
    16  // create an array from std::deque
    17  std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
    18  json j_deque(c_deque);
    19 
    20  // create an array from std::list
    21  std::list<bool> c_list {true, true, false, true};
    22  json j_list(c_list);
    23 
    24  // create an array from std::forward_list
    25  std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
    26  json j_flist(c_flist);
    27 
    28  // create an array from std::array
    29  std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
    30  json j_array(c_array);
    31 
    32  // create an array from std::set
    33  std::set<std::string> c_set {"one", "two", "three", "four", "one"};
    34  json j_set(c_set); // only one entry for "one" is used
    35 
    36  // create an array from std::unordered_set
    37  std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
    38  json j_uset(c_uset); // only one entry for "one" is used
    39 
    40  // create an array from std::multiset
    41  std::multiset<std::string> c_mset {"one", "two", "one", "four"};
    42  json j_mset(c_mset); // both entries for "one" are used
    43 
    44  // create an array from std::unordered_multiset
    45  std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
    46  json j_umset(c_umset); // both entries for "one" are used
    47 
    48  // serialize the JSON arrays
    49  std::cout << j_vec << '\n';
    50  std::cout << j_deque << '\n';
    51  std::cout << j_list << '\n';
    52  std::cout << j_flist << '\n';
    53  std::cout << j_array << '\n';
    54  std::cout << j_set << '\n';
    55  std::cout << j_uset << '\n';
    56  std::cout << j_mset << '\n';
    57  std::cout << j_umset << '\n';
    58 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with several compatible array type parameters.
    1 #include <json.hpp>
    2 #include <deque>
    3 #include <list>
    4 #include <forward_list>
    5 #include <set>
    6 #include <unordered_set>
    7 
    8 using json = nlohmann::json;
    9 
    10 int main()
    11 {
    12  // create an array from std::vector
    13  std::vector<int> c_vector {1, 2, 3, 4};
    14  json j_vec(c_vector);
    15 
    16  // create an array from std::deque
    17  std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
    18  json j_deque(c_deque);
    19 
    20  // create an array from std::list
    21  std::list<bool> c_list {true, true, false, true};
    22  json j_list(c_list);
    23 
    24  // create an array from std::forward_list
    25  std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
    26  json j_flist(c_flist);
    27 
    28  // create an array from std::array
    29  std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
    30  json j_array(c_array);
    31 
    32  // create an array from std::set
    33  std::set<std::string> c_set {"one", "two", "three", "four", "one"};
    34  json j_set(c_set); // only one entry for "one" is used
    35 
    36  // create an array from std::unordered_set
    37  std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
    38  json j_uset(c_uset); // only one entry for "one" is used
    39 
    40  // create an array from std::multiset
    41  std::multiset<std::string> c_mset {"one", "two", "one", "four"};
    42  json j_mset(c_mset); // both entries for "one" are used
    43 
    44  // create an array from std::unordered_multiset
    45  std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
    46  json j_umset(c_umset); // both entries for "one" are used
    47 
    48  // serialize the JSON arrays
    49  std::cout << j_vec << '\n';
    50  std::cout << j_deque << '\n';
    51  std::cout << j_list << '\n';
    52  std::cout << j_flist << '\n';
    53  std::cout << j_array << '\n';
    54  std::cout << j_set << '\n';
    55  std::cout << j_uset << '\n';
    56  std::cout << j_mset << '\n';
    57  std::cout << j_umset << '\n';
    58 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3,4]
     [1.2,2.3,3.4,5.6]
     [true,true,false,true]
    @@ -306,7 +306,7 @@ template<class CompatibleArrayType , typename std::enable_if< not std::is_
     
    diff --git a/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html b/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html index 7ae24e174..bd6968af7 100644 --- a/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html +++ b/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -275,7 +275,7 @@ use swap() with string"
    Complexity
    Constant.
    -
    Example
    The example below shows how arrays can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how arrays can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:441
    Output (play with this example online):
    value = {"array":["Snap","Crackle","Pop"]}
     array = [1,2,3,4]
    @@ -292,7 +292,7 @@ array = [1,2,3,4]
     
    diff --git a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html index b74a4cf55..00476125a 100644 --- a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html +++ b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -303,7 +303,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html b/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html index d6b3743ad..fb56c8ce0 100644 --- a/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html +++ b/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -289,7 +289,7 @@ template<typename T , typename std::enable_if< not(std::is_same< T, int
    diff --git a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html index b5a647482..b57eb79b4 100644 --- a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html +++ b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -275,7 +275,7 @@ use swap() with boolean"
    Complexity
    Constant.
    -
    Example
    The example below shows how strings can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how strings can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    StringType string_t
    a type for a string
    Definition: json.hpp:488
    Output (play with this example online):
    value = ["the good","the fast","the ugly"]
     string = the bad
    @@ -292,7 +292,7 @@ string = the bad
     
    diff --git a/classnlohmann_1_1basic__json_a873f4bff2f2a83f68fc1b5341ebdd446.html b/classnlohmann_1_1basic__json_a873f4bff2f2a83f68fc1b5341ebdd446.html index 2729b63ba..a742c1b7c 100644 --- a/classnlohmann_1_1basic__json_a873f4bff2f2a83f68fc1b5341ebdd446.html +++ b/classnlohmann_1_1basic__json_a873f4bff2f2a83f68fc1b5341ebdd446.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is structured (array or object), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_structured() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_structured()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_structured() << '\n';
    20  std::cout << j_boolean.is_structured() << '\n';
    21  std::cout << j_number_integer.is_structured() << '\n';
    22  std::cout << j_number_unsigned_integer.is_structured() << '\n';
    23  std::cout << j_number_float.is_structured() << '\n';
    24  std::cout << j_object.is_structured() << '\n';
    25  std::cout << j_array.is_structured() << '\n';
    26  std::cout << j_string.is_structured() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_structured() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_structured()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_structured() << '\n';
    20  std::cout << j_boolean.is_structured() << '\n';
    21  std::cout << j_number_integer.is_structured() << '\n';
    22  std::cout << j_number_unsigned_integer.is_structured() << '\n';
    23  std::cout << j_number_float.is_structured() << '\n';
    24  std::cout << j_object.is_structured() << '\n';
    25  std::cout << j_array.is_structured() << '\n';
    26  std::cout << j_string.is_structured() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -290,7 +290,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html index fe184b1b1..491abfa5e 100644 --- a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html +++ b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether lhs is greater than to rhs
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) << '\n';
    20  std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) << '\n';
    21  std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) << '\n';
    22  std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " <= " << array_2 << " " << (array_1 <= array_2) << '\n';
    20  std::cout << object_1 << " <= " << object_2 << " " << (object_1 <= object_2) << '\n';
    21  std::cout << number_1 << " <= " << number_2 << " " << (number_1 <= number_2) << '\n';
    22  std::cout << string_1 << " <= " << string_2 << " " << (string_1 <= string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] <= [1,2,4] true
     {"A":"a","B":"b"} <= {"A":"a","B":"b"} true
     17 <= 17.0000000000001 true
    @@ -298,7 +298,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a8abdfc0d6e051f6fa29d49da57bce631.html b/classnlohmann_1_1basic__json_a8abdfc0d6e051f6fa29d49da57bce631.html index cfecd8580..1858a35f7 100644 --- a/classnlohmann_1_1basic__json_a8abdfc0d6e051f6fa29d49da57bce631.html +++ b/classnlohmann_1_1basic__json_a8abdfc0d6e051f6fa29d49da57bce631.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is null, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_null() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_null()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_null() << '\n';
    20  std::cout << j_boolean.is_null() << '\n';
    21  std::cout << j_number_integer.is_null() << '\n';
    22  std::cout << j_number_unsigned_integer.is_null() << '\n';
    23  std::cout << j_number_float.is_null() << '\n';
    24  std::cout << j_object.is_null() << '\n';
    25  std::cout << j_array.is_null() << '\n';
    26  std::cout << j_string.is_null() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_null() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_null()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_null() << '\n';
    20  std::cout << j_boolean.is_null() << '\n';
    21  std::cout << j_number_integer.is_null() << '\n';
    22  std::cout << j_number_unsigned_integer.is_null() << '\n';
    23  std::cout << j_number_float.is_null() << '\n';
    24  std::cout << j_object.is_null() << '\n';
    25  std::cout << j_array.is_null() << '\n';
    26  std::cout << j_string.is_null() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    true
     false
     false
    @@ -285,7 +285,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html index 44428917e..7d277b228 100644 --- a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html +++ b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -290,7 +290,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows the constructor for different value_t values
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create the different JSON values with default values
    9  json j_boolean(json::value_t::boolean);
    10  json j_number_integer(json::value_t::number_integer);
    11  json j_number_float(json::value_t::number_float);
    12  json j_object(json::value_t::object);
    13  json j_array(json::value_t::array);
    14  json j_string(json::value_t::string);
    15 
    16  // serialize the JSON values
    17  std::cout << j_null << '\n';
    18  std::cout << j_boolean << '\n';
    19  std::cout << j_number_integer << '\n';
    20  std::cout << j_number_float << '\n';
    21  std::cout << j_object << '\n';
    22  std::cout << j_array << '\n';
    23  std::cout << j_string << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor for different value_t values
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create the different JSON values with default values
    9  json j_boolean(json::value_t::boolean);
    10  json j_number_integer(json::value_t::number_integer);
    11  json j_number_float(json::value_t::number_float);
    12  json j_object(json::value_t::object);
    13  json j_array(json::value_t::array);
    14  json j_string(json::value_t::string);
    15 
    16  // serialize the JSON values
    17  std::cout << j_null << '\n';
    18  std::cout << j_boolean << '\n';
    19  std::cout << j_number_integer << '\n';
    20  std::cout << j_number_float << '\n';
    21  std::cout << j_object << '\n';
    22  std::cout << j_array << '\n';
    23  std::cout << j_string << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    @@ -333,7 +333,7 @@ false
    diff --git a/classnlohmann_1_1basic__json_a8faa955d51ec1f63b9ea9a7cc1eb93e8.html b/classnlohmann_1_1basic__json_a8faa955d51ec1f63b9ea9a7cc1eb93e8.html index cf93b2d20..78eb4b7c0 100644 --- a/classnlohmann_1_1basic__json_a8faa955d51ec1f63b9ea9a7cc1eb93e8.html +++ b/classnlohmann_1_1basic__json_a8faa955d51ec1f63b9ea9a7cc1eb93e8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -285,7 +285,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at_json_pointer_const.cpp -o at_json_pointer_const 
    Since
    version 2.0.0
    -

    Definition at line 9993 of file json.hpp.

    +

    Definition at line 10161 of file json.hpp.

    @@ -295,7 +295,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_a9008c688b9bd5798e4090c971d20ee92.html b/classnlohmann_1_1basic__json_a9008c688b9bd5798e4090c971d20ee92.html index 7b47a64fb..7c32318db 100644 --- a/classnlohmann_1_1basic__json_a9008c688b9bd5798e4090c971d20ee92.html +++ b/classnlohmann_1_1basic__json_a9008c688b9bd5798e4090c971d20ee92.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ template<typename PointerType , typename std::enable_if< std::is_pointer&l
    Returns
    pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    @@ -291,7 +291,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a90f05d55d9d0702c075cd281fd0d85ae.html b/classnlohmann_1_1basic__json_a90f05d55d9d0702c075cd281fd0d85ae.html index 883b54ff6..04358858b 100644 --- a/classnlohmann_1_1basic__json_a90f05d55d9d0702c075cd281fd0d85ae.html +++ b/classnlohmann_1_1basic__json_a90f05d55d9d0702c075cd281fd0d85ae.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -290,7 +290,7 @@ template<typename CharPT , typename std::enable_if< std::is_pointer< Ch
    Note
    A UTF-8 byte order mark is silently ignored.
    String containers like std::string or string_t can be parsed with parse(const ContiguousContainer&, const parser_callback_t)
    -
    Example
    The example below demonstrates the parse() function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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  // 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:10545
    +
    Example
    The example below demonstrates the parse() function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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  // 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:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:1016
    the parser read a key of a value in an object
    @@ -343,7 +343,7 @@ String containers like std::string or diff --git a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html index 6b1315cb4..34b40128d 100644 --- a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html +++ b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
     {
    @@ -312,7 +312,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html b/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html index 2873a2b22..972c02eaa 100644 --- a/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html +++ b/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html b/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html index 4c35210d5..60146b08e 100644 --- a/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html +++ b/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a94ba313c00f1713fa4be85de64083754.html b/classnlohmann_1_1basic__json_a94ba313c00f1713fa4be85de64083754.html index b846a5ad3..1d6a1d31b 100644 --- a/classnlohmann_1_1basic__json_a94ba313c00f1713fa4be85de64083754.html +++ b/classnlohmann_1_1basic__json_a94ba313c00f1713fa4be85de64083754.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is object, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_object() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_object()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_object() << '\n';
    20  std::cout << j_boolean.is_object() << '\n';
    21  std::cout << j_number_integer.is_object() << '\n';
    22  std::cout << j_number_unsigned_integer.is_object() << '\n';
    23  std::cout << j_number_float.is_object() << '\n';
    24  std::cout << j_object.is_object() << '\n';
    25  std::cout << j_array.is_object() << '\n';
    26  std::cout << j_string.is_object() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_object() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_object()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_object() << '\n';
    20  std::cout << j_boolean.is_object() << '\n';
    21  std::cout << j_number_integer.is_object() << '\n';
    22  std::cout << j_number_unsigned_integer.is_object() << '\n';
    23  std::cout << j_number_float.is_object() << '\n';
    24  std::cout << j_object.is_object() << '\n';
    25  std::cout << j_array.is_object() << '\n';
    26  std::cout << j_string.is_object() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -285,7 +285,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a957eb9594c7f0ca93212c30f3a400873.html b/classnlohmann_1_1basic__json_a957eb9594c7f0ca93212c30f3a400873.html index 5388e4427..b2aaf4a36 100644 --- a/classnlohmann_1_1basic__json_a957eb9594c7f0ca93212c30f3a400873.html +++ b/classnlohmann_1_1basic__json_a957eb9594c7f0ca93212c30f3a400873.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is number (regardless whether integer, unsigned integer or floating-type), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number() << '\n';
    20  std::cout << j_boolean.is_number() << '\n';
    21  std::cout << j_number_integer.is_number() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number() << '\n';
    23  std::cout << j_number_float.is_number() << '\n';
    24  std::cout << j_object.is_number() << '\n';
    25  std::cout << j_array.is_number() << '\n';
    26  std::cout << j_string.is_number() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_number() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number() << '\n';
    20  std::cout << j_boolean.is_number() << '\n';
    21  std::cout << j_number_integer.is_number() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number() << '\n';
    23  std::cout << j_number_float.is_number() << '\n';
    24  std::cout << j_object.is_number() << '\n';
    25  std::cout << j_array.is_number() << '\n';
    26  std::cout << j_string.is_number() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     true
    @@ -290,7 +290,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a959bc32fc72a76cd5a1bd6977926f787.html b/classnlohmann_1_1basic__json_a959bc32fc72a76cd5a1bd6977926f787.html index 7b6d945cb..657bd2b93 100644 --- a/classnlohmann_1_1basic__json_a959bc32fc72a76cd5a1bd6977926f787.html +++ b/classnlohmann_1_1basic__json_a959bc32fc72a76cd5a1bd6977926f787.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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:10545
    +
    Example
    The example below demonstrates the parse() function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:1016
    the parser read a key of a value in an object
    @@ -333,7 +333,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a95d9c6a59674193aa55798968d1a9de6.html b/classnlohmann_1_1basic__json_a95d9c6a59674193aa55798968d1a9de6.html index 8d8ec6419..7157e0782 100644 --- a/classnlohmann_1_1basic__json_a95d9c6a59674193aa55798968d1a9de6.html +++ b/classnlohmann_1_1basic__json_a95d9c6a59674193aa55798968d1a9de6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorarray__key_type_const.cpp -o operatorarray__key_type_const 
    See also
    at(const typename object_t::key_type&) for access by reference with range checking
    @@ -298,7 +298,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html index bb2dd40f3..d6263e2ba 100644 --- a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html +++ b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether v is null
    Complexity
    Constant.
    Example
    The example compares several JSON types to the null pointer.
    -
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " == nullptr " << (array == nullptr) << '\n';
    17  std::cout << object << " == nullptr " << (object == nullptr) << '\n';
    18  std::cout << number << " == nullptr " << (number == nullptr) << '\n';
    19  std::cout << string << " == nullptr " << (string == nullptr) << '\n';
    20  std::cout << null << " == nullptr " << (null == nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " == nullptr " << (array == nullptr) << '\n';
    17  std::cout << object << " == nullptr " << (object == nullptr) << '\n';
    18  std::cout << number << " == nullptr " << (number == nullptr) << '\n';
    19  std::cout << string << " == nullptr " << (string == nullptr) << '\n';
    20  std::cout << null << " == nullptr " << (null == nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
    @@ -298,7 +298,7 @@ null == nullptr true
     
    diff --git a/classnlohmann_1_1basic__json_a9780ea9bb66b6191cb087b14396972c1.html b/classnlohmann_1_1basic__json_a9780ea9bb66b6191cb087b14396972c1.html index f7909e239..980a68590 100644 --- a/classnlohmann_1_1basic__json_a9780ea9bb66b6191cb087b14396972c1.html +++ b/classnlohmann_1_1basic__json_a9780ea9bb66b6191cb087b14396972c1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ template<typename PointerType , typename std::enable_if< std::is_pointer&l
    Returns
    pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    @@ -290,7 +290,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html index d6d8f6c15..1ac41af6a 100644 --- a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html +++ b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether v is null
    Complexity
    Constant.
    Example
    The example compares several JSON types to the null pointer.
    -
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " == nullptr " << (array == nullptr) << '\n';
    17  std::cout << object << " == nullptr " << (object == nullptr) << '\n';
    18  std::cout << number << " == nullptr " << (number == nullptr) << '\n';
    19  std::cout << string << " == nullptr " << (string == nullptr) << '\n';
    20  std::cout << null << " == nullptr " << (null == nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " == nullptr " << (array == nullptr) << '\n';
    17  std::cout << object << " == nullptr " << (object == nullptr) << '\n';
    18  std::cout << number << " == nullptr " << (number == nullptr) << '\n';
    19  std::cout << string << " == nullptr " << (string == nullptr) << '\n';
    20  std::cout << null << " == nullptr " << (null == nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
    @@ -298,7 +298,7 @@ null == nullptr true
     
    diff --git a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html index f7bbd90a9..0da47f024 100644 --- a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html +++ b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows the constructor with an object_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an object_t value
    8  json::object_t value = { {"one", 1}, {"two", 2} };
    9 
    10  // create a JSON object from the value
    11  json j(value);
    12 
    13  // serialize the JSON object
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with an object_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an object_t value
    8  json::object_t value = { {"one", 1}, {"two", 2} };
    9 
    10  // create a JSON object from the value
    11  json j(value);
    12 
    13  // serialize the JSON object
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:395
    Output (play with this example online):
    {"one":1,"two":2}
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__object_t.cpp -o basic_json__object_t 
    @@ -291,7 +291,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html b/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html index 061f859fc..8ec3623d4 100644 --- a/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html +++ b/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -275,7 +275,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Linear in the size of the initializer list init.
    Note
    This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.
    -
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html index f79c52bce..127ca6e37 100644 --- a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html +++ b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html b/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html index b65725e29..040e3f6cd 100644 --- a/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html +++ b/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -297,7 +297,7 @@ Example when certain parse events are triggered
    diff --git a/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html b/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html index f66d12737..da80e8142 100644 --- a/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html +++ b/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -275,7 +275,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Linear in the size of the initializer list init.
    Note
    This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.
    -
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -292,7 +292,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html index 2402f7320..41168611c 100644 --- a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html +++ b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    log(size()) + count(key)
    -
    Example
    The example shows the effect of erase().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows the effect of erase().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -297,7 +297,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_aa388dc101bc285a98122a38fd2e3a9db.html b/classnlohmann_1_1basic__json_aa388dc101bc285a98122a38fd2e3a9db.html index f6918193c..2618f493b 100644 --- a/classnlohmann_1_1basic__json_aa388dc101bc285a98122a38fd2e3a9db.html +++ b/classnlohmann_1_1basic__json_aa388dc101bc285a98122a38fd2e3a9db.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is an unsigned integer number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_unsigned() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_unsigned()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_unsigned() << '\n';
    20  std::cout << j_boolean.is_number_unsigned() << '\n';
    21  std::cout << j_number_integer.is_number_unsigned() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_unsigned() << '\n';
    23  std::cout << j_number_float.is_number_unsigned() << '\n';
    24  std::cout << j_object.is_number_unsigned() << '\n';
    25  std::cout << j_array.is_number_unsigned() << '\n';
    26  std::cout << j_string.is_number_unsigned() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_number_unsigned() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_unsigned()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_unsigned() << '\n';
    20  std::cout << j_boolean.is_number_unsigned() << '\n';
    21  std::cout << j_number_integer.is_number_unsigned() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_unsigned() << '\n';
    23  std::cout << j_number_float.is_number_unsigned() << '\n';
    24  std::cout << j_object.is_number_unsigned() << '\n';
    25  std::cout << j_array.is_number_unsigned() << '\n';
    26  std::cout << j_string.is_number_unsigned() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     false
     false
    @@ -290,7 +290,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html b/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html index 03231c99c..98a5afbf3 100644 --- a/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html +++ b/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html b/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html index f353afd7a..e0665e616 100644 --- a/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html +++ b/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -293,7 +293,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_aa7084e62b93ef0236698b246a58bb2da.html b/classnlohmann_1_1basic__json_aa7084e62b93ef0236698b246a58bb2da.html index 0ffc17041..089b0132e 100644 --- a/classnlohmann_1_1basic__json_aa7084e62b93ef0236698b246a58bb2da.html +++ b/classnlohmann_1_1basic__json_aa7084e62b93ef0236698b246a58bb2da.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rend().
  • -
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crend();
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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::const_reverse_iterator it = array.crend();
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:285
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aa730d68d55ccc48d2cd4835ff46d2a0f.html b/classnlohmann_1_1basic__json_aa730d68d55ccc48d2cd4835ff46d2a0f.html index 4044e048f..5b3216295 100644 --- a/classnlohmann_1_1basic__json_aa730d68d55ccc48d2cd4835ff46d2a0f.html +++ b/classnlohmann_1_1basic__json_aa730d68d55ccc48d2cd4835ff46d2a0f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).end().
  • -
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    end() – returns an iterator to the end
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aa7ad0ebda83e54c22ba8b3d954ef1293.html b/classnlohmann_1_1basic__json_aa7ad0ebda83e54c22ba8b3d954ef1293.html index 0adb6040b..fbc1ddbff 100644 --- a/classnlohmann_1_1basic__json_aa7ad0ebda83e54c22ba8b3d954ef1293.html +++ b/classnlohmann_1_1basic__json_aa7ad0ebda83e54c22ba8b3d954ef1293.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj

    Create a null JSON value. It either takes a null pointer as parameter (explicitly creating null) or no parameter (implicitly creating null). The passed null pointer itself is not read – it is only used to choose the right constructor.

    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this constructor never throws exceptions.
    -
    Example
    The following code shows the constructor with and without a null pointer parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // implicitly create a JSON null value
    8  json j1;
    9 
    10  // explicitly create a JSON null value
    11  json j2(nullptr);
    12 
    13  // serialize the JSON null value
    14  std::cout << j1 << '\n' << j2 << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with and without a null pointer parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // implicitly create a JSON null value
    8  json j1;
    9 
    10  // explicitly create a JSON null value
    11  json j2(nullptr);
    12 
    13  // serialize the JSON null value
    14  std::cout << j1 << '\n' << j2 << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    null
     null
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__nullptr_t.cpp -o basic_json__nullptr_t 
    @@ -279,7 +279,7 @@ null
    diff --git a/classnlohmann_1_1basic__json_aa8996e3f8cd3e5113dcc3cb34bef7c0a.html b/classnlohmann_1_1basic__json_aa8996e3f8cd3e5113dcc3cb34bef7c0a.html index 16e73d00b..7f38a23c1 100644 --- a/classnlohmann_1_1basic__json_aa8996e3f8cd3e5113dcc3cb34bef7c0a.html +++ b/classnlohmann_1_1basic__json_aa8996e3f8cd3e5113dcc3cb34bef7c0a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -305,7 +305,7 @@ use erase() with null"
  • other types: constant
  • -
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    null
     null
     null
    @@ -330,7 +330,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_aa8dca2e91a6301c36890f844e64f0023.html b/classnlohmann_1_1basic__json_aa8dca2e91a6301c36890f844e64f0023.html index 514bb8972..fb244d51f 100644 --- a/classnlohmann_1_1basic__json_aa8dca2e91a6301c36890f844e64f0023.html +++ b/classnlohmann_1_1basic__json_aa8dca2e91a6301c36890f844e64f0023.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -300,7 +300,7 @@ Each element in the range has a size of 1 byte. Violating this precondition yiel
    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 reading from an iterator range.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text given as std::vector
    8  std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
    9 
    10  // parse and serialize JSON
    11  json j_complete = json::parse(text.begin(), text.end());
    12  std::cout << std::setw(4) << j_complete << "\n\n";
    13 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below demonstrates the parse() function reading from an iterator range.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text given as std::vector
    8  std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
    9 
    10  // parse and serialize JSON
    11  json j_complete = json::parse(text.begin(), text.end());
    12  std::cout << std::setw(4) << j_complete << "\n\n";
    13 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    Output (play with this example online):
    [
         1,
    @@ -321,7 +321,7 @@ Each element in the range has a size of 1 byte. Violating this precondition yiel
     
    diff --git a/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html b/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html index 2a2071a27..f7f5f6a08 100644 --- a/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html +++ b/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • Has the semantics of reverse_iterator(begin()).
  • -
    Example
    The following code shows an example for rend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for rend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:283
    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 
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html b/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html index 2cec1ac50..f5d16cb3c 100644 --- a/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html +++ b/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -268,7 +268,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Constant.
    -
    Example
    The example below demonstrates boolean values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create boolean values
    8  json j_truth = true;
    9  json j_falsity = false;
    10 
    11  // serialize the JSON booleans
    12  std::cout << j_truth << '\n';
    13  std::cout << j_falsity << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below demonstrates boolean values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create boolean values
    8  json j_truth = true;
    9  json j_falsity = false;
    10 
    11  // serialize the JSON booleans
    12  std::cout << j_truth << '\n';
    13  std::cout << j_falsity << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    true
     false
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__boolean_t.cpp -o basic_json__boolean_t 
    @@ -284,7 +284,7 @@ false
    diff --git a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html index 270b3effe..db23233d6 100644 --- a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html +++ b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether lhs is less than rhs
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array_1 = {1, 2, 3};
    9  json array_2 = {1, 2, 4};
    10  json object_1 = {{"A", "a"}, {"B", "b"}};
    11  json object_2 = {{"B", "b"}, {"A", "a"}};
    12  json number_1 = 17;
    13  json number_2 = 17.0000000000001L;
    14  json string_1 = "foo";
    15  json string_2 = "bar";
    16 
    17  // output values and comparisons
    18  std::cout << std::boolalpha;
    19  std::cout << array_1 << " == " << array_2 << " " << (array_1 < array_2) << '\n';
    20  std::cout << object_1 << " == " << object_2 << " " << (object_1 < object_2) << '\n';
    21  std::cout << number_1 << " == " << number_2 << " " << (number_1 < number_2) << '\n';
    22  std::cout << string_1 << " == " << string_2 << " " << (string_1 < string_2) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
     {"A":"a","B":"b"} == {"A":"a","B":"b"} false
     17 == 17.0000000000001 true
    @@ -302,7 +302,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html index cd84b27b5..e90b702b7 100644 --- a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html +++ b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -303,7 +303,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html index 50ae6769b..451c32db1 100644 --- a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html +++ b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -286,7 +286,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Linear in the length of the input. The parser is a predictive LL(1) parser.
    Note
    A UTF-8 byte order mark is silently ignored.
    -
    Example
    The example below shows how a JSON value is constructed by reading a serialization from a stream.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create stream with serialized JSON
    8  std::stringstream ss;
    9  ss << R"({
    10  "number": 23,
    11  "string": "Hello, world!",
    12  "array": [1, 2, 3, 4, 5],
    13  "boolean": false,
    14  "null": null
    15  })";
    16 
    17  // create JSON value and read the serialization from the stream
    18  json j;
    19  j << ss;
    20 
    21  // serialize JSON
    22  std::cout << std::setw(2) << j << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how a JSON value is constructed by reading a serialization from a stream.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create stream with serialized JSON
    8  std::stringstream ss;
    9  ss << R"({
    10  "number": 23,
    11  "string": "Hello, world!",
    12  "array": [1, 2, 3, 4, 5],
    13  "boolean": false,
    14  "null": null
    15  })";
    16 
    17  // create JSON value and read the serialization from the stream
    18  json j;
    19  j << ss;
    20 
    21  // serialize JSON
    22  std::cout << std::setw(2) << j << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {
       "array": [
         1,
    @@ -314,7 +314,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html b/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html index 69446e686..fabaaaf4d 100644 --- a/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html +++ b/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -281,7 +281,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ab5386a09a24b341435172f43962a43f2.html b/classnlohmann_1_1basic__json_ab5386a09a24b341435172f43962a43f2.html index 2ad8e1fff..0c1b25401 100644 --- a/classnlohmann_1_1basic__json_ab5386a09a24b341435172f43962a43f2.html +++ b/classnlohmann_1_1basic__json_ab5386a09a24b341435172f43962a43f2.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<typename ReferenceType , typename std::enable_if< std::is_referen
    Complexity
    Constant.
    -
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    Output (play with this example online):
    17 17
    @@ -295,7 +295,7 @@ incompatible ReferenceType for get_ref, actual type is number
     
    diff --git a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html index edcad895f..0225f1b6b 100644 --- a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html +++ b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -279,7 +279,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html index 4a4eacf4d..0eb038b73 100644 --- a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html +++ b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -282,7 +282,7 @@ template<class CompatibleObjectType , typename std::enable_if< std::is_con
    -
    Example
    The following code shows the constructor with several compatible object type parameters.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using json = nlohmann::json;
    5 
    6 int main()
    7 {
    8  // create an object from std::map
    9  std::map<std::string, int> c_map
    10  {
    11  {"one", 1}, {"two", 2}, {"three", 3}
    12  };
    13  json j_map(c_map);
    14 
    15  // create an object from std::unordered_map
    16  std::unordered_map<const char*, double> c_umap
    17  {
    18  {"one", 1.2}, {"two", 2.3}, {"three", 3.4}
    19  };
    20  json j_umap(c_umap);
    21 
    22  // create an object from std::multimap
    23  std::multimap<std::string, bool> c_mmap
    24  {
    25  {"one", true}, {"two", true}, {"three", false}, {"three", true}
    26  };
    27  json j_mmap(c_mmap); // only one entry for key "three" is used
    28 
    29  // create an object from std::unordered_multimap
    30  std::unordered_multimap<std::string, bool> c_ummap
    31  {
    32  {"one", true}, {"two", true}, {"three", false}, {"three", true}
    33  };
    34  json j_ummap(c_ummap); // only one entry for key "three" is used
    35 
    36  // serialize the JSON objects
    37  std::cout << j_map << '\n';
    38  std::cout << j_umap << '\n';
    39  std::cout << j_mmap << '\n';
    40  std::cout << j_ummap << '\n';
    41 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with several compatible object type parameters.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using json = nlohmann::json;
    5 
    6 int main()
    7 {
    8  // create an object from std::map
    9  std::map<std::string, int> c_map
    10  {
    11  {"one", 1}, {"two", 2}, {"three", 3}
    12  };
    13  json j_map(c_map);
    14 
    15  // create an object from std::unordered_map
    16  std::unordered_map<const char*, double> c_umap
    17  {
    18  {"one", 1.2}, {"two", 2.3}, {"three", 3.4}
    19  };
    20  json j_umap(c_umap);
    21 
    22  // create an object from std::multimap
    23  std::multimap<std::string, bool> c_mmap
    24  {
    25  {"one", true}, {"two", true}, {"three", false}, {"three", true}
    26  };
    27  json j_mmap(c_mmap); // only one entry for key "three" is used
    28 
    29  // create an object from std::unordered_multimap
    30  std::unordered_multimap<std::string, bool> c_ummap
    31  {
    32  {"one", true}, {"two", true}, {"three", false}, {"three", true}
    33  };
    34  json j_ummap(c_ummap); // only one entry for key "three" is used
    35 
    36  // serialize the JSON objects
    37  std::cout << j_map << '\n';
    38  std::cout << j_umap << '\n';
    39  std::cout << j_mmap << '\n';
    40  std::cout << j_ummap << '\n';
    41 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"three":3,"two":2}
     {"one":1.2,"three":3.4,"two":2.3}
     {"one":true,"three":false,"two":true}
    @@ -301,7 +301,7 @@ template<class CompatibleObjectType , typename std::enable_if< std::is_con
     
    diff --git a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html index 448852d11..a10033916 100644 --- a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html +++ b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -274,7 +274,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    -
    Example
    The following code shows the constructor with an string_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an string_t value
    8  json::string_t value = "The quick brown fox jumps over the lazy doc";
    9 
    10  // create a JSON string from the value
    11  json j(value);
    12 
    13  // serialize the JSON array
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the constructor with an string_t parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an string_t value
    8  json::string_t value = "The quick brown fox jumps over the lazy doc";
    9 
    10  // create a JSON string from the value
    11  json j(value);
    12 
    13  // serialize the JSON array
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    StringType string_t
    a type for a string
    Definition: json.hpp:488
    Output (play with this example online):
    "The quick brown fox jumps over the lazy doc"
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__string_t.cpp -o basic_json__string_t 
    @@ -293,7 +293,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html b/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html index b4d7f4c70..933a2d286 100644 --- a/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html +++ b/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -273,7 +273,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ab9f8c9a02d6bb794ee26801a232ca4f4.html b/classnlohmann_1_1basic__json_ab9f8c9a02d6bb794ee26801a232ca4f4.html index a740594d0..e427de5f6 100644 --- a/classnlohmann_1_1basic__json_ab9f8c9a02d6bb794ee26801a232ca4f4.html +++ b/classnlohmann_1_1basic__json_ab9f8c9a02d6bb794ee26801a232ca4f4.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -295,7 +295,7 @@ out of range"
  • other types: constant
  • -
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    null
     null
     null
    @@ -320,7 +320,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_aba0695744dbcdad65825f91768a8f04f.html b/classnlohmann_1_1basic__json_aba0695744dbcdad65825f91768a8f04f.html index 1f4e9ba56..dddfd0321 100644 --- a/classnlohmann_1_1basic__json_aba0695744dbcdad65825f91768a8f04f.html +++ b/classnlohmann_1_1basic__json_aba0695744dbcdad65825f91768a8f04f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<typename ValueType , typename std::enable_if< not std::is_pointer
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     42 42
     17.23 17
    @@ -304,7 +304,7 @@ array: [1,2,3,4,5]
     
    diff --git a/classnlohmann_1_1basic__json_abc459edfac71c4ecc9347731f722026b.html b/classnlohmann_1_1basic__json_abc459edfac71c4ecc9347731f722026b.html index fdb99d4e4..503668d8c 100644 --- a/classnlohmann_1_1basic__json_abc459edfac71c4ecc9347731f722026b.html +++ b/classnlohmann_1_1basic__json_abc459edfac71c4ecc9347731f722026b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -267,7 +267,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    the original JSON from a flattened version
    Note
    Empty objects and arrays are flattened by flatten() to null values and can not unflattened to their original type. Apart from this example, for a JSON value j, the following is always true: j == j.flatten().unflatten().
    Complexity
    Linear in the size the JSON value.
    -
    Example
    The following code shows how a flattened JSON object is unflattened into the original nested JSON object.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j_flattened =
    9  {
    10  {"/answer/everything", 42},
    11  {"/happy", true},
    12  {"/list/0", 1},
    13  {"/list/1", 0},
    14  {"/list/2", 2},
    15  {"/name", "Niels"},
    16  {"/nothing", nullptr},
    17  {"/object/currency", "USD"},
    18  {"/object/value", 42.99},
    19  {"/pi", 3.141}
    20  };
    21 
    22  // call unflatten()
    23  std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows how a flattened JSON object is unflattened into the original nested JSON object.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j_flattened =
    9  {
    10  {"/answer/everything", 42},
    11  {"/happy", true},
    12  {"/list/0", 1},
    13  {"/list/1", 0},
    14  {"/list/2", 2},
    15  {"/name", "Niels"},
    16  {"/nothing", nullptr},
    17  {"/object/currency", "USD"},
    18  {"/object/value", 42.99},
    19  {"/pi", 3.141}
    20  };
    21 
    22  // call unflatten()
    23  std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {
         "answer": {
             "everything": 42
    @@ -290,7 +290,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    See also
    flatten() for the reverse function
    Since
    version 2.0.0
    -

    Definition at line 10054 of file json.hpp.

    +

    Definition at line 10222 of file json.hpp.

    @@ -300,7 +300,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_abd7e95159740e94160c13392b1536eb1.html b/classnlohmann_1_1basic__json_abd7e95159740e94160c13392b1536eb1.html index a355ea828..1224af66c 100644 --- a/classnlohmann_1_1basic__json_abd7e95159740e94160c13392b1536eb1.html +++ b/classnlohmann_1_1basic__json_abd7e95159740e94160c13392b1536eb1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).end().
  • -
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    end() – returns an iterator to the end
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html index 6ed77c5ce..aa9aa3122 100644 --- a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html +++ b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -286,7 +286,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html b/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html index aa78a24b0..76024538a 100644 --- a/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html +++ b/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ template<typename PointerType , typename std::enable_if< std::is_pointer&l
    Returns
    pointer to the internally stored JSON value if the requested pointer type PointerType fits to the JSON value; nullptr otherwise
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:586
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    @@ -291,7 +291,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_ac5bed64638180098b5db82f8e482d855.html b/classnlohmann_1_1basic__json_ac5bed64638180098b5db82f8e482d855.html index c0ade6509..2f9fa7453 100644 --- a/classnlohmann_1_1basic__json_ac5bed64638180098b5db82f8e482d855.html +++ b/classnlohmann_1_1basic__json_ac5bed64638180098b5db82f8e482d855.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<typename ValueType , typename std::enable_if< not std::is_pointer
    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 json = nlohmann::json;
    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 implicit conversions
    24  bool v1 = json_types["boolean"];
    25  int v2 = json_types["number"]["integer"];
    26  short v3 = json_types["number"]["integer"];
    27  float v4 = json_types["number"]["floating-point"];
    28  int v5 = json_types["number"]["floating-point"];
    29  std::string v6 = json_types["string"];
    30  std::vector<short> v7 = json_types["array"];
    31  std::unordered_map<std::string, json> v8 = json_types;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    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 json = nlohmann::json;
    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 implicit conversions
    24  bool v1 = json_types["boolean"];
    25  int v2 = json_types["number"]["integer"];
    26  short v3 = json_types["number"]["integer"];
    27  float v4 = json_types["number"]["floating-point"];
    28  int v5 = json_types["number"]["floating-point"];
    29  std::string v6 = json_types["string"];
    30  std::vector<short> v7 = json_types["array"];
    31  std::unordered_map<std::string, json> v8 = json_types;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    1
     42 42
     17.23 17
    @@ -301,7 +301,7 @@ array: [1,2,3,4,5]
     
    diff --git a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html index 847df24f5..39a9d5205 100644 --- a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html +++ b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ template<typename T >
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
     {
    @@ -314,7 +314,7 @@ template<typename T > 
    diff --git a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html index e66624706..10717b8dd 100644 --- a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html +++ b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ace63ac4eb1dd7251a259d32e397461a3.html b/classnlohmann_1_1basic__json_ace63ac4eb1dd7251a259d32e397461a3.html index 60b09dd8d..aa970b4df 100644 --- a/classnlohmann_1_1basic__json_ace63ac4eb1dd7251a259d32e397461a3.html +++ b/classnlohmann_1_1basic__json_ace63ac4eb1dd7251a259d32e397461a3.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -284,7 +284,7 @@ template<class T , std::size_t N>
    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 reading from an array.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  char 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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below demonstrates the parse() function reading from an array.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  char 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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    Output (play with this example online):
    {
         "Image": {
    @@ -319,7 +319,7 @@ template<class T , std::size_t N> 
    diff --git a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html index f0738af2a..c7527d090 100644 --- a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html +++ b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -277,7 +277,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Complexity
    Linear in the size of init.
    Example
    The following code shows an example for the object function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON objects
    8  json j_no_init_list = json::object();
    9  json j_empty_init_list = json::object({});
    10  json j_list_of_pairs = json::object({ {"one", 1}, {"two", 2} });
    11  //json j_invalid_list = json::object({ "one", 1 }); // would throw
    12 
    13  // serialize the JSON objects
    14  std::cout << j_no_init_list << '\n';
    15  std::cout << j_empty_init_list << '\n';
    16  std::cout << j_list_of_pairs << '\n';
    17 }
    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:1760
    -
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {}
     {}
     {"one":1,"two":2}
    @@ -297,7 +297,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html b/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html
    index 04a6cea40..38bd2c8e9 100644
    --- a/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html
    +++ b/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html
    @@ -23,7 +23,7 @@
      
       
        
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -276,7 +276,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if< s
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of several integer number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different integer types
    8  short n42 = 42;
    9  int n23 = 23;
    10  long n1024 = 1024;
    11  int_least32_t n17 = 17;
    12  uint8_t n8 = 8;
    13 
    14  // create JSON numbers
    15  json j42(n42);
    16  json j23(n23);
    17  json j1024(n1024);
    18  json j17(n17);
    19  json j8(n8);
    20 
    21  // serialize the JSON numbers
    22  std::cout << j42 << '\n';
    23  std::cout << j23 << '\n';
    24  std::cout << j1024 << '\n';
    25  std::cout << j17 << '\n';
    26  std::cout << j8 << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the construction of several integer number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different integer types
    8  short n42 = 42;
    9  int n23 = 23;
    10  long n1024 = 1024;
    11  int_least32_t n17 = 17;
    12  uint8_t n8 = 8;
    13 
    14  // create JSON numbers
    15  json j42(n42);
    16  json j23(n23);
    17  json j1024(n1024);
    18  json j17(n17);
    19  json j8(n8);
    20 
    21  // serialize the JSON numbers
    22  std::cout << j42 << '\n';
    23  std::cout << j23 << '\n';
    24  std::cout << j1024 << '\n';
    25  std::cout << j17 << '\n';
    26  std::cout << j8 << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    42
     23
     1024
    @@ -298,7 +298,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if< s
     
    diff --git a/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html b/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html index 84d240f35..4a52a2932 100644 --- a/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html +++ b/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -270,7 +270,7 @@ Illustration from cppreference.com
  • The complexity is constant.
  • -
    Example
    The following code shows an example for begin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for begin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    cbegin() – returns a const iterator to the beginning
    @@ -290,7 +290,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html b/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html index e6ba2e99a..e3c444aed 100644 --- a/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html +++ b/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Note
    Floating-point numbers are set to 0.0 which will be serialized to 0. The vale type remains number_float_t.
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows the effect of clear() to different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    null
     false
     0
    @@ -299,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_ad797fbde8b35ce96549d4bee5d42b234.html b/classnlohmann_1_1basic__json_ad797fbde8b35ce96549d4bee5d42b234.html index 7b750bacd..961e909d8 100644 --- a/classnlohmann_1_1basic__json_ad797fbde8b35ce96549d4bee5d42b234.html +++ b/classnlohmann_1_1basic__json_ad797fbde8b35ce96549d4bee5d42b234.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    2
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorarray__key_type_const.cpp -o operatorarray__key_type_const 
    See also
    at(const typename object_t::key_type&) for access by reference with range checking
    @@ -298,7 +298,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_adade77415e7f7bf08a9b5150c742714d.html b/classnlohmann_1_1basic__json_adade77415e7f7bf08a9b5150c742714d.html index c5dc8960d..0c7162e1c 100644 --- a/classnlohmann_1_1basic__json_adade77415e7f7bf08a9b5150c742714d.html +++ b/classnlohmann_1_1basic__json_adade77415e7f7bf08a9b5150c742714d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is boolean, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_boolean() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_boolean()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_boolean() << '\n';
    20  std::cout << j_boolean.is_boolean() << '\n';
    21  std::cout << j_number_integer.is_boolean() << '\n';
    22  std::cout << j_number_unsigned_integer.is_boolean() << '\n';
    23  std::cout << j_number_float.is_boolean() << '\n';
    24  std::cout << j_object.is_boolean() << '\n';
    25  std::cout << j_array.is_boolean() << '\n';
    26  std::cout << j_string.is_boolean() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_boolean() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_boolean()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_boolean() << '\n';
    20  std::cout << j_boolean.is_boolean() << '\n';
    21  std::cout << j_number_integer.is_boolean() << '\n';
    22  std::cout << j_number_unsigned_integer.is_boolean() << '\n';
    23  std::cout << j_number_float.is_boolean() << '\n';
    24  std::cout << j_object.is_boolean() << '\n';
    25  std::cout << j_array.is_boolean() << '\n';
    26  std::cout << j_string.is_boolean() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    false
     true
     false
    @@ -285,7 +285,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_adcd6086bac286854d5cc8b7f84d74a49.html b/classnlohmann_1_1basic__json_adcd6086bac286854d5cc8b7f84d74a49.html index 73adbe177..47424ffb3 100644 --- a/classnlohmann_1_1basic__json_adcd6086bac286854d5cc8b7f84d74a49.html +++ b/classnlohmann_1_1basic__json_adcd6086bac286854d5cc8b7f84d74a49.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -263,7 +263,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    true if type is primitive (string, number, boolean, or null), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_primitive() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_primitive()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_primitive() << '\n';
    20  std::cout << j_boolean.is_primitive() << '\n';
    21  std::cout << j_number_integer.is_primitive() << '\n';
    22  std::cout << j_number_unsigned_integer.is_primitive() << '\n';
    23  std::cout << j_number_float.is_primitive() << '\n';
    24  std::cout << j_object.is_primitive() << '\n';
    25  std::cout << j_array.is_primitive() << '\n';
    26  std::cout << j_string.is_primitive() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code exemplifies is_primitive() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_primitive()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_primitive() << '\n';
    20  std::cout << j_boolean.is_primitive() << '\n';
    21  std::cout << j_number_integer.is_primitive() << '\n';
    22  std::cout << j_number_unsigned_integer.is_primitive() << '\n';
    23  std::cout << j_number_float.is_primitive() << '\n';
    24  std::cout << j_object.is_primitive() << '\n';
    25  std::cout << j_array.is_primitive() << '\n';
    26  std::cout << j_string.is_primitive() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    true
     true
     true
    @@ -294,7 +294,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_ae08fa64b9f0a5b5c878cbbabb7a296ee.html b/classnlohmann_1_1basic__json_ae08fa64b9f0a5b5c878cbbabb7a296ee.html index 29b100db6..d35af5789 100644 --- a/classnlohmann_1_1basic__json_ae08fa64b9f0a5b5c878cbbabb7a296ee.html +++ b/classnlohmann_1_1basic__json_ae08fa64b9f0a5b5c878cbbabb7a296ee.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -272,7 +272,7 @@ template<template< typename U, typename V, typename... Args > class Obj
  • The complexity is linear.
  • -
    Example
    The code below shows and example for the copy assignment. It creates a copy of value a which is then swapped with b. Finally, the copy of a (which is the null value after the swap) is destroyed.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json a = 23;
    9  json b = 42;
    10 
    11  // copy-assign a to b
    12  b = a;
    13 
    14  // serialize the JSON arrays
    15  std::cout << a << '\n';
    16  std::cout << b << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The code below shows and example for the copy assignment. It creates a copy of value a which is then swapped with b. Finally, the copy of a (which is the null value after the swap) is destroyed.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json a = 23;
    9  json b = 42;
    10 
    11  // copy-assign a to b
    12  b = a;
    13 
    14  // serialize the JSON arrays
    15  std::cout << a << '\n';
    16  std::cout << b << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    23
     23
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__copyassignment.cpp -o basic_json__copyassignment 
    @@ -288,7 +288,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    diff --git a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html index a43be8edd..dbf83effe 100644 --- a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html +++ b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html index e6eb4c60a..2026f61b9 100644 --- a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html +++ b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    whether v is not null
    Complexity
    Constant.
    Example
    The example compares several JSON types to the null pointer.
    -
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " != nullptr " << (array != nullptr) << '\n';
    17  std::cout << object << " != nullptr " << (object != nullptr) << '\n';
    18  std::cout << number << " != nullptr " << (number != nullptr) << '\n';
    19  std::cout << string << " != nullptr " << (string != nullptr) << '\n';
    20  std::cout << null << " != nullptr " << (null != nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create several JSON values
    8  json array = {1, 2, 3};
    9  json object = {{"A", "a"}, {"B", "b"}};
    10  json number = 17;
    11  json string = "foo";
    12  json null;
    13 
    14  // output values and comparisons
    15  std::cout << std::boolalpha;
    16  std::cout << array << " != nullptr " << (array != nullptr) << '\n';
    17  std::cout << object << " != nullptr " << (object != nullptr) << '\n';
    18  std::cout << number << " != nullptr " << (number != nullptr) << '\n';
    19  std::cout << string << " != nullptr " << (string != nullptr) << '\n';
    20  std::cout << null << " != nullptr " << (null != nullptr) << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
    @@ -298,7 +298,7 @@ null != nullptr false
     
    diff --git a/classnlohmann_1_1basic__json_ae3fe0423252e171973cdd5786d036e30.html b/classnlohmann_1_1basic__json_ae3fe0423252e171973cdd5786d036e30.html index 38dc774e7..0fafa8392 100644 --- a/classnlohmann_1_1basic__json_ae3fe0423252e171973cdd5786d036e30.html +++ b/classnlohmann_1_1basic__json_ae3fe0423252e171973cdd5786d036e30.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename... Args > class Obj
  • Has the semantics of begin() == end().
  • -
    Example
    The following code uses empty() to check if a JSON object contains any elements.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 empty()
    19  std::cout << std::boolalpha;
    20  std::cout << j_null.empty() << '\n';
    21  std::cout << j_boolean.empty() << '\n';
    22  std::cout << j_number_integer.empty() << '\n';
    23  std::cout << j_number_float.empty() << '\n';
    24  std::cout << j_object.empty() << '\n';
    25  std::cout << j_object_empty.empty() << '\n';
    26  std::cout << j_array.empty() << '\n';
    27  std::cout << j_array_empty.empty() << '\n';
    28  std::cout << j_string.empty() << '\n';
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code uses empty() to check if a JSON object contains any elements.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 empty()
    19  std::cout << std::boolalpha;
    20  std::cout << j_null.empty() << '\n';
    21  std::cout << j_boolean.empty() << '\n';
    22  std::cout << j_number_integer.empty() << '\n';
    23  std::cout << j_number_float.empty() << '\n';
    24  std::cout << j_object.empty() << '\n';
    25  std::cout << j_object_empty.empty() << '\n';
    26  std::cout << j_array.empty() << '\n';
    27  std::cout << j_array_empty.empty() << '\n';
    28  std::cout << j_string.empty() << '\n';
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -310,7 +310,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html index e9d0d133e..9267be295 100644 --- a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html +++ b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -282,7 +282,7 @@ template<class CompatibleStringType , typename std::enable_if< std::is_con
    -
    Example
    The following code shows the construction of a string value from a compatible type.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a string value
    8  std::string s = "The quick brown fox jumps over the lazy dog.";
    9 
    10  // create a JSON string value
    11  json j = s;
    12 
    13  // serialize the JSON string
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows the construction of a string value from a compatible type.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a string value
    8  std::string s = "The quick brown fox jumps over the lazy dog.";
    9 
    10  // create a JSON string value
    11  json j = s;
    12 
    13  // serialize the JSON string
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "The quick brown fox jumps over the lazy dog."
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__CompatibleStringType.cpp -o basic_json__CompatibleStringType 
    See also
    basic_json(const string_t&) – create a string value
    @@ -300,7 +300,7 @@ template<class CompatibleStringType , typename std::enable_if< std::is_con
    diff --git a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html index e4c91b881..d6fd7be8f 100644 --- a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html +++ b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -287,7 +287,7 @@ Example when certain parse events are triggered diff --git a/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html b/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html index 8260ecda0..33c2fc40d 100644 --- a/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html +++ b/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -297,7 +297,7 @@ 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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    @@ -313,7 +313,7 @@ belong to container"
    diff --git a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html index 289061b31..9bbac573f 100644 --- a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html +++ b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_aeffd70f622f8f2a51fd3d95af64b63a7.html b/classnlohmann_1_1basic__json_aeffd70f622f8f2a51fd3d95af64b63a7.html index 902adf6c9..919940fd3 100644 --- a/classnlohmann_1_1basic__json_aeffd70f622f8f2a51fd3d95af64b63a7.html +++ b/classnlohmann_1_1basic__json_aeffd70f622f8f2a51fd3d95af64b63a7.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -293,7 +293,7 @@ Each element of the container has a size of 1 byte. Violating this precondition
    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 reading from a contiguous container.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text given as std::vector
    8  std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
    9 
    10  // parse and serialize JSON
    11  json j_complete = json::parse(text);
    12  std::cout << std::setw(4) << j_complete << "\n\n";
    13 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below demonstrates the parse() function reading from a contiguous container.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text given as std::vector
    8  std::vector<uint8_t> text = {'[', '1', ',', '2', ',', '3', ']', '\0'};
    9 
    10  // parse and serialize JSON
    11  json j_complete = json::parse(text);
    12  std::cout << std::setw(4) << j_complete << "\n\n";
    13 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    static basic_json parse(T(&array)[N], const parser_callback_t cb=nullptr)
    deserialize from an array
    Definition: json.hpp:5897
    Output (play with this example online):
    [
         1,
    @@ -314,7 +314,7 @@ Each element of the container has a size of 1 byte. Violating this precondition
     
    diff --git a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html index 2ea965451..80089093f 100644 --- a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html +++ b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -273,7 +273,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html b/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html index 359b41a1b..275c10967 100644 --- a/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html +++ b/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -266,7 +266,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html b/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html index d0ce91fb9..a2aac5f8f 100644 --- a/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html +++ b/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -259,7 +259,7 @@ template<template< typename U, typename V, typename... Args > class Obj diff --git a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html index f84f2d0c5..905612082 100644 --- a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html +++ b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -302,7 +302,7 @@ use 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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example below shows several ways to create JSON values by specifying a subrange with iterators.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    ["bravo","charly"]
     42
     {"one":"eins"}
    @@ -319,7 +319,7 @@ use construct with iterators from null"
     
    diff --git a/classnlohmann_1_1basic__json_af9587bc58ebfac62b2c6b08799f57c2f.html b/classnlohmann_1_1basic__json_af9587bc58ebfac62b2c6b08799f57c2f.html index fe1256bbe..4a34380fe 100644 --- a/classnlohmann_1_1basic__json_af9587bc58ebfac62b2c6b08799f57c2f.html +++ b/classnlohmann_1_1basic__json_af9587bc58ebfac62b2c6b08799f57c2f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -271,7 +271,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).begin().
  • -
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    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 
    See also
    begin() – returns an iterator to the beginning
    @@ -291,7 +291,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_afd4b7d7bcadc62da7c582fa36ba6805f.html b/classnlohmann_1_1basic__json_afd4b7d7bcadc62da7c582fa36ba6805f.html index fcccdf4e1..1bc5bb826 100644 --- a/classnlohmann_1_1basic__json_afd4b7d7bcadc62da7c582fa36ba6805f.html +++ b/classnlohmann_1_1basic__json_afd4b7d7bcadc62da7c582fa36ba6805f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    Returns
    string containing the serialization of the JSON value
    Complexity
    Linear.
    -
    Example
    The following example shows the effect of different indent parameters to the result of the serialization.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // call dump()
    12  std::cout << j_object.dump() << "\n\n";
    13  std::cout << j_object.dump(-1) << "\n\n";
    14  std::cout << j_object.dump(0) << "\n\n";
    15  std::cout << j_object.dump(4) << "\n\n";
    16  std::cout << j_array.dump() << "\n\n";
    17  std::cout << j_array.dump(-1) << "\n\n";
    18  std::cout << j_array.dump(0) << "\n\n";
    19  std::cout << j_array.dump(4) << "\n\n";
    20 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following example shows the effect of different indent parameters to the result of the serialization.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_object = {{"one", 1}, {"two", 2}};
    9  json j_array = {1, 2, 4, 8, 16};
    10 
    11  // call dump()
    12  std::cout << j_object.dump() << "\n\n";
    13  std::cout << j_object.dump(-1) << "\n\n";
    14  std::cout << j_object.dump(0) << "\n\n";
    15  std::cout << j_object.dump(4) << "\n\n";
    16  std::cout << j_array.dump() << "\n\n";
    17  std::cout << j_array.dump(-1) << "\n\n";
    18  std::cout << j_array.dump(0) << "\n\n";
    19  std::cout << j_array.dump(4) << "\n\n";
    20 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {"one":1,"two":2}
     
     {"one":1,"two":2}
    @@ -318,7 +318,7 @@ template<template< typename U, typename V, typename... Args > class Obj
     
    diff --git a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html index d2d13d29b..bbf602358 100644 --- a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html +++ b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -310,7 +310,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 json = nlohmann::json;
    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:10545
    +
    Example
    The example below shows how JSON values are created from initializer lists.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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:10713
    Output (play with this example online):
    {}
     {"one":1,"two":2}
     [1,2,3,4]
    @@ -332,7 +332,7 @@ initializer list"
     
    diff --git a/classnlohmann_1_1basic__json_aff9d131320db407da31304fb2b5cb7a5.html b/classnlohmann_1_1basic__json_aff9d131320db407da31304fb2b5cb7a5.html index dcdd97a8f..ec832d52e 100644 --- a/classnlohmann_1_1basic__json_aff9d131320db407da31304fb2b5cb7a5.html +++ b/classnlohmann_1_1basic__json_aff9d131320db407da31304fb2b5cb7a5.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -278,7 +278,7 @@ not found"
    Complexity
    Linear in the size of the JSON value and the length of the JSON patch. As usually only a fraction of the JSON value is affected by the patch, the complexity can usually be neglected.
    -
    Example
    The following code shows how a JSON patch is applied to a value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the original document
    8  json doc = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the patch
    16  json patch = R"(
    17  [
    18  { "op": "replace", "path": "/baz", "value": "boo" },
    19  { "op": "add", "path": "/hello", "value": ["world"] },
    20  { "op": "remove", "path": "/foo"}
    21  ]
    22  )"_json;
    23 
    24  // apply the patch
    25  json patched_doc = doc.patch(patch);
    26 
    27  // output original and patched document
    28  std::cout << std::setw(4) << doc << "\n\n"
    29  << std::setw(4) << patched_doc << std::endl;
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The following code shows how a JSON patch is applied to a value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the original document
    8  json doc = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the patch
    16  json patch = R"(
    17  [
    18  { "op": "replace", "path": "/baz", "value": "boo" },
    19  { "op": "add", "path": "/hello", "value": ["world"] },
    20  { "op": "remove", "path": "/foo"}
    21  ]
    22  )"_json;
    23 
    24  // apply the patch
    25  json patched_doc = doc.patch(patch);
    26 
    27  // output original and patched document
    28  std::cout << std::setw(4) << doc << "\n\n"
    29  << std::setw(4) << patched_doc << std::endl;
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    {
         "baz": "qux",
         "foo": "bar"
    @@ -298,7 +298,7 @@ not found" 
     RFC 6901 (JSON Pointer)
    Since
    version 2.0.0
    -

    Definition at line 10104 of file json.hpp.

    +

    Definition at line 10272 of file json.hpp.

    @@ -308,7 +308,7 @@ not found" diff --git a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html index 833bf5ea5..6f2ccb27b 100644 --- a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html +++ b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -269,7 +269,7 @@ template<template< typename U, typename V, typename... Args > class Obj
    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 json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10545
    +
    Example
    The example shows how find() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    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 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10713
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
    @@ -286,7 +286,7 @@ value at key "two": 2
     
    diff --git a/deprecated.html b/deprecated.html index 1f7dd5aaa..2ddfe91bf 100644 --- a/deprecated.html +++ b/deprecated.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -71,7 +71,7 @@ $(function() { diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 8c736d6e8..00de41e37 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -77,7 +77,7 @@ Files diff --git a/form_0.png b/form_0.png index 6f96e0da5..2ce1d5081 100644 Binary files a/form_0.png and b/form_0.png differ diff --git a/functions.html b/functions.html index c7d7bb43b..3aeb4f1c8 100644 --- a/functions.html +++ b/functions.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -79,7 +79,7 @@ $(function() { diff --git a/functions_0x7e.html b/functions_0x7e.html index 0d15da95d..b61b88fbb 100644 --- a/functions_0x7e.html +++ b/functions_0x7e.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -70,7 +70,7 @@ $(function() { diff --git a/functions_b.html b/functions_b.html index 69f76be9f..04521952f 100644 --- a/functions_b.html +++ b/functions_b.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -85,7 +85,7 @@ $(function() { diff --git a/functions_c.html b/functions_c.html index d6ba3e461..7e8436b31 100644 --- a/functions_c.html +++ b/functions_c.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -97,7 +97,7 @@ $(function() { diff --git a/functions_d.html b/functions_d.html index 8d97dfa30..840f32a27 100644 --- a/functions_d.html +++ b/functions_d.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -77,7 +77,7 @@ $(function() { diff --git a/functions_e.html b/functions_e.html index 2bc3b3942..24cd9b5e6 100644 --- a/functions_e.html +++ b/functions_e.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -76,7 +76,7 @@ $(function() { diff --git a/functions_enum.html b/functions_enum.html index c9a0c86d4..181b13245 100644 --- a/functions_enum.html +++ b/functions_enum.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -71,7 +71,7 @@ $(function() { diff --git a/functions_f.html b/functions_f.html index 0eafe148d..5bafdb761 100644 --- a/functions_f.html +++ b/functions_f.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -76,7 +76,7 @@ $(function() { diff --git a/functions_func.html b/functions_func.html index fc621b350..a0052118f 100644 --- a/functions_func.html +++ b/functions_func.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -390,7 +390,7 @@ $(function() { diff --git a/functions_g.html b/functions_g.html index c1672ace5..339964157 100644 --- a/functions_g.html +++ b/functions_g.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -79,7 +79,7 @@ $(function() { diff --git a/functions_i.html b/functions_i.html index d6fbc0424..8a056ddb7 100644 --- a/functions_i.html +++ b/functions_i.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -115,7 +115,7 @@ $(function() { diff --git a/functions_j.html b/functions_j.html index cd0bea87c..acfc54f1f 100644 --- a/functions_j.html +++ b/functions_j.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -73,7 +73,7 @@ $(function() { diff --git a/functions_k.html b/functions_k.html index 5e191a84b..10bfe7cc3 100644 --- a/functions_k.html +++ b/functions_k.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -71,7 +71,7 @@ $(function() { diff --git a/functions_m.html b/functions_m.html index d630719ac..44b6445b5 100644 --- a/functions_m.html +++ b/functions_m.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -70,7 +70,7 @@ $(function() { diff --git a/functions_n.html b/functions_n.html index a5008a189..82237d510 100644 --- a/functions_n.html +++ b/functions_n.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -76,7 +76,7 @@ $(function() { diff --git a/functions_o.html b/functions_o.html index 7506760ff..7e07f4788 100644 --- a/functions_o.html +++ b/functions_o.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -164,7 +164,7 @@ $(function() { diff --git a/functions_p.html b/functions_p.html index 68b413484..5589f308c 100644 --- a/functions_p.html +++ b/functions_p.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -87,7 +87,7 @@ $(function() { diff --git a/functions_r.html b/functions_r.html index 9817dc1af..80c957580 100644 --- a/functions_r.html +++ b/functions_r.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -82,7 +82,7 @@ $(function() { diff --git a/functions_rela.html b/functions_rela.html index 13eea3881..52ab6860b 100644 --- a/functions_rela.html +++ b/functions_rela.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -93,7 +93,7 @@ $(function() { diff --git a/functions_s.html b/functions_s.html index 3c01dee6e..2ce2a9175 100644 --- a/functions_s.html +++ b/functions_s.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -79,7 +79,7 @@ $(function() { diff --git a/functions_t.html b/functions_t.html index b99214e14..28b53b295 100644 --- a/functions_t.html +++ b/functions_t.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -73,7 +73,7 @@ $(function() { diff --git a/functions_type.html b/functions_type.html index c119bd7b3..c41c48e79 100644 --- a/functions_type.html +++ b/functions_type.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -133,7 +133,7 @@ $(function() { diff --git a/functions_u.html b/functions_u.html index c53ecd424..770c0a0ee 100644 --- a/functions_u.html +++ b/functions_u.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -70,7 +70,7 @@ $(function() { diff --git a/functions_v.html b/functions_v.html index 7e768eaef..30846960a 100644 --- a/functions_v.html +++ b/functions_v.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -80,7 +80,7 @@ $(function() { diff --git a/graph_legend.html b/graph_legend.html index 56875b47d..54fb7a9f6 100644 --- a/graph_legend.html +++ b/graph_legend.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -93,7 +93,7 @@ A yellow dashed arrow denotes a relation between a template instance and the tem diff --git a/hierarchy.html b/hierarchy.html index d8c40b8ae..e8dbcf482 100644 --- a/hierarchy.html +++ b/hierarchy.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -79,7 +79,7 @@ $(function() { diff --git a/index.html b/index.html index d423b6f5d..df9ed7376 100644 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -160,11 +160,11 @@ access at
    Copyright
    Copyright © 2013-2016 Niels Lohmann. The code is licensed under the MIT License.
    Author
    Niels Lohmann
    See also
    https://github.com/nlohmann/json to download the source code
    -
    Version
    2.0.6
    +
    Version
    2.0.7
    diff --git a/index_8md_source.html b/index_8md_source.html index c3ea66dc0..15d24ffbd 100644 --- a/index_8md_source.html +++ b/index_8md_source.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -64,10 +64,10 @@ $(function() {
    index.md
    -
    1 # JSON for Modern C++
    2 
    3 These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.
    4 
    5 # Contents
    6 
    7 - @link nlohmann::basic_json `basic_json` class @endlink
    8 - [Functions](functions_func.html)
    9  - object inspection
    10  - @link nlohmann::basic_json::dump dump @endlink -- value serialization
    11  - @link nlohmann::basic_json::type type @endlink -- type of the value
    12  - @link nlohmann::basic_json::is_primitive is_primitive @endlink,
    13  @link nlohmann::basic_json::is_structured is_structured @endlink,
    14  @link nlohmann::basic_json::is_null is_null @endlink,
    15  @link nlohmann::basic_json::is_boolean is_boolean @endlink,
    16  @link nlohmann::basic_json::is_number is_number @endlink,
    17  @link nlohmann::basic_json::is_number_integer is_number_integer @endlink,
    18  @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink,
    19  @link nlohmann::basic_json::is_number_float is_number_float @endlink,
    20  @link nlohmann::basic_json::is_object is_object @endlink,
    21  @link nlohmann::basic_json::is_array is_array @endlink,
    22  @link nlohmann::basic_json::is_string is_string @endlink,
    23  @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
    24  - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
    25  - value access
    26  - @link nlohmann::basic_json::get get @endlink -- get a value
    27  - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
    28  - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
    29  - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
    30  - lexicographical comparison operators
    31  - serialization
    32  - deserialization
    33 - Types
    34  - @link nlohmann::basic_json::array_t arrays @endlink
    35  - @link nlohmann::basic_json::object_t objects @endlink
    36  - @link nlohmann::basic_json::string_t strings @endlink
    37  - @link nlohmann::basic_json::boolean_t booleans @endlink
    38  - numbers
    39  - @link nlohmann::basic_json::number_integer_t signed integers @endlink
    40  - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
    41  - @link nlohmann::basic_json::number_float_t floating-point @endlink
    42 
    43 # Container function overview
    44 
    45 The container functions known from STL have been extended to support the different value types from JSON. However, not all functions can be applied to all value types. Note that the signature of some functions differ between the types; for instance, `at` may be called with either a string to address a key in an object or with an integer to address a value in an array.
    46 
    47 <table>
    48  <tr>
    49  <th rowspan="2">group</td>
    50  <th rowspan="2">function</td>
    51  <th colspan="6">JSON value type</th>
    52  </tr>
    53  <tr>
    54  <th>object</th>
    55  <th>array</th>
    56  <th>string</th>
    57  <th>number</th>
    58  <th>boolean</th>
    59  <th>null</th>
    60  </tr>
    61  <tr>
    62  <td rowspan="8">iterators</td>
    63  <td>`begin`</td>
    64  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    65  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    66  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    67  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    68  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    69  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink (returns `end()`)</td>
    70  </tr>
    71  <tr>
    72  <td>`cbegin`</td>
    73  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    74  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    75  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    76  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    77  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    78  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink (returns `cend()`)</td>
    79  </tr>
    80  <tr>
    81  <td>`end`</td>
    82  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    83  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    84  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    85  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    86  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    87  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    88  </tr>
    89  <tr>
    90  <td>`cend`</td>
    91  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    92  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    93  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    94  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    95  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    96  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    97  </tr>
    98  <tr>
    99  <td>`rbegin`</td>
    100  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    101  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    102  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    103  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    104  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    105  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    106  </tr>
    107  <tr>
    108  <td>`crbegin`</td>
    109  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    110  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    111  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    112  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    113  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    114  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    115  </tr>
    116  <tr>
    117  <td>`rend`</td>
    118  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    119  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    120  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    121  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    122  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    123  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    124  </tr>
    125  <tr>
    126  <td>`crend`</td>
    127  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    128  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    129  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    130  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    131  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    132  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    133  </tr>
    134  <tr>
    135  <td rowspan="4">element<br>access</td>
    136  <td>`at`</td>
    137  <td class="ok_green">@link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink</td>
    138  <td class="ok_green">@link nlohmann::basic_json::at(size_type) `at` @endlink</td>
    139  <td class="nok_throws">throws `std::domain_error`</td>
    140  <td class="nok_throws">throws `std::domain_error`</td>
    141  <td class="nok_throws">throws `std::domain_error`</td>
    142  <td class="nok_throws">throws `std::domain_error`</td>
    143  </tr>
    144  <tr>
    145  <td>`operator[]`</td>
    146  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type &key) `operator[]` @endlink</td>
    147  <td class="ok_green">@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink</td>
    148  <td class="nok_throws">throws `std::domain_error`</td>
    149  <td class="nok_throws">throws `std::domain_error`</td>
    150  <td class="nok_throws">throws `std::domain_error`</td>
    151  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type & key) `operator[]` @endlink (creates object)<br>@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink (creates array)</td>
    152  </tr>
    153  <tr>
    154  <td>`front`</td>
    155  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    156  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    157  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    158  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    159  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    160  <td class="nok_throws">throws `std::out_of_range`</td>
    161  </tr>
    162  <tr>
    163  <td>`back`</td>
    164  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    165  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    166  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    167  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    168  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    169  <td class="nok_throws">throws `std::out_of_range`</td>
    170  </tr>
    171  <tr>
    172  <td rowspan="3">capacity</td>
    173  <td>`empty`</td>
    174  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    175  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    176  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    177  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    178  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    179  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `true`)</td>
    180  </tr>
    181  <tr>
    182  <td>`size`</td>
    183  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    184  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    185  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    186  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    187  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    188  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `0`)</td>
    189  </tr>
    190  <tr>
    191  <td>`max_size_`</td>
    192  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    193  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    194  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    195  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    196  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    197  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `0`)</td>
    198  </tr>
    199  <tr>
    200  <td rowspan="5">modifiers</td>
    201  <td>`clear`</td>
    202  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    203  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    204  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    205  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    206  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    207  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    208  </tr>
    209  <tr>
    210  <td>`insert`</td>
    211  <td class="nok_throws">throws `std::domain_error`</td>
    212  <td class="ok_green">@link nlohmann::basic_json::insert `insert` @endlink</td>
    213  <td class="nok_throws">throws `std::domain_error`</td>
    214  <td class="nok_throws">throws `std::domain_error`</td>
    215  <td class="nok_throws">throws `std::domain_error`</td>
    216  <td class="nok_throws">throws `std::domain_error`</td>
    217  </tr>
    218  <tr>
    219  <td>`erase`</td>
    220  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    221  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    222  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    223  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    224  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    225  <td class="nok_throws">throws</td>
    226  </tr>
    227  <tr>
    228  <td>`push_back`</td>
    229  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink</td>
    230  <td class="ok_green">@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink</td>
    231  <td class="nok_throws">throws `std::domain_error`</td>
    232  <td class="nok_throws">throws `std::domain_error`</td>
    233  <td class="nok_throws">throws `std::domain_error`</td>
    234  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink (creates object)<br>@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink (creates array)</td>
    235  </tr>
    236  <tr>
    237  <td>`swap`</td>
    238  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    239  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    240  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    241  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    242  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    243  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    244  </tr>
    245  <tr>
    246  <td rowspan="2">lookup</td>
    247  <td>`find`</td>
    248  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    249  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink</td>
    250  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    251  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    252  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    253  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    254  </tr>
    255  <tr>
    256  <td>`count`</td>
    257  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    258  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink</td>
    259  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    260  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    261  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    262  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    263  </tr>
    264 </table>
    265 
    266 @copyright Copyright &copy; 2013-2016 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
    267 
    268 @author [Niels Lohmann](http://nlohmann.me)
    269 @see https://github.com/nlohmann/json to download the source code
    270 
    271 @version 2.0.6
    +
    1 # JSON for Modern C++
    2 
    3 These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.
    4 
    5 # Contents
    6 
    7 - @link nlohmann::basic_json `basic_json` class @endlink
    8 - [Functions](functions_func.html)
    9  - object inspection
    10  - @link nlohmann::basic_json::dump dump @endlink -- value serialization
    11  - @link nlohmann::basic_json::type type @endlink -- type of the value
    12  - @link nlohmann::basic_json::is_primitive is_primitive @endlink,
    13  @link nlohmann::basic_json::is_structured is_structured @endlink,
    14  @link nlohmann::basic_json::is_null is_null @endlink,
    15  @link nlohmann::basic_json::is_boolean is_boolean @endlink,
    16  @link nlohmann::basic_json::is_number is_number @endlink,
    17  @link nlohmann::basic_json::is_number_integer is_number_integer @endlink,
    18  @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink,
    19  @link nlohmann::basic_json::is_number_float is_number_float @endlink,
    20  @link nlohmann::basic_json::is_object is_object @endlink,
    21  @link nlohmann::basic_json::is_array is_array @endlink,
    22  @link nlohmann::basic_json::is_string is_string @endlink,
    23  @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
    24  - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
    25  - value access
    26  - @link nlohmann::basic_json::get get @endlink -- get a value
    27  - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
    28  - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
    29  - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
    30  - lexicographical comparison operators
    31  - serialization
    32  - deserialization
    33 - Types
    34  - @link nlohmann::basic_json::array_t arrays @endlink
    35  - @link nlohmann::basic_json::object_t objects @endlink
    36  - @link nlohmann::basic_json::string_t strings @endlink
    37  - @link nlohmann::basic_json::boolean_t booleans @endlink
    38  - numbers
    39  - @link nlohmann::basic_json::number_integer_t signed integers @endlink
    40  - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
    41  - @link nlohmann::basic_json::number_float_t floating-point @endlink
    42 
    43 # Container function overview
    44 
    45 The container functions known from STL have been extended to support the different value types from JSON. However, not all functions can be applied to all value types. Note that the signature of some functions differ between the types; for instance, `at` may be called with either a string to address a key in an object or with an integer to address a value in an array.
    46 
    47 <table>
    48  <tr>
    49  <th rowspan="2">group</td>
    50  <th rowspan="2">function</td>
    51  <th colspan="6">JSON value type</th>
    52  </tr>
    53  <tr>
    54  <th>object</th>
    55  <th>array</th>
    56  <th>string</th>
    57  <th>number</th>
    58  <th>boolean</th>
    59  <th>null</th>
    60  </tr>
    61  <tr>
    62  <td rowspan="8">iterators</td>
    63  <td>`begin`</td>
    64  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    65  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    66  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    67  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    68  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    69  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink (returns `end()`)</td>
    70  </tr>
    71  <tr>
    72  <td>`cbegin`</td>
    73  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    74  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    75  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    76  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    77  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    78  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink (returns `cend()`)</td>
    79  </tr>
    80  <tr>
    81  <td>`end`</td>
    82  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    83  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    84  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    85  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    86  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    87  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    88  </tr>
    89  <tr>
    90  <td>`cend`</td>
    91  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    92  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    93  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    94  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    95  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    96  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    97  </tr>
    98  <tr>
    99  <td>`rbegin`</td>
    100  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    101  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    102  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    103  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    104  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    105  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    106  </tr>
    107  <tr>
    108  <td>`crbegin`</td>
    109  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    110  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    111  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    112  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    113  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    114  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    115  </tr>
    116  <tr>
    117  <td>`rend`</td>
    118  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    119  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    120  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    121  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    122  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    123  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    124  </tr>
    125  <tr>
    126  <td>`crend`</td>
    127  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    128  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    129  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    130  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    131  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    132  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    133  </tr>
    134  <tr>
    135  <td rowspan="4">element<br>access</td>
    136  <td>`at`</td>
    137  <td class="ok_green">@link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink</td>
    138  <td class="ok_green">@link nlohmann::basic_json::at(size_type) `at` @endlink</td>
    139  <td class="nok_throws">throws `std::domain_error`</td>
    140  <td class="nok_throws">throws `std::domain_error`</td>
    141  <td class="nok_throws">throws `std::domain_error`</td>
    142  <td class="nok_throws">throws `std::domain_error`</td>
    143  </tr>
    144  <tr>
    145  <td>`operator[]`</td>
    146  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type &key) `operator[]` @endlink</td>
    147  <td class="ok_green">@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink</td>
    148  <td class="nok_throws">throws `std::domain_error`</td>
    149  <td class="nok_throws">throws `std::domain_error`</td>
    150  <td class="nok_throws">throws `std::domain_error`</td>
    151  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type & key) `operator[]` @endlink (creates object)<br>@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink (creates array)</td>
    152  </tr>
    153  <tr>
    154  <td>`front`</td>
    155  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    156  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    157  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    158  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    159  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    160  <td class="nok_throws">throws `std::out_of_range`</td>
    161  </tr>
    162  <tr>
    163  <td>`back`</td>
    164  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    165  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    166  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    167  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    168  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    169  <td class="nok_throws">throws `std::out_of_range`</td>
    170  </tr>
    171  <tr>
    172  <td rowspan="3">capacity</td>
    173  <td>`empty`</td>
    174  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    175  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    176  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    177  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    178  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    179  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `true`)</td>
    180  </tr>
    181  <tr>
    182  <td>`size`</td>
    183  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    184  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    185  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    186  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    187  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    188  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `0`)</td>
    189  </tr>
    190  <tr>
    191  <td>`max_size_`</td>
    192  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    193  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    194  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    195  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    196  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    197  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `0`)</td>
    198  </tr>
    199  <tr>
    200  <td rowspan="5">modifiers</td>
    201  <td>`clear`</td>
    202  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    203  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    204  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    205  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    206  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    207  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    208  </tr>
    209  <tr>
    210  <td>`insert`</td>
    211  <td class="nok_throws">throws `std::domain_error`</td>
    212  <td class="ok_green">@link nlohmann::basic_json::insert `insert` @endlink</td>
    213  <td class="nok_throws">throws `std::domain_error`</td>
    214  <td class="nok_throws">throws `std::domain_error`</td>
    215  <td class="nok_throws">throws `std::domain_error`</td>
    216  <td class="nok_throws">throws `std::domain_error`</td>
    217  </tr>
    218  <tr>
    219  <td>`erase`</td>
    220  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    221  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    222  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    223  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    224  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    225  <td class="nok_throws">throws</td>
    226  </tr>
    227  <tr>
    228  <td>`push_back`</td>
    229  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink</td>
    230  <td class="ok_green">@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink</td>
    231  <td class="nok_throws">throws `std::domain_error`</td>
    232  <td class="nok_throws">throws `std::domain_error`</td>
    233  <td class="nok_throws">throws `std::domain_error`</td>
    234  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink (creates object)<br>@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink (creates array)</td>
    235  </tr>
    236  <tr>
    237  <td>`swap`</td>
    238  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    239  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    240  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    241  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    242  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    243  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    244  </tr>
    245  <tr>
    246  <td rowspan="2">lookup</td>
    247  <td>`find`</td>
    248  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    249  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink</td>
    250  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    251  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    252  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    253  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    254  </tr>
    255  <tr>
    256  <td>`count`</td>
    257  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    258  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink</td>
    259  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    260  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    261  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    262  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    263  </tr>
    264 </table>
    265 
    266 @copyright Copyright &copy; 2013-2016 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
    267 
    268 @author [Niels Lohmann](http://nlohmann.me)
    269 @see https://github.com/nlohmann/json to download the source code
    270 
    271 @version 2.0.7
    diff --git a/json_8hpp_source.html b/json_8hpp_source.html index 80daaa061..b5b4ddba2 100644 --- a/json_8hpp_source.html +++ b/json_8hpp_source.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -68,7 +68,7 @@ $(function() {
    json.hpp
    -
    1 /*
    2  __ _____ _____ _____
    3  __| | __| | | | JSON for Modern C++
    4 | | |__ | | | | | | version 2.0.6
    5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
    6 
    7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
    8 Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
    9 
    10 Permission is hereby granted, free of charge, to any person obtaining a copy
    11 of this software and associated documentation files (the "Software"), to deal
    12 in the Software without restriction, including without limitation the rights
    13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    14 copies of the Software, and to permit persons to whom the Software is
    15 furnished to do so, subject to the following conditions:
    16 
    17 The above copyright notice and this permission notice shall be included in all
    18 copies or substantial portions of the Software.
    19 
    20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    26 SOFTWARE.
    27 */
    28 
    29 #ifndef NLOHMANN_JSON_HPP
    30 #define NLOHMANN_JSON_HPP
    31 
    32 #include <algorithm>
    33 #include <array>
    34 #include <cassert>
    35 #include <cctype>
    36 #include <ciso646>
    37 #include <cmath>
    38 #include <cstddef>
    39 #include <cstdint>
    40 #include <cstdlib>
    41 #include <cstring>
    42 #include <functional>
    43 #include <initializer_list>
    44 #include <iomanip>
    45 #include <iostream>
    46 #include <iterator>
    47 #include <limits>
    48 #include <locale>
    49 #include <map>
    50 #include <memory>
    51 #include <numeric>
    52 #include <sstream>
    53 #include <stdexcept>
    54 #include <string>
    55 #include <type_traits>
    56 #include <utility>
    57 #include <vector>
    58 
    59 // exclude unsupported compilers
    60 #if defined(__clang__)
    61  #define CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
    62  #if CLANG_VERSION < 30400
    63  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
    64  #endif
    65 #elif defined(__GNUC__)
    66  #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
    67  #if GCC_VERSION < 40900
    68  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
    69  #endif
    70 #endif
    71 
    72 // disable float-equal warnings on GCC/clang
    73 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    74  #pragma GCC diagnostic push
    75  #pragma GCC diagnostic ignored "-Wfloat-equal"
    76 #endif
    77 
    78 // allow for portable deprecation warnings
    79 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    80  #define JSON_DEPRECATED __attribute__((deprecated))
    81 #elif defined(_MSC_VER)
    82  #define JSON_DEPRECATED __declspec(deprecated)
    83 #else
    84  #define JSON_DEPRECATED
    85 #endif
    86 
    92 namespace nlohmann
    93 {
    94 
    95 
    100 namespace
    101 {
    112 template<typename T>
    113 struct has_mapped_type
    114 {
    115  private:
    116  template <typename U, typename = typename U::mapped_type>
    117  static int detect(U&&);
    118 
    119  static void detect(...);
    120  public:
    121  static constexpr bool value =
    122  std::is_integral<decltype(detect(std::declval<T>()))>::value;
    123 };
    124 
    137 struct DecimalSeparator : std::numpunct<char>
    138 {
    139  char do_decimal_point() const
    140  {
    141  return '.';
    142  }
    143 };
    144 
    145 }
    146 
    225 template <
    226  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    227  template<typename U, typename... Args> class ArrayType = std::vector,
    228  class StringType = std::string,
    229  class BooleanType = bool,
    230  class NumberIntegerType = std::int64_t,
    231  class NumberUnsignedType = std::uint64_t,
    232  class NumberFloatType = double,
    233  template<typename U> class AllocatorType = std::allocator
    234  >
    236 {
    237  private:
    239  using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
    240  BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
    241  AllocatorType>;
    242 
    243  public:
    244  // forward declarations
    245  template<typename Base> class json_reverse_iterator;
    246  class json_pointer;
    247 
    249  // container types //
    251 
    256 
    259 
    263  using const_reference = const value_type&;
    264 
    266  using difference_type = std::ptrdiff_t;
    268  using size_type = std::size_t;
    269 
    271  using allocator_type = AllocatorType<basic_json>;
    272 
    274  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    276  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    277 
    279  class iterator;
    281  class const_iterator;
    286 
    288 
    289 
    294  {
    295  return allocator_type();
    296  }
    297 
    298 
    300  // JSON value data types //
    302 
    307 
    391  using object_t = ObjectType<StringType,
    392  basic_json,
    393  std::less<StringType>,
    394  AllocatorType<std::pair<const StringType,
    395  basic_json>>>;
    396 
    441  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    442 
    488  using string_t = StringType;
    489 
    514  using boolean_t = BooleanType;
    515 
    586  using number_integer_t = NumberIntegerType;
    587 
    657  using number_unsigned_t = NumberUnsignedType;
    658 
    725  using number_float_t = NumberFloatType;
    726 
    728 
    729 
    731  // JSON type enumeration //
    733 
    756  enum class value_t : uint8_t
    757  {
    758  null,
    759  object,
    760  array,
    761  string,
    762  boolean,
    763  number_integer,
    764  number_unsigned,
    765  number_float,
    766  discarded
    767  };
    768 
    769 
    770  private:
    771 
    773  template<typename T, typename... Args>
    774  static T* create(Args&& ... args)
    775  {
    776  AllocatorType<T> alloc;
    777  auto deleter = [&](T * object)
    778  {
    779  alloc.deallocate(object, 1);
    780  };
    781  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    782  alloc.construct(object.get(), std::forward<Args>(args)...);
    783  assert(object.get() != nullptr);
    784  return object.release();
    785  }
    786 
    788  // JSON value storage //
    790 
    815  union json_value
    816  {
    818  object_t* object;
    820  array_t* array;
    822  string_t* string;
    824  boolean_t boolean;
    826  number_integer_t number_integer;
    828  number_unsigned_t number_unsigned;
    830  number_float_t number_float;
    831 
    833  json_value() = default;
    835  json_value(boolean_t v) noexcept : boolean(v) {}
    837  json_value(number_integer_t v) noexcept : number_integer(v) {}
    839  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    841  json_value(number_float_t v) noexcept : number_float(v) {}
    843  json_value(value_t t)
    844  {
    845  switch (t)
    846  {
    847  case value_t::object:
    848  {
    849  object = create<object_t>();
    850  break;
    851  }
    852 
    853  case value_t::array:
    854  {
    855  array = create<array_t>();
    856  break;
    857  }
    858 
    859  case value_t::string:
    860  {
    861  string = create<string_t>("");
    862  break;
    863  }
    864 
    865  case value_t::boolean:
    866  {
    867  boolean = boolean_t(false);
    868  break;
    869  }
    870 
    871  case value_t::number_integer:
    872  {
    873  number_integer = number_integer_t(0);
    874  break;
    875  }
    876 
    877  case value_t::number_unsigned:
    878  {
    879  number_unsigned = number_unsigned_t(0);
    880  break;
    881  }
    882 
    883  case value_t::number_float:
    884  {
    885  number_float = number_float_t(0.0);
    886  break;
    887  }
    888 
    889  default:
    890  {
    891  break;
    892  }
    893  }
    894  }
    895 
    897  json_value(const string_t& value)
    898  {
    899  string = create<string_t>(value);
    900  }
    901 
    903  json_value(const object_t& value)
    904  {
    905  object = create<object_t>(value);
    906  }
    907 
    909  json_value(const array_t& value)
    910  {
    911  array = create<array_t>(value);
    912  }
    913  };
    914 
    924  void assert_invariant() const
    925  {
    926  assert(m_type != value_t::object or m_value.object != nullptr);
    927  assert(m_type != value_t::array or m_value.array != nullptr);
    928  assert(m_type != value_t::string or m_value.string != nullptr);
    929  }
    930 
    931  public:
    933  // JSON parser callback //
    935 
    946  enum class parse_event_t : uint8_t
    947  {
    949  object_start,
    951  object_end,
    953  array_start,
    955  array_end,
    957  key,
    959  value
    960  };
    961 
    1014  using parser_callback_t = std::function<bool(int depth,
    1015  parse_event_t event,
    1016  basic_json& parsed)>;
    1017 
    1018 
    1020  // constructors //
    1022 
    1027 
    1068  : m_type(value_type), m_value(value_type)
    1069  {
    1070  assert_invariant();
    1071  }
    1072 
    1091  basic_json(std::nullptr_t = nullptr) noexcept
    1092  : basic_json(value_t::null)
    1093  {
    1094  assert_invariant();
    1095  }
    1096 
    1116  basic_json(const object_t& val)
    1117  : m_type(value_t::object), m_value(val)
    1118  {
    1119  assert_invariant();
    1120  }
    1121 
    1148  template<class CompatibleObjectType, typename std::enable_if<
    1149  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1150  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type = 0>
    1151  basic_json(const CompatibleObjectType& val)
    1152  : m_type(value_t::object)
    1153  {
    1154  using std::begin;
    1155  using std::end;
    1156  m_value.object = create<object_t>(begin(val), end(val));
    1157  assert_invariant();
    1158  }
    1159 
    1179  basic_json(const array_t& val)
    1180  : m_type(value_t::array), m_value(val)
    1181  {
    1182  assert_invariant();
    1183  }
    1184 
    1211  template<class CompatibleArrayType, typename std::enable_if<
    1212  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1213  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1214  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1215  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1216  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1217  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1218  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type = 0>
    1219  basic_json(const CompatibleArrayType& val)
    1220  : m_type(value_t::array)
    1221  {
    1222  using std::begin;
    1223  using std::end;
    1224  m_value.array = create<array_t>(begin(val), end(val));
    1225  assert_invariant();
    1226  }
    1227 
    1249  basic_json(const string_t& val)
    1250  : m_type(value_t::string), m_value(val)
    1251  {
    1252  assert_invariant();
    1253  }
    1254 
    1275  basic_json(const typename string_t::value_type* val)
    1276  : basic_json(string_t(val))
    1277  {
    1278  assert_invariant();
    1279  }
    1280 
    1304  template<class CompatibleStringType, typename std::enable_if<
    1305  std::is_constructible<string_t, CompatibleStringType>::value, int>::type = 0>
    1306  basic_json(const CompatibleStringType& val)
    1307  : basic_json(string_t(val))
    1308  {
    1309  assert_invariant();
    1310  }
    1311 
    1326  basic_json(boolean_t val) noexcept
    1327  : m_type(value_t::boolean), m_value(val)
    1328  {
    1329  assert_invariant();
    1330  }
    1331 
    1355  template<typename T, typename std::enable_if<
    1356  not (std::is_same<T, int>::value) and
    1357  std::is_same<T, number_integer_t>::value, int>::type = 0>
    1358  basic_json(const number_integer_t val) noexcept
    1359  : m_type(value_t::number_integer), m_value(val)
    1360  {
    1361  assert_invariant();
    1362  }
    1363 
    1389  basic_json(const int val) noexcept
    1390  : m_type(value_t::number_integer),
    1391  m_value(static_cast<number_integer_t>(val))
    1392  {
    1393  assert_invariant();
    1394  }
    1395 
    1421  template<typename CompatibleNumberIntegerType, typename std::enable_if<
    1422  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1423  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1424  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1425  CompatibleNumberIntegerType>::type = 0>
    1426  basic_json(const CompatibleNumberIntegerType val) noexcept
    1427  : m_type(value_t::number_integer),
    1428  m_value(static_cast<number_integer_t>(val))
    1429  {
    1430  assert_invariant();
    1431  }
    1432 
    1450  template<typename T, typename std::enable_if<
    1451  not (std::is_same<T, int>::value) and
    1452  std::is_same<T, number_unsigned_t>::value, int>::type = 0>
    1453  basic_json(const number_unsigned_t val) noexcept
    1454  : m_type(value_t::number_unsigned), m_value(val)
    1455  {
    1456  assert_invariant();
    1457  }
    1458 
    1479  template<typename CompatibleNumberUnsignedType, typename std::enable_if <
    1480  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1481  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1482  not std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1483  CompatibleNumberUnsignedType>::type = 0>
    1484  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1485  : m_type(value_t::number_unsigned),
    1486  m_value(static_cast<number_unsigned_t>(val))
    1487  {
    1488  assert_invariant();
    1489  }
    1490 
    1515  basic_json(const number_float_t val) noexcept
    1516  : m_type(value_t::number_float), m_value(val)
    1517  {
    1518  // replace infinity and NAN by null
    1519  if (not std::isfinite(val))
    1520  {
    1521  m_type = value_t::null;
    1522  m_value = json_value();
    1523  }
    1524 
    1525  assert_invariant();
    1526  }
    1527 
    1559  template<typename CompatibleNumberFloatType, typename = typename std::enable_if<
    1560  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1561  std::is_floating_point<CompatibleNumberFloatType>::value>::type>
    1562  basic_json(const CompatibleNumberFloatType val) noexcept
    1563  : basic_json(number_float_t(val))
    1564  {
    1565  assert_invariant();
    1566  }
    1567 
    1637  basic_json(std::initializer_list<basic_json> init,
    1638  bool type_deduction = true,
    1639  value_t manual_type = value_t::array)
    1640  {
    1641  // check if each element is an array with two elements whose first
    1642  // element is a string
    1643  bool is_an_object = std::all_of(init.begin(), init.end(),
    1644  [](const basic_json & element)
    1645  {
    1646  return element.is_array() and element.size() == 2 and element[0].is_string();
    1647  });
    1648 
    1649  // adjust type if type deduction is not wanted
    1650  if (not type_deduction)
    1651  {
    1652  // if array is wanted, do not create an object though possible
    1653  if (manual_type == value_t::array)
    1654  {
    1655  is_an_object = false;
    1656  }
    1657 
    1658  // if object is wanted but impossible, throw an exception
    1659  if (manual_type == value_t::object and not is_an_object)
    1660  {
    1661  throw std::domain_error("cannot create object from initializer list");
    1662  }
    1663  }
    1664 
    1665  if (is_an_object)
    1666  {
    1667  // the initializer list is a list of pairs -> create object
    1668  m_type = value_t::object;
    1669  m_value = value_t::object;
    1670 
    1671  std::for_each(init.begin(), init.end(), [this](const basic_json & element)
    1672  {
    1673  m_value.object->emplace(*(element[0].m_value.string), element[1]);
    1674  });
    1675  }
    1676  else
    1677  {
    1678  // the initializer list describes an array -> create array
    1679  m_type = value_t::array;
    1680  m_value.array = create<array_t>(init);
    1681  }
    1682 
    1683  assert_invariant();
    1684  }
    1685 
    1720  static basic_json array(std::initializer_list<basic_json> init =
    1721  std::initializer_list<basic_json>())
    1722  {
    1723  return basic_json(init, false, value_t::array);
    1724  }
    1725 
    1760  static basic_json object(std::initializer_list<basic_json> init =
    1761  std::initializer_list<basic_json>())
    1762  {
    1763  return basic_json(init, false, value_t::object);
    1764  }
    1765 
    1785  : m_type(value_t::array)
    1786  {
    1787  m_value.array = create<array_t>(cnt, val);
    1788  assert_invariant();
    1789  }
    1790 
    1828  template<class InputIT, typename std::enable_if<
    1829  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1830  std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int>::type = 0>
    1831  basic_json(InputIT first, InputIT last)
    1832  {
    1833  assert(first.m_object != nullptr);
    1834  assert(last.m_object != nullptr);
    1835 
    1836  // make sure iterator fits the current value
    1837  if (first.m_object != last.m_object)
    1838  {
    1839  throw std::domain_error("iterators are not compatible");
    1840  }
    1841 
    1842  // copy type from first iterator
    1843  m_type = first.m_object->m_type;
    1844 
    1845  // check if iterator range is complete for primitive values
    1846  switch (m_type)
    1847  {
    1848  case value_t::boolean:
    1849  case value_t::number_float:
    1850  case value_t::number_integer:
    1851  case value_t::number_unsigned:
    1852  case value_t::string:
    1853  {
    1854  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1855  {
    1856  throw std::out_of_range("iterators out of range");
    1857  }
    1858  break;
    1859  }
    1860 
    1861  default:
    1862  {
    1863  break;
    1864  }
    1865  }
    1866 
    1867  switch (m_type)
    1868  {
    1869  case value_t::number_integer:
    1870  {
    1871  m_value.number_integer = first.m_object->m_value.number_integer;
    1872  break;
    1873  }
    1874 
    1875  case value_t::number_unsigned:
    1876  {
    1877  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1878  break;
    1879  }
    1880 
    1881  case value_t::number_float:
    1882  {
    1883  m_value.number_float = first.m_object->m_value.number_float;
    1884  break;
    1885  }
    1886 
    1887  case value_t::boolean:
    1888  {
    1889  m_value.boolean = first.m_object->m_value.boolean;
    1890  break;
    1891  }
    1892 
    1893  case value_t::string:
    1894  {
    1895  m_value = *first.m_object->m_value.string;
    1896  break;
    1897  }
    1898 
    1899  case value_t::object:
    1900  {
    1901  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1902  break;
    1903  }
    1904 
    1905  case value_t::array:
    1906  {
    1907  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1908  break;
    1909  }
    1910 
    1911  default:
    1912  {
    1913  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1914  }
    1915  }
    1916 
    1917  assert_invariant();
    1918  }
    1919 
    1948  JSON_DEPRECATED
    1949  explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr)
    1950  {
    1951  *this = parser(i, cb).parse();
    1952  assert_invariant();
    1953  }
    1954 
    1956  // other constructors and destructor //
    1958 
    1981  basic_json(const basic_json& other)
    1982  : m_type(other.m_type)
    1983  {
    1984  // check of passed value is valid
    1985  other.assert_invariant();
    1986 
    1987  switch (m_type)
    1988  {
    1989  case value_t::object:
    1990  {
    1991  m_value = *other.m_value.object;
    1992  break;
    1993  }
    1994 
    1995  case value_t::array:
    1996  {
    1997  m_value = *other.m_value.array;
    1998  break;
    1999  }
    2000 
    2001  case value_t::string:
    2002  {
    2003  m_value = *other.m_value.string;
    2004  break;
    2005  }
    2006 
    2007  case value_t::boolean:
    2008  {
    2009  m_value = other.m_value.boolean;
    2010  break;
    2011  }
    2012 
    2013  case value_t::number_integer:
    2014  {
    2015  m_value = other.m_value.number_integer;
    2016  break;
    2017  }
    2018 
    2019  case value_t::number_unsigned:
    2020  {
    2021  m_value = other.m_value.number_unsigned;
    2022  break;
    2023  }
    2024 
    2025  case value_t::number_float:
    2026  {
    2027  m_value = other.m_value.number_float;
    2028  break;
    2029  }
    2030 
    2031  default:
    2032  {
    2033  break;
    2034  }
    2035  }
    2036 
    2037  assert_invariant();
    2038  }
    2039 
    2058  basic_json(basic_json&& other) noexcept
    2059  : m_type(std::move(other.m_type)),
    2060  m_value(std::move(other.m_value))
    2061  {
    2062  // check that passed value is valid
    2063  other.assert_invariant();
    2064 
    2065  // invalidate payload
    2066  other.m_type = value_t::null;
    2067  other.m_value = {};
    2068 
    2069  assert_invariant();
    2070  }
    2071 
    2095  reference& operator=(basic_json other) noexcept (
    2096  std::is_nothrow_move_constructible<value_t>::value and
    2097  std::is_nothrow_move_assignable<value_t>::value and
    2098  std::is_nothrow_move_constructible<json_value>::value and
    2099  std::is_nothrow_move_assignable<json_value>::value
    2100  )
    2101  {
    2102  // check that passed value is valid
    2103  other.assert_invariant();
    2104 
    2105  using std::swap;
    2106  swap(m_type, other.m_type);
    2107  swap(m_value, other.m_value);
    2108 
    2109  assert_invariant();
    2110  return *this;
    2111  }
    2112 
    2129  {
    2130  assert_invariant();
    2131 
    2132  switch (m_type)
    2133  {
    2134  case value_t::object:
    2135  {
    2136  AllocatorType<object_t> alloc;
    2137  alloc.destroy(m_value.object);
    2138  alloc.deallocate(m_value.object, 1);
    2139  break;
    2140  }
    2141 
    2142  case value_t::array:
    2143  {
    2144  AllocatorType<array_t> alloc;
    2145  alloc.destroy(m_value.array);
    2146  alloc.deallocate(m_value.array, 1);
    2147  break;
    2148  }
    2149 
    2150  case value_t::string:
    2151  {
    2152  AllocatorType<string_t> alloc;
    2153  alloc.destroy(m_value.string);
    2154  alloc.deallocate(m_value.string, 1);
    2155  break;
    2156  }
    2157 
    2158  default:
    2159  {
    2160  // all other types need no specific destructor
    2161  break;
    2162  }
    2163  }
    2164  }
    2165 
    2167 
    2168  public:
    2170  // object inspection //
    2172 
    2176 
    2200  string_t dump(const int indent = -1) const
    2201  {
    2202  std::stringstream ss;
    2203  // fix locale problems
    2204  const static std::locale loc(std::locale(), new DecimalSeparator);
    2205  ss.imbue(loc);
    2206 
    2207  // 6, 15 or 16 digits of precision allows round-trip IEEE 754
    2208  // string->float->string, string->double->string or string->long
    2209  // double->string; to be safe, we read this value from
    2210  // std::numeric_limits<number_float_t>::digits10
    2211  ss.precision(std::numeric_limits<double>::digits10);
    2212 
    2213  if (indent >= 0)
    2214  {
    2215  dump(ss, true, static_cast<unsigned int>(indent));
    2216  }
    2217  else
    2218  {
    2219  dump(ss, false, 0);
    2220  }
    2221 
    2222  return ss.str();
    2223  }
    2224 
    2243  constexpr value_t type() const noexcept
    2244  {
    2245  return m_type;
    2246  }
    2247 
    2273  constexpr bool is_primitive() const noexcept
    2274  {
    2275  return is_null() or is_string() or is_boolean() or is_number();
    2276  }
    2277 
    2300  constexpr bool is_structured() const noexcept
    2301  {
    2302  return is_array() or is_object();
    2303  }
    2304 
    2322  constexpr bool is_null() const noexcept
    2323  {
    2324  return m_type == value_t::null;
    2325  }
    2326 
    2344  constexpr bool is_boolean() const noexcept
    2345  {
    2346  return m_type == value_t::boolean;
    2347  }
    2348 
    2374  constexpr bool is_number() const noexcept
    2375  {
    2376  return is_number_integer() or is_number_float();
    2377  }
    2378 
    2403  constexpr bool is_number_integer() const noexcept
    2404  {
    2405  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2406  }
    2407 
    2431  constexpr bool is_number_unsigned() const noexcept
    2432  {
    2433  return m_type == value_t::number_unsigned;
    2434  }
    2435 
    2459  constexpr bool is_number_float() const noexcept
    2460  {
    2461  return m_type == value_t::number_float;
    2462  }
    2463 
    2481  constexpr bool is_object() const noexcept
    2482  {
    2483  return m_type == value_t::object;
    2484  }
    2485 
    2503  constexpr bool is_array() const noexcept
    2504  {
    2505  return m_type == value_t::array;
    2506  }
    2507 
    2525  constexpr bool is_string() const noexcept
    2526  {
    2527  return m_type == value_t::string;
    2528  }
    2529 
    2552  constexpr bool is_discarded() const noexcept
    2553  {
    2554  return m_type == value_t::discarded;
    2555  }
    2556 
    2575  constexpr operator value_t() const noexcept
    2576  {
    2577  return m_type;
    2578  }
    2579 
    2581 
    2582  private:
    2584  // value access //
    2586 
    2588  template<class T, typename std::enable_if<
    2589  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2590  std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
    2591  T get_impl(T*) const
    2592  {
    2593  if (is_object())
    2594  {
    2595  return T(m_value.object->begin(), m_value.object->end());
    2596  }
    2597  else
    2598  {
    2599  throw std::domain_error("type must be object, but is " + type_name());
    2600  }
    2601  }
    2602 
    2604  object_t get_impl(object_t*) const
    2605  {
    2606  if (is_object())
    2607  {
    2608  return *(m_value.object);
    2609  }
    2610  else
    2611  {
    2612  throw std::domain_error("type must be object, but is " + type_name());
    2613  }
    2614  }
    2615 
    2617  template<class T, typename std::enable_if<
    2618  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2619  not std::is_same<basic_json_t, typename T::value_type>::value and
    2620  not std::is_arithmetic<T>::value and
    2621  not std::is_convertible<std::string, T>::value and
    2622  not has_mapped_type<T>::value, int>::type = 0>
    2623  T get_impl(T*) const
    2624  {
    2625  if (is_array())
    2626  {
    2627  T to_vector;
    2628  std::transform(m_value.array->begin(), m_value.array->end(),
    2629  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2630  {
    2631  return i.get<typename T::value_type>();
    2632  });
    2633  return to_vector;
    2634  }
    2635  else
    2636  {
    2637  throw std::domain_error("type must be array, but is " + type_name());
    2638  }
    2639  }
    2640 
    2642  template<class T, typename std::enable_if<
    2643  std::is_convertible<basic_json_t, T>::value and
    2644  not std::is_same<basic_json_t, T>::value, int>::type = 0>
    2645  std::vector<T> get_impl(std::vector<T>*) const
    2646  {
    2647  if (is_array())
    2648  {
    2649  std::vector<T> to_vector;
    2650  to_vector.reserve(m_value.array->size());
    2651  std::transform(m_value.array->begin(), m_value.array->end(),
    2652  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2653  {
    2654  return i.get<T>();
    2655  });
    2656  return to_vector;
    2657  }
    2658  else
    2659  {
    2660  throw std::domain_error("type must be array, but is " + type_name());
    2661  }
    2662  }
    2663 
    2665  template<class T, typename std::enable_if<
    2666  std::is_same<basic_json, typename T::value_type>::value and
    2667  not has_mapped_type<T>::value, int>::type = 0>
    2668  T get_impl(T*) const
    2669  {
    2670  if (is_array())
    2671  {
    2672  return T(m_value.array->begin(), m_value.array->end());
    2673  }
    2674  else
    2675  {
    2676  throw std::domain_error("type must be array, but is " + type_name());
    2677  }
    2678  }
    2679 
    2681  array_t get_impl(array_t*) const
    2682  {
    2683  if (is_array())
    2684  {
    2685  return *(m_value.array);
    2686  }
    2687  else
    2688  {
    2689  throw std::domain_error("type must be array, but is " + type_name());
    2690  }
    2691  }
    2692 
    2694  template<typename T, typename std::enable_if<
    2695  std::is_convertible<string_t, T>::value, int>::type = 0>
    2696  T get_impl(T*) const
    2697  {
    2698  if (is_string())
    2699  {
    2700  return *m_value.string;
    2701  }
    2702  else
    2703  {
    2704  throw std::domain_error("type must be string, but is " + type_name());
    2705  }
    2706  }
    2707 
    2709  template<typename T, typename std::enable_if<
    2710  std::is_arithmetic<T>::value, int>::type = 0>
    2711  T get_impl(T*) const
    2712  {
    2713  switch (m_type)
    2714  {
    2715  case value_t::number_integer:
    2716  {
    2717  return static_cast<T>(m_value.number_integer);
    2718  }
    2719 
    2720  case value_t::number_unsigned:
    2721  {
    2722  return static_cast<T>(m_value.number_unsigned);
    2723  }
    2724 
    2725  case value_t::number_float:
    2726  {
    2727  return static_cast<T>(m_value.number_float);
    2728  }
    2729 
    2730  default:
    2731  {
    2732  throw std::domain_error("type must be number, but is " + type_name());
    2733  }
    2734  }
    2735  }
    2736 
    2738  constexpr boolean_t get_impl(boolean_t*) const
    2739  {
    2740  return is_boolean()
    2741  ? m_value.boolean
    2742  : throw std::domain_error("type must be boolean, but is " + type_name());
    2743  }
    2744 
    2746  object_t* get_impl_ptr(object_t*) noexcept
    2747  {
    2748  return is_object() ? m_value.object : nullptr;
    2749  }
    2750 
    2752  constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
    2753  {
    2754  return is_object() ? m_value.object : nullptr;
    2755  }
    2756 
    2758  array_t* get_impl_ptr(array_t*) noexcept
    2759  {
    2760  return is_array() ? m_value.array : nullptr;
    2761  }
    2762 
    2764  constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
    2765  {
    2766  return is_array() ? m_value.array : nullptr;
    2767  }
    2768 
    2770  string_t* get_impl_ptr(string_t*) noexcept
    2771  {
    2772  return is_string() ? m_value.string : nullptr;
    2773  }
    2774 
    2776  constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
    2777  {
    2778  return is_string() ? m_value.string : nullptr;
    2779  }
    2780 
    2782  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2783  {
    2784  return is_boolean() ? &m_value.boolean : nullptr;
    2785  }
    2786 
    2788  constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2789  {
    2790  return is_boolean() ? &m_value.boolean : nullptr;
    2791  }
    2792 
    2794  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2795  {
    2796  return is_number_integer() ? &m_value.number_integer : nullptr;
    2797  }
    2798 
    2800  constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2801  {
    2802  return is_number_integer() ? &m_value.number_integer : nullptr;
    2803  }
    2804 
    2806  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2807  {
    2808  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2809  }
    2810 
    2812  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2813  {
    2814  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2815  }
    2816 
    2818  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2819  {
    2820  return is_number_float() ? &m_value.number_float : nullptr;
    2821  }
    2822 
    2824  constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2825  {
    2826  return is_number_float() ? &m_value.number_float : nullptr;
    2827  }
    2828 
    2840  template<typename ReferenceType, typename ThisType>
    2841  static ReferenceType get_ref_impl(ThisType& obj)
    2842  {
    2843  // helper type
    2844  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2845 
    2846  // delegate the call to get_ptr<>()
    2847  auto ptr = obj.template get_ptr<PointerType>();
    2848 
    2849  if (ptr != nullptr)
    2850  {
    2851  return *ptr;
    2852  }
    2853  else
    2854  {
    2855  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2856  obj.type_name());
    2857  }
    2858  }
    2859 
    2860  public:
    2861 
    2865 
    2899  template<typename ValueType, typename std::enable_if<
    2900  not std::is_pointer<ValueType>::value, int>::type = 0>
    2901  ValueType get() const
    2902  {
    2903  return get_impl(static_cast<ValueType*>(nullptr));
    2904  }
    2905 
    2933  template<typename PointerType, typename std::enable_if<
    2934  std::is_pointer<PointerType>::value, int>::type = 0>
    2935  PointerType get() noexcept
    2936  {
    2937  // delegate the call to get_ptr
    2938  return get_ptr<PointerType>();
    2939  }
    2940 
    2945  template<typename PointerType, typename std::enable_if<
    2946  std::is_pointer<PointerType>::value, int>::type = 0>
    2947  constexpr const PointerType get() const noexcept
    2948  {
    2949  // delegate the call to get_ptr
    2950  return get_ptr<PointerType>();
    2951  }
    2952 
    2979  template<typename PointerType, typename std::enable_if<
    2980  std::is_pointer<PointerType>::value, int>::type = 0>
    2981  PointerType get_ptr() noexcept
    2982  {
    2983  // get the type of the PointerType (remove pointer and const)
    2984  using pointee_t = typename std::remove_const<typename
    2985  std::remove_pointer<typename
    2986  std::remove_const<PointerType>::type>::type>::type;
    2987  // make sure the type matches the allowed types
    2988  static_assert(
    2989  std::is_same<object_t, pointee_t>::value
    2990  or std::is_same<array_t, pointee_t>::value
    2991  or std::is_same<string_t, pointee_t>::value
    2992  or std::is_same<boolean_t, pointee_t>::value
    2993  or std::is_same<number_integer_t, pointee_t>::value
    2994  or std::is_same<number_unsigned_t, pointee_t>::value
    2995  or std::is_same<number_float_t, pointee_t>::value
    2996  , "incompatible pointer type");
    2997 
    2998  // delegate the call to get_impl_ptr<>()
    2999  return get_impl_ptr(static_cast<PointerType>(nullptr));
    3000  }
    3001 
    3006  template<typename PointerType, typename std::enable_if<
    3007  std::is_pointer<PointerType>::value and
    3008  std::is_const<typename std::remove_pointer<PointerType>::type>::value, int>::type = 0>
    3009  constexpr const PointerType get_ptr() const noexcept
    3010  {
    3011  // get the type of the PointerType (remove pointer and const)
    3012  using pointee_t = typename std::remove_const<typename
    3013  std::remove_pointer<typename
    3014  std::remove_const<PointerType>::type>::type>::type;
    3015  // make sure the type matches the allowed types
    3016  static_assert(
    3017  std::is_same<object_t, pointee_t>::value
    3018  or std::is_same<array_t, pointee_t>::value
    3019  or std::is_same<string_t, pointee_t>::value
    3020  or std::is_same<boolean_t, pointee_t>::value
    3021  or std::is_same<number_integer_t, pointee_t>::value
    3022  or std::is_same<number_unsigned_t, pointee_t>::value
    3023  or std::is_same<number_float_t, pointee_t>::value
    3024  , "incompatible pointer type");
    3025 
    3026  // delegate the call to get_impl_ptr<>() const
    3027  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    3028  }
    3029 
    3056  template<typename ReferenceType, typename std::enable_if<
    3057  std::is_reference<ReferenceType>::value, int>::type = 0>
    3058  ReferenceType get_ref()
    3059  {
    3060  // delegate call to get_ref_impl
    3061  return get_ref_impl<ReferenceType>(*this);
    3062  }
    3063 
    3068  template<typename ReferenceType, typename std::enable_if<
    3069  std::is_reference<ReferenceType>::value and
    3070  std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int>::type = 0>
    3071  ReferenceType get_ref() const
    3072  {
    3073  // delegate call to get_ref_impl
    3074  return get_ref_impl<ReferenceType>(*this);
    3075  }
    3076 
    3105  template < typename ValueType, typename std::enable_if <
    3106  not std::is_pointer<ValueType>::value and
    3107  not std::is_same<ValueType, typename string_t::value_type>::value
    3108 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    3109  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    3110 #endif
    3111  , int >::type = 0 >
    3112  operator ValueType() const
    3113  {
    3114  // delegate the call to get<>() const
    3115  return get<ValueType>();
    3116  }
    3117 
    3119 
    3120 
    3122  // element access //
    3124 
    3128 
    3152  {
    3153  // at only works for arrays
    3154  if (is_array())
    3155  {
    3156  try
    3157  {
    3158  return m_value.array->at(idx);
    3159  }
    3160  catch (std::out_of_range&)
    3161  {
    3162  // create better exception explanation
    3163  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3164  }
    3165  }
    3166  else
    3167  {
    3168  throw std::domain_error("cannot use at() with " + type_name());
    3169  }
    3170  }
    3171 
    3195  {
    3196  // at only works for arrays
    3197  if (is_array())
    3198  {
    3199  try
    3200  {
    3201  return m_value.array->at(idx);
    3202  }
    3203  catch (std::out_of_range&)
    3204  {
    3205  // create better exception explanation
    3206  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3207  }
    3208  }
    3209  else
    3210  {
    3211  throw std::domain_error("cannot use at() with " + type_name());
    3212  }
    3213  }
    3214 
    3241  reference at(const typename object_t::key_type& key)
    3242  {
    3243  // at only works for objects
    3244  if (is_object())
    3245  {
    3246  try
    3247  {
    3248  return m_value.object->at(key);
    3249  }
    3250  catch (std::out_of_range&)
    3251  {
    3252  // create better exception explanation
    3253  throw std::out_of_range("key '" + key + "' not found");
    3254  }
    3255  }
    3256  else
    3257  {
    3258  throw std::domain_error("cannot use at() with " + type_name());
    3259  }
    3260  }
    3261 
    3288  const_reference at(const typename object_t::key_type& key) const
    3289  {
    3290  // at only works for objects
    3291  if (is_object())
    3292  {
    3293  try
    3294  {
    3295  return m_value.object->at(key);
    3296  }
    3297  catch (std::out_of_range&)
    3298  {
    3299  // create better exception explanation
    3300  throw std::out_of_range("key '" + key + "' not found");
    3301  }
    3302  }
    3303  else
    3304  {
    3305  throw std::domain_error("cannot use at() with " + type_name());
    3306  }
    3307  }
    3308 
    3335  {
    3336  // implicitly convert null value to an empty array
    3337  if (is_null())
    3338  {
    3339  m_type = value_t::array;
    3340  m_value.array = create<array_t>();
    3341  assert_invariant();
    3342  }
    3343 
    3344  // operator[] only works for arrays
    3345  if (is_array())
    3346  {
    3347  // fill up array with null values if given idx is outside range
    3348  if (idx >= m_value.array->size())
    3349  {
    3350  m_value.array->insert(m_value.array->end(),
    3351  idx - m_value.array->size() + 1,
    3352  basic_json());
    3353  }
    3354 
    3355  return m_value.array->operator[](idx);
    3356  }
    3357  else
    3358  {
    3359  throw std::domain_error("cannot use operator[] with " + type_name());
    3360  }
    3361  }
    3362 
    3383  {
    3384  // const operator[] only works for arrays
    3385  if (is_array())
    3386  {
    3387  return m_value.array->operator[](idx);
    3388  }
    3389  else
    3390  {
    3391  throw std::domain_error("cannot use operator[] with " + type_name());
    3392  }
    3393  }
    3394 
    3422  reference operator[](const typename object_t::key_type& key)
    3423  {
    3424  // implicitly convert null value to an empty object
    3425  if (is_null())
    3426  {
    3427  m_type = value_t::object;
    3428  m_value.object = create<object_t>();
    3429  assert_invariant();
    3430  }
    3431 
    3432  // operator[] only works for objects
    3433  if (is_object())
    3434  {
    3435  return m_value.object->operator[](key);
    3436  }
    3437  else
    3438  {
    3439  throw std::domain_error("cannot use operator[] with " + type_name());
    3440  }
    3441  }
    3442 
    3473  const_reference operator[](const typename object_t::key_type& key) const
    3474  {
    3475  // const operator[] only works for objects
    3476  if (is_object())
    3477  {
    3478  assert(m_value.object->find(key) != m_value.object->end());
    3479  return m_value.object->find(key)->second;
    3480  }
    3481  else
    3482  {
    3483  throw std::domain_error("cannot use operator[] with " + type_name());
    3484  }
    3485  }
    3486 
    3514  template<typename T, std::size_t n>
    3515  reference operator[](T * (&key)[n])
    3516  {
    3517  return operator[](static_cast<const T>(key));
    3518  }
    3519 
    3549  template<typename T, std::size_t n>
    3550  const_reference operator[](T * (&key)[n]) const
    3551  {
    3552  return operator[](static_cast<const T>(key));
    3553  }
    3554 
    3582  template<typename T>
    3584  {
    3585  // implicitly convert null to object
    3586  if (is_null())
    3587  {
    3588  m_type = value_t::object;
    3589  m_value = value_t::object;
    3590  assert_invariant();
    3591  }
    3592 
    3593  // at only works for objects
    3594  if (is_object())
    3595  {
    3596  return m_value.object->operator[](key);
    3597  }
    3598  else
    3599  {
    3600  throw std::domain_error("cannot use operator[] with " + type_name());
    3601  }
    3602  }
    3603 
    3634  template<typename T>
    3636  {
    3637  // at only works for objects
    3638  if (is_object())
    3639  {
    3640  assert(m_value.object->find(key) != m_value.object->end());
    3641  return m_value.object->find(key)->second;
    3642  }
    3643  else
    3644  {
    3645  throw std::domain_error("cannot use operator[] with " + type_name());
    3646  }
    3647  }
    3648 
    3697  template<class ValueType, typename std::enable_if<
    3698  std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
    3699  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3700  {
    3701  // at only works for objects
    3702  if (is_object())
    3703  {
    3704  // if key is found, return value and given default value otherwise
    3705  const auto it = find(key);
    3706  if (it != end())
    3707  {
    3708  return *it;
    3709  }
    3710  else
    3711  {
    3712  return default_value;
    3713  }
    3714  }
    3715  else
    3716  {
    3717  throw std::domain_error("cannot use value() with " + type_name());
    3718  }
    3719  }
    3720 
    3725  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3726  {
    3727  return value(key, string_t(default_value));
    3728  }
    3729 
    3771  template<class ValueType, typename std::enable_if<
    3772  std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
    3773  ValueType value(const json_pointer& ptr, ValueType default_value) const
    3774  {
    3775  // at only works for objects
    3776  if (is_object())
    3777  {
    3778  // if pointer resolves a value, return it or use default value
    3779  try
    3780  {
    3781  return ptr.get_checked(this);
    3782  }
    3783  catch (std::out_of_range&)
    3784  {
    3785  return default_value;
    3786  }
    3787  }
    3788  else
    3789  {
    3790  throw std::domain_error("cannot use value() with " + type_name());
    3791  }
    3792  }
    3793 
    3798  string_t value(const json_pointer& ptr, const char* default_value) const
    3799  {
    3800  return value(ptr, string_t(default_value));
    3801  }
    3802 
    3829  {
    3830  return *begin();
    3831  }
    3832 
    3837  {
    3838  return *cbegin();
    3839  }
    3840 
    3872  {
    3873  auto tmp = end();
    3874  --tmp;
    3875  return *tmp;
    3876  }
    3877 
    3882  {
    3883  auto tmp = cend();
    3884  --tmp;
    3885  return *tmp;
    3886  }
    3887 
    3933  template<class IteratorType, typename std::enable_if<
    3934  std::is_same<IteratorType, typename basic_json_t::iterator>::value or
    3935  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int>::type
    3936  = 0>
    3937  IteratorType erase(IteratorType pos)
    3938  {
    3939  // make sure iterator fits the current value
    3940  if (this != pos.m_object)
    3941  {
    3942  throw std::domain_error("iterator does not fit current value");
    3943  }
    3944 
    3945  IteratorType result = end();
    3946 
    3947  switch (m_type)
    3948  {
    3949  case value_t::boolean:
    3950  case value_t::number_float:
    3951  case value_t::number_integer:
    3952  case value_t::number_unsigned:
    3953  case value_t::string:
    3954  {
    3955  if (not pos.m_it.primitive_iterator.is_begin())
    3956  {
    3957  throw std::out_of_range("iterator out of range");
    3958  }
    3959 
    3960  if (is_string())
    3961  {
    3962  AllocatorType<string_t> alloc;
    3963  alloc.destroy(m_value.string);
    3964  alloc.deallocate(m_value.string, 1);
    3965  m_value.string = nullptr;
    3966  }
    3967 
    3968  m_type = value_t::null;
    3969  assert_invariant();
    3970  break;
    3971  }
    3972 
    3973  case value_t::object:
    3974  {
    3975  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3976  break;
    3977  }
    3978 
    3979  case value_t::array:
    3980  {
    3981  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3982  break;
    3983  }
    3984 
    3985  default:
    3986  {
    3987  throw std::domain_error("cannot use erase() with " + type_name());
    3988  }
    3989  }
    3990 
    3991  return result;
    3992  }
    3993 
    4040  template<class IteratorType, typename std::enable_if<
    4041  std::is_same<IteratorType, typename basic_json_t::iterator>::value or
    4042  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int>::type
    4043  = 0>
    4044  IteratorType erase(IteratorType first, IteratorType last)
    4045  {
    4046  // make sure iterator fits the current value
    4047  if (this != first.m_object or this != last.m_object)
    4048  {
    4049  throw std::domain_error("iterators do not fit current value");
    4050  }
    4051 
    4052  IteratorType result = end();
    4053 
    4054  switch (m_type)
    4055  {
    4056  case value_t::boolean:
    4057  case value_t::number_float:
    4058  case value_t::number_integer:
    4059  case value_t::number_unsigned:
    4060  case value_t::string:
    4061  {
    4062  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    4063  {
    4064  throw std::out_of_range("iterators out of range");
    4065  }
    4066 
    4067  if (is_string())
    4068  {
    4069  AllocatorType<string_t> alloc;
    4070  alloc.destroy(m_value.string);
    4071  alloc.deallocate(m_value.string, 1);
    4072  m_value.string = nullptr;
    4073  }
    4074 
    4075  m_type = value_t::null;
    4076  assert_invariant();
    4077  break;
    4078  }
    4079 
    4080  case value_t::object:
    4081  {
    4082  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    4083  last.m_it.object_iterator);
    4084  break;
    4085  }
    4086 
    4087  case value_t::array:
    4088  {
    4089  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    4090  last.m_it.array_iterator);
    4091  break;
    4092  }
    4093 
    4094  default:
    4095  {
    4096  throw std::domain_error("cannot use erase() with " + type_name());
    4097  }
    4098  }
    4099 
    4100  return result;
    4101  }
    4102 
    4132  size_type erase(const typename object_t::key_type& key)
    4133  {
    4134  // this erase only works for objects
    4135  if (is_object())
    4136  {
    4137  return m_value.object->erase(key);
    4138  }
    4139  else
    4140  {
    4141  throw std::domain_error("cannot use erase() with " + type_name());
    4142  }
    4143  }
    4144 
    4169  void erase(const size_type idx)
    4170  {
    4171  // this erase only works for arrays
    4172  if (is_array())
    4173  {
    4174  if (idx >= size())
    4175  {
    4176  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    4177  }
    4178 
    4179  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    4180  }
    4181  else
    4182  {
    4183  throw std::domain_error("cannot use erase() with " + type_name());
    4184  }
    4185  }
    4186 
    4188 
    4189 
    4191  // lookup //
    4193 
    4196 
    4215  iterator find(typename object_t::key_type key)
    4216  {
    4217  auto result = end();
    4218 
    4219  if (is_object())
    4220  {
    4221  result.m_it.object_iterator = m_value.object->find(key);
    4222  }
    4223 
    4224  return result;
    4225  }
    4226 
    4231  const_iterator find(typename object_t::key_type key) const
    4232  {
    4233  auto result = cend();
    4234 
    4235  if (is_object())
    4236  {
    4237  result.m_it.object_iterator = m_value.object->find(key);
    4238  }
    4239 
    4240  return result;
    4241  }
    4242 
    4261  size_type count(typename object_t::key_type key) const
    4262  {
    4263  // return 0 for all nonobject types
    4264  return is_object() ? m_value.object->count(key) : 0;
    4265  }
    4266 
    4268 
    4269 
    4271  // iterators //
    4273 
    4276 
    4301  iterator begin() noexcept
    4302  {
    4303  iterator result(this);
    4304  result.set_begin();
    4305  return result;
    4306  }
    4307 
    4311  const_iterator begin() const noexcept
    4312  {
    4313  return cbegin();
    4314  }
    4315 
    4341  const_iterator cbegin() const noexcept
    4342  {
    4343  const_iterator result(this);
    4344  result.set_begin();
    4345  return result;
    4346  }
    4347 
    4372  iterator end() noexcept
    4373  {
    4374  iterator result(this);
    4375  result.set_end();
    4376  return result;
    4377  }
    4378 
    4382  const_iterator end() const noexcept
    4383  {
    4384  return cend();
    4385  }
    4386 
    4412  const_iterator cend() const noexcept
    4413  {
    4414  const_iterator result(this);
    4415  result.set_end();
    4416  return result;
    4417  }
    4418 
    4443  {
    4444  return reverse_iterator(end());
    4445  }
    4446 
    4451  {
    4452  return crbegin();
    4453  }
    4454 
    4480  {
    4481  return reverse_iterator(begin());
    4482  }
    4483 
    4487  const_reverse_iterator rend() const noexcept
    4488  {
    4489  return crend();
    4490  }
    4491 
    4517  {
    4518  return const_reverse_iterator(cend());
    4519  }
    4520 
    4546  {
    4547  return const_reverse_iterator(cbegin());
    4548  }
    4549 
    4550  private:
    4551  // forward declaration
    4552  template<typename IteratorType> class iteration_proxy;
    4553 
    4554  public:
    4566  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4567  {
    4568  return iteration_proxy<iterator>(cont);
    4569  }
    4570 
    4574  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4575  {
    4576  return iteration_proxy<const_iterator>(cont);
    4577  }
    4578 
    4580 
    4581 
    4583  // capacity //
    4585 
    4588 
    4626  bool empty() const noexcept
    4627  {
    4628  switch (m_type)
    4629  {
    4630  case value_t::null:
    4631  {
    4632  // null values are empty
    4633  return true;
    4634  }
    4635 
    4636  case value_t::array:
    4637  {
    4638  // delegate call to array_t::empty()
    4639  return m_value.array->empty();
    4640  }
    4641 
    4642  case value_t::object:
    4643  {
    4644  // delegate call to object_t::empty()
    4645  return m_value.object->empty();
    4646  }
    4647 
    4648  default:
    4649  {
    4650  // all other types are nonempty
    4651  return false;
    4652  }
    4653  }
    4654  }
    4655 
    4694  size_type size() const noexcept
    4695  {
    4696  switch (m_type)
    4697  {
    4698  case value_t::null:
    4699  {
    4700  // null values are empty
    4701  return 0;
    4702  }
    4703 
    4704  case value_t::array:
    4705  {
    4706  // delegate call to array_t::size()
    4707  return m_value.array->size();
    4708  }
    4709 
    4710  case value_t::object:
    4711  {
    4712  // delegate call to object_t::size()
    4713  return m_value.object->size();
    4714  }
    4715 
    4716  default:
    4717  {
    4718  // all other types have size 1
    4719  return 1;
    4720  }
    4721  }
    4722  }
    4723 
    4760  size_type max_size() const noexcept
    4761  {
    4762  switch (m_type)
    4763  {
    4764  case value_t::array:
    4765  {
    4766  // delegate call to array_t::max_size()
    4767  return m_value.array->max_size();
    4768  }
    4769 
    4770  case value_t::object:
    4771  {
    4772  // delegate call to object_t::max_size()
    4773  return m_value.object->max_size();
    4774  }
    4775 
    4776  default:
    4777  {
    4778  // all other types have max_size() == size()
    4779  return size();
    4780  }
    4781  }
    4782  }
    4783 
    4785 
    4786 
    4788  // modifiers //
    4790 
    4793 
    4819  void clear() noexcept
    4820  {
    4821  switch (m_type)
    4822  {
    4823  case value_t::number_integer:
    4824  {
    4825  m_value.number_integer = 0;
    4826  break;
    4827  }
    4828 
    4829  case value_t::number_unsigned:
    4830  {
    4831  m_value.number_unsigned = 0;
    4832  break;
    4833  }
    4834 
    4835  case value_t::number_float:
    4836  {
    4837  m_value.number_float = 0.0;
    4838  break;
    4839  }
    4840 
    4841  case value_t::boolean:
    4842  {
    4843  m_value.boolean = false;
    4844  break;
    4845  }
    4846 
    4847  case value_t::string:
    4848  {
    4849  m_value.string->clear();
    4850  break;
    4851  }
    4852 
    4853  case value_t::array:
    4854  {
    4855  m_value.array->clear();
    4856  break;
    4857  }
    4858 
    4859  case value_t::object:
    4860  {
    4861  m_value.object->clear();
    4862  break;
    4863  }
    4864 
    4865  default:
    4866  {
    4867  break;
    4868  }
    4869  }
    4870  }
    4871 
    4892  void push_back(basic_json&& val)
    4893  {
    4894  // push_back only works for null objects or arrays
    4895  if (not(is_null() or is_array()))
    4896  {
    4897  throw std::domain_error("cannot use push_back() with " + type_name());
    4898  }
    4899 
    4900  // transform null object into an array
    4901  if (is_null())
    4902  {
    4903  m_type = value_t::array;
    4904  m_value = value_t::array;
    4905  assert_invariant();
    4906  }
    4907 
    4908  // add element to array (move semantics)
    4909  m_value.array->push_back(std::move(val));
    4910  // invalidate object
    4911  val.m_type = value_t::null;
    4912  }
    4913 
    4919  {
    4920  push_back(std::move(val));
    4921  return *this;
    4922  }
    4923 
    4928  void push_back(const basic_json& val)
    4929  {
    4930  // push_back only works for null objects or arrays
    4931  if (not(is_null() or is_array()))
    4932  {
    4933  throw std::domain_error("cannot use push_back() with " + type_name());
    4934  }
    4935 
    4936  // transform null object into an array
    4937  if (is_null())
    4938  {
    4939  m_type = value_t::array;
    4940  m_value = value_t::array;
    4941  assert_invariant();
    4942  }
    4943 
    4944  // add element to array
    4945  m_value.array->push_back(val);
    4946  }
    4947 
    4953  {
    4954  push_back(val);
    4955  return *this;
    4956  }
    4957 
    4978  void push_back(const typename object_t::value_type& val)
    4979  {
    4980  // push_back only works for null objects or objects
    4981  if (not(is_null() or is_object()))
    4982  {
    4983  throw std::domain_error("cannot use push_back() with " + type_name());
    4984  }
    4985 
    4986  // transform null object into an object
    4987  if (is_null())
    4988  {
    4989  m_type = value_t::object;
    4990  m_value = value_t::object;
    4991  assert_invariant();
    4992  }
    4993 
    4994  // add element to array
    4995  m_value.object->insert(val);
    4996  }
    4997 
    5002  reference operator+=(const typename object_t::value_type& val)
    5003  {
    5004  push_back(val);
    5005  return *this;
    5006  }
    5007 
    5033  void push_back(std::initializer_list<basic_json> init)
    5034  {
    5035  if (is_object() and init.size() == 2 and init.begin()->is_string())
    5036  {
    5037  const string_t key = *init.begin();
    5038  push_back(typename object_t::value_type(key, *(init.begin() + 1)));
    5039  }
    5040  else
    5041  {
    5042  push_back(basic_json(init));
    5043  }
    5044  }
    5045 
    5050  reference operator+=(std::initializer_list<basic_json> init)
    5051  {
    5052  push_back(init);
    5053  return *this;
    5054  }
    5055 
    5079  {
    5080  // insert only works for arrays
    5081  if (is_array())
    5082  {
    5083  // check if iterator pos fits to this JSON value
    5084  if (pos.m_object != this)
    5085  {
    5086  throw std::domain_error("iterator does not fit current value");
    5087  }
    5088 
    5089  // insert to array and return iterator
    5090  iterator result(this);
    5091  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    5092  return result;
    5093  }
    5094  else
    5095  {
    5096  throw std::domain_error("cannot use insert() with " + type_name());
    5097  }
    5098  }
    5099 
    5105  {
    5106  return insert(pos, val);
    5107  }
    5108 
    5134  {
    5135  // insert only works for arrays
    5136  if (is_array())
    5137  {
    5138  // check if iterator pos fits to this JSON value
    5139  if (pos.m_object != this)
    5140  {
    5141  throw std::domain_error("iterator does not fit current value");
    5142  }
    5143 
    5144  // insert to array and return iterator
    5145  iterator result(this);
    5146  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    5147  return result;
    5148  }
    5149  else
    5150  {
    5151  throw std::domain_error("cannot use insert() with " + type_name());
    5152  }
    5153  }
    5154 
    5186  {
    5187  // insert only works for arrays
    5188  if (not is_array())
    5189  {
    5190  throw std::domain_error("cannot use insert() with " + type_name());
    5191  }
    5192 
    5193  // check if iterator pos fits to this JSON value
    5194  if (pos.m_object != this)
    5195  {
    5196  throw std::domain_error("iterator does not fit current value");
    5197  }
    5198 
    5199  // check if range iterators belong to the same JSON object
    5200  if (first.m_object != last.m_object)
    5201  {
    5202  throw std::domain_error("iterators do not fit");
    5203  }
    5204 
    5205  if (first.m_object == this or last.m_object == this)
    5206  {
    5207  throw std::domain_error("passed iterators may not belong to container");
    5208  }
    5209 
    5210  // insert to array and return iterator
    5211  iterator result(this);
    5212  result.m_it.array_iterator = m_value.array->insert(
    5213  pos.m_it.array_iterator,
    5214  first.m_it.array_iterator,
    5215  last.m_it.array_iterator);
    5216  return result;
    5217  }
    5218 
    5243  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    5244  {
    5245  // insert only works for arrays
    5246  if (not is_array())
    5247  {
    5248  throw std::domain_error("cannot use insert() with " + type_name());
    5249  }
    5250 
    5251  // check if iterator pos fits to this JSON value
    5252  if (pos.m_object != this)
    5253  {
    5254  throw std::domain_error("iterator does not fit current value");
    5255  }
    5256 
    5257  // insert to array and return iterator
    5258  iterator result(this);
    5259  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    5260  return result;
    5261  }
    5262 
    5280  void swap(reference other) noexcept (
    5281  std::is_nothrow_move_constructible<value_t>::value and
    5282  std::is_nothrow_move_assignable<value_t>::value and
    5283  std::is_nothrow_move_constructible<json_value>::value and
    5284  std::is_nothrow_move_assignable<json_value>::value
    5285  )
    5286  {
    5287  std::swap(m_type, other.m_type);
    5288  std::swap(m_value, other.m_value);
    5289  assert_invariant();
    5290  }
    5291 
    5312  void swap(array_t& other)
    5313  {
    5314  // swap only works for arrays
    5315  if (is_array())
    5316  {
    5317  std::swap(*(m_value.array), other);
    5318  }
    5319  else
    5320  {
    5321  throw std::domain_error("cannot use swap() with " + type_name());
    5322  }
    5323  }
    5324 
    5345  void swap(object_t& other)
    5346  {
    5347  // swap only works for objects
    5348  if (is_object())
    5349  {
    5350  std::swap(*(m_value.object), other);
    5351  }
    5352  else
    5353  {
    5354  throw std::domain_error("cannot use swap() with " + type_name());
    5355  }
    5356  }
    5357 
    5378  void swap(string_t& other)
    5379  {
    5380  // swap only works for strings
    5381  if (is_string())
    5382  {
    5383  std::swap(*(m_value.string), other);
    5384  }
    5385  else
    5386  {
    5387  throw std::domain_error("cannot use swap() with " + type_name());
    5388  }
    5389  }
    5390 
    5392 
    5393 
    5395  // lexicographical comparison operators //
    5397 
    5400 
    5401  private:
    5411  friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    5412  {
    5413  static constexpr std::array<uint8_t, 8> order = {{
    5414  0, // null
    5415  3, // object
    5416  4, // array
    5417  5, // string
    5418  1, // boolean
    5419  2, // integer
    5420  2, // unsigned
    5421  2, // float
    5422  }
    5423  };
    5424 
    5425  // discarded values are not comparable
    5426  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5427  {
    5428  return false;
    5429  }
    5430 
    5431  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5432  }
    5433 
    5434  public:
    5458  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5459  {
    5460  const auto lhs_type = lhs.type();
    5461  const auto rhs_type = rhs.type();
    5462 
    5463  if (lhs_type == rhs_type)
    5464  {
    5465  switch (lhs_type)
    5466  {
    5467  case value_t::array:
    5468  {
    5469  return *lhs.m_value.array == *rhs.m_value.array;
    5470  }
    5471  case value_t::object:
    5472  {
    5473  return *lhs.m_value.object == *rhs.m_value.object;
    5474  }
    5475  case value_t::null:
    5476  {
    5477  return true;
    5478  }
    5479  case value_t::string:
    5480  {
    5481  return *lhs.m_value.string == *rhs.m_value.string;
    5482  }
    5483  case value_t::boolean:
    5484  {
    5485  return lhs.m_value.boolean == rhs.m_value.boolean;
    5486  }
    5487  case value_t::number_integer:
    5488  {
    5489  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5490  }
    5491  case value_t::number_unsigned:
    5492  {
    5493  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5494  }
    5495  case value_t::number_float:
    5496  {
    5497  return lhs.m_value.number_float == rhs.m_value.number_float;
    5498  }
    5499  default:
    5500  {
    5501  return false;
    5502  }
    5503  }
    5504  }
    5505  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5506  {
    5507  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5508  }
    5509  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5510  {
    5511  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5512  }
    5513  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5514  {
    5515  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5516  }
    5517  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5518  {
    5519  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5520  }
    5521  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5522  {
    5523  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5524  }
    5525  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5526  {
    5527  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5528  }
    5529 
    5530  return false;
    5531  }
    5532 
    5551  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5552  {
    5553  return v.is_null();
    5554  }
    5555 
    5560  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5561  {
    5562  return v.is_null();
    5563  }
    5564 
    5581  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5582  {
    5583  return not (lhs == rhs);
    5584  }
    5585 
    5604  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5605  {
    5606  return not v.is_null();
    5607  }
    5608 
    5613  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5614  {
    5615  return not v.is_null();
    5616  }
    5617 
    5642  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5643  {
    5644  const auto lhs_type = lhs.type();
    5645  const auto rhs_type = rhs.type();
    5646 
    5647  if (lhs_type == rhs_type)
    5648  {
    5649  switch (lhs_type)
    5650  {
    5651  case value_t::array:
    5652  {
    5653  return *lhs.m_value.array < *rhs.m_value.array;
    5654  }
    5655  case value_t::object:
    5656  {
    5657  return *lhs.m_value.object < *rhs.m_value.object;
    5658  }
    5659  case value_t::null:
    5660  {
    5661  return false;
    5662  }
    5663  case value_t::string:
    5664  {
    5665  return *lhs.m_value.string < *rhs.m_value.string;
    5666  }
    5667  case value_t::boolean:
    5668  {
    5669  return lhs.m_value.boolean < rhs.m_value.boolean;
    5670  }
    5671  case value_t::number_integer:
    5672  {
    5673  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5674  }
    5675  case value_t::number_unsigned:
    5676  {
    5677  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5678  }
    5679  case value_t::number_float:
    5680  {
    5681  return lhs.m_value.number_float < rhs.m_value.number_float;
    5682  }
    5683  default:
    5684  {
    5685  return false;
    5686  }
    5687  }
    5688  }
    5689  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5690  {
    5691  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5692  }
    5693  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5694  {
    5695  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5696  }
    5697  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5698  {
    5699  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5700  }
    5701  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5702  {
    5703  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5704  }
    5705  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5706  {
    5707  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5708  }
    5709  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5710  {
    5711  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5712  }
    5713 
    5714  // We only reach this line if we cannot compare values. In that case,
    5715  // we compare types. Note we have to call the operator explicitly,
    5716  // because MSVC has problems otherwise.
    5717  return operator<(lhs_type, rhs_type);
    5718  }
    5719 
    5737  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5738  {
    5739  return not (rhs < lhs);
    5740  }
    5741 
    5759  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5760  {
    5761  return not (lhs <= rhs);
    5762  }
    5763 
    5781  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5782  {
    5783  return not (lhs < rhs);
    5784  }
    5785 
    5787 
    5788 
    5790  // serialization //
    5792 
    5795 
    5822  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5823  {
    5824  // read width member and use it as indentation parameter if nonzero
    5825  const bool pretty_print = (o.width() > 0);
    5826  const auto indentation = (pretty_print ? o.width() : 0);
    5827 
    5828  // reset width to 0 for subsequent calls to this stream
    5829  o.width(0);
    5830 
    5831  // fix locale problems
    5832  const auto old_locale = o.imbue(std::locale(std::locale(), new DecimalSeparator));
    5833  // set precision
    5834 
    5835  // 6, 15 or 16 digits of precision allows round-trip IEEE 754
    5836  // string->float->string, string->double->string or string->long
    5837  // double->string; to be safe, we read this value from
    5838  // std::numeric_limits<number_float_t>::digits10
    5839  const auto old_precision = o.precision(std::numeric_limits<double>::digits10);
    5840 
    5841  // do the actual serialization
    5842  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5843 
    5844  // reset locale and precision
    5845  o.imbue(old_locale);
    5846  o.precision(old_precision);
    5847  return o;
    5848  }
    5849 
    5854  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5855  {
    5856  return o << j;
    5857  }
    5858 
    5860 
    5861 
    5863  // deserialization //
    5865 
    5868 
    5896  template<class T, std::size_t N>
    5897  static basic_json parse(T (&array)[N],
    5898  const parser_callback_t cb = nullptr)
    5899  {
    5900  // delegate the call to the iterator-range parse overload
    5901  return parse(std::begin(array), std::end(array), cb);
    5902  }
    5903 
    5931  template<typename CharPT, typename std::enable_if<
    5932  std::is_pointer<CharPT>::value and
    5933  std::is_integral<typename std::remove_pointer<CharPT>::type>::value and
    5934  sizeof(typename std::remove_pointer<CharPT>::type) == 1, int>::type = 0>
    5935  static basic_json parse(const CharPT s,
    5936  const parser_callback_t cb = nullptr)
    5937  {
    5938  return parser(reinterpret_cast<const char*>(s), cb).parse();
    5939  }
    5940 
    5965  static basic_json parse(std::istream& i,
    5966  const parser_callback_t cb = nullptr)
    5967  {
    5968  return parser(i, cb).parse();
    5969  }
    5970 
    5974  static basic_json parse(std::istream&& i,
    5975  const parser_callback_t cb = nullptr)
    5976  {
    5977  return parser(i, cb).parse();
    5978  }
    5979 
    6021  template<class IteratorType, typename std::enable_if<
    6022  std::is_base_of<
    6023  std::random_access_iterator_tag,
    6024  typename std::iterator_traits<IteratorType>::iterator_category>::value, int>::type = 0>
    6025  static basic_json parse(IteratorType first, IteratorType last,
    6026  const parser_callback_t cb = nullptr)
    6027  {
    6028  // assertion to check that the iterator range is indeed contiguous,
    6029  // see http://stackoverflow.com/a/35008842/266378 for more discussion
    6030  assert(std::accumulate(first, last, std::make_pair<bool, int>(true, 0),
    6031  [&first](std::pair<bool, int> res, decltype(*first) val)
    6032  {
    6033  res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
    6034  return res;
    6035  }).first);
    6036 
    6037  // assertion to check that each element is 1 byte long
    6038  static_assert(sizeof(typename std::iterator_traits<IteratorType>::value_type) == 1,
    6039  "each element in the iterator range must have the size of 1 byte");
    6040 
    6041  // if iterator range is empty, create a parser with an empty string
    6042  // to generate "unexpected EOF" error message
    6043  if (std::distance(first, last) <= 0)
    6044  {
    6045  return parser("").parse();
    6046  }
    6047 
    6048  return parser(first, last, cb).parse();
    6049  }
    6050 
    6091  template<class ContiguousContainer, typename std::enable_if<
    6092  not std::is_pointer<ContiguousContainer>::value and
    6093  std::is_base_of<
    6094  std::random_access_iterator_tag,
    6095  typename std::iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value
    6096  , int>::type = 0>
    6097  static basic_json parse(const ContiguousContainer& c,
    6098  const parser_callback_t cb = nullptr)
    6099  {
    6100  // delegate the call to the iterator-range parse overload
    6101  return parse(std::begin(c), std::end(c), cb);
    6102  }
    6103 
    6127  friend std::istream& operator<<(basic_json& j, std::istream& i)
    6128  {
    6129  j = parser(i).parse();
    6130  return i;
    6131  }
    6132 
    6137  friend std::istream& operator>>(std::istream& i, basic_json& j)
    6138  {
    6139  j = parser(i).parse();
    6140  return i;
    6141  }
    6142 
    6144 
    6145 
    6146  private:
    6148  // convenience functions //
    6150 
    6163  std::string type_name() const
    6164  {
    6165  switch (m_type)
    6166  {
    6167  case value_t::null:
    6168  return "null";
    6169  case value_t::object:
    6170  return "object";
    6171  case value_t::array:
    6172  return "array";
    6173  case value_t::string:
    6174  return "string";
    6175  case value_t::boolean:
    6176  return "boolean";
    6177  case value_t::discarded:
    6178  return "discarded";
    6179  default:
    6180  return "number";
    6181  }
    6182  }
    6183 
    6192  static std::size_t extra_space(const string_t& s) noexcept
    6193  {
    6194  return std::accumulate(s.begin(), s.end(), size_t{},
    6195  [](size_t res, typename string_t::value_type c)
    6196  {
    6197  switch (c)
    6198  {
    6199  case '"':
    6200  case '\\':
    6201  case '\b':
    6202  case '\f':
    6203  case '\n':
    6204  case '\r':
    6205  case '\t':
    6206  {
    6207  // from c (1 byte) to \x (2 bytes)
    6208  return res + 1;
    6209  }
    6210 
    6211  default:
    6212  {
    6213  if (c >= 0x00 and c <= 0x1f)
    6214  {
    6215  // from c (1 byte) to \uxxxx (6 bytes)
    6216  return res + 5;
    6217  }
    6218  else
    6219  {
    6220  return res;
    6221  }
    6222  }
    6223  }
    6224  });
    6225  }
    6226 
    6240  static string_t escape_string(const string_t& s)
    6241  {
    6242  const auto space = extra_space(s);
    6243  if (space == 0)
    6244  {
    6245  return s;
    6246  }
    6247 
    6248  // create a result string of necessary size
    6249  string_t result(s.size() + space, '\\');
    6250  std::size_t pos = 0;
    6251 
    6252  for (const auto& c : s)
    6253  {
    6254  switch (c)
    6255  {
    6256  // quotation mark (0x22)
    6257  case '"':
    6258  {
    6259  result[pos + 1] = '"';
    6260  pos += 2;
    6261  break;
    6262  }
    6263 
    6264  // reverse solidus (0x5c)
    6265  case '\\':
    6266  {
    6267  // nothing to change
    6268  pos += 2;
    6269  break;
    6270  }
    6271 
    6272  // backspace (0x08)
    6273  case '\b':
    6274  {
    6275  result[pos + 1] = 'b';
    6276  pos += 2;
    6277  break;
    6278  }
    6279 
    6280  // formfeed (0x0c)
    6281  case '\f':
    6282  {
    6283  result[pos + 1] = 'f';
    6284  pos += 2;
    6285  break;
    6286  }
    6287 
    6288  // newline (0x0a)
    6289  case '\n':
    6290  {
    6291  result[pos + 1] = 'n';
    6292  pos += 2;
    6293  break;
    6294  }
    6295 
    6296  // carriage return (0x0d)
    6297  case '\r':
    6298  {
    6299  result[pos + 1] = 'r';
    6300  pos += 2;
    6301  break;
    6302  }
    6303 
    6304  // horizontal tab (0x09)
    6305  case '\t':
    6306  {
    6307  result[pos + 1] = 't';
    6308  pos += 2;
    6309  break;
    6310  }
    6311 
    6312  default:
    6313  {
    6314  if (c >= 0x00 and c <= 0x1f)
    6315  {
    6316  // convert a number 0..15 to its hex representation
    6317  // (0..f)
    6318  static const char hexify[16] =
    6319  {
    6320  '0', '1', '2', '3', '4', '5', '6', '7',
    6321  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
    6322  };
    6323 
    6324  // print character c as \uxxxx
    6325  for (const char m :
    6326  { 'u', '0', '0', hexify[c >> 4], hexify[c & 0x0f]
    6327  })
    6328  {
    6329  result[++pos] = m;
    6330  }
    6331 
    6332  ++pos;
    6333  }
    6334  else
    6335  {
    6336  // all other characters are added as-is
    6337  result[pos++] = c;
    6338  }
    6339  break;
    6340  }
    6341  }
    6342  }
    6343 
    6344  return result;
    6345  }
    6346 
    6364  void dump(std::ostream& o,
    6365  const bool pretty_print,
    6366  const unsigned int indent_step,
    6367  const unsigned int current_indent = 0) const
    6368  {
    6369  // variable to hold indentation for recursive calls
    6370  unsigned int new_indent = current_indent;
    6371 
    6372  switch (m_type)
    6373  {
    6374  case value_t::object:
    6375  {
    6376  if (m_value.object->empty())
    6377  {
    6378  o << "{}";
    6379  return;
    6380  }
    6381 
    6382  o << "{";
    6383 
    6384  // increase indentation
    6385  if (pretty_print)
    6386  {
    6387  new_indent += indent_step;
    6388  o << "\n";
    6389  }
    6390 
    6391  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    6392  {
    6393  if (i != m_value.object->cbegin())
    6394  {
    6395  o << (pretty_print ? ",\n" : ",");
    6396  }
    6397  o << string_t(new_indent, ' ') << "\""
    6398  << escape_string(i->first) << "\":"
    6399  << (pretty_print ? " " : "");
    6400  i->second.dump(o, pretty_print, indent_step, new_indent);
    6401  }
    6402 
    6403  // decrease indentation
    6404  if (pretty_print)
    6405  {
    6406  new_indent -= indent_step;
    6407  o << "\n";
    6408  }
    6409 
    6410  o << string_t(new_indent, ' ') + "}";
    6411  return;
    6412  }
    6413 
    6414  case value_t::array:
    6415  {
    6416  if (m_value.array->empty())
    6417  {
    6418  o << "[]";
    6419  return;
    6420  }
    6421 
    6422  o << "[";
    6423 
    6424  // increase indentation
    6425  if (pretty_print)
    6426  {
    6427  new_indent += indent_step;
    6428  o << "\n";
    6429  }
    6430 
    6431  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    6432  {
    6433  if (i != m_value.array->cbegin())
    6434  {
    6435  o << (pretty_print ? ",\n" : ",");
    6436  }
    6437  o << string_t(new_indent, ' ');
    6438  i->dump(o, pretty_print, indent_step, new_indent);
    6439  }
    6440 
    6441  // decrease indentation
    6442  if (pretty_print)
    6443  {
    6444  new_indent -= indent_step;
    6445  o << "\n";
    6446  }
    6447 
    6448  o << string_t(new_indent, ' ') << "]";
    6449  return;
    6450  }
    6451 
    6452  case value_t::string:
    6453  {
    6454  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    6455  return;
    6456  }
    6457 
    6458  case value_t::boolean:
    6459  {
    6460  o << (m_value.boolean ? "true" : "false");
    6461  return;
    6462  }
    6463 
    6464  case value_t::number_integer:
    6465  {
    6466  o << m_value.number_integer;
    6467  return;
    6468  }
    6469 
    6470  case value_t::number_unsigned:
    6471  {
    6472  o << m_value.number_unsigned;
    6473  return;
    6474  }
    6475 
    6476  case value_t::number_float:
    6477  {
    6478  if (m_value.number_float == 0)
    6479  {
    6480  // special case for zero to get "0.0"/"-0.0"
    6481  o << (std::signbit(m_value.number_float) ? "-0.0" : "0.0");
    6482  }
    6483  else
    6484  {
    6485  o << m_value.number_float;
    6486  }
    6487  return;
    6488  }
    6489 
    6490  case value_t::discarded:
    6491  {
    6492  o << "<discarded>";
    6493  return;
    6494  }
    6495 
    6496  case value_t::null:
    6497  {
    6498  o << "null";
    6499  return;
    6500  }
    6501  }
    6502  }
    6503 
    6504  private:
    6506  // member variables //
    6508 
    6510  value_t m_type = value_t::null;
    6511 
    6513  json_value m_value = {};
    6514 
    6515 
    6516  private:
    6518  // iterators //
    6520 
    6530  class primitive_iterator_t
    6531  {
    6532  public:
    6534  void set_begin() noexcept
    6535  {
    6536  m_it = begin_value;
    6537  }
    6538 
    6540  void set_end() noexcept
    6541  {
    6542  m_it = end_value;
    6543  }
    6544 
    6546  constexpr bool is_begin() const noexcept
    6547  {
    6548  return (m_it == begin_value);
    6549  }
    6550 
    6552  constexpr bool is_end() const noexcept
    6553  {
    6554  return (m_it == end_value);
    6555  }
    6556 
    6558  operator difference_type& () noexcept
    6559  {
    6560  return m_it;
    6561  }
    6562 
    6564  constexpr operator difference_type () const noexcept
    6565  {
    6566  return m_it;
    6567  }
    6568 
    6569  private:
    6570  static constexpr difference_type begin_value = 0;
    6571  static constexpr difference_type end_value = begin_value + 1;
    6572 
    6574  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    6575  };
    6576 
    6584  struct internal_iterator
    6585  {
    6587  typename object_t::iterator object_iterator;
    6589  typename array_t::iterator array_iterator;
    6591  primitive_iterator_t primitive_iterator;
    6592 
    6594  internal_iterator() noexcept
    6595  : object_iterator(), array_iterator(), primitive_iterator()
    6596  {}
    6597  };
    6598 
    6600  template<typename IteratorType>
    6601  class iteration_proxy
    6602  {
    6603  private:
    6605  class iteration_proxy_internal
    6606  {
    6607  private:
    6609  IteratorType anchor;
    6611  size_t array_index = 0;
    6612 
    6613  public:
    6614  explicit iteration_proxy_internal(IteratorType it) noexcept
    6615  : anchor(it)
    6616  {}
    6617 
    6619  iteration_proxy_internal& operator*()
    6620  {
    6621  return *this;
    6622  }
    6623 
    6625  iteration_proxy_internal& operator++()
    6626  {
    6627  ++anchor;
    6628  ++array_index;
    6629 
    6630  return *this;
    6631  }
    6632 
    6634  bool operator!= (const iteration_proxy_internal& o) const
    6635  {
    6636  return anchor != o.anchor;
    6637  }
    6638 
    6640  typename basic_json::string_t key() const
    6641  {
    6642  assert(anchor.m_object != nullptr);
    6643 
    6644  switch (anchor.m_object->type())
    6645  {
    6646  // use integer array index as key
    6647  case value_t::array:
    6648  {
    6649  return std::to_string(array_index);
    6650  }
    6651 
    6652  // use key from the object
    6653  case value_t::object:
    6654  {
    6655  return anchor.key();
    6656  }
    6657 
    6658  // use an empty key for all primitive types
    6659  default:
    6660  {
    6661  return "";
    6662  }
    6663  }
    6664  }
    6665 
    6667  typename IteratorType::reference value() const
    6668  {
    6669  return anchor.value();
    6670  }
    6671  };
    6672 
    6674  typename IteratorType::reference container;
    6675 
    6676  public:
    6678  explicit iteration_proxy(typename IteratorType::reference cont)
    6679  : container(cont)
    6680  {}
    6681 
    6683  iteration_proxy_internal begin() noexcept
    6684  {
    6685  return iteration_proxy_internal(container.begin());
    6686  }
    6687 
    6689  iteration_proxy_internal end() noexcept
    6690  {
    6691  return iteration_proxy_internal(container.end());
    6692  }
    6693  };
    6694 
    6695  public:
    6715  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6716  {
    6718  friend class basic_json;
    6719 
    6720  public:
    6730  using iterator_category = std::bidirectional_iterator_tag;
    6731 
    6733  const_iterator() = default;
    6734 
    6741  explicit const_iterator(pointer object) noexcept
    6742  : m_object(object)
    6743  {
    6744  assert(m_object != nullptr);
    6745 
    6746  switch (m_object->m_type)
    6747  {
    6749  {
    6750  m_it.object_iterator = typename object_t::iterator();
    6751  break;
    6752  }
    6753 
    6755  {
    6756  m_it.array_iterator = typename array_t::iterator();
    6757  break;
    6758  }
    6759 
    6760  default:
    6761  {
    6762  m_it.primitive_iterator = primitive_iterator_t();
    6763  break;
    6764  }
    6765  }
    6766  }
    6767 
    6773  explicit const_iterator(const iterator& other) noexcept
    6774  : m_object(other.m_object)
    6775  {
    6776  if (m_object != nullptr)
    6777  {
    6778  switch (m_object->m_type)
    6779  {
    6781  {
    6782  m_it.object_iterator = other.m_it.object_iterator;
    6783  break;
    6784  }
    6785 
    6787  {
    6788  m_it.array_iterator = other.m_it.array_iterator;
    6789  break;
    6790  }
    6791 
    6792  default:
    6793  {
    6794  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6795  break;
    6796  }
    6797  }
    6798  }
    6799  }
    6800 
    6806  const_iterator(const const_iterator& other) noexcept
    6807  : m_object(other.m_object), m_it(other.m_it)
    6808  {}
    6809 
    6816  std::is_nothrow_move_constructible<pointer>::value and
    6817  std::is_nothrow_move_assignable<pointer>::value and
    6818  std::is_nothrow_move_constructible<internal_iterator>::value and
    6819  std::is_nothrow_move_assignable<internal_iterator>::value
    6820  )
    6821  {
    6822  std::swap(m_object, other.m_object);
    6823  std::swap(m_it, other.m_it);
    6824  return *this;
    6825  }
    6826 
    6827  private:
    6832  void set_begin() noexcept
    6833  {
    6834  assert(m_object != nullptr);
    6835 
    6836  switch (m_object->m_type)
    6837  {
    6839  {
    6840  m_it.object_iterator = m_object->m_value.object->begin();
    6841  break;
    6842  }
    6843 
    6845  {
    6846  m_it.array_iterator = m_object->m_value.array->begin();
    6847  break;
    6848  }
    6849 
    6851  {
    6852  // set to end so begin()==end() is true: null is empty
    6853  m_it.primitive_iterator.set_end();
    6854  break;
    6855  }
    6856 
    6857  default:
    6858  {
    6859  m_it.primitive_iterator.set_begin();
    6860  break;
    6861  }
    6862  }
    6863  }
    6864 
    6869  void set_end() noexcept
    6870  {
    6871  assert(m_object != nullptr);
    6872 
    6873  switch (m_object->m_type)
    6874  {
    6876  {
    6877  m_it.object_iterator = m_object->m_value.object->end();
    6878  break;
    6879  }
    6880 
    6882  {
    6883  m_it.array_iterator = m_object->m_value.array->end();
    6884  break;
    6885  }
    6886 
    6887  default:
    6888  {
    6889  m_it.primitive_iterator.set_end();
    6890  break;
    6891  }
    6892  }
    6893  }
    6894 
    6895  public:
    6901  {
    6902  assert(m_object != nullptr);
    6903 
    6904  switch (m_object->m_type)
    6905  {
    6907  {
    6908  assert(m_it.object_iterator != m_object->m_value.object->end());
    6909  return m_it.object_iterator->second;
    6910  }
    6911 
    6913  {
    6914  assert(m_it.array_iterator != m_object->m_value.array->end());
    6915  return *m_it.array_iterator;
    6916  }
    6917 
    6919  {
    6920  throw std::out_of_range("cannot get value");
    6921  }
    6922 
    6923  default:
    6924  {
    6925  if (m_it.primitive_iterator.is_begin())
    6926  {
    6927  return *m_object;
    6928  }
    6929  else
    6930  {
    6931  throw std::out_of_range("cannot get value");
    6932  }
    6933  }
    6934  }
    6935  }
    6936 
    6942  {
    6943  assert(m_object != nullptr);
    6944 
    6945  switch (m_object->m_type)
    6946  {
    6948  {
    6949  assert(m_it.object_iterator != m_object->m_value.object->end());
    6950  return &(m_it.object_iterator->second);
    6951  }
    6952 
    6954  {
    6955  assert(m_it.array_iterator != m_object->m_value.array->end());
    6956  return &*m_it.array_iterator;
    6957  }
    6958 
    6959  default:
    6960  {
    6961  if (m_it.primitive_iterator.is_begin())
    6962  {
    6963  return m_object;
    6964  }
    6965  else
    6966  {
    6967  throw std::out_of_range("cannot get value");
    6968  }
    6969  }
    6970  }
    6971  }
    6972 
    6978  {
    6979  auto result = *this;
    6980  ++(*this);
    6981  return result;
    6982  }
    6983 
    6989  {
    6990  assert(m_object != nullptr);
    6991 
    6992  switch (m_object->m_type)
    6993  {
    6995  {
    6996  std::advance(m_it.object_iterator, 1);
    6997  break;
    6998  }
    6999 
    7001  {
    7002  std::advance(m_it.array_iterator, 1);
    7003  break;
    7004  }
    7005 
    7006  default:
    7007  {
    7008  ++m_it.primitive_iterator;
    7009  break;
    7010  }
    7011  }
    7012 
    7013  return *this;
    7014  }
    7015 
    7021  {
    7022  auto result = *this;
    7023  --(*this);
    7024  return result;
    7025  }
    7026 
    7032  {
    7033  assert(m_object != nullptr);
    7034 
    7035  switch (m_object->m_type)
    7036  {
    7038  {
    7039  std::advance(m_it.object_iterator, -1);
    7040  break;
    7041  }
    7042 
    7044  {
    7045  std::advance(m_it.array_iterator, -1);
    7046  break;
    7047  }
    7048 
    7049  default:
    7050  {
    7051  --m_it.primitive_iterator;
    7052  break;
    7053  }
    7054  }
    7055 
    7056  return *this;
    7057  }
    7058 
    7063  bool operator==(const const_iterator& other) const
    7064  {
    7065  // if objects are not the same, the comparison is undefined
    7066  if (m_object != other.m_object)
    7067  {
    7068  throw std::domain_error("cannot compare iterators of different containers");
    7069  }
    7070 
    7071  assert(m_object != nullptr);
    7072 
    7073  switch (m_object->m_type)
    7074  {
    7076  {
    7077  return (m_it.object_iterator == other.m_it.object_iterator);
    7078  }
    7079 
    7081  {
    7082  return (m_it.array_iterator == other.m_it.array_iterator);
    7083  }
    7084 
    7085  default:
    7086  {
    7087  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    7088  }
    7089  }
    7090  }
    7091 
    7096  bool operator!=(const const_iterator& other) const
    7097  {
    7098  return not operator==(other);
    7099  }
    7100 
    7105  bool operator<(const const_iterator& other) const
    7106  {
    7107  // if objects are not the same, the comparison is undefined
    7108  if (m_object != other.m_object)
    7109  {
    7110  throw std::domain_error("cannot compare iterators of different containers");
    7111  }
    7112 
    7113  assert(m_object != nullptr);
    7114 
    7115  switch (m_object->m_type)
    7116  {
    7118  {
    7119  throw std::domain_error("cannot compare order of object iterators");
    7120  }
    7121 
    7123  {
    7124  return (m_it.array_iterator < other.m_it.array_iterator);
    7125  }
    7126 
    7127  default:
    7128  {
    7129  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    7130  }
    7131  }
    7132  }
    7133 
    7138  bool operator<=(const const_iterator& other) const
    7139  {
    7140  return not other.operator < (*this);
    7141  }
    7142 
    7147  bool operator>(const const_iterator& other) const
    7148  {
    7149  return not operator<=(other);
    7150  }
    7151 
    7156  bool operator>=(const const_iterator& other) const
    7157  {
    7158  return not operator<(other);
    7159  }
    7160 
    7166  {
    7167  assert(m_object != nullptr);
    7168 
    7169  switch (m_object->m_type)
    7170  {
    7172  {
    7173  throw std::domain_error("cannot use offsets with object iterators");
    7174  }
    7175 
    7177  {
    7178  std::advance(m_it.array_iterator, i);
    7179  break;
    7180  }
    7181 
    7182  default:
    7183  {
    7184  m_it.primitive_iterator += i;
    7185  break;
    7186  }
    7187  }
    7188 
    7189  return *this;
    7190  }
    7191 
    7197  {
    7198  return operator+=(-i);
    7199  }
    7200 
    7206  {
    7207  auto result = *this;
    7208  result += i;
    7209  return result;
    7210  }
    7211 
    7217  {
    7218  auto result = *this;
    7219  result -= i;
    7220  return result;
    7221  }
    7222 
    7228  {
    7229  assert(m_object != nullptr);
    7230 
    7231  switch (m_object->m_type)
    7232  {
    7234  {
    7235  throw std::domain_error("cannot use offsets with object iterators");
    7236  }
    7237 
    7239  {
    7240  return m_it.array_iterator - other.m_it.array_iterator;
    7241  }
    7242 
    7243  default:
    7244  {
    7245  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    7246  }
    7247  }
    7248  }
    7249 
    7255  {
    7256  assert(m_object != nullptr);
    7257 
    7258  switch (m_object->m_type)
    7259  {
    7261  {
    7262  throw std::domain_error("cannot use operator[] for object iterators");
    7263  }
    7264 
    7266  {
    7267  return *std::next(m_it.array_iterator, n);
    7268  }
    7269 
    7271  {
    7272  throw std::out_of_range("cannot get value");
    7273  }
    7274 
    7275  default:
    7276  {
    7277  if (m_it.primitive_iterator == -n)
    7278  {
    7279  return *m_object;
    7280  }
    7281  else
    7282  {
    7283  throw std::out_of_range("cannot get value");
    7284  }
    7285  }
    7286  }
    7287  }
    7288 
    7293  typename object_t::key_type key() const
    7294  {
    7295  assert(m_object != nullptr);
    7296 
    7297  if (m_object->is_object())
    7298  {
    7299  return m_it.object_iterator->first;
    7300  }
    7301  else
    7302  {
    7303  throw std::domain_error("cannot use key() for non-object iterators");
    7304  }
    7305  }
    7306 
    7312  {
    7313  return operator*();
    7314  }
    7315 
    7316  private:
    7318  pointer m_object = nullptr;
    7320  internal_iterator m_it = internal_iterator();
    7321  };
    7322 
    7335  class iterator : public const_iterator
    7336  {
    7337  public:
    7339  using pointer = typename basic_json::pointer;
    7341 
    7343  iterator() = default;
    7344 
    7346  explicit iterator(pointer object) noexcept
    7347  : base_iterator(object)
    7348  {}
    7349 
    7351  iterator(const iterator& other) noexcept
    7352  : base_iterator(other)
    7353  {}
    7354 
    7356  iterator& operator=(iterator other) noexcept(
    7357  std::is_nothrow_move_constructible<pointer>::value and
    7358  std::is_nothrow_move_assignable<pointer>::value and
    7359  std::is_nothrow_move_constructible<internal_iterator>::value and
    7360  std::is_nothrow_move_assignable<internal_iterator>::value
    7361  )
    7362  {
    7363  base_iterator::operator=(other);
    7364  return *this;
    7365  }
    7366 
    7369  {
    7370  return const_cast<reference>(base_iterator::operator*());
    7371  }
    7372 
    7375  {
    7376  return const_cast<pointer>(base_iterator::operator->());
    7377  }
    7378 
    7381  {
    7382  iterator result = *this;
    7383  base_iterator::operator++();
    7384  return result;
    7385  }
    7386 
    7389  {
    7390  base_iterator::operator++();
    7391  return *this;
    7392  }
    7393 
    7396  {
    7397  iterator result = *this;
    7398  base_iterator::operator--();
    7399  return result;
    7400  }
    7401 
    7404  {
    7405  base_iterator::operator--();
    7406  return *this;
    7407  }
    7408 
    7411  {
    7412  base_iterator::operator+=(i);
    7413  return *this;
    7414  }
    7415 
    7418  {
    7419  base_iterator::operator-=(i);
    7420  return *this;
    7421  }
    7422 
    7425  {
    7426  auto result = *this;
    7427  result += i;
    7428  return result;
    7429  }
    7430 
    7433  {
    7434  auto result = *this;
    7435  result -= i;
    7436  return result;
    7437  }
    7438 
    7440  difference_type operator-(const iterator& other) const
    7441  {
    7442  return base_iterator::operator-(other);
    7443  }
    7444 
    7447  {
    7448  return const_cast<reference>(base_iterator::operator[](n));
    7449  }
    7450 
    7453  {
    7454  return const_cast<reference>(base_iterator::value());
    7455  }
    7456  };
    7457 
    7475  template<typename Base>
    7476  class json_reverse_iterator : public std::reverse_iterator<Base>
    7477  {
    7478  public:
    7480  using base_iterator = std::reverse_iterator<Base>;
    7482  using reference = typename Base::reference;
    7483 
    7485  json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
    7486  : base_iterator(it)
    7487  {}
    7488 
    7491  : base_iterator(it)
    7492  {}
    7493 
    7496  {
    7497  return base_iterator::operator++(1);
    7498  }
    7499 
    7502  {
    7503  base_iterator::operator++();
    7504  return *this;
    7505  }
    7506 
    7509  {
    7510  return base_iterator::operator--(1);
    7511  }
    7512 
    7515  {
    7516  base_iterator::operator--();
    7517  return *this;
    7518  }
    7519 
    7522  {
    7523  base_iterator::operator+=(i);
    7524  return *this;
    7525  }
    7526 
    7529  {
    7530  auto result = *this;
    7531  result += i;
    7532  return result;
    7533  }
    7534 
    7537  {
    7538  auto result = *this;
    7539  result -= i;
    7540  return result;
    7541  }
    7542 
    7545  {
    7546  return this->base() - other.base();
    7547  }
    7548 
    7551  {
    7552  return *(this->operator+(n));
    7553  }
    7554 
    7556  typename object_t::key_type key() const
    7557  {
    7558  auto it = --this->base();
    7559  return it.key();
    7560  }
    7561 
    7564  {
    7565  auto it = --this->base();
    7566  return it.operator * ();
    7567  }
    7568  };
    7569 
    7570 
    7571  private:
    7573  // lexer and parser //
    7575 
    7583  class lexer
    7584  {
    7585  public:
    7587  enum class token_type
    7588  {
    7589  uninitialized,
    7590  literal_true,
    7591  literal_false,
    7592  literal_null,
    7593  value_string,
    7594  value_number,
    7595  begin_array,
    7596  begin_object,
    7597  end_array,
    7598  end_object,
    7599  name_separator,
    7600  value_separator,
    7601  parse_error,
    7602  end_of_input
    7603  };
    7604 
    7606  using lexer_char_t = unsigned char;
    7607 
    7609  lexer(const lexer_char_t* buff, const size_t len) noexcept
    7610  : m_content(buff)
    7611  {
    7612  assert(m_content != nullptr);
    7613  m_start = m_cursor = m_content;
    7614  m_limit = m_content + len;
    7615  }
    7616 
    7618  explicit lexer(std::istream& s)
    7619  : m_stream(&s), m_line_buffer()
    7620  {
    7621  // fill buffer
    7622  fill_line_buffer();
    7623  }
    7624 
    7625  // switch off unwanted functions (due to pointer members)
    7626  lexer() = delete;
    7627  lexer(const lexer&) = delete;
    7628  lexer operator=(const lexer&) = delete;
    7629 
    7653  static string_t to_unicode(const std::size_t codepoint1,
    7654  const std::size_t codepoint2 = 0)
    7655  {
    7656  // calculate the code point from the given code points
    7657  std::size_t codepoint = codepoint1;
    7658 
    7659  // check if codepoint1 is a high surrogate
    7660  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    7661  {
    7662  // check if codepoint2 is a low surrogate
    7663  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    7664  {
    7665  codepoint =
    7666  // high surrogate occupies the most significant 22 bits
    7667  (codepoint1 << 10)
    7668  // low surrogate occupies the least significant 15 bits
    7669  + codepoint2
    7670  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7671  // in the result so we have to subtract with:
    7672  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7673  - 0x35FDC00;
    7674  }
    7675  else
    7676  {
    7677  throw std::invalid_argument("missing or wrong low surrogate");
    7678  }
    7679  }
    7680 
    7681  string_t result;
    7682 
    7683  if (codepoint < 0x80)
    7684  {
    7685  // 1-byte characters: 0xxxxxxx (ASCII)
    7686  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7687  }
    7688  else if (codepoint <= 0x7ff)
    7689  {
    7690  // 2-byte characters: 110xxxxx 10xxxxxx
    7691  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7692  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7693  }
    7694  else if (codepoint <= 0xffff)
    7695  {
    7696  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7697  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7698  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7699  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7700  }
    7701  else if (codepoint <= 0x10ffff)
    7702  {
    7703  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7704  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7705  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7706  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7707  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7708  }
    7709  else
    7710  {
    7711  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7712  }
    7713 
    7714  return result;
    7715  }
    7716 
    7718  static std::string token_type_name(const token_type t)
    7719  {
    7720  switch (t)
    7721  {
    7722  case token_type::uninitialized:
    7723  return "<uninitialized>";
    7724  case token_type::literal_true:
    7725  return "true literal";
    7726  case token_type::literal_false:
    7727  return "false literal";
    7728  case token_type::literal_null:
    7729  return "null literal";
    7730  case token_type::value_string:
    7731  return "string literal";
    7732  case token_type::value_number:
    7733  return "number literal";
    7734  case token_type::begin_array:
    7735  return "'['";
    7736  case token_type::begin_object:
    7737  return "'{'";
    7738  case token_type::end_array:
    7739  return "']'";
    7740  case token_type::end_object:
    7741  return "'}'";
    7742  case token_type::name_separator:
    7743  return "':'";
    7744  case token_type::value_separator:
    7745  return "','";
    7746  case token_type::parse_error:
    7747  return "<parse error>";
    7748  case token_type::end_of_input:
    7749  return "end of input";
    7750  default:
    7751  {
    7752  // catch non-enum values
    7753  return "unknown token"; // LCOV_EXCL_LINE
    7754  }
    7755  }
    7756  }
    7757 
    7779  token_type scan()
    7780  {
    7781  while (true)
    7782  {
    7783  // pointer for backtracking information
    7784  m_marker = nullptr;
    7785 
    7786  // remember the begin of the token
    7787  m_start = m_cursor;
    7788  assert(m_start != nullptr);
    7789 
    7790 
    7791  {
    7792  lexer_char_t yych;
    7793  unsigned int yyaccept = 0;
    7794  static const unsigned char yybm[] =
    7795  {
    7796  0, 0, 0, 0, 0, 0, 0, 0,
    7797  0, 32, 32, 0, 0, 32, 0, 0,
    7798  0, 0, 0, 0, 0, 0, 0, 0,
    7799  0, 0, 0, 0, 0, 0, 0, 0,
    7800  160, 128, 0, 128, 128, 128, 128, 128,
    7801  128, 128, 128, 128, 128, 128, 128, 128,
    7802  192, 192, 192, 192, 192, 192, 192, 192,
    7803  192, 192, 128, 128, 128, 128, 128, 128,
    7804  128, 128, 128, 128, 128, 128, 128, 128,
    7805  128, 128, 128, 128, 128, 128, 128, 128,
    7806  128, 128, 128, 128, 128, 128, 128, 128,
    7807  128, 128, 128, 128, 0, 128, 128, 128,
    7808  128, 128, 128, 128, 128, 128, 128, 128,
    7809  128, 128, 128, 128, 128, 128, 128, 128,
    7810  128, 128, 128, 128, 128, 128, 128, 128,
    7811  128, 128, 128, 128, 128, 128, 128, 128,
    7812  128, 128, 128, 128, 128, 128, 128, 128,
    7813  128, 128, 128, 128, 128, 128, 128, 128,
    7814  128, 128, 128, 128, 128, 128, 128, 128,
    7815  128, 128, 128, 128, 128, 128, 128, 128,
    7816  128, 128, 128, 128, 128, 128, 128, 128,
    7817  128, 128, 128, 128, 128, 128, 128, 128,
    7818  128, 128, 128, 128, 128, 128, 128, 128,
    7819  128, 128, 128, 128, 128, 128, 128, 128,
    7820  128, 128, 128, 128, 128, 128, 128, 128,
    7821  128, 128, 128, 128, 128, 128, 128, 128,
    7822  128, 128, 128, 128, 128, 128, 128, 128,
    7823  128, 128, 128, 128, 128, 128, 128, 128,
    7824  128, 128, 128, 128, 128, 128, 128, 128,
    7825  128, 128, 128, 128, 128, 128, 128, 128,
    7826  128, 128, 128, 128, 128, 128, 128, 128,
    7827  128, 128, 128, 128, 128, 128, 128, 128,
    7828  };
    7829  if ((m_limit - m_cursor) < 5)
    7830  {
    7831  fill_line_buffer();
    7832  }
    7833  yych = *m_cursor;
    7834  if (yybm[0 + yych] & 32)
    7835  {
    7836  goto basic_json_parser_6;
    7837  }
    7838  if (yych <= '\\')
    7839  {
    7840  if (yych <= '-')
    7841  {
    7842  if (yych <= '"')
    7843  {
    7844  if (yych <= 0x00)
    7845  {
    7846  goto basic_json_parser_2;
    7847  }
    7848  if (yych <= '!')
    7849  {
    7850  goto basic_json_parser_4;
    7851  }
    7852  goto basic_json_parser_9;
    7853  }
    7854  else
    7855  {
    7856  if (yych <= '+')
    7857  {
    7858  goto basic_json_parser_4;
    7859  }
    7860  if (yych <= ',')
    7861  {
    7862  goto basic_json_parser_10;
    7863  }
    7864  goto basic_json_parser_12;
    7865  }
    7866  }
    7867  else
    7868  {
    7869  if (yych <= '9')
    7870  {
    7871  if (yych <= '/')
    7872  {
    7873  goto basic_json_parser_4;
    7874  }
    7875  if (yych <= '0')
    7876  {
    7877  goto basic_json_parser_13;
    7878  }
    7879  goto basic_json_parser_15;
    7880  }
    7881  else
    7882  {
    7883  if (yych <= ':')
    7884  {
    7885  goto basic_json_parser_17;
    7886  }
    7887  if (yych == '[')
    7888  {
    7889  goto basic_json_parser_19;
    7890  }
    7891  goto basic_json_parser_4;
    7892  }
    7893  }
    7894  }
    7895  else
    7896  {
    7897  if (yych <= 't')
    7898  {
    7899  if (yych <= 'f')
    7900  {
    7901  if (yych <= ']')
    7902  {
    7903  goto basic_json_parser_21;
    7904  }
    7905  if (yych <= 'e')
    7906  {
    7907  goto basic_json_parser_4;
    7908  }
    7909  goto basic_json_parser_23;
    7910  }
    7911  else
    7912  {
    7913  if (yych == 'n')
    7914  {
    7915  goto basic_json_parser_24;
    7916  }
    7917  if (yych <= 's')
    7918  {
    7919  goto basic_json_parser_4;
    7920  }
    7921  goto basic_json_parser_25;
    7922  }
    7923  }
    7924  else
    7925  {
    7926  if (yych <= '|')
    7927  {
    7928  if (yych == '{')
    7929  {
    7930  goto basic_json_parser_26;
    7931  }
    7932  goto basic_json_parser_4;
    7933  }
    7934  else
    7935  {
    7936  if (yych <= '}')
    7937  {
    7938  goto basic_json_parser_28;
    7939  }
    7940  if (yych == 0xEF)
    7941  {
    7942  goto basic_json_parser_30;
    7943  }
    7944  goto basic_json_parser_4;
    7945  }
    7946  }
    7947  }
    7948 basic_json_parser_2:
    7949  ++m_cursor;
    7950  {
    7951  last_token_type = token_type::end_of_input;
    7952  break;
    7953  }
    7954 basic_json_parser_4:
    7955  ++m_cursor;
    7956 basic_json_parser_5:
    7957  {
    7958  last_token_type = token_type::parse_error;
    7959  break;
    7960  }
    7961 basic_json_parser_6:
    7962  ++m_cursor;
    7963  if (m_limit <= m_cursor)
    7964  {
    7965  fill_line_buffer();
    7966  }
    7967  yych = *m_cursor;
    7968  if (yybm[0 + yych] & 32)
    7969  {
    7970  goto basic_json_parser_6;
    7971  }
    7972  {
    7973  continue;
    7974  }
    7975 basic_json_parser_9:
    7976  yyaccept = 0;
    7977  yych = *(m_marker = ++m_cursor);
    7978  if (yych <= 0x1F)
    7979  {
    7980  goto basic_json_parser_5;
    7981  }
    7982  goto basic_json_parser_32;
    7983 basic_json_parser_10:
    7984  ++m_cursor;
    7985  {
    7986  last_token_type = token_type::value_separator;
    7987  break;
    7988  }
    7989 basic_json_parser_12:
    7990  yych = *++m_cursor;
    7991  if (yych <= '/')
    7992  {
    7993  goto basic_json_parser_5;
    7994  }
    7995  if (yych <= '0')
    7996  {
    7997  goto basic_json_parser_13;
    7998  }
    7999  if (yych <= '9')
    8000  {
    8001  goto basic_json_parser_15;
    8002  }
    8003  goto basic_json_parser_5;
    8004 basic_json_parser_13:
    8005  yyaccept = 1;
    8006  yych = *(m_marker = ++m_cursor);
    8007  if (yych <= 'D')
    8008  {
    8009  if (yych == '.')
    8010  {
    8011  goto basic_json_parser_37;
    8012  }
    8013  }
    8014  else
    8015  {
    8016  if (yych <= 'E')
    8017  {
    8018  goto basic_json_parser_38;
    8019  }
    8020  if (yych == 'e')
    8021  {
    8022  goto basic_json_parser_38;
    8023  }
    8024  }
    8025 basic_json_parser_14:
    8026  {
    8027  last_token_type = token_type::value_number;
    8028  break;
    8029  }
    8030 basic_json_parser_15:
    8031  yyaccept = 1;
    8032  m_marker = ++m_cursor;
    8033  if ((m_limit - m_cursor) < 3)
    8034  {
    8035  fill_line_buffer();
    8036  }
    8037  yych = *m_cursor;
    8038  if (yybm[0 + yych] & 64)
    8039  {
    8040  goto basic_json_parser_15;
    8041  }
    8042  if (yych <= 'D')
    8043  {
    8044  if (yych == '.')
    8045  {
    8046  goto basic_json_parser_37;
    8047  }
    8048  goto basic_json_parser_14;
    8049  }
    8050  else
    8051  {
    8052  if (yych <= 'E')
    8053  {
    8054  goto basic_json_parser_38;
    8055  }
    8056  if (yych == 'e')
    8057  {
    8058  goto basic_json_parser_38;
    8059  }
    8060  goto basic_json_parser_14;
    8061  }
    8062 basic_json_parser_17:
    8063  ++m_cursor;
    8064  {
    8065  last_token_type = token_type::name_separator;
    8066  break;
    8067  }
    8068 basic_json_parser_19:
    8069  ++m_cursor;
    8070  {
    8071  last_token_type = token_type::begin_array;
    8072  break;
    8073  }
    8074 basic_json_parser_21:
    8075  ++m_cursor;
    8076  {
    8077  last_token_type = token_type::end_array;
    8078  break;
    8079  }
    8080 basic_json_parser_23:
    8081  yyaccept = 0;
    8082  yych = *(m_marker = ++m_cursor);
    8083  if (yych == 'a')
    8084  {
    8085  goto basic_json_parser_39;
    8086  }
    8087  goto basic_json_parser_5;
    8088 basic_json_parser_24:
    8089  yyaccept = 0;
    8090  yych = *(m_marker = ++m_cursor);
    8091  if (yych == 'u')
    8092  {
    8093  goto basic_json_parser_40;
    8094  }
    8095  goto basic_json_parser_5;
    8096 basic_json_parser_25:
    8097  yyaccept = 0;
    8098  yych = *(m_marker = ++m_cursor);
    8099  if (yych == 'r')
    8100  {
    8101  goto basic_json_parser_41;
    8102  }
    8103  goto basic_json_parser_5;
    8104 basic_json_parser_26:
    8105  ++m_cursor;
    8106  {
    8107  last_token_type = token_type::begin_object;
    8108  break;
    8109  }
    8110 basic_json_parser_28:
    8111  ++m_cursor;
    8112  {
    8113  last_token_type = token_type::end_object;
    8114  break;
    8115  }
    8116 basic_json_parser_30:
    8117  yyaccept = 0;
    8118  yych = *(m_marker = ++m_cursor);
    8119  if (yych == 0xBB)
    8120  {
    8121  goto basic_json_parser_42;
    8122  }
    8123  goto basic_json_parser_5;
    8124 basic_json_parser_31:
    8125  ++m_cursor;
    8126  if (m_limit <= m_cursor)
    8127  {
    8128  fill_line_buffer();
    8129  }
    8130  yych = *m_cursor;
    8131 basic_json_parser_32:
    8132  if (yybm[0 + yych] & 128)
    8133  {
    8134  goto basic_json_parser_31;
    8135  }
    8136  if (yych <= 0x1F)
    8137  {
    8138  goto basic_json_parser_33;
    8139  }
    8140  if (yych <= '"')
    8141  {
    8142  goto basic_json_parser_34;
    8143  }
    8144  goto basic_json_parser_36;
    8145 basic_json_parser_33:
    8146  m_cursor = m_marker;
    8147  if (yyaccept == 0)
    8148  {
    8149  goto basic_json_parser_5;
    8150  }
    8151  else
    8152  {
    8153  goto basic_json_parser_14;
    8154  }
    8155 basic_json_parser_34:
    8156  ++m_cursor;
    8157  {
    8158  last_token_type = token_type::value_string;
    8159  break;
    8160  }
    8161 basic_json_parser_36:
    8162  ++m_cursor;
    8163  if (m_limit <= m_cursor)
    8164  {
    8165  fill_line_buffer();
    8166  }
    8167  yych = *m_cursor;
    8168  if (yych <= 'e')
    8169  {
    8170  if (yych <= '/')
    8171  {
    8172  if (yych == '"')
    8173  {
    8174  goto basic_json_parser_31;
    8175  }
    8176  if (yych <= '.')
    8177  {
    8178  goto basic_json_parser_33;
    8179  }
    8180  goto basic_json_parser_31;
    8181  }
    8182  else
    8183  {
    8184  if (yych <= '\\')
    8185  {
    8186  if (yych <= '[')
    8187  {
    8188  goto basic_json_parser_33;
    8189  }
    8190  goto basic_json_parser_31;
    8191  }
    8192  else
    8193  {
    8194  if (yych == 'b')
    8195  {
    8196  goto basic_json_parser_31;
    8197  }
    8198  goto basic_json_parser_33;
    8199  }
    8200  }
    8201  }
    8202  else
    8203  {
    8204  if (yych <= 'q')
    8205  {
    8206  if (yych <= 'f')
    8207  {
    8208  goto basic_json_parser_31;
    8209  }
    8210  if (yych == 'n')
    8211  {
    8212  goto basic_json_parser_31;
    8213  }
    8214  goto basic_json_parser_33;
    8215  }
    8216  else
    8217  {
    8218  if (yych <= 's')
    8219  {
    8220  if (yych <= 'r')
    8221  {
    8222  goto basic_json_parser_31;
    8223  }
    8224  goto basic_json_parser_33;
    8225  }
    8226  else
    8227  {
    8228  if (yych <= 't')
    8229  {
    8230  goto basic_json_parser_31;
    8231  }
    8232  if (yych <= 'u')
    8233  {
    8234  goto basic_json_parser_43;
    8235  }
    8236  goto basic_json_parser_33;
    8237  }
    8238  }
    8239  }
    8240 basic_json_parser_37:
    8241  yych = *++m_cursor;
    8242  if (yych <= '/')
    8243  {
    8244  goto basic_json_parser_33;
    8245  }
    8246  if (yych <= '9')
    8247  {
    8248  goto basic_json_parser_44;
    8249  }
    8250  goto basic_json_parser_33;
    8251 basic_json_parser_38:
    8252  yych = *++m_cursor;
    8253  if (yych <= ',')
    8254  {
    8255  if (yych == '+')
    8256  {
    8257  goto basic_json_parser_46;
    8258  }
    8259  goto basic_json_parser_33;
    8260  }
    8261  else
    8262  {
    8263  if (yych <= '-')
    8264  {
    8265  goto basic_json_parser_46;
    8266  }
    8267  if (yych <= '/')
    8268  {
    8269  goto basic_json_parser_33;
    8270  }
    8271  if (yych <= '9')
    8272  {
    8273  goto basic_json_parser_47;
    8274  }
    8275  goto basic_json_parser_33;
    8276  }
    8277 basic_json_parser_39:
    8278  yych = *++m_cursor;
    8279  if (yych == 'l')
    8280  {
    8281  goto basic_json_parser_49;
    8282  }
    8283  goto basic_json_parser_33;
    8284 basic_json_parser_40:
    8285  yych = *++m_cursor;
    8286  if (yych == 'l')
    8287  {
    8288  goto basic_json_parser_50;
    8289  }
    8290  goto basic_json_parser_33;
    8291 basic_json_parser_41:
    8292  yych = *++m_cursor;
    8293  if (yych == 'u')
    8294  {
    8295  goto basic_json_parser_51;
    8296  }
    8297  goto basic_json_parser_33;
    8298 basic_json_parser_42:
    8299  yych = *++m_cursor;
    8300  if (yych == 0xBF)
    8301  {
    8302  goto basic_json_parser_52;
    8303  }
    8304  goto basic_json_parser_33;
    8305 basic_json_parser_43:
    8306  ++m_cursor;
    8307  if (m_limit <= m_cursor)
    8308  {
    8309  fill_line_buffer();
    8310  }
    8311  yych = *m_cursor;
    8312  if (yych <= '@')
    8313  {
    8314  if (yych <= '/')
    8315  {
    8316  goto basic_json_parser_33;
    8317  }
    8318  if (yych <= '9')
    8319  {
    8320  goto basic_json_parser_54;
    8321  }
    8322  goto basic_json_parser_33;
    8323  }
    8324  else
    8325  {
    8326  if (yych <= 'F')
    8327  {
    8328  goto basic_json_parser_54;
    8329  }
    8330  if (yych <= '`')
    8331  {
    8332  goto basic_json_parser_33;
    8333  }
    8334  if (yych <= 'f')
    8335  {
    8336  goto basic_json_parser_54;
    8337  }
    8338  goto basic_json_parser_33;
    8339  }
    8340 basic_json_parser_44:
    8341  yyaccept = 1;
    8342  m_marker = ++m_cursor;
    8343  if ((m_limit - m_cursor) < 3)
    8344  {
    8345  fill_line_buffer();
    8346  }
    8347  yych = *m_cursor;
    8348  if (yych <= 'D')
    8349  {
    8350  if (yych <= '/')
    8351  {
    8352  goto basic_json_parser_14;
    8353  }
    8354  if (yych <= '9')
    8355  {
    8356  goto basic_json_parser_44;
    8357  }
    8358  goto basic_json_parser_14;
    8359  }
    8360  else
    8361  {
    8362  if (yych <= 'E')
    8363  {
    8364  goto basic_json_parser_38;
    8365  }
    8366  if (yych == 'e')
    8367  {
    8368  goto basic_json_parser_38;
    8369  }
    8370  goto basic_json_parser_14;
    8371  }
    8372 basic_json_parser_46:
    8373  yych = *++m_cursor;
    8374  if (yych <= '/')
    8375  {
    8376  goto basic_json_parser_33;
    8377  }
    8378  if (yych >= ':')
    8379  {
    8380  goto basic_json_parser_33;
    8381  }
    8382 basic_json_parser_47:
    8383  ++m_cursor;
    8384  if (m_limit <= m_cursor)
    8385  {
    8386  fill_line_buffer();
    8387  }
    8388  yych = *m_cursor;
    8389  if (yych <= '/')
    8390  {
    8391  goto basic_json_parser_14;
    8392  }
    8393  if (yych <= '9')
    8394  {
    8395  goto basic_json_parser_47;
    8396  }
    8397  goto basic_json_parser_14;
    8398 basic_json_parser_49:
    8399  yych = *++m_cursor;
    8400  if (yych == 's')
    8401  {
    8402  goto basic_json_parser_55;
    8403  }
    8404  goto basic_json_parser_33;
    8405 basic_json_parser_50:
    8406  yych = *++m_cursor;
    8407  if (yych == 'l')
    8408  {
    8409  goto basic_json_parser_56;
    8410  }
    8411  goto basic_json_parser_33;
    8412 basic_json_parser_51:
    8413  yych = *++m_cursor;
    8414  if (yych == 'e')
    8415  {
    8416  goto basic_json_parser_58;
    8417  }
    8418  goto basic_json_parser_33;
    8419 basic_json_parser_52:
    8420  ++m_cursor;
    8421  {
    8422  continue;
    8423  }
    8424 basic_json_parser_54:
    8425  ++m_cursor;
    8426  if (m_limit <= m_cursor)
    8427  {
    8428  fill_line_buffer();
    8429  }
    8430  yych = *m_cursor;
    8431  if (yych <= '@')
    8432  {
    8433  if (yych <= '/')
    8434  {
    8435  goto basic_json_parser_33;
    8436  }
    8437  if (yych <= '9')
    8438  {
    8439  goto basic_json_parser_60;
    8440  }
    8441  goto basic_json_parser_33;
    8442  }
    8443  else
    8444  {
    8445  if (yych <= 'F')
    8446  {
    8447  goto basic_json_parser_60;
    8448  }
    8449  if (yych <= '`')
    8450  {
    8451  goto basic_json_parser_33;
    8452  }
    8453  if (yych <= 'f')
    8454  {
    8455  goto basic_json_parser_60;
    8456  }
    8457  goto basic_json_parser_33;
    8458  }
    8459 basic_json_parser_55:
    8460  yych = *++m_cursor;
    8461  if (yych == 'e')
    8462  {
    8463  goto basic_json_parser_61;
    8464  }
    8465  goto basic_json_parser_33;
    8466 basic_json_parser_56:
    8467  ++m_cursor;
    8468  {
    8469  last_token_type = token_type::literal_null;
    8470  break;
    8471  }
    8472 basic_json_parser_58:
    8473  ++m_cursor;
    8474  {
    8475  last_token_type = token_type::literal_true;
    8476  break;
    8477  }
    8478 basic_json_parser_60:
    8479  ++m_cursor;
    8480  if (m_limit <= m_cursor)
    8481  {
    8482  fill_line_buffer();
    8483  }
    8484  yych = *m_cursor;
    8485  if (yych <= '@')
    8486  {
    8487  if (yych <= '/')
    8488  {
    8489  goto basic_json_parser_33;
    8490  }
    8491  if (yych <= '9')
    8492  {
    8493  goto basic_json_parser_63;
    8494  }
    8495  goto basic_json_parser_33;
    8496  }
    8497  else
    8498  {
    8499  if (yych <= 'F')
    8500  {
    8501  goto basic_json_parser_63;
    8502  }
    8503  if (yych <= '`')
    8504  {
    8505  goto basic_json_parser_33;
    8506  }
    8507  if (yych <= 'f')
    8508  {
    8509  goto basic_json_parser_63;
    8510  }
    8511  goto basic_json_parser_33;
    8512  }
    8513 basic_json_parser_61:
    8514  ++m_cursor;
    8515  {
    8516  last_token_type = token_type::literal_false;
    8517  break;
    8518  }
    8519 basic_json_parser_63:
    8520  ++m_cursor;
    8521  if (m_limit <= m_cursor)
    8522  {
    8523  fill_line_buffer();
    8524  }
    8525  yych = *m_cursor;
    8526  if (yych <= '@')
    8527  {
    8528  if (yych <= '/')
    8529  {
    8530  goto basic_json_parser_33;
    8531  }
    8532  if (yych <= '9')
    8533  {
    8534  goto basic_json_parser_31;
    8535  }
    8536  goto basic_json_parser_33;
    8537  }
    8538  else
    8539  {
    8540  if (yych <= 'F')
    8541  {
    8542  goto basic_json_parser_31;
    8543  }
    8544  if (yych <= '`')
    8545  {
    8546  goto basic_json_parser_33;
    8547  }
    8548  if (yych <= 'f')
    8549  {
    8550  goto basic_json_parser_31;
    8551  }
    8552  goto basic_json_parser_33;
    8553  }
    8554  }
    8555 
    8556  }
    8557 
    8558  return last_token_type;
    8559  }
    8560 
    8589  void fill_line_buffer()
    8590  {
    8591  // number of processed characters (p)
    8592  const auto offset_start = m_start - m_content;
    8593  // offset for m_marker wrt. to m_start
    8594  const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
    8595  // number of unprocessed characters (u)
    8596  const auto offset_cursor = m_cursor - m_start;
    8597 
    8598  // no stream is used or end of file is reached
    8599  if (m_stream == nullptr or m_stream->eof())
    8600  {
    8601  // copy unprocessed characters to line buffer
    8602  m_line_buffer.clear();
    8603  for (m_cursor = m_start; m_cursor != m_limit; ++m_cursor)
    8604  {
    8605  m_line_buffer.append(1, static_cast<const char>(*m_cursor));
    8606  }
    8607 
    8608  // append 5 characters (size of longest keyword "false") to
    8609  // make sure that there is sufficient space between m_cursor
    8610  // and m_limit
    8611  m_line_buffer.append(5, '\0');
    8612  }
    8613  else
    8614  {
    8615  // delete processed characters from line buffer
    8616  m_line_buffer.erase(0, static_cast<size_t>(offset_start));
    8617  // read next line from input stream
    8618  std::string line;
    8619  std::getline(*m_stream, line);
    8620  // add line with newline symbol to the line buffer
    8621  m_line_buffer += line + "\n";
    8622  }
    8623 
    8624  // set pointers
    8625  m_content = reinterpret_cast<const lexer_char_t*>(m_line_buffer.c_str());
    8626  assert(m_content != nullptr);
    8627  m_start = m_content;
    8628  m_marker = m_start + offset_marker;
    8629  m_cursor = m_start + offset_cursor;
    8630  m_limit = m_start + m_line_buffer.size();
    8631  }
    8632 
    8634  string_t get_token_string() const
    8635  {
    8636  assert(m_start != nullptr);
    8637  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    8638  static_cast<size_t>(m_cursor - m_start));
    8639  }
    8640 
    8698  string_t get_string() const
    8699  {
    8700  assert(m_cursor - m_start >= 2);
    8701 
    8702  string_t result;
    8703  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    8704 
    8705  // iterate the result between the quotes
    8706  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    8707  {
    8708  // process escaped characters
    8709  if (*i == '\\')
    8710  {
    8711  // read next character
    8712  ++i;
    8713 
    8714  switch (*i)
    8715  {
    8716  // the default escapes
    8717  case 't':
    8718  {
    8719  result += "\t";
    8720  break;
    8721  }
    8722  case 'b':
    8723  {
    8724  result += "\b";
    8725  break;
    8726  }
    8727  case 'f':
    8728  {
    8729  result += "\f";
    8730  break;
    8731  }
    8732  case 'n':
    8733  {
    8734  result += "\n";
    8735  break;
    8736  }
    8737  case 'r':
    8738  {
    8739  result += "\r";
    8740  break;
    8741  }
    8742  case '\\':
    8743  {
    8744  result += "\\";
    8745  break;
    8746  }
    8747  case '/':
    8748  {
    8749  result += "/";
    8750  break;
    8751  }
    8752  case '"':
    8753  {
    8754  result += "\"";
    8755  break;
    8756  }
    8757 
    8758  // unicode
    8759  case 'u':
    8760  {
    8761  // get code xxxx from uxxxx
    8762  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8763  4).c_str(), nullptr, 16);
    8764 
    8765  // check if codepoint is a high surrogate
    8766  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8767  {
    8768  // make sure there is a subsequent unicode
    8769  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8770  {
    8771  throw std::invalid_argument("missing low surrogate");
    8772  }
    8773 
    8774  // get code yyyy from uxxxx\uyyyy
    8775  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8776  (i + 7), 4).c_str(), nullptr, 16);
    8777  result += to_unicode(codepoint, codepoint2);
    8778  // skip the next 10 characters (xxxx\uyyyy)
    8779  i += 10;
    8780  }
    8781  else
    8782  {
    8783  // add unicode character(s)
    8784  result += to_unicode(codepoint);
    8785  // skip the next four characters (xxxx)
    8786  i += 4;
    8787  }
    8788  break;
    8789  }
    8790  }
    8791  }
    8792  else
    8793  {
    8794  // all other characters are just copied to the end of the
    8795  // string
    8796  result.append(1, static_cast<typename string_t::value_type>(*i));
    8797  }
    8798  }
    8799 
    8800  return result;
    8801  }
    8802 
    8818  long double str_to_float_t(long double* /* type */, char** endptr) const
    8819  {
    8820  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8821  }
    8822 
    8838  double str_to_float_t(double* /* type */, char** endptr) const
    8839  {
    8840  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8841  }
    8842 
    8858  float str_to_float_t(float* /* type */, char** endptr) const
    8859  {
    8860  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8861  }
    8862 
    8884  void get_number(basic_json& result) const
    8885  {
    8886  assert(m_start != nullptr);
    8887 
    8888  const lexer::lexer_char_t* curptr = m_start;
    8889 
    8890  // accumulate the integer conversion result (unsigned for now)
    8891  number_unsigned_t value = 0;
    8892 
    8893  // maximum absolute value of the relevant integer type
    8894  number_unsigned_t max;
    8895 
    8896  // temporarily store the type to avoid unecessary bitfield access
    8897  value_t type;
    8898 
    8899  // look for sign
    8900  if (*curptr == '-')
    8901  {
    8902  type = value_t::number_integer;
    8903  max = static_cast<uint64_t>((std::numeric_limits<number_integer_t>::max)()) + 1;
    8904  curptr++;
    8905  }
    8906  else
    8907  {
    8908  type = value_t::number_unsigned;
    8909  max = static_cast<uint64_t>((std::numeric_limits<number_unsigned_t>::max)());
    8910  }
    8911 
    8912  // count the significant figures
    8913  for (; curptr < m_cursor; curptr++)
    8914  {
    8915  // quickly skip tests if a digit
    8916  if (*curptr < '0' || *curptr > '9')
    8917  {
    8918  if (*curptr == '.')
    8919  {
    8920  // don't count '.' but change to float
    8921  type = value_t::number_float;
    8922  continue;
    8923  }
    8924  // assume exponent (if not then will fail parse): change to
    8925  // float, stop counting and record exponent details
    8926  type = value_t::number_float;
    8927  break;
    8928  }
    8929 
    8930  // skip if definitely not an integer
    8931  if (type != value_t::number_float)
    8932  {
    8933  // multiply last value by ten and add the new digit
    8934  auto temp = value * 10 + *curptr - '0';
    8935 
    8936  // test for overflow
    8937  if (temp < value || temp > max)
    8938  {
    8939  // overflow
    8940  type = value_t::number_float;
    8941  }
    8942  else
    8943  {
    8944  // no overflow - save it
    8945  value = temp;
    8946  }
    8947  }
    8948  }
    8949 
    8950  // save the value (if not a float)
    8951  if (type == value_t::number_unsigned)
    8952  {
    8953  result.m_value.number_unsigned = value;
    8954  }
    8955  else if (type == value_t::number_integer)
    8956  {
    8957  result.m_value.number_integer = -static_cast<number_integer_t>(value);
    8958  }
    8959  else
    8960  {
    8961  // parse with strtod
    8962  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
    8963  }
    8964 
    8965  // save the type
    8966  result.m_type = type;
    8967  }
    8968 
    8969  private:
    8971  std::istream* m_stream = nullptr;
    8973  string_t m_line_buffer {};
    8975  const lexer_char_t* m_content = nullptr;
    8977  const lexer_char_t* m_start = nullptr;
    8979  const lexer_char_t* m_marker = nullptr;
    8981  const lexer_char_t* m_cursor = nullptr;
    8983  const lexer_char_t* m_limit = nullptr;
    8985  token_type last_token_type = token_type::end_of_input;
    8986  };
    8987 
    8993  class parser
    8994  {
    8995  public:
    8997  parser(const char* buff, const parser_callback_t cb = nullptr)
    8998  : callback(cb),
    8999  m_lexer(reinterpret_cast<const typename lexer::lexer_char_t*>(buff), strlen(buff))
    9000  {}
    9001 
    9003  parser(std::istream& is, const parser_callback_t cb = nullptr)
    9004  : callback(cb), m_lexer(is)
    9005  {}
    9006 
    9008  template<class IteratorType, typename std::enable_if<
    9009  std::is_same<typename std::iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value
    9010  , int>::type
    9011  = 0>
    9012  parser(IteratorType first, IteratorType last, const parser_callback_t cb = nullptr)
    9013  : callback(cb),
    9014  m_lexer(reinterpret_cast<const typename lexer::lexer_char_t*>(&(*first)),
    9015  static_cast<size_t>(std::distance(first, last)))
    9016  {}
    9017 
    9019  basic_json parse()
    9020  {
    9021  // read first token
    9022  get_token();
    9023 
    9024  basic_json result = parse_internal(true);
    9025  result.assert_invariant();
    9026 
    9027  expect(lexer::token_type::end_of_input);
    9028 
    9029  // return parser result and replace it with null in case the
    9030  // top-level value was discarded by the callback function
    9031  return result.is_discarded() ? basic_json() : std::move(result);
    9032  }
    9033 
    9034  private:
    9036  basic_json parse_internal(bool keep)
    9037  {
    9038  auto result = basic_json(value_t::discarded);
    9039 
    9040  switch (last_token)
    9041  {
    9042  case lexer::token_type::begin_object:
    9043  {
    9044  if (keep and (not callback
    9045  or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0)))
    9046  {
    9047  // explicitly set result to object to cope with {}
    9048  result.m_type = value_t::object;
    9049  result.m_value = value_t::object;
    9050  }
    9051 
    9052  // read next token
    9053  get_token();
    9054 
    9055  // closing } -> we are done
    9056  if (last_token == lexer::token_type::end_object)
    9057  {
    9058  get_token();
    9059  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    9060  {
    9061  result = basic_json(value_t::discarded);
    9062  }
    9063  return result;
    9064  }
    9065 
    9066  // no comma is expected here
    9067  unexpect(lexer::token_type::value_separator);
    9068 
    9069  // otherwise: parse key-value pairs
    9070  do
    9071  {
    9072  // ugly, but could be fixed with loop reorganization
    9073  if (last_token == lexer::token_type::value_separator)
    9074  {
    9075  get_token();
    9076  }
    9077 
    9078  // store key
    9079  expect(lexer::token_type::value_string);
    9080  const auto key = m_lexer.get_string();
    9081 
    9082  bool keep_tag = false;
    9083  if (keep)
    9084  {
    9085  if (callback)
    9086  {
    9087  basic_json k(key);
    9088  keep_tag = callback(depth, parse_event_t::key, k);
    9089  }
    9090  else
    9091  {
    9092  keep_tag = true;
    9093  }
    9094  }
    9095 
    9096  // parse separator (:)
    9097  get_token();
    9098  expect(lexer::token_type::name_separator);
    9099 
    9100  // parse and add value
    9101  get_token();
    9102  auto value = parse_internal(keep);
    9103  if (keep and keep_tag and not value.is_discarded())
    9104  {
    9105  result[key] = std::move(value);
    9106  }
    9107  }
    9108  while (last_token == lexer::token_type::value_separator);
    9109 
    9110  // closing }
    9111  expect(lexer::token_type::end_object);
    9112  get_token();
    9113  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    9114  {
    9115  result = basic_json(value_t::discarded);
    9116  }
    9117 
    9118  return result;
    9119  }
    9120 
    9121  case lexer::token_type::begin_array:
    9122  {
    9123  if (keep and (not callback
    9124  or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0)))
    9125  {
    9126  // explicitly set result to object to cope with []
    9127  result.m_type = value_t::array;
    9128  result.m_value = value_t::array;
    9129  }
    9130 
    9131  // read next token
    9132  get_token();
    9133 
    9134  // closing ] -> we are done
    9135  if (last_token == lexer::token_type::end_array)
    9136  {
    9137  get_token();
    9138  if (callback and not callback(--depth, parse_event_t::array_end, result))
    9139  {
    9140  result = basic_json(value_t::discarded);
    9141  }
    9142  return result;
    9143  }
    9144 
    9145  // no comma is expected here
    9146  unexpect(lexer::token_type::value_separator);
    9147 
    9148  // otherwise: parse values
    9149  do
    9150  {
    9151  // ugly, but could be fixed with loop reorganization
    9152  if (last_token == lexer::token_type::value_separator)
    9153  {
    9154  get_token();
    9155  }
    9156 
    9157  // parse value
    9158  auto value = parse_internal(keep);
    9159  if (keep and not value.is_discarded())
    9160  {
    9161  result.push_back(std::move(value));
    9162  }
    9163  }
    9164  while (last_token == lexer::token_type::value_separator);
    9165 
    9166  // closing ]
    9167  expect(lexer::token_type::end_array);
    9168  get_token();
    9169  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    9170  {
    9171  result = basic_json(value_t::discarded);
    9172  }
    9173 
    9174  return result;
    9175  }
    9176 
    9177  case lexer::token_type::literal_null:
    9178  {
    9179  get_token();
    9180  result.m_type = value_t::null;
    9181  break;
    9182  }
    9183 
    9184  case lexer::token_type::value_string:
    9185  {
    9186  const auto s = m_lexer.get_string();
    9187  get_token();
    9188  result = basic_json(s);
    9189  break;
    9190  }
    9191 
    9192  case lexer::token_type::literal_true:
    9193  {
    9194  get_token();
    9195  result.m_type = value_t::boolean;
    9196  result.m_value = true;
    9197  break;
    9198  }
    9199 
    9200  case lexer::token_type::literal_false:
    9201  {
    9202  get_token();
    9203  result.m_type = value_t::boolean;
    9204  result.m_value = false;
    9205  break;
    9206  }
    9207 
    9208  case lexer::token_type::value_number:
    9209  {
    9210  m_lexer.get_number(result);
    9211  get_token();
    9212  break;
    9213  }
    9214 
    9215  default:
    9216  {
    9217  // the last token was unexpected
    9218  unexpect(last_token);
    9219  }
    9220  }
    9221 
    9222  if (keep and callback and not callback(depth, parse_event_t::value, result))
    9223  {
    9224  result = basic_json(value_t::discarded);
    9225  }
    9226  return result;
    9227  }
    9228 
    9230  typename lexer::token_type get_token()
    9231  {
    9232  last_token = m_lexer.scan();
    9233  return last_token;
    9234  }
    9235 
    9236  void expect(typename lexer::token_type t) const
    9237  {
    9238  if (t != last_token)
    9239  {
    9240  std::string error_msg = "parse error - unexpected ";
    9241  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() +
    9242  "'") :
    9243  lexer::token_type_name(last_token));
    9244  error_msg += "; expected " + lexer::token_type_name(t);
    9245  throw std::invalid_argument(error_msg);
    9246  }
    9247  }
    9248 
    9249  void unexpect(typename lexer::token_type t) const
    9250  {
    9251  if (t == last_token)
    9252  {
    9253  std::string error_msg = "parse error - unexpected ";
    9254  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() +
    9255  "'") :
    9256  lexer::token_type_name(last_token));
    9257  throw std::invalid_argument(error_msg);
    9258  }
    9259  }
    9260 
    9261  private:
    9263  int depth = 0;
    9265  const parser_callback_t callback = nullptr;
    9267  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    9269  lexer m_lexer;
    9270  };
    9271 
    9272  public:
    9285  {
    9287  friend class basic_json;
    9288 
    9289  public:
    9312  explicit json_pointer(const std::string& s = "")
    9313  : reference_tokens(split(s))
    9314  {}
    9315 
    9331  std::string to_string() const noexcept
    9332  {
    9333  return std::accumulate(reference_tokens.begin(),
    9334  reference_tokens.end(), std::string{},
    9335  [](const std::string & a, const std::string & b)
    9336  {
    9337  return a + "/" + escape(b);
    9338  });
    9339  }
    9340 
    9342  operator std::string() const
    9343  {
    9344  return to_string();
    9345  }
    9347  private:
    9349  std::string pop_back()
    9350  {
    9351  if (is_root())
    9352  {
    9353  throw std::domain_error("JSON pointer has no parent");
    9354  }
    9355 
    9356  auto last = reference_tokens.back();
    9357  reference_tokens.pop_back();
    9358  return last;
    9359  }
    9360 
    9362  bool is_root() const
    9363  {
    9364  return reference_tokens.empty();
    9365  }
    9366 
    9367  json_pointer top() const
    9368  {
    9369  if (is_root())
    9370  {
    9371  throw std::domain_error("JSON pointer has no parent");
    9372  }
    9373 
    9374  json_pointer result = *this;
    9375  result.reference_tokens = {reference_tokens[0]};
    9376  return result;
    9377  }
    9378 
    9384  reference get_and_create(reference j) const
    9385  {
    9386  pointer result = &j;
    9387 
    9388  // in case no reference tokens exist, return a reference to the
    9389  // JSON value j which will be overwritten by a primitive value
    9390  for (const auto& reference_token : reference_tokens)
    9391  {
    9392  switch (result->m_type)
    9393  {
    9394  case value_t::null:
    9395  {
    9396  if (reference_token == "0")
    9397  {
    9398  // start a new array if reference token is 0
    9399  result = &result->operator[](0);
    9400  }
    9401  else
    9402  {
    9403  // start a new object otherwise
    9404  result = &result->operator[](reference_token);
    9405  }
    9406  break;
    9407  }
    9408 
    9409  case value_t::object:
    9410  {
    9411  // create an entry in the object
    9412  result = &result->operator[](reference_token);
    9413  break;
    9414  }
    9415 
    9416  case value_t::array:
    9417  {
    9418  // create an entry in the array
    9419  result = &result->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9420  break;
    9421  }
    9422 
    9423  /*
    9424  The following code is only reached if there exists a
    9425  reference token _and_ the current value is primitive. In
    9426  this case, we have an error situation, because primitive
    9427  values may only occur as single value; that is, with an
    9428  empty list of reference tokens.
    9429  */
    9430  default:
    9431  {
    9432  throw std::domain_error("invalid value to unflatten");
    9433  }
    9434  }
    9435  }
    9436 
    9437  return *result;
    9438  }
    9439 
    9459  reference get_unchecked(pointer ptr) const
    9460  {
    9461  for (const auto& reference_token : reference_tokens)
    9462  {
    9463  // convert null values to arrays or objects before continuing
    9464  if (ptr->m_type == value_t::null)
    9465  {
    9466  // check if reference token is a number
    9467  const bool nums = std::all_of(reference_token.begin(),
    9468  reference_token.end(),
    9469  [](const char x)
    9470  {
    9471  return std::isdigit(x);
    9472  });
    9473 
    9474  // change value to array for numbers or "-" or to object
    9475  // otherwise
    9476  if (nums or reference_token == "-")
    9477  {
    9478  *ptr = value_t::array;
    9479  }
    9480  else
    9481  {
    9482  *ptr = value_t::object;
    9483  }
    9484  }
    9485 
    9486  switch (ptr->m_type)
    9487  {
    9488  case value_t::object:
    9489  {
    9490  // use unchecked object access
    9491  ptr = &ptr->operator[](reference_token);
    9492  break;
    9493  }
    9494 
    9495  case value_t::array:
    9496  {
    9497  // error condition (cf. RFC 6901, Sect. 4)
    9498  if (reference_token.size() > 1 and reference_token[0] == '0')
    9499  {
    9500  throw std::domain_error("array index must not begin with '0'");
    9501  }
    9502 
    9503  if (reference_token == "-")
    9504  {
    9505  // explicityly treat "-" as index beyond the end
    9506  ptr = &ptr->operator[](ptr->m_value.array->size());
    9507  }
    9508  else
    9509  {
    9510  // convert array index to number; unchecked access
    9511  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9512  }
    9513  break;
    9514  }
    9515 
    9516  default:
    9517  {
    9518  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9519  }
    9520  }
    9521  }
    9522 
    9523  return *ptr;
    9524  }
    9525 
    9526  reference get_checked(pointer ptr) const
    9527  {
    9528  for (const auto& reference_token : reference_tokens)
    9529  {
    9530  switch (ptr->m_type)
    9531  {
    9532  case value_t::object:
    9533  {
    9534  // note: at performs range check
    9535  ptr = &ptr->at(reference_token);
    9536  break;
    9537  }
    9538 
    9539  case value_t::array:
    9540  {
    9541  if (reference_token == "-")
    9542  {
    9543  // "-" always fails the range check
    9544  throw std::out_of_range("array index '-' (" +
    9545  std::to_string(ptr->m_value.array->size()) +
    9546  ") is out of range");
    9547  }
    9548 
    9549  // error condition (cf. RFC 6901, Sect. 4)
    9550  if (reference_token.size() > 1 and reference_token[0] == '0')
    9551  {
    9552  throw std::domain_error("array index must not begin with '0'");
    9553  }
    9554 
    9555  // note: at performs range check
    9556  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9557  break;
    9558  }
    9559 
    9560  default:
    9561  {
    9562  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9563  }
    9564  }
    9565  }
    9566 
    9567  return *ptr;
    9568  }
    9569 
    9578  const_reference get_unchecked(const_pointer ptr) const
    9579  {
    9580  for (const auto& reference_token : reference_tokens)
    9581  {
    9582  switch (ptr->m_type)
    9583  {
    9584  case value_t::object:
    9585  {
    9586  // use unchecked object access
    9587  ptr = &ptr->operator[](reference_token);
    9588  break;
    9589  }
    9590 
    9591  case value_t::array:
    9592  {
    9593  if (reference_token == "-")
    9594  {
    9595  // "-" cannot be used for const access
    9596  throw std::out_of_range("array index '-' (" +
    9597  std::to_string(ptr->m_value.array->size()) +
    9598  ") is out of range");
    9599  }
    9600 
    9601  // error condition (cf. RFC 6901, Sect. 4)
    9602  if (reference_token.size() > 1 and reference_token[0] == '0')
    9603  {
    9604  throw std::domain_error("array index must not begin with '0'");
    9605  }
    9606 
    9607  // use unchecked array access
    9608  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9609  break;
    9610  }
    9611 
    9612  default:
    9613  {
    9614  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9615  }
    9616  }
    9617  }
    9618 
    9619  return *ptr;
    9620  }
    9621 
    9622  const_reference get_checked(const_pointer ptr) const
    9623  {
    9624  for (const auto& reference_token : reference_tokens)
    9625  {
    9626  switch (ptr->m_type)
    9627  {
    9628  case value_t::object:
    9629  {
    9630  // note: at performs range check
    9631  ptr = &ptr->at(reference_token);
    9632  break;
    9633  }
    9634 
    9635  case value_t::array:
    9636  {
    9637  if (reference_token == "-")
    9638  {
    9639  // "-" always fails the range check
    9640  throw std::out_of_range("array index '-' (" +
    9641  std::to_string(ptr->m_value.array->size()) +
    9642  ") is out of range");
    9643  }
    9644 
    9645  // error condition (cf. RFC 6901, Sect. 4)
    9646  if (reference_token.size() > 1 and reference_token[0] == '0')
    9647  {
    9648  throw std::domain_error("array index must not begin with '0'");
    9649  }
    9650 
    9651  // note: at performs range check
    9652  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9653  break;
    9654  }
    9655 
    9656  default:
    9657  {
    9658  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9659  }
    9660  }
    9661  }
    9662 
    9663  return *ptr;
    9664  }
    9665 
    9667  static std::vector<std::string> split(const std::string& reference_string)
    9668  {
    9669  std::vector<std::string> result;
    9670 
    9671  // special case: empty reference string -> no reference tokens
    9672  if (reference_string.empty())
    9673  {
    9674  return result;
    9675  }
    9676 
    9677  // check if nonempty reference string begins with slash
    9678  if (reference_string[0] != '/')
    9679  {
    9680  throw std::domain_error("JSON pointer must be empty or begin with '/'");
    9681  }
    9682 
    9683  // extract the reference tokens:
    9684  // - slash: position of the last read slash (or end of string)
    9685  // - start: position after the previous slash
    9686  for (
    9687  // search for the first slash after the first character
    9688  size_t slash = reference_string.find_first_of("/", 1),
    9689  // set the beginning of the first reference token
    9690  start = 1;
    9691  // we can stop if start == string::npos+1 = 0
    9692  start != 0;
    9693  // set the beginning of the next reference token
    9694  // (will eventually be 0 if slash == std::string::npos)
    9695  start = slash + 1,
    9696  // find next slash
    9697  slash = reference_string.find_first_of("/", start))
    9698  {
    9699  // use the text between the beginning of the reference token
    9700  // (start) and the last slash (slash).
    9701  auto reference_token = reference_string.substr(start, slash - start);
    9702 
    9703  // check reference tokens are properly escaped
    9704  for (size_t pos = reference_token.find_first_of("~");
    9705  pos != std::string::npos;
    9706  pos = reference_token.find_first_of("~", pos + 1))
    9707  {
    9708  assert(reference_token[pos] == '~');
    9709 
    9710  // ~ must be followed by 0 or 1
    9711  if (pos == reference_token.size() - 1 or
    9712  (reference_token[pos + 1] != '0' and
    9713  reference_token[pos + 1] != '1'))
    9714  {
    9715  throw std::domain_error("escape error: '~' must be followed with '0' or '1'");
    9716  }
    9717  }
    9718 
    9719  // finally, store the reference token
    9720  unescape(reference_token);
    9721  result.push_back(reference_token);
    9722  }
    9723 
    9724  return result;
    9725  }
    9726 
    9727  private:
    9742  static void replace_substring(std::string& s,
    9743  const std::string& f,
    9744  const std::string& t)
    9745  {
    9746  assert(not f.empty());
    9747 
    9748  for (
    9749  size_t pos = s.find(f); // find first occurrence of f
    9750  pos != std::string::npos; // make sure f was found
    9751  s.replace(pos, f.size(), t), // replace with t
    9752  pos = s.find(f, pos + t.size()) // find next occurrence of f
    9753  );
    9754  }
    9755 
    9757  static std::string escape(std::string s)
    9758  {
    9759  // escape "~"" to "~0" and "/" to "~1"
    9760  replace_substring(s, "~", "~0");
    9761  replace_substring(s, "/", "~1");
    9762  return s;
    9763  }
    9764 
    9766  static void unescape(std::string& s)
    9767  {
    9768  // first transform any occurrence of the sequence '~1' to '/'
    9769  replace_substring(s, "~1", "/");
    9770  // then transform any occurrence of the sequence '~0' to '~'
    9771  replace_substring(s, "~0", "~");
    9772  }
    9773 
    9781  static void flatten(const std::string& reference_string,
    9782  const basic_json& value,
    9783  basic_json& result)
    9784  {
    9785  switch (value.m_type)
    9786  {
    9787  case value_t::array:
    9788  {
    9789  if (value.m_value.array->empty())
    9790  {
    9791  // flatten empty array as null
    9792  result[reference_string] = nullptr;
    9793  }
    9794  else
    9795  {
    9796  // iterate array and use index as reference string
    9797  for (size_t i = 0; i < value.m_value.array->size(); ++i)
    9798  {
    9799  flatten(reference_string + "/" + std::to_string(i),
    9800  value.m_value.array->operator[](i), result);
    9801  }
    9802  }
    9803  break;
    9804  }
    9805 
    9806  case value_t::object:
    9807  {
    9808  if (value.m_value.object->empty())
    9809  {
    9810  // flatten empty object as null
    9811  result[reference_string] = nullptr;
    9812  }
    9813  else
    9814  {
    9815  // iterate object and use keys as reference string
    9816  for (const auto& element : *value.m_value.object)
    9817  {
    9818  flatten(reference_string + "/" + escape(element.first),
    9819  element.second, result);
    9820  }
    9821  }
    9822  break;
    9823  }
    9824 
    9825  default:
    9826  {
    9827  // add primitive value with its reference string
    9828  result[reference_string] = value;
    9829  break;
    9830  }
    9831  }
    9832  }
    9833 
    9839  static basic_json unflatten(const basic_json& value)
    9840  {
    9841  if (not value.is_object())
    9842  {
    9843  throw std::domain_error("only objects can be unflattened");
    9844  }
    9845 
    9846  basic_json result;
    9847 
    9848  // iterate the JSON object values
    9849  for (const auto& element : *value.m_value.object)
    9850  {
    9851  if (not element.second.is_primitive())
    9852  {
    9853  throw std::domain_error("values in object must be primitive");
    9854  }
    9855 
    9856  // assign value to reference pointed to by JSON pointer; Note
    9857  // that if the JSON pointer is "" (i.e., points to the whole
    9858  // value), function get_and_create returns a reference to
    9859  // result itself. An assignment will then create a primitive
    9860  // value.
    9861  json_pointer(element.first).get_and_create(result) = element.second;
    9862  }
    9863 
    9864  return result;
    9865  }
    9866 
    9867  private:
    9869  std::vector<std::string> reference_tokens {};
    9870  };
    9871 
    9873  // JSON Pointer support //
    9875 
    9878 
    9912  reference operator[](const json_pointer& ptr)
    9913  {
    9914  return ptr.get_unchecked(this);
    9915  }
    9939  const_reference operator[](const json_pointer& ptr) const
    9940  {
    9941  return ptr.get_unchecked(this);
    9942  }
    9964  reference at(const json_pointer& ptr)
    9965  {
    9966  return ptr.get_checked(this);
    9967  }
    9989  const_reference at(const json_pointer& ptr) const
    9990  {
    9991  return ptr.get_checked(this);
    9992  }
    10016  basic_json flatten() const
    10017  {
    10018  basic_json result(value_t::object);
    10019  json_pointer::flatten("", *this, result);
    10020  return result;
    10021  }
    10022 
    10050  basic_json unflatten() const
    10051  {
    10052  return json_pointer::unflatten(*this);
    10053  }
    10056 
    10058  // JSON Patch functions //
    10060 
    10063 
    10100  basic_json patch(const basic_json& json_patch) const
    10101  {
    10102  // make a working copy to apply the patch to
    10103  basic_json result = *this;
    10105  // the valid JSON Patch operations
    10106  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
    10107 
    10108  const auto get_op = [](const std::string op)
    10109  {
    10110  if (op == "add")
    10111  {
    10112  return patch_operations::add;
    10113  }
    10114  if (op == "remove")
    10115  {
    10116  return patch_operations::remove;
    10117  }
    10118  if (op == "replace")
    10119  {
    10120  return patch_operations::replace;
    10121  }
    10122  if (op == "move")
    10123  {
    10124  return patch_operations::move;
    10125  }
    10126  if (op == "copy")
    10127  {
    10128  return patch_operations::copy;
    10129  }
    10130  if (op == "test")
    10131  {
    10132  return patch_operations::test;
    10133  }
    10134 
    10135  return patch_operations::invalid;
    10136  };
    10137 
    10138  // wrapper for "add" operation; add value at ptr
    10139  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
    10140  {
    10141  // adding to the root of the target document means replacing it
    10142  if (ptr.is_root())
    10143  {
    10144  result = val;
    10145  }
    10146  else
    10147  {
    10148  // make sure the top element of the pointer exists
    10149  json_pointer top_pointer = ptr.top();
    10150  if (top_pointer != ptr)
    10151  {
    10152  result.at(top_pointer);
    10153  }
    10154 
    10155  // get reference to parent of JSON pointer ptr
    10156  const auto last_path = ptr.pop_back();
    10157  basic_json& parent = result[ptr];
    10158 
    10159  switch (parent.m_type)
    10160  {
    10161  case value_t::null:
    10162  case value_t::object:
    10163  {
    10164  // use operator[] to add value
    10165  parent[last_path] = val;
    10166  break;
    10167  }
    10168 
    10169  case value_t::array:
    10170  {
    10171  if (last_path == "-")
    10172  {
    10173  // special case: append to back
    10174  parent.push_back(val);
    10175  }
    10176  else
    10177  {
    10178  const auto idx = std::stoi(last_path);
    10179  if (static_cast<size_type>(idx) > parent.size())
    10180  {
    10181  // avoid undefined behavior
    10182  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    10183  }
    10184  else
    10185  {
    10186  // default case: insert add offset
    10187  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
    10188  }
    10189  }
    10190  break;
    10191  }
    10192 
    10193  default:
    10194  {
    10195  // if there exists a parent it cannot be primitive
    10196  assert(false); // LCOV_EXCL_LINE
    10197  }
    10198  }
    10199  }
    10200  };
    10201 
    10202  // wrapper for "remove" operation; remove value at ptr
    10203  const auto operation_remove = [&result](json_pointer & ptr)
    10204  {
    10205  // get reference to parent of JSON pointer ptr
    10206  const auto last_path = ptr.pop_back();
    10207  basic_json& parent = result.at(ptr);
    10208 
    10209  // remove child
    10210  if (parent.is_object())
    10211  {
    10212  // perform range check
    10213  auto it = parent.find(last_path);
    10214  if (it != parent.end())
    10215  {
    10216  parent.erase(it);
    10217  }
    10218  else
    10219  {
    10220  throw std::out_of_range("key '" + last_path + "' not found");
    10221  }
    10222  }
    10223  else if (parent.is_array())
    10224  {
    10225  // note erase performs range check
    10226  parent.erase(static_cast<size_type>(std::stoi(last_path)));
    10227  }
    10228  };
    10229 
    10230  // type check
    10231  if (not json_patch.is_array())
    10232  {
    10233  // a JSON patch must be an array of objects
    10234  throw std::invalid_argument("JSON patch must be an array of objects");
    10235  }
    10236 
    10237  // iterate and apply th eoperations
    10238  for (const auto& val : json_patch)
    10239  {
    10240  // wrapper to get a value for an operation
    10241  const auto get_value = [&val](const std::string & op,
    10242  const std::string & member,
    10243  bool string_type) -> basic_json&
    10244  {
    10245  // find value
    10246  auto it = val.m_value.object->find(member);
    10247 
    10248  // context-sensitive error message
    10249  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
    10250 
    10251  // check if desired value is present
    10252  if (it == val.m_value.object->end())
    10253  {
    10254  throw std::invalid_argument(error_msg + " must have member '" + member + "'");
    10255  }
    10256 
    10257  // check if result is of type string
    10258  if (string_type and not it->second.is_string())
    10259  {
    10260  throw std::invalid_argument(error_msg + " must have string member '" + member + "'");
    10261  }
    10262 
    10263  // no error: return value
    10264  return it->second;
    10265  };
    10266 
    10267  // type check
    10268  if (not val.is_object())
    10269  {
    10270  throw std::invalid_argument("JSON patch must be an array of objects");
    10271  }
    10272 
    10273  // collect mandatory members
    10274  const std::string op = get_value("op", "op", true);
    10275  const std::string path = get_value(op, "path", true);
    10276  json_pointer ptr(path);
    10277 
    10278  switch (get_op(op))
    10279  {
    10280  case patch_operations::add:
    10281  {
    10282  operation_add(ptr, get_value("add", "value", false));
    10283  break;
    10284  }
    10285 
    10286  case patch_operations::remove:
    10287  {
    10288  operation_remove(ptr);
    10289  break;
    10290  }
    10291 
    10292  case patch_operations::replace:
    10293  {
    10294  // the "path" location must exist - use at()
    10295  result.at(ptr) = get_value("replace", "value", false);
    10296  break;
    10297  }
    10298 
    10299  case patch_operations::move:
    10300  {
    10301  const std::string from_path = get_value("move", "from", true);
    10302  json_pointer from_ptr(from_path);
    10303 
    10304  // the "from" location must exist - use at()
    10305  basic_json v = result.at(from_ptr);
    10306 
    10307  // The move operation is functionally identical to a
    10308  // "remove" operation on the "from" location, followed
    10309  // immediately by an "add" operation at the target
    10310  // location with the value that was just removed.
    10311  operation_remove(from_ptr);
    10312  operation_add(ptr, v);
    10313  break;
    10314  }
    10315 
    10316  case patch_operations::copy:
    10317  {
    10318  const std::string from_path = get_value("copy", "from", true);;
    10319  const json_pointer from_ptr(from_path);
    10320 
    10321  // the "from" location must exist - use at()
    10322  result[ptr] = result.at(from_ptr);
    10323  break;
    10324  }
    10325 
    10326  case patch_operations::test:
    10327  {
    10328  bool success = false;
    10329  try
    10330  {
    10331  // check if "value" matches the one at "path"
    10332  // the "path" location must exist - use at()
    10333  success = (result.at(ptr) == get_value("test", "value", false));
    10334  }
    10335  catch (std::out_of_range&)
    10336  {
    10337  // ignore out of range errors: success remains false
    10338  }
    10339 
    10340  // throw an exception if test fails
    10341  if (not success)
    10342  {
    10343  throw std::domain_error("unsuccessful: " + val.dump());
    10344  }
    10345 
    10346  break;
    10347  }
    10348 
    10349  case patch_operations::invalid:
    10350  {
    10351  // op must be "add", "remove", "replace", "move", "copy", or
    10352  // "test"
    10353  throw std::invalid_argument("operation value '" + op + "' is invalid");
    10354  }
    10355  }
    10356  }
    10357 
    10358  return result;
    10359  }
    10360 
    10393  static basic_json diff(const basic_json& source,
    10394  const basic_json& target,
    10395  const std::string& path = "")
    10396  {
    10397  // the patch
    10398  basic_json result(value_t::array);
    10399 
    10400  // if the values are the same, return empty patch
    10401  if (source == target)
    10402  {
    10403  return result;
    10404  }
    10405 
    10406  if (source.type() != target.type())
    10407  {
    10408  // different types: replace value
    10409  result.push_back(
    10410  {
    10411  {"op", "replace"},
    10412  {"path", path},
    10413  {"value", target}
    10414  });
    10415  }
    10416  else
    10417  {
    10418  switch (source.type())
    10419  {
    10420  case value_t::array:
    10421  {
    10422  // first pass: traverse common elements
    10423  size_t i = 0;
    10424  while (i < source.size() and i < target.size())
    10425  {
    10426  // recursive call to compare array values at index i
    10427  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
    10428  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    10429  ++i;
    10430  }
    10431 
    10432  // i now reached the end of at least one array
    10433  // in a second pass, traverse the remaining elements
    10434 
    10435  // remove my remaining elements
    10436  const auto end_index = static_cast<difference_type>(result.size());
    10437  while (i < source.size())
    10438  {
    10439  // add operations in reverse order to avoid invalid
    10440  // indices
    10441  result.insert(result.begin() + end_index, object(
    10442  {
    10443  {"op", "remove"},
    10444  {"path", path + "/" + std::to_string(i)}
    10445  }));
    10446  ++i;
    10447  }
    10448 
    10449  // add other remaining elements
    10450  while (i < target.size())
    10451  {
    10452  result.push_back(
    10453  {
    10454  {"op", "add"},
    10455  {"path", path + "/" + std::to_string(i)},
    10456  {"value", target[i]}
    10457  });
    10458  ++i;
    10459  }
    10460 
    10461  break;
    10462  }
    10463 
    10464  case value_t::object:
    10465  {
    10466  // first pass: traverse this object's elements
    10467  for (auto it = source.begin(); it != source.end(); ++it)
    10468  {
    10469  // escape the key name to be used in a JSON patch
    10470  const auto key = json_pointer::escape(it.key());
    10471 
    10472  if (target.find(it.key()) != target.end())
    10473  {
    10474  // recursive call to compare object values at key it
    10475  auto temp_diff = diff(it.value(), target[it.key()], path + "/" + key);
    10476  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    10477  }
    10478  else
    10479  {
    10480  // found a key that is not in o -> remove it
    10481  result.push_back(object(
    10482  {
    10483  {"op", "remove"},
    10484  {"path", path + "/" + key}
    10485  }));
    10486  }
    10487  }
    10488 
    10489  // second pass: traverse other object's elements
    10490  for (auto it = target.begin(); it != target.end(); ++it)
    10491  {
    10492  if (source.find(it.key()) == source.end())
    10493  {
    10494  // found a key that is not in this -> add it
    10495  const auto key = json_pointer::escape(it.key());
    10496  result.push_back(
    10497  {
    10498  {"op", "add"},
    10499  {"path", path + "/" + key},
    10500  {"value", it.value()}
    10501  });
    10502  }
    10503  }
    10504 
    10505  break;
    10506  }
    10507 
    10508  default:
    10509  {
    10510  // both primitive type: replace value
    10511  result.push_back(
    10512  {
    10513  {"op", "replace"},
    10514  {"path", path},
    10515  {"value", target}
    10516  });
    10517  break;
    10518  }
    10519  }
    10520  }
    10521 
    10522  return result;
    10523  }
    10524 
    10526 };
    10527 
    10528 
    10530 // presets //
    10532 
    10541 using json = basic_json<>;
    10542 }
    10543 
    10544 
    10546 // nonmember support //
    10548 
    10549 // specialization of std::swap, and std::hash
    10550 namespace std
    10551 {
    10557 template<>
    10558 inline void swap(nlohmann::json& j1,
    10559  nlohmann::json& j2) noexcept(
    10560  is_nothrow_move_constructible<nlohmann::json>::value and
    10561  is_nothrow_move_assignable<nlohmann::json>::value
    10562  )
    10563 {
    10564  j1.swap(j2);
    10565 }
    10566 
    10568 template<>
    10569 struct hash<nlohmann::json>
    10570 {
    10576  std::size_t operator()(const nlohmann::json& j) const
    10577  {
    10578  // a naive hashing via the string representation
    10579  const auto& h = hash<nlohmann::json::string_t>();
    10580  return h(j.dump());
    10581  }
    10582 };
    10583 }
    10584 
    10597 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    10598 {
    10599  return nlohmann::json::parse(s);
    10600 }
    10601 
    10614 inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
    10615 {
    10616  return nlohmann::json::json_pointer(s);
    10617 }
    10618 
    10619 // restore GCC/clang diagnostic settings
    10620 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    10621  #pragma GCC diagnostic pop
    10622 #endif
    10623 
    10624 #endif
    const_iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6741
    +
    1 /*
    2  __ _____ _____ _____
    3  __| | __| | | | JSON for Modern C++
    4 | | |__ | | | | | | version 2.0.7
    5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
    6 
    7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
    8 Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
    9 
    10 Permission is hereby granted, free of charge, to any person obtaining a copy
    11 of this software and associated documentation files (the "Software"), to deal
    12 in the Software without restriction, including without limitation the rights
    13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    14 copies of the Software, and to permit persons to whom the Software is
    15 furnished to do so, subject to the following conditions:
    16 
    17 The above copyright notice and this permission notice shall be included in all
    18 copies or substantial portions of the Software.
    19 
    20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    26 SOFTWARE.
    27 */
    28 
    29 #ifndef NLOHMANN_JSON_HPP
    30 #define NLOHMANN_JSON_HPP
    31 
    32 #include <algorithm>
    33 #include <array>
    34 #include <cassert>
    35 #include <cctype>
    36 #include <ciso646>
    37 #include <cmath>
    38 #include <cstddef>
    39 #include <cstdint>
    40 #include <cstdlib>
    41 #include <cstring>
    42 #include <functional>
    43 #include <initializer_list>
    44 #include <iomanip>
    45 #include <iostream>
    46 #include <iterator>
    47 #include <limits>
    48 #include <locale>
    49 #include <map>
    50 #include <memory>
    51 #include <numeric>
    52 #include <sstream>
    53 #include <stdexcept>
    54 #include <string>
    55 #include <type_traits>
    56 #include <utility>
    57 #include <vector>
    58 
    59 // exclude unsupported compilers
    60 #if defined(__clang__)
    61  #define CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
    62  #if CLANG_VERSION < 30400
    63  #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers"
    64  #endif
    65 #elif defined(__GNUC__)
    66  #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
    67  #if GCC_VERSION < 40900
    68  #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
    69  #endif
    70 #endif
    71 
    72 // disable float-equal warnings on GCC/clang
    73 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    74  #pragma GCC diagnostic push
    75  #pragma GCC diagnostic ignored "-Wfloat-equal"
    76 #endif
    77 
    78 // allow for portable deprecation warnings
    79 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    80  #define JSON_DEPRECATED __attribute__((deprecated))
    81 #elif defined(_MSC_VER)
    82  #define JSON_DEPRECATED __declspec(deprecated)
    83 #else
    84  #define JSON_DEPRECATED
    85 #endif
    86 
    92 namespace nlohmann
    93 {
    94 
    95 
    100 namespace
    101 {
    112 template<typename T>
    113 struct has_mapped_type
    114 {
    115  private:
    116  template <typename U, typename = typename U::mapped_type>
    117  static int detect(U&&);
    118 
    119  static void detect(...);
    120  public:
    121  static constexpr bool value =
    122  std::is_integral<decltype(detect(std::declval<T>()))>::value;
    123 };
    124 
    137 struct DecimalSeparator : std::numpunct<char>
    138 {
    139  char do_decimal_point() const
    140  {
    141  return '.';
    142  }
    143 };
    144 
    145 }
    146 
    225 template <
    226  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    227  template<typename U, typename... Args> class ArrayType = std::vector,
    228  class StringType = std::string,
    229  class BooleanType = bool,
    230  class NumberIntegerType = std::int64_t,
    231  class NumberUnsignedType = std::uint64_t,
    232  class NumberFloatType = double,
    233  template<typename U> class AllocatorType = std::allocator
    234  >
    236 {
    237  private:
    239  using basic_json_t = basic_json<ObjectType, ArrayType, StringType,
    240  BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType,
    241  AllocatorType>;
    242 
    243  public:
    244  // forward declarations
    245  template<typename Base> class json_reverse_iterator;
    246  class json_pointer;
    247 
    249  // container types //
    251 
    256 
    259 
    263  using const_reference = const value_type&;
    264 
    266  using difference_type = std::ptrdiff_t;
    268  using size_type = std::size_t;
    269 
    271  using allocator_type = AllocatorType<basic_json>;
    272 
    274  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    276  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    277 
    279  class iterator;
    281  class const_iterator;
    286 
    288 
    289 
    294  {
    295  return allocator_type();
    296  }
    297 
    298 
    300  // JSON value data types //
    302 
    307 
    391  using object_t = ObjectType<StringType,
    392  basic_json,
    393  std::less<StringType>,
    394  AllocatorType<std::pair<const StringType,
    395  basic_json>>>;
    396 
    441  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    442 
    488  using string_t = StringType;
    489 
    514  using boolean_t = BooleanType;
    515 
    586  using number_integer_t = NumberIntegerType;
    587 
    657  using number_unsigned_t = NumberUnsignedType;
    658 
    725  using number_float_t = NumberFloatType;
    726 
    728 
    729 
    731  // JSON type enumeration //
    733 
    756  enum class value_t : uint8_t
    757  {
    758  null,
    759  object,
    760  array,
    761  string,
    762  boolean,
    763  number_integer,
    764  number_unsigned,
    765  number_float,
    766  discarded
    767  };
    768 
    769 
    770  private:
    771 
    773  template<typename T, typename... Args>
    774  static T* create(Args&& ... args)
    775  {
    776  AllocatorType<T> alloc;
    777  auto deleter = [&](T * object)
    778  {
    779  alloc.deallocate(object, 1);
    780  };
    781  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    782  alloc.construct(object.get(), std::forward<Args>(args)...);
    783  assert(object.get() != nullptr);
    784  return object.release();
    785  }
    786 
    788  // JSON value storage //
    790 
    815  union json_value
    816  {
    818  object_t* object;
    820  array_t* array;
    822  string_t* string;
    824  boolean_t boolean;
    826  number_integer_t number_integer;
    828  number_unsigned_t number_unsigned;
    830  number_float_t number_float;
    831 
    833  json_value() = default;
    835  json_value(boolean_t v) noexcept : boolean(v) {}
    837  json_value(number_integer_t v) noexcept : number_integer(v) {}
    839  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    841  json_value(number_float_t v) noexcept : number_float(v) {}
    843  json_value(value_t t)
    844  {
    845  switch (t)
    846  {
    847  case value_t::object:
    848  {
    849  object = create<object_t>();
    850  break;
    851  }
    852 
    853  case value_t::array:
    854  {
    855  array = create<array_t>();
    856  break;
    857  }
    858 
    859  case value_t::string:
    860  {
    861  string = create<string_t>("");
    862  break;
    863  }
    864 
    865  case value_t::boolean:
    866  {
    867  boolean = boolean_t(false);
    868  break;
    869  }
    870 
    871  case value_t::number_integer:
    872  {
    873  number_integer = number_integer_t(0);
    874  break;
    875  }
    876 
    877  case value_t::number_unsigned:
    878  {
    879  number_unsigned = number_unsigned_t(0);
    880  break;
    881  }
    882 
    883  case value_t::number_float:
    884  {
    885  number_float = number_float_t(0.0);
    886  break;
    887  }
    888 
    889  default:
    890  {
    891  break;
    892  }
    893  }
    894  }
    895 
    897  json_value(const string_t& value)
    898  {
    899  string = create<string_t>(value);
    900  }
    901 
    903  json_value(const object_t& value)
    904  {
    905  object = create<object_t>(value);
    906  }
    907 
    909  json_value(const array_t& value)
    910  {
    911  array = create<array_t>(value);
    912  }
    913  };
    914 
    924  void assert_invariant() const
    925  {
    926  assert(m_type != value_t::object or m_value.object != nullptr);
    927  assert(m_type != value_t::array or m_value.array != nullptr);
    928  assert(m_type != value_t::string or m_value.string != nullptr);
    929  }
    930 
    931  public:
    933  // JSON parser callback //
    935 
    946  enum class parse_event_t : uint8_t
    947  {
    949  object_start,
    951  object_end,
    953  array_start,
    955  array_end,
    957  key,
    959  value
    960  };
    961 
    1014  using parser_callback_t = std::function<bool(int depth,
    1015  parse_event_t event,
    1016  basic_json& parsed)>;
    1017 
    1018 
    1020  // constructors //
    1022 
    1027 
    1068  : m_type(value_type), m_value(value_type)
    1069  {
    1070  assert_invariant();
    1071  }
    1072 
    1091  basic_json(std::nullptr_t = nullptr) noexcept
    1092  : basic_json(value_t::null)
    1093  {
    1094  assert_invariant();
    1095  }
    1096 
    1116  basic_json(const object_t& val)
    1117  : m_type(value_t::object), m_value(val)
    1118  {
    1119  assert_invariant();
    1120  }
    1121 
    1148  template<class CompatibleObjectType, typename std::enable_if<
    1149  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1150  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type = 0>
    1151  basic_json(const CompatibleObjectType& val)
    1152  : m_type(value_t::object)
    1153  {
    1154  using std::begin;
    1155  using std::end;
    1156  m_value.object = create<object_t>(begin(val), end(val));
    1157  assert_invariant();
    1158  }
    1159 
    1179  basic_json(const array_t& val)
    1180  : m_type(value_t::array), m_value(val)
    1181  {
    1182  assert_invariant();
    1183  }
    1184 
    1211  template<class CompatibleArrayType, typename std::enable_if<
    1212  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1213  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1214  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1215  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1216  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1217  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1218  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type = 0>
    1219  basic_json(const CompatibleArrayType& val)
    1220  : m_type(value_t::array)
    1221  {
    1222  using std::begin;
    1223  using std::end;
    1224  m_value.array = create<array_t>(begin(val), end(val));
    1225  assert_invariant();
    1226  }
    1227 
    1249  basic_json(const string_t& val)
    1250  : m_type(value_t::string), m_value(val)
    1251  {
    1252  assert_invariant();
    1253  }
    1254 
    1275  basic_json(const typename string_t::value_type* val)
    1276  : basic_json(string_t(val))
    1277  {
    1278  assert_invariant();
    1279  }
    1280 
    1304  template<class CompatibleStringType, typename std::enable_if<
    1305  std::is_constructible<string_t, CompatibleStringType>::value, int>::type = 0>
    1306  basic_json(const CompatibleStringType& val)
    1307  : basic_json(string_t(val))
    1308  {
    1309  assert_invariant();
    1310  }
    1311 
    1326  basic_json(boolean_t val) noexcept
    1327  : m_type(value_t::boolean), m_value(val)
    1328  {
    1329  assert_invariant();
    1330  }
    1331 
    1355  template<typename T, typename std::enable_if<
    1356  not (std::is_same<T, int>::value) and
    1357  std::is_same<T, number_integer_t>::value, int>::type = 0>
    1358  basic_json(const number_integer_t val) noexcept
    1359  : m_type(value_t::number_integer), m_value(val)
    1360  {
    1361  assert_invariant();
    1362  }
    1363 
    1389  basic_json(const int val) noexcept
    1390  : m_type(value_t::number_integer),
    1391  m_value(static_cast<number_integer_t>(val))
    1392  {
    1393  assert_invariant();
    1394  }
    1395 
    1421  template<typename CompatibleNumberIntegerType, typename std::enable_if<
    1422  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1423  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1424  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1425  CompatibleNumberIntegerType>::type = 0>
    1426  basic_json(const CompatibleNumberIntegerType val) noexcept
    1427  : m_type(value_t::number_integer),
    1428  m_value(static_cast<number_integer_t>(val))
    1429  {
    1430  assert_invariant();
    1431  }
    1432 
    1450  template<typename T, typename std::enable_if<
    1451  not (std::is_same<T, int>::value) and
    1452  std::is_same<T, number_unsigned_t>::value, int>::type = 0>
    1453  basic_json(const number_unsigned_t val) noexcept
    1454  : m_type(value_t::number_unsigned), m_value(val)
    1455  {
    1456  assert_invariant();
    1457  }
    1458 
    1479  template<typename CompatibleNumberUnsignedType, typename std::enable_if <
    1480  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1481  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1482  not std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1483  CompatibleNumberUnsignedType>::type = 0>
    1484  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1485  : m_type(value_t::number_unsigned),
    1486  m_value(static_cast<number_unsigned_t>(val))
    1487  {
    1488  assert_invariant();
    1489  }
    1490 
    1515  basic_json(const number_float_t val) noexcept
    1516  : m_type(value_t::number_float), m_value(val)
    1517  {
    1518  // replace infinity and NAN by null
    1519  if (not std::isfinite(val))
    1520  {
    1521  m_type = value_t::null;
    1522  m_value = json_value();
    1523  }
    1524 
    1525  assert_invariant();
    1526  }
    1527 
    1559  template<typename CompatibleNumberFloatType, typename = typename std::enable_if<
    1560  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1561  std::is_floating_point<CompatibleNumberFloatType>::value>::type>
    1562  basic_json(const CompatibleNumberFloatType val) noexcept
    1563  : basic_json(number_float_t(val))
    1564  {
    1565  assert_invariant();
    1566  }
    1567 
    1637  basic_json(std::initializer_list<basic_json> init,
    1638  bool type_deduction = true,
    1639  value_t manual_type = value_t::array)
    1640  {
    1641  // check if each element is an array with two elements whose first
    1642  // element is a string
    1643  bool is_an_object = std::all_of(init.begin(), init.end(),
    1644  [](const basic_json & element)
    1645  {
    1646  return element.is_array() and element.size() == 2 and element[0].is_string();
    1647  });
    1648 
    1649  // adjust type if type deduction is not wanted
    1650  if (not type_deduction)
    1651  {
    1652  // if array is wanted, do not create an object though possible
    1653  if (manual_type == value_t::array)
    1654  {
    1655  is_an_object = false;
    1656  }
    1657 
    1658  // if object is wanted but impossible, throw an exception
    1659  if (manual_type == value_t::object and not is_an_object)
    1660  {
    1661  throw std::domain_error("cannot create object from initializer list");
    1662  }
    1663  }
    1664 
    1665  if (is_an_object)
    1666  {
    1667  // the initializer list is a list of pairs -> create object
    1668  m_type = value_t::object;
    1669  m_value = value_t::object;
    1670 
    1671  std::for_each(init.begin(), init.end(), [this](const basic_json & element)
    1672  {
    1673  m_value.object->emplace(*(element[0].m_value.string), element[1]);
    1674  });
    1675  }
    1676  else
    1677  {
    1678  // the initializer list describes an array -> create array
    1679  m_type = value_t::array;
    1680  m_value.array = create<array_t>(init);
    1681  }
    1682 
    1683  assert_invariant();
    1684  }
    1685 
    1720  static basic_json array(std::initializer_list<basic_json> init =
    1721  std::initializer_list<basic_json>())
    1722  {
    1723  return basic_json(init, false, value_t::array);
    1724  }
    1725 
    1760  static basic_json object(std::initializer_list<basic_json> init =
    1761  std::initializer_list<basic_json>())
    1762  {
    1763  return basic_json(init, false, value_t::object);
    1764  }
    1765 
    1785  : m_type(value_t::array)
    1786  {
    1787  m_value.array = create<array_t>(cnt, val);
    1788  assert_invariant();
    1789  }
    1790 
    1828  template<class InputIT, typename std::enable_if<
    1829  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1830  std::is_same<InputIT, typename basic_json_t::const_iterator>::value, int>::type = 0>
    1831  basic_json(InputIT first, InputIT last)
    1832  {
    1833  assert(first.m_object != nullptr);
    1834  assert(last.m_object != nullptr);
    1835 
    1836  // make sure iterator fits the current value
    1837  if (first.m_object != last.m_object)
    1838  {
    1839  throw std::domain_error("iterators are not compatible");
    1840  }
    1841 
    1842  // copy type from first iterator
    1843  m_type = first.m_object->m_type;
    1844 
    1845  // check if iterator range is complete for primitive values
    1846  switch (m_type)
    1847  {
    1848  case value_t::boolean:
    1849  case value_t::number_float:
    1850  case value_t::number_integer:
    1851  case value_t::number_unsigned:
    1852  case value_t::string:
    1853  {
    1854  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1855  {
    1856  throw std::out_of_range("iterators out of range");
    1857  }
    1858  break;
    1859  }
    1860 
    1861  default:
    1862  {
    1863  break;
    1864  }
    1865  }
    1866 
    1867  switch (m_type)
    1868  {
    1869  case value_t::number_integer:
    1870  {
    1871  m_value.number_integer = first.m_object->m_value.number_integer;
    1872  break;
    1873  }
    1874 
    1875  case value_t::number_unsigned:
    1876  {
    1877  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1878  break;
    1879  }
    1880 
    1881  case value_t::number_float:
    1882  {
    1883  m_value.number_float = first.m_object->m_value.number_float;
    1884  break;
    1885  }
    1886 
    1887  case value_t::boolean:
    1888  {
    1889  m_value.boolean = first.m_object->m_value.boolean;
    1890  break;
    1891  }
    1892 
    1893  case value_t::string:
    1894  {
    1895  m_value = *first.m_object->m_value.string;
    1896  break;
    1897  }
    1898 
    1899  case value_t::object:
    1900  {
    1901  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1902  break;
    1903  }
    1904 
    1905  case value_t::array:
    1906  {
    1907  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1908  break;
    1909  }
    1910 
    1911  default:
    1912  {
    1913  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1914  }
    1915  }
    1916 
    1917  assert_invariant();
    1918  }
    1919 
    1948  JSON_DEPRECATED
    1949  explicit basic_json(std::istream& i, const parser_callback_t cb = nullptr)
    1950  {
    1951  *this = parser(i, cb).parse();
    1952  assert_invariant();
    1953  }
    1954 
    1956  // other constructors and destructor //
    1958 
    1981  basic_json(const basic_json& other)
    1982  : m_type(other.m_type)
    1983  {
    1984  // check of passed value is valid
    1985  other.assert_invariant();
    1986 
    1987  switch (m_type)
    1988  {
    1989  case value_t::object:
    1990  {
    1991  m_value = *other.m_value.object;
    1992  break;
    1993  }
    1994 
    1995  case value_t::array:
    1996  {
    1997  m_value = *other.m_value.array;
    1998  break;
    1999  }
    2000 
    2001  case value_t::string:
    2002  {
    2003  m_value = *other.m_value.string;
    2004  break;
    2005  }
    2006 
    2007  case value_t::boolean:
    2008  {
    2009  m_value = other.m_value.boolean;
    2010  break;
    2011  }
    2012 
    2013  case value_t::number_integer:
    2014  {
    2015  m_value = other.m_value.number_integer;
    2016  break;
    2017  }
    2018 
    2019  case value_t::number_unsigned:
    2020  {
    2021  m_value = other.m_value.number_unsigned;
    2022  break;
    2023  }
    2024 
    2025  case value_t::number_float:
    2026  {
    2027  m_value = other.m_value.number_float;
    2028  break;
    2029  }
    2030 
    2031  default:
    2032  {
    2033  break;
    2034  }
    2035  }
    2036 
    2037  assert_invariant();
    2038  }
    2039 
    2058  basic_json(basic_json&& other) noexcept
    2059  : m_type(std::move(other.m_type)),
    2060  m_value(std::move(other.m_value))
    2061  {
    2062  // check that passed value is valid
    2063  other.assert_invariant();
    2064 
    2065  // invalidate payload
    2066  other.m_type = value_t::null;
    2067  other.m_value = {};
    2068 
    2069  assert_invariant();
    2070  }
    2071 
    2095  reference& operator=(basic_json other) noexcept (
    2096  std::is_nothrow_move_constructible<value_t>::value and
    2097  std::is_nothrow_move_assignable<value_t>::value and
    2098  std::is_nothrow_move_constructible<json_value>::value and
    2099  std::is_nothrow_move_assignable<json_value>::value
    2100  )
    2101  {
    2102  // check that passed value is valid
    2103  other.assert_invariant();
    2104 
    2105  using std::swap;
    2106  swap(m_type, other.m_type);
    2107  swap(m_value, other.m_value);
    2108 
    2109  assert_invariant();
    2110  return *this;
    2111  }
    2112 
    2129  {
    2130  assert_invariant();
    2131 
    2132  switch (m_type)
    2133  {
    2134  case value_t::object:
    2135  {
    2136  AllocatorType<object_t> alloc;
    2137  alloc.destroy(m_value.object);
    2138  alloc.deallocate(m_value.object, 1);
    2139  break;
    2140  }
    2141 
    2142  case value_t::array:
    2143  {
    2144  AllocatorType<array_t> alloc;
    2145  alloc.destroy(m_value.array);
    2146  alloc.deallocate(m_value.array, 1);
    2147  break;
    2148  }
    2149 
    2150  case value_t::string:
    2151  {
    2152  AllocatorType<string_t> alloc;
    2153  alloc.destroy(m_value.string);
    2154  alloc.deallocate(m_value.string, 1);
    2155  break;
    2156  }
    2157 
    2158  default:
    2159  {
    2160  // all other types need no specific destructor
    2161  break;
    2162  }
    2163  }
    2164  }
    2165 
    2167 
    2168  public:
    2170  // object inspection //
    2172 
    2176 
    2200  string_t dump(const int indent = -1) const
    2201  {
    2202  std::stringstream ss;
    2203  // fix locale problems
    2204  const static std::locale loc(std::locale(), new DecimalSeparator);
    2205  ss.imbue(loc);
    2206 
    2207  // 6, 15 or 16 digits of precision allows round-trip IEEE 754
    2208  // string->float->string, string->double->string or string->long
    2209  // double->string; to be safe, we read this value from
    2210  // std::numeric_limits<number_float_t>::digits10
    2211  ss.precision(std::numeric_limits<double>::digits10);
    2212 
    2213  if (indent >= 0)
    2214  {
    2215  dump(ss, true, static_cast<unsigned int>(indent));
    2216  }
    2217  else
    2218  {
    2219  dump(ss, false, 0);
    2220  }
    2221 
    2222  return ss.str();
    2223  }
    2224 
    2243  constexpr value_t type() const noexcept
    2244  {
    2245  return m_type;
    2246  }
    2247 
    2273  constexpr bool is_primitive() const noexcept
    2274  {
    2275  return is_null() or is_string() or is_boolean() or is_number();
    2276  }
    2277 
    2300  constexpr bool is_structured() const noexcept
    2301  {
    2302  return is_array() or is_object();
    2303  }
    2304 
    2322  constexpr bool is_null() const noexcept
    2323  {
    2324  return m_type == value_t::null;
    2325  }
    2326 
    2344  constexpr bool is_boolean() const noexcept
    2345  {
    2346  return m_type == value_t::boolean;
    2347  }
    2348 
    2374  constexpr bool is_number() const noexcept
    2375  {
    2376  return is_number_integer() or is_number_float();
    2377  }
    2378 
    2403  constexpr bool is_number_integer() const noexcept
    2404  {
    2405  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2406  }
    2407 
    2431  constexpr bool is_number_unsigned() const noexcept
    2432  {
    2433  return m_type == value_t::number_unsigned;
    2434  }
    2435 
    2459  constexpr bool is_number_float() const noexcept
    2460  {
    2461  return m_type == value_t::number_float;
    2462  }
    2463 
    2481  constexpr bool is_object() const noexcept
    2482  {
    2483  return m_type == value_t::object;
    2484  }
    2485 
    2503  constexpr bool is_array() const noexcept
    2504  {
    2505  return m_type == value_t::array;
    2506  }
    2507 
    2525  constexpr bool is_string() const noexcept
    2526  {
    2527  return m_type == value_t::string;
    2528  }
    2529 
    2552  constexpr bool is_discarded() const noexcept
    2553  {
    2554  return m_type == value_t::discarded;
    2555  }
    2556 
    2575  constexpr operator value_t() const noexcept
    2576  {
    2577  return m_type;
    2578  }
    2579 
    2581 
    2582  private:
    2584  // value access //
    2586 
    2588  template<class T, typename std::enable_if<
    2589  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2590  std::is_convertible<basic_json_t, typename T::mapped_type>::value, int>::type = 0>
    2591  T get_impl(T*) const
    2592  {
    2593  if (is_object())
    2594  {
    2595  return T(m_value.object->begin(), m_value.object->end());
    2596  }
    2597  else
    2598  {
    2599  throw std::domain_error("type must be object, but is " + type_name());
    2600  }
    2601  }
    2602 
    2604  object_t get_impl(object_t*) const
    2605  {
    2606  if (is_object())
    2607  {
    2608  return *(m_value.object);
    2609  }
    2610  else
    2611  {
    2612  throw std::domain_error("type must be object, but is " + type_name());
    2613  }
    2614  }
    2615 
    2617  template<class T, typename std::enable_if<
    2618  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2619  not std::is_same<basic_json_t, typename T::value_type>::value and
    2620  not std::is_arithmetic<T>::value and
    2621  not std::is_convertible<std::string, T>::value and
    2622  not has_mapped_type<T>::value, int>::type = 0>
    2623  T get_impl(T*) const
    2624  {
    2625  if (is_array())
    2626  {
    2627  T to_vector;
    2628  std::transform(m_value.array->begin(), m_value.array->end(),
    2629  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2630  {
    2631  return i.get<typename T::value_type>();
    2632  });
    2633  return to_vector;
    2634  }
    2635  else
    2636  {
    2637  throw std::domain_error("type must be array, but is " + type_name());
    2638  }
    2639  }
    2640 
    2642  template<class T, typename std::enable_if<
    2643  std::is_convertible<basic_json_t, T>::value and
    2644  not std::is_same<basic_json_t, T>::value, int>::type = 0>
    2645  std::vector<T> get_impl(std::vector<T>*) const
    2646  {
    2647  if (is_array())
    2648  {
    2649  std::vector<T> to_vector;
    2650  to_vector.reserve(m_value.array->size());
    2651  std::transform(m_value.array->begin(), m_value.array->end(),
    2652  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2653  {
    2654  return i.get<T>();
    2655  });
    2656  return to_vector;
    2657  }
    2658  else
    2659  {
    2660  throw std::domain_error("type must be array, but is " + type_name());
    2661  }
    2662  }
    2663 
    2665  template<class T, typename std::enable_if<
    2666  std::is_same<basic_json, typename T::value_type>::value and
    2667  not has_mapped_type<T>::value, int>::type = 0>
    2668  T get_impl(T*) const
    2669  {
    2670  if (is_array())
    2671  {
    2672  return T(m_value.array->begin(), m_value.array->end());
    2673  }
    2674  else
    2675  {
    2676  throw std::domain_error("type must be array, but is " + type_name());
    2677  }
    2678  }
    2679 
    2681  array_t get_impl(array_t*) const
    2682  {
    2683  if (is_array())
    2684  {
    2685  return *(m_value.array);
    2686  }
    2687  else
    2688  {
    2689  throw std::domain_error("type must be array, but is " + type_name());
    2690  }
    2691  }
    2692 
    2694  template<typename T, typename std::enable_if<
    2695  std::is_convertible<string_t, T>::value, int>::type = 0>
    2696  T get_impl(T*) const
    2697  {
    2698  if (is_string())
    2699  {
    2700  return *m_value.string;
    2701  }
    2702  else
    2703  {
    2704  throw std::domain_error("type must be string, but is " + type_name());
    2705  }
    2706  }
    2707 
    2709  template<typename T, typename std::enable_if<
    2710  std::is_arithmetic<T>::value, int>::type = 0>
    2711  T get_impl(T*) const
    2712  {
    2713  switch (m_type)
    2714  {
    2715  case value_t::number_integer:
    2716  {
    2717  return static_cast<T>(m_value.number_integer);
    2718  }
    2719 
    2720  case value_t::number_unsigned:
    2721  {
    2722  return static_cast<T>(m_value.number_unsigned);
    2723  }
    2724 
    2725  case value_t::number_float:
    2726  {
    2727  return static_cast<T>(m_value.number_float);
    2728  }
    2729 
    2730  default:
    2731  {
    2732  throw std::domain_error("type must be number, but is " + type_name());
    2733  }
    2734  }
    2735  }
    2736 
    2738  constexpr boolean_t get_impl(boolean_t*) const
    2739  {
    2740  return is_boolean()
    2741  ? m_value.boolean
    2742  : throw std::domain_error("type must be boolean, but is " + type_name());
    2743  }
    2744 
    2746  object_t* get_impl_ptr(object_t*) noexcept
    2747  {
    2748  return is_object() ? m_value.object : nullptr;
    2749  }
    2750 
    2752  constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
    2753  {
    2754  return is_object() ? m_value.object : nullptr;
    2755  }
    2756 
    2758  array_t* get_impl_ptr(array_t*) noexcept
    2759  {
    2760  return is_array() ? m_value.array : nullptr;
    2761  }
    2762 
    2764  constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
    2765  {
    2766  return is_array() ? m_value.array : nullptr;
    2767  }
    2768 
    2770  string_t* get_impl_ptr(string_t*) noexcept
    2771  {
    2772  return is_string() ? m_value.string : nullptr;
    2773  }
    2774 
    2776  constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
    2777  {
    2778  return is_string() ? m_value.string : nullptr;
    2779  }
    2780 
    2782  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2783  {
    2784  return is_boolean() ? &m_value.boolean : nullptr;
    2785  }
    2786 
    2788  constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2789  {
    2790  return is_boolean() ? &m_value.boolean : nullptr;
    2791  }
    2792 
    2794  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2795  {
    2796  return is_number_integer() ? &m_value.number_integer : nullptr;
    2797  }
    2798 
    2800  constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2801  {
    2802  return is_number_integer() ? &m_value.number_integer : nullptr;
    2803  }
    2804 
    2806  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2807  {
    2808  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2809  }
    2810 
    2812  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2813  {
    2814  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2815  }
    2816 
    2818  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2819  {
    2820  return is_number_float() ? &m_value.number_float : nullptr;
    2821  }
    2822 
    2824  constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2825  {
    2826  return is_number_float() ? &m_value.number_float : nullptr;
    2827  }
    2828 
    2840  template<typename ReferenceType, typename ThisType>
    2841  static ReferenceType get_ref_impl(ThisType& obj)
    2842  {
    2843  // helper type
    2844  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2845 
    2846  // delegate the call to get_ptr<>()
    2847  auto ptr = obj.template get_ptr<PointerType>();
    2848 
    2849  if (ptr != nullptr)
    2850  {
    2851  return *ptr;
    2852  }
    2853  else
    2854  {
    2855  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2856  obj.type_name());
    2857  }
    2858  }
    2859 
    2860  public:
    2861 
    2865 
    2899  template<typename ValueType, typename std::enable_if<
    2900  not std::is_pointer<ValueType>::value, int>::type = 0>
    2901  ValueType get() const
    2902  {
    2903  return get_impl(static_cast<ValueType*>(nullptr));
    2904  }
    2905 
    2933  template<typename PointerType, typename std::enable_if<
    2934  std::is_pointer<PointerType>::value, int>::type = 0>
    2935  PointerType get() noexcept
    2936  {
    2937  // delegate the call to get_ptr
    2938  return get_ptr<PointerType>();
    2939  }
    2940 
    2945  template<typename PointerType, typename std::enable_if<
    2946  std::is_pointer<PointerType>::value, int>::type = 0>
    2947  constexpr const PointerType get() const noexcept
    2948  {
    2949  // delegate the call to get_ptr
    2950  return get_ptr<PointerType>();
    2951  }
    2952 
    2979  template<typename PointerType, typename std::enable_if<
    2980  std::is_pointer<PointerType>::value, int>::type = 0>
    2981  PointerType get_ptr() noexcept
    2982  {
    2983  // get the type of the PointerType (remove pointer and const)
    2984  using pointee_t = typename std::remove_const<typename
    2985  std::remove_pointer<typename
    2986  std::remove_const<PointerType>::type>::type>::type;
    2987  // make sure the type matches the allowed types
    2988  static_assert(
    2989  std::is_same<object_t, pointee_t>::value
    2990  or std::is_same<array_t, pointee_t>::value
    2991  or std::is_same<string_t, pointee_t>::value
    2992  or std::is_same<boolean_t, pointee_t>::value
    2993  or std::is_same<number_integer_t, pointee_t>::value
    2994  or std::is_same<number_unsigned_t, pointee_t>::value
    2995  or std::is_same<number_float_t, pointee_t>::value
    2996  , "incompatible pointer type");
    2997 
    2998  // delegate the call to get_impl_ptr<>()
    2999  return get_impl_ptr(static_cast<PointerType>(nullptr));
    3000  }
    3001 
    3006  template<typename PointerType, typename std::enable_if<
    3007  std::is_pointer<PointerType>::value and
    3008  std::is_const<typename std::remove_pointer<PointerType>::type>::value, int>::type = 0>
    3009  constexpr const PointerType get_ptr() const noexcept
    3010  {
    3011  // get the type of the PointerType (remove pointer and const)
    3012  using pointee_t = typename std::remove_const<typename
    3013  std::remove_pointer<typename
    3014  std::remove_const<PointerType>::type>::type>::type;
    3015  // make sure the type matches the allowed types
    3016  static_assert(
    3017  std::is_same<object_t, pointee_t>::value
    3018  or std::is_same<array_t, pointee_t>::value
    3019  or std::is_same<string_t, pointee_t>::value
    3020  or std::is_same<boolean_t, pointee_t>::value
    3021  or std::is_same<number_integer_t, pointee_t>::value
    3022  or std::is_same<number_unsigned_t, pointee_t>::value
    3023  or std::is_same<number_float_t, pointee_t>::value
    3024  , "incompatible pointer type");
    3025 
    3026  // delegate the call to get_impl_ptr<>() const
    3027  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    3028  }
    3029 
    3056  template<typename ReferenceType, typename std::enable_if<
    3057  std::is_reference<ReferenceType>::value, int>::type = 0>
    3058  ReferenceType get_ref()
    3059  {
    3060  // delegate call to get_ref_impl
    3061  return get_ref_impl<ReferenceType>(*this);
    3062  }
    3063 
    3068  template<typename ReferenceType, typename std::enable_if<
    3069  std::is_reference<ReferenceType>::value and
    3070  std::is_const<typename std::remove_reference<ReferenceType>::type>::value, int>::type = 0>
    3071  ReferenceType get_ref() const
    3072  {
    3073  // delegate call to get_ref_impl
    3074  return get_ref_impl<ReferenceType>(*this);
    3075  }
    3076 
    3105  template < typename ValueType, typename std::enable_if <
    3106  not std::is_pointer<ValueType>::value and
    3107  not std::is_same<ValueType, typename string_t::value_type>::value
    3108 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    3109  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    3110 #endif
    3111  , int >::type = 0 >
    3112  operator ValueType() const
    3113  {
    3114  // delegate the call to get<>() const
    3115  return get<ValueType>();
    3116  }
    3117 
    3119 
    3120 
    3122  // element access //
    3124 
    3128 
    3152  {
    3153  // at only works for arrays
    3154  if (is_array())
    3155  {
    3156  try
    3157  {
    3158  return m_value.array->at(idx);
    3159  }
    3160  catch (std::out_of_range&)
    3161  {
    3162  // create better exception explanation
    3163  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3164  }
    3165  }
    3166  else
    3167  {
    3168  throw std::domain_error("cannot use at() with " + type_name());
    3169  }
    3170  }
    3171 
    3195  {
    3196  // at only works for arrays
    3197  if (is_array())
    3198  {
    3199  try
    3200  {
    3201  return m_value.array->at(idx);
    3202  }
    3203  catch (std::out_of_range&)
    3204  {
    3205  // create better exception explanation
    3206  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3207  }
    3208  }
    3209  else
    3210  {
    3211  throw std::domain_error("cannot use at() with " + type_name());
    3212  }
    3213  }
    3214 
    3241  reference at(const typename object_t::key_type& key)
    3242  {
    3243  // at only works for objects
    3244  if (is_object())
    3245  {
    3246  try
    3247  {
    3248  return m_value.object->at(key);
    3249  }
    3250  catch (std::out_of_range&)
    3251  {
    3252  // create better exception explanation
    3253  throw std::out_of_range("key '" + key + "' not found");
    3254  }
    3255  }
    3256  else
    3257  {
    3258  throw std::domain_error("cannot use at() with " + type_name());
    3259  }
    3260  }
    3261 
    3288  const_reference at(const typename object_t::key_type& key) const
    3289  {
    3290  // at only works for objects
    3291  if (is_object())
    3292  {
    3293  try
    3294  {
    3295  return m_value.object->at(key);
    3296  }
    3297  catch (std::out_of_range&)
    3298  {
    3299  // create better exception explanation
    3300  throw std::out_of_range("key '" + key + "' not found");
    3301  }
    3302  }
    3303  else
    3304  {
    3305  throw std::domain_error("cannot use at() with " + type_name());
    3306  }
    3307  }
    3308 
    3335  {
    3336  // implicitly convert null value to an empty array
    3337  if (is_null())
    3338  {
    3339  m_type = value_t::array;
    3340  m_value.array = create<array_t>();
    3341  assert_invariant();
    3342  }
    3343 
    3344  // operator[] only works for arrays
    3345  if (is_array())
    3346  {
    3347  // fill up array with null values if given idx is outside range
    3348  if (idx >= m_value.array->size())
    3349  {
    3350  m_value.array->insert(m_value.array->end(),
    3351  idx - m_value.array->size() + 1,
    3352  basic_json());
    3353  }
    3354 
    3355  return m_value.array->operator[](idx);
    3356  }
    3357  else
    3358  {
    3359  throw std::domain_error("cannot use operator[] with " + type_name());
    3360  }
    3361  }
    3362 
    3383  {
    3384  // const operator[] only works for arrays
    3385  if (is_array())
    3386  {
    3387  return m_value.array->operator[](idx);
    3388  }
    3389  else
    3390  {
    3391  throw std::domain_error("cannot use operator[] with " + type_name());
    3392  }
    3393  }
    3394 
    3422  reference operator[](const typename object_t::key_type& key)
    3423  {
    3424  // implicitly convert null value to an empty object
    3425  if (is_null())
    3426  {
    3427  m_type = value_t::object;
    3428  m_value.object = create<object_t>();
    3429  assert_invariant();
    3430  }
    3431 
    3432  // operator[] only works for objects
    3433  if (is_object())
    3434  {
    3435  return m_value.object->operator[](key);
    3436  }
    3437  else
    3438  {
    3439  throw std::domain_error("cannot use operator[] with " + type_name());
    3440  }
    3441  }
    3442 
    3473  const_reference operator[](const typename object_t::key_type& key) const
    3474  {
    3475  // const operator[] only works for objects
    3476  if (is_object())
    3477  {
    3478  assert(m_value.object->find(key) != m_value.object->end());
    3479  return m_value.object->find(key)->second;
    3480  }
    3481  else
    3482  {
    3483  throw std::domain_error("cannot use operator[] with " + type_name());
    3484  }
    3485  }
    3486 
    3514  template<typename T, std::size_t n>
    3515  reference operator[](T * (&key)[n])
    3516  {
    3517  return operator[](static_cast<const T>(key));
    3518  }
    3519 
    3549  template<typename T, std::size_t n>
    3550  const_reference operator[](T * (&key)[n]) const
    3551  {
    3552  return operator[](static_cast<const T>(key));
    3553  }
    3554 
    3582  template<typename T>
    3584  {
    3585  // implicitly convert null to object
    3586  if (is_null())
    3587  {
    3588  m_type = value_t::object;
    3589  m_value = value_t::object;
    3590  assert_invariant();
    3591  }
    3592 
    3593  // at only works for objects
    3594  if (is_object())
    3595  {
    3596  return m_value.object->operator[](key);
    3597  }
    3598  else
    3599  {
    3600  throw std::domain_error("cannot use operator[] with " + type_name());
    3601  }
    3602  }
    3603 
    3634  template<typename T>
    3636  {
    3637  // at only works for objects
    3638  if (is_object())
    3639  {
    3640  assert(m_value.object->find(key) != m_value.object->end());
    3641  return m_value.object->find(key)->second;
    3642  }
    3643  else
    3644  {
    3645  throw std::domain_error("cannot use operator[] with " + type_name());
    3646  }
    3647  }
    3648 
    3697  template<class ValueType, typename std::enable_if<
    3698  std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
    3699  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3700  {
    3701  // at only works for objects
    3702  if (is_object())
    3703  {
    3704  // if key is found, return value and given default value otherwise
    3705  const auto it = find(key);
    3706  if (it != end())
    3707  {
    3708  return *it;
    3709  }
    3710  else
    3711  {
    3712  return default_value;
    3713  }
    3714  }
    3715  else
    3716  {
    3717  throw std::domain_error("cannot use value() with " + type_name());
    3718  }
    3719  }
    3720 
    3725  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3726  {
    3727  return value(key, string_t(default_value));
    3728  }
    3729 
    3771  template<class ValueType, typename std::enable_if<
    3772  std::is_convertible<basic_json_t, ValueType>::value, int>::type = 0>
    3773  ValueType value(const json_pointer& ptr, ValueType default_value) const
    3774  {
    3775  // at only works for objects
    3776  if (is_object())
    3777  {
    3778  // if pointer resolves a value, return it or use default value
    3779  try
    3780  {
    3781  return ptr.get_checked(this);
    3782  }
    3783  catch (std::out_of_range&)
    3784  {
    3785  return default_value;
    3786  }
    3787  }
    3788  else
    3789  {
    3790  throw std::domain_error("cannot use value() with " + type_name());
    3791  }
    3792  }
    3793 
    3798  string_t value(const json_pointer& ptr, const char* default_value) const
    3799  {
    3800  return value(ptr, string_t(default_value));
    3801  }
    3802 
    3829  {
    3830  return *begin();
    3831  }
    3832 
    3837  {
    3838  return *cbegin();
    3839  }
    3840 
    3872  {
    3873  auto tmp = end();
    3874  --tmp;
    3875  return *tmp;
    3876  }
    3877 
    3882  {
    3883  auto tmp = cend();
    3884  --tmp;
    3885  return *tmp;
    3886  }
    3887 
    3933  template<class IteratorType, typename std::enable_if<
    3934  std::is_same<IteratorType, typename basic_json_t::iterator>::value or
    3935  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int>::type
    3936  = 0>
    3937  IteratorType erase(IteratorType pos)
    3938  {
    3939  // make sure iterator fits the current value
    3940  if (this != pos.m_object)
    3941  {
    3942  throw std::domain_error("iterator does not fit current value");
    3943  }
    3944 
    3945  IteratorType result = end();
    3946 
    3947  switch (m_type)
    3948  {
    3949  case value_t::boolean:
    3950  case value_t::number_float:
    3951  case value_t::number_integer:
    3952  case value_t::number_unsigned:
    3953  case value_t::string:
    3954  {
    3955  if (not pos.m_it.primitive_iterator.is_begin())
    3956  {
    3957  throw std::out_of_range("iterator out of range");
    3958  }
    3959 
    3960  if (is_string())
    3961  {
    3962  AllocatorType<string_t> alloc;
    3963  alloc.destroy(m_value.string);
    3964  alloc.deallocate(m_value.string, 1);
    3965  m_value.string = nullptr;
    3966  }
    3967 
    3968  m_type = value_t::null;
    3969  assert_invariant();
    3970  break;
    3971  }
    3972 
    3973  case value_t::object:
    3974  {
    3975  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3976  break;
    3977  }
    3978 
    3979  case value_t::array:
    3980  {
    3981  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3982  break;
    3983  }
    3984 
    3985  default:
    3986  {
    3987  throw std::domain_error("cannot use erase() with " + type_name());
    3988  }
    3989  }
    3990 
    3991  return result;
    3992  }
    3993 
    4040  template<class IteratorType, typename std::enable_if<
    4041  std::is_same<IteratorType, typename basic_json_t::iterator>::value or
    4042  std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int>::type
    4043  = 0>
    4044  IteratorType erase(IteratorType first, IteratorType last)
    4045  {
    4046  // make sure iterator fits the current value
    4047  if (this != first.m_object or this != last.m_object)
    4048  {
    4049  throw std::domain_error("iterators do not fit current value");
    4050  }
    4051 
    4052  IteratorType result = end();
    4053 
    4054  switch (m_type)
    4055  {
    4056  case value_t::boolean:
    4057  case value_t::number_float:
    4058  case value_t::number_integer:
    4059  case value_t::number_unsigned:
    4060  case value_t::string:
    4061  {
    4062  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    4063  {
    4064  throw std::out_of_range("iterators out of range");
    4065  }
    4066 
    4067  if (is_string())
    4068  {
    4069  AllocatorType<string_t> alloc;
    4070  alloc.destroy(m_value.string);
    4071  alloc.deallocate(m_value.string, 1);
    4072  m_value.string = nullptr;
    4073  }
    4074 
    4075  m_type = value_t::null;
    4076  assert_invariant();
    4077  break;
    4078  }
    4079 
    4080  case value_t::object:
    4081  {
    4082  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    4083  last.m_it.object_iterator);
    4084  break;
    4085  }
    4086 
    4087  case value_t::array:
    4088  {
    4089  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    4090  last.m_it.array_iterator);
    4091  break;
    4092  }
    4093 
    4094  default:
    4095  {
    4096  throw std::domain_error("cannot use erase() with " + type_name());
    4097  }
    4098  }
    4099 
    4100  return result;
    4101  }
    4102 
    4132  size_type erase(const typename object_t::key_type& key)
    4133  {
    4134  // this erase only works for objects
    4135  if (is_object())
    4136  {
    4137  return m_value.object->erase(key);
    4138  }
    4139  else
    4140  {
    4141  throw std::domain_error("cannot use erase() with " + type_name());
    4142  }
    4143  }
    4144 
    4169  void erase(const size_type idx)
    4170  {
    4171  // this erase only works for arrays
    4172  if (is_array())
    4173  {
    4174  if (idx >= size())
    4175  {
    4176  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    4177  }
    4178 
    4179  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    4180  }
    4181  else
    4182  {
    4183  throw std::domain_error("cannot use erase() with " + type_name());
    4184  }
    4185  }
    4186 
    4188 
    4189 
    4191  // lookup //
    4193 
    4196 
    4215  iterator find(typename object_t::key_type key)
    4216  {
    4217  auto result = end();
    4218 
    4219  if (is_object())
    4220  {
    4221  result.m_it.object_iterator = m_value.object->find(key);
    4222  }
    4223 
    4224  return result;
    4225  }
    4226 
    4231  const_iterator find(typename object_t::key_type key) const
    4232  {
    4233  auto result = cend();
    4234 
    4235  if (is_object())
    4236  {
    4237  result.m_it.object_iterator = m_value.object->find(key);
    4238  }
    4239 
    4240  return result;
    4241  }
    4242 
    4261  size_type count(typename object_t::key_type key) const
    4262  {
    4263  // return 0 for all nonobject types
    4264  return is_object() ? m_value.object->count(key) : 0;
    4265  }
    4266 
    4268 
    4269 
    4271  // iterators //
    4273 
    4276 
    4301  iterator begin() noexcept
    4302  {
    4303  iterator result(this);
    4304  result.set_begin();
    4305  return result;
    4306  }
    4307 
    4311  const_iterator begin() const noexcept
    4312  {
    4313  return cbegin();
    4314  }
    4315 
    4341  const_iterator cbegin() const noexcept
    4342  {
    4343  const_iterator result(this);
    4344  result.set_begin();
    4345  return result;
    4346  }
    4347 
    4372  iterator end() noexcept
    4373  {
    4374  iterator result(this);
    4375  result.set_end();
    4376  return result;
    4377  }
    4378 
    4382  const_iterator end() const noexcept
    4383  {
    4384  return cend();
    4385  }
    4386 
    4412  const_iterator cend() const noexcept
    4413  {
    4414  const_iterator result(this);
    4415  result.set_end();
    4416  return result;
    4417  }
    4418 
    4443  {
    4444  return reverse_iterator(end());
    4445  }
    4446 
    4451  {
    4452  return crbegin();
    4453  }
    4454 
    4480  {
    4481  return reverse_iterator(begin());
    4482  }
    4483 
    4487  const_reverse_iterator rend() const noexcept
    4488  {
    4489  return crend();
    4490  }
    4491 
    4517  {
    4518  return const_reverse_iterator(cend());
    4519  }
    4520 
    4546  {
    4547  return const_reverse_iterator(cbegin());
    4548  }
    4549 
    4550  private:
    4551  // forward declaration
    4552  template<typename IteratorType> class iteration_proxy;
    4553 
    4554  public:
    4566  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4567  {
    4568  return iteration_proxy<iterator>(cont);
    4569  }
    4570 
    4574  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4575  {
    4576  return iteration_proxy<const_iterator>(cont);
    4577  }
    4578 
    4580 
    4581 
    4583  // capacity //
    4585 
    4588 
    4626  bool empty() const noexcept
    4627  {
    4628  switch (m_type)
    4629  {
    4630  case value_t::null:
    4631  {
    4632  // null values are empty
    4633  return true;
    4634  }
    4635 
    4636  case value_t::array:
    4637  {
    4638  // delegate call to array_t::empty()
    4639  return m_value.array->empty();
    4640  }
    4641 
    4642  case value_t::object:
    4643  {
    4644  // delegate call to object_t::empty()
    4645  return m_value.object->empty();
    4646  }
    4647 
    4648  default:
    4649  {
    4650  // all other types are nonempty
    4651  return false;
    4652  }
    4653  }
    4654  }
    4655 
    4694  size_type size() const noexcept
    4695  {
    4696  switch (m_type)
    4697  {
    4698  case value_t::null:
    4699  {
    4700  // null values are empty
    4701  return 0;
    4702  }
    4703 
    4704  case value_t::array:
    4705  {
    4706  // delegate call to array_t::size()
    4707  return m_value.array->size();
    4708  }
    4709 
    4710  case value_t::object:
    4711  {
    4712  // delegate call to object_t::size()
    4713  return m_value.object->size();
    4714  }
    4715 
    4716  default:
    4717  {
    4718  // all other types have size 1
    4719  return 1;
    4720  }
    4721  }
    4722  }
    4723 
    4760  size_type max_size() const noexcept
    4761  {
    4762  switch (m_type)
    4763  {
    4764  case value_t::array:
    4765  {
    4766  // delegate call to array_t::max_size()
    4767  return m_value.array->max_size();
    4768  }
    4769 
    4770  case value_t::object:
    4771  {
    4772  // delegate call to object_t::max_size()
    4773  return m_value.object->max_size();
    4774  }
    4775 
    4776  default:
    4777  {
    4778  // all other types have max_size() == size()
    4779  return size();
    4780  }
    4781  }
    4782  }
    4783 
    4785 
    4786 
    4788  // modifiers //
    4790 
    4793 
    4819  void clear() noexcept
    4820  {
    4821  switch (m_type)
    4822  {
    4823  case value_t::number_integer:
    4824  {
    4825  m_value.number_integer = 0;
    4826  break;
    4827  }
    4828 
    4829  case value_t::number_unsigned:
    4830  {
    4831  m_value.number_unsigned = 0;
    4832  break;
    4833  }
    4834 
    4835  case value_t::number_float:
    4836  {
    4837  m_value.number_float = 0.0;
    4838  break;
    4839  }
    4840 
    4841  case value_t::boolean:
    4842  {
    4843  m_value.boolean = false;
    4844  break;
    4845  }
    4846 
    4847  case value_t::string:
    4848  {
    4849  m_value.string->clear();
    4850  break;
    4851  }
    4852 
    4853  case value_t::array:
    4854  {
    4855  m_value.array->clear();
    4856  break;
    4857  }
    4858 
    4859  case value_t::object:
    4860  {
    4861  m_value.object->clear();
    4862  break;
    4863  }
    4864 
    4865  default:
    4866  {
    4867  break;
    4868  }
    4869  }
    4870  }
    4871 
    4892  void push_back(basic_json&& val)
    4893  {
    4894  // push_back only works for null objects or arrays
    4895  if (not(is_null() or is_array()))
    4896  {
    4897  throw std::domain_error("cannot use push_back() with " + type_name());
    4898  }
    4899 
    4900  // transform null object into an array
    4901  if (is_null())
    4902  {
    4903  m_type = value_t::array;
    4904  m_value = value_t::array;
    4905  assert_invariant();
    4906  }
    4907 
    4908  // add element to array (move semantics)
    4909  m_value.array->push_back(std::move(val));
    4910  // invalidate object
    4911  val.m_type = value_t::null;
    4912  }
    4913 
    4919  {
    4920  push_back(std::move(val));
    4921  return *this;
    4922  }
    4923 
    4928  void push_back(const basic_json& val)
    4929  {
    4930  // push_back only works for null objects or arrays
    4931  if (not(is_null() or is_array()))
    4932  {
    4933  throw std::domain_error("cannot use push_back() with " + type_name());
    4934  }
    4935 
    4936  // transform null object into an array
    4937  if (is_null())
    4938  {
    4939  m_type = value_t::array;
    4940  m_value = value_t::array;
    4941  assert_invariant();
    4942  }
    4943 
    4944  // add element to array
    4945  m_value.array->push_back(val);
    4946  }
    4947 
    4953  {
    4954  push_back(val);
    4955  return *this;
    4956  }
    4957 
    4978  void push_back(const typename object_t::value_type& val)
    4979  {
    4980  // push_back only works for null objects or objects
    4981  if (not(is_null() or is_object()))
    4982  {
    4983  throw std::domain_error("cannot use push_back() with " + type_name());
    4984  }
    4985 
    4986  // transform null object into an object
    4987  if (is_null())
    4988  {
    4989  m_type = value_t::object;
    4990  m_value = value_t::object;
    4991  assert_invariant();
    4992  }
    4993 
    4994  // add element to array
    4995  m_value.object->insert(val);
    4996  }
    4997 
    5002  reference operator+=(const typename object_t::value_type& val)
    5003  {
    5004  push_back(val);
    5005  return *this;
    5006  }
    5007 
    5033  void push_back(std::initializer_list<basic_json> init)
    5034  {
    5035  if (is_object() and init.size() == 2 and init.begin()->is_string())
    5036  {
    5037  const string_t key = *init.begin();
    5038  push_back(typename object_t::value_type(key, *(init.begin() + 1)));
    5039  }
    5040  else
    5041  {
    5042  push_back(basic_json(init));
    5043  }
    5044  }
    5045 
    5050  reference operator+=(std::initializer_list<basic_json> init)
    5051  {
    5052  push_back(init);
    5053  return *this;
    5054  }
    5055 
    5079  {
    5080  // insert only works for arrays
    5081  if (is_array())
    5082  {
    5083  // check if iterator pos fits to this JSON value
    5084  if (pos.m_object != this)
    5085  {
    5086  throw std::domain_error("iterator does not fit current value");
    5087  }
    5088 
    5089  // insert to array and return iterator
    5090  iterator result(this);
    5091  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    5092  return result;
    5093  }
    5094  else
    5095  {
    5096  throw std::domain_error("cannot use insert() with " + type_name());
    5097  }
    5098  }
    5099 
    5105  {
    5106  return insert(pos, val);
    5107  }
    5108 
    5134  {
    5135  // insert only works for arrays
    5136  if (is_array())
    5137  {
    5138  // check if iterator pos fits to this JSON value
    5139  if (pos.m_object != this)
    5140  {
    5141  throw std::domain_error("iterator does not fit current value");
    5142  }
    5143 
    5144  // insert to array and return iterator
    5145  iterator result(this);
    5146  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    5147  return result;
    5148  }
    5149  else
    5150  {
    5151  throw std::domain_error("cannot use insert() with " + type_name());
    5152  }
    5153  }
    5154 
    5186  {
    5187  // insert only works for arrays
    5188  if (not is_array())
    5189  {
    5190  throw std::domain_error("cannot use insert() with " + type_name());
    5191  }
    5192 
    5193  // check if iterator pos fits to this JSON value
    5194  if (pos.m_object != this)
    5195  {
    5196  throw std::domain_error("iterator does not fit current value");
    5197  }
    5198 
    5199  // check if range iterators belong to the same JSON object
    5200  if (first.m_object != last.m_object)
    5201  {
    5202  throw std::domain_error("iterators do not fit");
    5203  }
    5204 
    5205  if (first.m_object == this or last.m_object == this)
    5206  {
    5207  throw std::domain_error("passed iterators may not belong to container");
    5208  }
    5209 
    5210  // insert to array and return iterator
    5211  iterator result(this);
    5212  result.m_it.array_iterator = m_value.array->insert(
    5213  pos.m_it.array_iterator,
    5214  first.m_it.array_iterator,
    5215  last.m_it.array_iterator);
    5216  return result;
    5217  }
    5218 
    5243  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    5244  {
    5245  // insert only works for arrays
    5246  if (not is_array())
    5247  {
    5248  throw std::domain_error("cannot use insert() with " + type_name());
    5249  }
    5250 
    5251  // check if iterator pos fits to this JSON value
    5252  if (pos.m_object != this)
    5253  {
    5254  throw std::domain_error("iterator does not fit current value");
    5255  }
    5256 
    5257  // insert to array and return iterator
    5258  iterator result(this);
    5259  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    5260  return result;
    5261  }
    5262 
    5280  void swap(reference other) noexcept (
    5281  std::is_nothrow_move_constructible<value_t>::value and
    5282  std::is_nothrow_move_assignable<value_t>::value and
    5283  std::is_nothrow_move_constructible<json_value>::value and
    5284  std::is_nothrow_move_assignable<json_value>::value
    5285  )
    5286  {
    5287  std::swap(m_type, other.m_type);
    5288  std::swap(m_value, other.m_value);
    5289  assert_invariant();
    5290  }
    5291 
    5312  void swap(array_t& other)
    5313  {
    5314  // swap only works for arrays
    5315  if (is_array())
    5316  {
    5317  std::swap(*(m_value.array), other);
    5318  }
    5319  else
    5320  {
    5321  throw std::domain_error("cannot use swap() with " + type_name());
    5322  }
    5323  }
    5324 
    5345  void swap(object_t& other)
    5346  {
    5347  // swap only works for objects
    5348  if (is_object())
    5349  {
    5350  std::swap(*(m_value.object), other);
    5351  }
    5352  else
    5353  {
    5354  throw std::domain_error("cannot use swap() with " + type_name());
    5355  }
    5356  }
    5357 
    5378  void swap(string_t& other)
    5379  {
    5380  // swap only works for strings
    5381  if (is_string())
    5382  {
    5383  std::swap(*(m_value.string), other);
    5384  }
    5385  else
    5386  {
    5387  throw std::domain_error("cannot use swap() with " + type_name());
    5388  }
    5389  }
    5390 
    5392 
    5393 
    5395  // lexicographical comparison operators //
    5397 
    5400 
    5401  private:
    5411  friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    5412  {
    5413  static constexpr std::array<uint8_t, 8> order = {{
    5414  0, // null
    5415  3, // object
    5416  4, // array
    5417  5, // string
    5418  1, // boolean
    5419  2, // integer
    5420  2, // unsigned
    5421  2, // float
    5422  }
    5423  };
    5424 
    5425  // discarded values are not comparable
    5426  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5427  {
    5428  return false;
    5429  }
    5430 
    5431  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5432  }
    5433 
    5434  public:
    5458  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5459  {
    5460  const auto lhs_type = lhs.type();
    5461  const auto rhs_type = rhs.type();
    5462 
    5463  if (lhs_type == rhs_type)
    5464  {
    5465  switch (lhs_type)
    5466  {
    5467  case value_t::array:
    5468  {
    5469  return *lhs.m_value.array == *rhs.m_value.array;
    5470  }
    5471  case value_t::object:
    5472  {
    5473  return *lhs.m_value.object == *rhs.m_value.object;
    5474  }
    5475  case value_t::null:
    5476  {
    5477  return true;
    5478  }
    5479  case value_t::string:
    5480  {
    5481  return *lhs.m_value.string == *rhs.m_value.string;
    5482  }
    5483  case value_t::boolean:
    5484  {
    5485  return lhs.m_value.boolean == rhs.m_value.boolean;
    5486  }
    5487  case value_t::number_integer:
    5488  {
    5489  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5490  }
    5491  case value_t::number_unsigned:
    5492  {
    5493  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5494  }
    5495  case value_t::number_float:
    5496  {
    5497  return lhs.m_value.number_float == rhs.m_value.number_float;
    5498  }
    5499  default:
    5500  {
    5501  return false;
    5502  }
    5503  }
    5504  }
    5505  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5506  {
    5507  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5508  }
    5509  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5510  {
    5511  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5512  }
    5513  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5514  {
    5515  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5516  }
    5517  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5518  {
    5519  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5520  }
    5521  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5522  {
    5523  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5524  }
    5525  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5526  {
    5527  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5528  }
    5529 
    5530  return false;
    5531  }
    5532 
    5551  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5552  {
    5553  return v.is_null();
    5554  }
    5555 
    5560  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5561  {
    5562  return v.is_null();
    5563  }
    5564 
    5581  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5582  {
    5583  return not (lhs == rhs);
    5584  }
    5585 
    5604  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5605  {
    5606  return not v.is_null();
    5607  }
    5608 
    5613  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5614  {
    5615  return not v.is_null();
    5616  }
    5617 
    5642  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5643  {
    5644  const auto lhs_type = lhs.type();
    5645  const auto rhs_type = rhs.type();
    5646 
    5647  if (lhs_type == rhs_type)
    5648  {
    5649  switch (lhs_type)
    5650  {
    5651  case value_t::array:
    5652  {
    5653  return *lhs.m_value.array < *rhs.m_value.array;
    5654  }
    5655  case value_t::object:
    5656  {
    5657  return *lhs.m_value.object < *rhs.m_value.object;
    5658  }
    5659  case value_t::null:
    5660  {
    5661  return false;
    5662  }
    5663  case value_t::string:
    5664  {
    5665  return *lhs.m_value.string < *rhs.m_value.string;
    5666  }
    5667  case value_t::boolean:
    5668  {
    5669  return lhs.m_value.boolean < rhs.m_value.boolean;
    5670  }
    5671  case value_t::number_integer:
    5672  {
    5673  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5674  }
    5675  case value_t::number_unsigned:
    5676  {
    5677  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5678  }
    5679  case value_t::number_float:
    5680  {
    5681  return lhs.m_value.number_float < rhs.m_value.number_float;
    5682  }
    5683  default:
    5684  {
    5685  return false;
    5686  }
    5687  }
    5688  }
    5689  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5690  {
    5691  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5692  }
    5693  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5694  {
    5695  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5696  }
    5697  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5698  {
    5699  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5700  }
    5701  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5702  {
    5703  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5704  }
    5705  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5706  {
    5707  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5708  }
    5709  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5710  {
    5711  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5712  }
    5713 
    5714  // We only reach this line if we cannot compare values. In that case,
    5715  // we compare types. Note we have to call the operator explicitly,
    5716  // because MSVC has problems otherwise.
    5717  return operator<(lhs_type, rhs_type);
    5718  }
    5719 
    5737  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5738  {
    5739  return not (rhs < lhs);
    5740  }
    5741 
    5759  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5760  {
    5761  return not (lhs <= rhs);
    5762  }
    5763 
    5781  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5782  {
    5783  return not (lhs < rhs);
    5784  }
    5785 
    5787 
    5788 
    5790  // serialization //
    5792 
    5795 
    5822  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5823  {
    5824  // read width member and use it as indentation parameter if nonzero
    5825  const bool pretty_print = (o.width() > 0);
    5826  const auto indentation = (pretty_print ? o.width() : 0);
    5827 
    5828  // reset width to 0 for subsequent calls to this stream
    5829  o.width(0);
    5830 
    5831  // fix locale problems
    5832  const auto old_locale = o.imbue(std::locale(std::locale(), new DecimalSeparator));
    5833  // set precision
    5834 
    5835  // 6, 15 or 16 digits of precision allows round-trip IEEE 754
    5836  // string->float->string, string->double->string or string->long
    5837  // double->string; to be safe, we read this value from
    5838  // std::numeric_limits<number_float_t>::digits10
    5839  const auto old_precision = o.precision(std::numeric_limits<double>::digits10);
    5840 
    5841  // do the actual serialization
    5842  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5843 
    5844  // reset locale and precision
    5845  o.imbue(old_locale);
    5846  o.precision(old_precision);
    5847  return o;
    5848  }
    5849 
    5854  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5855  {
    5856  return o << j;
    5857  }
    5858 
    5860 
    5861 
    5863  // deserialization //
    5865 
    5868 
    5896  template<class T, std::size_t N>
    5897  static basic_json parse(T (&array)[N],
    5898  const parser_callback_t cb = nullptr)
    5899  {
    5900  // delegate the call to the iterator-range parse overload
    5901  return parse(std::begin(array), std::end(array), cb);
    5902  }
    5903 
    5931  template<typename CharPT, typename std::enable_if<
    5932  std::is_pointer<CharPT>::value and
    5933  std::is_integral<typename std::remove_pointer<CharPT>::type>::value and
    5934  sizeof(typename std::remove_pointer<CharPT>::type) == 1, int>::type = 0>
    5935  static basic_json parse(const CharPT s,
    5936  const parser_callback_t cb = nullptr)
    5937  {
    5938  return parser(reinterpret_cast<const char*>(s), cb).parse();
    5939  }
    5940 
    5965  static basic_json parse(std::istream& i,
    5966  const parser_callback_t cb = nullptr)
    5967  {
    5968  return parser(i, cb).parse();
    5969  }
    5970 
    5974  static basic_json parse(std::istream&& i,
    5975  const parser_callback_t cb = nullptr)
    5976  {
    5977  return parser(i, cb).parse();
    5978  }
    5979 
    6021  template<class IteratorType, typename std::enable_if<
    6022  std::is_base_of<
    6023  std::random_access_iterator_tag,
    6024  typename std::iterator_traits<IteratorType>::iterator_category>::value, int>::type = 0>
    6025  static basic_json parse(IteratorType first, IteratorType last,
    6026  const parser_callback_t cb = nullptr)
    6027  {
    6028  // assertion to check that the iterator range is indeed contiguous,
    6029  // see http://stackoverflow.com/a/35008842/266378 for more discussion
    6030  assert(std::accumulate(first, last, std::make_pair<bool, int>(true, 0),
    6031  [&first](std::pair<bool, int> res, decltype(*first) val)
    6032  {
    6033  res.first &= (val == *(std::next(std::addressof(*first), res.second++)));
    6034  return res;
    6035  }).first);
    6036 
    6037  // assertion to check that each element is 1 byte long
    6038  static_assert(sizeof(typename std::iterator_traits<IteratorType>::value_type) == 1,
    6039  "each element in the iterator range must have the size of 1 byte");
    6040 
    6041  // if iterator range is empty, create a parser with an empty string
    6042  // to generate "unexpected EOF" error message
    6043  if (std::distance(first, last) <= 0)
    6044  {
    6045  return parser("").parse();
    6046  }
    6047 
    6048  return parser(first, last, cb).parse();
    6049  }
    6050 
    6091  template<class ContiguousContainer, typename std::enable_if<
    6092  not std::is_pointer<ContiguousContainer>::value and
    6093  std::is_base_of<
    6094  std::random_access_iterator_tag,
    6095  typename std::iterator_traits<decltype(std::begin(std::declval<ContiguousContainer const>()))>::iterator_category>::value
    6096  , int>::type = 0>
    6097  static basic_json parse(const ContiguousContainer& c,
    6098  const parser_callback_t cb = nullptr)
    6099  {
    6100  // delegate the call to the iterator-range parse overload
    6101  return parse(std::begin(c), std::end(c), cb);
    6102  }
    6103 
    6127  friend std::istream& operator<<(basic_json& j, std::istream& i)
    6128  {
    6129  j = parser(i).parse();
    6130  return i;
    6131  }
    6132 
    6137  friend std::istream& operator>>(std::istream& i, basic_json& j)
    6138  {
    6139  j = parser(i).parse();
    6140  return i;
    6141  }
    6142 
    6144 
    6145 
    6146  private:
    6148  // convenience functions //
    6150 
    6163  std::string type_name() const
    6164  {
    6165  switch (m_type)
    6166  {
    6167  case value_t::null:
    6168  return "null";
    6169  case value_t::object:
    6170  return "object";
    6171  case value_t::array:
    6172  return "array";
    6173  case value_t::string:
    6174  return "string";
    6175  case value_t::boolean:
    6176  return "boolean";
    6177  case value_t::discarded:
    6178  return "discarded";
    6179  default:
    6180  return "number";
    6181  }
    6182  }
    6183 
    6192  static std::size_t extra_space(const string_t& s) noexcept
    6193  {
    6194  return std::accumulate(s.begin(), s.end(), size_t{},
    6195  [](size_t res, typename string_t::value_type c)
    6196  {
    6197  switch (c)
    6198  {
    6199  case '"':
    6200  case '\\':
    6201  case '\b':
    6202  case '\f':
    6203  case '\n':
    6204  case '\r':
    6205  case '\t':
    6206  {
    6207  // from c (1 byte) to \x (2 bytes)
    6208  return res + 1;
    6209  }
    6210 
    6211  default:
    6212  {
    6213  if (c >= 0x00 and c <= 0x1f)
    6214  {
    6215  // from c (1 byte) to \uxxxx (6 bytes)
    6216  return res + 5;
    6217  }
    6218  else
    6219  {
    6220  return res;
    6221  }
    6222  }
    6223  }
    6224  });
    6225  }
    6226 
    6240  static string_t escape_string(const string_t& s)
    6241  {
    6242  const auto space = extra_space(s);
    6243  if (space == 0)
    6244  {
    6245  return s;
    6246  }
    6247 
    6248  // create a result string of necessary size
    6249  string_t result(s.size() + space, '\\');
    6250  std::size_t pos = 0;
    6251 
    6252  for (const auto& c : s)
    6253  {
    6254  switch (c)
    6255  {
    6256  // quotation mark (0x22)
    6257  case '"':
    6258  {
    6259  result[pos + 1] = '"';
    6260  pos += 2;
    6261  break;
    6262  }
    6263 
    6264  // reverse solidus (0x5c)
    6265  case '\\':
    6266  {
    6267  // nothing to change
    6268  pos += 2;
    6269  break;
    6270  }
    6271 
    6272  // backspace (0x08)
    6273  case '\b':
    6274  {
    6275  result[pos + 1] = 'b';
    6276  pos += 2;
    6277  break;
    6278  }
    6279 
    6280  // formfeed (0x0c)
    6281  case '\f':
    6282  {
    6283  result[pos + 1] = 'f';
    6284  pos += 2;
    6285  break;
    6286  }
    6287 
    6288  // newline (0x0a)
    6289  case '\n':
    6290  {
    6291  result[pos + 1] = 'n';
    6292  pos += 2;
    6293  break;
    6294  }
    6295 
    6296  // carriage return (0x0d)
    6297  case '\r':
    6298  {
    6299  result[pos + 1] = 'r';
    6300  pos += 2;
    6301  break;
    6302  }
    6303 
    6304  // horizontal tab (0x09)
    6305  case '\t':
    6306  {
    6307  result[pos + 1] = 't';
    6308  pos += 2;
    6309  break;
    6310  }
    6311 
    6312  default:
    6313  {
    6314  if (c >= 0x00 and c <= 0x1f)
    6315  {
    6316  // convert a number 0..15 to its hex representation
    6317  // (0..f)
    6318  static const char hexify[16] =
    6319  {
    6320  '0', '1', '2', '3', '4', '5', '6', '7',
    6321  '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
    6322  };
    6323 
    6324  // print character c as \uxxxx
    6325  for (const char m :
    6326  { 'u', '0', '0', hexify[c >> 4], hexify[c & 0x0f]
    6327  })
    6328  {
    6329  result[++pos] = m;
    6330  }
    6331 
    6332  ++pos;
    6333  }
    6334  else
    6335  {
    6336  // all other characters are added as-is
    6337  result[pos++] = c;
    6338  }
    6339  break;
    6340  }
    6341  }
    6342  }
    6343 
    6344  return result;
    6345  }
    6346 
    6364  void dump(std::ostream& o,
    6365  const bool pretty_print,
    6366  const unsigned int indent_step,
    6367  const unsigned int current_indent = 0) const
    6368  {
    6369  // variable to hold indentation for recursive calls
    6370  unsigned int new_indent = current_indent;
    6371 
    6372  switch (m_type)
    6373  {
    6374  case value_t::object:
    6375  {
    6376  if (m_value.object->empty())
    6377  {
    6378  o << "{}";
    6379  return;
    6380  }
    6381 
    6382  o << "{";
    6383 
    6384  // increase indentation
    6385  if (pretty_print)
    6386  {
    6387  new_indent += indent_step;
    6388  o << "\n";
    6389  }
    6390 
    6391  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    6392  {
    6393  if (i != m_value.object->cbegin())
    6394  {
    6395  o << (pretty_print ? ",\n" : ",");
    6396  }
    6397  o << string_t(new_indent, ' ') << "\""
    6398  << escape_string(i->first) << "\":"
    6399  << (pretty_print ? " " : "");
    6400  i->second.dump(o, pretty_print, indent_step, new_indent);
    6401  }
    6402 
    6403  // decrease indentation
    6404  if (pretty_print)
    6405  {
    6406  new_indent -= indent_step;
    6407  o << "\n";
    6408  }
    6409 
    6410  o << string_t(new_indent, ' ') + "}";
    6411  return;
    6412  }
    6413 
    6414  case value_t::array:
    6415  {
    6416  if (m_value.array->empty())
    6417  {
    6418  o << "[]";
    6419  return;
    6420  }
    6421 
    6422  o << "[";
    6423 
    6424  // increase indentation
    6425  if (pretty_print)
    6426  {
    6427  new_indent += indent_step;
    6428  o << "\n";
    6429  }
    6430 
    6431  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    6432  {
    6433  if (i != m_value.array->cbegin())
    6434  {
    6435  o << (pretty_print ? ",\n" : ",");
    6436  }
    6437  o << string_t(new_indent, ' ');
    6438  i->dump(o, pretty_print, indent_step, new_indent);
    6439  }
    6440 
    6441  // decrease indentation
    6442  if (pretty_print)
    6443  {
    6444  new_indent -= indent_step;
    6445  o << "\n";
    6446  }
    6447 
    6448  o << string_t(new_indent, ' ') << "]";
    6449  return;
    6450  }
    6451 
    6452  case value_t::string:
    6453  {
    6454  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    6455  return;
    6456  }
    6457 
    6458  case value_t::boolean:
    6459  {
    6460  o << (m_value.boolean ? "true" : "false");
    6461  return;
    6462  }
    6463 
    6464  case value_t::number_integer:
    6465  {
    6466  o << m_value.number_integer;
    6467  return;
    6468  }
    6469 
    6470  case value_t::number_unsigned:
    6471  {
    6472  o << m_value.number_unsigned;
    6473  return;
    6474  }
    6475 
    6476  case value_t::number_float:
    6477  {
    6478  if (m_value.number_float == 0)
    6479  {
    6480  // special case for zero to get "0.0"/"-0.0"
    6481  o << (std::signbit(m_value.number_float) ? "-0.0" : "0.0");
    6482  }
    6483  else
    6484  {
    6485  o << m_value.number_float;
    6486  }
    6487  return;
    6488  }
    6489 
    6490  case value_t::discarded:
    6491  {
    6492  o << "<discarded>";
    6493  return;
    6494  }
    6495 
    6496  case value_t::null:
    6497  {
    6498  o << "null";
    6499  return;
    6500  }
    6501  }
    6502  }
    6503 
    6504  private:
    6506  // member variables //
    6508 
    6510  value_t m_type = value_t::null;
    6511 
    6513  json_value m_value = {};
    6514 
    6515 
    6516  private:
    6518  // iterators //
    6520 
    6530  class primitive_iterator_t
    6531  {
    6532  public:
    6534  void set_begin() noexcept
    6535  {
    6536  m_it = begin_value;
    6537  }
    6538 
    6540  void set_end() noexcept
    6541  {
    6542  m_it = end_value;
    6543  }
    6544 
    6546  constexpr bool is_begin() const noexcept
    6547  {
    6548  return (m_it == begin_value);
    6549  }
    6550 
    6552  constexpr bool is_end() const noexcept
    6553  {
    6554  return (m_it == end_value);
    6555  }
    6556 
    6558  operator difference_type& () noexcept
    6559  {
    6560  return m_it;
    6561  }
    6562 
    6564  constexpr operator difference_type () const noexcept
    6565  {
    6566  return m_it;
    6567  }
    6568 
    6569  private:
    6570  static constexpr difference_type begin_value = 0;
    6571  static constexpr difference_type end_value = begin_value + 1;
    6572 
    6574  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    6575  };
    6576 
    6584  struct internal_iterator
    6585  {
    6587  typename object_t::iterator object_iterator;
    6589  typename array_t::iterator array_iterator;
    6591  primitive_iterator_t primitive_iterator;
    6592 
    6594  internal_iterator() noexcept
    6595  : object_iterator(), array_iterator(), primitive_iterator()
    6596  {}
    6597  };
    6598 
    6600  template<typename IteratorType>
    6601  class iteration_proxy
    6602  {
    6603  private:
    6605  class iteration_proxy_internal
    6606  {
    6607  private:
    6609  IteratorType anchor;
    6611  size_t array_index = 0;
    6612 
    6613  public:
    6614  explicit iteration_proxy_internal(IteratorType it) noexcept
    6615  : anchor(it)
    6616  {}
    6617 
    6619  iteration_proxy_internal& operator*()
    6620  {
    6621  return *this;
    6622  }
    6623 
    6625  iteration_proxy_internal& operator++()
    6626  {
    6627  ++anchor;
    6628  ++array_index;
    6629 
    6630  return *this;
    6631  }
    6632 
    6634  bool operator!= (const iteration_proxy_internal& o) const
    6635  {
    6636  return anchor != o.anchor;
    6637  }
    6638 
    6640  typename basic_json::string_t key() const
    6641  {
    6642  assert(anchor.m_object != nullptr);
    6643 
    6644  switch (anchor.m_object->type())
    6645  {
    6646  // use integer array index as key
    6647  case value_t::array:
    6648  {
    6649  return std::to_string(array_index);
    6650  }
    6651 
    6652  // use key from the object
    6653  case value_t::object:
    6654  {
    6655  return anchor.key();
    6656  }
    6657 
    6658  // use an empty key for all primitive types
    6659  default:
    6660  {
    6661  return "";
    6662  }
    6663  }
    6664  }
    6665 
    6667  typename IteratorType::reference value() const
    6668  {
    6669  return anchor.value();
    6670  }
    6671  };
    6672 
    6674  typename IteratorType::reference container;
    6675 
    6676  public:
    6678  explicit iteration_proxy(typename IteratorType::reference cont)
    6679  : container(cont)
    6680  {}
    6681 
    6683  iteration_proxy_internal begin() noexcept
    6684  {
    6685  return iteration_proxy_internal(container.begin());
    6686  }
    6687 
    6689  iteration_proxy_internal end() noexcept
    6690  {
    6691  return iteration_proxy_internal(container.end());
    6692  }
    6693  };
    6694 
    6695  public:
    6715  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6716  {
    6718  friend class basic_json;
    6719 
    6720  public:
    6730  using iterator_category = std::bidirectional_iterator_tag;
    6731 
    6733  const_iterator() = default;
    6734 
    6741  explicit const_iterator(pointer object) noexcept
    6742  : m_object(object)
    6743  {
    6744  assert(m_object != nullptr);
    6745 
    6746  switch (m_object->m_type)
    6747  {
    6749  {
    6750  m_it.object_iterator = typename object_t::iterator();
    6751  break;
    6752  }
    6753 
    6755  {
    6756  m_it.array_iterator = typename array_t::iterator();
    6757  break;
    6758  }
    6759 
    6760  default:
    6761  {
    6762  m_it.primitive_iterator = primitive_iterator_t();
    6763  break;
    6764  }
    6765  }
    6766  }
    6767 
    6773  explicit const_iterator(const iterator& other) noexcept
    6774  : m_object(other.m_object)
    6775  {
    6776  if (m_object != nullptr)
    6777  {
    6778  switch (m_object->m_type)
    6779  {
    6781  {
    6782  m_it.object_iterator = other.m_it.object_iterator;
    6783  break;
    6784  }
    6785 
    6787  {
    6788  m_it.array_iterator = other.m_it.array_iterator;
    6789  break;
    6790  }
    6791 
    6792  default:
    6793  {
    6794  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6795  break;
    6796  }
    6797  }
    6798  }
    6799  }
    6800 
    6806  const_iterator(const const_iterator& other) noexcept
    6807  : m_object(other.m_object), m_it(other.m_it)
    6808  {}
    6809 
    6816  std::is_nothrow_move_constructible<pointer>::value and
    6817  std::is_nothrow_move_assignable<pointer>::value and
    6818  std::is_nothrow_move_constructible<internal_iterator>::value and
    6819  std::is_nothrow_move_assignable<internal_iterator>::value
    6820  )
    6821  {
    6822  std::swap(m_object, other.m_object);
    6823  std::swap(m_it, other.m_it);
    6824  return *this;
    6825  }
    6826 
    6827  private:
    6832  void set_begin() noexcept
    6833  {
    6834  assert(m_object != nullptr);
    6835 
    6836  switch (m_object->m_type)
    6837  {
    6839  {
    6840  m_it.object_iterator = m_object->m_value.object->begin();
    6841  break;
    6842  }
    6843 
    6845  {
    6846  m_it.array_iterator = m_object->m_value.array->begin();
    6847  break;
    6848  }
    6849 
    6851  {
    6852  // set to end so begin()==end() is true: null is empty
    6853  m_it.primitive_iterator.set_end();
    6854  break;
    6855  }
    6856 
    6857  default:
    6858  {
    6859  m_it.primitive_iterator.set_begin();
    6860  break;
    6861  }
    6862  }
    6863  }
    6864 
    6869  void set_end() noexcept
    6870  {
    6871  assert(m_object != nullptr);
    6872 
    6873  switch (m_object->m_type)
    6874  {
    6876  {
    6877  m_it.object_iterator = m_object->m_value.object->end();
    6878  break;
    6879  }
    6880 
    6882  {
    6883  m_it.array_iterator = m_object->m_value.array->end();
    6884  break;
    6885  }
    6886 
    6887  default:
    6888  {
    6889  m_it.primitive_iterator.set_end();
    6890  break;
    6891  }
    6892  }
    6893  }
    6894 
    6895  public:
    6901  {
    6902  assert(m_object != nullptr);
    6903 
    6904  switch (m_object->m_type)
    6905  {
    6907  {
    6908  assert(m_it.object_iterator != m_object->m_value.object->end());
    6909  return m_it.object_iterator->second;
    6910  }
    6911 
    6913  {
    6914  assert(m_it.array_iterator != m_object->m_value.array->end());
    6915  return *m_it.array_iterator;
    6916  }
    6917 
    6919  {
    6920  throw std::out_of_range("cannot get value");
    6921  }
    6922 
    6923  default:
    6924  {
    6925  if (m_it.primitive_iterator.is_begin())
    6926  {
    6927  return *m_object;
    6928  }
    6929  else
    6930  {
    6931  throw std::out_of_range("cannot get value");
    6932  }
    6933  }
    6934  }
    6935  }
    6936 
    6942  {
    6943  assert(m_object != nullptr);
    6944 
    6945  switch (m_object->m_type)
    6946  {
    6948  {
    6949  assert(m_it.object_iterator != m_object->m_value.object->end());
    6950  return &(m_it.object_iterator->second);
    6951  }
    6952 
    6954  {
    6955  assert(m_it.array_iterator != m_object->m_value.array->end());
    6956  return &*m_it.array_iterator;
    6957  }
    6958 
    6959  default:
    6960  {
    6961  if (m_it.primitive_iterator.is_begin())
    6962  {
    6963  return m_object;
    6964  }
    6965  else
    6966  {
    6967  throw std::out_of_range("cannot get value");
    6968  }
    6969  }
    6970  }
    6971  }
    6972 
    6978  {
    6979  auto result = *this;
    6980  ++(*this);
    6981  return result;
    6982  }
    6983 
    6989  {
    6990  assert(m_object != nullptr);
    6991 
    6992  switch (m_object->m_type)
    6993  {
    6995  {
    6996  std::advance(m_it.object_iterator, 1);
    6997  break;
    6998  }
    6999 
    7001  {
    7002  std::advance(m_it.array_iterator, 1);
    7003  break;
    7004  }
    7005 
    7006  default:
    7007  {
    7008  ++m_it.primitive_iterator;
    7009  break;
    7010  }
    7011  }
    7012 
    7013  return *this;
    7014  }
    7015 
    7021  {
    7022  auto result = *this;
    7023  --(*this);
    7024  return result;
    7025  }
    7026 
    7032  {
    7033  assert(m_object != nullptr);
    7034 
    7035  switch (m_object->m_type)
    7036  {
    7038  {
    7039  std::advance(m_it.object_iterator, -1);
    7040  break;
    7041  }
    7042 
    7044  {
    7045  std::advance(m_it.array_iterator, -1);
    7046  break;
    7047  }
    7048 
    7049  default:
    7050  {
    7051  --m_it.primitive_iterator;
    7052  break;
    7053  }
    7054  }
    7055 
    7056  return *this;
    7057  }
    7058 
    7063  bool operator==(const const_iterator& other) const
    7064  {
    7065  // if objects are not the same, the comparison is undefined
    7066  if (m_object != other.m_object)
    7067  {
    7068  throw std::domain_error("cannot compare iterators of different containers");
    7069  }
    7070 
    7071  assert(m_object != nullptr);
    7072 
    7073  switch (m_object->m_type)
    7074  {
    7076  {
    7077  return (m_it.object_iterator == other.m_it.object_iterator);
    7078  }
    7079 
    7081  {
    7082  return (m_it.array_iterator == other.m_it.array_iterator);
    7083  }
    7084 
    7085  default:
    7086  {
    7087  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    7088  }
    7089  }
    7090  }
    7091 
    7096  bool operator!=(const const_iterator& other) const
    7097  {
    7098  return not operator==(other);
    7099  }
    7100 
    7105  bool operator<(const const_iterator& other) const
    7106  {
    7107  // if objects are not the same, the comparison is undefined
    7108  if (m_object != other.m_object)
    7109  {
    7110  throw std::domain_error("cannot compare iterators of different containers");
    7111  }
    7112 
    7113  assert(m_object != nullptr);
    7114 
    7115  switch (m_object->m_type)
    7116  {
    7118  {
    7119  throw std::domain_error("cannot compare order of object iterators");
    7120  }
    7121 
    7123  {
    7124  return (m_it.array_iterator < other.m_it.array_iterator);
    7125  }
    7126 
    7127  default:
    7128  {
    7129  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    7130  }
    7131  }
    7132  }
    7133 
    7138  bool operator<=(const const_iterator& other) const
    7139  {
    7140  return not other.operator < (*this);
    7141  }
    7142 
    7147  bool operator>(const const_iterator& other) const
    7148  {
    7149  return not operator<=(other);
    7150  }
    7151 
    7156  bool operator>=(const const_iterator& other) const
    7157  {
    7158  return not operator<(other);
    7159  }
    7160 
    7166  {
    7167  assert(m_object != nullptr);
    7168 
    7169  switch (m_object->m_type)
    7170  {
    7172  {
    7173  throw std::domain_error("cannot use offsets with object iterators");
    7174  }
    7175 
    7177  {
    7178  std::advance(m_it.array_iterator, i);
    7179  break;
    7180  }
    7181 
    7182  default:
    7183  {
    7184  m_it.primitive_iterator += i;
    7185  break;
    7186  }
    7187  }
    7188 
    7189  return *this;
    7190  }
    7191 
    7197  {
    7198  return operator+=(-i);
    7199  }
    7200 
    7206  {
    7207  auto result = *this;
    7208  result += i;
    7209  return result;
    7210  }
    7211 
    7217  {
    7218  auto result = *this;
    7219  result -= i;
    7220  return result;
    7221  }
    7222 
    7228  {
    7229  assert(m_object != nullptr);
    7230 
    7231  switch (m_object->m_type)
    7232  {
    7234  {
    7235  throw std::domain_error("cannot use offsets with object iterators");
    7236  }
    7237 
    7239  {
    7240  return m_it.array_iterator - other.m_it.array_iterator;
    7241  }
    7242 
    7243  default:
    7244  {
    7245  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    7246  }
    7247  }
    7248  }
    7249 
    7255  {
    7256  assert(m_object != nullptr);
    7257 
    7258  switch (m_object->m_type)
    7259  {
    7261  {
    7262  throw std::domain_error("cannot use operator[] for object iterators");
    7263  }
    7264 
    7266  {
    7267  return *std::next(m_it.array_iterator, n);
    7268  }
    7269 
    7271  {
    7272  throw std::out_of_range("cannot get value");
    7273  }
    7274 
    7275  default:
    7276  {
    7277  if (m_it.primitive_iterator == -n)
    7278  {
    7279  return *m_object;
    7280  }
    7281  else
    7282  {
    7283  throw std::out_of_range("cannot get value");
    7284  }
    7285  }
    7286  }
    7287  }
    7288 
    7293  typename object_t::key_type key() const
    7294  {
    7295  assert(m_object != nullptr);
    7296 
    7297  if (m_object->is_object())
    7298  {
    7299  return m_it.object_iterator->first;
    7300  }
    7301  else
    7302  {
    7303  throw std::domain_error("cannot use key() for non-object iterators");
    7304  }
    7305  }
    7306 
    7312  {
    7313  return operator*();
    7314  }
    7315 
    7316  private:
    7318  pointer m_object = nullptr;
    7320  internal_iterator m_it = internal_iterator();
    7321  };
    7322 
    7335  class iterator : public const_iterator
    7336  {
    7337  public:
    7339  using pointer = typename basic_json::pointer;
    7341 
    7343  iterator() = default;
    7344 
    7346  explicit iterator(pointer object) noexcept
    7347  : base_iterator(object)
    7348  {}
    7349 
    7351  iterator(const iterator& other) noexcept
    7352  : base_iterator(other)
    7353  {}
    7354 
    7356  iterator& operator=(iterator other) noexcept(
    7357  std::is_nothrow_move_constructible<pointer>::value and
    7358  std::is_nothrow_move_assignable<pointer>::value and
    7359  std::is_nothrow_move_constructible<internal_iterator>::value and
    7360  std::is_nothrow_move_assignable<internal_iterator>::value
    7361  )
    7362  {
    7363  base_iterator::operator=(other);
    7364  return *this;
    7365  }
    7366 
    7369  {
    7370  return const_cast<reference>(base_iterator::operator*());
    7371  }
    7372 
    7375  {
    7376  return const_cast<pointer>(base_iterator::operator->());
    7377  }
    7378 
    7381  {
    7382  iterator result = *this;
    7383  base_iterator::operator++();
    7384  return result;
    7385  }
    7386 
    7389  {
    7390  base_iterator::operator++();
    7391  return *this;
    7392  }
    7393 
    7396  {
    7397  iterator result = *this;
    7398  base_iterator::operator--();
    7399  return result;
    7400  }
    7401 
    7404  {
    7405  base_iterator::operator--();
    7406  return *this;
    7407  }
    7408 
    7411  {
    7412  base_iterator::operator+=(i);
    7413  return *this;
    7414  }
    7415 
    7418  {
    7419  base_iterator::operator-=(i);
    7420  return *this;
    7421  }
    7422 
    7425  {
    7426  auto result = *this;
    7427  result += i;
    7428  return result;
    7429  }
    7430 
    7433  {
    7434  auto result = *this;
    7435  result -= i;
    7436  return result;
    7437  }
    7438 
    7440  difference_type operator-(const iterator& other) const
    7441  {
    7442  return base_iterator::operator-(other);
    7443  }
    7444 
    7447  {
    7448  return const_cast<reference>(base_iterator::operator[](n));
    7449  }
    7450 
    7453  {
    7454  return const_cast<reference>(base_iterator::value());
    7455  }
    7456  };
    7457 
    7475  template<typename Base>
    7476  class json_reverse_iterator : public std::reverse_iterator<Base>
    7477  {
    7478  public:
    7480  using base_iterator = std::reverse_iterator<Base>;
    7482  using reference = typename Base::reference;
    7483 
    7485  json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
    7486  : base_iterator(it)
    7487  {}
    7488 
    7491  : base_iterator(it)
    7492  {}
    7493 
    7496  {
    7497  return base_iterator::operator++(1);
    7498  }
    7499 
    7502  {
    7503  base_iterator::operator++();
    7504  return *this;
    7505  }
    7506 
    7509  {
    7510  return base_iterator::operator--(1);
    7511  }
    7512 
    7515  {
    7516  base_iterator::operator--();
    7517  return *this;
    7518  }
    7519 
    7522  {
    7523  base_iterator::operator+=(i);
    7524  return *this;
    7525  }
    7526 
    7529  {
    7530  auto result = *this;
    7531  result += i;
    7532  return result;
    7533  }
    7534 
    7537  {
    7538  auto result = *this;
    7539  result -= i;
    7540  return result;
    7541  }
    7542 
    7545  {
    7546  return this->base() - other.base();
    7547  }
    7548 
    7551  {
    7552  return *(this->operator+(n));
    7553  }
    7554 
    7556  typename object_t::key_type key() const
    7557  {
    7558  auto it = --this->base();
    7559  return it.key();
    7560  }
    7561 
    7564  {
    7565  auto it = --this->base();
    7566  return it.operator * ();
    7567  }
    7568  };
    7569 
    7570 
    7571  private:
    7573  // lexer and parser //
    7575 
    7583  class lexer
    7584  {
    7585  public:
    7587  enum class token_type
    7588  {
    7589  uninitialized,
    7590  literal_true,
    7591  literal_false,
    7592  literal_null,
    7593  value_string,
    7594  value_number,
    7595  begin_array,
    7596  begin_object,
    7597  end_array,
    7598  end_object,
    7599  name_separator,
    7600  value_separator,
    7601  parse_error,
    7602  end_of_input
    7603  };
    7604 
    7606  using lexer_char_t = unsigned char;
    7607 
    7609  lexer(const lexer_char_t* buff, const size_t len) noexcept
    7610  : m_content(buff)
    7611  {
    7612  assert(m_content != nullptr);
    7613  m_start = m_cursor = m_content;
    7614  m_limit = m_content + len;
    7615  }
    7616 
    7618  explicit lexer(std::istream& s)
    7619  : m_stream(&s), m_line_buffer()
    7620  {
    7621  // fill buffer
    7622  fill_line_buffer();
    7623 
    7624  // skip UTF-8 byte-order mark
    7625  if (m_line_buffer.size() >= 3 and m_line_buffer.substr(0, 3) == "\xEF\xBB\xBF")
    7626  {
    7627  m_line_buffer[0] = ' ';
    7628  m_line_buffer[1] = ' ';
    7629  m_line_buffer[2] = ' ';
    7630  }
    7631  }
    7632 
    7633  // switch off unwanted functions (due to pointer members)
    7634  lexer() = delete;
    7635  lexer(const lexer&) = delete;
    7636  lexer operator=(const lexer&) = delete;
    7637 
    7661  static string_t to_unicode(const std::size_t codepoint1,
    7662  const std::size_t codepoint2 = 0)
    7663  {
    7664  // calculate the code point from the given code points
    7665  std::size_t codepoint = codepoint1;
    7666 
    7667  // check if codepoint1 is a high surrogate
    7668  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    7669  {
    7670  // check if codepoint2 is a low surrogate
    7671  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    7672  {
    7673  codepoint =
    7674  // high surrogate occupies the most significant 22 bits
    7675  (codepoint1 << 10)
    7676  // low surrogate occupies the least significant 15 bits
    7677  + codepoint2
    7678  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7679  // in the result so we have to subtract with:
    7680  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7681  - 0x35FDC00;
    7682  }
    7683  else
    7684  {
    7685  throw std::invalid_argument("missing or wrong low surrogate");
    7686  }
    7687  }
    7688 
    7689  string_t result;
    7690 
    7691  if (codepoint < 0x80)
    7692  {
    7693  // 1-byte characters: 0xxxxxxx (ASCII)
    7694  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7695  }
    7696  else if (codepoint <= 0x7ff)
    7697  {
    7698  // 2-byte characters: 110xxxxx 10xxxxxx
    7699  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7700  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7701  }
    7702  else if (codepoint <= 0xffff)
    7703  {
    7704  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7705  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7706  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7707  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7708  }
    7709  else if (codepoint <= 0x10ffff)
    7710  {
    7711  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7712  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7713  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7714  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7715  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7716  }
    7717  else
    7718  {
    7719  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7720  }
    7721 
    7722  return result;
    7723  }
    7724 
    7726  static std::string token_type_name(const token_type t)
    7727  {
    7728  switch (t)
    7729  {
    7730  case token_type::uninitialized:
    7731  return "<uninitialized>";
    7732  case token_type::literal_true:
    7733  return "true literal";
    7734  case token_type::literal_false:
    7735  return "false literal";
    7736  case token_type::literal_null:
    7737  return "null literal";
    7738  case token_type::value_string:
    7739  return "string literal";
    7740  case token_type::value_number:
    7741  return "number literal";
    7742  case token_type::begin_array:
    7743  return "'['";
    7744  case token_type::begin_object:
    7745  return "'{'";
    7746  case token_type::end_array:
    7747  return "']'";
    7748  case token_type::end_object:
    7749  return "'}'";
    7750  case token_type::name_separator:
    7751  return "':'";
    7752  case token_type::value_separator:
    7753  return "','";
    7754  case token_type::parse_error:
    7755  return "<parse error>";
    7756  case token_type::end_of_input:
    7757  return "end of input";
    7758  default:
    7759  {
    7760  // catch non-enum values
    7761  return "unknown token"; // LCOV_EXCL_LINE
    7762  }
    7763  }
    7764  }
    7765 
    7787  token_type scan()
    7788  {
    7789  while (true)
    7790  {
    7791  // pointer for backtracking information
    7792  m_marker = nullptr;
    7793 
    7794  // remember the begin of the token
    7795  m_start = m_cursor;
    7796  assert(m_start != nullptr);
    7797 
    7798 
    7799  {
    7800  lexer_char_t yych;
    7801  unsigned int yyaccept = 0;
    7802  static const unsigned char yybm[] =
    7803  {
    7804  0, 0, 0, 0, 0, 0, 0, 0,
    7805  0, 32, 32, 0, 0, 32, 0, 0,
    7806  0, 0, 0, 0, 0, 0, 0, 0,
    7807  0, 0, 0, 0, 0, 0, 0, 0,
    7808  160, 128, 0, 128, 128, 128, 128, 128,
    7809  128, 128, 128, 128, 128, 128, 128, 128,
    7810  192, 192, 192, 192, 192, 192, 192, 192,
    7811  192, 192, 128, 128, 128, 128, 128, 128,
    7812  128, 128, 128, 128, 128, 128, 128, 128,
    7813  128, 128, 128, 128, 128, 128, 128, 128,
    7814  128, 128, 128, 128, 128, 128, 128, 128,
    7815  128, 128, 128, 128, 0, 128, 128, 128,
    7816  128, 128, 128, 128, 128, 128, 128, 128,
    7817  128, 128, 128, 128, 128, 128, 128, 128,
    7818  128, 128, 128, 128, 128, 128, 128, 128,
    7819  128, 128, 128, 128, 128, 128, 128, 128,
    7820  0, 0, 0, 0, 0, 0, 0, 0,
    7821  0, 0, 0, 0, 0, 0, 0, 0,
    7822  0, 0, 0, 0, 0, 0, 0, 0,
    7823  0, 0, 0, 0, 0, 0, 0, 0,
    7824  0, 0, 0, 0, 0, 0, 0, 0,
    7825  0, 0, 0, 0, 0, 0, 0, 0,
    7826  0, 0, 0, 0, 0, 0, 0, 0,
    7827  0, 0, 0, 0, 0, 0, 0, 0,
    7828  0, 0, 0, 0, 0, 0, 0, 0,
    7829  0, 0, 0, 0, 0, 0, 0, 0,
    7830  0, 0, 0, 0, 0, 0, 0, 0,
    7831  0, 0, 0, 0, 0, 0, 0, 0,
    7832  0, 0, 0, 0, 0, 0, 0, 0,
    7833  0, 0, 0, 0, 0, 0, 0, 0,
    7834  0, 0, 0, 0, 0, 0, 0, 0,
    7835  0, 0, 0, 0, 0, 0, 0, 0,
    7836  };
    7837  if ((m_limit - m_cursor) < 5)
    7838  {
    7839  fill_line_buffer(5); // LCOV_EXCL_LINE
    7840  }
    7841  yych = *m_cursor;
    7842  if (yybm[0 + yych] & 32)
    7843  {
    7844  goto basic_json_parser_6;
    7845  }
    7846  if (yych <= '[')
    7847  {
    7848  if (yych <= '-')
    7849  {
    7850  if (yych <= '"')
    7851  {
    7852  if (yych <= 0x00)
    7853  {
    7854  goto basic_json_parser_2;
    7855  }
    7856  if (yych <= '!')
    7857  {
    7858  goto basic_json_parser_4;
    7859  }
    7860  goto basic_json_parser_9;
    7861  }
    7862  else
    7863  {
    7864  if (yych <= '+')
    7865  {
    7866  goto basic_json_parser_4;
    7867  }
    7868  if (yych <= ',')
    7869  {
    7870  goto basic_json_parser_10;
    7871  }
    7872  goto basic_json_parser_12;
    7873  }
    7874  }
    7875  else
    7876  {
    7877  if (yych <= '9')
    7878  {
    7879  if (yych <= '/')
    7880  {
    7881  goto basic_json_parser_4;
    7882  }
    7883  if (yych <= '0')
    7884  {
    7885  goto basic_json_parser_13;
    7886  }
    7887  goto basic_json_parser_15;
    7888  }
    7889  else
    7890  {
    7891  if (yych <= ':')
    7892  {
    7893  goto basic_json_parser_17;
    7894  }
    7895  if (yych <= 'Z')
    7896  {
    7897  goto basic_json_parser_4;
    7898  }
    7899  goto basic_json_parser_19;
    7900  }
    7901  }
    7902  }
    7903  else
    7904  {
    7905  if (yych <= 'n')
    7906  {
    7907  if (yych <= 'e')
    7908  {
    7909  if (yych == ']')
    7910  {
    7911  goto basic_json_parser_21;
    7912  }
    7913  goto basic_json_parser_4;
    7914  }
    7915  else
    7916  {
    7917  if (yych <= 'f')
    7918  {
    7919  goto basic_json_parser_23;
    7920  }
    7921  if (yych <= 'm')
    7922  {
    7923  goto basic_json_parser_4;
    7924  }
    7925  goto basic_json_parser_24;
    7926  }
    7927  }
    7928  else
    7929  {
    7930  if (yych <= 'z')
    7931  {
    7932  if (yych == 't')
    7933  {
    7934  goto basic_json_parser_25;
    7935  }
    7936  goto basic_json_parser_4;
    7937  }
    7938  else
    7939  {
    7940  if (yych <= '{')
    7941  {
    7942  goto basic_json_parser_26;
    7943  }
    7944  if (yych == '}')
    7945  {
    7946  goto basic_json_parser_28;
    7947  }
    7948  goto basic_json_parser_4;
    7949  }
    7950  }
    7951  }
    7952 basic_json_parser_2:
    7953  ++m_cursor;
    7954  {
    7955  last_token_type = token_type::end_of_input;
    7956  break;
    7957  }
    7958 basic_json_parser_4:
    7959  ++m_cursor;
    7960 basic_json_parser_5:
    7961  {
    7962  last_token_type = token_type::parse_error;
    7963  break;
    7964  }
    7965 basic_json_parser_6:
    7966  ++m_cursor;
    7967  if (m_limit <= m_cursor)
    7968  {
    7969  fill_line_buffer(1); // LCOV_EXCL_LINE
    7970  }
    7971  yych = *m_cursor;
    7972  if (yybm[0 + yych] & 32)
    7973  {
    7974  goto basic_json_parser_6;
    7975  }
    7976  {
    7977  continue;
    7978  }
    7979 basic_json_parser_9:
    7980  yyaccept = 0;
    7981  yych = *(m_marker = ++m_cursor);
    7982  if (yych <= 0x1F)
    7983  {
    7984  goto basic_json_parser_5;
    7985  }
    7986  if (yych <= 0x7F)
    7987  {
    7988  goto basic_json_parser_31;
    7989  }
    7990  if (yych <= 0xC1)
    7991  {
    7992  goto basic_json_parser_5;
    7993  }
    7994  if (yych <= 0xF4)
    7995  {
    7996  goto basic_json_parser_31;
    7997  }
    7998  goto basic_json_parser_5;
    7999 basic_json_parser_10:
    8000  ++m_cursor;
    8001  {
    8002  last_token_type = token_type::value_separator;
    8003  break;
    8004  }
    8005 basic_json_parser_12:
    8006  yych = *++m_cursor;
    8007  if (yych <= '/')
    8008  {
    8009  goto basic_json_parser_5;
    8010  }
    8011  if (yych <= '0')
    8012  {
    8013  goto basic_json_parser_13;
    8014  }
    8015  if (yych <= '9')
    8016  {
    8017  goto basic_json_parser_15;
    8018  }
    8019  goto basic_json_parser_5;
    8020 basic_json_parser_13:
    8021  yyaccept = 1;
    8022  yych = *(m_marker = ++m_cursor);
    8023  if (yych <= 'D')
    8024  {
    8025  if (yych == '.')
    8026  {
    8027  goto basic_json_parser_43;
    8028  }
    8029  }
    8030  else
    8031  {
    8032  if (yych <= 'E')
    8033  {
    8034  goto basic_json_parser_44;
    8035  }
    8036  if (yych == 'e')
    8037  {
    8038  goto basic_json_parser_44;
    8039  }
    8040  }
    8041 basic_json_parser_14:
    8042  {
    8043  last_token_type = token_type::value_number;
    8044  break;
    8045  }
    8046 basic_json_parser_15:
    8047  yyaccept = 1;
    8048  m_marker = ++m_cursor;
    8049  if ((m_limit - m_cursor) < 3)
    8050  {
    8051  fill_line_buffer(3); // LCOV_EXCL_LINE
    8052  }
    8053  yych = *m_cursor;
    8054  if (yybm[0 + yych] & 64)
    8055  {
    8056  goto basic_json_parser_15;
    8057  }
    8058  if (yych <= 'D')
    8059  {
    8060  if (yych == '.')
    8061  {
    8062  goto basic_json_parser_43;
    8063  }
    8064  goto basic_json_parser_14;
    8065  }
    8066  else
    8067  {
    8068  if (yych <= 'E')
    8069  {
    8070  goto basic_json_parser_44;
    8071  }
    8072  if (yych == 'e')
    8073  {
    8074  goto basic_json_parser_44;
    8075  }
    8076  goto basic_json_parser_14;
    8077  }
    8078 basic_json_parser_17:
    8079  ++m_cursor;
    8080  {
    8081  last_token_type = token_type::name_separator;
    8082  break;
    8083  }
    8084 basic_json_parser_19:
    8085  ++m_cursor;
    8086  {
    8087  last_token_type = token_type::begin_array;
    8088  break;
    8089  }
    8090 basic_json_parser_21:
    8091  ++m_cursor;
    8092  {
    8093  last_token_type = token_type::end_array;
    8094  break;
    8095  }
    8096 basic_json_parser_23:
    8097  yyaccept = 0;
    8098  yych = *(m_marker = ++m_cursor);
    8099  if (yych == 'a')
    8100  {
    8101  goto basic_json_parser_45;
    8102  }
    8103  goto basic_json_parser_5;
    8104 basic_json_parser_24:
    8105  yyaccept = 0;
    8106  yych = *(m_marker = ++m_cursor);
    8107  if (yych == 'u')
    8108  {
    8109  goto basic_json_parser_46;
    8110  }
    8111  goto basic_json_parser_5;
    8112 basic_json_parser_25:
    8113  yyaccept = 0;
    8114  yych = *(m_marker = ++m_cursor);
    8115  if (yych == 'r')
    8116  {
    8117  goto basic_json_parser_47;
    8118  }
    8119  goto basic_json_parser_5;
    8120 basic_json_parser_26:
    8121  ++m_cursor;
    8122  {
    8123  last_token_type = token_type::begin_object;
    8124  break;
    8125  }
    8126 basic_json_parser_28:
    8127  ++m_cursor;
    8128  {
    8129  last_token_type = token_type::end_object;
    8130  break;
    8131  }
    8132 basic_json_parser_30:
    8133  ++m_cursor;
    8134  if (m_limit <= m_cursor)
    8135  {
    8136  fill_line_buffer(1); // LCOV_EXCL_LINE
    8137  }
    8138  yych = *m_cursor;
    8139 basic_json_parser_31:
    8140  if (yybm[0 + yych] & 128)
    8141  {
    8142  goto basic_json_parser_30;
    8143  }
    8144  if (yych <= 0xE0)
    8145  {
    8146  if (yych <= '\\')
    8147  {
    8148  if (yych <= 0x1F)
    8149  {
    8150  goto basic_json_parser_32;
    8151  }
    8152  if (yych <= '"')
    8153  {
    8154  goto basic_json_parser_33;
    8155  }
    8156  goto basic_json_parser_35;
    8157  }
    8158  else
    8159  {
    8160  if (yych <= 0xC1)
    8161  {
    8162  goto basic_json_parser_32;
    8163  }
    8164  if (yych <= 0xDF)
    8165  {
    8166  goto basic_json_parser_36;
    8167  }
    8168  goto basic_json_parser_37;
    8169  }
    8170  }
    8171  else
    8172  {
    8173  if (yych <= 0xEF)
    8174  {
    8175  if (yych == 0xED)
    8176  {
    8177  goto basic_json_parser_39;
    8178  }
    8179  goto basic_json_parser_38;
    8180  }
    8181  else
    8182  {
    8183  if (yych <= 0xF0)
    8184  {
    8185  goto basic_json_parser_40;
    8186  }
    8187  if (yych <= 0xF3)
    8188  {
    8189  goto basic_json_parser_41;
    8190  }
    8191  if (yych <= 0xF4)
    8192  {
    8193  goto basic_json_parser_42;
    8194  }
    8195  }
    8196  }
    8197 basic_json_parser_32:
    8198  m_cursor = m_marker;
    8199  if (yyaccept == 0)
    8200  {
    8201  goto basic_json_parser_5;
    8202  }
    8203  else
    8204  {
    8205  goto basic_json_parser_14;
    8206  }
    8207 basic_json_parser_33:
    8208  ++m_cursor;
    8209  {
    8210  last_token_type = token_type::value_string;
    8211  break;
    8212  }
    8213 basic_json_parser_35:
    8214  ++m_cursor;
    8215  if (m_limit <= m_cursor)
    8216  {
    8217  fill_line_buffer(1); // LCOV_EXCL_LINE
    8218  }
    8219  yych = *m_cursor;
    8220  if (yych <= 'e')
    8221  {
    8222  if (yych <= '/')
    8223  {
    8224  if (yych == '"')
    8225  {
    8226  goto basic_json_parser_30;
    8227  }
    8228  if (yych <= '.')
    8229  {
    8230  goto basic_json_parser_32;
    8231  }
    8232  goto basic_json_parser_30;
    8233  }
    8234  else
    8235  {
    8236  if (yych <= '\\')
    8237  {
    8238  if (yych <= '[')
    8239  {
    8240  goto basic_json_parser_32;
    8241  }
    8242  goto basic_json_parser_30;
    8243  }
    8244  else
    8245  {
    8246  if (yych == 'b')
    8247  {
    8248  goto basic_json_parser_30;
    8249  }
    8250  goto basic_json_parser_32;
    8251  }
    8252  }
    8253  }
    8254  else
    8255  {
    8256  if (yych <= 'q')
    8257  {
    8258  if (yych <= 'f')
    8259  {
    8260  goto basic_json_parser_30;
    8261  }
    8262  if (yych == 'n')
    8263  {
    8264  goto basic_json_parser_30;
    8265  }
    8266  goto basic_json_parser_32;
    8267  }
    8268  else
    8269  {
    8270  if (yych <= 's')
    8271  {
    8272  if (yych <= 'r')
    8273  {
    8274  goto basic_json_parser_30;
    8275  }
    8276  goto basic_json_parser_32;
    8277  }
    8278  else
    8279  {
    8280  if (yych <= 't')
    8281  {
    8282  goto basic_json_parser_30;
    8283  }
    8284  if (yych <= 'u')
    8285  {
    8286  goto basic_json_parser_48;
    8287  }
    8288  goto basic_json_parser_32;
    8289  }
    8290  }
    8291  }
    8292 basic_json_parser_36:
    8293  ++m_cursor;
    8294  if (m_limit <= m_cursor)
    8295  {
    8296  fill_line_buffer(1); // LCOV_EXCL_LINE
    8297  }
    8298  yych = *m_cursor;
    8299  if (yych <= 0x7F)
    8300  {
    8301  goto basic_json_parser_32;
    8302  }
    8303  if (yych <= 0xBF)
    8304  {
    8305  goto basic_json_parser_30;
    8306  }
    8307  goto basic_json_parser_32;
    8308 basic_json_parser_37:
    8309  ++m_cursor;
    8310  if (m_limit <= m_cursor)
    8311  {
    8312  fill_line_buffer(1); // LCOV_EXCL_LINE
    8313  }
    8314  yych = *m_cursor;
    8315  if (yych <= 0x9F)
    8316  {
    8317  goto basic_json_parser_32;
    8318  }
    8319  if (yych <= 0xBF)
    8320  {
    8321  goto basic_json_parser_36;
    8322  }
    8323  goto basic_json_parser_32;
    8324 basic_json_parser_38:
    8325  ++m_cursor;
    8326  if (m_limit <= m_cursor)
    8327  {
    8328  fill_line_buffer(1); // LCOV_EXCL_LINE
    8329  }
    8330  yych = *m_cursor;
    8331  if (yych <= 0x7F)
    8332  {
    8333  goto basic_json_parser_32;
    8334  }
    8335  if (yych <= 0xBF)
    8336  {
    8337  goto basic_json_parser_36;
    8338  }
    8339  goto basic_json_parser_32;
    8340 basic_json_parser_39:
    8341  ++m_cursor;
    8342  if (m_limit <= m_cursor)
    8343  {
    8344  fill_line_buffer(1); // LCOV_EXCL_LINE
    8345  }
    8346  yych = *m_cursor;
    8347  if (yych <= 0x7F)
    8348  {
    8349  goto basic_json_parser_32;
    8350  }
    8351  if (yych <= 0x9F)
    8352  {
    8353  goto basic_json_parser_36;
    8354  }
    8355  goto basic_json_parser_32;
    8356 basic_json_parser_40:
    8357  ++m_cursor;
    8358  if (m_limit <= m_cursor)
    8359  {
    8360  fill_line_buffer(1); // LCOV_EXCL_LINE
    8361  }
    8362  yych = *m_cursor;
    8363  if (yych <= 0x8F)
    8364  {
    8365  goto basic_json_parser_32;
    8366  }
    8367  if (yych <= 0xBF)
    8368  {
    8369  goto basic_json_parser_38;
    8370  }
    8371  goto basic_json_parser_32;
    8372 basic_json_parser_41:
    8373  ++m_cursor;
    8374  if (m_limit <= m_cursor)
    8375  {
    8376  fill_line_buffer(1); // LCOV_EXCL_LINE
    8377  }
    8378  yych = *m_cursor;
    8379  if (yych <= 0x7F)
    8380  {
    8381  goto basic_json_parser_32;
    8382  }
    8383  if (yych <= 0xBF)
    8384  {
    8385  goto basic_json_parser_38;
    8386  }
    8387  goto basic_json_parser_32;
    8388 basic_json_parser_42:
    8389  ++m_cursor;
    8390  if (m_limit <= m_cursor)
    8391  {
    8392  fill_line_buffer(1); // LCOV_EXCL_LINE
    8393  }
    8394  yych = *m_cursor;
    8395  if (yych <= 0x7F)
    8396  {
    8397  goto basic_json_parser_32;
    8398  }
    8399  if (yych <= 0x8F)
    8400  {
    8401  goto basic_json_parser_38;
    8402  }
    8403  goto basic_json_parser_32;
    8404 basic_json_parser_43:
    8405  yych = *++m_cursor;
    8406  if (yych <= '/')
    8407  {
    8408  goto basic_json_parser_32;
    8409  }
    8410  if (yych <= '9')
    8411  {
    8412  goto basic_json_parser_49;
    8413  }
    8414  goto basic_json_parser_32;
    8415 basic_json_parser_44:
    8416  yych = *++m_cursor;
    8417  if (yych <= ',')
    8418  {
    8419  if (yych == '+')
    8420  {
    8421  goto basic_json_parser_51;
    8422  }
    8423  goto basic_json_parser_32;
    8424  }
    8425  else
    8426  {
    8427  if (yych <= '-')
    8428  {
    8429  goto basic_json_parser_51;
    8430  }
    8431  if (yych <= '/')
    8432  {
    8433  goto basic_json_parser_32;
    8434  }
    8435  if (yych <= '9')
    8436  {
    8437  goto basic_json_parser_52;
    8438  }
    8439  goto basic_json_parser_32;
    8440  }
    8441 basic_json_parser_45:
    8442  yych = *++m_cursor;
    8443  if (yych == 'l')
    8444  {
    8445  goto basic_json_parser_54;
    8446  }
    8447  goto basic_json_parser_32;
    8448 basic_json_parser_46:
    8449  yych = *++m_cursor;
    8450  if (yych == 'l')
    8451  {
    8452  goto basic_json_parser_55;
    8453  }
    8454  goto basic_json_parser_32;
    8455 basic_json_parser_47:
    8456  yych = *++m_cursor;
    8457  if (yych == 'u')
    8458  {
    8459  goto basic_json_parser_56;
    8460  }
    8461  goto basic_json_parser_32;
    8462 basic_json_parser_48:
    8463  ++m_cursor;
    8464  if (m_limit <= m_cursor)
    8465  {
    8466  fill_line_buffer(1); // LCOV_EXCL_LINE
    8467  }
    8468  yych = *m_cursor;
    8469  if (yych <= '@')
    8470  {
    8471  if (yych <= '/')
    8472  {
    8473  goto basic_json_parser_32;
    8474  }
    8475  if (yych <= '9')
    8476  {
    8477  goto basic_json_parser_57;
    8478  }
    8479  goto basic_json_parser_32;
    8480  }
    8481  else
    8482  {
    8483  if (yych <= 'F')
    8484  {
    8485  goto basic_json_parser_57;
    8486  }
    8487  if (yych <= '`')
    8488  {
    8489  goto basic_json_parser_32;
    8490  }
    8491  if (yych <= 'f')
    8492  {
    8493  goto basic_json_parser_57;
    8494  }
    8495  goto basic_json_parser_32;
    8496  }
    8497 basic_json_parser_49:
    8498  yyaccept = 1;
    8499  m_marker = ++m_cursor;
    8500  if ((m_limit - m_cursor) < 3)
    8501  {
    8502  fill_line_buffer(3); // LCOV_EXCL_LINE
    8503  }
    8504  yych = *m_cursor;
    8505  if (yych <= 'D')
    8506  {
    8507  if (yych <= '/')
    8508  {
    8509  goto basic_json_parser_14;
    8510  }
    8511  if (yych <= '9')
    8512  {
    8513  goto basic_json_parser_49;
    8514  }
    8515  goto basic_json_parser_14;
    8516  }
    8517  else
    8518  {
    8519  if (yych <= 'E')
    8520  {
    8521  goto basic_json_parser_44;
    8522  }
    8523  if (yych == 'e')
    8524  {
    8525  goto basic_json_parser_44;
    8526  }
    8527  goto basic_json_parser_14;
    8528  }
    8529 basic_json_parser_51:
    8530  yych = *++m_cursor;
    8531  if (yych <= '/')
    8532  {
    8533  goto basic_json_parser_32;
    8534  }
    8535  if (yych >= ':')
    8536  {
    8537  goto basic_json_parser_32;
    8538  }
    8539 basic_json_parser_52:
    8540  ++m_cursor;
    8541  if (m_limit <= m_cursor)
    8542  {
    8543  fill_line_buffer(1); // LCOV_EXCL_LINE
    8544  }
    8545  yych = *m_cursor;
    8546  if (yych <= '/')
    8547  {
    8548  goto basic_json_parser_14;
    8549  }
    8550  if (yych <= '9')
    8551  {
    8552  goto basic_json_parser_52;
    8553  }
    8554  goto basic_json_parser_14;
    8555 basic_json_parser_54:
    8556  yych = *++m_cursor;
    8557  if (yych == 's')
    8558  {
    8559  goto basic_json_parser_58;
    8560  }
    8561  goto basic_json_parser_32;
    8562 basic_json_parser_55:
    8563  yych = *++m_cursor;
    8564  if (yych == 'l')
    8565  {
    8566  goto basic_json_parser_59;
    8567  }
    8568  goto basic_json_parser_32;
    8569 basic_json_parser_56:
    8570  yych = *++m_cursor;
    8571  if (yych == 'e')
    8572  {
    8573  goto basic_json_parser_61;
    8574  }
    8575  goto basic_json_parser_32;
    8576 basic_json_parser_57:
    8577  ++m_cursor;
    8578  if (m_limit <= m_cursor)
    8579  {
    8580  fill_line_buffer(1); // LCOV_EXCL_LINE
    8581  }
    8582  yych = *m_cursor;
    8583  if (yych <= '@')
    8584  {
    8585  if (yych <= '/')
    8586  {
    8587  goto basic_json_parser_32;
    8588  }
    8589  if (yych <= '9')
    8590  {
    8591  goto basic_json_parser_63;
    8592  }
    8593  goto basic_json_parser_32;
    8594  }
    8595  else
    8596  {
    8597  if (yych <= 'F')
    8598  {
    8599  goto basic_json_parser_63;
    8600  }
    8601  if (yych <= '`')
    8602  {
    8603  goto basic_json_parser_32;
    8604  }
    8605  if (yych <= 'f')
    8606  {
    8607  goto basic_json_parser_63;
    8608  }
    8609  goto basic_json_parser_32;
    8610  }
    8611 basic_json_parser_58:
    8612  yych = *++m_cursor;
    8613  if (yych == 'e')
    8614  {
    8615  goto basic_json_parser_64;
    8616  }
    8617  goto basic_json_parser_32;
    8618 basic_json_parser_59:
    8619  ++m_cursor;
    8620  {
    8621  last_token_type = token_type::literal_null;
    8622  break;
    8623  }
    8624 basic_json_parser_61:
    8625  ++m_cursor;
    8626  {
    8627  last_token_type = token_type::literal_true;
    8628  break;
    8629  }
    8630 basic_json_parser_63:
    8631  ++m_cursor;
    8632  if (m_limit <= m_cursor)
    8633  {
    8634  fill_line_buffer(1); // LCOV_EXCL_LINE
    8635  }
    8636  yych = *m_cursor;
    8637  if (yych <= '@')
    8638  {
    8639  if (yych <= '/')
    8640  {
    8641  goto basic_json_parser_32;
    8642  }
    8643  if (yych <= '9')
    8644  {
    8645  goto basic_json_parser_66;
    8646  }
    8647  goto basic_json_parser_32;
    8648  }
    8649  else
    8650  {
    8651  if (yych <= 'F')
    8652  {
    8653  goto basic_json_parser_66;
    8654  }
    8655  if (yych <= '`')
    8656  {
    8657  goto basic_json_parser_32;
    8658  }
    8659  if (yych <= 'f')
    8660  {
    8661  goto basic_json_parser_66;
    8662  }
    8663  goto basic_json_parser_32;
    8664  }
    8665 basic_json_parser_64:
    8666  ++m_cursor;
    8667  {
    8668  last_token_type = token_type::literal_false;
    8669  break;
    8670  }
    8671 basic_json_parser_66:
    8672  ++m_cursor;
    8673  if (m_limit <= m_cursor)
    8674  {
    8675  fill_line_buffer(1); // LCOV_EXCL_LINE
    8676  }
    8677  yych = *m_cursor;
    8678  if (yych <= '@')
    8679  {
    8680  if (yych <= '/')
    8681  {
    8682  goto basic_json_parser_32;
    8683  }
    8684  if (yych <= '9')
    8685  {
    8686  goto basic_json_parser_30;
    8687  }
    8688  goto basic_json_parser_32;
    8689  }
    8690  else
    8691  {
    8692  if (yych <= 'F')
    8693  {
    8694  goto basic_json_parser_30;
    8695  }
    8696  if (yych <= '`')
    8697  {
    8698  goto basic_json_parser_32;
    8699  }
    8700  if (yych <= 'f')
    8701  {
    8702  goto basic_json_parser_30;
    8703  }
    8704  goto basic_json_parser_32;
    8705  }
    8706  }
    8707 
    8708  }
    8709 
    8710  return last_token_type;
    8711  }
    8712 
    8741  void fill_line_buffer(size_t n = 0)
    8742  {
    8743  // number of processed characters (p)
    8744  const auto offset_start = m_start - m_content;
    8745  // offset for m_marker wrt. to m_start
    8746  const auto offset_marker = (m_marker == nullptr) ? 0 : m_marker - m_start;
    8747  // number of unprocessed characters (u)
    8748  const auto offset_cursor = m_cursor - m_start;
    8749 
    8750  // no stream is used or end of file is reached
    8751  if (m_stream == nullptr or m_stream->eof())
    8752  {
    8753  // skip this part if we are already using the line buffer
    8754  if (m_start != reinterpret_cast<const lexer_char_t*>(m_line_buffer.data()))
    8755  {
    8756  // copy unprocessed characters to line buffer
    8757  m_line_buffer.clear();
    8758  for (m_cursor = m_start; m_cursor != m_limit; ++m_cursor)
    8759  {
    8760  m_line_buffer.append(1, static_cast<const char>(*m_cursor));
    8761  }
    8762  }
    8763 
    8764  // append n characters to make sure that there is sufficient
    8765  // space between m_cursor and m_limit
    8766  m_line_buffer.append(1, '\x00');
    8767  m_line_buffer.append(n - 1, '\x01');
    8768  }
    8769  else
    8770  {
    8771  // delete processed characters from line buffer
    8772  m_line_buffer.erase(0, static_cast<size_t>(offset_start));
    8773  // read next line from input stream
    8774  std::string line;
    8775  std::getline(*m_stream, line, '\n');
    8776  // add line with newline symbol to the line buffer
    8777  m_line_buffer += line + "\n";
    8778  }
    8779 
    8780  // set pointers
    8781  m_content = reinterpret_cast<const lexer_char_t*>(m_line_buffer.c_str());
    8782  assert(m_content != nullptr);
    8783  m_start = m_content;
    8784  m_marker = m_start + offset_marker;
    8785  m_cursor = m_start + offset_cursor;
    8786  m_limit = m_start + m_line_buffer.size();
    8787  }
    8788 
    8790  string_t get_token_string() const
    8791  {
    8792  assert(m_start != nullptr);
    8793  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    8794  static_cast<size_t>(m_cursor - m_start));
    8795  }
    8796 
    8854  string_t get_string() const
    8855  {
    8856  assert(m_cursor - m_start >= 2);
    8857 
    8858  string_t result;
    8859  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    8860 
    8861  // iterate the result between the quotes
    8862  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    8863  {
    8864  // process escaped characters
    8865  if (*i == '\\')
    8866  {
    8867  // read next character
    8868  ++i;
    8869 
    8870  switch (*i)
    8871  {
    8872  // the default escapes
    8873  case 't':
    8874  {
    8875  result += "\t";
    8876  break;
    8877  }
    8878  case 'b':
    8879  {
    8880  result += "\b";
    8881  break;
    8882  }
    8883  case 'f':
    8884  {
    8885  result += "\f";
    8886  break;
    8887  }
    8888  case 'n':
    8889  {
    8890  result += "\n";
    8891  break;
    8892  }
    8893  case 'r':
    8894  {
    8895  result += "\r";
    8896  break;
    8897  }
    8898  case '\\':
    8899  {
    8900  result += "\\";
    8901  break;
    8902  }
    8903  case '/':
    8904  {
    8905  result += "/";
    8906  break;
    8907  }
    8908  case '"':
    8909  {
    8910  result += "\"";
    8911  break;
    8912  }
    8913 
    8914  // unicode
    8915  case 'u':
    8916  {
    8917  // get code xxxx from uxxxx
    8918  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8919  4).c_str(), nullptr, 16);
    8920 
    8921  // check if codepoint is a high surrogate
    8922  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8923  {
    8924  // make sure there is a subsequent unicode
    8925  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8926  {
    8927  throw std::invalid_argument("missing low surrogate");
    8928  }
    8929 
    8930  // get code yyyy from uxxxx\uyyyy
    8931  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8932  (i + 7), 4).c_str(), nullptr, 16);
    8933  result += to_unicode(codepoint, codepoint2);
    8934  // skip the next 10 characters (xxxx\uyyyy)
    8935  i += 10;
    8936  }
    8937  else if (codepoint >= 0xDC00 and codepoint <= 0xDFFF)
    8938  {
    8939  // we found a lone low surrogate
    8940  throw std::invalid_argument("missing high surrogate");
    8941  }
    8942  else
    8943  {
    8944  // add unicode character(s)
    8945  result += to_unicode(codepoint);
    8946  // skip the next four characters (xxxx)
    8947  i += 4;
    8948  }
    8949  break;
    8950  }
    8951  }
    8952  }
    8953  else
    8954  {
    8955  // all other characters are just copied to the end of the
    8956  // string
    8957  result.append(1, static_cast<typename string_t::value_type>(*i));
    8958  }
    8959  }
    8960 
    8961  return result;
    8962  }
    8963 
    8979  long double str_to_float_t(long double* /* type */, char** endptr) const
    8980  {
    8981  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8982  }
    8983 
    8999  double str_to_float_t(double* /* type */, char** endptr) const
    9000  {
    9001  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    9002  }
    9003 
    9019  float str_to_float_t(float* /* type */, char** endptr) const
    9020  {
    9021  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    9022  }
    9023 
    9045  void get_number(basic_json& result) const
    9046  {
    9047  assert(m_start != nullptr);
    9048 
    9049  const lexer::lexer_char_t* curptr = m_start;
    9050 
    9051  // accumulate the integer conversion result (unsigned for now)
    9052  number_unsigned_t value = 0;
    9053 
    9054  // maximum absolute value of the relevant integer type
    9055  number_unsigned_t max;
    9056 
    9057  // temporarily store the type to avoid unecessary bitfield access
    9058  value_t type;
    9059 
    9060  // look for sign
    9061  if (*curptr == '-')
    9062  {
    9063  type = value_t::number_integer;
    9064  max = static_cast<uint64_t>((std::numeric_limits<number_integer_t>::max)()) + 1;
    9065  curptr++;
    9066  }
    9067  else
    9068  {
    9069  type = value_t::number_unsigned;
    9070  max = static_cast<uint64_t>((std::numeric_limits<number_unsigned_t>::max)());
    9071  }
    9072 
    9073  // count the significant figures
    9074  for (; curptr < m_cursor; curptr++)
    9075  {
    9076  // quickly skip tests if a digit
    9077  if (*curptr < '0' || *curptr > '9')
    9078  {
    9079  if (*curptr == '.')
    9080  {
    9081  // don't count '.' but change to float
    9082  type = value_t::number_float;
    9083  continue;
    9084  }
    9085  // assume exponent (if not then will fail parse): change to
    9086  // float, stop counting and record exponent details
    9087  type = value_t::number_float;
    9088  break;
    9089  }
    9090 
    9091  // skip if definitely not an integer
    9092  if (type != value_t::number_float)
    9093  {
    9094  // multiply last value by ten and add the new digit
    9095  auto temp = value * 10 + *curptr - '0';
    9096 
    9097  // test for overflow
    9098  if (temp < value || temp > max)
    9099  {
    9100  // overflow
    9101  type = value_t::number_float;
    9102  }
    9103  else
    9104  {
    9105  // no overflow - save it
    9106  value = temp;
    9107  }
    9108  }
    9109  }
    9110 
    9111  // save the value (if not a float)
    9112  if (type == value_t::number_unsigned)
    9113  {
    9114  result.m_value.number_unsigned = value;
    9115  }
    9116  else if (type == value_t::number_integer)
    9117  {
    9118  result.m_value.number_integer = -static_cast<number_integer_t>(value);
    9119  }
    9120  else
    9121  {
    9122  // parse with strtod
    9123  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
    9124 
    9125  // replace infinity and NAN by null
    9126  if (not std::isfinite(result.m_value.number_float))
    9127  {
    9128  type = value_t::null;
    9129  result.m_value = basic_json::json_value();
    9130  }
    9131  }
    9132 
    9133  // save the type
    9134  result.m_type = type;
    9135  }
    9136 
    9137  private:
    9139  std::istream* m_stream = nullptr;
    9141  string_t m_line_buffer {};
    9143  const lexer_char_t* m_content = nullptr;
    9145  const lexer_char_t* m_start = nullptr;
    9147  const lexer_char_t* m_marker = nullptr;
    9149  const lexer_char_t* m_cursor = nullptr;
    9151  const lexer_char_t* m_limit = nullptr;
    9153  token_type last_token_type = token_type::end_of_input;
    9154  };
    9155 
    9161  class parser
    9162  {
    9163  public:
    9165  parser(const char* buff, const parser_callback_t cb = nullptr)
    9166  : callback(cb),
    9167  m_lexer(reinterpret_cast<const typename lexer::lexer_char_t*>(buff), strlen(buff))
    9168  {}
    9169 
    9171  parser(std::istream& is, const parser_callback_t cb = nullptr)
    9172  : callback(cb), m_lexer(is)
    9173  {}
    9174 
    9176  template<class IteratorType, typename std::enable_if<
    9177  std::is_same<typename std::iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value
    9178  , int>::type
    9179  = 0>
    9180  parser(IteratorType first, IteratorType last, const parser_callback_t cb = nullptr)
    9181  : callback(cb),
    9182  m_lexer(reinterpret_cast<const typename lexer::lexer_char_t*>(&(*first)),
    9183  static_cast<size_t>(std::distance(first, last)))
    9184  {}
    9185 
    9187  basic_json parse()
    9188  {
    9189  // read first token
    9190  get_token();
    9191 
    9192  basic_json result = parse_internal(true);
    9193  result.assert_invariant();
    9194 
    9195  expect(lexer::token_type::end_of_input);
    9196 
    9197  // return parser result and replace it with null in case the
    9198  // top-level value was discarded by the callback function
    9199  return result.is_discarded() ? basic_json() : std::move(result);
    9200  }
    9201 
    9202  private:
    9204  basic_json parse_internal(bool keep)
    9205  {
    9206  auto result = basic_json(value_t::discarded);
    9207 
    9208  switch (last_token)
    9209  {
    9210  case lexer::token_type::begin_object:
    9211  {
    9212  if (keep and (not callback
    9213  or ((keep = callback(depth++, parse_event_t::object_start, result)) != 0)))
    9214  {
    9215  // explicitly set result to object to cope with {}
    9216  result.m_type = value_t::object;
    9217  result.m_value = value_t::object;
    9218  }
    9219 
    9220  // read next token
    9221  get_token();
    9222 
    9223  // closing } -> we are done
    9224  if (last_token == lexer::token_type::end_object)
    9225  {
    9226  get_token();
    9227  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    9228  {
    9229  result = basic_json(value_t::discarded);
    9230  }
    9231  return result;
    9232  }
    9233 
    9234  // no comma is expected here
    9235  unexpect(lexer::token_type::value_separator);
    9236 
    9237  // otherwise: parse key-value pairs
    9238  do
    9239  {
    9240  // ugly, but could be fixed with loop reorganization
    9241  if (last_token == lexer::token_type::value_separator)
    9242  {
    9243  get_token();
    9244  }
    9245 
    9246  // store key
    9247  expect(lexer::token_type::value_string);
    9248  const auto key = m_lexer.get_string();
    9249 
    9250  bool keep_tag = false;
    9251  if (keep)
    9252  {
    9253  if (callback)
    9254  {
    9255  basic_json k(key);
    9256  keep_tag = callback(depth, parse_event_t::key, k);
    9257  }
    9258  else
    9259  {
    9260  keep_tag = true;
    9261  }
    9262  }
    9263 
    9264  // parse separator (:)
    9265  get_token();
    9266  expect(lexer::token_type::name_separator);
    9267 
    9268  // parse and add value
    9269  get_token();
    9270  auto value = parse_internal(keep);
    9271  if (keep and keep_tag and not value.is_discarded())
    9272  {
    9273  result[key] = std::move(value);
    9274  }
    9275  }
    9276  while (last_token == lexer::token_type::value_separator);
    9277 
    9278  // closing }
    9279  expect(lexer::token_type::end_object);
    9280  get_token();
    9281  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    9282  {
    9283  result = basic_json(value_t::discarded);
    9284  }
    9285 
    9286  return result;
    9287  }
    9288 
    9289  case lexer::token_type::begin_array:
    9290  {
    9291  if (keep and (not callback
    9292  or ((keep = callback(depth++, parse_event_t::array_start, result)) != 0)))
    9293  {
    9294  // explicitly set result to object to cope with []
    9295  result.m_type = value_t::array;
    9296  result.m_value = value_t::array;
    9297  }
    9298 
    9299  // read next token
    9300  get_token();
    9301 
    9302  // closing ] -> we are done
    9303  if (last_token == lexer::token_type::end_array)
    9304  {
    9305  get_token();
    9306  if (callback and not callback(--depth, parse_event_t::array_end, result))
    9307  {
    9308  result = basic_json(value_t::discarded);
    9309  }
    9310  return result;
    9311  }
    9312 
    9313  // no comma is expected here
    9314  unexpect(lexer::token_type::value_separator);
    9315 
    9316  // otherwise: parse values
    9317  do
    9318  {
    9319  // ugly, but could be fixed with loop reorganization
    9320  if (last_token == lexer::token_type::value_separator)
    9321  {
    9322  get_token();
    9323  }
    9324 
    9325  // parse value
    9326  auto value = parse_internal(keep);
    9327  if (keep and not value.is_discarded())
    9328  {
    9329  result.push_back(std::move(value));
    9330  }
    9331  }
    9332  while (last_token == lexer::token_type::value_separator);
    9333 
    9334  // closing ]
    9335  expect(lexer::token_type::end_array);
    9336  get_token();
    9337  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    9338  {
    9339  result = basic_json(value_t::discarded);
    9340  }
    9341 
    9342  return result;
    9343  }
    9344 
    9345  case lexer::token_type::literal_null:
    9346  {
    9347  get_token();
    9348  result.m_type = value_t::null;
    9349  break;
    9350  }
    9351 
    9352  case lexer::token_type::value_string:
    9353  {
    9354  const auto s = m_lexer.get_string();
    9355  get_token();
    9356  result = basic_json(s);
    9357  break;
    9358  }
    9359 
    9360  case lexer::token_type::literal_true:
    9361  {
    9362  get_token();
    9363  result.m_type = value_t::boolean;
    9364  result.m_value = true;
    9365  break;
    9366  }
    9367 
    9368  case lexer::token_type::literal_false:
    9369  {
    9370  get_token();
    9371  result.m_type = value_t::boolean;
    9372  result.m_value = false;
    9373  break;
    9374  }
    9375 
    9376  case lexer::token_type::value_number:
    9377  {
    9378  m_lexer.get_number(result);
    9379  get_token();
    9380  break;
    9381  }
    9382 
    9383  default:
    9384  {
    9385  // the last token was unexpected
    9386  unexpect(last_token);
    9387  }
    9388  }
    9389 
    9390  if (keep and callback and not callback(depth, parse_event_t::value, result))
    9391  {
    9392  result = basic_json(value_t::discarded);
    9393  }
    9394  return result;
    9395  }
    9396 
    9398  typename lexer::token_type get_token()
    9399  {
    9400  last_token = m_lexer.scan();
    9401  return last_token;
    9402  }
    9403 
    9404  void expect(typename lexer::token_type t) const
    9405  {
    9406  if (t != last_token)
    9407  {
    9408  std::string error_msg = "parse error - unexpected ";
    9409  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() +
    9410  "'") :
    9411  lexer::token_type_name(last_token));
    9412  error_msg += "; expected " + lexer::token_type_name(t);
    9413  throw std::invalid_argument(error_msg);
    9414  }
    9415  }
    9416 
    9417  void unexpect(typename lexer::token_type t) const
    9418  {
    9419  if (t == last_token)
    9420  {
    9421  std::string error_msg = "parse error - unexpected ";
    9422  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token_string() +
    9423  "'") :
    9424  lexer::token_type_name(last_token));
    9425  throw std::invalid_argument(error_msg);
    9426  }
    9427  }
    9428 
    9429  private:
    9431  int depth = 0;
    9433  const parser_callback_t callback = nullptr;
    9435  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    9437  lexer m_lexer;
    9438  };
    9439 
    9440  public:
    9453  {
    9455  friend class basic_json;
    9456 
    9457  public:
    9480  explicit json_pointer(const std::string& s = "")
    9481  : reference_tokens(split(s))
    9482  {}
    9483 
    9499  std::string to_string() const noexcept
    9500  {
    9501  return std::accumulate(reference_tokens.begin(),
    9502  reference_tokens.end(), std::string{},
    9503  [](const std::string & a, const std::string & b)
    9504  {
    9505  return a + "/" + escape(b);
    9506  });
    9507  }
    9508 
    9510  operator std::string() const
    9511  {
    9512  return to_string();
    9513  }
    9515  private:
    9517  std::string pop_back()
    9518  {
    9519  if (is_root())
    9520  {
    9521  throw std::domain_error("JSON pointer has no parent");
    9522  }
    9523 
    9524  auto last = reference_tokens.back();
    9525  reference_tokens.pop_back();
    9526  return last;
    9527  }
    9528 
    9530  bool is_root() const
    9531  {
    9532  return reference_tokens.empty();
    9533  }
    9534 
    9535  json_pointer top() const
    9536  {
    9537  if (is_root())
    9538  {
    9539  throw std::domain_error("JSON pointer has no parent");
    9540  }
    9541 
    9542  json_pointer result = *this;
    9543  result.reference_tokens = {reference_tokens[0]};
    9544  return result;
    9545  }
    9546 
    9552  reference get_and_create(reference j) const
    9553  {
    9554  pointer result = &j;
    9555 
    9556  // in case no reference tokens exist, return a reference to the
    9557  // JSON value j which will be overwritten by a primitive value
    9558  for (const auto& reference_token : reference_tokens)
    9559  {
    9560  switch (result->m_type)
    9561  {
    9562  case value_t::null:
    9563  {
    9564  if (reference_token == "0")
    9565  {
    9566  // start a new array if reference token is 0
    9567  result = &result->operator[](0);
    9568  }
    9569  else
    9570  {
    9571  // start a new object otherwise
    9572  result = &result->operator[](reference_token);
    9573  }
    9574  break;
    9575  }
    9576 
    9577  case value_t::object:
    9578  {
    9579  // create an entry in the object
    9580  result = &result->operator[](reference_token);
    9581  break;
    9582  }
    9583 
    9584  case value_t::array:
    9585  {
    9586  // create an entry in the array
    9587  result = &result->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9588  break;
    9589  }
    9590 
    9591  /*
    9592  The following code is only reached if there exists a
    9593  reference token _and_ the current value is primitive. In
    9594  this case, we have an error situation, because primitive
    9595  values may only occur as single value; that is, with an
    9596  empty list of reference tokens.
    9597  */
    9598  default:
    9599  {
    9600  throw std::domain_error("invalid value to unflatten");
    9601  }
    9602  }
    9603  }
    9604 
    9605  return *result;
    9606  }
    9607 
    9627  reference get_unchecked(pointer ptr) const
    9628  {
    9629  for (const auto& reference_token : reference_tokens)
    9630  {
    9631  // convert null values to arrays or objects before continuing
    9632  if (ptr->m_type == value_t::null)
    9633  {
    9634  // check if reference token is a number
    9635  const bool nums = std::all_of(reference_token.begin(),
    9636  reference_token.end(),
    9637  [](const char x)
    9638  {
    9639  return std::isdigit(x);
    9640  });
    9641 
    9642  // change value to array for numbers or "-" or to object
    9643  // otherwise
    9644  if (nums or reference_token == "-")
    9645  {
    9646  *ptr = value_t::array;
    9647  }
    9648  else
    9649  {
    9650  *ptr = value_t::object;
    9651  }
    9652  }
    9653 
    9654  switch (ptr->m_type)
    9655  {
    9656  case value_t::object:
    9657  {
    9658  // use unchecked object access
    9659  ptr = &ptr->operator[](reference_token);
    9660  break;
    9661  }
    9662 
    9663  case value_t::array:
    9664  {
    9665  // error condition (cf. RFC 6901, Sect. 4)
    9666  if (reference_token.size() > 1 and reference_token[0] == '0')
    9667  {
    9668  throw std::domain_error("array index must not begin with '0'");
    9669  }
    9670 
    9671  if (reference_token == "-")
    9672  {
    9673  // explicityly treat "-" as index beyond the end
    9674  ptr = &ptr->operator[](ptr->m_value.array->size());
    9675  }
    9676  else
    9677  {
    9678  // convert array index to number; unchecked access
    9679  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9680  }
    9681  break;
    9682  }
    9683 
    9684  default:
    9685  {
    9686  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9687  }
    9688  }
    9689  }
    9690 
    9691  return *ptr;
    9692  }
    9693 
    9694  reference get_checked(pointer ptr) const
    9695  {
    9696  for (const auto& reference_token : reference_tokens)
    9697  {
    9698  switch (ptr->m_type)
    9699  {
    9700  case value_t::object:
    9701  {
    9702  // note: at performs range check
    9703  ptr = &ptr->at(reference_token);
    9704  break;
    9705  }
    9706 
    9707  case value_t::array:
    9708  {
    9709  if (reference_token == "-")
    9710  {
    9711  // "-" always fails the range check
    9712  throw std::out_of_range("array index '-' (" +
    9713  std::to_string(ptr->m_value.array->size()) +
    9714  ") is out of range");
    9715  }
    9716 
    9717  // error condition (cf. RFC 6901, Sect. 4)
    9718  if (reference_token.size() > 1 and reference_token[0] == '0')
    9719  {
    9720  throw std::domain_error("array index must not begin with '0'");
    9721  }
    9722 
    9723  // note: at performs range check
    9724  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9725  break;
    9726  }
    9727 
    9728  default:
    9729  {
    9730  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9731  }
    9732  }
    9733  }
    9734 
    9735  return *ptr;
    9736  }
    9737 
    9746  const_reference get_unchecked(const_pointer ptr) const
    9747  {
    9748  for (const auto& reference_token : reference_tokens)
    9749  {
    9750  switch (ptr->m_type)
    9751  {
    9752  case value_t::object:
    9753  {
    9754  // use unchecked object access
    9755  ptr = &ptr->operator[](reference_token);
    9756  break;
    9757  }
    9758 
    9759  case value_t::array:
    9760  {
    9761  if (reference_token == "-")
    9762  {
    9763  // "-" cannot be used for const access
    9764  throw std::out_of_range("array index '-' (" +
    9765  std::to_string(ptr->m_value.array->size()) +
    9766  ") is out of range");
    9767  }
    9768 
    9769  // error condition (cf. RFC 6901, Sect. 4)
    9770  if (reference_token.size() > 1 and reference_token[0] == '0')
    9771  {
    9772  throw std::domain_error("array index must not begin with '0'");
    9773  }
    9774 
    9775  // use unchecked array access
    9776  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9777  break;
    9778  }
    9779 
    9780  default:
    9781  {
    9782  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9783  }
    9784  }
    9785  }
    9786 
    9787  return *ptr;
    9788  }
    9789 
    9790  const_reference get_checked(const_pointer ptr) const
    9791  {
    9792  for (const auto& reference_token : reference_tokens)
    9793  {
    9794  switch (ptr->m_type)
    9795  {
    9796  case value_t::object:
    9797  {
    9798  // note: at performs range check
    9799  ptr = &ptr->at(reference_token);
    9800  break;
    9801  }
    9802 
    9803  case value_t::array:
    9804  {
    9805  if (reference_token == "-")
    9806  {
    9807  // "-" always fails the range check
    9808  throw std::out_of_range("array index '-' (" +
    9809  std::to_string(ptr->m_value.array->size()) +
    9810  ") is out of range");
    9811  }
    9812 
    9813  // error condition (cf. RFC 6901, Sect. 4)
    9814  if (reference_token.size() > 1 and reference_token[0] == '0')
    9815  {
    9816  throw std::domain_error("array index must not begin with '0'");
    9817  }
    9818 
    9819  // note: at performs range check
    9820  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9821  break;
    9822  }
    9823 
    9824  default:
    9825  {
    9826  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9827  }
    9828  }
    9829  }
    9830 
    9831  return *ptr;
    9832  }
    9833 
    9835  static std::vector<std::string> split(const std::string& reference_string)
    9836  {
    9837  std::vector<std::string> result;
    9838 
    9839  // special case: empty reference string -> no reference tokens
    9840  if (reference_string.empty())
    9841  {
    9842  return result;
    9843  }
    9844 
    9845  // check if nonempty reference string begins with slash
    9846  if (reference_string[0] != '/')
    9847  {
    9848  throw std::domain_error("JSON pointer must be empty or begin with '/'");
    9849  }
    9850 
    9851  // extract the reference tokens:
    9852  // - slash: position of the last read slash (or end of string)
    9853  // - start: position after the previous slash
    9854  for (
    9855  // search for the first slash after the first character
    9856  size_t slash = reference_string.find_first_of("/", 1),
    9857  // set the beginning of the first reference token
    9858  start = 1;
    9859  // we can stop if start == string::npos+1 = 0
    9860  start != 0;
    9861  // set the beginning of the next reference token
    9862  // (will eventually be 0 if slash == std::string::npos)
    9863  start = slash + 1,
    9864  // find next slash
    9865  slash = reference_string.find_first_of("/", start))
    9866  {
    9867  // use the text between the beginning of the reference token
    9868  // (start) and the last slash (slash).
    9869  auto reference_token = reference_string.substr(start, slash - start);
    9870 
    9871  // check reference tokens are properly escaped
    9872  for (size_t pos = reference_token.find_first_of("~");
    9873  pos != std::string::npos;
    9874  pos = reference_token.find_first_of("~", pos + 1))
    9875  {
    9876  assert(reference_token[pos] == '~');
    9877 
    9878  // ~ must be followed by 0 or 1
    9879  if (pos == reference_token.size() - 1 or
    9880  (reference_token[pos + 1] != '0' and
    9881  reference_token[pos + 1] != '1'))
    9882  {
    9883  throw std::domain_error("escape error: '~' must be followed with '0' or '1'");
    9884  }
    9885  }
    9886 
    9887  // finally, store the reference token
    9888  unescape(reference_token);
    9889  result.push_back(reference_token);
    9890  }
    9891 
    9892  return result;
    9893  }
    9894 
    9895  private:
    9910  static void replace_substring(std::string& s,
    9911  const std::string& f,
    9912  const std::string& t)
    9913  {
    9914  assert(not f.empty());
    9915 
    9916  for (
    9917  size_t pos = s.find(f); // find first occurrence of f
    9918  pos != std::string::npos; // make sure f was found
    9919  s.replace(pos, f.size(), t), // replace with t
    9920  pos = s.find(f, pos + t.size()) // find next occurrence of f
    9921  );
    9922  }
    9923 
    9925  static std::string escape(std::string s)
    9926  {
    9927  // escape "~"" to "~0" and "/" to "~1"
    9928  replace_substring(s, "~", "~0");
    9929  replace_substring(s, "/", "~1");
    9930  return s;
    9931  }
    9932 
    9934  static void unescape(std::string& s)
    9935  {
    9936  // first transform any occurrence of the sequence '~1' to '/'
    9937  replace_substring(s, "~1", "/");
    9938  // then transform any occurrence of the sequence '~0' to '~'
    9939  replace_substring(s, "~0", "~");
    9940  }
    9941 
    9949  static void flatten(const std::string& reference_string,
    9950  const basic_json& value,
    9951  basic_json& result)
    9952  {
    9953  switch (value.m_type)
    9954  {
    9955  case value_t::array:
    9956  {
    9957  if (value.m_value.array->empty())
    9958  {
    9959  // flatten empty array as null
    9960  result[reference_string] = nullptr;
    9961  }
    9962  else
    9963  {
    9964  // iterate array and use index as reference string
    9965  for (size_t i = 0; i < value.m_value.array->size(); ++i)
    9966  {
    9967  flatten(reference_string + "/" + std::to_string(i),
    9968  value.m_value.array->operator[](i), result);
    9969  }
    9970  }
    9971  break;
    9972  }
    9973 
    9974  case value_t::object:
    9975  {
    9976  if (value.m_value.object->empty())
    9977  {
    9978  // flatten empty object as null
    9979  result[reference_string] = nullptr;
    9980  }
    9981  else
    9982  {
    9983  // iterate object and use keys as reference string
    9984  for (const auto& element : *value.m_value.object)
    9985  {
    9986  flatten(reference_string + "/" + escape(element.first),
    9987  element.second, result);
    9988  }
    9989  }
    9990  break;
    9991  }
    9992 
    9993  default:
    9994  {
    9995  // add primitive value with its reference string
    9996  result[reference_string] = value;
    9997  break;
    9998  }
    9999  }
    10000  }
    10001 
    10007  static basic_json unflatten(const basic_json& value)
    10008  {
    10009  if (not value.is_object())
    10010  {
    10011  throw std::domain_error("only objects can be unflattened");
    10012  }
    10013 
    10014  basic_json result;
    10015 
    10016  // iterate the JSON object values
    10017  for (const auto& element : *value.m_value.object)
    10018  {
    10019  if (not element.second.is_primitive())
    10020  {
    10021  throw std::domain_error("values in object must be primitive");
    10022  }
    10023 
    10024  // assign value to reference pointed to by JSON pointer; Note
    10025  // that if the JSON pointer is "" (i.e., points to the whole
    10026  // value), function get_and_create returns a reference to
    10027  // result itself. An assignment will then create a primitive
    10028  // value.
    10029  json_pointer(element.first).get_and_create(result) = element.second;
    10030  }
    10031 
    10032  return result;
    10033  }
    10034 
    10035  private:
    10037  std::vector<std::string> reference_tokens {};
    10038  };
    10039 
    10041  // JSON Pointer support //
    10043 
    10046 
    10080  reference operator[](const json_pointer& ptr)
    10081  {
    10082  return ptr.get_unchecked(this);
    10083  }
    10107  const_reference operator[](const json_pointer& ptr) const
    10108  {
    10109  return ptr.get_unchecked(this);
    10110  }
    10132  reference at(const json_pointer& ptr)
    10133  {
    10134  return ptr.get_checked(this);
    10135  }
    10157  const_reference at(const json_pointer& ptr) const
    10158  {
    10159  return ptr.get_checked(this);
    10160  }
    10184  basic_json flatten() const
    10185  {
    10186  basic_json result(value_t::object);
    10187  json_pointer::flatten("", *this, result);
    10188  return result;
    10189  }
    10190 
    10218  basic_json unflatten() const
    10219  {
    10220  return json_pointer::unflatten(*this);
    10221  }
    10224 
    10226  // JSON Patch functions //
    10228 
    10231 
    10268  basic_json patch(const basic_json& json_patch) const
    10269  {
    10270  // make a working copy to apply the patch to
    10271  basic_json result = *this;
    10273  // the valid JSON Patch operations
    10274  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
    10275 
    10276  const auto get_op = [](const std::string op)
    10277  {
    10278  if (op == "add")
    10279  {
    10280  return patch_operations::add;
    10281  }
    10282  if (op == "remove")
    10283  {
    10284  return patch_operations::remove;
    10285  }
    10286  if (op == "replace")
    10287  {
    10288  return patch_operations::replace;
    10289  }
    10290  if (op == "move")
    10291  {
    10292  return patch_operations::move;
    10293  }
    10294  if (op == "copy")
    10295  {
    10296  return patch_operations::copy;
    10297  }
    10298  if (op == "test")
    10299  {
    10300  return patch_operations::test;
    10301  }
    10302 
    10303  return patch_operations::invalid;
    10304  };
    10305 
    10306  // wrapper for "add" operation; add value at ptr
    10307  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
    10308  {
    10309  // adding to the root of the target document means replacing it
    10310  if (ptr.is_root())
    10311  {
    10312  result = val;
    10313  }
    10314  else
    10315  {
    10316  // make sure the top element of the pointer exists
    10317  json_pointer top_pointer = ptr.top();
    10318  if (top_pointer != ptr)
    10319  {
    10320  result.at(top_pointer);
    10321  }
    10322 
    10323  // get reference to parent of JSON pointer ptr
    10324  const auto last_path = ptr.pop_back();
    10325  basic_json& parent = result[ptr];
    10326 
    10327  switch (parent.m_type)
    10328  {
    10329  case value_t::null:
    10330  case value_t::object:
    10331  {
    10332  // use operator[] to add value
    10333  parent[last_path] = val;
    10334  break;
    10335  }
    10336 
    10337  case value_t::array:
    10338  {
    10339  if (last_path == "-")
    10340  {
    10341  // special case: append to back
    10342  parent.push_back(val);
    10343  }
    10344  else
    10345  {
    10346  const auto idx = std::stoi(last_path);
    10347  if (static_cast<size_type>(idx) > parent.size())
    10348  {
    10349  // avoid undefined behavior
    10350  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    10351  }
    10352  else
    10353  {
    10354  // default case: insert add offset
    10355  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
    10356  }
    10357  }
    10358  break;
    10359  }
    10360 
    10361  default:
    10362  {
    10363  // if there exists a parent it cannot be primitive
    10364  assert(false); // LCOV_EXCL_LINE
    10365  }
    10366  }
    10367  }
    10368  };
    10369 
    10370  // wrapper for "remove" operation; remove value at ptr
    10371  const auto operation_remove = [&result](json_pointer & ptr)
    10372  {
    10373  // get reference to parent of JSON pointer ptr
    10374  const auto last_path = ptr.pop_back();
    10375  basic_json& parent = result.at(ptr);
    10376 
    10377  // remove child
    10378  if (parent.is_object())
    10379  {
    10380  // perform range check
    10381  auto it = parent.find(last_path);
    10382  if (it != parent.end())
    10383  {
    10384  parent.erase(it);
    10385  }
    10386  else
    10387  {
    10388  throw std::out_of_range("key '" + last_path + "' not found");
    10389  }
    10390  }
    10391  else if (parent.is_array())
    10392  {
    10393  // note erase performs range check
    10394  parent.erase(static_cast<size_type>(std::stoi(last_path)));
    10395  }
    10396  };
    10397 
    10398  // type check
    10399  if (not json_patch.is_array())
    10400  {
    10401  // a JSON patch must be an array of objects
    10402  throw std::invalid_argument("JSON patch must be an array of objects");
    10403  }
    10404 
    10405  // iterate and apply th eoperations
    10406  for (const auto& val : json_patch)
    10407  {
    10408  // wrapper to get a value for an operation
    10409  const auto get_value = [&val](const std::string & op,
    10410  const std::string & member,
    10411  bool string_type) -> basic_json&
    10412  {
    10413  // find value
    10414  auto it = val.m_value.object->find(member);
    10415 
    10416  // context-sensitive error message
    10417  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
    10418 
    10419  // check if desired value is present
    10420  if (it == val.m_value.object->end())
    10421  {
    10422  throw std::invalid_argument(error_msg + " must have member '" + member + "'");
    10423  }
    10424 
    10425  // check if result is of type string
    10426  if (string_type and not it->second.is_string())
    10427  {
    10428  throw std::invalid_argument(error_msg + " must have string member '" + member + "'");
    10429  }
    10430 
    10431  // no error: return value
    10432  return it->second;
    10433  };
    10434 
    10435  // type check
    10436  if (not val.is_object())
    10437  {
    10438  throw std::invalid_argument("JSON patch must be an array of objects");
    10439  }
    10440 
    10441  // collect mandatory members
    10442  const std::string op = get_value("op", "op", true);
    10443  const std::string path = get_value(op, "path", true);
    10444  json_pointer ptr(path);
    10445 
    10446  switch (get_op(op))
    10447  {
    10448  case patch_operations::add:
    10449  {
    10450  operation_add(ptr, get_value("add", "value", false));
    10451  break;
    10452  }
    10453 
    10454  case patch_operations::remove:
    10455  {
    10456  operation_remove(ptr);
    10457  break;
    10458  }
    10459 
    10460  case patch_operations::replace:
    10461  {
    10462  // the "path" location must exist - use at()
    10463  result.at(ptr) = get_value("replace", "value", false);
    10464  break;
    10465  }
    10466 
    10467  case patch_operations::move:
    10468  {
    10469  const std::string from_path = get_value("move", "from", true);
    10470  json_pointer from_ptr(from_path);
    10471 
    10472  // the "from" location must exist - use at()
    10473  basic_json v = result.at(from_ptr);
    10474 
    10475  // The move operation is functionally identical to a
    10476  // "remove" operation on the "from" location, followed
    10477  // immediately by an "add" operation at the target
    10478  // location with the value that was just removed.
    10479  operation_remove(from_ptr);
    10480  operation_add(ptr, v);
    10481  break;
    10482  }
    10483 
    10484  case patch_operations::copy:
    10485  {
    10486  const std::string from_path = get_value("copy", "from", true);;
    10487  const json_pointer from_ptr(from_path);
    10488 
    10489  // the "from" location must exist - use at()
    10490  result[ptr] = result.at(from_ptr);
    10491  break;
    10492  }
    10493 
    10494  case patch_operations::test:
    10495  {
    10496  bool success = false;
    10497  try
    10498  {
    10499  // check if "value" matches the one at "path"
    10500  // the "path" location must exist - use at()
    10501  success = (result.at(ptr) == get_value("test", "value", false));
    10502  }
    10503  catch (std::out_of_range&)
    10504  {
    10505  // ignore out of range errors: success remains false
    10506  }
    10507 
    10508  // throw an exception if test fails
    10509  if (not success)
    10510  {
    10511  throw std::domain_error("unsuccessful: " + val.dump());
    10512  }
    10513 
    10514  break;
    10515  }
    10516 
    10517  case patch_operations::invalid:
    10518  {
    10519  // op must be "add", "remove", "replace", "move", "copy", or
    10520  // "test"
    10521  throw std::invalid_argument("operation value '" + op + "' is invalid");
    10522  }
    10523  }
    10524  }
    10525 
    10526  return result;
    10527  }
    10528 
    10561  static basic_json diff(const basic_json& source,
    10562  const basic_json& target,
    10563  const std::string& path = "")
    10564  {
    10565  // the patch
    10566  basic_json result(value_t::array);
    10567 
    10568  // if the values are the same, return empty patch
    10569  if (source == target)
    10570  {
    10571  return result;
    10572  }
    10573 
    10574  if (source.type() != target.type())
    10575  {
    10576  // different types: replace value
    10577  result.push_back(
    10578  {
    10579  {"op", "replace"},
    10580  {"path", path},
    10581  {"value", target}
    10582  });
    10583  }
    10584  else
    10585  {
    10586  switch (source.type())
    10587  {
    10588  case value_t::array:
    10589  {
    10590  // first pass: traverse common elements
    10591  size_t i = 0;
    10592  while (i < source.size() and i < target.size())
    10593  {
    10594  // recursive call to compare array values at index i
    10595  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
    10596  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    10597  ++i;
    10598  }
    10599 
    10600  // i now reached the end of at least one array
    10601  // in a second pass, traverse the remaining elements
    10602 
    10603  // remove my remaining elements
    10604  const auto end_index = static_cast<difference_type>(result.size());
    10605  while (i < source.size())
    10606  {
    10607  // add operations in reverse order to avoid invalid
    10608  // indices
    10609  result.insert(result.begin() + end_index, object(
    10610  {
    10611  {"op", "remove"},
    10612  {"path", path + "/" + std::to_string(i)}
    10613  }));
    10614  ++i;
    10615  }
    10616 
    10617  // add other remaining elements
    10618  while (i < target.size())
    10619  {
    10620  result.push_back(
    10621  {
    10622  {"op", "add"},
    10623  {"path", path + "/" + std::to_string(i)},
    10624  {"value", target[i]}
    10625  });
    10626  ++i;
    10627  }
    10628 
    10629  break;
    10630  }
    10631 
    10632  case value_t::object:
    10633  {
    10634  // first pass: traverse this object's elements
    10635  for (auto it = source.begin(); it != source.end(); ++it)
    10636  {
    10637  // escape the key name to be used in a JSON patch
    10638  const auto key = json_pointer::escape(it.key());
    10639 
    10640  if (target.find(it.key()) != target.end())
    10641  {
    10642  // recursive call to compare object values at key it
    10643  auto temp_diff = diff(it.value(), target[it.key()], path + "/" + key);
    10644  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    10645  }
    10646  else
    10647  {
    10648  // found a key that is not in o -> remove it
    10649  result.push_back(object(
    10650  {
    10651  {"op", "remove"},
    10652  {"path", path + "/" + key}
    10653  }));
    10654  }
    10655  }
    10656 
    10657  // second pass: traverse other object's elements
    10658  for (auto it = target.begin(); it != target.end(); ++it)
    10659  {
    10660  if (source.find(it.key()) == source.end())
    10661  {
    10662  // found a key that is not in this -> add it
    10663  const auto key = json_pointer::escape(it.key());
    10664  result.push_back(
    10665  {
    10666  {"op", "add"},
    10667  {"path", path + "/" + key},
    10668  {"value", it.value()}
    10669  });
    10670  }
    10671  }
    10672 
    10673  break;
    10674  }
    10675 
    10676  default:
    10677  {
    10678  // both primitive type: replace value
    10679  result.push_back(
    10680  {
    10681  {"op", "replace"},
    10682  {"path", path},
    10683  {"value", target}
    10684  });
    10685  break;
    10686  }
    10687  }
    10688  }
    10689 
    10690  return result;
    10691  }
    10692 
    10694 };
    10695 
    10696 
    10698 // presets //
    10700 
    10709 using json = basic_json<>;
    10710 }
    10711 
    10712 
    10714 // nonmember support //
    10716 
    10717 // specialization of std::swap, and std::hash
    10718 namespace std
    10719 {
    10725 template<>
    10726 inline void swap(nlohmann::json& j1,
    10727  nlohmann::json& j2) noexcept(
    10728  is_nothrow_move_constructible<nlohmann::json>::value and
    10729  is_nothrow_move_assignable<nlohmann::json>::value
    10730  )
    10731 {
    10732  j1.swap(j2);
    10733 }
    10734 
    10736 template<>
    10737 struct hash<nlohmann::json>
    10738 {
    10744  std::size_t operator()(const nlohmann::json& j) const
    10745  {
    10746  // a naive hashing via the string representation
    10747  const auto& h = hash<nlohmann::json::string_t>();
    10748  return h(j.dump());
    10749  }
    10750 };
    10751 }
    10752 
    10766 inline nlohmann::json operator "" _json(const char* s, std::size_t n)
    10767 {
    10768  return nlohmann::json::parse(s, s + n);
    10769 }
    10770 
    10784 inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n)
    10785 {
    10786  return nlohmann::json::json_pointer(std::string(s, n));
    10787 }
    10788 
    10789 // restore GCC/clang diagnostic settings
    10790 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    10791  #pragma GCC diagnostic pop
    10792 #endif
    10793 
    10794 #endif
    const_iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6741
    size_type max_size() const noexcept
    returns the maximum possible number of elements
    Definition: json.hpp:4760
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:5737
    constexpr value_t type() const noexcept
    return the type of the JSON value (explicit)
    Definition: json.hpp:2243
    @@ -145,7 +145,7 @@ $(function() {
    void push_back(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4978
    bool empty() const noexcept
    checks whether the container is empty
    Definition: json.hpp:4626
    void push_back(std::initializer_list< basic_json > init)
    add an object to an object
    Definition: json.hpp:5033
    -
    json_pointer(const std::string &s="")
    create JSON pointer
    Definition: json.hpp:9312
    +
    json_pointer(const std::string &s="")
    create JSON pointer
    Definition: json.hpp:9480
    iterator insert(const_iterator pos, const_iterator first, const_iterator last)
    inserts elements
    Definition: json.hpp:5185
    constexpr const PointerType get_ptr() const noexcept
    get a pointer value (implicit)
    Definition: json.hpp:3009
    constexpr bool is_number_float() const noexcept
    return whether value is a floating-point number
    Definition: json.hpp:2459
    @@ -205,7 +205,7 @@ $(function() {
    reference value() const
    return the value of an iterator
    Definition: json.hpp:7311
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3699
    const_reference operator[](T *key) const
    read-only access specified object element
    Definition: json.hpp:3635
    - +
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:725
    value_t
    the JSON type enumeration
    Definition: json.hpp:756
    reverse_iterator rbegin() noexcept
    returns an iterator to the reverse-beginning
    Definition: json.hpp:4442
    @@ -291,7 +291,7 @@ $(function() {
    diff --git a/namespacemembers.html b/namespacemembers.html index 8c760ed89..f8cc2d523 100644 --- a/namespacemembers.html +++ b/namespacemembers.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -68,7 +68,7 @@ $(function() {
    diff --git a/namespacemembers_type.html b/namespacemembers_type.html index 6e0537f3e..a703dcf40 100644 --- a/namespacemembers_type.html +++ b/namespacemembers_type.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -68,7 +68,7 @@ $(function() { diff --git a/namespacenlohmann.html b/namespacenlohmann.html index f319d4add..19df70a66 100644 --- a/namespacenlohmann.html +++ b/namespacenlohmann.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -96,7 +96,7 @@ Typedefs diff --git a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html index ad2af9da6..90eae12ca 100644 --- a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html +++ b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -88,7 +88,7 @@ Classes diff --git a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html index 74a003a58..1c130d56e 100644 --- a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html +++ b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -88,7 +88,7 @@ $(function() {

    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 10545 of file json.hpp.

    +

    Definition at line 10713 of file json.hpp.

    @@ -98,7 +98,7 @@ $(function() { diff --git a/pages.html b/pages.html index 91ecabc20..e2a48a43e 100644 --- a/pages.html +++ b/pages.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -72,7 +72,7 @@ $(function() { 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 584478e63..be95b38db 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 @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -75,7 +75,7 @@ $(function() { 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 1a7113fbb..b785e1d42 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -88,11 +88,11 @@ Public Member Functions struct std::hash< nlohmann::json > -

    Definition at line 10573 of file json.hpp.

    +

    Definition at line 10741 of file json.hpp.

    diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_aec1567d1fa47dbe5b77954dce3a55b64.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_aec1567d1fa47dbe5b77954dce3a55b64.html index 3ded3ebe4..4cfeea0d6 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_aec1567d1fa47dbe5b77954dce3a55b64.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_aec1567d1fa47dbe5b77954dce3a55b64.html @@ -23,7 +23,7 @@
    JSON for Modern C++ -  2.0.6 +  2.0.7
    @@ -99,7 +99,7 @@ $(function() {
    Since
    version 1.0.0
    -

    Definition at line 10580 of file json.hpp.

    +

    Definition at line 10748 of file json.hpp.

    @@ -109,7 +109,7 @@ $(function() {