diff --git a/annotated.html b/annotated.html index 663013a42..69f7ad059 100644 --- a/annotated.html +++ b/annotated.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classes.html b/classes.html index 12751bddc..e4f786b5c 100644 --- a/classes.html +++ b/classes.html @@ -103,7 +103,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json-members.html b/classnlohmann_1_1basic__json-members.html index 12da71920..f46785f81 100644 --- a/classnlohmann_1_1basic__json-members.html +++ b/classnlohmann_1_1basic__json-members.html @@ -244,7 +244,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json.html b/classnlohmann_1_1basic__json.html index cbff708d8..de3cab988 100644 --- a/classnlohmann_1_1basic__json.html +++ b/classnlohmann_1_1basic__json.html @@ -695,7 +695,7 @@ class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, N diff --git a/classnlohmann_1_1basic__json_1_1const__iterator-members.html b/classnlohmann_1_1basic__json_1_1const__iterator-members.html index abfc2abb7..389503336 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator-members.html @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1const__iterator.html b/classnlohmann_1_1basic__json_1_1const__iterator.html index 5ea1b0942..b24aa9486 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator.html @@ -219,7 +219,7 @@ class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, N diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html index 3b88210b9..8bb3fcf09 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html index da011f659..5f7f6e3b8 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html index ea79131e0..e3c711287 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html index 947f4d513..a0ab33e74 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html index 2d2c714e9..7b42a39a1 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html index 1c3dee20e..14e5c54a7 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html index 8cedbb799..c4c763abd 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html b/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html index ba73a7aea..fbb8d8507 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6b682f09787eff62f03493d45aa05902.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6b682f09787eff62f03493d45aa05902.html index 18fc3946c..1f8a25c69 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6b682f09787eff62f03493d45aa05902.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6b682f09787eff62f03493d45aa05902.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html index c33873988..f81b5ec2f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a72761de693f95edc195956197f4e5569.html b/classnlohmann_1_1basic__json_1_1const__iterator_a72761de693f95edc195956197f4e5569.html index 4e3454eb5..e87c268c4 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a72761de693f95edc195956197f4e5569.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a72761de693f95edc195956197f4e5569.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html index bfc0bc733..5d5f5965f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html b/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html index 049b79caf..fa982401a 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html index bb67a9492..52b9694c0 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html index 004521ee6..b5c320704 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html index c7e1d4ef6..77f353dc5 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html index 6bfa369da..951de9b70 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html b/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html index 594a190bf..7b861034f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html index b28450868..6faeb9eae 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html index 9715b7569..e70c8c597 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html index 09c9f6b87..8f9dbb17b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html index cac8f7249..292a78275 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac6f4562e16e99b60820d100880b4c3c8.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac6f4562e16e99b60820d100880b4c3c8.html index c80a477c5..34b236861 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac6f4562e16e99b60820d100880b4c3c8.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac6f4562e16e99b60820d100880b4c3c8.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html index ebda8ac59..9ae01f9bf 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html @@ -150,7 +150,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html index 4981c1a91..25cfe88ae 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html b/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html index 1acdf45b7..2cdfa3008 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html index 68d3fb4ad..d8b37c1fd 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ada3100cdb8700566051828f1355fa745.html @@ -149,7 +149,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html index 1515b875f..2dc41f51b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html @@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html index f8857eaa1..fe2478a5b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html index 40bca1334..33825cdfb 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_af6941c3711dabb2e64960dd57e00d201.html b/classnlohmann_1_1basic__json_1_1const__iterator_af6941c3711dabb2e64960dd57e00d201.html index 3c0c5b7ab..0a45b10b9 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_af6941c3711dabb2e64960dd57e00d201.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_af6941c3711dabb2e64960dd57e00d201.html @@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator-members.html b/classnlohmann_1_1basic__json_1_1iterator-members.html index 537bf243f..adabf9c93 100644 --- a/classnlohmann_1_1basic__json_1_1iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1iterator-members.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1iterator.html b/classnlohmann_1_1basic__json_1_1iterator.html index af36061c8..d415d821f 100644 --- a/classnlohmann_1_1basic__json_1_1iterator.html +++ b/classnlohmann_1_1basic__json_1_1iterator.html @@ -270,7 +270,7 @@ class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, N diff --git a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html index 27592ad54..af8177c5e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html index 81d7dfb6c..564fac520 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html index 8e3ca20da..4ec89ed6e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html index 69b33d66c..0fd4acb49 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html index 4114eed91..f892744e7 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html @@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html b/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html index 6f6d4eeab..3f63449ff 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html b/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html index 58150af58..03332121a 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html @@ -139,7 +139,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html b/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html index b724409c0..210803eaa 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html index 4dfd2f11c..e933b7b38 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html b/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html index d079e0f3c..b7b98620b 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html b/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html index b3a1269ba..f3eba9111 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html index 1fa01b573..d3ebaa6f1 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html @@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html b/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html index cf4f391b9..2f1c6398e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab07728b4da636eda0a24e0a51b8b46d7.html b/classnlohmann_1_1basic__json_1_1iterator_ab07728b4da636eda0a24e0a51b8b46d7.html index 33437fa32..11e873311 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab07728b4da636eda0a24e0a51b8b46d7.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab07728b4da636eda0a24e0a51b8b46d7.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html index ef6f9b016..ed15b0770 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html index 85e2d7041..8ac83d71e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html index 3a4e33d2c..5699d2c11 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html @@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html b/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html index 229725d02..ffbdf6c27 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ae58cd597336ad125d9615cff87fcd87e.html b/classnlohmann_1_1basic__json_1_1iterator_ae58cd597336ad125d9615cff87fcd87e.html index d3500e157..e91fddc02 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ae58cd597336ad125d9615cff87fcd87e.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ae58cd597336ad125d9615cff87fcd87e.html @@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html index 816db2abe..99429cc28 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html index 24645db32..d751399db 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html @@ -112,7 +112,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html index b70b97068..7f607f56f 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html @@ -174,7 +174,7 @@ class nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, N diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html index f6af4e36d..761a5aa5d 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html @@ -139,7 +139,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 fb0149b12..aa43ea7a2 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html @@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a53407187cceeb3ee5390318713dad827.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a53407187cceeb3ee5390318713dad827.html index 3449ee842..fd8224662 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a53407187cceeb3ee5390318713dad827.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a53407187cceeb3ee5390318713dad827.html @@ -139,7 +139,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 7fec7c440..b7b360ae2 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html @@ -139,7 +139,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 a69136658..20abb80ac 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html @@ -138,7 +138,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 862cfbe66..1579ce0df 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html @@ -139,7 +139,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 3a5bc7a55..6d86473a6 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html @@ -127,7 +127,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7c5e0d3bd0e1a2ba9226b7eb539a53d6.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7c5e0d3bd0e1a2ba9226b7eb539a53d6.html index 29a5a736c..1bb3ab519 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7c5e0d3bd0e1a2ba9226b7eb539a53d6.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7c5e0d3bd0e1a2ba9226b7eb539a53d6.html @@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html index e9d84e735..1f2beed50 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html @@ -139,7 +139,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 9fa6a25f2..4104e401e 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html @@ -139,7 +139,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 4cdd16d66..1a936a511 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html @@ -127,7 +127,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html index d1e05967a..beb65d100 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html @@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html index b8e9c0264..04330d5a7 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html @@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html index 9ed6d67a7..e28f73a55 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html @@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html index 76258ce4f..ce4d8a98f 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html @@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html b/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html index 0e04508ee..a31fbc0f8 100644 --- a/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html +++ b/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html @@ -281,12 +281,10 @@ template<template< typename U, typename V, typename...Args > class Obje
  • 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call size()
    19  std::cout << j_null.size() << '\n';
    20  std::cout << j_boolean.size() << '\n';
    21  std::cout << j_number_integer.size() << '\n';
    22  std::cout << j_number_float.size() << '\n';
    23  std::cout << j_object.size() << '\n';
    24  std::cout << j_object_empty.size() << '\n';
    25  std::cout << j_array.size() << '\n';
    26  std::cout << j_array_empty.size() << '\n';
    27  std::cout << j_string.size() << '\n';
    28 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    size_type size() const noexcept
    returns the number of elements
    Definition: json.hpp:4330
    -
    Output (play with this example online):
    0
    +
    Output (play with this example online):
    0
     1
     1
     1
    @@ -308,7 +306,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html b/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html
    index 2ff357a26..534b93b2b 100644
    --- a/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html
    +++ b/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html
    @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a08ad7169ceb437efff7b2d4a8c0dafe2.html b/classnlohmann_1_1basic__json_a08ad7169ceb437efff7b2d4a8c0dafe2.html
    index 9d87b494b..80dc15a76 100644
    --- a/classnlohmann_1_1basic__json_a08ad7169ceb437efff7b2d4a8c0dafe2.html
    +++ b/classnlohmann_1_1basic__json_a08ad7169ceb437efff7b2d4a8c0dafe2.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is a boolean.

    Returns
    true if type is boolean, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_boolean for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    bool is_boolean() const noexcept
    return whether value is a boolean
    Definition: json.hpp:2167
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     true
     false
     false
    @@ -284,7 +282,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html b/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html
    index 69a85f41e..d9082290d 100644
    --- a/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html
    +++ b/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html
    @@ -267,12 +267,10 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows an example for back.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call 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'; // would throw
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // would throw
    27  std::cout << j_string.back() << '\n';
    28 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    reference back()
    access the last element
    Definition: json.hpp:3583
    +
    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'; // would throw
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // would throw
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     17
     23.42
     2
    @@ -291,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html b/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html
    index 7e973a435..9e26123d1 100644
    --- a/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html
    +++ b/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html
    @@ -296,10 +296,8 @@ value() with null"
       
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object with different entry types
    8  json j =
    9  {
    10  {"integer", 1},
    11  {"floating", 42.23},
    12  {"string", "hello world"},
    13  {"boolean", true},
    14  {"object", {{"key1", 1}, {"key2", 2}}},
    15  {"array", {1, 2, 3}}
    16  };
    17 
    18  // access existing values
    19  int v_integer = j.value("integer", 0);
    20  double v_floating = j.value("floating", 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("nonexisting", "oops");
    24  bool v_boolean = j.value("nonexisting", false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3498
    -
    Output (play with this example online):
    1 42.23 oops false
    +
    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:8538
    +
    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 +314,7 @@ value() with null" diff --git a/classnlohmann_1_1basic__json_a0a60ef55808edb545f4f46e49656d035.html b/classnlohmann_1_1basic__json_a0a60ef55808edb545f4f46e49656d035.html index 544de5526..7e413460d 100644 --- a/classnlohmann_1_1basic__json_a0a60ef55808edb545f4f46e49656d035.html +++ b/classnlohmann_1_1basic__json_a0a60ef55808edb545f4f46e49656d035.html @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    const_reverse_iterator crend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:4199
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:247
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/crend.cpp -o crend 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html index 1172c7a3c..b4729ebf3 100644 --- a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html +++ b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html @@ -289,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html index 15d348d97..0f3849871 100644 --- a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html +++ b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html @@ -277,10 +277,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Linear in cnt.
    -
    Example
    The following code shows examples for the basic_json(size_type, const basic_json&) constructor.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array by creating copies of a JSON value
    8  json value = "Hello";
    9  json array_0 = json(0, value);
    10  json array_1 = json(1, value);
    11  json array_5 = json(5, value);
    12 
    13  // serialize the JSON arrays
    14  std::cout << array_0 << '\n';
    15  std::cout << array_1 << '\n';
    16  std::cout << array_5 << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    []
    +
    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:8538
    +
    Output (play with this example online):
    []
     ["Hello"]
     ["Hello","Hello","Hello","Hello","Hello"]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__size_type_basic_json.cpp -o basic_json__size_type_basic_json 
    @@ -296,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html index c331a8651..d34cc7b9d 100644 --- a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html +++ b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html @@ -282,9 +282,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
     {"A":"a","B":"b"} == {"A":"a","B":"b"} true
     17 == 17.0 true
     "foo" == "bar" false
    @@ -301,7 +300,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html b/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html
    index 6c6a5329f..45fbf2bb0 100644
    --- a/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html
    +++ b/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html
    @@ -278,15 +278,12 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    Returns
    result of the deserialization
    Complexity
    Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
    Note
    A UTF-8 byte order mark is silently ignored.
    -
    Example
    The example below demonstrates the parse function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  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 }
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4451
    -
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5479
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:922
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:857
    -
    Output (play with this example online):
    {
    +
    Output (play with this example online):
    {
         "Image": {
             "Animated": false,
             "Height": 600,
    @@ -334,7 +331,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html
    index 0ff6ceb79..5a99167e6 100644
    --- a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html
    +++ b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html
    @@ -276,9 +276,8 @@ 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    Output (play with this example online):
    2
     
     {
         "one": 1,
    @@ -313,7 +312,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 d7ff7a36a..0a61e7129 100644
    --- a/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html
    +++ b/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html
    @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a1846cc6db1f38f5918c8200d9ce31896.html b/classnlohmann_1_1basic__json_a1846cc6db1f38f5918c8200d9ce31896.html
    index eadae7e9d..891981295 100644
    --- a/classnlohmann_1_1basic__json_a1846cc6db1f38f5918c8200d9ce31896.html
    +++ b/classnlohmann_1_1basic__json_a1846cc6db1f38f5918c8200d9ce31896.html
    @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    const_reverse_iterator crend() const
    returns a const reverse iterator to one before the first
    Definition: json.hpp:4199
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:247
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/crend.cpp -o crend 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a197631f31d9b17285bf9f4c156fe49c2.html b/classnlohmann_1_1basic__json_a197631f31d9b17285bf9f4c156fe49c2.html index 7d6760af3..4ef2097f3 100644 --- a/classnlohmann_1_1basic__json_a197631f31d9b17285bf9f4c156fe49c2.html +++ b/classnlohmann_1_1basic__json_a197631f31d9b17285bf9f4c156fe49c2.html @@ -275,10 +275,9 @@ template<typename T , typename std::enable_if<
    Note
    This constructor would have the same signature as basic_json(const int value), so we need to switch this one off in case number_integer_t is the same as int. This is done via the helper type T.
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of a JSON integer number value.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    Example
    The example below shows the construction of a JSON 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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    42
    +
    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 
    See also
    basic_json(const int) – create a number value (integer)
    @@ -295,7 +294,7 @@ template<typename T , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html index 8f6acbe92..2ab68c4d1 100644 --- a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html +++ b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html @@ -268,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html index c8a92970b..69611fc87 100644 --- a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html +++ b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json array = {1, 2, 3, 4, 5};
    9  json null;
    10 
    11  // print values
    12  std::cout << array << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  array.push_back(6);
    17  array += 7;
    18  null += "first";
    19  null += "second";
    20 
    21  // print values
    22  std::cout << array << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    [1,2,3,4,5]
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
     ["first","second"]
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a1ec2232bcd43091d49f8dfdd6cfe9865.html b/classnlohmann_1_1basic__json_a1ec2232bcd43091d49f8dfdd6cfe9865.html
    index 779dd1d89..9eb816565 100644
    --- a/classnlohmann_1_1basic__json_a1ec2232bcd43091d49f8dfdd6cfe9865.html
    +++ b/classnlohmann_1_1basic__json_a1ec2232bcd43091d49f8dfdd6cfe9865.html
    @@ -268,11 +268,8 @@ Illustration from cppreference.com
     
  • The complexity is constant.
  • -
    Example
    The following code shows an example for end.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::iterator it = array.end();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:6669
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/end.cpp -o end 
    Since
    version 1.0.0
    @@ -286,7 +283,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html b/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html index bd3cbe7c7..b22bf01da 100644 --- a/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html +++ b/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html @@ -274,10 +274,8 @@ template<typename ValueType , typename std::enable_if<
    Complexity
    Linear in the size of the JSON value.
    -
    Example
    The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard std::vector<short>, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string, json>.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using namespace nlohmann;
    5 
    6 int main()
    7 {
    8  // create a JSON value with different types
    9  json json_types =
    10  {
    11  {"boolean", true},
    12  {
    13  "number", {
    14  {"integer", 42},
    15  {"floating-point", 17.23}
    16  }
    17  },
    18  {"string", "Hello, world!"},
    19  {"array", {1, 2, 3, 4, 5}},
    20  {"null", nullptr}
    21  };
    22 
    23  // use explicit conversions
    24  auto v1 = json_types["boolean"].get<bool>();
    25  auto v2 = json_types["number"]["integer"].get<int>();
    26  auto v3 = json_types["number"]["integer"].get<short>();
    27  auto v4 = json_types["number"]["floating-point"].get<float>();
    28  auto v5 = json_types["number"]["floating-point"].get<int>();
    29  auto v6 = json_types["string"].get<std::string>();
    30  auto v7 = json_types["array"].get<std::vector<short>>();
    31  auto v8 = json_types.get<std::unordered_map<std::string, json>>();
    32 
    33  // print the conversion results
    34  std::cout << v1 << '\n';
    35  std::cout << v2 << ' ' << v3 << '\n';
    36  std::cout << v4 << ' ' << v5 << '\n';
    37  std::cout << v6 << '\n';
    38 
    39  for (auto i : v7)
    40  {
    41  std::cout << i << ' ';
    42  }
    43  std::cout << "\n\n";
    44 
    45  for (auto i : v8)
    46  {
    47  std::cout << i.first << ": " << i.second << '\n';
    48  }
    49 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2720
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    Output (play with this example online):
    1
     42 42
     17.23 17
     Hello, world!
    @@ -304,7 +302,7 @@ array: [1,2,3,4,5]
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html
    index 6f77732fc..8dcde0180 100644
    --- a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html
    +++ b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html
    @@ -274,11 +274,10 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read and written using at.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON array
    8  json array = {"first", "2nd", "third", "fourth"};
    9 
    10  // output element at index 2 (third element)
    11  std::cout << array.at(2) << '\n';
    12 
    13  // change element at index 1 (second element) to "second"
    14  array.at(1) = "second";
    15 
    16  // output changed array
    17  std::cout << array << '\n';
    18 
    19  // try to write beyond the array limit
    20  try
    21  {
    22  array.at(5) = "sixth";
    23  }
    24  catch (std::out_of_range& e)
    25  {
    26  std::cout << "out of range: " << e.what() << '\n';
    27  }
    28 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    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:1636
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2950
    -
    Output (play with this example online):
    "third"
    +
    Output (play with this example online):
    "third"
     ["first","second","third","fourth"]
     out of range: array index 5 is out of range
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at__size_type.cpp -o at__size_type 
    @@ -294,7 +293,7 @@ out of range: array index 5 is out of range diff --git a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html index 1f51326f2..07cfd3482 100644 --- a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html +++ b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html @@ -296,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a245b34ee6341bed2e3a611e223c53c48.html b/classnlohmann_1_1basic__json_a245b34ee6341bed2e3a611e223c53c48.html index 611649f2e..a39f92015 100644 --- a/classnlohmann_1_1basic__json_a245b34ee6341bed2e3a611e223c53c48.html +++ b/classnlohmann_1_1basic__json_a245b34ee6341bed2e3a611e223c53c48.html @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje

    This function returns true iff the JSON value is an integer or unsigned integer number. This excludes floating-point values.

    Returns
    true if type is an integer or unsigned integer number, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_number_integer for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    bool is_number_integer() const noexcept
    return whether value is an integer number
    Definition: json.hpp:2220
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     true
     true
    @@ -289,7 +287,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html b/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html
    index 27afd8f6f..00e5cad9a 100644
    --- a/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html
    +++ b/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html
    @@ -302,13 +302,8 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_boolean = true;
    9  json j_number_integer = 17;
    10  json j_number_float = 23.42;
    11  json j_object = {{"one", 1}, {"two", 2}};
    12  json j_array = {1, 2, 4, 8, 16};
    13  json j_string = "Hello, world";
    14 
    15  // call erase
    16  j_boolean.erase(j_boolean.begin(), j_boolean.end());
    17  j_number_integer.erase(j_number_integer.begin(), j_number_integer.end());
    18  j_number_float.erase(j_number_float.begin(), j_number_float.end());
    19  j_object.erase(j_object.find("two"), j_object.end());
    20  j_array.erase(j_array.begin() + 1, j_array.begin() + 3);
    21  j_string.erase(j_string.begin(), j_string.end());
    22 
    23  // print values
    24  std::cout << j_boolean << '\n';
    25  std::cout << j_number_integer << '\n';
    26  std::cout << j_number_float << '\n';
    27  std::cout << j_object << '\n';
    28  std::cout << j_array << '\n';
    29  std::cout << j_string << '\n';
    30 }
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3914
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3650
    -
    Output (play with this example online):
    null
    +
    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:8538
    +
    Output (play with this example online):
    null
     null
     null
     {"one":1}
    @@ -332,7 +327,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html b/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html
    index 7b1df93ba..a0af99e76 100644
    --- a/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html
    +++ b/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html
    @@ -275,9 +275,8 @@ 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    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
    @@ -294,7 +293,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html index acdf384e8..cd18c3d8f 100644 --- a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html +++ b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html index ad76a424f..9160873a0 100644 --- a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html +++ b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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:8538
    +
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
     
    @@ -310,7 +309,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html b/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html
    index 99a0d58f7..b7f8f7234 100644
    --- a/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html
    +++ b/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html
    @@ -278,14 +278,12 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    Returns
    result of the deserialization
    Complexity
    Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
    Note
    A UTF-8 byte order mark is silently ignored.
    -
    Example
    The example below demonstrates the parse function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  std::string text = R"(
    9  {
    10  "Image": {
    11  "Width": 800,
    12  "Height": 600,
    13  "Title": "View from 15th Floor",
    14  "Thumbnail": {
    15  "Url": "http://www.example.com/image/481989943",
    16  "Height": 125,
    17  "Width": 100
    18  },
    19  "Animated" : false,
    20  "IDs": [116, 943, 234, 38793]
    21  }
    22  }
    23  )";
    24 
    25  // parse and serialize JSON
    26  json j_complete = json::parse(text);
    27  std::cout << std::setw(4) << j_complete << "\n\n";
    28 
    29 
    30  // define parser callback
    31  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
    32  {
    33  // skip object elements with key "Thumbnail"
    34  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
    35  {
    36  return false;
    37  }
    38  else
    39  {
    40  return true;
    41  }
    42  };
    43 
    44  // parse (with callback) and serialize JSON
    45  json j_filtered = json::parse(text, cb);
    46  std::cout << std::setw(4) << j_filtered << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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  std::string text = R"(
    9  {
    10  "Image": {
    11  "Width": 800,
    12  "Height": 600,
    13  "Title": "View from 15th Floor",
    14  "Thumbnail": {
    15  "Url": "http://www.example.com/image/481989943",
    16  "Height": 125,
    17  "Width": 100
    18  },
    19  "Animated" : false,
    20  "IDs": [116, 943, 234, 38793]
    21  }
    22  }
    23  )";
    24 
    25  // parse and serialize JSON
    26  json j_complete = json::parse(text);
    27  std::cout << std::setw(4) << j_complete << "\n\n";
    28 
    29 
    30  // define parser callback
    31  json::parser_callback_t cb = [](int depth, json::parse_event_t event, json & parsed)
    32  {
    33  // skip object elements with key "Thumbnail"
    34  if (event == json::parse_event_t::key and parsed == json("Thumbnail"))
    35  {
    36  return false;
    37  }
    38  else
    39  {
    40  return true;
    41  }
    42  };
    43 
    44  // parse (with callback) and serialize JSON
    45  json j_filtered = json::parse(text, cb);
    46  std::cout << std::setw(4) << j_filtered << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5479
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:922
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:857
    -
    Output (play with this example online):
    {
    +
    Output (play with this example online):
    {
         "Image": {
             "Animated": false,
             "Height": 600,
    @@ -333,7 +331,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html
    index 0cbc26916..03978c09b 100644
    --- a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html
    +++ b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html
    @@ -272,9 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows the constructor with string literal parameter.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "The quick brown fox jumps over the lazy doc"
    +
    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:8538
    +
    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
    @@ -291,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html b/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html index 651a1f75f..238b2c82d 100644 --- a/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html +++ b/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html @@ -272,11 +272,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON values can be swapped.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
    9 
    10  // create an object_t
    11  json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
    12 
    13  // swap the object stored in the JSON value
    14  value["translation"].swap(object);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "object = " << object << '\n';
    19 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    Example
    The example below shows how JSON values can be swapped.
    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:8538
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:354
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4870
    -
    Output (play with this example online):
    value = {"translation":{"cow":"Kuh","dog":"Hund"}}
    +
    Output (play with this example online):
    value = {"translation":{"cow":"Kuh","dog":"Hund"}}
     object = {"one":"eins","two":"zwei"}
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__object_t.cpp -o swap__object_t 
    Since
    version 1.0.0
    @@ -291,7 +289,7 @@ object = {"one":"eins","two":"zwei"} diff --git a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html index d5e3f1f7b..6dc67a98a 100644 --- a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html +++ b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html @@ -272,10 +272,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The following code shows the constructor with an array_t parameter.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:400
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    ["one","two",3,4.5,false]
    +
    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:8538
    +
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:400
    +
    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 
    See also
    basic_json(const CompatibleArrayType&) – create an array value from a compatible STL containers
    Since
    version 1.0.0
    @@ -290,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a3da0951c80c8f4b26497aba38cb3e463.html b/classnlohmann_1_1basic__json_a3da0951c80c8f4b26497aba38cb3e463.html index f5241230a..d433352b7 100644 --- a/classnlohmann_1_1basic__json_a3da0951c80c8f4b26497aba38cb3e463.html +++ b/classnlohmann_1_1basic__json_a3da0951c80c8f4b26497aba38cb3e463.html @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    const_reverse_iterator crbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:4176
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:247
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/crbegin.cpp -o crbegin 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html index 0a97f52b2..bd1f5e0f8 100644 --- a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html +++ b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html @@ -274,10 +274,8 @@ range"
    Complexity
    Linear in distance between idx and the end of the container.
    -
    Example
    The example shows the effect of erase.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json j_array = {0, 1, 2, 3, 4, 5};
    9 
    10  // call erase
    11  j_array.erase(2);
    12 
    13  // print values
    14  std::cout << j_array << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3650
    -
    Output (play with this example online):
    [0,1,3,4,5]
    +
    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:8538
    +
    Output (play with this example online):
    [0,1,3,4,5]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/erase__size_type.cpp -o erase__size_type 
    See also
    erase(InteratorType) – removes the element at a given position
    @@ -296,7 +294,7 @@ range" diff --git a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html index 2d8bd3383..deaf63a35 100644 --- a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html +++ b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html b/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html index 970650a51..8e98b3f97 100644 --- a/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html +++ b/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html @@ -292,12 +292,8 @@ of range"
  • other types: constant
  • -
    Example
    The example shows the result of erase for different JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_boolean = true;
    9  json j_number_integer = 17;
    10  json j_number_float = 23.42;
    11  json j_object = {{"one", 1}, {"two", 2}};
    12  json j_array = {1, 2, 4, 8, 16};
    13  json j_string = "Hello, world";
    14 
    15  // call erase
    16  j_boolean.erase(j_boolean.begin());
    17  j_number_integer.erase(j_number_integer.begin());
    18  j_number_float.erase(j_number_float.begin());
    19  j_object.erase(j_object.find("two"));
    20  j_array.erase(j_array.begin() + 2);
    21  j_string.erase(j_string.begin());
    22 
    23  // print values
    24  std::cout << j_boolean << '\n';
    25  std::cout << j_number_integer << '\n';
    26  std::cout << j_number_float << '\n';
    27  std::cout << j_object << '\n';
    28  std::cout << j_array << '\n';
    29  std::cout << j_string << '\n';
    30 }
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3914
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3650
    -
    Output (play with this example online):
    null
    +
    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:8538
    +
    Output (play with this example online):
    null
     null
     null
     {"one":1}
    @@ -321,7 +317,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html
    index cbec9933c..221adb907 100644
    --- a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html
    +++ b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html
    @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json array = {1, 2, 3, 4, 5};
    9  json null;
    10 
    11  // print values
    12  std::cout << array << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  array.push_back(6);
    17  array += 7;
    18  null += "first";
    19  null += "second";
    20 
    21  // print values
    22  std::cout << array << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    [1,2,3,4,5]
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
     ["first","second"]
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html
    index 70f3b3c3f..5afda769b 100644
    --- a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html
    +++ b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html
    @@ -277,9 +277,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows an example for the copy constructor.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    ["one","two",3,4.5,false] = ["one","two",3,4.5,false]
    +
    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:8538
    +
    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 
    Since
    version 1.0.0
    @@ -294,7 +293,7 @@ true diff --git a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html index 39ccab741..d4176331d 100644 --- a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html +++ b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html @@ -278,9 +278,8 @@ 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 JSON floating-point number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    42.2299995422363
    +
    Example
    The example below shows the construction of several JSON 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:8538
    +
    Output (play with this example online):
    42.2299995422363
     null
     23.42
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__CompatibleNumberFloatType.cpp -o basic_json__CompatibleNumberFloatType 
    @@ -297,7 +296,7 @@ null diff --git a/classnlohmann_1_1basic__json_a4cf971f099c8114bb96c9d1c93e683f3.html b/classnlohmann_1_1basic__json_a4cf971f099c8114bb96c9d1c93e683f3.html index 7f0000fcc..b8e5cfe8d 100644 --- a/classnlohmann_1_1basic__json_a4cf971f099c8114bb96c9d1c93e683f3.html +++ b/classnlohmann_1_1basic__json_a4cf971f099c8114bb96c9d1c93e683f3.html @@ -268,11 +268,8 @@ Illustration from cppreference.com
  • The complexity is constant.
  • -
    Example
    The following code shows an example for begin.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::iterator it = array.begin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:6669
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/begin.cpp -o begin 
    Since
    version 1.0.0
    @@ -286,7 +283,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html index c2b643f3b..476e2f0cb 100644 --- a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html +++ b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html @@ -275,12 +275,10 @@ template<typename ReferenceType , typename std::enable_if<
    Complexity
    Constant.
    -
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting references
    11  auto r1 = value.get_ref<const json::number_integer_t&>();
    12  auto r2 = value.get_ref<json::number_integer_t&>();
    13 
    14  // print the values
    15  std::cout << r1 << ' ' << r2 << '\n';
    16 
    17  // incompatible type throws exception
    18  try
    19  {
    20  auto r3 = value.get_ref<json::number_float_t&>();
    21  }
    22  catch (std::domain_error& ex)
    23  {
    24  std::cout << ex.what() << '\n';
    25  }
    26 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    ReferenceType get_ref()
    get a reference value (implicit)
    Definition: json.hpp:2855
    -
    Output (play with this example online):
    17 17
    +
    Output (play with this example online):
    17 17
     incompatible ReferenceType for get_ref, actual type is number
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get_ref.cpp -o get_ref 
    Since
    version 1.1.0
    @@ -295,7 +293,7 @@ incompatible ReferenceType for get_ref, actual type is number diff --git a/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html b/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html index 504ab1bcd..8c03d4cf7 100644 --- a/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html +++ b/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html @@ -267,10 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json j_object = {{"one", 1}, {"two", 2}};
    9 
    10  // call find
    11  auto count_two = j_object.count("two");
    12  auto count_three = j_object.count("three");
    13 
    14  // print values
    15  std::cout << std::boolalpha;
    16  std::cout << "number of elements with key \"two\": " << count_two << '\n';
    17  std::cout << "number of elements with key \"three\": " << count_three << '\n';
    18 }
    size_type count(typename object_t::key_type key) const
    returns the number of occurrences of a key in a JSON object
    Definition: json.hpp:3962
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    number of elements with key "two": 1
    +
    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 << std::boolalpha;
    16  std::cout << "number of elements with key \"two\": " << count_two << '\n';
    17  std::cout << "number of elements with key \"three\": " << count_three << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    +
    Output (play with this example online):
    number of elements with key "two": 1
     number of elements with key "three": 0
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/count.cpp -o count 
    Since
    version 1.0.0
    @@ -285,7 +283,7 @@ number of elements with key "three": 0 diff --git a/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html b/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html index c3a383a92..8a9b0d7fc 100644 --- a/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html +++ b/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container, O(log(size())).
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json object = {{"one", 1}, {"two", 2}};
    9  json null;
    10 
    11  // print values
    12  std::cout << object << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  object.push_back(json::object_t::value_type("three", 3));
    17  object += json::object_t::value_type("four", 4);
    18  null += json::object_t::value_type("A", "a");
    19  null += json::object_t::value_type("B", "b");
    20 
    21  // print values
    22  std::cout << object << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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:8538
    +
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
     {"A":"a","B":"b"}
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a5339f60209573ede87534b282c09fbd5.html b/classnlohmann_1_1basic__json_a5339f60209573ede87534b282c09fbd5.html
    index 4a3900649..06437e40d 100644
    --- a/classnlohmann_1_1basic__json_a5339f60209573ede87534b282c09fbd5.html
    +++ b/classnlohmann_1_1basic__json_a5339f60209573ede87534b282c09fbd5.html
    @@ -267,9 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 a JSON integer number value from an anonymous enum.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    17
    +
    Example
    The example below shows the construction of a JSON 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:8538
    +
    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)
    @@ -286,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html index 2c741eb22..ff966bba3 100644 --- a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html +++ b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html @@ -272,10 +272,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    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:1636
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    []
    +
    Output (play with this example online):
    []
     []
     [1,2,3,4]
     [["one",1],["two",2]]
    @@ -295,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a579c170c06dc73a97f5e4c54d0942616.html b/classnlohmann_1_1basic__json_a579c170c06dc73a97f5e4c54d0942616.html
    index 43918e18b..e09ba9b33 100644
    --- a/classnlohmann_1_1basic__json_a579c170c06dc73a97f5e4c54d0942616.html
    +++ b/classnlohmann_1_1basic__json_a579c170c06dc73a97f5e4c54d0942616.html
    @@ -260,9 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    Implicitly return the type of the JSON value as a value from the value_t enumeration.

    Returns
    the type of the JSON value
    Complexity
    Constant.
    -
    Example
    The following code exemplifies the value_t operator for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call 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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    value_t
    the JSON type enumeration
    Definition: json.hpp:703
    array (ordered collection of values)
    @@ -270,7 +269,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    number value (floating-point)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     true
     true
     true
    @@ -290,7 +289,7 @@ true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html
    index 5f0b07bae..507da751d 100644
    --- a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html
    +++ b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html
    @@ -275,9 +275,8 @@ use operator[] with null"
       
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    4
    +
    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:8538
    +
    Output (play with this example online):
    4
     [1,2,3,4,6]
     [1,2,3,4,6,null,null,null,null,null,11]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorarray__size_type.cpp -o operatorarray__size_type 
    @@ -293,7 +292,7 @@ use operator[] with null" diff --git a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html index a88d7375a..7e9117f1b 100644 --- a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html +++ b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
    +
    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:8538
    +
    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
     "foo" == "bar" true
    @@ -297,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a5d288e4e8828c2ef03a4f9958ce3d175.html b/classnlohmann_1_1basic__json_a5d288e4e8828c2ef03a4f9958ce3d175.html
    index 760696d9f..6a3c749ff 100644
    --- a/classnlohmann_1_1basic__json_a5d288e4e8828c2ef03a4f9958ce3d175.html
    +++ b/classnlohmann_1_1basic__json_a5d288e4e8828c2ef03a4f9958ce3d175.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is a floating-point number. This excludes integer and unsigned integer values.

    Returns
    true if type is a floating-point number, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_number_float for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    bool is_number_float() const noexcept
    return whether value is a floating-point number
    Definition: json.hpp:2270
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -289,7 +287,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html
    index e35b39e41..b032feb95 100644
    --- a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html
    +++ b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html
    @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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:8538
    +
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
     
    @@ -310,7 +309,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a5ffdd3a9d2e02ebcbad13cb90af57523.html b/classnlohmann_1_1basic__json_a5ffdd3a9d2e02ebcbad13cb90af57523.html
    index db041afe0..c1f98d164 100644
    --- a/classnlohmann_1_1basic__json_a5ffdd3a9d2e02ebcbad13cb90af57523.html
    +++ b/classnlohmann_1_1basic__json_a5ffdd3a9d2e02ebcbad13cb90af57523.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is null.

    Returns
    true if type is null, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_null for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    bool is_null() const noexcept
    return whether value is null
    Definition: json.hpp:2148
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    true
    +
    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:8538
    +
    Output (play with this example online):
    true
     false
     false
     false
    @@ -284,7 +282,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html
    index f18ecfc23..679a1aaf3 100644
    --- a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html
    +++ b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html
    @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html
    index eaa2c4799..ee8f0a8c2 100644
    --- a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html
    +++ b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html
    @@ -284,9 +284,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {
    +
    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:8538
    +
    Output (play with this example online):
    {
       "array": [
         1,
         2,
    @@ -313,7 +312,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a620e4d98496f85bd7be080248c0f14e9.html b/classnlohmann_1_1basic__json_a620e4d98496f85bd7be080248c0f14e9.html
    index 47f7f59ca..e4d88821c 100644
    --- a/classnlohmann_1_1basic__json_a620e4d98496f85bd7be080248c0f14e9.html
    +++ b/classnlohmann_1_1basic__json_a620e4d98496f85bd7be080248c0f14e9.html
    @@ -287,7 +287,7 @@ template<typename T , typename std::enable_if<
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html
    index 6f2a13bf1..f4f9c330d 100644
    --- a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html
    +++ b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html
    @@ -292,11 +292,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Linear in cnt plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // insert number 7 copies of number 7 before number 3
    11  auto new_pos = v.insert(v.begin() + 2, 7, 7);
    12 
    13  // output new array and result of insert call
    14  std::cout << *new_pos << '\n';
    15  std::cout << v << '\n';
    16 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4665
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    7
    +
    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:8538
    +
    Output (play with this example online):
    7
     [1,2,7,7,7,7,7,7,7,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__count.cpp -o insert__count 
    Since
    version 1.0.0
    @@ -311,7 +308,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a626a27f30d6912d7f516eac511fd3362.html b/classnlohmann_1_1basic__json_a626a27f30d6912d7f516eac511fd3362.html index 52d5872f3..de72f80ff 100644 --- a/classnlohmann_1_1basic__json_a626a27f30d6912d7f516eac511fd3362.html +++ b/classnlohmann_1_1basic__json_a626a27f30d6912d7f516eac511fd3362.html @@ -261,10 +261,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Note
    This function will always be false for JSON values after parsing. That is, discarded values can only occur during parsing, but will be removed when inside a structured value or replaced by null in other cases.
    Returns
    true if type is discarded, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_discarded for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    bool is_discarded() const noexcept
    return whether value is discarded
    Definition: json.hpp:2351
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -285,7 +283,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html b/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html
    index 0b6214e0d..86b2abf82 100644
    --- a/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html
    +++ b/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html
    @@ -274,10 +274,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using at.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON object
    8  json object =
    9  {
    10  {"the good", "il buono"},
    11  {"the bad", "il cativo"},
    12  {"the ugly", "il brutto"}
    13  };
    14 
    15  // output element with key "the ugly"
    16  std::cout << object.at("the ugly") << '\n';
    17 
    18  // try to read from a nonexisting key
    19  try
    20  {
    21  std::cout << object.at("the fast") << '\n';
    22  }
    23  catch (std::out_of_range)
    24  {
    25  std::cout << "out of range" << '\n';
    26  }
    27 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2950
    -
    Output (play with this example online):
    "il brutto"
    +
    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:8538
    +
    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 
    See also
    operator[](const typename object_t::key_type&) for unchecked access by reference
    @@ -295,7 +293,7 @@ out of range diff --git a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html index b7c9fc0f3..40469aabf 100644 --- a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html +++ b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html @@ -287,7 +287,7 @@ template<typename CompatibleNumberUnsignedType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_a6adb089a5cacff9c7ad80d753b3fdf98.html b/classnlohmann_1_1basic__json_a6adb089a5cacff9c7ad80d753b3fdf98.html index 792c67a42..433c96f19 100644 --- a/classnlohmann_1_1basic__json_a6adb089a5cacff9c7ad80d753b3fdf98.html +++ b/classnlohmann_1_1basic__json_a6adb089a5cacff9c7ad80d753b3fdf98.html @@ -270,10 +270,9 @@ template<template< typename U, typename V, typename...Args > class Obje 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    +
    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:8538
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    Output (play with this example online):
    3.14159265358979
    +
    Output (play with this example online):
    3.14159265358979
     null
     null
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__number_float_t.cpp -o basic_json__number_float_t 
    @@ -290,7 +289,7 @@ null diff --git a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html index 448dc2c49..605b5c2e5 100644 --- a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html +++ b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
     {"A":"a","B":"b"} == {"A":"a","B":"b"} false
     17 == 17.0 false
     "foo" == "bar" true
    @@ -297,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html
    index fdd8a857a..9e773fa6c 100644
    --- a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html
    +++ b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html
    @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json array = {1, 2, 3, 4, 5};
    9  json null;
    10 
    11  // print values
    12  std::cout << array << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  array.push_back(6);
    17  array += 7;
    18  null += "first";
    19  null += "second";
    20 
    21  // print values
    22  std::cout << array << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    [1,2,3,4,5]
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
     ["first","second"]
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html
    index dc3a073bb..ecb21ebb8 100644
    --- a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html
    +++ b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html
    @@ -267,12 +267,10 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows an example for back.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call 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'; // would throw
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // would throw
    27  std::cout << j_string.back() << '\n';
    28 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    reference back()
    access the last element
    Definition: json.hpp:3583
    +
    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'; // would throw
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // would throw
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     17
     23.42
     2
    @@ -291,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a73619da32d2a1388f5c7b37f2032138f.html b/classnlohmann_1_1basic__json_a73619da32d2a1388f5c7b37f2032138f.html
    index f1e2c9fcb..2198e75ca 100644
    --- a/classnlohmann_1_1basic__json_a73619da32d2a1388f5c7b37f2032138f.html
    +++ b/classnlohmann_1_1basic__json_a73619da32d2a1388f5c7b37f2032138f.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is an array.

    Returns
    true if type is array, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_array for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    bool is_array() const noexcept
    return whether value is an array
    Definition: json.hpp:2308
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -284,7 +282,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html
    index a85729241..b41f934de 100644
    --- a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html
    +++ b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html
    @@ -267,9 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    null
    +
    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:8538
    +
    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 
    Since
    version 1.0.0
    @@ -284,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html b/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html index c8c4aafc6..50bc42237 100644 --- a/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html +++ b/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html @@ -280,7 +280,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html index 3d3e45515..7e4db34f2 100644 --- a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html +++ b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] >= [1,2,4] false
    +
    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:8538
    +
    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
     "foo" >= "bar" true
    @@ -297,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a791afb7d6974c52b134d66aa1f249164.html b/classnlohmann_1_1basic__json_a791afb7d6974c52b134d66aa1f249164.html
    index f9f8dd75f..750acdc26 100644
    --- a/classnlohmann_1_1basic__json_a791afb7d6974c52b134d66aa1f249164.html
    +++ b/classnlohmann_1_1basic__json_a791afb7d6974c52b134d66aa1f249164.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is a number. This includes both integer and floating-point values.

    Returns
    true if type is number (regardless whether integer, unsigned integer or floating-type), false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_number for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    bool is_number() const noexcept
    return whether value is a number
    Definition: json.hpp:2194
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     true
     true
    @@ -289,7 +287,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html
    index 543a98688..e6678a3fc 100644
    --- a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html
    +++ b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html
    @@ -269,12 +269,10 @@ template<typename PointerType , typename std::enable_if<
     
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting pointers
    11  auto p1 = value.get_ptr<const json::number_integer_t*>();
    12  auto p2 = value.get_ptr<json::number_integer_t*>();
    13  auto p3 = value.get_ptr<json::number_integer_t* const>();
    14  auto p4 = value.get_ptr<const json::number_integer_t* const>();
    15  auto p5 = value.get_ptr<json::number_float_t*>();
    16 
    17  // print the pointees
    18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
    19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
    20 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    PointerType get_ptr() noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2804
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    Output (play with this example online):
    17 17 17 17
    +
    Output (play with this example online):
    17 17 17 17
     true
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get_ptr.cpp -o get_ptr 
    Since
    version 1.0.0
    @@ -289,7 +287,7 @@ true diff --git a/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html b/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html index 962eb5f34..03a574cf8 100644 --- a/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html +++ b/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html @@ -270,9 +270,8 @@ template<template< typename U, typename V, typename...Args > class Obje
  • 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    23
    +
    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:8538
    +
    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 
    Since
    version 1.0.0
    @@ -287,7 +286,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html index 8c299bc8c..c68adc96c 100644 --- a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html +++ b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html @@ -274,10 +274,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using at.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON object
    8  json object =
    9  {
    10  {"the good", "il buono"},
    11  {"the bad", "il cativo"},
    12  {"the ugly", "il brutto"}
    13  };
    14 
    15  // output element with key "the ugly"
    16  std::cout << object.at("the ugly") << '\n';
    17 
    18  // change element with key "the bad"
    19  object.at("the bad") = "il cattivo";
    20 
    21  // output changed array
    22  std::cout << object << '\n';
    23 
    24  // try to write at a nonexisting key
    25  try
    26  {
    27  object.at("the fast") = "il rapido";
    28  }
    29  catch (std::out_of_range& e)
    30  {
    31  std::cout << "out of range: " << e.what() << '\n';
    32  }
    33 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2950
    -
    Output (play with this example online):
    "il brutto"
    +
    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:8538
    +
    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
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at__object_t_key_type.cpp -o at__object_t_key_type 
    @@ -296,7 +294,7 @@ out of range: key 'the fast' not found diff --git a/classnlohmann_1_1basic__json_a7f53f3afd83a13c949c6c42e66e9c4b4.html b/classnlohmann_1_1basic__json_a7f53f3afd83a13c949c6c42e66e9c4b4.html index ec195a7ca..d10f7fbcc 100644 --- a/classnlohmann_1_1basic__json_a7f53f3afd83a13c949c6c42e66e9c4b4.html +++ b/classnlohmann_1_1basic__json_a7f53f3afd83a13c949c6c42e66e9c4b4.html @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    11  json::reverse_iterator it = array.rbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    reverse_iterator rbegin()
    returns an iterator to the reverse-beginning
    Definition: json.hpp:4114
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:245
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/rbegin.cpp -o rbegin 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html index 6d69a849d..bfecf5431 100644 --- a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html +++ b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html @@ -285,11 +285,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // insert number 10 before number 3
    11  auto new_pos = v.insert(v.begin() + 2, 10);
    12 
    13  // output new array and result of insert call
    14  std::cout << *new_pos << '\n';
    15  std::cout << v << '\n';
    16 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4665
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    10
    +
    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:8538
    +
    Output (play with this example online):
    10
     [1,2,10,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
    Since
    version 1.0.0
    @@ -304,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html index ecefeee00..d553602da 100644 --- a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html +++ b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -

    Output (play with this example online):

    [1,2,3] != nullptr true
    +
    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:8538
    +

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
     "foo" != nullptr true
    @@ -297,7 +296,7 @@ null != nullptr false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html b/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html
    index b64636e68..b2f4bf4c3 100644
    --- a/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html
    +++ b/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html
    @@ -267,12 +267,10 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows an example for front.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // would throw
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // would throw
    27  std::cout << j_string.front() << '\n';
    28 }
    reference front()
    access the first element
    Definition: json.hpp:3549
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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'; // would throw
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // would throw
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     17
     23.42
     1
    @@ -291,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html b/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html
    index 724d3bf3b..fcdefacff 100644
    --- a/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html
    +++ b/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html
    @@ -267,10 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    string_t dump(const int indent=-1) const
    serialization
    Definition: json.hpp:2057
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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:8538
    +
    Output (play with this example online):
    {"one":1,"two":2}
     
     {"one":1,"two":2}
     
    @@ -318,7 +316,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html b/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html
    index ba6d87b22..4b74ca2fd 100644
    --- a/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html
    +++ b/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html
    @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json array = {1, 2, 3, 4, 5};
    9  json null;
    10 
    11  // print values
    12  std::cout << array << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  array.push_back(6);
    17  array += 7;
    18  null += "first";
    19  null += "second";
    20 
    21  // print values
    22  std::cout << array << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    [1,2,3,4,5]
    +
    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:8538
    +
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
     ["first","second"]
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html
    index 204ee9e01..9112a1135 100644
    --- a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html
    +++ b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html
    @@ -280,9 +280,8 @@ template<class CompatibleArrayType , typename std::enable_if<
       
       
    -
    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 namespace nlohmann;
    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); // only one entry for "one" is 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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3,4]
    +
    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); // only one entry for "one" is 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:8538
    +
    Output (play with this example online):
    [1,2,3,4]
     [1.2,2.3,3.4,5.6]
     [true,true,false,true]
     [12345678909876,23456789098765,34567890987654,45678909876543]
    @@ -305,7 +304,7 @@ template<class CompatibleArrayType , typename std::enable_if<
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html b/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html
    index 529e4ff09..1928460ea 100644
    --- a/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html
    +++ b/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html
    @@ -273,11 +273,9 @@ use swap() with string"
       
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON values can be swapped.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = {{"array", {1, 2, 3, 4}}};
    9 
    10  // create an array_t
    11  json::array_t array = {"Snap", "Crackle", "Pop"};
    12 
    13  // swap the array stored in the JSON value
    14  value["array"].swap(array);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "array = " << array << '\n';
    19 }
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:400
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4870
    -
    Output (play with this example online):
    value = {"array":["Snap","Crackle","Pop"]}
    +
    Example
    The example below shows how JSON values can be swapped.
    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:8538
    +
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:400
    +
    Output (play with this example online):
    value = {"array":["Snap","Crackle","Pop"]}
     array = [1,2,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__array_t.cpp -o swap__array_t 
    Since
    version 1.0.0
    @@ -292,7 +290,7 @@ array = [1,2,3,4] diff --git a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html index f922e2099..d64e3bdf2 100644 --- a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html +++ b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html @@ -285,11 +285,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // insert number 10 before number 3
    11  auto new_pos = v.insert(v.begin() + 2, 10);
    12 
    13  // output new array and result of insert call
    14  std::cout << *new_pos << '\n';
    15  std::cout << v << '\n';
    16 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4665
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    10
    +
    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:8538
    +
    Output (play with this example online):
    10
     [1,2,10,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
    Since
    version 1.0.0
    @@ -304,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html index ad7e3da0d..e525079a8 100644 --- a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html +++ b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html @@ -273,11 +273,9 @@ use swap() with boolean"
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON values can be swapped.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { "the good", "the bad", "the ugly" };
    9 
    10  // create string_t
    11  json::string_t string = "the fast";
    12 
    13  // swap the object stored in the JSON value
    14  value[1].swap(string);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "string = " << string << '\n';
    19 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    Example
    The example below shows how JSON values can be swapped.
    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:8538
    StringType string_t
    a type for a string
    Definition: json.hpp:447
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4870
    -
    Output (play with this example online):
    value = ["the good","the fast","the ugly"]
    +
    Output (play with this example online):
    value = ["the good","the fast","the ugly"]
     string = the bad
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__string_t.cpp -o swap__string_t 
    Since
    version 1.0.0
    @@ -292,7 +290,7 @@ string = the bad diff --git a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html index 16f105909..eaa27fdb1 100644 --- a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html +++ b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] <= [1,2,4] true
    +
    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:8538
    +
    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
     "foo" <= "bar" false
    @@ -297,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a8969119432218155193bb1dac30aa4ff.html b/classnlohmann_1_1basic__json_a8969119432218155193bb1dac30aa4ff.html
    index ac0c8d849..caf94aaa5 100644
    --- a/classnlohmann_1_1basic__json_a8969119432218155193bb1dac30aa4ff.html
    +++ b/classnlohmann_1_1basic__json_a8969119432218155193bb1dac30aa4ff.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is an object.

    Returns
    true if type is object, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_object for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    bool is_object() const noexcept
    return whether value is an object
    Definition: json.hpp:2289
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -284,7 +282,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html
    index e9ac460f6..ca6bc2aa5 100644
    --- a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html
    +++ b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html
    @@ -288,16 +288,15 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows the constructor for different value_t values
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    number value (floating-point)
    -
    Output (play with this example online):
    null
    +
    Output (play with this example online):
    null
     false
     0
     0.0
    @@ -332,7 +331,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html b/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html
    index 50b436937..fc2a8c4bf 100644
    --- a/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html
    +++ b/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html
    @@ -281,12 +281,10 @@ template<template< typename U, typename V, typename...Args > class Obje
     
  • 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call 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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    bool empty() const noexcept
    checks whether the container is empty
    Definition: json.hpp:4272
    +
    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:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     false
     false
     false
    @@ -308,7 +306,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html
    index 24efcd4a4..98a373139 100644
    --- a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html
    +++ b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html
    @@ -274,9 +274,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    Output (play with this example online):
    2
     
     {
         "one": 1,
    @@ -311,7 +310,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html b/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html
    index 673acbc2c..14d5856d2 100644
    --- a/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html
    +++ b/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html
    @@ -276,7 +276,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html b/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html
    index 01b856a8c..76e84ae35 100644
    --- a/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html
    +++ b/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html
    @@ -272,10 +272,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Logarithmic in the size of the container, O(log(size())).
    -
    Example
    The example shows how push_back and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json object = {{"one", 1}, {"two", 2}};
    9  json null;
    10 
    11  // print values
    12  std::cout << object << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values
    16  object.push_back(json::object_t::value_type("three", 3));
    17  object += json::object_t::value_type("four", 4);
    18  null += json::object_t::value_type("A", "a");
    19  null += json::object_t::value_type("B", "b");
    20 
    21  // print values
    22  std::cout << object << '\n';
    23  std::cout << null << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4527
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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:8538
    +
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
     {"A":"a","B":"b"}
    @@ -292,7 +290,7 @@ null
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html
    index 4401ba33d..a1d770542 100644
    --- a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html
    +++ b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html
    @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -

    Output (play with this example online):

    [1,2,3] == nullptr false
    +
    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:8538
    +

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
     "foo" == nullptr false
    @@ -297,7 +296,7 @@ null == nullptr true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html
    index 06e7a3136..086a677a4 100644
    --- a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html
    +++ b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html
    @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -

    Output (play with this example online):

    [1,2,3] == nullptr false
    +
    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:8538
    +

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
     "foo" == nullptr false
    @@ -297,7 +296,7 @@ null == nullptr true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html b/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html
    index b399f29c6..20dbffc1c 100644
    --- a/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html
    +++ b/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html
    @@ -274,10 +274,8 @@ operator[] with null"
       
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON array
    8  json array = {"first", "2nd", "third", "fourth"};
    9 
    10  // output element at index 2 (third element)
    11  std::cout << array.at(2) << '\n';
    12 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2950
    -
    Output (play with this example online):
    "third"
    +
    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:8538
    +
    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 +289,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html index 9f0b4b2fe..8a26951f1 100644 --- a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html +++ b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html @@ -272,10 +272,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The following code shows the constructor with an object_t parameter.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:354
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {"one":1,"two":2}
    +
    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 
    See also
    basic_json(const CompatibleObjectType&) – create an object value from a compatible STL container
    Since
    version 1.0.0
    @@ -290,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a9c01092601b6229eee4f971aad263133.html b/classnlohmann_1_1basic__json_a9c01092601b6229eee4f971aad263133.html index 0381aba87..abfa26be1 100644 --- a/classnlohmann_1_1basic__json_a9c01092601b6229eee4f971aad263133.html +++ b/classnlohmann_1_1basic__json_a9c01092601b6229eee4f971aad263133.html @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    const_reverse_iterator crbegin() const
    returns a const reverse iterator to the last element
    Definition: json.hpp:4176
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:247
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/crbegin.cpp -o crbegin 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html index 53abcf70b..e5c0da56d 100644 --- a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html +++ b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html b/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html index 019fe6a99..7e6bce53d 100644 --- a/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html +++ b/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html @@ -291,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html index 1169e9802..21257091c 100644 --- a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html +++ b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html @@ -273,10 +273,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    log(size()) + count(key)
    -
    Example
    The example shows the effect of erase.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json j_object = {{"one", 1}, {"two", 2}};
    9 
    10  // call erase
    11  auto count_one = j_object.erase("one");
    12  auto count_three = j_object.erase("three");
    13 
    14  // print values
    15  std::cout << j_object << '\n';
    16  std::cout << count_one << " " << count_three << '\n';
    17 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3650
    -
    Output (play with this example online):
    {"two":2}
    +
    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:8538
    +
    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 
    See also
    erase(InteratorType) – removes the element at a given position
    @@ -296,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html b/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html index 17790171c..1d63630b9 100644 --- a/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html +++ b/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html b/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html index c15b94e6e..076d466b5 100644 --- a/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html +++ b/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html @@ -267,12 +267,10 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The following code shows an example for front.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // would throw
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // would throw
    27  std::cout << j_string.front() << '\n';
    28 }
    reference front()
    access the first element
    Definition: json.hpp:3549
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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'; // would throw
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // would throw
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     17
     23.42
     1
    @@ -291,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html b/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html
    index 938318537..2e80c5948 100644
    --- a/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html
    +++ b/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html
    @@ -275,12 +275,10 @@ template<typename ReferenceType , typename std::enable_if<
       
    Complexity
    Constant.
    -
    Example
    The example shows several calls to get_ref().
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting references
    11  auto r1 = value.get_ref<const json::number_integer_t&>();
    12  auto r2 = value.get_ref<json::number_integer_t&>();
    13 
    14  // print the values
    15  std::cout << r1 << ' ' << r2 << '\n';
    16 
    17  // incompatible type throws exception
    18  try
    19  {
    20  auto r3 = value.get_ref<json::number_float_t&>();
    21  }
    22  catch (std::domain_error& ex)
    23  {
    24  std::cout << ex.what() << '\n';
    25  }
    26 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    ReferenceType get_ref()
    get a reference value (implicit)
    Definition: json.hpp:2855
    -
    Output (play with this example online):
    17 17
    +
    Output (play with this example online):
    17 17
     incompatible ReferenceType for get_ref, actual type is number
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get_ref.cpp -o get_ref 
    Since
    version 1.1.0
    @@ -295,7 +293,7 @@ incompatible ReferenceType for get_ref, actual type is number diff --git a/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html b/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html index 901928298..2443e3005 100644 --- a/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html +++ b/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html @@ -277,9 +277,8 @@ 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    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 +295,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html b/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html index 4a2dc75f4..13e478aeb 100644 --- a/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html +++ b/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html @@ -267,11 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    Iterator to an element with key equivalent to key. If no such element is found, past-the-end (see end()) iterator is returned.
    Complexity
    Logarithmic in the size of the JSON object.
    -
    Example
    The example shows how find is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json j_object = {{"one", 1}, {"two", 2}};
    9 
    10  // call find
    11  auto it_two = j_object.find("two");
    12  auto it_three = j_object.find("three");
    13 
    14  // print values
    15  std::cout << std::boolalpha;
    16  std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n';
    17  std::cout << "value at key \"two\": " << *it_two << '\n';
    18  std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n';
    19 }
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3914
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "two" was found: true
    +
    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:8538
    +
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/find__key_type.cpp -o find__key_type 
    @@ -287,7 +284,7 @@ value at key "two": 2 diff --git a/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html b/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html index 68ad4f698..d44f7ee46 100644 --- a/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html +++ b/classnlohmann_1_1basic__json_aac185a137428a7337aa620de07bfbbd7.html @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html index 1a89d5e22..835e49802 100644 --- a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html +++ b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html @@ -282,9 +282,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    whether lhs is less than rhs
    Complexity
    Linear.
    -
    Example
    The example demonstrates comparing several JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
    +
    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:8538
    +
    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
     "foo" == "bar" false
    @@ -301,7 +300,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html
    index 64d1abfa9..da8189da7 100644
    --- a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html
    +++ b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html
    @@ -285,11 +285,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    Returns
    iterator pointing to the first element inserted, or pos if ilist is empty
    Complexity
    Linear in ilist.size() plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // insert range from v2 before the end of array v
    11  auto new_pos = v.insert(v.end(), {7, 8, 9});
    12 
    13  // output new array and result of insert call
    14  std::cout << *new_pos << '\n';
    15  std::cout << v << '\n';
    16 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4665
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    7
    +
    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:8538
    +
    Output (play with this example online):
    7
     [1,2,3,4,7,8,9]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__ilist.cpp -o insert__ilist 
    Since
    version 1.0.0
    @@ -304,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html index aad912009..b2cc8ac6b 100644 --- a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html +++ b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html @@ -284,9 +284,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {
    +
    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:8538
    +
    Output (play with this example online):
    {
       "array": [
         1,
         2,
    @@ -313,7 +312,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html b/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html
    index 53c55a347..5aff9f1af 100644
    --- a/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html
    +++ b/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html
    @@ -279,7 +279,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html b/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html
    index 9eca9fe1c..ef73816f2 100644
    --- a/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html
    +++ b/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html
    @@ -274,10 +274,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read using at.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON array
    8  json array = {"first", "2nd", "third", "fourth"};
    9 
    10  // output element at index 2 (third element)
    11  std::cout << array.at(2) << '\n';
    12 
    13  // try to read beyond the array limit
    14  try
    15  {
    16  std::cout << array.at(5) << '\n';
    17  }
    18  catch (std::out_of_range)
    19  {
    20  std::cout << "out of range" << '\n';
    21  }
    22 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:2950
    -
    Output (play with this example online):
    "third"
    +
    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:8538
    +
    Output (play with this example online):
    "third"
     out of range
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at__size_type_const.cpp -o at__size_type_const 
    Since
    version 1.0.0
    @@ -292,7 +290,7 @@ out of range diff --git a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html index e85b5aa54..7bef2dc6c 100644 --- a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html +++ b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html @@ -277,7 +277,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab7b7b44891ddbc2df8ba3cbef3609178.html b/classnlohmann_1_1basic__json_ab7b7b44891ddbc2df8ba3cbef3609178.html index 2bf760724..74bb455f1 100644 --- a/classnlohmann_1_1basic__json_ab7b7b44891ddbc2df8ba3cbef3609178.html +++ b/classnlohmann_1_1basic__json_ab7b7b44891ddbc2df8ba3cbef3609178.html @@ -269,12 +269,10 @@ template<typename PointerType , typename std::enable_if<
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting pointers
    11  auto p1 = value.get<const json::number_integer_t*>();
    12  auto p2 = value.get<json::number_integer_t*>();
    13  auto p3 = value.get<json::number_integer_t* const>();
    14  auto p4 = value.get<const json::number_integer_t* const>();
    15  auto p5 = value.get<json::number_float_t*>();
    16 
    17  // print the pointees
    18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
    19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
    20 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2720
    -
    Output (play with this example online):
    17 17 17 17
    +
    Output (play with this example online):
    17 17 17 17
     true
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get__PointerType.cpp -o get__PointerType 
    See also
    get_ptr() for explicit pointer-member access
    @@ -290,7 +288,7 @@ true diff --git a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html index 942417762..3a789fa3e 100644 --- a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html +++ b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html @@ -280,9 +280,8 @@ template<class CompatibleObjectType , typename std::enable_if<
    -
    Example
    The following code shows the constructor with several compatible object type parameters.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {"one":1,"three":3,"two":2}
    +
    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:8538
    +
    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}
     {"one":true,"three":false,"two":true}
    @@ -300,7 +299,7 @@ template<class CompatibleObjectType , typename std::enable_if<
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab7d704826813d13731fbcaf220160826.html b/classnlohmann_1_1basic__json_ab7d704826813d13731fbcaf220160826.html
    index c8afb8ceb..e93bb60cb 100644
    --- a/classnlohmann_1_1basic__json_ab7d704826813d13731fbcaf220160826.html
    +++ b/classnlohmann_1_1basic__json_ab7d704826813d13731fbcaf220160826.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is an unsigned integer number. This excludes floating-point and (signed) integer values.

    Returns
    true if type is an unsigned integer number, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_number_unsigned for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    bool is_number_unsigned() const noexcept
    return whether value is an unsigned integer number
    Definition: json.hpp:2245
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     true
    @@ -289,7 +287,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html b/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html
    index 99582256e..17de7785b 100644
    --- a/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html
    +++ b/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html
    @@ -278,15 +278,12 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    Returns
    result of the deserialization
    Complexity
    Linear in the length of the input. The parser is a predictive LL(1) parser. The complexity can be higher if the parser callback function cb has a super-linear complexity.
    Note
    A UTF-8 byte order mark is silently ignored.
    -
    Example
    The example below demonstrates the parse function with and without callback function.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  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 }
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4451
    -
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5479
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:922
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:857
    -
    Output (play with this example online):
    {
    +
    Output (play with this example online):
    {
         "Image": {
             "Animated": false,
             "Height": 600,
    @@ -334,7 +331,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab856bebfdfbcf45061f1474ea8ba9924.html b/classnlohmann_1_1basic__json_ab856bebfdfbcf45061f1474ea8ba9924.html
    index 2b14f8d70..d88054798 100644
    --- a/classnlohmann_1_1basic__json_ab856bebfdfbcf45061f1474ea8ba9924.html
    +++ b/classnlohmann_1_1basic__json_ab856bebfdfbcf45061f1474ea8ba9924.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON type is primitive (string, number, boolean, or null).

    Returns
    true if type is primitive (string, number, boolean, or null), false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_primitive for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    bool is_primitive() const noexcept
    return whether type is primitive
    Definition: json.hpp:2109
    -
    Output (play with this example online):
    true
    +
    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:8538
    +
    Output (play with this example online):
    true
     true
     true
     true
    @@ -284,7 +282,7 @@ true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html
    index 9ebddffd5..e4879cd34 100644
    --- a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html
    +++ b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html
    @@ -272,10 +272,9 @@ template<template< typename U, typename V, typename...Args > class Obje
       
       
    -
    Example
    The following code shows the constructor with an string_t parameter.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    StringType string_t
    a type for a string
    Definition: json.hpp:447
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "The quick brown fox jumps over the lazy doc"
    +
    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 
    See also
    basic_json(const typename string_t::value_type*) – create a string value from a character pointer
    @@ -292,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html b/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html index 0e403c424..622c8bb34 100644 --- a/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html +++ b/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html @@ -271,7 +271,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_abb5df282f9edf9cca898c6b8a9911111.html b/classnlohmann_1_1basic__json_abb5df282f9edf9cca898c6b8a9911111.html index 7b23a6058..aec1d2e45 100644 --- a/classnlohmann_1_1basic__json_abb5df282f9edf9cca898c6b8a9911111.html +++ b/classnlohmann_1_1basic__json_abb5df282f9edf9cca898c6b8a9911111.html @@ -264,9 +264,8 @@ template<template< typename U, typename V, typename...Args > class Obje
  • As postcondition, it holds: basic_json().empty() == true.
  • -
    Example
    The following code shows the constructor for a null JSON value.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON value with default null value
    8  json j;
    9 
    10  // serialize the JSON null value
    11  std::cout << j << '\n';
    12 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    null
    +
    Example
    The following code shows the constructor for a null JSON value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value with default null value
    8  json j;
    9 
    10  // serialize the JSON null value
    11  std::cout << j << '\n';
    12 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    +
    Output (play with this example online):
    null
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json.cpp -o basic_json 
    See also
    basic_json(std::nullptr_t) – create a null value
    Since
    version 1.0.0
    @@ -279,7 +278,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_abc13258393358cb75a32fac86480bc9c.html b/classnlohmann_1_1basic__json_abc13258393358cb75a32fac86480bc9c.html index 1ce721e9c..9b72ab31c 100644 --- a/classnlohmann_1_1basic__json_abc13258393358cb75a32fac86480bc9c.html +++ b/classnlohmann_1_1basic__json_abc13258393358cb75a32fac86480bc9c.html @@ -269,11 +269,8 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::const_iterator it = array.cend();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    const_iterator cend() const
    returns a const iterator to one past the last element
    Definition: json.hpp:4090
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:6127
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
    Since
    version 1.0.0
    @@ -287,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html index 4d813da02..f65a42a5f 100644 --- a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html +++ b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html @@ -284,7 +284,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html b/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html index 56ed40c32..716b024ec 100644 --- a/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html +++ b/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html @@ -269,12 +269,10 @@ template<typename PointerType , typename std::enable_if<
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting pointers
    11  auto p1 = value.get<const json::number_integer_t*>();
    12  auto p2 = value.get<json::number_integer_t*>();
    13  auto p3 = value.get<json::number_integer_t* const>();
    14  auto p4 = value.get<const json::number_integer_t* const>();
    15  auto p5 = value.get<json::number_float_t*>();
    16 
    17  // print the pointees
    18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
    19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
    20 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2720
    -
    Output (play with this example online):
    17 17 17 17
    +
    Output (play with this example online):
    17 17 17 17
     true
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get__PointerType.cpp -o get__PointerType 
    See also
    get_ptr() for explicit pointer-member access
    @@ -290,7 +288,7 @@ true diff --git a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html index ee49a2801..a6c141537 100644 --- a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html +++ b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html @@ -276,9 +276,8 @@ 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    Output (play with this example online):
    2
     
     {
         "one": 1,
    @@ -313,7 +312,7 @@ template<typename T > 
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html
    index 5b841340f..97a0d025a 100644
    --- a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html
    +++ b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html
    @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_acbc1c415072afe69b5e69b87f496e44b.html b/classnlohmann_1_1basic__json_acbc1c415072afe69b5e69b87f496e44b.html
    index ceeb6e7ad..ffc8b8812 100644
    --- a/classnlohmann_1_1basic__json_acbc1c415072afe69b5e69b87f496e44b.html
    +++ b/classnlohmann_1_1basic__json_acbc1c415072afe69b5e69b87f496e44b.html
    @@ -269,11 +269,8 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  const json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::const_iterator it = array.cbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:6127
    -
    const_iterator cbegin() const
    returns a const iterator to the first element
    Definition: json.hpp:4031
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
    Since
    version 1.0.0
    @@ -287,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ad09218e192a80ffa8df531941afdab60.html b/classnlohmann_1_1basic__json_ad09218e192a80ffa8df531941afdab60.html index 2f2aee2d5..0cb2561d0 100644 --- a/classnlohmann_1_1basic__json_ad09218e192a80ffa8df531941afdab60.html +++ b/classnlohmann_1_1basic__json_ad09218e192a80ffa8df531941afdab60.html @@ -260,17 +260,15 @@ template<template< typename U, typename V, typename...Args > class Obje

    Return the type of the JSON value as a value from the value_t enumeration.

    Returns
    the type of the JSON value
    Complexity
    Constant.
    -
    Example
    The following code exemplifies type() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call 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 }
    value_t type() const noexcept
    return the type of the JSON value (explicit)
    Definition: json.hpp:2088
    -
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    object (unordered set of name/value pairs)
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    array (ordered collection of values)
    number value (floating-point)
    -
    Output (play with this example online):
    true
    +
    Output (play with this example online):
    true
     true
     true
     true
    @@ -290,7 +288,7 @@ true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad101425649dbc5c2e851fdb52c31741d.html b/classnlohmann_1_1basic__json_ad101425649dbc5c2e851fdb52c31741d.html
    index 08bde5530..d1642c713 100644
    --- a/classnlohmann_1_1basic__json_ad101425649dbc5c2e851fdb52c31741d.html
    +++ b/classnlohmann_1_1basic__json_ad101425649dbc5c2e851fdb52c31741d.html
    @@ -268,11 +268,9 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    11  json::reverse_iterator it = array.rend();
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    reverse_iterator rend()
    returns an iterator to the reverse-end
    Definition: json.hpp:4145
    -
    a template for a reverse iterator class
    Definition: json.hpp:238
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:245
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/rend.cpp -o rend 
    Since
    version 1.0.0
    @@ -286,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html index 50b58883e..4cd53aade 100644 --- a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html +++ b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html @@ -274,10 +274,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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:1676
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {}
    +
    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:1676
    +
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    +
    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/object.cpp -o object 
    @@ -296,7 +295,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html b/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html index fb1b6854d..9b9078fad 100644 --- a/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html +++ b/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html @@ -274,9 +274,8 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if<
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of several JSON integer number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    42
    +
    Example
    The example below shows the construction of several JSON 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:8538
    +
    Output (play with this example online):
    42
     23
     1024
     17
    @@ -297,7 +296,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if<
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad2f716992118a42aa8f8d57950a8d0bb.html b/classnlohmann_1_1basic__json_ad2f716992118a42aa8f8d57950a8d0bb.html
    index fe766e6cb..769f19d27 100644
    --- a/classnlohmann_1_1basic__json_ad2f716992118a42aa8f8d57950a8d0bb.html
    +++ b/classnlohmann_1_1basic__json_ad2f716992118a42aa8f8d57950a8d0bb.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON value is a string.

    Returns
    true if type is string, false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_string for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    bool is_string() const noexcept
    return whether value is a string
    Definition: json.hpp:2327
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -284,7 +282,7 @@ true
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad534f6d0d48bfd1d85f72d7f1b62a46d.html b/classnlohmann_1_1basic__json_ad534f6d0d48bfd1d85f72d7f1b62a46d.html
    index 78d1cd4b2..0ed4e656a 100644
    --- a/classnlohmann_1_1basic__json_ad534f6d0d48bfd1d85f72d7f1b62a46d.html
    +++ b/classnlohmann_1_1basic__json_ad534f6d0d48bfd1d85f72d7f1b62a46d.html
    @@ -269,11 +269,8 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  const json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::const_iterator it = array.cbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:6127
    -
    const_iterator cbegin() const
    returns a const iterator to the first element
    Definition: json.hpp:4031
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
    Since
    version 1.0.0
    @@ -287,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html b/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html index cbbe96f45..96d9a37fb 100644 --- a/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html +++ b/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html @@ -281,10 +281,8 @@ template<template< typename U, typename V, typename...Args > class Obje
  • 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call max_size()
    17  std::cout << j_null.max_size() << '\n';
    18  std::cout << j_boolean.max_size() << '\n';
    19  std::cout << j_number_integer.max_size() << '\n';
    20  std::cout << j_number_float.max_size() << '\n';
    21  std::cout << j_object.max_size() << '\n';
    22  std::cout << j_array.max_size() << '\n';
    23  std::cout << j_string.max_size() << '\n';
    24 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    size_type max_size() const noexcept
    returns the maximum possible number of elements
    Definition: json.hpp:4392
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    0
    +
    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:8538
    +
    Output (play with this example online):
    0
     1
     1
     1
    @@ -304,7 +302,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html b/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html
    index 4771dabff..ff20e7d15 100644
    --- a/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html
    +++ b/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html
    @@ -276,10 +276,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
     
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call clear()
    17  j_null.clear();
    18  j_boolean.clear();
    19  j_number_integer.clear();
    20  j_number_float.clear();
    21  j_object.clear();
    22  j_array.clear();
    23  j_string.clear();
    24 
    25  // serialize the cleared values()
    26  std::cout << j_null << '\n';
    27  std::cout << j_boolean << '\n';
    28  std::cout << j_number_integer << '\n';
    29  std::cout << j_number_float << '\n';
    30  std::cout << j_object << '\n';
    31  std::cout << j_array << '\n';
    32  std::cout << j_string << '\n';
    33 }
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4451
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    null
    +
    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:8538
    +
    Output (play with this example online):
    null
     false
     0
     0.0
    @@ -299,7 +297,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html b/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html
    index e31b8c57e..94c8cc15c 100644
    --- a/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html
    +++ b/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html
    @@ -278,9 +278,8 @@ 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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    2
    +
    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:8538
    +
    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
    @@ -297,7 +296,7 @@ operator[] with null" diff --git a/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html b/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html index f1698bed9..7eae69726 100644 --- a/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html +++ b/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html @@ -260,9 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje

    Create a null JSON value. This is the explicitly version of the null value constructor as it takes a null pointer as parameter. It allows to create null values by explicitly assigning a nullptr to a JSON value. The passed null pointer itself is not read – it is only used to choose the right constructor.

    Complexity
    Constant.
    -
    Example
    The following code shows the constructor with null pointer parameter.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON null value
    8  json j(nullptr);
    9 
    10  // serialize the JSON null value
    11  std::cout << j << '\n';
    12 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    null
    +
    Example
    The following code shows the constructor with null pointer parameter.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON null value
    8  json j(nullptr);
    9 
    10  // serialize the JSON null value
    11  std::cout << j << '\n';
    12 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    +
    Output (play with this example online):
    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 
    See also
    basic_json() – default constructor (implicitly creating a null value)
    Since
    version 1.0.0
    @@ -277,7 +276,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_ae129dc8ccd58cc3c64614db7d40a7dc9.html b/classnlohmann_1_1basic__json_ae129dc8ccd58cc3c64614db7d40a7dc9.html index 768830af3..85611588b 100644 --- a/classnlohmann_1_1basic__json_ae129dc8ccd58cc3c64614db7d40a7dc9.html +++ b/classnlohmann_1_1basic__json_ae129dc8ccd58cc3c64614db7d40a7dc9.html @@ -269,11 +269,8 @@ 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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::const_iterator it = array.cend();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    const_iterator cend() const
    returns a const iterator to one past the last element
    Definition: json.hpp:4090
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:6127
    -
    Output (play with this example online):
    5
    +
    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:8538
    +
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
    Since
    version 1.0.0
    @@ -287,7 +284,7 @@ Illustration from cppreference.com diff --git a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html index c21120097..b3ad11272 100644 --- a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html +++ b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html index d8048d75b..d1d9cdfc0 100644 --- a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html +++ b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html @@ -278,9 +278,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    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 namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -

    Output (play with this example online):

    [1,2,3] != nullptr true
    +
    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:8538
    +

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
     "foo" != nullptr true
    @@ -297,7 +296,7 @@ null != nullptr false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_ae799491eda5f5868a38ccdafca9fe0f0.html b/classnlohmann_1_1basic__json_ae799491eda5f5868a38ccdafca9fe0f0.html
    index 4743b4d2c..3af2a8a13 100644
    --- a/classnlohmann_1_1basic__json_ae799491eda5f5868a38ccdafca9fe0f0.html
    +++ b/classnlohmann_1_1basic__json_ae799491eda5f5868a38ccdafca9fe0f0.html
    @@ -266,9 +266,8 @@ template<template< typename U, typename V, typename...Args > class Obje
       
    Complexity
    Constant.
    -
    Example
    The example below demonstrates boolean values.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    true
    +
    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:8538
    +
    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 
    Since
    version 1.0.0
    @@ -283,7 +282,7 @@ false diff --git a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html index e2f921a13..3b01b3968 100644 --- a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html +++ b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html @@ -280,9 +280,8 @@ template<class CompatibleStringType , typename std::enable_if<
    -
    Example
    The following code shows the construction of a string value from a compatible type.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "The quick brown fox jumps over the lazy dog."
    +
    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:8538
    +
    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
    @@ -299,7 +298,7 @@ template<class CompatibleStringType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html index ea1d08fc3..66a76f272 100644 --- a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html +++ b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html @@ -287,7 +287,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html b/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html index 45d735528..2ca59663c 100644 --- a/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html +++ b/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html @@ -295,12 +295,8 @@ belong to container"
    Returns
    iterator pointing to the first element inserted, or pos if first==last
    Complexity
    Linear in std::distance(first, last) plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // create a JSON array to copy values from
    11  json v2 = {"one", "two", "three", "four"};
    12 
    13  // insert range from v2 before the end of array v
    14  auto new_pos = v.insert(v.end(), v2.begin(), v2.end());
    15 
    16  // output new array and result of insert call
    17  std::cout << *new_pos << '\n';
    18  std::cout << v << '\n';
    19 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4665
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "one"
    +
    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:8538
    +
    Output (play with this example online):
    "one"
     [1,2,3,4,"one","two","three","four"]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__range.cpp -o insert__range 
    Since
    version 1.0.0
    @@ -315,7 +311,7 @@ belong to container" diff --git a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html index 9e990c223..858f91025 100644 --- a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html +++ b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html b/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html index 7d36464fb..13ff90fe5 100644 --- a/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html +++ b/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html @@ -274,9 +274,8 @@ template<typename ValueType , typename std::enable_if<
    Complexity
    Linear in the size of the JSON value.
    -
    Example
    The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard std::vector<short>, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string, json>.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using namespace nlohmann;
    5 
    6 int main()
    7 {
    8  // create a JSON value with different types
    9  json json_types =
    10  {
    11  {"boolean", true},
    12  {
    13  "number", {
    14  {"integer", 42},
    15  {"floating-point", 17.23}
    16  }
    17  },
    18  {"string", "Hello, world!"},
    19  {"array", {1, 2, 3, 4, 5}},
    20  {"null", nullptr}
    21  };
    22 
    23  // use 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 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    1
    +
    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:8538
    +
    Output (play with this example online):
    1
     42 42
     17.23 17
     Hello, world!
    @@ -300,7 +299,7 @@ array: [1,2,3,4,5]
     
     
     
    diff --git a/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html b/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html
    index b4642ef26..253ffbf4e 100644
    --- a/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html
    +++ b/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html
    @@ -294,10 +294,8 @@ value() with null"
       
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object with different entry types
    8  json j =
    9  {
    10  {"integer", 1},
    11  {"floating", 42.23},
    12  {"string", "hello world"},
    13  {"boolean", true},
    14  {"object", {{"key1", 1}, {"key2", 2}}},
    15  {"array", {1, 2, 3}}
    16  };
    17 
    18  // access existing values
    19  int v_integer = j.value("integer", 0);
    20  double v_floating = j.value("floating", 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("nonexisting", "oops");
    24  bool v_boolean = j.value("nonexisting", false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3498
    -
    Output (play with this example online):
    1 42.23 oops false
    +
    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:8538
    +
    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 +312,7 @@ value() with null" diff --git a/classnlohmann_1_1basic__json_af12127e6fe8adbe727081f188aa599e2.html b/classnlohmann_1_1basic__json_af12127e6fe8adbe727081f188aa599e2.html index dac7badfe..a7610cd0e 100644 --- a/classnlohmann_1_1basic__json_af12127e6fe8adbe727081f188aa599e2.html +++ b/classnlohmann_1_1basic__json_af12127e6fe8adbe727081f188aa599e2.html @@ -269,12 +269,10 @@ template<typename PointerType , typename std::enable_if<
    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 namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON number
    8  json value = 17;
    9 
    10  // explicitly getting pointers
    11  auto p1 = value.get_ptr<const json::number_integer_t*>();
    12  auto p2 = value.get_ptr<json::number_integer_t*>();
    13  auto p3 = value.get_ptr<json::number_integer_t* const>();
    14  auto p4 = value.get_ptr<const json::number_integer_t* const>();
    15  auto p5 = value.get_ptr<json::number_float_t*>();
    16 
    17  // print the pointees
    18  std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
    19  std::cout << std::boolalpha << (p5 == nullptr) << '\n';
    20 }
    a class to store JSON values
    Definition: json.hpp:194
    +
    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:8538
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:544
    -
    PointerType get_ptr() noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2804
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:684
    -
    Output (play with this example online):
    17 17 17 17
    +
    Output (play with this example online):
    17 17 17 17
     true
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/get_ptr.cpp -o get_ptr 
    Since
    version 1.0.0
    @@ -289,7 +287,7 @@ true diff --git a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html index 1697ef4ff..d101a9293 100644 --- a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html +++ b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html @@ -271,7 +271,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html b/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html index baa415eea..065d5c86e 100644 --- a/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html +++ b/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html @@ -264,7 +264,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html b/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html index ede4d9151..4fb76fc61 100644 --- a/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html +++ b/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html @@ -257,7 +257,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html b/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html index 94fc3ef52..2f79bfda1 100644 --- a/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html +++ b/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html @@ -266,10 +266,8 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON arrays can be swapped.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create two JSON values
    8  json j1 = {1, 2, 3, 4, 5};
    9  json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}};
    10 
    11  // swap the values
    12  j1.swap(j2);
    13 
    14  // output the values
    15  std::cout << "j1 = " << j1 << '\n';
    16  std::cout << "j2 = " << j2 << '\n';
    17 }
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    void swap(reference other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    exchanges the values
    Definition: json.hpp:4870
    -
    Output (play with this example online):
    j1 = {"e":2.71828182845905,"pi":3.14159265358979}
    +
    Example
    The example below shows how JSON arrays can be swapped.
    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:8538
    +
    Output (play with this example online):
    j1 = {"e":2.71828182845905,"pi":3.14159265358979}
     j2 = [1,2,3,4,5]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__reference.cpp -o swap__reference 
    Since
    version 1.0.0
    @@ -284,7 +282,7 @@ j2 = [1,2,3,4,5] diff --git a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html index c717698fe..87f2f24bd 100644 --- a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html +++ b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html @@ -299,12 +299,8 @@ construct with iterators from null"
    Complexity
    Linear in distance between first and last.
    -
    Example
    The example below shows several ways to create JSON values by specifying a subrange with iterators.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
    9  json j_number = 42;
    10  json j_object = {{"one", "eins"}, {"two", "zwei"}};
    11 
    12  // create copies using iterators
    13  json j_array_range(j_array.begin() + 1, j_array.end() - 2);
    14  json j_number_range(j_number.begin(), j_number.end());
    15  json j_object_range(j_object.begin(), j_object.find("two"));
    16 
    17  // serialize the values
    18  std::cout << j_array_range << '\n';
    19  std::cout << j_number_range << '\n';
    20  std::cout << j_object_range << '\n';
    21 }
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3914
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    iterator begin()
    returns an iterator to the first element
    Definition: json.hpp:3997
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    ["bravo","charly"]
    +
    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:8538
    +
    Output (play with this example online):
    ["bravo","charly"]
     42
     {"one":"eins"}
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/basic_json__InputIt_InputIt.cpp -o basic_json__InputIt_InputIt 
    @@ -320,7 +316,7 @@ construct with iterators from null" diff --git a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html index 736662d18..0e5f8d1ff 100644 --- a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html +++ b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html @@ -308,10 +308,8 @@ initializer list"
    Complexity
    Linear in the size of the initializer list init.
    -
    Example
    The example below shows how JSON values are created from initializer lists
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_empty_init_list = json({});
    9  json j_object = { {"one", 1}, {"two", 2} };
    10  json j_array = {1, 2, 3, 4};
    11  json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
    12  json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
    13 
    14  // serialize the JSON value
    15  std::cout << j_empty_init_list << '\n';
    16  std::cout << j_object << '\n';
    17  std::cout << j_array << '\n';
    18  std::cout << j_nested_object << '\n';
    19  std::cout << j_nested_array << '\n';
    20 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:8538
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    {}
    +
    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:8538
    +
    Output (play with this example online):
    {}
     {"one":1,"two":2}
     [1,2,3,4]
     {"one":[1],"two":[1,2]}
    @@ -332,7 +330,7 @@ initializer list"
     
     
     
    diff --git a/classnlohmann_1_1basic__json_afec7d87796b8b538119b3ddc0d6950fb.html b/classnlohmann_1_1basic__json_afec7d87796b8b538119b3ddc0d6950fb.html
    index 5e4bce631..bf6ea8d32 100644
    --- a/classnlohmann_1_1basic__json_afec7d87796b8b538119b3ddc0d6950fb.html
    +++ b/classnlohmann_1_1basic__json_afec7d87796b8b538119b3ddc0d6950fb.html
    @@ -260,10 +260,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     

    This function returns true iff the JSON type is structured (array or object).

    Returns
    true if type is structured (array or object), false otherwise.
    Complexity
    Constant.
    -
    Example
    The following code exemplifies is_structured for all JSON types.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_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 }
    bool is_structured() const noexcept
    return whether type is structured
    Definition: json.hpp:2129
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    false
    +
    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:8538
    +
    Output (play with this example online):
    false
     false
     false
     false
    @@ -284,7 +282,7 @@ false
     
     
     
    diff --git a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html
    index 5d99205e5..311dee36c 100644
    --- a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html
    +++ b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html
    @@ -267,11 +267,8 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    Returns
    Iterator to an element with key equivalent to key. If no such element is found, past-the-end (see end()) iterator is returned.
    Complexity
    Logarithmic in the size of the JSON object.
    -
    Example
    The example shows how find is used.
    1 #include <json.hpp>
    2 
    3 using namespace nlohmann;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json j_object = {{"one", 1}, {"two", 2}};
    9 
    10  // call find
    11  auto it_two = j_object.find("two");
    12  auto it_three = j_object.find("three");
    13 
    14  // print values
    15  std::cout << std::boolalpha;
    16  std::cout << "\"two\" was found: " << (it_two != j_object.end()) << '\n';
    17  std::cout << "value at key \"two\": " << *it_two << '\n';
    18  std::cout << "\"three\" was found: " << (it_three != j_object.end()) << '\n';
    19 }
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:3914
    -
    a class to store JSON values
    Definition: json.hpp:194
    -
    iterator end()
    returns an iterator to one past the last element
    Definition: json.hpp:4056
    -
    namespace for Niels Lohmann
    Definition: json.hpp:88
    -
    Output (play with this example online):
    "two" was found: true
    +
    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:8538
    +
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/find__key_type.cpp -o find__key_type 
    @@ -287,7 +284,7 @@ value at key "two": 2 diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 65ef4e277..981a1aa42 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -92,7 +92,7 @@ Files diff --git a/functions.html b/functions.html index d4ca5c5d3..6f504e023 100644 --- a/functions.html +++ b/functions.html @@ -134,7 +134,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_0x7e.html b/functions_0x7e.html index f2ef615aa..a2e854e9c 100644 --- a/functions_0x7e.html +++ b/functions_0x7e.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_b.html b/functions_b.html index 72ba87842..5ba933a50 100644 --- a/functions_b.html +++ b/functions_b.html @@ -139,7 +139,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_c.html b/functions_c.html index 48544ba9b..28ff89899 100644 --- a/functions_c.html +++ b/functions_c.html @@ -152,7 +152,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_d.html b/functions_d.html index 4125b9e18..e8105b9fd 100644 --- a/functions_d.html +++ b/functions_d.html @@ -129,7 +129,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_e.html b/functions_e.html index a6caf3b9a..cbf31020c 100644 --- a/functions_e.html +++ b/functions_e.html @@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_enum.html b/functions_enum.html index 2710d999d..aae0b06a2 100644 --- a/functions_enum.html +++ b/functions_enum.html @@ -103,7 +103,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_f.html b/functions_f.html index 0b9500aca..bfb7abbb1 100644 --- a/functions_f.html +++ b/functions_f.html @@ -128,7 +128,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_func.html b/functions_func.html index f330aa105..03a119edc 100644 --- a/functions_func.html +++ b/functions_func.html @@ -419,7 +419,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_g.html b/functions_g.html index 3abb19307..07dc1a758 100644 --- a/functions_g.html +++ b/functions_g.html @@ -134,7 +134,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_i.html b/functions_i.html index 8953abfbc..4114defbe 100644 --- a/functions_i.html +++ b/functions_i.html @@ -170,7 +170,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_j.html b/functions_j.html index b7341f8b8..53ef4dd5b 100644 --- a/functions_j.html +++ b/functions_j.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_k.html b/functions_k.html index f0caeba2a..44153149b 100644 --- a/functions_k.html +++ b/functions_k.html @@ -126,7 +126,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_m.html b/functions_m.html index 39d29f090..12a2c740d 100644 --- a/functions_m.html +++ b/functions_m.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_n.html b/functions_n.html index ddc42dd6f..948e4474a 100644 --- a/functions_n.html +++ b/functions_n.html @@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_o.html b/functions_o.html index 19604330a..7691914d0 100644 --- a/functions_o.html +++ b/functions_o.html @@ -216,7 +216,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_p.html b/functions_p.html index 69c96f231..b8de4402d 100644 --- a/functions_p.html +++ b/functions_p.html @@ -139,7 +139,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_r.html b/functions_r.html index 49cd758ec..7f0d70dc0 100644 --- a/functions_r.html +++ b/functions_r.html @@ -137,7 +137,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_rela.html b/functions_rela.html index 1c3d84695..9ef678973 100644 --- a/functions_rela.html +++ b/functions_rela.html @@ -124,7 +124,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_s.html b/functions_s.html index 7458be6aa..71287dbad 100644 --- a/functions_s.html +++ b/functions_s.html @@ -134,7 +134,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_t.html b/functions_t.html index e1d6ca225..eaa080395 100644 --- a/functions_t.html +++ b/functions_t.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_type.html b/functions_type.html index 5554b2807..dbe1daf9f 100644 --- a/functions_type.html +++ b/functions_type.html @@ -165,7 +165,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_v.html b/functions_v.html index bac594900..7da101b77 100644 --- a/functions_v.html +++ b/functions_v.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/graph_legend.html b/graph_legend.html index d075f7a54..95c64aaf4 100644 --- a/graph_legend.html +++ b/graph_legend.html @@ -108,7 +108,7 @@ A yellow dashed arrow denotes a relation between a template instance and the tem diff --git a/hierarchy.html b/hierarchy.html index 2ea4c4e56..1055321f5 100644 --- a/hierarchy.html +++ b/hierarchy.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/index.html b/index.html index daf23bbc7..280369b2f 100644 --- a/index.html +++ b/index.html @@ -92,7 +92,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/json_8hpp_source.html b/json_8hpp_source.html index df76a26ec..7683fccd6 100644 --- a/json_8hpp_source.html +++ b/json_8hpp_source.html @@ -83,7 +83,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    json.hpp
    -
    1 
    38 #ifndef NLOHMANN_JSON_HPP
    39 #define NLOHMANN_JSON_HPP
    40 
    41 #include <algorithm>
    42 #include <array>
    43 #include <cassert>
    44 #include <ciso646>
    45 #include <cmath>
    46 #include <cstddef>
    47 #include <cstdio>
    48 #include <cstdlib>
    49 #include <functional>
    50 #include <initializer_list>
    51 #include <iomanip>
    52 #include <iostream>
    53 #include <iterator>
    54 #include <limits>
    55 #include <map>
    56 #include <memory>
    57 #include <sstream>
    58 #include <stdexcept>
    59 #include <string>
    60 #include <type_traits>
    61 #include <utility>
    62 #include <vector>
    63 
    64 // enable ssize_t on MinGW
    65 #ifdef __GNUC__
    66  #ifdef __MINGW32__
    67  #include <sys/types.h>
    68  #endif
    69 #endif
    70 
    71 // disable float-equal warnings on GCC/clang
    72 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    73  #pragma GCC diagnostic push
    74  #pragma GCC diagnostic ignored "-Wfloat-equal"
    75 #endif
    76 
    77 // enable ssize_t for MSVC
    78 #ifdef _MSC_VER
    79  #include <basetsd.h>
    80  using ssize_t = SSIZE_T;
    81 #endif
    82 
    88 namespace nlohmann
    89 {
    90 
    91 
    96 namespace
    97 {
    102 template<typename T>
    103 struct has_mapped_type
    104 {
    105  private:
    106  template<typename C> static char test(typename C::mapped_type*);
    107  template<typename C> static char (&test(...))[2];
    108  public:
    109  static constexpr bool value = sizeof(test<T>(0)) == 1;
    110 };
    111 
    112 }
    113 
    184 template <
    185  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    186  template<typename U, typename... Args> class ArrayType = std::vector,
    187  class StringType = std::string,
    188  class BooleanType = bool,
    189  class NumberIntegerType = int64_t,
    190  class NumberUnsignedType = uint64_t,
    191  class NumberFloatType = double,
    192  template<typename U> class AllocatorType = std::allocator
    193  >
    195 {
    196  private:
    198  using basic_json_t = basic_json<ObjectType,
    199  ArrayType,
    200  StringType,
    201  BooleanType,
    202  NumberIntegerType,
    203  NumberUnsignedType,
    204  NumberFloatType,
    205  AllocatorType>;
    206 
    207  public:
    208 
    210  // container types //
    212 
    215 
    218 
    222  using const_reference = const value_type&;
    223 
    225  using difference_type = std::ptrdiff_t;
    227  using size_type = std::size_t;
    228 
    230  using allocator_type = AllocatorType<basic_json>;
    231 
    233  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    235  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    236 
    237  // forward declaration
    238  template<typename Base> class json_reverse_iterator;
    239 
    241  class iterator;
    243  class const_iterator;
    248 
    250 
    251 
    256  {
    257  return allocator_type();
    258  }
    259 
    260 
    262  // JSON value data types //
    264 
    267 
    350  using object_t = ObjectType<StringType,
    351  basic_json,
    352  std::less<StringType>,
    353  AllocatorType<std::pair<const StringType,
    354  basic_json>>>;
    355 
    400  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    401 
    447  using string_t = StringType;
    448 
    473  using boolean_t = BooleanType;
    474 
    544  using number_integer_t = NumberIntegerType;
    545 
    616  using number_unsigned_t = NumberUnsignedType;
    617 
    684  using number_float_t = NumberFloatType;
    685 
    687 
    688 
    690  // JSON type enumeration //
    692 
    703  enum class value_t : uint8_t
    704  {
    705  null,
    706  object,
    707  array,
    708  string,
    709  boolean,
    710  number_integer,
    711  number_unsigned,
    712  number_float,
    713  discarded
    714  };
    715 
    716 
    717  private:
    719  template<typename T, typename... Args>
    720  static T* create(Args&& ... args)
    721  {
    722  AllocatorType<T> alloc;
    723  auto deleter = [&](T * object)
    724  {
    725  alloc.deallocate(object, 1);
    726  };
    727  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    728  alloc.construct(object.get(), std::forward<Args>(args)...);
    729  return object.release();
    730  }
    731 
    733  // JSON value storage //
    735 
    743  union json_value
    744  {
    746  object_t* object;
    748  array_t* array;
    750  string_t* string;
    752  boolean_t boolean;
    754  number_integer_t number_integer;
    756  number_unsigned_t number_unsigned;
    758  number_float_t number_float;
    759 
    761  json_value() noexcept = default;
    763  json_value(boolean_t v) noexcept : boolean(v) {}
    765  json_value(number_integer_t v) noexcept : number_integer(v) {}
    767  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    769  json_value(number_float_t v) noexcept : number_float(v) {}
    771  json_value(value_t t)
    772  {
    773  switch (t)
    774  {
    775  case value_t::object:
    776  {
    777  object = create<object_t>();
    778  break;
    779  }
    780 
    781  case value_t::array:
    782  {
    783  array = create<array_t>();
    784  break;
    785  }
    786 
    787  case value_t::string:
    788  {
    789  string = create<string_t>("");
    790  break;
    791  }
    792 
    793  case value_t::boolean:
    794  {
    795  boolean = boolean_t(false);
    796  break;
    797  }
    798 
    799  case value_t::number_integer:
    800  {
    801  number_integer = number_integer_t(0);
    802  break;
    803  }
    804 
    805  case value_t::number_unsigned:
    806  {
    807  number_unsigned = number_unsigned_t(0);
    808  break;
    809  }
    810 
    811  case value_t::number_float:
    812  {
    813  number_float = number_float_t(0.0);
    814  break;
    815  }
    816 
    817  default:
    818  {
    819  break;
    820  }
    821  }
    822  }
    823 
    825  json_value(const string_t& value)
    826  {
    827  string = create<string_t>(value);
    828  }
    829 
    831  json_value(const object_t& value)
    832  {
    833  object = create<object_t>(value);
    834  }
    835 
    837  json_value(const array_t& value)
    838  {
    839  array = create<array_t>(value);
    840  }
    841  };
    842 
    843 
    844  public:
    846  // JSON parser callback //
    848 
    857  enum class parse_event_t : uint8_t
    858  {
    860  object_start,
    862  object_end,
    864  array_start,
    866  array_end,
    868  key,
    870  value
    871  };
    872 
    922  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    923 
    924 
    926  // constructors //
    928 
    931 
    972  : m_type(value_type), m_value(value_type)
    973  {}
    974 
    994  basic_json() noexcept = default;
    995 
    1015  basic_json(std::nullptr_t) noexcept
    1016  : basic_json(value_t::null)
    1017  {}
    1018 
    1038  basic_json(const object_t& val)
    1039  : m_type(value_t::object), m_value(val)
    1040  {}
    1041 
    1065  template <class CompatibleObjectType, typename
    1066  std::enable_if<
    1067  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1068  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    1069  = 0>
    1070  basic_json(const CompatibleObjectType& val)
    1071  : m_type(value_t::object)
    1072  {
    1073  using std::begin;
    1074  using std::end;
    1075  m_value.object = create<object_t>(begin(val), end(val));
    1076  }
    1077 
    1097  basic_json(const array_t& val)
    1098  : m_type(value_t::array), m_value(val)
    1099  {}
    1100 
    1124  template <class CompatibleArrayType, typename
    1125  std::enable_if<
    1126  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1127  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1128  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1129  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1130  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1131  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1132  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1133  = 0>
    1134  basic_json(const CompatibleArrayType& val)
    1135  : m_type(value_t::array)
    1136  {
    1137  using std::begin;
    1138  using std::end;
    1139  m_value.array = create<array_t>(begin(val), end(val));
    1140  }
    1141 
    1163  basic_json(const string_t& val)
    1164  : m_type(value_t::string), m_value(val)
    1165  {}
    1166 
    1187  basic_json(const typename string_t::value_type* val)
    1188  : basic_json(string_t(val))
    1189  {}
    1190 
    1214  template <class CompatibleStringType, typename
    1215  std::enable_if<
    1216  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1217  = 0>
    1218  basic_json(const CompatibleStringType& val)
    1219  : basic_json(string_t(val))
    1220  {}
    1221 
    1237  : m_type(value_t::boolean), m_value(val)
    1238  {}
    1239 
    1265  template<typename T,
    1266  typename std::enable_if<
    1267  not (std::is_same<T, int>::value)
    1268  and std::is_same<T, number_integer_t>::value
    1269  , int>::type
    1270  = 0>
    1272  : m_type(value_t::number_integer), m_value(val)
    1273  {}
    1274 
    1300  basic_json(const int val)
    1301  : m_type(value_t::number_integer),
    1302  m_value(static_cast<number_integer_t>(val))
    1303  {}
    1304 
    1330  template<typename CompatibleNumberIntegerType, typename
    1331  std::enable_if<
    1332  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1333  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1334  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1335  CompatibleNumberIntegerType>::type
    1336  = 0>
    1337  basic_json(const CompatibleNumberIntegerType val) noexcept
    1338  : m_type(value_t::number_integer),
    1339  m_value(static_cast<number_integer_t>(val))
    1340  {}
    1341 
    1359  template<typename T,
    1360  typename std::enable_if<
    1361  not (std::is_same<T, int>::value)
    1362  and std::is_same<T, number_unsigned_t>::value
    1363  , int>::type
    1364  = 0>
    1366  : m_type(value_t::number_unsigned), m_value(val)
    1367  {}
    1368 
    1389  template < typename CompatibleNumberUnsignedType, typename
    1390  std::enable_if <
    1391  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1392  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1393  !std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1394  CompatibleNumberUnsignedType >::type
    1395  = 0 >
    1396  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1397  : m_type(value_t::number_unsigned),
    1398  m_value(static_cast<number_unsigned_t>(val))
    1399  {}
    1400 
    1426  : m_type(value_t::number_float), m_value(val)
    1427  {
    1428  // replace infinity and NAN by null
    1429  if (not std::isfinite(val))
    1430  {
    1431  m_type = value_t::null;
    1432  m_value = json_value();
    1433  }
    1434  }
    1435 
    1466  template<typename CompatibleNumberFloatType, typename = typename
    1467  std::enable_if<
    1468  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1469  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1470  >
    1471  basic_json(const CompatibleNumberFloatType val) noexcept
    1472  : basic_json(number_float_t(val))
    1473  {}
    1474 
    1544  basic_json(std::initializer_list<basic_json> init,
    1545  bool type_deduction = true,
    1546  value_t manual_type = value_t::array)
    1547  {
    1548  // the initializer list could describe an object
    1549  bool is_an_object = true;
    1550 
    1551  // check if each element is an array with two elements whose first
    1552  // element is a string
    1553  for (const auto& element : init)
    1554  {
    1555  if (not element.is_array() or element.size() != 2
    1556  or not element[0].is_string())
    1557  {
    1558  // we found an element that makes it impossible to use the
    1559  // initializer list as object
    1560  is_an_object = false;
    1561  break;
    1562  }
    1563  }
    1564 
    1565  // adjust type if type deduction is not wanted
    1566  if (not type_deduction)
    1567  {
    1568  // if array is wanted, do not create an object though possible
    1569  if (manual_type == value_t::array)
    1570  {
    1571  is_an_object = false;
    1572  }
    1573 
    1574  // if object is wanted but impossible, throw an exception
    1575  if (manual_type == value_t::object and not is_an_object)
    1576  {
    1577  throw std::domain_error("cannot create object from initializer list");
    1578  }
    1579  }
    1580 
    1581  if (is_an_object)
    1582  {
    1583  // the initializer list is a list of pairs -> create object
    1584  m_type = value_t::object;
    1585  m_value = value_t::object;
    1586 
    1587  assert(m_value.object != nullptr);
    1588 
    1589  for (auto& element : init)
    1590  {
    1591  m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
    1592  }
    1593  }
    1594  else
    1595  {
    1596  // the initializer list describes an array -> create array
    1597  m_type = value_t::array;
    1598  m_value.array = create<array_t>(std::move(init));
    1599  }
    1600  }
    1601 
    1636  static basic_json array(std::initializer_list<basic_json> init =
    1637  std::initializer_list<basic_json>())
    1638  {
    1639  return basic_json(init, false, value_t::array);
    1640  }
    1641 
    1676  static basic_json object(std::initializer_list<basic_json> init =
    1677  std::initializer_list<basic_json>())
    1678  {
    1679  return basic_json(init, false, value_t::object);
    1680  }
    1681 
    1700  basic_json(size_type cnt, const basic_json& val)
    1701  : m_type(value_t::array)
    1702  {
    1703  m_value.array = create<array_t>(cnt, val);
    1704  }
    1705 
    1740  template <class InputIT, typename
    1741  std::enable_if<
    1742  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1743  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1744  , int>::type
    1745  = 0>
    1746  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1747  {
    1748  // make sure iterator fits the current value
    1749  if (first.m_object != last.m_object)
    1750  {
    1751  throw std::domain_error("iterators are not compatible");
    1752  }
    1753 
    1754  // check if iterator range is complete for primitive values
    1755  switch (m_type)
    1756  {
    1757  case value_t::boolean:
    1758  case value_t::number_float:
    1759  case value_t::number_integer:
    1760  case value_t::number_unsigned:
    1761  case value_t::string:
    1762  {
    1763  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1764  {
    1765  throw std::out_of_range("iterators out of range");
    1766  }
    1767  break;
    1768  }
    1769 
    1770  default:
    1771  {
    1772  break;
    1773  }
    1774  }
    1775 
    1776  switch (m_type)
    1777  {
    1778  case value_t::number_integer:
    1779  {
    1780  assert(first.m_object != nullptr);
    1781  m_value.number_integer = first.m_object->m_value.number_integer;
    1782  break;
    1783  }
    1784 
    1785  case value_t::number_unsigned:
    1786  {
    1787  assert(first.m_object != nullptr);
    1788  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1789  break;
    1790  }
    1791 
    1792  case value_t::number_float:
    1793  {
    1794  assert(first.m_object != nullptr);
    1795  m_value.number_float = first.m_object->m_value.number_float;
    1796  break;
    1797  }
    1798 
    1799  case value_t::boolean:
    1800  {
    1801  assert(first.m_object != nullptr);
    1802  m_value.boolean = first.m_object->m_value.boolean;
    1803  break;
    1804  }
    1805 
    1806  case value_t::string:
    1807  {
    1808  assert(first.m_object != nullptr);
    1809  m_value = *first.m_object->m_value.string;
    1810  break;
    1811  }
    1812 
    1813  case value_t::object:
    1814  {
    1815  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1816  break;
    1817  }
    1818 
    1819  case value_t::array:
    1820  {
    1821  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1822  break;
    1823  }
    1824 
    1825  default:
    1826  {
    1827  assert(first.m_object != nullptr);
    1828  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1829  }
    1830  }
    1831  }
    1832 
    1834  // other constructors and destructor //
    1836 
    1857  basic_json(const basic_json& other)
    1858  : m_type(other.m_type)
    1859  {
    1860  switch (m_type)
    1861  {
    1862  case value_t::object:
    1863  {
    1864  assert(other.m_value.object != nullptr);
    1865  m_value = *other.m_value.object;
    1866  break;
    1867  }
    1868 
    1869  case value_t::array:
    1870  {
    1871  assert(other.m_value.array != nullptr);
    1872  m_value = *other.m_value.array;
    1873  break;
    1874  }
    1875 
    1876  case value_t::string:
    1877  {
    1878  assert(other.m_value.string != nullptr);
    1879  m_value = *other.m_value.string;
    1880  break;
    1881  }
    1882 
    1883  case value_t::boolean:
    1884  {
    1885  m_value = other.m_value.boolean;
    1886  break;
    1887  }
    1888 
    1889  case value_t::number_integer:
    1890  {
    1891  m_value = other.m_value.number_integer;
    1892  break;
    1893  }
    1894 
    1895  case value_t::number_unsigned:
    1896  {
    1897  m_value = other.m_value.number_unsigned;
    1898  break;
    1899  }
    1900 
    1901  case value_t::number_float:
    1902  {
    1903  m_value = other.m_value.number_float;
    1904  break;
    1905  }
    1906 
    1907  default:
    1908  {
    1909  break;
    1910  }
    1911  }
    1912  }
    1913 
    1932  basic_json(basic_json&& other) noexcept
    1933  : m_type(std::move(other.m_type)),
    1934  m_value(std::move(other.m_value))
    1935  {
    1936  // invalidate payload
    1937  other.m_type = value_t::null;
    1938  other.m_value = {};
    1939  }
    1940 
    1962  reference& operator=(basic_json other) noexcept (
    1963  std::is_nothrow_move_constructible<value_t>::value and
    1964  std::is_nothrow_move_assignable<value_t>::value and
    1965  std::is_nothrow_move_constructible<json_value>::value and
    1966  std::is_nothrow_move_assignable<json_value>::value
    1967  )
    1968  {
    1969  using std::swap;
    1970  swap(m_type, other.m_type);
    1971  swap(m_value, other.m_value);
    1972  return *this;
    1973  }
    1974 
    1989  {
    1990  switch (m_type)
    1991  {
    1992  case value_t::object:
    1993  {
    1994  AllocatorType<object_t> alloc;
    1995  alloc.destroy(m_value.object);
    1996  alloc.deallocate(m_value.object, 1);
    1997  break;
    1998  }
    1999 
    2000  case value_t::array:
    2001  {
    2002  AllocatorType<array_t> alloc;
    2003  alloc.destroy(m_value.array);
    2004  alloc.deallocate(m_value.array, 1);
    2005  break;
    2006  }
    2007 
    2008  case value_t::string:
    2009  {
    2010  AllocatorType<string_t> alloc;
    2011  alloc.destroy(m_value.string);
    2012  alloc.deallocate(m_value.string, 1);
    2013  break;
    2014  }
    2015 
    2016  default:
    2017  {
    2018  // all other types need no specific destructor
    2019  break;
    2020  }
    2021  }
    2022  }
    2023 
    2025 
    2026  public:
    2028  // object inspection //
    2030 
    2033 
    2057  string_t dump(const int indent = -1) const
    2058  {
    2059  std::stringstream ss;
    2060 
    2061  if (indent >= 0)
    2062  {
    2063  dump(ss, true, static_cast<unsigned int>(indent));
    2064  }
    2065  else
    2066  {
    2067  dump(ss, false, 0);
    2068  }
    2069 
    2070  return ss.str();
    2071  }
    2072 
    2088  value_t type() const noexcept
    2089  {
    2090  return m_type;
    2091  }
    2092 
    2109  bool is_primitive() const noexcept
    2110  {
    2111  return is_null() or is_string() or is_boolean() or is_number();
    2112  }
    2113 
    2129  bool is_structured() const noexcept
    2130  {
    2131  return is_array() or is_object();
    2132  }
    2133 
    2148  bool is_null() const noexcept
    2149  {
    2150  return m_type == value_t::null;
    2151  }
    2152 
    2167  bool is_boolean() const noexcept
    2168  {
    2169  return m_type == value_t::boolean;
    2170  }
    2171 
    2194  bool is_number() const noexcept
    2195  {
    2196  return is_number_integer() or is_number_float();
    2197  }
    2198 
    2220  bool is_number_integer() const noexcept
    2221  {
    2222  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2223  }
    2224 
    2245  bool is_number_unsigned() const noexcept
    2246  {
    2247  return m_type == value_t::number_unsigned;
    2248  }
    2249 
    2270  bool is_number_float() const noexcept
    2271  {
    2272  return m_type == value_t::number_float;
    2273  }
    2274 
    2289  bool is_object() const noexcept
    2290  {
    2291  return m_type == value_t::object;
    2292  }
    2293 
    2308  bool is_array() const noexcept
    2309  {
    2310  return m_type == value_t::array;
    2311  }
    2312 
    2327  bool is_string() const noexcept
    2328  {
    2329  return m_type == value_t::string;
    2330  }
    2331 
    2351  bool is_discarded() const noexcept
    2352  {
    2353  return m_type == value_t::discarded;
    2354  }
    2355 
    2371  operator value_t() const noexcept
    2372  {
    2373  return m_type;
    2374  }
    2375 
    2377 
    2378  private:
    2380  // value access //
    2382 
    2384  template <class T, typename
    2385  std::enable_if<
    2386  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2387  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2388  , int>::type = 0>
    2389  T get_impl(T*) const
    2390  {
    2391  if (is_object())
    2392  {
    2393  assert(m_value.object != nullptr);
    2394  return T(m_value.object->begin(), m_value.object->end());
    2395  }
    2396  else
    2397  {
    2398  throw std::domain_error("type must be object, but is " + type_name());
    2399  }
    2400  }
    2401 
    2403  object_t get_impl(object_t*) const
    2404  {
    2405  if (is_object())
    2406  {
    2407  assert(m_value.object != nullptr);
    2408  return *(m_value.object);
    2409  }
    2410  else
    2411  {
    2412  throw std::domain_error("type must be object, but is " + type_name());
    2413  }
    2414  }
    2415 
    2417  template <class T, typename
    2418  std::enable_if<
    2419  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2420  not std::is_same<basic_json_t, typename T::value_type>::value and
    2421  not std::is_arithmetic<T>::value and
    2422  not std::is_convertible<std::string, T>::value and
    2423  not has_mapped_type<T>::value
    2424  , int>::type = 0>
    2425  T get_impl(T*) const
    2426  {
    2427  if (is_array())
    2428  {
    2429  T to_vector;
    2430  assert(m_value.array != nullptr);
    2431  std::transform(m_value.array->begin(), m_value.array->end(),
    2432  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2433  {
    2434  return i.get<typename T::value_type>();
    2435  });
    2436  return to_vector;
    2437  }
    2438  else
    2439  {
    2440  throw std::domain_error("type must be array, but is " + type_name());
    2441  }
    2442  }
    2443 
    2445  template <class T, typename
    2446  std::enable_if<
    2447  std::is_convertible<basic_json_t, T>::value and
    2448  not std::is_same<basic_json_t, T>::value
    2449  , int>::type = 0>
    2450  std::vector<T> get_impl(std::vector<T>*) const
    2451  {
    2452  if (is_array())
    2453  {
    2454  std::vector<T> to_vector;
    2455  assert(m_value.array != nullptr);
    2456  to_vector.reserve(m_value.array->size());
    2457  std::transform(m_value.array->begin(), m_value.array->end(),
    2458  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2459  {
    2460  return i.get<T>();
    2461  });
    2462  return to_vector;
    2463  }
    2464  else
    2465  {
    2466  throw std::domain_error("type must be array, but is " + type_name());
    2467  }
    2468  }
    2469 
    2471  template <class T, typename
    2472  std::enable_if<
    2473  std::is_same<basic_json, typename T::value_type>::value and
    2474  not has_mapped_type<T>::value
    2475  , int>::type = 0>
    2476  T get_impl(T*) const
    2477  {
    2478  if (is_array())
    2479  {
    2480  assert(m_value.array != nullptr);
    2481  return T(m_value.array->begin(), m_value.array->end());
    2482  }
    2483  else
    2484  {
    2485  throw std::domain_error("type must be array, but is " + type_name());
    2486  }
    2487  }
    2488 
    2490  array_t get_impl(array_t*) const
    2491  {
    2492  if (is_array())
    2493  {
    2494  assert(m_value.array != nullptr);
    2495  return *(m_value.array);
    2496  }
    2497  else
    2498  {
    2499  throw std::domain_error("type must be array, but is " + type_name());
    2500  }
    2501  }
    2502 
    2504  template <typename T, typename
    2505  std::enable_if<
    2506  std::is_convertible<string_t, T>::value
    2507  , int>::type = 0>
    2508  T get_impl(T*) const
    2509  {
    2510  if (is_string())
    2511  {
    2512  assert(m_value.string != nullptr);
    2513  return *m_value.string;
    2514  }
    2515  else
    2516  {
    2517  throw std::domain_error("type must be string, but is " + type_name());
    2518  }
    2519  }
    2520 
    2522  template<typename T, typename
    2523  std::enable_if<
    2524  std::is_arithmetic<T>::value
    2525  , int>::type = 0>
    2526  T get_impl(T*) const
    2527  {
    2528  switch (m_type)
    2529  {
    2530  case value_t::number_integer:
    2531  {
    2532  return static_cast<T>(m_value.number_integer);
    2533  }
    2534 
    2535  case value_t::number_unsigned:
    2536  {
    2537  return static_cast<T>(m_value.number_unsigned);
    2538  }
    2539 
    2540  case value_t::number_float:
    2541  {
    2542  return static_cast<T>(m_value.number_float);
    2543  }
    2544 
    2545  default:
    2546  {
    2547  throw std::domain_error("type must be number, but is " + type_name());
    2548  }
    2549  }
    2550  }
    2551 
    2553  boolean_t get_impl(boolean_t*) const
    2554  {
    2555  if (is_boolean())
    2556  {
    2557  return m_value.boolean;
    2558  }
    2559  else
    2560  {
    2561  throw std::domain_error("type must be boolean, but is " + type_name());
    2562  }
    2563  }
    2564 
    2566  object_t* get_impl_ptr(object_t*) noexcept
    2567  {
    2568  return is_object() ? m_value.object : nullptr;
    2569  }
    2570 
    2572  const object_t* get_impl_ptr(const object_t*) const noexcept
    2573  {
    2574  return is_object() ? m_value.object : nullptr;
    2575  }
    2576 
    2578  array_t* get_impl_ptr(array_t*) noexcept
    2579  {
    2580  return is_array() ? m_value.array : nullptr;
    2581  }
    2582 
    2584  const array_t* get_impl_ptr(const array_t*) const noexcept
    2585  {
    2586  return is_array() ? m_value.array : nullptr;
    2587  }
    2588 
    2590  string_t* get_impl_ptr(string_t*) noexcept
    2591  {
    2592  return is_string() ? m_value.string : nullptr;
    2593  }
    2594 
    2596  const string_t* get_impl_ptr(const string_t*) const noexcept
    2597  {
    2598  return is_string() ? m_value.string : nullptr;
    2599  }
    2600 
    2602  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2603  {
    2604  return is_boolean() ? &m_value.boolean : nullptr;
    2605  }
    2606 
    2608  const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2609  {
    2610  return is_boolean() ? &m_value.boolean : nullptr;
    2611  }
    2612 
    2614  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2615  {
    2616  return is_number_integer() ? &m_value.number_integer : nullptr;
    2617  }
    2618 
    2620  const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2621  {
    2622  return is_number_integer() ? &m_value.number_integer : nullptr;
    2623  }
    2624 
    2626  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2627  {
    2628  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2629  }
    2630 
    2632  const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2633  {
    2634  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2635  }
    2636 
    2638  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2639  {
    2640  return is_number_float() ? &m_value.number_float : nullptr;
    2641  }
    2642 
    2644  const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2645  {
    2646  return is_number_float() ? &m_value.number_float : nullptr;
    2647  }
    2648 
    2660  template<typename ReferenceType, typename ThisType>
    2661  static ReferenceType get_ref_impl(ThisType& obj)
    2662  {
    2663  // delegate the call to get_ptr<>()
    2664  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2665  auto ptr = obj.template get_ptr<PointerType>();
    2666 
    2667  if (ptr != nullptr)
    2668  {
    2669  return *ptr;
    2670  }
    2671  else
    2672  {
    2673  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2674  obj.type_name());
    2675  }
    2676  }
    2677 
    2678  public:
    2679 
    2682 
    2716  template<typename ValueType, typename
    2717  std::enable_if<
    2718  not std::is_pointer<ValueType>::value
    2719  , int>::type = 0>
    2720  ValueType get() const
    2721  {
    2722  return get_impl(static_cast<ValueType*>(nullptr));
    2723  }
    2724 
    2751  template<typename PointerType, typename
    2752  std::enable_if<
    2753  std::is_pointer<PointerType>::value
    2754  , int>::type = 0>
    2755  PointerType get() noexcept
    2756  {
    2757  // delegate the call to get_ptr
    2758  return get_ptr<PointerType>();
    2759  }
    2760 
    2765  template<typename PointerType, typename
    2766  std::enable_if<
    2767  std::is_pointer<PointerType>::value
    2768  , int>::type = 0>
    2769  const PointerType get() const noexcept
    2770  {
    2771  // delegate the call to get_ptr
    2772  return get_ptr<PointerType>();
    2773  }
    2774 
    2800  template<typename PointerType, typename
    2801  std::enable_if<
    2802  std::is_pointer<PointerType>::value
    2803  , int>::type = 0>
    2804  PointerType get_ptr() noexcept
    2805  {
    2806  // delegate the call to get_impl_ptr<>()
    2807  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2808  }
    2809 
    2814  template<typename PointerType, typename
    2815  std::enable_if<
    2816  std::is_pointer<PointerType>::value
    2817  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2818  , int>::type = 0>
    2819  const PointerType get_ptr() const noexcept
    2820  {
    2821  // delegate the call to get_impl_ptr<>() const
    2822  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2823  }
    2824 
    2851  template<typename ReferenceType, typename
    2852  std::enable_if<
    2853  std::is_reference<ReferenceType>::value
    2854  , int>::type = 0>
    2855  ReferenceType get_ref()
    2856  {
    2857  // delegate call to get_ref_impl
    2858  return get_ref_impl<ReferenceType>(*this);
    2859  }
    2860 
    2865  template<typename ReferenceType, typename
    2866  std::enable_if<
    2867  std::is_reference<ReferenceType>::value
    2868  and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
    2869  , int>::type = 0>
    2870  ReferenceType get_ref() const
    2871  {
    2872  // delegate call to get_ref_impl
    2873  return get_ref_impl<ReferenceType>(*this);
    2874  }
    2875 
    2904  template < typename ValueType, typename
    2905  std::enable_if <
    2906  not std::is_pointer<ValueType>::value
    2907  and not std::is_same<ValueType, typename string_t::value_type>::value
    2908 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    2909  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    2910 #endif
    2911  , int >::type = 0 >
    2912  operator ValueType() const
    2913  {
    2914  // delegate the call to get<>() const
    2915  return get<ValueType>();
    2916  }
    2917 
    2919 
    2920 
    2922  // element access //
    2924 
    2927 
    2951  {
    2952  // at only works for arrays
    2953  if (is_array())
    2954  {
    2955  try
    2956  {
    2957  assert(m_value.array != nullptr);
    2958  return m_value.array->at(idx);
    2959  }
    2960  catch (std::out_of_range&)
    2961  {
    2962  // create better exception explanation
    2963  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2964  }
    2965  }
    2966  else
    2967  {
    2968  throw std::domain_error("cannot use at() with " + type_name());
    2969  }
    2970  }
    2971 
    2995  {
    2996  // at only works for arrays
    2997  if (is_array())
    2998  {
    2999  try
    3000  {
    3001  assert(m_value.array != nullptr);
    3002  return m_value.array->at(idx);
    3003  }
    3004  catch (std::out_of_range&)
    3005  {
    3006  // create better exception explanation
    3007  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3008  }
    3009  }
    3010  else
    3011  {
    3012  throw std::domain_error("cannot use at() with " + type_name());
    3013  }
    3014  }
    3015 
    3042  reference at(const typename object_t::key_type& key)
    3043  {
    3044  // at only works for objects
    3045  if (is_object())
    3046  {
    3047  try
    3048  {
    3049  assert(m_value.object != nullptr);
    3050  return m_value.object->at(key);
    3051  }
    3052  catch (std::out_of_range&)
    3053  {
    3054  // create better exception explanation
    3055  throw std::out_of_range("key '" + key + "' not found");
    3056  }
    3057  }
    3058  else
    3059  {
    3060  throw std::domain_error("cannot use at() with " + type_name());
    3061  }
    3062  }
    3063 
    3090  const_reference at(const typename object_t::key_type& key) const
    3091  {
    3092  // at only works for objects
    3093  if (is_object())
    3094  {
    3095  try
    3096  {
    3097  assert(m_value.object != nullptr);
    3098  return m_value.object->at(key);
    3099  }
    3100  catch (std::out_of_range&)
    3101  {
    3102  // create better exception explanation
    3103  throw std::out_of_range("key '" + key + "' not found");
    3104  }
    3105  }
    3106  else
    3107  {
    3108  throw std::domain_error("cannot use at() with " + type_name());
    3109  }
    3110  }
    3111 
    3138  {
    3139  // implicitly convert null to object
    3140  if (is_null())
    3141  {
    3142  m_type = value_t::array;
    3143  m_value.array = create<array_t>();
    3144  }
    3145 
    3146  // [] only works for arrays
    3147  if (is_array())
    3148  {
    3149  assert(m_value.array != nullptr);
    3150  for (size_t i = m_value.array->size(); i <= idx; ++i)
    3151  {
    3152  m_value.array->push_back(basic_json());
    3153  }
    3154 
    3155  return m_value.array->operator[](idx);
    3156  }
    3157  else
    3158  {
    3159  throw std::domain_error("cannot use operator[] with " + type_name());
    3160  }
    3161  }
    3162 
    3183  {
    3184  // at only works for arrays
    3185  if (is_array())
    3186  {
    3187  assert(m_value.array != nullptr);
    3188  return m_value.array->operator[](idx);
    3189  }
    3190  else
    3191  {
    3192  throw std::domain_error("cannot use operator[] with " + type_name());
    3193  }
    3194  }
    3195 
    3223  reference operator[](const typename object_t::key_type& key)
    3224  {
    3225  // implicitly convert null to object
    3226  if (is_null())
    3227  {
    3228  m_type = value_t::object;
    3229  m_value.object = create<object_t>();
    3230  }
    3231 
    3232  // [] only works for objects
    3233  if (is_object())
    3234  {
    3235  assert(m_value.object != nullptr);
    3236  return m_value.object->operator[](key);
    3237  }
    3238  else
    3239  {
    3240  throw std::domain_error("cannot use operator[] with " + type_name());
    3241  }
    3242  }
    3243 
    3271  const_reference operator[](const typename object_t::key_type& key) const
    3272  {
    3273  // [] only works for objects
    3274  if (is_object())
    3275  {
    3276  assert(m_value.object != nullptr);
    3277  assert(m_value.object->find(key) != m_value.object->end());
    3278  return m_value.object->find(key)->second;
    3279  }
    3280  else
    3281  {
    3282  throw std::domain_error("cannot use operator[] with " + type_name());
    3283  }
    3284  }
    3285 
    3313  template<typename T, std::size_t n>
    3314  reference operator[](T * (&key)[n])
    3315  {
    3316  return operator[](static_cast<const T>(key));
    3317  }
    3318 
    3348  template<typename T, std::size_t n>
    3349  const_reference operator[](T * (&key)[n]) const
    3350  {
    3351  return operator[](static_cast<const T>(key));
    3352  }
    3353 
    3381  template<typename T>
    3383  {
    3384  // implicitly convert null to object
    3385  if (is_null())
    3386  {
    3387  m_type = value_t::object;
    3388  m_value = value_t::object;
    3389  }
    3390 
    3391  // at only works for objects
    3392  if (is_object())
    3393  {
    3394  assert(m_value.object != nullptr);
    3395  return m_value.object->operator[](key);
    3396  }
    3397  else
    3398  {
    3399  throw std::domain_error("cannot use operator[] with " + type_name());
    3400  }
    3401  }
    3402 
    3430  template<typename T>
    3432  {
    3433  // at only works for objects
    3434  if (is_object())
    3435  {
    3436  assert(m_value.object != nullptr);
    3437  assert(m_value.object->find(key) != m_value.object->end());
    3438  return m_value.object->find(key)->second;
    3439  }
    3440  else
    3441  {
    3442  throw std::domain_error("cannot use operator[] with " + type_name());
    3443  }
    3444  }
    3445 
    3494  template <class ValueType, typename
    3495  std::enable_if<
    3496  std::is_convertible<basic_json_t, ValueType>::value
    3497  , int>::type = 0>
    3498  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3499  {
    3500  // at only works for objects
    3501  if (is_object())
    3502  {
    3503  // if key is found, return value and given default value otherwise
    3504  const auto it = find(key);
    3505  if (it != end())
    3506  {
    3507  return *it;
    3508  }
    3509  else
    3510  {
    3511  return default_value;
    3512  }
    3513  }
    3514  else
    3515  {
    3516  throw std::domain_error("cannot use value() with " + type_name());
    3517  }
    3518  }
    3519 
    3524  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3525  {
    3526  return value(key, string_t(default_value));
    3527  }
    3528 
    3550  {
    3551  return *begin();
    3552  }
    3553 
    3558  {
    3559  return *cbegin();
    3560  }
    3561 
    3584  {
    3585  auto tmp = end();
    3586  --tmp;
    3587  return *tmp;
    3588  }
    3589 
    3594  {
    3595  auto tmp = cend();
    3596  --tmp;
    3597  return *tmp;
    3598  }
    3599 
    3644  template <class InteratorType, typename
    3645  std::enable_if<
    3646  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3647  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3648  , int>::type
    3649  = 0>
    3650  InteratorType erase(InteratorType pos)
    3651  {
    3652  // make sure iterator fits the current value
    3653  if (this != pos.m_object)
    3654  {
    3655  throw std::domain_error("iterator does not fit current value");
    3656  }
    3657 
    3658  InteratorType result = end();
    3659 
    3660  switch (m_type)
    3661  {
    3662  case value_t::boolean:
    3663  case value_t::number_float:
    3664  case value_t::number_integer:
    3665  case value_t::number_unsigned:
    3666  case value_t::string:
    3667  {
    3668  if (not pos.m_it.primitive_iterator.is_begin())
    3669  {
    3670  throw std::out_of_range("iterator out of range");
    3671  }
    3672 
    3673  if (is_string())
    3674  {
    3675  delete m_value.string;
    3676  m_value.string = nullptr;
    3677  }
    3678 
    3679  m_type = value_t::null;
    3680  break;
    3681  }
    3682 
    3683  case value_t::object:
    3684  {
    3685  assert(m_value.object != nullptr);
    3686  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3687  break;
    3688  }
    3689 
    3690  case value_t::array:
    3691  {
    3692  assert(m_value.array != nullptr);
    3693  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3694  break;
    3695  }
    3696 
    3697  default:
    3698  {
    3699  throw std::domain_error("cannot use erase() with " + type_name());
    3700  }
    3701  }
    3702 
    3703  return result;
    3704  }
    3705 
    3750  template <class InteratorType, typename
    3751  std::enable_if<
    3752  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3753  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3754  , int>::type
    3755  = 0>
    3756  InteratorType erase(InteratorType first, InteratorType last)
    3757  {
    3758  // make sure iterator fits the current value
    3759  if (this != first.m_object or this != last.m_object)
    3760  {
    3761  throw std::domain_error("iterators do not fit current value");
    3762  }
    3763 
    3764  InteratorType result = end();
    3765 
    3766  switch (m_type)
    3767  {
    3768  case value_t::boolean:
    3769  case value_t::number_float:
    3770  case value_t::number_integer:
    3771  case value_t::number_unsigned:
    3772  case value_t::string:
    3773  {
    3774  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3775  {
    3776  throw std::out_of_range("iterators out of range");
    3777  }
    3778 
    3779  if (is_string())
    3780  {
    3781  delete m_value.string;
    3782  m_value.string = nullptr;
    3783  }
    3784 
    3785  m_type = value_t::null;
    3786  break;
    3787  }
    3788 
    3789  case value_t::object:
    3790  {
    3791  assert(m_value.object != nullptr);
    3792  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3793  last.m_it.object_iterator);
    3794  break;
    3795  }
    3796 
    3797  case value_t::array:
    3798  {
    3799  assert(m_value.array != nullptr);
    3800  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3801  last.m_it.array_iterator);
    3802  break;
    3803  }
    3804 
    3805  default:
    3806  {
    3807  throw std::domain_error("cannot use erase() with " + type_name());
    3808  }
    3809  }
    3810 
    3811  return result;
    3812  }
    3813 
    3840  size_type erase(const typename object_t::key_type& key)
    3841  {
    3842  // this erase only works for objects
    3843  if (is_object())
    3844  {
    3845  assert(m_value.object != nullptr);
    3846  return m_value.object->erase(key);
    3847  }
    3848  else
    3849  {
    3850  throw std::domain_error("cannot use erase() with " + type_name());
    3851  }
    3852  }
    3853 
    3878  void erase(const size_type idx)
    3879  {
    3880  // this erase only works for arrays
    3881  if (is_array())
    3882  {
    3883  if (idx >= size())
    3884  {
    3885  throw std::out_of_range("index out of range");
    3886  }
    3887 
    3888  assert(m_value.array != nullptr);
    3889  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    3890  }
    3891  else
    3892  {
    3893  throw std::domain_error("cannot use erase() with " + type_name());
    3894  }
    3895  }
    3896 
    3914  iterator find(typename object_t::key_type key)
    3915  {
    3916  auto result = end();
    3917 
    3918  if (is_object())
    3919  {
    3920  assert(m_value.object != nullptr);
    3921  result.m_it.object_iterator = m_value.object->find(key);
    3922  }
    3923 
    3924  return result;
    3925  }
    3926 
    3931  const_iterator find(typename object_t::key_type key) const
    3932  {
    3933  auto result = cend();
    3934 
    3935  if (is_object())
    3936  {
    3937  assert(m_value.object != nullptr);
    3938  result.m_it.object_iterator = m_value.object->find(key);
    3939  }
    3940 
    3941  return result;
    3942  }
    3943 
    3962  size_type count(typename object_t::key_type key) const
    3963  {
    3964  // return 0 for all nonobject types
    3965  assert(not is_object() or m_value.object != nullptr);
    3966  return is_object() ? m_value.object->count(key) : 0;
    3967  }
    3968 
    3970 
    3971 
    3973  // iterators //
    3975 
    3978 
    3998  {
    3999  iterator result(this);
    4000  result.set_begin();
    4001  return result;
    4002  }
    4003 
    4008  {
    4009  return cbegin();
    4010  }
    4011 
    4032  {
    4033  const_iterator result(this);
    4034  result.set_begin();
    4035  return result;
    4036  }
    4037 
    4057  {
    4058  iterator result(this);
    4059  result.set_end();
    4060  return result;
    4061  }
    4062 
    4067  {
    4068  return cend();
    4069  }
    4070 
    4091  {
    4092  const_iterator result(this);
    4093  result.set_end();
    4094  return result;
    4095  }
    4096 
    4115  {
    4116  return reverse_iterator(end());
    4117  }
    4118 
    4123  {
    4124  return crbegin();
    4125  }
    4126 
    4146  {
    4147  return reverse_iterator(begin());
    4148  }
    4149 
    4154  {
    4155  return crend();
    4156  }
    4157 
    4177  {
    4178  return const_reverse_iterator(cend());
    4179  }
    4180 
    4200  {
    4201  return const_reverse_iterator(cbegin());
    4202  }
    4203 
    4204  private:
    4205  // forward declaration
    4206  template<typename IteratorType> class iteration_proxy;
    4207 
    4208  public:
    4220  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4221  {
    4222  return iteration_proxy<iterator>(cont);
    4223  }
    4224 
    4228  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4229  {
    4230  return iteration_proxy<const_iterator>(cont);
    4231  }
    4232 
    4234 
    4235 
    4237  // capacity //
    4239 
    4242 
    4272  bool empty() const noexcept
    4273  {
    4274  switch (m_type)
    4275  {
    4276  case value_t::null:
    4277  {
    4278  // null values are empty
    4279  return true;
    4280  }
    4281 
    4282  case value_t::array:
    4283  {
    4284  assert(m_value.array != nullptr);
    4285  return m_value.array->empty();
    4286  }
    4287 
    4288  case value_t::object:
    4289  {
    4290  assert(m_value.object != nullptr);
    4291  return m_value.object->empty();
    4292  }
    4293 
    4294  default:
    4295  {
    4296  // all other types are nonempty
    4297  return false;
    4298  }
    4299  }
    4300  }
    4301 
    4330  size_type size() const noexcept
    4331  {
    4332  switch (m_type)
    4333  {
    4334  case value_t::null:
    4335  {
    4336  // null values are empty
    4337  return 0;
    4338  }
    4339 
    4340  case value_t::array:
    4341  {
    4342  assert(m_value.array != nullptr);
    4343  return m_value.array->size();
    4344  }
    4345 
    4346  case value_t::object:
    4347  {
    4348  assert(m_value.object != nullptr);
    4349  return m_value.object->size();
    4350  }
    4351 
    4352  default:
    4353  {
    4354  // all other types have size 1
    4355  return 1;
    4356  }
    4357  }
    4358  }
    4359 
    4392  size_type max_size() const noexcept
    4393  {
    4394  switch (m_type)
    4395  {
    4396  case value_t::array:
    4397  {
    4398  assert(m_value.array != nullptr);
    4399  return m_value.array->max_size();
    4400  }
    4401 
    4402  case value_t::object:
    4403  {
    4404  assert(m_value.object != nullptr);
    4405  return m_value.object->max_size();
    4406  }
    4407 
    4408  default:
    4409  {
    4410  // all other types have max_size() == size()
    4411  return size();
    4412  }
    4413  }
    4414  }
    4415 
    4417 
    4418 
    4420  // modifiers //
    4422 
    4425 
    4451  void clear() noexcept
    4452  {
    4453  switch (m_type)
    4454  {
    4455  case value_t::number_integer:
    4456  {
    4457  m_value.number_integer = 0;
    4458  break;
    4459  }
    4460 
    4461  case value_t::number_unsigned:
    4462  {
    4463  m_value.number_unsigned = 0;
    4464  break;
    4465  }
    4466 
    4467  case value_t::number_float:
    4468  {
    4469  m_value.number_float = 0.0;
    4470  break;
    4471  }
    4472 
    4473  case value_t::boolean:
    4474  {
    4475  m_value.boolean = false;
    4476  break;
    4477  }
    4478 
    4479  case value_t::string:
    4480  {
    4481  assert(m_value.string != nullptr);
    4482  m_value.string->clear();
    4483  break;
    4484  }
    4485 
    4486  case value_t::array:
    4487  {
    4488  assert(m_value.array != nullptr);
    4489  m_value.array->clear();
    4490  break;
    4491  }
    4492 
    4493  case value_t::object:
    4494  {
    4495  assert(m_value.object != nullptr);
    4496  m_value.object->clear();
    4497  break;
    4498  }
    4499 
    4500  default:
    4501  {
    4502  break;
    4503  }
    4504  }
    4505  }
    4506 
    4527  void push_back(basic_json&& val)
    4528  {
    4529  // push_back only works for null objects or arrays
    4530  if (not(is_null() or is_array()))
    4531  {
    4532  throw std::domain_error("cannot use push_back() with " + type_name());
    4533  }
    4534 
    4535  // transform null object into an array
    4536  if (is_null())
    4537  {
    4538  m_type = value_t::array;
    4539  m_value = value_t::array;
    4540  }
    4541 
    4542  // add element to array (move semantics)
    4543  assert(m_value.array != nullptr);
    4544  m_value.array->push_back(std::move(val));
    4545  // invalidate object
    4546  val.m_type = value_t::null;
    4547  }
    4548 
    4553  reference operator+=(basic_json&& val)
    4554  {
    4555  push_back(std::move(val));
    4556  return *this;
    4557  }
    4558 
    4563  void push_back(const basic_json& val)
    4564  {
    4565  // push_back only works for null objects or arrays
    4566  if (not(is_null() or is_array()))
    4567  {
    4568  throw std::domain_error("cannot use push_back() with " + type_name());
    4569  }
    4570 
    4571  // transform null object into an array
    4572  if (is_null())
    4573  {
    4574  m_type = value_t::array;
    4575  m_value = value_t::array;
    4576  }
    4577 
    4578  // add element to array
    4579  assert(m_value.array != nullptr);
    4580  m_value.array->push_back(val);
    4581  }
    4582 
    4587  reference operator+=(const basic_json& val)
    4588  {
    4589  push_back(val);
    4590  return *this;
    4591  }
    4592 
    4613  void push_back(const typename object_t::value_type& val)
    4614  {
    4615  // push_back only works for null objects or objects
    4616  if (not(is_null() or is_object()))
    4617  {
    4618  throw std::domain_error("cannot use push_back() with " + type_name());
    4619  }
    4620 
    4621  // transform null object into an object
    4622  if (is_null())
    4623  {
    4624  m_type = value_t::object;
    4625  m_value = value_t::object;
    4626  }
    4627 
    4628  // add element to array
    4629  assert(m_value.object != nullptr);
    4630  m_value.object->insert(val);
    4631  }
    4632 
    4637  reference operator+=(const typename object_t::value_type& val)
    4638  {
    4639  push_back(val);
    4640  return operator[](val.first);
    4641  }
    4642 
    4665  iterator insert(const_iterator pos, const basic_json& val)
    4666  {
    4667  // insert only works for arrays
    4668  if (is_array())
    4669  {
    4670  // check if iterator pos fits to this JSON value
    4671  if (pos.m_object != this)
    4672  {
    4673  throw std::domain_error("iterator does not fit current value");
    4674  }
    4675 
    4676  // insert to array and return iterator
    4677  iterator result(this);
    4678  assert(m_value.array != nullptr);
    4679  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4680  return result;
    4681  }
    4682  else
    4683  {
    4684  throw std::domain_error("cannot use insert() with " + type_name());
    4685  }
    4686  }
    4687 
    4692  iterator insert(const_iterator pos, basic_json&& val)
    4693  {
    4694  return insert(pos, val);
    4695  }
    4696 
    4721  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    4722  {
    4723  // insert only works for arrays
    4724  if (is_array())
    4725  {
    4726  // check if iterator pos fits to this JSON value
    4727  if (pos.m_object != this)
    4728  {
    4729  throw std::domain_error("iterator does not fit current value");
    4730  }
    4731 
    4732  // insert to array and return iterator
    4733  iterator result(this);
    4734  assert(m_value.array != nullptr);
    4735  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    4736  return result;
    4737  }
    4738  else
    4739  {
    4740  throw std::domain_error("cannot use insert() with " + type_name());
    4741  }
    4742  }
    4743 
    4775  {
    4776  // insert only works for arrays
    4777  if (not is_array())
    4778  {
    4779  throw std::domain_error("cannot use insert() with " + type_name());
    4780  }
    4781 
    4782  // check if iterator pos fits to this JSON value
    4783  if (pos.m_object != this)
    4784  {
    4785  throw std::domain_error("iterator does not fit current value");
    4786  }
    4787 
    4788  if (first.m_object != last.m_object)
    4789  {
    4790  throw std::domain_error("iterators do not fit");
    4791  }
    4792 
    4793  if (first.m_object == this or last.m_object == this)
    4794  {
    4795  throw std::domain_error("passed iterators may not belong to container");
    4796  }
    4797 
    4798  // insert to array and return iterator
    4799  iterator result(this);
    4800  assert(m_value.array != nullptr);
    4801  result.m_it.array_iterator = m_value.array->insert(
    4802  pos.m_it.array_iterator,
    4803  first.m_it.array_iterator,
    4804  last.m_it.array_iterator);
    4805  return result;
    4806  }
    4807 
    4832  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    4833  {
    4834  // insert only works for arrays
    4835  if (not is_array())
    4836  {
    4837  throw std::domain_error("cannot use insert() with " + type_name());
    4838  }
    4839 
    4840  // check if iterator pos fits to this JSON value
    4841  if (pos.m_object != this)
    4842  {
    4843  throw std::domain_error("iterator does not fit current value");
    4844  }
    4845 
    4846  // insert to array and return iterator
    4847  iterator result(this);
    4848  assert(m_value.array != nullptr);
    4849  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    4850  return result;
    4851  }
    4852 
    4870  void swap(reference other) noexcept (
    4871  std::is_nothrow_move_constructible<value_t>::value and
    4872  std::is_nothrow_move_assignable<value_t>::value and
    4873  std::is_nothrow_move_constructible<json_value>::value and
    4874  std::is_nothrow_move_assignable<json_value>::value
    4875  )
    4876  {
    4877  std::swap(m_type, other.m_type);
    4878  std::swap(m_value, other.m_value);
    4879  }
    4880 
    4901  void swap(array_t& other)
    4902  {
    4903  // swap only works for arrays
    4904  if (is_array())
    4905  {
    4906  assert(m_value.array != nullptr);
    4907  std::swap(*(m_value.array), other);
    4908  }
    4909  else
    4910  {
    4911  throw std::domain_error("cannot use swap() with " + type_name());
    4912  }
    4913  }
    4914 
    4935  void swap(object_t& other)
    4936  {
    4937  // swap only works for objects
    4938  if (is_object())
    4939  {
    4940  assert(m_value.object != nullptr);
    4941  std::swap(*(m_value.object), other);
    4942  }
    4943  else
    4944  {
    4945  throw std::domain_error("cannot use swap() with " + type_name());
    4946  }
    4947  }
    4948 
    4969  void swap(string_t& other)
    4970  {
    4971  // swap only works for strings
    4972  if (is_string())
    4973  {
    4974  assert(m_value.string != nullptr);
    4975  std::swap(*(m_value.string), other);
    4976  }
    4977  else
    4978  {
    4979  throw std::domain_error("cannot use swap() with " + type_name());
    4980  }
    4981  }
    4982 
    4984 
    4985 
    4987  // lexicographical comparison operators //
    4989 
    4992 
    4993  private:
    5003  friend bool operator<(const value_t lhs, const value_t rhs)
    5004  {
    5005  static constexpr std::array<uint8_t, 8> order = {{
    5006  0, // null
    5007  3, // object
    5008  4, // array
    5009  5, // string
    5010  1, // boolean
    5011  2, // integer
    5012  2, // unsigned
    5013  2, // float
    5014  }
    5015  };
    5016 
    5017  // discarded values are not comparable
    5018  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5019  {
    5020  return false;
    5021  }
    5022 
    5023  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5024  }
    5025 
    5026  public:
    5050  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5051  {
    5052  const auto lhs_type = lhs.type();
    5053  const auto rhs_type = rhs.type();
    5054 
    5055  if (lhs_type == rhs_type)
    5056  {
    5057  switch (lhs_type)
    5058  {
    5059  case value_t::array:
    5060  {
    5061  assert(lhs.m_value.array != nullptr);
    5062  assert(rhs.m_value.array != nullptr);
    5063  return *lhs.m_value.array == *rhs.m_value.array;
    5064  }
    5065  case value_t::object:
    5066  {
    5067  assert(lhs.m_value.object != nullptr);
    5068  assert(rhs.m_value.object != nullptr);
    5069  return *lhs.m_value.object == *rhs.m_value.object;
    5070  }
    5071  case value_t::null:
    5072  {
    5073  return true;
    5074  }
    5075  case value_t::string:
    5076  {
    5077  assert(lhs.m_value.string != nullptr);
    5078  assert(rhs.m_value.string != nullptr);
    5079  return *lhs.m_value.string == *rhs.m_value.string;
    5080  }
    5081  case value_t::boolean:
    5082  {
    5083  return lhs.m_value.boolean == rhs.m_value.boolean;
    5084  }
    5085  case value_t::number_integer:
    5086  {
    5087  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5088  }
    5089  case value_t::number_unsigned:
    5090  {
    5091  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5092  }
    5093  case value_t::number_float:
    5094  {
    5095  return lhs.m_value.number_float == rhs.m_value.number_float;
    5096  }
    5097  default:
    5098  {
    5099  return false;
    5100  }
    5101  }
    5102  }
    5103  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5104  {
    5105  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5106  }
    5107  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5108  {
    5109  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5110  }
    5111  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5112  {
    5113  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5114  }
    5115  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5116  {
    5117  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5118  }
    5119  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5120  {
    5121  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5122  }
    5123  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5124  {
    5125  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5126  }
    5127 
    5128  return false;
    5129  }
    5130 
    5149  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5150  {
    5151  return v.is_null();
    5152  }
    5153 
    5158  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5159  {
    5160  return v.is_null();
    5161  }
    5162 
    5179  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5180  {
    5181  return not (lhs == rhs);
    5182  }
    5183 
    5202  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5203  {
    5204  return not v.is_null();
    5205  }
    5206 
    5211  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5212  {
    5213  return not v.is_null();
    5214  }
    5215 
    5240  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5241  {
    5242  const auto lhs_type = lhs.type();
    5243  const auto rhs_type = rhs.type();
    5244 
    5245  if (lhs_type == rhs_type)
    5246  {
    5247  switch (lhs_type)
    5248  {
    5249  case value_t::array:
    5250  {
    5251  assert(lhs.m_value.array != nullptr);
    5252  assert(rhs.m_value.array != nullptr);
    5253  return *lhs.m_value.array < *rhs.m_value.array;
    5254  }
    5255  case value_t::object:
    5256  {
    5257  assert(lhs.m_value.object != nullptr);
    5258  assert(rhs.m_value.object != nullptr);
    5259  return *lhs.m_value.object < *rhs.m_value.object;
    5260  }
    5261  case value_t::null:
    5262  {
    5263  return false;
    5264  }
    5265  case value_t::string:
    5266  {
    5267  assert(lhs.m_value.string != nullptr);
    5268  assert(rhs.m_value.string != nullptr);
    5269  return *lhs.m_value.string < *rhs.m_value.string;
    5270  }
    5271  case value_t::boolean:
    5272  {
    5273  return lhs.m_value.boolean < rhs.m_value.boolean;
    5274  }
    5275  case value_t::number_integer:
    5276  {
    5277  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5278  }
    5279  case value_t::number_unsigned:
    5280  {
    5281  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5282  }
    5283  case value_t::number_float:
    5284  {
    5285  return lhs.m_value.number_float < rhs.m_value.number_float;
    5286  }
    5287  default:
    5288  {
    5289  return false;
    5290  }
    5291  }
    5292  }
    5293  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5294  {
    5295  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5296  }
    5297  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5298  {
    5299  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5300  }
    5301  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5302  {
    5303  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5304  }
    5305  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5306  {
    5307  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5308  }
    5309  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5310  {
    5311  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5312  }
    5313  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5314  {
    5315  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5316  }
    5317 
    5318  // We only reach this line if we cannot compare values. In that case,
    5319  // we compare types. Note we have to call the operator explicitly,
    5320  // because MSVC has problems otherwise.
    5321  return operator<(lhs_type, rhs_type);
    5322  }
    5323 
    5341  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5342  {
    5343  return not (rhs < lhs);
    5344  }
    5345 
    5363  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5364  {
    5365  return not (lhs <= rhs);
    5366  }
    5367 
    5385  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5386  {
    5387  return not (lhs < rhs);
    5388  }
    5389 
    5391 
    5392 
    5394  // serialization //
    5396 
    5399 
    5422  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5423  {
    5424  // read width member and use it as indentation parameter if nonzero
    5425  const bool pretty_print = (o.width() > 0);
    5426  const auto indentation = (pretty_print ? o.width() : 0);
    5427 
    5428  // reset width to 0 for subsequent calls to this stream
    5429  o.width(0);
    5430 
    5431  // do the actual serialization
    5432  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5433  return o;
    5434  }
    5435 
    5440  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5441  {
    5442  return o << j;
    5443  }
    5444 
    5446 
    5447 
    5449  // deserialization //
    5451 
    5454 
    5479  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5480  {
    5481  return parser(s, cb).parse();
    5482  }
    5483 
    5508  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5509  {
    5510  return parser(i, cb).parse();
    5511  }
    5512 
    5516  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5517  {
    5518  return parser(i, cb).parse();
    5519  }
    5520 
    5544  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5545  {
    5546  j = parser(i).parse();
    5547  return i;
    5548  }
    5549 
    5554  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5555  {
    5556  j = parser(i).parse();
    5557  return i;
    5558  }
    5559 
    5561 
    5562 
    5563  private:
    5565  // convenience functions //
    5567 
    5569  string_t type_name() const
    5570  {
    5571  switch (m_type)
    5572  {
    5573  case value_t::null:
    5574  return "null";
    5575  case value_t::object:
    5576  return "object";
    5577  case value_t::array:
    5578  return "array";
    5579  case value_t::string:
    5580  return "string";
    5581  case value_t::boolean:
    5582  return "boolean";
    5583  case value_t::discarded:
    5584  return "discarded";
    5585  default:
    5586  return "number";
    5587  }
    5588  }
    5589 
    5598  static std::size_t extra_space(const string_t& s) noexcept
    5599  {
    5600  std::size_t result = 0;
    5601 
    5602  for (const auto& c : s)
    5603  {
    5604  switch (c)
    5605  {
    5606  case '"':
    5607  case '\\':
    5608  case '\b':
    5609  case '\f':
    5610  case '\n':
    5611  case '\r':
    5612  case '\t':
    5613  {
    5614  // from c (1 byte) to \x (2 bytes)
    5615  result += 1;
    5616  break;
    5617  }
    5618 
    5619  default:
    5620  {
    5621  if (c >= 0x00 and c <= 0x1f)
    5622  {
    5623  // from c (1 byte) to \uxxxx (6 bytes)
    5624  result += 5;
    5625  }
    5626  break;
    5627  }
    5628  }
    5629  }
    5630 
    5631  return result;
    5632  }
    5633 
    5647  static string_t escape_string(const string_t& s) noexcept
    5648  {
    5649  const auto space = extra_space(s);
    5650  if (space == 0)
    5651  {
    5652  return s;
    5653  }
    5654 
    5655  // create a result string of necessary size
    5656  string_t result(s.size() + space, '\\');
    5657  std::size_t pos = 0;
    5658 
    5659  for (const auto& c : s)
    5660  {
    5661  switch (c)
    5662  {
    5663  // quotation mark (0x22)
    5664  case '"':
    5665  {
    5666  result[pos + 1] = '"';
    5667  pos += 2;
    5668  break;
    5669  }
    5670 
    5671  // reverse solidus (0x5c)
    5672  case '\\':
    5673  {
    5674  // nothing to change
    5675  pos += 2;
    5676  break;
    5677  }
    5678 
    5679  // backspace (0x08)
    5680  case '\b':
    5681  {
    5682  result[pos + 1] = 'b';
    5683  pos += 2;
    5684  break;
    5685  }
    5686 
    5687  // formfeed (0x0c)
    5688  case '\f':
    5689  {
    5690  result[pos + 1] = 'f';
    5691  pos += 2;
    5692  break;
    5693  }
    5694 
    5695  // newline (0x0a)
    5696  case '\n':
    5697  {
    5698  result[pos + 1] = 'n';
    5699  pos += 2;
    5700  break;
    5701  }
    5702 
    5703  // carriage return (0x0d)
    5704  case '\r':
    5705  {
    5706  result[pos + 1] = 'r';
    5707  pos += 2;
    5708  break;
    5709  }
    5710 
    5711  // horizontal tab (0x09)
    5712  case '\t':
    5713  {
    5714  result[pos + 1] = 't';
    5715  pos += 2;
    5716  break;
    5717  }
    5718 
    5719  default:
    5720  {
    5721  if (c >= 0x00 and c <= 0x1f)
    5722  {
    5723  // convert a number 0..15 to its hex representation (0..f)
    5724  auto hexify = [](const char v) -> char
    5725  {
    5726  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    5727  };
    5728 
    5729  // print character c as \uxxxx
    5730  for (const char m :
    5731  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    5732  })
    5733  {
    5734  result[++pos] = m;
    5735  }
    5736 
    5737  ++pos;
    5738  }
    5739  else
    5740  {
    5741  // all other characters are added as-is
    5742  result[pos++] = c;
    5743  }
    5744  break;
    5745  }
    5746  }
    5747  }
    5748 
    5749  return result;
    5750  }
    5751 
    5769  void dump(std::ostream& o,
    5770  const bool pretty_print,
    5771  const unsigned int indent_step,
    5772  const unsigned int current_indent = 0) const
    5773  {
    5774  // variable to hold indentation for recursive calls
    5775  unsigned int new_indent = current_indent;
    5776 
    5777  switch (m_type)
    5778  {
    5779  case value_t::object:
    5780  {
    5781  assert(m_value.object != nullptr);
    5782 
    5783  if (m_value.object->empty())
    5784  {
    5785  o << "{}";
    5786  return;
    5787  }
    5788 
    5789  o << "{";
    5790 
    5791  // increase indentation
    5792  if (pretty_print)
    5793  {
    5794  new_indent += indent_step;
    5795  o << "\n";
    5796  }
    5797 
    5798  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    5799  {
    5800  if (i != m_value.object->cbegin())
    5801  {
    5802  o << (pretty_print ? ",\n" : ",");
    5803  }
    5804  o << string_t(new_indent, ' ') << "\""
    5805  << escape_string(i->first) << "\":"
    5806  << (pretty_print ? " " : "");
    5807  i->second.dump(o, pretty_print, indent_step, new_indent);
    5808  }
    5809 
    5810  // decrease indentation
    5811  if (pretty_print)
    5812  {
    5813  new_indent -= indent_step;
    5814  o << "\n";
    5815  }
    5816 
    5817  o << string_t(new_indent, ' ') + "}";
    5818  return;
    5819  }
    5820 
    5821  case value_t::array:
    5822  {
    5823  assert(m_value.array != nullptr);
    5824 
    5825  if (m_value.array->empty())
    5826  {
    5827  o << "[]";
    5828  return;
    5829  }
    5830 
    5831  o << "[";
    5832 
    5833  // increase indentation
    5834  if (pretty_print)
    5835  {
    5836  new_indent += indent_step;
    5837  o << "\n";
    5838  }
    5839 
    5840  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    5841  {
    5842  if (i != m_value.array->cbegin())
    5843  {
    5844  o << (pretty_print ? ",\n" : ",");
    5845  }
    5846  o << string_t(new_indent, ' ');
    5847  i->dump(o, pretty_print, indent_step, new_indent);
    5848  }
    5849 
    5850  // decrease indentation
    5851  if (pretty_print)
    5852  {
    5853  new_indent -= indent_step;
    5854  o << "\n";
    5855  }
    5856 
    5857  o << string_t(new_indent, ' ') << "]";
    5858  return;
    5859  }
    5860 
    5861  case value_t::string:
    5862  {
    5863  assert(m_value.string != nullptr);
    5864  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    5865  return;
    5866  }
    5867 
    5868  case value_t::boolean:
    5869  {
    5870  o << (m_value.boolean ? "true" : "false");
    5871  return;
    5872  }
    5873 
    5874  case value_t::number_integer:
    5875  {
    5876  o << m_value.number_integer;
    5877  return;
    5878  }
    5879 
    5880  case value_t::number_unsigned:
    5881  {
    5882  o << m_value.number_unsigned;
    5883  return;
    5884  }
    5885 
    5886  case value_t::number_float:
    5887  {
    5888  // If the number is an integer then output as a fixed with with
    5889  // precision 1 to output "0.0", "1.0" etc as expected for some
    5890  // round trip tests otherwise 15 digits of precision allows
    5891  // round-trip IEEE 754 string->double->string; to be safe, we
    5892  // read this value from
    5893  // std::numeric_limits<number_float_t>::digits10
    5894  if (std::fmod(m_value.number_float, 1) == 0)
    5895  {
    5896  o << std::fixed << std::setprecision(1);
    5897  }
    5898  else
    5899  {
    5900  // std::defaultfloat not supported in gcc version < 5
    5901  o.unsetf(std::ios_base::floatfield);
    5902  o << std::setprecision(std::numeric_limits<double>::digits10);
    5903  }
    5904  o << m_value.number_float;
    5905  return;
    5906  }
    5907 
    5908  case value_t::discarded:
    5909  {
    5910  o << "<discarded>";
    5911  return;
    5912  }
    5913 
    5914  case value_t::null:
    5915  {
    5916  o << "null";
    5917  return;
    5918  }
    5919  }
    5920  }
    5921 
    5922  private:
    5924  // member variables //
    5926 
    5928  value_t m_type = value_t::null;
    5929 
    5931  json_value m_value = {};
    5932 
    5933 
    5934  private:
    5936  // iterators //
    5938 
    5948  class primitive_iterator_t
    5949  {
    5950  public:
    5952  void set_begin()
    5953  {
    5954  m_it = begin_value;
    5955  }
    5956 
    5958  void set_end()
    5959  {
    5960  m_it = end_value;
    5961  }
    5962 
    5964  bool is_begin() const
    5965  {
    5966  return (m_it == begin_value);
    5967  }
    5968 
    5970  bool is_end() const
    5971  {
    5972  return (m_it == end_value);
    5973  }
    5974 
    5976  operator difference_type& ()
    5977  {
    5978  return m_it;
    5979  }
    5980 
    5982  operator difference_type () const
    5983  {
    5984  return m_it;
    5985  }
    5986 
    5987  private:
    5988  static constexpr difference_type begin_value = 0;
    5989  static constexpr difference_type end_value = begin_value + 1;
    5990 
    5992  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    5993  };
    5994 
    6002  struct internal_iterator
    6003  {
    6005  typename object_t::iterator object_iterator;
    6007  typename array_t::iterator array_iterator;
    6009  primitive_iterator_t primitive_iterator;
    6010 
    6012  internal_iterator()
    6013  : object_iterator(), array_iterator(), primitive_iterator()
    6014  {}
    6015  };
    6016 
    6018  template<typename IteratorType>
    6019  class iteration_proxy
    6020  {
    6021  private:
    6023  class iteration_proxy_internal
    6024  {
    6025  private:
    6027  IteratorType anchor;
    6029  size_t array_index = 0;
    6030 
    6031  public:
    6032  iteration_proxy_internal(IteratorType it)
    6033  : anchor(it)
    6034  {}
    6035 
    6037  iteration_proxy_internal& operator*()
    6038  {
    6039  return *this;
    6040  }
    6041 
    6043  iteration_proxy_internal& operator++()
    6044  {
    6045  ++anchor;
    6046  ++array_index;
    6047 
    6048  return *this;
    6049  }
    6050 
    6052  bool operator!= (const iteration_proxy_internal& o) const
    6053  {
    6054  return anchor != o.anchor;
    6055  }
    6056 
    6058  typename basic_json::string_t key() const
    6059  {
    6060  assert(anchor.m_object != nullptr);
    6061 
    6062  switch (anchor.m_object->type())
    6063  {
    6064  // use integer array index as key
    6065  case value_t::array:
    6066  {
    6067  return std::to_string(array_index);
    6068  }
    6069 
    6070  // use key from the object
    6071  case value_t::object:
    6072  {
    6073  return anchor.key();
    6074  }
    6075 
    6076  // use an empty key for all primitive types
    6077  default:
    6078  {
    6079  return "";
    6080  }
    6081  }
    6082  }
    6083 
    6085  typename IteratorType::reference value() const
    6086  {
    6087  return anchor.value();
    6088  }
    6089  };
    6090 
    6092  typename IteratorType::reference container;
    6093 
    6094  public:
    6096  iteration_proxy(typename IteratorType::reference cont)
    6097  : container(cont)
    6098  {}
    6099 
    6101  iteration_proxy_internal begin()
    6102  {
    6103  return iteration_proxy_internal(container.begin());
    6104  }
    6105 
    6107  iteration_proxy_internal end()
    6108  {
    6109  return iteration_proxy_internal(container.end());
    6110  }
    6111  };
    6112 
    6113  public:
    6127  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6128  {
    6130  friend class basic_json;
    6131 
    6132  public:
    6142  using iterator_category = std::bidirectional_iterator_tag;
    6143 
    6145  const_iterator() = default;
    6146 
    6148  const_iterator(pointer object) : m_object(object)
    6149  {
    6150  assert(m_object != nullptr);
    6151 
    6152  switch (m_object->m_type)
    6153  {
    6155  {
    6156  m_it.object_iterator = typename object_t::iterator();
    6157  break;
    6158  }
    6159 
    6161  {
    6162  m_it.array_iterator = typename array_t::iterator();
    6163  break;
    6164  }
    6165 
    6166  default:
    6167  {
    6168  m_it.primitive_iterator = primitive_iterator_t();
    6169  break;
    6170  }
    6171  }
    6172  }
    6173 
    6175  const_iterator(const iterator& other) : m_object(other.m_object)
    6176  {
    6177  assert(m_object != nullptr);
    6178 
    6179  switch (m_object->m_type)
    6180  {
    6182  {
    6183  m_it.object_iterator = other.m_it.object_iterator;
    6184  break;
    6185  }
    6186 
    6188  {
    6189  m_it.array_iterator = other.m_it.array_iterator;
    6190  break;
    6191  }
    6192 
    6193  default:
    6194  {
    6195  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6196  break;
    6197  }
    6198  }
    6199  }
    6200 
    6202  const_iterator(const const_iterator& other) noexcept
    6203  : m_object(other.m_object), m_it(other.m_it)
    6204  {}
    6205 
    6208  std::is_nothrow_move_constructible<pointer>::value and
    6209  std::is_nothrow_move_assignable<pointer>::value and
    6210  std::is_nothrow_move_constructible<internal_iterator>::value and
    6211  std::is_nothrow_move_assignable<internal_iterator>::value
    6212  )
    6213  {
    6214  std::swap(m_object, other.m_object);
    6215  std::swap(m_it, other.m_it);
    6216  return *this;
    6217  }
    6218 
    6219  private:
    6221  void set_begin()
    6222  {
    6223  assert(m_object != nullptr);
    6224 
    6225  switch (m_object->m_type)
    6226  {
    6228  {
    6229  assert(m_object->m_value.object != nullptr);
    6230  m_it.object_iterator = m_object->m_value.object->begin();
    6231  break;
    6232  }
    6233 
    6235  {
    6236  assert(m_object->m_value.array != nullptr);
    6237  m_it.array_iterator = m_object->m_value.array->begin();
    6238  break;
    6239  }
    6240 
    6242  {
    6243  // set to end so begin()==end() is true: null is empty
    6244  m_it.primitive_iterator.set_end();
    6245  break;
    6246  }
    6247 
    6248  default:
    6249  {
    6250  m_it.primitive_iterator.set_begin();
    6251  break;
    6252  }
    6253  }
    6254  }
    6255 
    6257  void set_end()
    6258  {
    6259  assert(m_object != nullptr);
    6260 
    6261  switch (m_object->m_type)
    6262  {
    6264  {
    6265  assert(m_object->m_value.object != nullptr);
    6266  m_it.object_iterator = m_object->m_value.object->end();
    6267  break;
    6268  }
    6269 
    6271  {
    6272  assert(m_object->m_value.array != nullptr);
    6273  m_it.array_iterator = m_object->m_value.array->end();
    6274  break;
    6275  }
    6276 
    6277  default:
    6278  {
    6279  m_it.primitive_iterator.set_end();
    6280  break;
    6281  }
    6282  }
    6283  }
    6284 
    6285  public:
    6288  {
    6289  assert(m_object != nullptr);
    6290 
    6291  switch (m_object->m_type)
    6292  {
    6294  {
    6295  assert(m_object->m_value.object);
    6296  assert(m_it.object_iterator != m_object->m_value.object->end());
    6297  return m_it.object_iterator->second;
    6298  }
    6299 
    6301  {
    6302  assert(m_object->m_value.array);
    6303  assert(m_it.array_iterator != m_object->m_value.array->end());
    6304  return *m_it.array_iterator;
    6305  }
    6306 
    6308  {
    6309  throw std::out_of_range("cannot get value");
    6310  }
    6311 
    6312  default:
    6313  {
    6314  if (m_it.primitive_iterator.is_begin())
    6315  {
    6316  return *m_object;
    6317  }
    6318  else
    6319  {
    6320  throw std::out_of_range("cannot get value");
    6321  }
    6322  }
    6323  }
    6324  }
    6325 
    6328  {
    6329  assert(m_object != nullptr);
    6330 
    6331  switch (m_object->m_type)
    6332  {
    6334  {
    6335  assert(m_object->m_value.object);
    6336  assert(m_it.object_iterator != m_object->m_value.object->end());
    6337  return &(m_it.object_iterator->second);
    6338  }
    6339 
    6341  {
    6342  assert(m_object->m_value.array);
    6343  assert(m_it.array_iterator != m_object->m_value.array->end());
    6344  return &*m_it.array_iterator;
    6345  }
    6346 
    6347  default:
    6348  {
    6349  if (m_it.primitive_iterator.is_begin())
    6350  {
    6351  return m_object;
    6352  }
    6353  else
    6354  {
    6355  throw std::out_of_range("cannot get value");
    6356  }
    6357  }
    6358  }
    6359  }
    6360 
    6363  {
    6364  auto result = *this;
    6365  ++(*this);
    6366  return result;
    6367  }
    6368 
    6371  {
    6372  assert(m_object != nullptr);
    6373 
    6374  switch (m_object->m_type)
    6375  {
    6377  {
    6378  ++m_it.object_iterator;
    6379  break;
    6380  }
    6381 
    6383  {
    6384  ++m_it.array_iterator;
    6385  break;
    6386  }
    6387 
    6388  default:
    6389  {
    6390  ++m_it.primitive_iterator;
    6391  break;
    6392  }
    6393  }
    6394 
    6395  return *this;
    6396  }
    6397 
    6400  {
    6401  auto result = *this;
    6402  --(*this);
    6403  return result;
    6404  }
    6405 
    6408  {
    6409  assert(m_object != nullptr);
    6410 
    6411  switch (m_object->m_type)
    6412  {
    6414  {
    6415  --m_it.object_iterator;
    6416  break;
    6417  }
    6418 
    6420  {
    6421  --m_it.array_iterator;
    6422  break;
    6423  }
    6424 
    6425  default:
    6426  {
    6427  --m_it.primitive_iterator;
    6428  break;
    6429  }
    6430  }
    6431 
    6432  return *this;
    6433  }
    6434 
    6436  bool operator==(const const_iterator& other) const
    6437  {
    6438  // if objects are not the same, the comparison is undefined
    6439  if (m_object != other.m_object)
    6440  {
    6441  throw std::domain_error("cannot compare iterators of different containers");
    6442  }
    6443 
    6444  assert(m_object != nullptr);
    6445 
    6446  switch (m_object->m_type)
    6447  {
    6449  {
    6450  return (m_it.object_iterator == other.m_it.object_iterator);
    6451  }
    6452 
    6454  {
    6455  return (m_it.array_iterator == other.m_it.array_iterator);
    6456  }
    6457 
    6458  default:
    6459  {
    6460  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6461  }
    6462  }
    6463  }
    6464 
    6466  bool operator!=(const const_iterator& other) const
    6467  {
    6468  return not operator==(other);
    6469  }
    6470 
    6472  bool operator<(const const_iterator& other) const
    6473  {
    6474  // if objects are not the same, the comparison is undefined
    6475  if (m_object != other.m_object)
    6476  {
    6477  throw std::domain_error("cannot compare iterators of different containers");
    6478  }
    6479 
    6480  assert(m_object != nullptr);
    6481 
    6482  switch (m_object->m_type)
    6483  {
    6485  {
    6486  throw std::domain_error("cannot compare order of object iterators");
    6487  }
    6488 
    6490  {
    6491  return (m_it.array_iterator < other.m_it.array_iterator);
    6492  }
    6493 
    6494  default:
    6495  {
    6496  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6497  }
    6498  }
    6499  }
    6500 
    6502  bool operator<=(const const_iterator& other) const
    6503  {
    6504  return not other.operator < (*this);
    6505  }
    6506 
    6508  bool operator>(const const_iterator& other) const
    6509  {
    6510  return not operator<=(other);
    6511  }
    6512 
    6514  bool operator>=(const const_iterator& other) const
    6515  {
    6516  return not operator<(other);
    6517  }
    6518 
    6521  {
    6522  assert(m_object != nullptr);
    6523 
    6524  switch (m_object->m_type)
    6525  {
    6527  {
    6528  throw std::domain_error("cannot use offsets with object iterators");
    6529  }
    6530 
    6532  {
    6533  m_it.array_iterator += i;
    6534  break;
    6535  }
    6536 
    6537  default:
    6538  {
    6539  m_it.primitive_iterator += i;
    6540  break;
    6541  }
    6542  }
    6543 
    6544  return *this;
    6545  }
    6546 
    6549  {
    6550  return operator+=(-i);
    6551  }
    6552 
    6555  {
    6556  auto result = *this;
    6557  result += i;
    6558  return result;
    6559  }
    6560 
    6563  {
    6564  auto result = *this;
    6565  result -= i;
    6566  return result;
    6567  }
    6568 
    6571  {
    6572  assert(m_object != nullptr);
    6573 
    6574  switch (m_object->m_type)
    6575  {
    6577  {
    6578  throw std::domain_error("cannot use offsets with object iterators");
    6579  }
    6580 
    6582  {
    6583  return m_it.array_iterator - other.m_it.array_iterator;
    6584  }
    6585 
    6586  default:
    6587  {
    6588  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6589  }
    6590  }
    6591  }
    6592 
    6595  {
    6596  assert(m_object != nullptr);
    6597 
    6598  switch (m_object->m_type)
    6599  {
    6601  {
    6602  throw std::domain_error("cannot use operator[] for object iterators");
    6603  }
    6604 
    6606  {
    6607  return *(m_it.array_iterator + n);
    6608  }
    6609 
    6611  {
    6612  throw std::out_of_range("cannot get value");
    6613  }
    6614 
    6615  default:
    6616  {
    6617  if (m_it.primitive_iterator == -n)
    6618  {
    6619  return *m_object;
    6620  }
    6621  else
    6622  {
    6623  throw std::out_of_range("cannot get value");
    6624  }
    6625  }
    6626  }
    6627  }
    6628 
    6630  typename object_t::key_type key() const
    6631  {
    6632  assert(m_object != nullptr);
    6633 
    6634  if (m_object->is_object())
    6635  {
    6636  return m_it.object_iterator->first;
    6637  }
    6638  else
    6639  {
    6640  throw std::domain_error("cannot use key() for non-object iterators");
    6641  }
    6642  }
    6643 
    6646  {
    6647  return operator*();
    6648  }
    6649 
    6650  private:
    6652  pointer m_object = nullptr;
    6654  internal_iterator m_it = internal_iterator();
    6655  };
    6656 
    6669  class iterator : public const_iterator
    6670  {
    6671  public:
    6673  using pointer = typename basic_json::pointer;
    6675 
    6677  iterator() = default;
    6678 
    6680  iterator(pointer object) noexcept
    6681  : base_iterator(object)
    6682  {}
    6683 
    6685  iterator(const iterator& other) noexcept
    6686  : base_iterator(other)
    6687  {}
    6688 
    6690  iterator& operator=(iterator other) noexcept(
    6691  std::is_nothrow_move_constructible<pointer>::value and
    6692  std::is_nothrow_move_assignable<pointer>::value and
    6693  std::is_nothrow_move_constructible<internal_iterator>::value and
    6694  std::is_nothrow_move_assignable<internal_iterator>::value
    6695  )
    6696  {
    6697  base_iterator::operator=(other);
    6698  return *this;
    6699  }
    6700 
    6703  {
    6704  return const_cast<reference>(base_iterator::operator*());
    6705  }
    6706 
    6709  {
    6710  return const_cast<pointer>(base_iterator::operator->());
    6711  }
    6712 
    6715  {
    6716  iterator result = *this;
    6717  base_iterator::operator++();
    6718  return result;
    6719  }
    6720 
    6723  {
    6724  base_iterator::operator++();
    6725  return *this;
    6726  }
    6727 
    6730  {
    6731  iterator result = *this;
    6732  base_iterator::operator--();
    6733  return result;
    6734  }
    6735 
    6738  {
    6739  base_iterator::operator--();
    6740  return *this;
    6741  }
    6742 
    6745  {
    6746  base_iterator::operator+=(i);
    6747  return *this;
    6748  }
    6749 
    6752  {
    6753  base_iterator::operator-=(i);
    6754  return *this;
    6755  }
    6756 
    6759  {
    6760  auto result = *this;
    6761  result += i;
    6762  return result;
    6763  }
    6764 
    6767  {
    6768  auto result = *this;
    6769  result -= i;
    6770  return result;
    6771  }
    6772 
    6773  difference_type operator-(const iterator& other) const
    6774  {
    6775  return base_iterator::operator-(other);
    6776  }
    6777 
    6780  {
    6781  return const_cast<reference>(base_iterator::operator[](n));
    6782  }
    6783 
    6786  {
    6787  return const_cast<reference>(base_iterator::value());
    6788  }
    6789  };
    6790 
    6808  template<typename Base>
    6809  class json_reverse_iterator : public std::reverse_iterator<Base>
    6810  {
    6811  public:
    6813  using base_iterator = std::reverse_iterator<Base>;
    6815  using reference = typename Base::reference;
    6816 
    6818  json_reverse_iterator(const typename base_iterator::iterator_type& it)
    6819  : base_iterator(it)
    6820  {}
    6821 
    6824  : base_iterator(it)
    6825  {}
    6826 
    6829  {
    6830  return base_iterator::operator++(1);
    6831  }
    6832 
    6835  {
    6836  base_iterator::operator++();
    6837  return *this;
    6838  }
    6839 
    6842  {
    6843  return base_iterator::operator--(1);
    6844  }
    6845 
    6848  {
    6849  base_iterator::operator--();
    6850  return *this;
    6851  }
    6852 
    6855  {
    6856  base_iterator::operator+=(i);
    6857  return *this;
    6858  }
    6859 
    6862  {
    6863  auto result = *this;
    6864  result += i;
    6865  return result;
    6866  }
    6867 
    6870  {
    6871  auto result = *this;
    6872  result -= i;
    6873  return result;
    6874  }
    6875 
    6878  {
    6879  return this->base() - other.base();
    6880  }
    6881 
    6884  {
    6885  return *(this->operator+(n));
    6886  }
    6887 
    6889  typename object_t::key_type key() const
    6890  {
    6891  auto it = --this->base();
    6892  return it.key();
    6893  }
    6894 
    6897  {
    6898  auto it = --this->base();
    6899  return it.operator * ();
    6900  }
    6901  };
    6902 
    6903 
    6904  private:
    6906  // lexer and parser //
    6908 
    6916  class lexer
    6917  {
    6918  public:
    6920  enum class token_type
    6921  {
    6922  uninitialized,
    6923  literal_true,
    6924  literal_false,
    6925  literal_null,
    6926  value_string,
    6927  value_number,
    6928  begin_array,
    6929  begin_object,
    6930  end_array,
    6931  end_object,
    6932  name_separator,
    6933  value_separator,
    6934  parse_error,
    6935  end_of_input
    6936  };
    6937 
    6939  using lexer_char_t = unsigned char;
    6940 
    6942  explicit lexer(const string_t& s) noexcept
    6943  : m_stream(nullptr), m_buffer(s)
    6944  {
    6945  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    6946  assert(m_content != nullptr);
    6947  m_start = m_cursor = m_content;
    6948  m_limit = m_content + s.size();
    6949  }
    6950 
    6952  explicit lexer(std::istream* s) noexcept
    6953  : m_stream(s), m_buffer()
    6954  {
    6955  assert(m_stream != nullptr);
    6956  getline(*m_stream, m_buffer);
    6957  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    6958  assert(m_content != nullptr);
    6959  m_start = m_cursor = m_content;
    6960  m_limit = m_content + m_buffer.size();
    6961  }
    6962 
    6964  lexer() = default;
    6965 
    6966  // switch off unwanted functions
    6967  lexer(const lexer&) = delete;
    6968  lexer operator=(const lexer&) = delete;
    6969 
    6985  static string_t to_unicode(const std::size_t codepoint1,
    6986  const std::size_t codepoint2 = 0)
    6987  {
    6988  string_t result;
    6989 
    6990  // calculate the codepoint from the given code points
    6991  std::size_t codepoint = codepoint1;
    6992 
    6993  // check if codepoint1 is a high surrogate
    6994  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    6995  {
    6996  // check if codepoint2 is a low surrogate
    6997  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    6998  {
    6999  codepoint =
    7000  // high surrogate occupies the most significant 22 bits
    7001  (codepoint1 << 10)
    7002  // low surrogate occupies the least significant 15 bits
    7003  + codepoint2
    7004  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7005  // in the result so we have to subtract with:
    7006  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7007  - 0x35FDC00;
    7008  }
    7009  else
    7010  {
    7011  throw std::invalid_argument("missing or wrong low surrogate");
    7012  }
    7013  }
    7014 
    7015  if (codepoint < 0x80)
    7016  {
    7017  // 1-byte characters: 0xxxxxxx (ASCII)
    7018  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7019  }
    7020  else if (codepoint <= 0x7ff)
    7021  {
    7022  // 2-byte characters: 110xxxxx 10xxxxxx
    7023  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7024  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7025  }
    7026  else if (codepoint <= 0xffff)
    7027  {
    7028  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7029  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7030  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7031  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7032  }
    7033  else if (codepoint <= 0x10ffff)
    7034  {
    7035  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7036  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7037  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7038  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7039  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7040  }
    7041  else
    7042  {
    7043  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7044  }
    7045 
    7046  return result;
    7047  }
    7048 
    7050  static std::string token_type_name(token_type t)
    7051  {
    7052  switch (t)
    7053  {
    7054  case token_type::uninitialized:
    7055  return "<uninitialized>";
    7056  case token_type::literal_true:
    7057  return "true literal";
    7058  case token_type::literal_false:
    7059  return "false literal";
    7060  case token_type::literal_null:
    7061  return "null literal";
    7062  case token_type::value_string:
    7063  return "string literal";
    7064  case token_type::value_number:
    7065  return "number literal";
    7066  case token_type::begin_array:
    7067  return "'['";
    7068  case token_type::begin_object:
    7069  return "'{'";
    7070  case token_type::end_array:
    7071  return "']'";
    7072  case token_type::end_object:
    7073  return "'}'";
    7074  case token_type::name_separator:
    7075  return "':'";
    7076  case token_type::value_separator:
    7077  return "','";
    7078  case token_type::parse_error:
    7079  return "<parse error>";
    7080  case token_type::end_of_input:
    7081  return "end of input";
    7082  default:
    7083  {
    7084  // catch non-enum values
    7085  return "unknown token"; // LCOV_EXCL_LINE
    7086  }
    7087  }
    7088  }
    7089 
    7100  token_type scan() noexcept
    7101  {
    7102  // pointer for backtracking information
    7103  m_marker = nullptr;
    7104 
    7105  // remember the begin of the token
    7106  m_start = m_cursor;
    7107  assert(m_start != nullptr);
    7108 
    7109 
    7110  {
    7111  lexer_char_t yych;
    7112  unsigned int yyaccept = 0;
    7113  static const unsigned char yybm[] =
    7114  {
    7115  0, 0, 0, 0, 0, 0, 0, 0,
    7116  0, 32, 32, 0, 0, 32, 0, 0,
    7117  64, 64, 64, 64, 64, 64, 64, 64,
    7118  64, 64, 64, 64, 64, 64, 64, 64,
    7119  96, 64, 0, 64, 64, 64, 64, 64,
    7120  64, 64, 64, 64, 64, 64, 64, 64,
    7121  192, 192, 192, 192, 192, 192, 192, 192,
    7122  192, 192, 64, 64, 64, 64, 64, 64,
    7123  64, 64, 64, 64, 64, 64, 64, 64,
    7124  64, 64, 64, 64, 64, 64, 64, 64,
    7125  64, 64, 64, 64, 64, 64, 64, 64,
    7126  64, 64, 64, 64, 0, 64, 64, 64,
    7127  64, 64, 64, 64, 64, 64, 64, 64,
    7128  64, 64, 64, 64, 64, 64, 64, 64,
    7129  64, 64, 64, 64, 64, 64, 64, 64,
    7130  64, 64, 64, 64, 64, 64, 64, 64,
    7131  64, 64, 64, 64, 64, 64, 64, 64,
    7132  64, 64, 64, 64, 64, 64, 64, 64,
    7133  64, 64, 64, 64, 64, 64, 64, 64,
    7134  64, 64, 64, 64, 64, 64, 64, 64,
    7135  64, 64, 64, 64, 64, 64, 64, 64,
    7136  64, 64, 64, 64, 64, 64, 64, 64,
    7137  64, 64, 64, 64, 64, 64, 64, 64,
    7138  64, 64, 64, 64, 64, 64, 64, 64,
    7139  64, 64, 64, 64, 64, 64, 64, 64,
    7140  64, 64, 64, 64, 64, 64, 64, 64,
    7141  64, 64, 64, 64, 64, 64, 64, 64,
    7142  64, 64, 64, 64, 64, 64, 64, 64,
    7143  64, 64, 64, 64, 64, 64, 64, 64,
    7144  64, 64, 64, 64, 64, 64, 64, 64,
    7145  64, 64, 64, 64, 64, 64, 64, 64,
    7146  64, 64, 64, 64, 64, 64, 64, 64,
    7147  };
    7148  if ((m_limit - m_cursor) < 5)
    7149  {
    7150  yyfill(); // LCOV_EXCL_LINE;
    7151  }
    7152  yych = *m_cursor;
    7153  if (yych <= ':')
    7154  {
    7155  if (yych <= ' ')
    7156  {
    7157  if (yych <= '\n')
    7158  {
    7159  if (yych <= 0x00)
    7160  {
    7161  goto basic_json_parser_28;
    7162  }
    7163  if (yych <= 0x08)
    7164  {
    7165  goto basic_json_parser_30;
    7166  }
    7167  if (yych >= '\n')
    7168  {
    7169  goto basic_json_parser_4;
    7170  }
    7171  }
    7172  else
    7173  {
    7174  if (yych == '\r')
    7175  {
    7176  goto basic_json_parser_2;
    7177  }
    7178  if (yych <= 0x1F)
    7179  {
    7180  goto basic_json_parser_30;
    7181  }
    7182  }
    7183  }
    7184  else
    7185  {
    7186  if (yych <= ',')
    7187  {
    7188  if (yych == '"')
    7189  {
    7190  goto basic_json_parser_27;
    7191  }
    7192  if (yych <= '+')
    7193  {
    7194  goto basic_json_parser_30;
    7195  }
    7196  goto basic_json_parser_16;
    7197  }
    7198  else
    7199  {
    7200  if (yych <= '/')
    7201  {
    7202  if (yych <= '-')
    7203  {
    7204  goto basic_json_parser_23;
    7205  }
    7206  goto basic_json_parser_30;
    7207  }
    7208  else
    7209  {
    7210  if (yych <= '0')
    7211  {
    7212  goto basic_json_parser_24;
    7213  }
    7214  if (yych <= '9')
    7215  {
    7216  goto basic_json_parser_26;
    7217  }
    7218  goto basic_json_parser_18;
    7219  }
    7220  }
    7221  }
    7222  }
    7223  else
    7224  {
    7225  if (yych <= 'n')
    7226  {
    7227  if (yych <= ']')
    7228  {
    7229  if (yych == '[')
    7230  {
    7231  goto basic_json_parser_8;
    7232  }
    7233  if (yych <= '\\')
    7234  {
    7235  goto basic_json_parser_30;
    7236  }
    7237  goto basic_json_parser_10;
    7238  }
    7239  else
    7240  {
    7241  if (yych == 'f')
    7242  {
    7243  goto basic_json_parser_22;
    7244  }
    7245  if (yych <= 'm')
    7246  {
    7247  goto basic_json_parser_30;
    7248  }
    7249  goto basic_json_parser_20;
    7250  }
    7251  }
    7252  else
    7253  {
    7254  if (yych <= '{')
    7255  {
    7256  if (yych == 't')
    7257  {
    7258  goto basic_json_parser_21;
    7259  }
    7260  if (yych <= 'z')
    7261  {
    7262  goto basic_json_parser_30;
    7263  }
    7264  goto basic_json_parser_12;
    7265  }
    7266  else
    7267  {
    7268  if (yych <= '}')
    7269  {
    7270  if (yych <= '|')
    7271  {
    7272  goto basic_json_parser_30;
    7273  }
    7274  goto basic_json_parser_14;
    7275  }
    7276  else
    7277  {
    7278  if (yych == 0xEF)
    7279  {
    7280  goto basic_json_parser_6;
    7281  }
    7282  goto basic_json_parser_30;
    7283  }
    7284  }
    7285  }
    7286  }
    7287 basic_json_parser_2:
    7288  ++m_cursor;
    7289  yych = *m_cursor;
    7290  goto basic_json_parser_5;
    7291 basic_json_parser_3:
    7292  {
    7293  return scan();
    7294  }
    7295 basic_json_parser_4:
    7296  ++m_cursor;
    7297  if (m_limit <= m_cursor)
    7298  {
    7299  yyfill(); // LCOV_EXCL_LINE;
    7300  }
    7301  yych = *m_cursor;
    7302 basic_json_parser_5:
    7303  if (yybm[0 + yych] & 32)
    7304  {
    7305  goto basic_json_parser_4;
    7306  }
    7307  goto basic_json_parser_3;
    7308 basic_json_parser_6:
    7309  yyaccept = 0;
    7310  yych = *(m_marker = ++m_cursor);
    7311  if (yych == 0xBB)
    7312  {
    7313  goto basic_json_parser_64;
    7314  }
    7315 basic_json_parser_7:
    7316  {
    7317  return token_type::parse_error;
    7318  }
    7319 basic_json_parser_8:
    7320  ++m_cursor;
    7321  {
    7322  return token_type::begin_array;
    7323  }
    7324 basic_json_parser_10:
    7325  ++m_cursor;
    7326  {
    7327  return token_type::end_array;
    7328  }
    7329 basic_json_parser_12:
    7330  ++m_cursor;
    7331  {
    7332  return token_type::begin_object;
    7333  }
    7334 basic_json_parser_14:
    7335  ++m_cursor;
    7336  {
    7337  return token_type::end_object;
    7338  }
    7339 basic_json_parser_16:
    7340  ++m_cursor;
    7341  {
    7342  return token_type::value_separator;
    7343  }
    7344 basic_json_parser_18:
    7345  ++m_cursor;
    7346  {
    7347  return token_type::name_separator;
    7348  }
    7349 basic_json_parser_20:
    7350  yyaccept = 0;
    7351  yych = *(m_marker = ++m_cursor);
    7352  if (yych == 'u')
    7353  {
    7354  goto basic_json_parser_60;
    7355  }
    7356  goto basic_json_parser_7;
    7357 basic_json_parser_21:
    7358  yyaccept = 0;
    7359  yych = *(m_marker = ++m_cursor);
    7360  if (yych == 'r')
    7361  {
    7362  goto basic_json_parser_56;
    7363  }
    7364  goto basic_json_parser_7;
    7365 basic_json_parser_22:
    7366  yyaccept = 0;
    7367  yych = *(m_marker = ++m_cursor);
    7368  if (yych == 'a')
    7369  {
    7370  goto basic_json_parser_51;
    7371  }
    7372  goto basic_json_parser_7;
    7373 basic_json_parser_23:
    7374  yych = *++m_cursor;
    7375  if (yych <= '/')
    7376  {
    7377  goto basic_json_parser_7;
    7378  }
    7379  if (yych <= '0')
    7380  {
    7381  goto basic_json_parser_50;
    7382  }
    7383  if (yych <= '9')
    7384  {
    7385  goto basic_json_parser_41;
    7386  }
    7387  goto basic_json_parser_7;
    7388 basic_json_parser_24:
    7389  yyaccept = 1;
    7390  yych = *(m_marker = ++m_cursor);
    7391  if (yych <= 'D')
    7392  {
    7393  if (yych == '.')
    7394  {
    7395  goto basic_json_parser_43;
    7396  }
    7397  }
    7398  else
    7399  {
    7400  if (yych <= 'E')
    7401  {
    7402  goto basic_json_parser_44;
    7403  }
    7404  if (yych == 'e')
    7405  {
    7406  goto basic_json_parser_44;
    7407  }
    7408  }
    7409 basic_json_parser_25:
    7410  {
    7411  return token_type::value_number;
    7412  }
    7413 basic_json_parser_26:
    7414  yyaccept = 1;
    7415  yych = *(m_marker = ++m_cursor);
    7416  goto basic_json_parser_42;
    7417 basic_json_parser_27:
    7418  yyaccept = 0;
    7419  yych = *(m_marker = ++m_cursor);
    7420  if (yych <= 0x0F)
    7421  {
    7422  goto basic_json_parser_7;
    7423  }
    7424  goto basic_json_parser_32;
    7425 basic_json_parser_28:
    7426  ++m_cursor;
    7427  {
    7428  return token_type::end_of_input;
    7429  }
    7430 basic_json_parser_30:
    7431  yych = *++m_cursor;
    7432  goto basic_json_parser_7;
    7433 basic_json_parser_31:
    7434  ++m_cursor;
    7435  if (m_limit <= m_cursor)
    7436  {
    7437  yyfill(); // LCOV_EXCL_LINE;
    7438  }
    7439  yych = *m_cursor;
    7440 basic_json_parser_32:
    7441  if (yybm[0 + yych] & 64)
    7442  {
    7443  goto basic_json_parser_31;
    7444  }
    7445  if (yych <= 0x0F)
    7446  {
    7447  goto basic_json_parser_33;
    7448  }
    7449  if (yych <= '"')
    7450  {
    7451  goto basic_json_parser_35;
    7452  }
    7453  goto basic_json_parser_34;
    7454 basic_json_parser_33:
    7455  m_cursor = m_marker;
    7456  if (yyaccept == 0)
    7457  {
    7458  goto basic_json_parser_7;
    7459  }
    7460  else
    7461  {
    7462  goto basic_json_parser_25;
    7463  }
    7464 basic_json_parser_34:
    7465  ++m_cursor;
    7466  if (m_limit <= m_cursor)
    7467  {
    7468  yyfill(); // LCOV_EXCL_LINE;
    7469  }
    7470  yych = *m_cursor;
    7471  if (yych <= 'e')
    7472  {
    7473  if (yych <= '/')
    7474  {
    7475  if (yych == '"')
    7476  {
    7477  goto basic_json_parser_31;
    7478  }
    7479  if (yych <= '.')
    7480  {
    7481  goto basic_json_parser_33;
    7482  }
    7483  goto basic_json_parser_31;
    7484  }
    7485  else
    7486  {
    7487  if (yych <= '\\')
    7488  {
    7489  if (yych <= '[')
    7490  {
    7491  goto basic_json_parser_33;
    7492  }
    7493  goto basic_json_parser_31;
    7494  }
    7495  else
    7496  {
    7497  if (yych == 'b')
    7498  {
    7499  goto basic_json_parser_31;
    7500  }
    7501  goto basic_json_parser_33;
    7502  }
    7503  }
    7504  }
    7505  else
    7506  {
    7507  if (yych <= 'q')
    7508  {
    7509  if (yych <= 'f')
    7510  {
    7511  goto basic_json_parser_31;
    7512  }
    7513  if (yych == 'n')
    7514  {
    7515  goto basic_json_parser_31;
    7516  }
    7517  goto basic_json_parser_33;
    7518  }
    7519  else
    7520  {
    7521  if (yych <= 's')
    7522  {
    7523  if (yych <= 'r')
    7524  {
    7525  goto basic_json_parser_31;
    7526  }
    7527  goto basic_json_parser_33;
    7528  }
    7529  else
    7530  {
    7531  if (yych <= 't')
    7532  {
    7533  goto basic_json_parser_31;
    7534  }
    7535  if (yych <= 'u')
    7536  {
    7537  goto basic_json_parser_37;
    7538  }
    7539  goto basic_json_parser_33;
    7540  }
    7541  }
    7542  }
    7543 basic_json_parser_35:
    7544  ++m_cursor;
    7545  {
    7546  return token_type::value_string;
    7547  }
    7548 basic_json_parser_37:
    7549  ++m_cursor;
    7550  if (m_limit <= m_cursor)
    7551  {
    7552  yyfill(); // LCOV_EXCL_LINE;
    7553  }
    7554  yych = *m_cursor;
    7555  if (yych <= '@')
    7556  {
    7557  if (yych <= '/')
    7558  {
    7559  goto basic_json_parser_33;
    7560  }
    7561  if (yych >= ':')
    7562  {
    7563  goto basic_json_parser_33;
    7564  }
    7565  }
    7566  else
    7567  {
    7568  if (yych <= 'F')
    7569  {
    7570  goto basic_json_parser_38;
    7571  }
    7572  if (yych <= '`')
    7573  {
    7574  goto basic_json_parser_33;
    7575  }
    7576  if (yych >= 'g')
    7577  {
    7578  goto basic_json_parser_33;
    7579  }
    7580  }
    7581 basic_json_parser_38:
    7582  ++m_cursor;
    7583  if (m_limit <= m_cursor)
    7584  {
    7585  yyfill(); // LCOV_EXCL_LINE;
    7586  }
    7587  yych = *m_cursor;
    7588  if (yych <= '@')
    7589  {
    7590  if (yych <= '/')
    7591  {
    7592  goto basic_json_parser_33;
    7593  }
    7594  if (yych >= ':')
    7595  {
    7596  goto basic_json_parser_33;
    7597  }
    7598  }
    7599  else
    7600  {
    7601  if (yych <= 'F')
    7602  {
    7603  goto basic_json_parser_39;
    7604  }
    7605  if (yych <= '`')
    7606  {
    7607  goto basic_json_parser_33;
    7608  }
    7609  if (yych >= 'g')
    7610  {
    7611  goto basic_json_parser_33;
    7612  }
    7613  }
    7614 basic_json_parser_39:
    7615  ++m_cursor;
    7616  if (m_limit <= m_cursor)
    7617  {
    7618  yyfill(); // LCOV_EXCL_LINE;
    7619  }
    7620  yych = *m_cursor;
    7621  if (yych <= '@')
    7622  {
    7623  if (yych <= '/')
    7624  {
    7625  goto basic_json_parser_33;
    7626  }
    7627  if (yych >= ':')
    7628  {
    7629  goto basic_json_parser_33;
    7630  }
    7631  }
    7632  else
    7633  {
    7634  if (yych <= 'F')
    7635  {
    7636  goto basic_json_parser_40;
    7637  }
    7638  if (yych <= '`')
    7639  {
    7640  goto basic_json_parser_33;
    7641  }
    7642  if (yych >= 'g')
    7643  {
    7644  goto basic_json_parser_33;
    7645  }
    7646  }
    7647 basic_json_parser_40:
    7648  ++m_cursor;
    7649  if (m_limit <= m_cursor)
    7650  {
    7651  yyfill(); // LCOV_EXCL_LINE;
    7652  }
    7653  yych = *m_cursor;
    7654  if (yych <= '@')
    7655  {
    7656  if (yych <= '/')
    7657  {
    7658  goto basic_json_parser_33;
    7659  }
    7660  if (yych <= '9')
    7661  {
    7662  goto basic_json_parser_31;
    7663  }
    7664  goto basic_json_parser_33;
    7665  }
    7666  else
    7667  {
    7668  if (yych <= 'F')
    7669  {
    7670  goto basic_json_parser_31;
    7671  }
    7672  if (yych <= '`')
    7673  {
    7674  goto basic_json_parser_33;
    7675  }
    7676  if (yych <= 'f')
    7677  {
    7678  goto basic_json_parser_31;
    7679  }
    7680  goto basic_json_parser_33;
    7681  }
    7682 basic_json_parser_41:
    7683  yyaccept = 1;
    7684  m_marker = ++m_cursor;
    7685  if ((m_limit - m_cursor) < 3)
    7686  {
    7687  yyfill(); // LCOV_EXCL_LINE;
    7688  }
    7689  yych = *m_cursor;
    7690 basic_json_parser_42:
    7691  if (yybm[0 + yych] & 128)
    7692  {
    7693  goto basic_json_parser_41;
    7694  }
    7695  if (yych <= 'D')
    7696  {
    7697  if (yych != '.')
    7698  {
    7699  goto basic_json_parser_25;
    7700  }
    7701  }
    7702  else
    7703  {
    7704  if (yych <= 'E')
    7705  {
    7706  goto basic_json_parser_44;
    7707  }
    7708  if (yych == 'e')
    7709  {
    7710  goto basic_json_parser_44;
    7711  }
    7712  goto basic_json_parser_25;
    7713  }
    7714 basic_json_parser_43:
    7715  yych = *++m_cursor;
    7716  if (yych <= '/')
    7717  {
    7718  goto basic_json_parser_33;
    7719  }
    7720  if (yych <= '9')
    7721  {
    7722  goto basic_json_parser_48;
    7723  }
    7724  goto basic_json_parser_33;
    7725 basic_json_parser_44:
    7726  yych = *++m_cursor;
    7727  if (yych <= ',')
    7728  {
    7729  if (yych != '+')
    7730  {
    7731  goto basic_json_parser_33;
    7732  }
    7733  }
    7734  else
    7735  {
    7736  if (yych <= '-')
    7737  {
    7738  goto basic_json_parser_45;
    7739  }
    7740  if (yych <= '/')
    7741  {
    7742  goto basic_json_parser_33;
    7743  }
    7744  if (yych <= '9')
    7745  {
    7746  goto basic_json_parser_46;
    7747  }
    7748  goto basic_json_parser_33;
    7749  }
    7750 basic_json_parser_45:
    7751  yych = *++m_cursor;
    7752  if (yych <= '/')
    7753  {
    7754  goto basic_json_parser_33;
    7755  }
    7756  if (yych >= ':')
    7757  {
    7758  goto basic_json_parser_33;
    7759  }
    7760 basic_json_parser_46:
    7761  ++m_cursor;
    7762  if (m_limit <= m_cursor)
    7763  {
    7764  yyfill(); // LCOV_EXCL_LINE;
    7765  }
    7766  yych = *m_cursor;
    7767  if (yych <= '/')
    7768  {
    7769  goto basic_json_parser_25;
    7770  }
    7771  if (yych <= '9')
    7772  {
    7773  goto basic_json_parser_46;
    7774  }
    7775  goto basic_json_parser_25;
    7776 basic_json_parser_48:
    7777  yyaccept = 1;
    7778  m_marker = ++m_cursor;
    7779  if ((m_limit - m_cursor) < 3)
    7780  {
    7781  yyfill(); // LCOV_EXCL_LINE;
    7782  }
    7783  yych = *m_cursor;
    7784  if (yych <= 'D')
    7785  {
    7786  if (yych <= '/')
    7787  {
    7788  goto basic_json_parser_25;
    7789  }
    7790  if (yych <= '9')
    7791  {
    7792  goto basic_json_parser_48;
    7793  }
    7794  goto basic_json_parser_25;
    7795  }
    7796  else
    7797  {
    7798  if (yych <= 'E')
    7799  {
    7800  goto basic_json_parser_44;
    7801  }
    7802  if (yych == 'e')
    7803  {
    7804  goto basic_json_parser_44;
    7805  }
    7806  goto basic_json_parser_25;
    7807  }
    7808 basic_json_parser_50:
    7809  yyaccept = 1;
    7810  yych = *(m_marker = ++m_cursor);
    7811  if (yych <= 'D')
    7812  {
    7813  if (yych == '.')
    7814  {
    7815  goto basic_json_parser_43;
    7816  }
    7817  goto basic_json_parser_25;
    7818  }
    7819  else
    7820  {
    7821  if (yych <= 'E')
    7822  {
    7823  goto basic_json_parser_44;
    7824  }
    7825  if (yych == 'e')
    7826  {
    7827  goto basic_json_parser_44;
    7828  }
    7829  goto basic_json_parser_25;
    7830  }
    7831 basic_json_parser_51:
    7832  yych = *++m_cursor;
    7833  if (yych != 'l')
    7834  {
    7835  goto basic_json_parser_33;
    7836  }
    7837  yych = *++m_cursor;
    7838  if (yych != 's')
    7839  {
    7840  goto basic_json_parser_33;
    7841  }
    7842  yych = *++m_cursor;
    7843  if (yych != 'e')
    7844  {
    7845  goto basic_json_parser_33;
    7846  }
    7847  ++m_cursor;
    7848  {
    7849  return token_type::literal_false;
    7850  }
    7851 basic_json_parser_56:
    7852  yych = *++m_cursor;
    7853  if (yych != 'u')
    7854  {
    7855  goto basic_json_parser_33;
    7856  }
    7857  yych = *++m_cursor;
    7858  if (yych != 'e')
    7859  {
    7860  goto basic_json_parser_33;
    7861  }
    7862  ++m_cursor;
    7863  {
    7864  return token_type::literal_true;
    7865  }
    7866 basic_json_parser_60:
    7867  yych = *++m_cursor;
    7868  if (yych != 'l')
    7869  {
    7870  goto basic_json_parser_33;
    7871  }
    7872  yych = *++m_cursor;
    7873  if (yych != 'l')
    7874  {
    7875  goto basic_json_parser_33;
    7876  }
    7877  ++m_cursor;
    7878  {
    7879  return token_type::literal_null;
    7880  }
    7881 basic_json_parser_64:
    7882  yych = *++m_cursor;
    7883  if (yych != 0xBF)
    7884  {
    7885  goto basic_json_parser_33;
    7886  }
    7887  ++m_cursor;
    7888  {
    7889  return scan();
    7890  }
    7891  }
    7892 
    7893 
    7894  }
    7895 
    7897  void yyfill() noexcept
    7898  {
    7899  if (m_stream == nullptr or not * m_stream)
    7900  {
    7901  return;
    7902  }
    7903 
    7904  const ssize_t offset_start = m_start - m_content;
    7905  const ssize_t offset_marker = m_marker - m_start;
    7906  const ssize_t offset_cursor = m_cursor - m_start;
    7907 
    7908  m_buffer.erase(0, static_cast<size_t>(offset_start));
    7909  std::string line;
    7910  assert(m_stream != nullptr);
    7911  std::getline(*m_stream, line);
    7912  m_buffer += "\n" + line; // add line with newline symbol
    7913 
    7914  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7915  assert(m_content != nullptr);
    7916  m_start = m_content;
    7917  m_marker = m_start + offset_marker;
    7918  m_cursor = m_start + offset_cursor;
    7919  m_limit = m_start + m_buffer.size() - 1;
    7920  }
    7921 
    7923  string_t get_token() const noexcept
    7924  {
    7925  assert(m_start != nullptr);
    7926  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7927  static_cast<size_t>(m_cursor - m_start));
    7928  }
    7929 
    7951  string_t get_string() const
    7952  {
    7953  string_t result;
    7954  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    7955 
    7956  // iterate the result between the quotes
    7957  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    7958  {
    7959  // process escaped characters
    7960  if (*i == '\\')
    7961  {
    7962  // read next character
    7963  ++i;
    7964 
    7965  switch (*i)
    7966  {
    7967  // the default escapes
    7968  case 't':
    7969  {
    7970  result += "\t";
    7971  break;
    7972  }
    7973  case 'b':
    7974  {
    7975  result += "\b";
    7976  break;
    7977  }
    7978  case 'f':
    7979  {
    7980  result += "\f";
    7981  break;
    7982  }
    7983  case 'n':
    7984  {
    7985  result += "\n";
    7986  break;
    7987  }
    7988  case 'r':
    7989  {
    7990  result += "\r";
    7991  break;
    7992  }
    7993  case '\\':
    7994  {
    7995  result += "\\";
    7996  break;
    7997  }
    7998  case '/':
    7999  {
    8000  result += "/";
    8001  break;
    8002  }
    8003  case '"':
    8004  {
    8005  result += "\"";
    8006  break;
    8007  }
    8008 
    8009  // unicode
    8010  case 'u':
    8011  {
    8012  // get code xxxx from uxxxx
    8013  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8014  4).c_str(), nullptr, 16);
    8015 
    8016  // check if codepoint is a high surrogate
    8017  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8018  {
    8019  // make sure there is a subsequent unicode
    8020  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8021  {
    8022  throw std::invalid_argument("missing low surrogate");
    8023  }
    8024 
    8025  // get code yyyy from uxxxx\uyyyy
    8026  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8027  (i + 7), 4).c_str(), nullptr, 16);
    8028  result += to_unicode(codepoint, codepoint2);
    8029  // skip the next 10 characters (xxxx\uyyyy)
    8030  i += 10;
    8031  }
    8032  else
    8033  {
    8034  // add unicode character(s)
    8035  result += to_unicode(codepoint);
    8036  // skip the next four characters (xxxx)
    8037  i += 4;
    8038  }
    8039  break;
    8040  }
    8041  }
    8042  }
    8043  else
    8044  {
    8045  // all other characters are just copied to the end of the
    8046  // string
    8047  result.append(1, static_cast<typename string_t::value_type>(*i));
    8048  }
    8049  }
    8050 
    8051  return result;
    8052  }
    8053 
    8074  long double str_to_float_t(long double* /* type */, char** endptr) const
    8075  {
    8076  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8077  }
    8078 
    8093  double str_to_float_t(double* /* type */, char** endptr) const
    8094  {
    8095  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8096  }
    8097 
    8112  float str_to_float_t(float* /* type */, char** endptr) const
    8113  {
    8114  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8115  }
    8116 
    8129  template <typename T_A, typename T_B>
    8130  bool attempt_cast(T_A source, T_B& dest) const
    8131  {
    8132  dest = static_cast<T_B>(source);
    8133  return (source == static_cast<T_A>(dest));
    8134  }
    8135 
    8174  void get_number(basic_json& result) const
    8175  {
    8176  typename string_t::value_type* endptr;
    8177  assert(m_start != nullptr);
    8178  errno = 0;
    8179 
    8180  // attempt to parse it as an integer - first checking for a
    8181  // negative number
    8182  if (*reinterpret_cast<typename string_t::const_pointer>(m_start) != '-')
    8183  {
    8184  // positive, parse with strtoull and attempt cast to
    8185  // number_unsigned_t
    8186  if (attempt_cast(std::strtoull(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
    8187  10), result.m_value.number_unsigned))
    8188  {
    8189  result.m_type = value_t::number_unsigned;
    8190  }
    8191  else
    8192  {
    8193  // cast failed due to overflow - store as float
    8194  result.m_type = value_t::number_float;
    8195  }
    8196  }
    8197  else
    8198  {
    8199  // Negative, parse with strtoll and attempt cast to
    8200  // number_integer_t
    8201  if (attempt_cast(std::strtoll(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
    8202  10), result.m_value.number_unsigned))
    8203  {
    8204  result.m_type = value_t::number_integer;
    8205  }
    8206  else
    8207  {
    8208  // cast failed due to overflow - store as float
    8209  result.m_type = value_t::number_float;
    8210  }
    8211  }
    8212 
    8213  // check the end of the number was reached and no range error
    8214  // occurred
    8215  if (reinterpret_cast<lexer_char_t*>(endptr) != m_cursor || errno == ERANGE)
    8216  {
    8217  result.m_type = value_t::number_float;
    8218  }
    8219 
    8220  if (result.m_type == value_t::number_float)
    8221  {
    8222  // either the number won't fit in an integer (range error from
    8223  // strtoull/strtoll or overflow on cast) or there was something
    8224  // else after the number, which could be an exponent
    8225 
    8226  // parse with strtod
    8227  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), &endptr);
    8228 
    8229  // anything after the number is an error
    8230  if (reinterpret_cast<lexer_char_t*>(endptr) != m_cursor)
    8231  {
    8232  throw std::invalid_argument(std::string("parse error - ") + get_token() + " is not a number");
    8233  }
    8234  }
    8235  }
    8236 
    8237  private:
    8239  std::istream* m_stream = nullptr;
    8241  string_t m_buffer;
    8243  const lexer_char_t* m_content = nullptr;
    8245  const lexer_char_t* m_start = nullptr;
    8247  const lexer_char_t* m_marker = nullptr;
    8249  const lexer_char_t* m_cursor = nullptr;
    8251  const lexer_char_t* m_limit = nullptr;
    8252  };
    8253 
    8259  class parser
    8260  {
    8261  public:
    8263  parser(const string_t& s, parser_callback_t cb = nullptr)
    8264  : callback(cb), m_lexer(s)
    8265  {
    8266  // read first token
    8267  get_token();
    8268  }
    8269 
    8271  parser(std::istream& _is, parser_callback_t cb = nullptr)
    8272  : callback(cb), m_lexer(&_is)
    8273  {
    8274  // read first token
    8275  get_token();
    8276  }
    8277 
    8279  basic_json parse()
    8280  {
    8281  basic_json result = parse_internal(true);
    8282 
    8283  expect(lexer::token_type::end_of_input);
    8284 
    8285  // return parser result and replace it with null in case the
    8286  // top-level value was discarded by the callback function
    8287  return result.is_discarded() ? basic_json() : result;
    8288  }
    8289 
    8290  private:
    8292  basic_json parse_internal(bool keep)
    8293  {
    8294  auto result = basic_json(value_t::discarded);
    8295 
    8296  switch (last_token)
    8297  {
    8298  case lexer::token_type::begin_object:
    8299  {
    8300  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    8301  {
    8302  // explicitly set result to object to cope with {}
    8303  result.m_type = value_t::object;
    8304  result.m_value = json_value(value_t::object);
    8305  }
    8306 
    8307  // read next token
    8308  get_token();
    8309 
    8310  // closing } -> we are done
    8311  if (last_token == lexer::token_type::end_object)
    8312  {
    8313  get_token();
    8314  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8315  {
    8316  result = basic_json(value_t::discarded);
    8317  }
    8318  return result;
    8319  }
    8320 
    8321  // no comma is expected here
    8322  unexpect(lexer::token_type::value_separator);
    8323 
    8324  // otherwise: parse key-value pairs
    8325  do
    8326  {
    8327  // ugly, but could be fixed with loop reorganization
    8328  if (last_token == lexer::token_type::value_separator)
    8329  {
    8330  get_token();
    8331  }
    8332 
    8333  // store key
    8334  expect(lexer::token_type::value_string);
    8335  const auto key = m_lexer.get_string();
    8336 
    8337  bool keep_tag = false;
    8338  if (keep)
    8339  {
    8340  if (callback)
    8341  {
    8342  basic_json k(key);
    8343  keep_tag = callback(depth, parse_event_t::key, k);
    8344  }
    8345  else
    8346  {
    8347  keep_tag = true;
    8348  }
    8349  }
    8350 
    8351  // parse separator (:)
    8352  get_token();
    8353  expect(lexer::token_type::name_separator);
    8354 
    8355  // parse and add value
    8356  get_token();
    8357  auto value = parse_internal(keep);
    8358  if (keep and keep_tag and not value.is_discarded())
    8359  {
    8360  result[key] = std::move(value);
    8361  }
    8362  }
    8363  while (last_token == lexer::token_type::value_separator);
    8364 
    8365  // closing }
    8366  expect(lexer::token_type::end_object);
    8367  get_token();
    8368  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8369  {
    8370  result = basic_json(value_t::discarded);
    8371  }
    8372 
    8373  return result;
    8374  }
    8375 
    8376  case lexer::token_type::begin_array:
    8377  {
    8378  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    8379  {
    8380  // explicitly set result to object to cope with []
    8381  result.m_type = value_t::array;
    8382  result.m_value = json_value(value_t::array);
    8383  }
    8384 
    8385  // read next token
    8386  get_token();
    8387 
    8388  // closing ] -> we are done
    8389  if (last_token == lexer::token_type::end_array)
    8390  {
    8391  get_token();
    8392  if (callback and not callback(--depth, parse_event_t::array_end, result))
    8393  {
    8394  result = basic_json(value_t::discarded);
    8395  }
    8396  return result;
    8397  }
    8398 
    8399  // no comma is expected here
    8400  unexpect(lexer::token_type::value_separator);
    8401 
    8402  // otherwise: parse values
    8403  do
    8404  {
    8405  // ugly, but could be fixed with loop reorganization
    8406  if (last_token == lexer::token_type::value_separator)
    8407  {
    8408  get_token();
    8409  }
    8410 
    8411  // parse value
    8412  auto value = parse_internal(keep);
    8413  if (keep and not value.is_discarded())
    8414  {
    8415  result.push_back(std::move(value));
    8416  }
    8417  }
    8418  while (last_token == lexer::token_type::value_separator);
    8419 
    8420  // closing ]
    8421  expect(lexer::token_type::end_array);
    8422  get_token();
    8423  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    8424  {
    8425  result = basic_json(value_t::discarded);
    8426  }
    8427 
    8428  return result;
    8429  }
    8430 
    8431  case lexer::token_type::literal_null:
    8432  {
    8433  get_token();
    8434  result.m_type = value_t::null;
    8435  break;
    8436  }
    8437 
    8438  case lexer::token_type::value_string:
    8439  {
    8440  const auto s = m_lexer.get_string();
    8441  get_token();
    8442  result = basic_json(s);
    8443  break;
    8444  }
    8445 
    8446  case lexer::token_type::literal_true:
    8447  {
    8448  get_token();
    8449  result.m_type = value_t::boolean;
    8450  result.m_value = true;
    8451  break;
    8452  }
    8453 
    8454  case lexer::token_type::literal_false:
    8455  {
    8456  get_token();
    8457  result.m_type = value_t::boolean;
    8458  result.m_value = false;
    8459  break;
    8460  }
    8461 
    8462  case lexer::token_type::value_number:
    8463  {
    8464  m_lexer.get_number(result);
    8465  get_token();
    8466  break;
    8467  }
    8468 
    8469  default:
    8470  {
    8471  // the last token was unexpected
    8472  unexpect(last_token);
    8473  }
    8474  }
    8475 
    8476  if (keep and callback and not callback(depth, parse_event_t::value, result))
    8477  {
    8478  result = basic_json(value_t::discarded);
    8479  }
    8480  return result;
    8481  }
    8482 
    8484  typename lexer::token_type get_token()
    8485  {
    8486  last_token = m_lexer.scan();
    8487  return last_token;
    8488  }
    8489 
    8490  void expect(typename lexer::token_type t) const
    8491  {
    8492  if (t != last_token)
    8493  {
    8494  std::string error_msg = "parse error - unexpected ";
    8495  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8496  lexer::token_type_name(last_token));
    8497  error_msg += "; expected " + lexer::token_type_name(t);
    8498  throw std::invalid_argument(error_msg);
    8499  }
    8500  }
    8501 
    8502  void unexpect(typename lexer::token_type t) const
    8503  {
    8504  if (t == last_token)
    8505  {
    8506  std::string error_msg = "parse error - unexpected ";
    8507  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8508  lexer::token_type_name(last_token));
    8509  throw std::invalid_argument(error_msg);
    8510  }
    8511  }
    8512 
    8513  private:
    8515  int depth = 0;
    8517  parser_callback_t callback;
    8519  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    8521  lexer m_lexer;
    8522  };
    8523 };
    8524 
    8525 
    8527 // presets //
    8529 
    8539 }
    8540 
    8541 
    8543 // nonmember functions //
    8545 
    8546 // specialization of std::swap, and std::hash
    8547 namespace std
    8548 {
    8554 template <>
    8555 inline void swap(nlohmann::json& j1,
    8556  nlohmann::json& j2) noexcept(
    8557  is_nothrow_move_constructible<nlohmann::json>::value and
    8558  is_nothrow_move_assignable<nlohmann::json>::value
    8559  )
    8560 {
    8561  j1.swap(j2);
    8562 }
    8563 
    8565 template <>
    8566 struct hash<nlohmann::json>
    8567 {
    8573  std::size_t operator()(const nlohmann::json& j) const
    8574  {
    8575  // a naive hashing via the string representation
    8576  const auto& h = hash<nlohmann::json::string_t>();
    8577  return h(j.dump());
    8578  }
    8579 };
    8580 }
    8581 
    8594 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    8595 {
    8596  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    8597 }
    8598 
    8599 // restore GCC/clang diagnostic settings
    8600 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    8601  #pragma GCC diagnostic pop
    8602 #endif
    8603 
    8604 #endif
    bool is_null() const noexcept
    return whether value is null
    Definition: json.hpp:2148
    +
    1 
    38 #ifndef NLOHMANN_JSON_HPP
    39 #define NLOHMANN_JSON_HPP
    40 
    41 #include <algorithm>
    42 #include <array>
    43 #include <cassert>
    44 #include <ciso646>
    45 #include <cmath>
    46 #include <cstddef>
    47 #include <cstdio>
    48 #include <cstdlib>
    49 #include <functional>
    50 #include <initializer_list>
    51 #include <iomanip>
    52 #include <iostream>
    53 #include <iterator>
    54 #include <limits>
    55 #include <map>
    56 #include <memory>
    57 #include <sstream>
    58 #include <stdexcept>
    59 #include <string>
    60 #include <type_traits>
    61 #include <utility>
    62 #include <vector>
    63 
    64 // enable ssize_t on MinGW
    65 #ifdef __GNUC__
    66  #ifdef __MINGW32__
    67  #include <sys/types.h>
    68  #endif
    69 #endif
    70 
    71 // disable float-equal warnings on GCC/clang
    72 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    73  #pragma GCC diagnostic push
    74  #pragma GCC diagnostic ignored "-Wfloat-equal"
    75 #endif
    76 
    77 // enable ssize_t for MSVC
    78 #ifdef _MSC_VER
    79  #include <basetsd.h>
    80  using ssize_t = SSIZE_T;
    81 #endif
    82 
    88 namespace nlohmann
    89 {
    90 
    91 
    96 namespace
    97 {
    102 template<typename T>
    103 struct has_mapped_type
    104 {
    105  private:
    106  template<typename C> static char test(typename C::mapped_type*);
    107  template<typename C> static char (&test(...))[2];
    108  public:
    109  static constexpr bool value = sizeof(test<T>(0)) == 1;
    110 };
    111 
    112 }
    113 
    184 template <
    185  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    186  template<typename U, typename... Args> class ArrayType = std::vector,
    187  class StringType = std::string,
    188  class BooleanType = bool,
    189  class NumberIntegerType = int64_t,
    190  class NumberUnsignedType = uint64_t,
    191  class NumberFloatType = double,
    192  template<typename U> class AllocatorType = std::allocator
    193  >
    195 {
    196  private:
    198  using basic_json_t = basic_json<ObjectType,
    199  ArrayType,
    200  StringType,
    201  BooleanType,
    202  NumberIntegerType,
    203  NumberUnsignedType,
    204  NumberFloatType,
    205  AllocatorType>;
    206 
    207  public:
    208 
    210  // container types //
    212 
    215 
    218 
    222  using const_reference = const value_type&;
    223 
    225  using difference_type = std::ptrdiff_t;
    227  using size_type = std::size_t;
    228 
    230  using allocator_type = AllocatorType<basic_json>;
    231 
    233  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    235  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    236 
    237  // forward declaration
    238  template<typename Base> class json_reverse_iterator;
    239 
    241  class iterator;
    243  class const_iterator;
    248 
    250 
    251 
    256  {
    257  return allocator_type();
    258  }
    259 
    260 
    262  // JSON value data types //
    264 
    267 
    350  using object_t = ObjectType<StringType,
    351  basic_json,
    352  std::less<StringType>,
    353  AllocatorType<std::pair<const StringType,
    354  basic_json>>>;
    355 
    400  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    401 
    447  using string_t = StringType;
    448 
    473  using boolean_t = BooleanType;
    474 
    544  using number_integer_t = NumberIntegerType;
    545 
    616  using number_unsigned_t = NumberUnsignedType;
    617 
    684  using number_float_t = NumberFloatType;
    685 
    687 
    688 
    690  // JSON type enumeration //
    692 
    703  enum class value_t : uint8_t
    704  {
    705  null,
    706  object,
    707  array,
    708  string,
    709  boolean,
    710  number_integer,
    711  number_unsigned,
    712  number_float,
    713  discarded
    714  };
    715 
    716 
    717  private:
    719  template<typename T, typename... Args>
    720  static T* create(Args&& ... args)
    721  {
    722  AllocatorType<T> alloc;
    723  auto deleter = [&](T * object)
    724  {
    725  alloc.deallocate(object, 1);
    726  };
    727  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    728  alloc.construct(object.get(), std::forward<Args>(args)...);
    729  return object.release();
    730  }
    731 
    733  // JSON value storage //
    735 
    743  union json_value
    744  {
    746  object_t* object;
    748  array_t* array;
    750  string_t* string;
    752  boolean_t boolean;
    754  number_integer_t number_integer;
    756  number_unsigned_t number_unsigned;
    758  number_float_t number_float;
    759 
    761  json_value() noexcept = default;
    763  json_value(boolean_t v) noexcept : boolean(v) {}
    765  json_value(number_integer_t v) noexcept : number_integer(v) {}
    767  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    769  json_value(number_float_t v) noexcept : number_float(v) {}
    771  json_value(value_t t)
    772  {
    773  switch (t)
    774  {
    775  case value_t::object:
    776  {
    777  object = create<object_t>();
    778  break;
    779  }
    780 
    781  case value_t::array:
    782  {
    783  array = create<array_t>();
    784  break;
    785  }
    786 
    787  case value_t::string:
    788  {
    789  string = create<string_t>("");
    790  break;
    791  }
    792 
    793  case value_t::boolean:
    794  {
    795  boolean = boolean_t(false);
    796  break;
    797  }
    798 
    799  case value_t::number_integer:
    800  {
    801  number_integer = number_integer_t(0);
    802  break;
    803  }
    804 
    805  case value_t::number_unsigned:
    806  {
    807  number_unsigned = number_unsigned_t(0);
    808  break;
    809  }
    810 
    811  case value_t::number_float:
    812  {
    813  number_float = number_float_t(0.0);
    814  break;
    815  }
    816 
    817  default:
    818  {
    819  break;
    820  }
    821  }
    822  }
    823 
    825  json_value(const string_t& value)
    826  {
    827  string = create<string_t>(value);
    828  }
    829 
    831  json_value(const object_t& value)
    832  {
    833  object = create<object_t>(value);
    834  }
    835 
    837  json_value(const array_t& value)
    838  {
    839  array = create<array_t>(value);
    840  }
    841  };
    842 
    843 
    844  public:
    846  // JSON parser callback //
    848 
    857  enum class parse_event_t : uint8_t
    858  {
    860  object_start,
    862  object_end,
    864  array_start,
    866  array_end,
    868  key,
    870  value
    871  };
    872 
    922  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    923 
    924 
    926  // constructors //
    928 
    931 
    972  : m_type(value_type), m_value(value_type)
    973  {}
    974 
    994  basic_json() noexcept = default;
    995 
    1015  basic_json(std::nullptr_t) noexcept
    1016  : basic_json(value_t::null)
    1017  {}
    1018 
    1038  basic_json(const object_t& val)
    1039  : m_type(value_t::object), m_value(val)
    1040  {}
    1041 
    1065  template <class CompatibleObjectType, typename
    1066  std::enable_if<
    1067  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1068  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    1069  = 0>
    1070  basic_json(const CompatibleObjectType& val)
    1071  : m_type(value_t::object)
    1072  {
    1073  using std::begin;
    1074  using std::end;
    1075  m_value.object = create<object_t>(begin(val), end(val));
    1076  }
    1077 
    1097  basic_json(const array_t& val)
    1098  : m_type(value_t::array), m_value(val)
    1099  {}
    1100 
    1124  template <class CompatibleArrayType, typename
    1125  std::enable_if<
    1126  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1127  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1128  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1129  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1130  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1131  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1132  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1133  = 0>
    1134  basic_json(const CompatibleArrayType& val)
    1135  : m_type(value_t::array)
    1136  {
    1137  using std::begin;
    1138  using std::end;
    1139  m_value.array = create<array_t>(begin(val), end(val));
    1140  }
    1141 
    1163  basic_json(const string_t& val)
    1164  : m_type(value_t::string), m_value(val)
    1165  {}
    1166 
    1187  basic_json(const typename string_t::value_type* val)
    1188  : basic_json(string_t(val))
    1189  {}
    1190 
    1214  template <class CompatibleStringType, typename
    1215  std::enable_if<
    1216  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1217  = 0>
    1218  basic_json(const CompatibleStringType& val)
    1219  : basic_json(string_t(val))
    1220  {}
    1221 
    1237  : m_type(value_t::boolean), m_value(val)
    1238  {}
    1239 
    1265  template<typename T,
    1266  typename std::enable_if<
    1267  not (std::is_same<T, int>::value)
    1268  and std::is_same<T, number_integer_t>::value
    1269  , int>::type
    1270  = 0>
    1272  : m_type(value_t::number_integer), m_value(val)
    1273  {}
    1274 
    1300  basic_json(const int val)
    1301  : m_type(value_t::number_integer),
    1302  m_value(static_cast<number_integer_t>(val))
    1303  {}
    1304 
    1330  template<typename CompatibleNumberIntegerType, typename
    1331  std::enable_if<
    1332  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1333  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1334  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1335  CompatibleNumberIntegerType>::type
    1336  = 0>
    1337  basic_json(const CompatibleNumberIntegerType val) noexcept
    1338  : m_type(value_t::number_integer),
    1339  m_value(static_cast<number_integer_t>(val))
    1340  {}
    1341 
    1359  template<typename T,
    1360  typename std::enable_if<
    1361  not (std::is_same<T, int>::value)
    1362  and std::is_same<T, number_unsigned_t>::value
    1363  , int>::type
    1364  = 0>
    1366  : m_type(value_t::number_unsigned), m_value(val)
    1367  {}
    1368 
    1389  template < typename CompatibleNumberUnsignedType, typename
    1390  std::enable_if <
    1391  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1392  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1393  !std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1394  CompatibleNumberUnsignedType >::type
    1395  = 0 >
    1396  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1397  : m_type(value_t::number_unsigned),
    1398  m_value(static_cast<number_unsigned_t>(val))
    1399  {}
    1400 
    1426  : m_type(value_t::number_float), m_value(val)
    1427  {
    1428  // replace infinity and NAN by null
    1429  if (not std::isfinite(val))
    1430  {
    1431  m_type = value_t::null;
    1432  m_value = json_value();
    1433  }
    1434  }
    1435 
    1466  template<typename CompatibleNumberFloatType, typename = typename
    1467  std::enable_if<
    1468  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1469  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1470  >
    1471  basic_json(const CompatibleNumberFloatType val) noexcept
    1472  : basic_json(number_float_t(val))
    1473  {}
    1474 
    1544  basic_json(std::initializer_list<basic_json> init,
    1545  bool type_deduction = true,
    1546  value_t manual_type = value_t::array)
    1547  {
    1548  // the initializer list could describe an object
    1549  bool is_an_object = true;
    1550 
    1551  // check if each element is an array with two elements whose first
    1552  // element is a string
    1553  for (const auto& element : init)
    1554  {
    1555  if (not element.is_array() or element.size() != 2
    1556  or not element[0].is_string())
    1557  {
    1558  // we found an element that makes it impossible to use the
    1559  // initializer list as object
    1560  is_an_object = false;
    1561  break;
    1562  }
    1563  }
    1564 
    1565  // adjust type if type deduction is not wanted
    1566  if (not type_deduction)
    1567  {
    1568  // if array is wanted, do not create an object though possible
    1569  if (manual_type == value_t::array)
    1570  {
    1571  is_an_object = false;
    1572  }
    1573 
    1574  // if object is wanted but impossible, throw an exception
    1575  if (manual_type == value_t::object and not is_an_object)
    1576  {
    1577  throw std::domain_error("cannot create object from initializer list");
    1578  }
    1579  }
    1580 
    1581  if (is_an_object)
    1582  {
    1583  // the initializer list is a list of pairs -> create object
    1584  m_type = value_t::object;
    1585  m_value = value_t::object;
    1586 
    1587  assert(m_value.object != nullptr);
    1588 
    1589  for (auto& element : init)
    1590  {
    1591  m_value.object->emplace(std::move(*(element[0].m_value.string)), std::move(element[1]));
    1592  }
    1593  }
    1594  else
    1595  {
    1596  // the initializer list describes an array -> create array
    1597  m_type = value_t::array;
    1598  m_value.array = create<array_t>(std::move(init));
    1599  }
    1600  }
    1601 
    1636  static basic_json array(std::initializer_list<basic_json> init =
    1637  std::initializer_list<basic_json>())
    1638  {
    1639  return basic_json(init, false, value_t::array);
    1640  }
    1641 
    1676  static basic_json object(std::initializer_list<basic_json> init =
    1677  std::initializer_list<basic_json>())
    1678  {
    1679  return basic_json(init, false, value_t::object);
    1680  }
    1681 
    1700  basic_json(size_type cnt, const basic_json& val)
    1701  : m_type(value_t::array)
    1702  {
    1703  m_value.array = create<array_t>(cnt, val);
    1704  }
    1705 
    1740  template <class InputIT, typename
    1741  std::enable_if<
    1742  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1743  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1744  , int>::type
    1745  = 0>
    1746  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1747  {
    1748  // make sure iterator fits the current value
    1749  if (first.m_object != last.m_object)
    1750  {
    1751  throw std::domain_error("iterators are not compatible");
    1752  }
    1753 
    1754  // check if iterator range is complete for primitive values
    1755  switch (m_type)
    1756  {
    1757  case value_t::boolean:
    1758  case value_t::number_float:
    1759  case value_t::number_integer:
    1760  case value_t::number_unsigned:
    1761  case value_t::string:
    1762  {
    1763  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1764  {
    1765  throw std::out_of_range("iterators out of range");
    1766  }
    1767  break;
    1768  }
    1769 
    1770  default:
    1771  {
    1772  break;
    1773  }
    1774  }
    1775 
    1776  switch (m_type)
    1777  {
    1778  case value_t::number_integer:
    1779  {
    1780  assert(first.m_object != nullptr);
    1781  m_value.number_integer = first.m_object->m_value.number_integer;
    1782  break;
    1783  }
    1784 
    1785  case value_t::number_unsigned:
    1786  {
    1787  assert(first.m_object != nullptr);
    1788  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1789  break;
    1790  }
    1791 
    1792  case value_t::number_float:
    1793  {
    1794  assert(first.m_object != nullptr);
    1795  m_value.number_float = first.m_object->m_value.number_float;
    1796  break;
    1797  }
    1798 
    1799  case value_t::boolean:
    1800  {
    1801  assert(first.m_object != nullptr);
    1802  m_value.boolean = first.m_object->m_value.boolean;
    1803  break;
    1804  }
    1805 
    1806  case value_t::string:
    1807  {
    1808  assert(first.m_object != nullptr);
    1809  m_value = *first.m_object->m_value.string;
    1810  break;
    1811  }
    1812 
    1813  case value_t::object:
    1814  {
    1815  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1816  break;
    1817  }
    1818 
    1819  case value_t::array:
    1820  {
    1821  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1822  break;
    1823  }
    1824 
    1825  default:
    1826  {
    1827  assert(first.m_object != nullptr);
    1828  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1829  }
    1830  }
    1831  }
    1832 
    1834  // other constructors and destructor //
    1836 
    1857  basic_json(const basic_json& other)
    1858  : m_type(other.m_type)
    1859  {
    1860  switch (m_type)
    1861  {
    1862  case value_t::object:
    1863  {
    1864  assert(other.m_value.object != nullptr);
    1865  m_value = *other.m_value.object;
    1866  break;
    1867  }
    1868 
    1869  case value_t::array:
    1870  {
    1871  assert(other.m_value.array != nullptr);
    1872  m_value = *other.m_value.array;
    1873  break;
    1874  }
    1875 
    1876  case value_t::string:
    1877  {
    1878  assert(other.m_value.string != nullptr);
    1879  m_value = *other.m_value.string;
    1880  break;
    1881  }
    1882 
    1883  case value_t::boolean:
    1884  {
    1885  m_value = other.m_value.boolean;
    1886  break;
    1887  }
    1888 
    1889  case value_t::number_integer:
    1890  {
    1891  m_value = other.m_value.number_integer;
    1892  break;
    1893  }
    1894 
    1895  case value_t::number_unsigned:
    1896  {
    1897  m_value = other.m_value.number_unsigned;
    1898  break;
    1899  }
    1900 
    1901  case value_t::number_float:
    1902  {
    1903  m_value = other.m_value.number_float;
    1904  break;
    1905  }
    1906 
    1907  default:
    1908  {
    1909  break;
    1910  }
    1911  }
    1912  }
    1913 
    1932  basic_json(basic_json&& other) noexcept
    1933  : m_type(std::move(other.m_type)),
    1934  m_value(std::move(other.m_value))
    1935  {
    1936  // invalidate payload
    1937  other.m_type = value_t::null;
    1938  other.m_value = {};
    1939  }
    1940 
    1962  reference& operator=(basic_json other) noexcept (
    1963  std::is_nothrow_move_constructible<value_t>::value and
    1964  std::is_nothrow_move_assignable<value_t>::value and
    1965  std::is_nothrow_move_constructible<json_value>::value and
    1966  std::is_nothrow_move_assignable<json_value>::value
    1967  )
    1968  {
    1969  using std::swap;
    1970  swap(m_type, other.m_type);
    1971  swap(m_value, other.m_value);
    1972  return *this;
    1973  }
    1974 
    1989  {
    1990  switch (m_type)
    1991  {
    1992  case value_t::object:
    1993  {
    1994  AllocatorType<object_t> alloc;
    1995  alloc.destroy(m_value.object);
    1996  alloc.deallocate(m_value.object, 1);
    1997  break;
    1998  }
    1999 
    2000  case value_t::array:
    2001  {
    2002  AllocatorType<array_t> alloc;
    2003  alloc.destroy(m_value.array);
    2004  alloc.deallocate(m_value.array, 1);
    2005  break;
    2006  }
    2007 
    2008  case value_t::string:
    2009  {
    2010  AllocatorType<string_t> alloc;
    2011  alloc.destroy(m_value.string);
    2012  alloc.deallocate(m_value.string, 1);
    2013  break;
    2014  }
    2015 
    2016  default:
    2017  {
    2018  // all other types need no specific destructor
    2019  break;
    2020  }
    2021  }
    2022  }
    2023 
    2025 
    2026  public:
    2028  // object inspection //
    2030 
    2033 
    2057  string_t dump(const int indent = -1) const
    2058  {
    2059  std::stringstream ss;
    2060 
    2061  if (indent >= 0)
    2062  {
    2063  dump(ss, true, static_cast<unsigned int>(indent));
    2064  }
    2065  else
    2066  {
    2067  dump(ss, false, 0);
    2068  }
    2069 
    2070  return ss.str();
    2071  }
    2072 
    2088  value_t type() const noexcept
    2089  {
    2090  return m_type;
    2091  }
    2092 
    2109  bool is_primitive() const noexcept
    2110  {
    2111  return is_null() or is_string() or is_boolean() or is_number();
    2112  }
    2113 
    2129  bool is_structured() const noexcept
    2130  {
    2131  return is_array() or is_object();
    2132  }
    2133 
    2148  bool is_null() const noexcept
    2149  {
    2150  return m_type == value_t::null;
    2151  }
    2152 
    2167  bool is_boolean() const noexcept
    2168  {
    2169  return m_type == value_t::boolean;
    2170  }
    2171 
    2194  bool is_number() const noexcept
    2195  {
    2196  return is_number_integer() or is_number_float();
    2197  }
    2198 
    2220  bool is_number_integer() const noexcept
    2221  {
    2222  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2223  }
    2224 
    2245  bool is_number_unsigned() const noexcept
    2246  {
    2247  return m_type == value_t::number_unsigned;
    2248  }
    2249 
    2270  bool is_number_float() const noexcept
    2271  {
    2272  return m_type == value_t::number_float;
    2273  }
    2274 
    2289  bool is_object() const noexcept
    2290  {
    2291  return m_type == value_t::object;
    2292  }
    2293 
    2308  bool is_array() const noexcept
    2309  {
    2310  return m_type == value_t::array;
    2311  }
    2312 
    2327  bool is_string() const noexcept
    2328  {
    2329  return m_type == value_t::string;
    2330  }
    2331 
    2351  bool is_discarded() const noexcept
    2352  {
    2353  return m_type == value_t::discarded;
    2354  }
    2355 
    2371  operator value_t() const noexcept
    2372  {
    2373  return m_type;
    2374  }
    2375 
    2377 
    2378  private:
    2380  // value access //
    2382 
    2384  template <class T, typename
    2385  std::enable_if<
    2386  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2387  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2388  , int>::type = 0>
    2389  T get_impl(T*) const
    2390  {
    2391  if (is_object())
    2392  {
    2393  assert(m_value.object != nullptr);
    2394  return T(m_value.object->begin(), m_value.object->end());
    2395  }
    2396  else
    2397  {
    2398  throw std::domain_error("type must be object, but is " + type_name());
    2399  }
    2400  }
    2401 
    2403  object_t get_impl(object_t*) const
    2404  {
    2405  if (is_object())
    2406  {
    2407  assert(m_value.object != nullptr);
    2408  return *(m_value.object);
    2409  }
    2410  else
    2411  {
    2412  throw std::domain_error("type must be object, but is " + type_name());
    2413  }
    2414  }
    2415 
    2417  template <class T, typename
    2418  std::enable_if<
    2419  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2420  not std::is_same<basic_json_t, typename T::value_type>::value and
    2421  not std::is_arithmetic<T>::value and
    2422  not std::is_convertible<std::string, T>::value and
    2423  not has_mapped_type<T>::value
    2424  , int>::type = 0>
    2425  T get_impl(T*) const
    2426  {
    2427  if (is_array())
    2428  {
    2429  T to_vector;
    2430  assert(m_value.array != nullptr);
    2431  std::transform(m_value.array->begin(), m_value.array->end(),
    2432  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2433  {
    2434  return i.get<typename T::value_type>();
    2435  });
    2436  return to_vector;
    2437  }
    2438  else
    2439  {
    2440  throw std::domain_error("type must be array, but is " + type_name());
    2441  }
    2442  }
    2443 
    2445  template <class T, typename
    2446  std::enable_if<
    2447  std::is_convertible<basic_json_t, T>::value and
    2448  not std::is_same<basic_json_t, T>::value
    2449  , int>::type = 0>
    2450  std::vector<T> get_impl(std::vector<T>*) const
    2451  {
    2452  if (is_array())
    2453  {
    2454  std::vector<T> to_vector;
    2455  assert(m_value.array != nullptr);
    2456  to_vector.reserve(m_value.array->size());
    2457  std::transform(m_value.array->begin(), m_value.array->end(),
    2458  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2459  {
    2460  return i.get<T>();
    2461  });
    2462  return to_vector;
    2463  }
    2464  else
    2465  {
    2466  throw std::domain_error("type must be array, but is " + type_name());
    2467  }
    2468  }
    2469 
    2471  template <class T, typename
    2472  std::enable_if<
    2473  std::is_same<basic_json, typename T::value_type>::value and
    2474  not has_mapped_type<T>::value
    2475  , int>::type = 0>
    2476  T get_impl(T*) const
    2477  {
    2478  if (is_array())
    2479  {
    2480  assert(m_value.array != nullptr);
    2481  return T(m_value.array->begin(), m_value.array->end());
    2482  }
    2483  else
    2484  {
    2485  throw std::domain_error("type must be array, but is " + type_name());
    2486  }
    2487  }
    2488 
    2490  array_t get_impl(array_t*) const
    2491  {
    2492  if (is_array())
    2493  {
    2494  assert(m_value.array != nullptr);
    2495  return *(m_value.array);
    2496  }
    2497  else
    2498  {
    2499  throw std::domain_error("type must be array, but is " + type_name());
    2500  }
    2501  }
    2502 
    2504  template <typename T, typename
    2505  std::enable_if<
    2506  std::is_convertible<string_t, T>::value
    2507  , int>::type = 0>
    2508  T get_impl(T*) const
    2509  {
    2510  if (is_string())
    2511  {
    2512  assert(m_value.string != nullptr);
    2513  return *m_value.string;
    2514  }
    2515  else
    2516  {
    2517  throw std::domain_error("type must be string, but is " + type_name());
    2518  }
    2519  }
    2520 
    2522  template<typename T, typename
    2523  std::enable_if<
    2524  std::is_arithmetic<T>::value
    2525  , int>::type = 0>
    2526  T get_impl(T*) const
    2527  {
    2528  switch (m_type)
    2529  {
    2530  case value_t::number_integer:
    2531  {
    2532  return static_cast<T>(m_value.number_integer);
    2533  }
    2534 
    2535  case value_t::number_unsigned:
    2536  {
    2537  return static_cast<T>(m_value.number_unsigned);
    2538  }
    2539 
    2540  case value_t::number_float:
    2541  {
    2542  return static_cast<T>(m_value.number_float);
    2543  }
    2544 
    2545  default:
    2546  {
    2547  throw std::domain_error("type must be number, but is " + type_name());
    2548  }
    2549  }
    2550  }
    2551 
    2553  boolean_t get_impl(boolean_t*) const
    2554  {
    2555  if (is_boolean())
    2556  {
    2557  return m_value.boolean;
    2558  }
    2559  else
    2560  {
    2561  throw std::domain_error("type must be boolean, but is " + type_name());
    2562  }
    2563  }
    2564 
    2566  object_t* get_impl_ptr(object_t*) noexcept
    2567  {
    2568  return is_object() ? m_value.object : nullptr;
    2569  }
    2570 
    2572  const object_t* get_impl_ptr(const object_t*) const noexcept
    2573  {
    2574  return is_object() ? m_value.object : nullptr;
    2575  }
    2576 
    2578  array_t* get_impl_ptr(array_t*) noexcept
    2579  {
    2580  return is_array() ? m_value.array : nullptr;
    2581  }
    2582 
    2584  const array_t* get_impl_ptr(const array_t*) const noexcept
    2585  {
    2586  return is_array() ? m_value.array : nullptr;
    2587  }
    2588 
    2590  string_t* get_impl_ptr(string_t*) noexcept
    2591  {
    2592  return is_string() ? m_value.string : nullptr;
    2593  }
    2594 
    2596  const string_t* get_impl_ptr(const string_t*) const noexcept
    2597  {
    2598  return is_string() ? m_value.string : nullptr;
    2599  }
    2600 
    2602  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2603  {
    2604  return is_boolean() ? &m_value.boolean : nullptr;
    2605  }
    2606 
    2608  const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2609  {
    2610  return is_boolean() ? &m_value.boolean : nullptr;
    2611  }
    2612 
    2614  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2615  {
    2616  return is_number_integer() ? &m_value.number_integer : nullptr;
    2617  }
    2618 
    2620  const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2621  {
    2622  return is_number_integer() ? &m_value.number_integer : nullptr;
    2623  }
    2624 
    2626  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2627  {
    2628  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2629  }
    2630 
    2632  const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2633  {
    2634  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2635  }
    2636 
    2638  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2639  {
    2640  return is_number_float() ? &m_value.number_float : nullptr;
    2641  }
    2642 
    2644  const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2645  {
    2646  return is_number_float() ? &m_value.number_float : nullptr;
    2647  }
    2648 
    2660  template<typename ReferenceType, typename ThisType>
    2661  static ReferenceType get_ref_impl(ThisType& obj)
    2662  {
    2663  // delegate the call to get_ptr<>()
    2664  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2665  auto ptr = obj.template get_ptr<PointerType>();
    2666 
    2667  if (ptr != nullptr)
    2668  {
    2669  return *ptr;
    2670  }
    2671  else
    2672  {
    2673  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2674  obj.type_name());
    2675  }
    2676  }
    2677 
    2678  public:
    2679 
    2682 
    2716  template<typename ValueType, typename
    2717  std::enable_if<
    2718  not std::is_pointer<ValueType>::value
    2719  , int>::type = 0>
    2720  ValueType get() const
    2721  {
    2722  return get_impl(static_cast<ValueType*>(nullptr));
    2723  }
    2724 
    2751  template<typename PointerType, typename
    2752  std::enable_if<
    2753  std::is_pointer<PointerType>::value
    2754  , int>::type = 0>
    2755  PointerType get() noexcept
    2756  {
    2757  // delegate the call to get_ptr
    2758  return get_ptr<PointerType>();
    2759  }
    2760 
    2765  template<typename PointerType, typename
    2766  std::enable_if<
    2767  std::is_pointer<PointerType>::value
    2768  , int>::type = 0>
    2769  const PointerType get() const noexcept
    2770  {
    2771  // delegate the call to get_ptr
    2772  return get_ptr<PointerType>();
    2773  }
    2774 
    2800  template<typename PointerType, typename
    2801  std::enable_if<
    2802  std::is_pointer<PointerType>::value
    2803  , int>::type = 0>
    2804  PointerType get_ptr() noexcept
    2805  {
    2806  // delegate the call to get_impl_ptr<>()
    2807  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2808  }
    2809 
    2814  template<typename PointerType, typename
    2815  std::enable_if<
    2816  std::is_pointer<PointerType>::value
    2817  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2818  , int>::type = 0>
    2819  const PointerType get_ptr() const noexcept
    2820  {
    2821  // delegate the call to get_impl_ptr<>() const
    2822  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2823  }
    2824 
    2851  template<typename ReferenceType, typename
    2852  std::enable_if<
    2853  std::is_reference<ReferenceType>::value
    2854  , int>::type = 0>
    2855  ReferenceType get_ref()
    2856  {
    2857  // delegate call to get_ref_impl
    2858  return get_ref_impl<ReferenceType>(*this);
    2859  }
    2860 
    2865  template<typename ReferenceType, typename
    2866  std::enable_if<
    2867  std::is_reference<ReferenceType>::value
    2868  and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
    2869  , int>::type = 0>
    2870  ReferenceType get_ref() const
    2871  {
    2872  // delegate call to get_ref_impl
    2873  return get_ref_impl<ReferenceType>(*this);
    2874  }
    2875 
    2904  template < typename ValueType, typename
    2905  std::enable_if <
    2906  not std::is_pointer<ValueType>::value
    2907  and not std::is_same<ValueType, typename string_t::value_type>::value
    2908 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    2909  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    2910 #endif
    2911  , int >::type = 0 >
    2912  operator ValueType() const
    2913  {
    2914  // delegate the call to get<>() const
    2915  return get<ValueType>();
    2916  }
    2917 
    2919 
    2920 
    2922  // element access //
    2924 
    2927 
    2951  {
    2952  // at only works for arrays
    2953  if (is_array())
    2954  {
    2955  try
    2956  {
    2957  assert(m_value.array != nullptr);
    2958  return m_value.array->at(idx);
    2959  }
    2960  catch (std::out_of_range&)
    2961  {
    2962  // create better exception explanation
    2963  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    2964  }
    2965  }
    2966  else
    2967  {
    2968  throw std::domain_error("cannot use at() with " + type_name());
    2969  }
    2970  }
    2971 
    2995  {
    2996  // at only works for arrays
    2997  if (is_array())
    2998  {
    2999  try
    3000  {
    3001  assert(m_value.array != nullptr);
    3002  return m_value.array->at(idx);
    3003  }
    3004  catch (std::out_of_range&)
    3005  {
    3006  // create better exception explanation
    3007  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3008  }
    3009  }
    3010  else
    3011  {
    3012  throw std::domain_error("cannot use at() with " + type_name());
    3013  }
    3014  }
    3015 
    3042  reference at(const typename object_t::key_type& key)
    3043  {
    3044  // at only works for objects
    3045  if (is_object())
    3046  {
    3047  try
    3048  {
    3049  assert(m_value.object != nullptr);
    3050  return m_value.object->at(key);
    3051  }
    3052  catch (std::out_of_range&)
    3053  {
    3054  // create better exception explanation
    3055  throw std::out_of_range("key '" + key + "' not found");
    3056  }
    3057  }
    3058  else
    3059  {
    3060  throw std::domain_error("cannot use at() with " + type_name());
    3061  }
    3062  }
    3063 
    3090  const_reference at(const typename object_t::key_type& key) const
    3091  {
    3092  // at only works for objects
    3093  if (is_object())
    3094  {
    3095  try
    3096  {
    3097  assert(m_value.object != nullptr);
    3098  return m_value.object->at(key);
    3099  }
    3100  catch (std::out_of_range&)
    3101  {
    3102  // create better exception explanation
    3103  throw std::out_of_range("key '" + key + "' not found");
    3104  }
    3105  }
    3106  else
    3107  {
    3108  throw std::domain_error("cannot use at() with " + type_name());
    3109  }
    3110  }
    3111 
    3138  {
    3139  // implicitly convert null to object
    3140  if (is_null())
    3141  {
    3142  m_type = value_t::array;
    3143  m_value.array = create<array_t>();
    3144  }
    3145 
    3146  // [] only works for arrays
    3147  if (is_array())
    3148  {
    3149  assert(m_value.array != nullptr);
    3150  for (size_t i = m_value.array->size(); i <= idx; ++i)
    3151  {
    3152  m_value.array->push_back(basic_json());
    3153  }
    3154 
    3155  return m_value.array->operator[](idx);
    3156  }
    3157  else
    3158  {
    3159  throw std::domain_error("cannot use operator[] with " + type_name());
    3160  }
    3161  }
    3162 
    3183  {
    3184  // at only works for arrays
    3185  if (is_array())
    3186  {
    3187  assert(m_value.array != nullptr);
    3188  return m_value.array->operator[](idx);
    3189  }
    3190  else
    3191  {
    3192  throw std::domain_error("cannot use operator[] with " + type_name());
    3193  }
    3194  }
    3195 
    3223  reference operator[](const typename object_t::key_type& key)
    3224  {
    3225  // implicitly convert null to object
    3226  if (is_null())
    3227  {
    3228  m_type = value_t::object;
    3229  m_value.object = create<object_t>();
    3230  }
    3231 
    3232  // [] only works for objects
    3233  if (is_object())
    3234  {
    3235  assert(m_value.object != nullptr);
    3236  return m_value.object->operator[](key);
    3237  }
    3238  else
    3239  {
    3240  throw std::domain_error("cannot use operator[] with " + type_name());
    3241  }
    3242  }
    3243 
    3271  const_reference operator[](const typename object_t::key_type& key) const
    3272  {
    3273  // [] only works for objects
    3274  if (is_object())
    3275  {
    3276  assert(m_value.object != nullptr);
    3277  assert(m_value.object->find(key) != m_value.object->end());
    3278  return m_value.object->find(key)->second;
    3279  }
    3280  else
    3281  {
    3282  throw std::domain_error("cannot use operator[] with " + type_name());
    3283  }
    3284  }
    3285 
    3313  template<typename T, std::size_t n>
    3314  reference operator[](T * (&key)[n])
    3315  {
    3316  return operator[](static_cast<const T>(key));
    3317  }
    3318 
    3348  template<typename T, std::size_t n>
    3349  const_reference operator[](T * (&key)[n]) const
    3350  {
    3351  return operator[](static_cast<const T>(key));
    3352  }
    3353 
    3381  template<typename T>
    3383  {
    3384  // implicitly convert null to object
    3385  if (is_null())
    3386  {
    3387  m_type = value_t::object;
    3388  m_value = value_t::object;
    3389  }
    3390 
    3391  // at only works for objects
    3392  if (is_object())
    3393  {
    3394  assert(m_value.object != nullptr);
    3395  return m_value.object->operator[](key);
    3396  }
    3397  else
    3398  {
    3399  throw std::domain_error("cannot use operator[] with " + type_name());
    3400  }
    3401  }
    3402 
    3430  template<typename T>
    3432  {
    3433  // at only works for objects
    3434  if (is_object())
    3435  {
    3436  assert(m_value.object != nullptr);
    3437  assert(m_value.object->find(key) != m_value.object->end());
    3438  return m_value.object->find(key)->second;
    3439  }
    3440  else
    3441  {
    3442  throw std::domain_error("cannot use operator[] with " + type_name());
    3443  }
    3444  }
    3445 
    3494  template <class ValueType, typename
    3495  std::enable_if<
    3496  std::is_convertible<basic_json_t, ValueType>::value
    3497  , int>::type = 0>
    3498  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3499  {
    3500  // at only works for objects
    3501  if (is_object())
    3502  {
    3503  // if key is found, return value and given default value otherwise
    3504  const auto it = find(key);
    3505  if (it != end())
    3506  {
    3507  return *it;
    3508  }
    3509  else
    3510  {
    3511  return default_value;
    3512  }
    3513  }
    3514  else
    3515  {
    3516  throw std::domain_error("cannot use value() with " + type_name());
    3517  }
    3518  }
    3519 
    3524  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3525  {
    3526  return value(key, string_t(default_value));
    3527  }
    3528 
    3550  {
    3551  return *begin();
    3552  }
    3553 
    3558  {
    3559  return *cbegin();
    3560  }
    3561 
    3584  {
    3585  auto tmp = end();
    3586  --tmp;
    3587  return *tmp;
    3588  }
    3589 
    3594  {
    3595  auto tmp = cend();
    3596  --tmp;
    3597  return *tmp;
    3598  }
    3599 
    3644  template <class InteratorType, typename
    3645  std::enable_if<
    3646  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3647  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3648  , int>::type
    3649  = 0>
    3650  InteratorType erase(InteratorType pos)
    3651  {
    3652  // make sure iterator fits the current value
    3653  if (this != pos.m_object)
    3654  {
    3655  throw std::domain_error("iterator does not fit current value");
    3656  }
    3657 
    3658  InteratorType result = end();
    3659 
    3660  switch (m_type)
    3661  {
    3662  case value_t::boolean:
    3663  case value_t::number_float:
    3664  case value_t::number_integer:
    3665  case value_t::number_unsigned:
    3666  case value_t::string:
    3667  {
    3668  if (not pos.m_it.primitive_iterator.is_begin())
    3669  {
    3670  throw std::out_of_range("iterator out of range");
    3671  }
    3672 
    3673  if (is_string())
    3674  {
    3675  delete m_value.string;
    3676  m_value.string = nullptr;
    3677  }
    3678 
    3679  m_type = value_t::null;
    3680  break;
    3681  }
    3682 
    3683  case value_t::object:
    3684  {
    3685  assert(m_value.object != nullptr);
    3686  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3687  break;
    3688  }
    3689 
    3690  case value_t::array:
    3691  {
    3692  assert(m_value.array != nullptr);
    3693  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3694  break;
    3695  }
    3696 
    3697  default:
    3698  {
    3699  throw std::domain_error("cannot use erase() with " + type_name());
    3700  }
    3701  }
    3702 
    3703  return result;
    3704  }
    3705 
    3750  template <class InteratorType, typename
    3751  std::enable_if<
    3752  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3753  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3754  , int>::type
    3755  = 0>
    3756  InteratorType erase(InteratorType first, InteratorType last)
    3757  {
    3758  // make sure iterator fits the current value
    3759  if (this != first.m_object or this != last.m_object)
    3760  {
    3761  throw std::domain_error("iterators do not fit current value");
    3762  }
    3763 
    3764  InteratorType result = end();
    3765 
    3766  switch (m_type)
    3767  {
    3768  case value_t::boolean:
    3769  case value_t::number_float:
    3770  case value_t::number_integer:
    3771  case value_t::number_unsigned:
    3772  case value_t::string:
    3773  {
    3774  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3775  {
    3776  throw std::out_of_range("iterators out of range");
    3777  }
    3778 
    3779  if (is_string())
    3780  {
    3781  delete m_value.string;
    3782  m_value.string = nullptr;
    3783  }
    3784 
    3785  m_type = value_t::null;
    3786  break;
    3787  }
    3788 
    3789  case value_t::object:
    3790  {
    3791  assert(m_value.object != nullptr);
    3792  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3793  last.m_it.object_iterator);
    3794  break;
    3795  }
    3796 
    3797  case value_t::array:
    3798  {
    3799  assert(m_value.array != nullptr);
    3800  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3801  last.m_it.array_iterator);
    3802  break;
    3803  }
    3804 
    3805  default:
    3806  {
    3807  throw std::domain_error("cannot use erase() with " + type_name());
    3808  }
    3809  }
    3810 
    3811  return result;
    3812  }
    3813 
    3840  size_type erase(const typename object_t::key_type& key)
    3841  {
    3842  // this erase only works for objects
    3843  if (is_object())
    3844  {
    3845  assert(m_value.object != nullptr);
    3846  return m_value.object->erase(key);
    3847  }
    3848  else
    3849  {
    3850  throw std::domain_error("cannot use erase() with " + type_name());
    3851  }
    3852  }
    3853 
    3878  void erase(const size_type idx)
    3879  {
    3880  // this erase only works for arrays
    3881  if (is_array())
    3882  {
    3883  if (idx >= size())
    3884  {
    3885  throw std::out_of_range("index out of range");
    3886  }
    3887 
    3888  assert(m_value.array != nullptr);
    3889  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    3890  }
    3891  else
    3892  {
    3893  throw std::domain_error("cannot use erase() with " + type_name());
    3894  }
    3895  }
    3896 
    3914  iterator find(typename object_t::key_type key)
    3915  {
    3916  auto result = end();
    3917 
    3918  if (is_object())
    3919  {
    3920  assert(m_value.object != nullptr);
    3921  result.m_it.object_iterator = m_value.object->find(key);
    3922  }
    3923 
    3924  return result;
    3925  }
    3926 
    3931  const_iterator find(typename object_t::key_type key) const
    3932  {
    3933  auto result = cend();
    3934 
    3935  if (is_object())
    3936  {
    3937  assert(m_value.object != nullptr);
    3938  result.m_it.object_iterator = m_value.object->find(key);
    3939  }
    3940 
    3941  return result;
    3942  }
    3943 
    3962  size_type count(typename object_t::key_type key) const
    3963  {
    3964  // return 0 for all nonobject types
    3965  assert(not is_object() or m_value.object != nullptr);
    3966  return is_object() ? m_value.object->count(key) : 0;
    3967  }
    3968 
    3970 
    3971 
    3973  // iterators //
    3975 
    3978 
    3998  {
    3999  iterator result(this);
    4000  result.set_begin();
    4001  return result;
    4002  }
    4003 
    4008  {
    4009  return cbegin();
    4010  }
    4011 
    4032  {
    4033  const_iterator result(this);
    4034  result.set_begin();
    4035  return result;
    4036  }
    4037 
    4057  {
    4058  iterator result(this);
    4059  result.set_end();
    4060  return result;
    4061  }
    4062 
    4067  {
    4068  return cend();
    4069  }
    4070 
    4091  {
    4092  const_iterator result(this);
    4093  result.set_end();
    4094  return result;
    4095  }
    4096 
    4115  {
    4116  return reverse_iterator(end());
    4117  }
    4118 
    4123  {
    4124  return crbegin();
    4125  }
    4126 
    4146  {
    4147  return reverse_iterator(begin());
    4148  }
    4149 
    4154  {
    4155  return crend();
    4156  }
    4157 
    4177  {
    4178  return const_reverse_iterator(cend());
    4179  }
    4180 
    4200  {
    4201  return const_reverse_iterator(cbegin());
    4202  }
    4203 
    4204  private:
    4205  // forward declaration
    4206  template<typename IteratorType> class iteration_proxy;
    4207 
    4208  public:
    4220  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4221  {
    4222  return iteration_proxy<iterator>(cont);
    4223  }
    4224 
    4228  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4229  {
    4230  return iteration_proxy<const_iterator>(cont);
    4231  }
    4232 
    4234 
    4235 
    4237  // capacity //
    4239 
    4242 
    4272  bool empty() const noexcept
    4273  {
    4274  switch (m_type)
    4275  {
    4276  case value_t::null:
    4277  {
    4278  // null values are empty
    4279  return true;
    4280  }
    4281 
    4282  case value_t::array:
    4283  {
    4284  assert(m_value.array != nullptr);
    4285  return m_value.array->empty();
    4286  }
    4287 
    4288  case value_t::object:
    4289  {
    4290  assert(m_value.object != nullptr);
    4291  return m_value.object->empty();
    4292  }
    4293 
    4294  default:
    4295  {
    4296  // all other types are nonempty
    4297  return false;
    4298  }
    4299  }
    4300  }
    4301 
    4330  size_type size() const noexcept
    4331  {
    4332  switch (m_type)
    4333  {
    4334  case value_t::null:
    4335  {
    4336  // null values are empty
    4337  return 0;
    4338  }
    4339 
    4340  case value_t::array:
    4341  {
    4342  assert(m_value.array != nullptr);
    4343  return m_value.array->size();
    4344  }
    4345 
    4346  case value_t::object:
    4347  {
    4348  assert(m_value.object != nullptr);
    4349  return m_value.object->size();
    4350  }
    4351 
    4352  default:
    4353  {
    4354  // all other types have size 1
    4355  return 1;
    4356  }
    4357  }
    4358  }
    4359 
    4392  size_type max_size() const noexcept
    4393  {
    4394  switch (m_type)
    4395  {
    4396  case value_t::array:
    4397  {
    4398  assert(m_value.array != nullptr);
    4399  return m_value.array->max_size();
    4400  }
    4401 
    4402  case value_t::object:
    4403  {
    4404  assert(m_value.object != nullptr);
    4405  return m_value.object->max_size();
    4406  }
    4407 
    4408  default:
    4409  {
    4410  // all other types have max_size() == size()
    4411  return size();
    4412  }
    4413  }
    4414  }
    4415 
    4417 
    4418 
    4420  // modifiers //
    4422 
    4425 
    4451  void clear() noexcept
    4452  {
    4453  switch (m_type)
    4454  {
    4455  case value_t::number_integer:
    4456  {
    4457  m_value.number_integer = 0;
    4458  break;
    4459  }
    4460 
    4461  case value_t::number_unsigned:
    4462  {
    4463  m_value.number_unsigned = 0;
    4464  break;
    4465  }
    4466 
    4467  case value_t::number_float:
    4468  {
    4469  m_value.number_float = 0.0;
    4470  break;
    4471  }
    4472 
    4473  case value_t::boolean:
    4474  {
    4475  m_value.boolean = false;
    4476  break;
    4477  }
    4478 
    4479  case value_t::string:
    4480  {
    4481  assert(m_value.string != nullptr);
    4482  m_value.string->clear();
    4483  break;
    4484  }
    4485 
    4486  case value_t::array:
    4487  {
    4488  assert(m_value.array != nullptr);
    4489  m_value.array->clear();
    4490  break;
    4491  }
    4492 
    4493  case value_t::object:
    4494  {
    4495  assert(m_value.object != nullptr);
    4496  m_value.object->clear();
    4497  break;
    4498  }
    4499 
    4500  default:
    4501  {
    4502  break;
    4503  }
    4504  }
    4505  }
    4506 
    4527  void push_back(basic_json&& val)
    4528  {
    4529  // push_back only works for null objects or arrays
    4530  if (not(is_null() or is_array()))
    4531  {
    4532  throw std::domain_error("cannot use push_back() with " + type_name());
    4533  }
    4534 
    4535  // transform null object into an array
    4536  if (is_null())
    4537  {
    4538  m_type = value_t::array;
    4539  m_value = value_t::array;
    4540  }
    4541 
    4542  // add element to array (move semantics)
    4543  assert(m_value.array != nullptr);
    4544  m_value.array->push_back(std::move(val));
    4545  // invalidate object
    4546  val.m_type = value_t::null;
    4547  }
    4548 
    4553  reference operator+=(basic_json&& val)
    4554  {
    4555  push_back(std::move(val));
    4556  return *this;
    4557  }
    4558 
    4563  void push_back(const basic_json& val)
    4564  {
    4565  // push_back only works for null objects or arrays
    4566  if (not(is_null() or is_array()))
    4567  {
    4568  throw std::domain_error("cannot use push_back() with " + type_name());
    4569  }
    4570 
    4571  // transform null object into an array
    4572  if (is_null())
    4573  {
    4574  m_type = value_t::array;
    4575  m_value = value_t::array;
    4576  }
    4577 
    4578  // add element to array
    4579  assert(m_value.array != nullptr);
    4580  m_value.array->push_back(val);
    4581  }
    4582 
    4587  reference operator+=(const basic_json& val)
    4588  {
    4589  push_back(val);
    4590  return *this;
    4591  }
    4592 
    4613  void push_back(const typename object_t::value_type& val)
    4614  {
    4615  // push_back only works for null objects or objects
    4616  if (not(is_null() or is_object()))
    4617  {
    4618  throw std::domain_error("cannot use push_back() with " + type_name());
    4619  }
    4620 
    4621  // transform null object into an object
    4622  if (is_null())
    4623  {
    4624  m_type = value_t::object;
    4625  m_value = value_t::object;
    4626  }
    4627 
    4628  // add element to array
    4629  assert(m_value.object != nullptr);
    4630  m_value.object->insert(val);
    4631  }
    4632 
    4637  reference operator+=(const typename object_t::value_type& val)
    4638  {
    4639  push_back(val);
    4640  return operator[](val.first);
    4641  }
    4642 
    4665  iterator insert(const_iterator pos, const basic_json& val)
    4666  {
    4667  // insert only works for arrays
    4668  if (is_array())
    4669  {
    4670  // check if iterator pos fits to this JSON value
    4671  if (pos.m_object != this)
    4672  {
    4673  throw std::domain_error("iterator does not fit current value");
    4674  }
    4675 
    4676  // insert to array and return iterator
    4677  iterator result(this);
    4678  assert(m_value.array != nullptr);
    4679  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4680  return result;
    4681  }
    4682  else
    4683  {
    4684  throw std::domain_error("cannot use insert() with " + type_name());
    4685  }
    4686  }
    4687 
    4692  iterator insert(const_iterator pos, basic_json&& val)
    4693  {
    4694  return insert(pos, val);
    4695  }
    4696 
    4721  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    4722  {
    4723  // insert only works for arrays
    4724  if (is_array())
    4725  {
    4726  // check if iterator pos fits to this JSON value
    4727  if (pos.m_object != this)
    4728  {
    4729  throw std::domain_error("iterator does not fit current value");
    4730  }
    4731 
    4732  // insert to array and return iterator
    4733  iterator result(this);
    4734  assert(m_value.array != nullptr);
    4735  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    4736  return result;
    4737  }
    4738  else
    4739  {
    4740  throw std::domain_error("cannot use insert() with " + type_name());
    4741  }
    4742  }
    4743 
    4775  {
    4776  // insert only works for arrays
    4777  if (not is_array())
    4778  {
    4779  throw std::domain_error("cannot use insert() with " + type_name());
    4780  }
    4781 
    4782  // check if iterator pos fits to this JSON value
    4783  if (pos.m_object != this)
    4784  {
    4785  throw std::domain_error("iterator does not fit current value");
    4786  }
    4787 
    4788  if (first.m_object != last.m_object)
    4789  {
    4790  throw std::domain_error("iterators do not fit");
    4791  }
    4792 
    4793  if (first.m_object == this or last.m_object == this)
    4794  {
    4795  throw std::domain_error("passed iterators may not belong to container");
    4796  }
    4797 
    4798  // insert to array and return iterator
    4799  iterator result(this);
    4800  assert(m_value.array != nullptr);
    4801  result.m_it.array_iterator = m_value.array->insert(
    4802  pos.m_it.array_iterator,
    4803  first.m_it.array_iterator,
    4804  last.m_it.array_iterator);
    4805  return result;
    4806  }
    4807 
    4832  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    4833  {
    4834  // insert only works for arrays
    4835  if (not is_array())
    4836  {
    4837  throw std::domain_error("cannot use insert() with " + type_name());
    4838  }
    4839 
    4840  // check if iterator pos fits to this JSON value
    4841  if (pos.m_object != this)
    4842  {
    4843  throw std::domain_error("iterator does not fit current value");
    4844  }
    4845 
    4846  // insert to array and return iterator
    4847  iterator result(this);
    4848  assert(m_value.array != nullptr);
    4849  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    4850  return result;
    4851  }
    4852 
    4870  void swap(reference other) noexcept (
    4871  std::is_nothrow_move_constructible<value_t>::value and
    4872  std::is_nothrow_move_assignable<value_t>::value and
    4873  std::is_nothrow_move_constructible<json_value>::value and
    4874  std::is_nothrow_move_assignable<json_value>::value
    4875  )
    4876  {
    4877  std::swap(m_type, other.m_type);
    4878  std::swap(m_value, other.m_value);
    4879  }
    4880 
    4901  void swap(array_t& other)
    4902  {
    4903  // swap only works for arrays
    4904  if (is_array())
    4905  {
    4906  assert(m_value.array != nullptr);
    4907  std::swap(*(m_value.array), other);
    4908  }
    4909  else
    4910  {
    4911  throw std::domain_error("cannot use swap() with " + type_name());
    4912  }
    4913  }
    4914 
    4935  void swap(object_t& other)
    4936  {
    4937  // swap only works for objects
    4938  if (is_object())
    4939  {
    4940  assert(m_value.object != nullptr);
    4941  std::swap(*(m_value.object), other);
    4942  }
    4943  else
    4944  {
    4945  throw std::domain_error("cannot use swap() with " + type_name());
    4946  }
    4947  }
    4948 
    4969  void swap(string_t& other)
    4970  {
    4971  // swap only works for strings
    4972  if (is_string())
    4973  {
    4974  assert(m_value.string != nullptr);
    4975  std::swap(*(m_value.string), other);
    4976  }
    4977  else
    4978  {
    4979  throw std::domain_error("cannot use swap() with " + type_name());
    4980  }
    4981  }
    4982 
    4984 
    4985 
    4987  // lexicographical comparison operators //
    4989 
    4992 
    4993  private:
    5003  friend bool operator<(const value_t lhs, const value_t rhs)
    5004  {
    5005  static constexpr std::array<uint8_t, 8> order = {{
    5006  0, // null
    5007  3, // object
    5008  4, // array
    5009  5, // string
    5010  1, // boolean
    5011  2, // integer
    5012  2, // unsigned
    5013  2, // float
    5014  }
    5015  };
    5016 
    5017  // discarded values are not comparable
    5018  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5019  {
    5020  return false;
    5021  }
    5022 
    5023  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5024  }
    5025 
    5026  public:
    5050  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5051  {
    5052  const auto lhs_type = lhs.type();
    5053  const auto rhs_type = rhs.type();
    5054 
    5055  if (lhs_type == rhs_type)
    5056  {
    5057  switch (lhs_type)
    5058  {
    5059  case value_t::array:
    5060  {
    5061  assert(lhs.m_value.array != nullptr);
    5062  assert(rhs.m_value.array != nullptr);
    5063  return *lhs.m_value.array == *rhs.m_value.array;
    5064  }
    5065  case value_t::object:
    5066  {
    5067  assert(lhs.m_value.object != nullptr);
    5068  assert(rhs.m_value.object != nullptr);
    5069  return *lhs.m_value.object == *rhs.m_value.object;
    5070  }
    5071  case value_t::null:
    5072  {
    5073  return true;
    5074  }
    5075  case value_t::string:
    5076  {
    5077  assert(lhs.m_value.string != nullptr);
    5078  assert(rhs.m_value.string != nullptr);
    5079  return *lhs.m_value.string == *rhs.m_value.string;
    5080  }
    5081  case value_t::boolean:
    5082  {
    5083  return lhs.m_value.boolean == rhs.m_value.boolean;
    5084  }
    5085  case value_t::number_integer:
    5086  {
    5087  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5088  }
    5089  case value_t::number_unsigned:
    5090  {
    5091  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5092  }
    5093  case value_t::number_float:
    5094  {
    5095  return lhs.m_value.number_float == rhs.m_value.number_float;
    5096  }
    5097  default:
    5098  {
    5099  return false;
    5100  }
    5101  }
    5102  }
    5103  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5104  {
    5105  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5106  }
    5107  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5108  {
    5109  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5110  }
    5111  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5112  {
    5113  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5114  }
    5115  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5116  {
    5117  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5118  }
    5119  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5120  {
    5121  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5122  }
    5123  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5124  {
    5125  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5126  }
    5127 
    5128  return false;
    5129  }
    5130 
    5149  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5150  {
    5151  return v.is_null();
    5152  }
    5153 
    5158  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5159  {
    5160  return v.is_null();
    5161  }
    5162 
    5179  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5180  {
    5181  return not (lhs == rhs);
    5182  }
    5183 
    5202  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5203  {
    5204  return not v.is_null();
    5205  }
    5206 
    5211  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5212  {
    5213  return not v.is_null();
    5214  }
    5215 
    5240  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5241  {
    5242  const auto lhs_type = lhs.type();
    5243  const auto rhs_type = rhs.type();
    5244 
    5245  if (lhs_type == rhs_type)
    5246  {
    5247  switch (lhs_type)
    5248  {
    5249  case value_t::array:
    5250  {
    5251  assert(lhs.m_value.array != nullptr);
    5252  assert(rhs.m_value.array != nullptr);
    5253  return *lhs.m_value.array < *rhs.m_value.array;
    5254  }
    5255  case value_t::object:
    5256  {
    5257  assert(lhs.m_value.object != nullptr);
    5258  assert(rhs.m_value.object != nullptr);
    5259  return *lhs.m_value.object < *rhs.m_value.object;
    5260  }
    5261  case value_t::null:
    5262  {
    5263  return false;
    5264  }
    5265  case value_t::string:
    5266  {
    5267  assert(lhs.m_value.string != nullptr);
    5268  assert(rhs.m_value.string != nullptr);
    5269  return *lhs.m_value.string < *rhs.m_value.string;
    5270  }
    5271  case value_t::boolean:
    5272  {
    5273  return lhs.m_value.boolean < rhs.m_value.boolean;
    5274  }
    5275  case value_t::number_integer:
    5276  {
    5277  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5278  }
    5279  case value_t::number_unsigned:
    5280  {
    5281  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5282  }
    5283  case value_t::number_float:
    5284  {
    5285  return lhs.m_value.number_float < rhs.m_value.number_float;
    5286  }
    5287  default:
    5288  {
    5289  return false;
    5290  }
    5291  }
    5292  }
    5293  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5294  {
    5295  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5296  }
    5297  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5298  {
    5299  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5300  }
    5301  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5302  {
    5303  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5304  }
    5305  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5306  {
    5307  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5308  }
    5309  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5310  {
    5311  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5312  }
    5313  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5314  {
    5315  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5316  }
    5317 
    5318  // We only reach this line if we cannot compare values. In that case,
    5319  // we compare types. Note we have to call the operator explicitly,
    5320  // because MSVC has problems otherwise.
    5321  return operator<(lhs_type, rhs_type);
    5322  }
    5323 
    5341  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5342  {
    5343  return not (rhs < lhs);
    5344  }
    5345 
    5363  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5364  {
    5365  return not (lhs <= rhs);
    5366  }
    5367 
    5385  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5386  {
    5387  return not (lhs < rhs);
    5388  }
    5389 
    5391 
    5392 
    5394  // serialization //
    5396 
    5399 
    5422  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5423  {
    5424  // read width member and use it as indentation parameter if nonzero
    5425  const bool pretty_print = (o.width() > 0);
    5426  const auto indentation = (pretty_print ? o.width() : 0);
    5427 
    5428  // reset width to 0 for subsequent calls to this stream
    5429  o.width(0);
    5430 
    5431  // do the actual serialization
    5432  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5433  return o;
    5434  }
    5435 
    5440  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5441  {
    5442  return o << j;
    5443  }
    5444 
    5446 
    5447 
    5449  // deserialization //
    5451 
    5454 
    5479  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5480  {
    5481  return parser(s, cb).parse();
    5482  }
    5483 
    5508  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5509  {
    5510  return parser(i, cb).parse();
    5511  }
    5512 
    5516  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5517  {
    5518  return parser(i, cb).parse();
    5519  }
    5520 
    5544  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5545  {
    5546  j = parser(i).parse();
    5547  return i;
    5548  }
    5549 
    5554  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5555  {
    5556  j = parser(i).parse();
    5557  return i;
    5558  }
    5559 
    5561 
    5562 
    5563  private:
    5565  // convenience functions //
    5567 
    5569  string_t type_name() const
    5570  {
    5571  switch (m_type)
    5572  {
    5573  case value_t::null:
    5574  return "null";
    5575  case value_t::object:
    5576  return "object";
    5577  case value_t::array:
    5578  return "array";
    5579  case value_t::string:
    5580  return "string";
    5581  case value_t::boolean:
    5582  return "boolean";
    5583  case value_t::discarded:
    5584  return "discarded";
    5585  default:
    5586  return "number";
    5587  }
    5588  }
    5589 
    5598  static std::size_t extra_space(const string_t& s) noexcept
    5599  {
    5600  std::size_t result = 0;
    5601 
    5602  for (const auto& c : s)
    5603  {
    5604  switch (c)
    5605  {
    5606  case '"':
    5607  case '\\':
    5608  case '\b':
    5609  case '\f':
    5610  case '\n':
    5611  case '\r':
    5612  case '\t':
    5613  {
    5614  // from c (1 byte) to \x (2 bytes)
    5615  result += 1;
    5616  break;
    5617  }
    5618 
    5619  default:
    5620  {
    5621  if (c >= 0x00 and c <= 0x1f)
    5622  {
    5623  // from c (1 byte) to \uxxxx (6 bytes)
    5624  result += 5;
    5625  }
    5626  break;
    5627  }
    5628  }
    5629  }
    5630 
    5631  return result;
    5632  }
    5633 
    5647  static string_t escape_string(const string_t& s) noexcept
    5648  {
    5649  const auto space = extra_space(s);
    5650  if (space == 0)
    5651  {
    5652  return s;
    5653  }
    5654 
    5655  // create a result string of necessary size
    5656  string_t result(s.size() + space, '\\');
    5657  std::size_t pos = 0;
    5658 
    5659  for (const auto& c : s)
    5660  {
    5661  switch (c)
    5662  {
    5663  // quotation mark (0x22)
    5664  case '"':
    5665  {
    5666  result[pos + 1] = '"';
    5667  pos += 2;
    5668  break;
    5669  }
    5670 
    5671  // reverse solidus (0x5c)
    5672  case '\\':
    5673  {
    5674  // nothing to change
    5675  pos += 2;
    5676  break;
    5677  }
    5678 
    5679  // backspace (0x08)
    5680  case '\b':
    5681  {
    5682  result[pos + 1] = 'b';
    5683  pos += 2;
    5684  break;
    5685  }
    5686 
    5687  // formfeed (0x0c)
    5688  case '\f':
    5689  {
    5690  result[pos + 1] = 'f';
    5691  pos += 2;
    5692  break;
    5693  }
    5694 
    5695  // newline (0x0a)
    5696  case '\n':
    5697  {
    5698  result[pos + 1] = 'n';
    5699  pos += 2;
    5700  break;
    5701  }
    5702 
    5703  // carriage return (0x0d)
    5704  case '\r':
    5705  {
    5706  result[pos + 1] = 'r';
    5707  pos += 2;
    5708  break;
    5709  }
    5710 
    5711  // horizontal tab (0x09)
    5712  case '\t':
    5713  {
    5714  result[pos + 1] = 't';
    5715  pos += 2;
    5716  break;
    5717  }
    5718 
    5719  default:
    5720  {
    5721  if (c >= 0x00 and c <= 0x1f)
    5722  {
    5723  // convert a number 0..15 to its hex representation (0..f)
    5724  auto hexify = [](const char v) -> char
    5725  {
    5726  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    5727  };
    5728 
    5729  // print character c as \uxxxx
    5730  for (const char m :
    5731  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    5732  })
    5733  {
    5734  result[++pos] = m;
    5735  }
    5736 
    5737  ++pos;
    5738  }
    5739  else
    5740  {
    5741  // all other characters are added as-is
    5742  result[pos++] = c;
    5743  }
    5744  break;
    5745  }
    5746  }
    5747  }
    5748 
    5749  return result;
    5750  }
    5751 
    5769  void dump(std::ostream& o,
    5770  const bool pretty_print,
    5771  const unsigned int indent_step,
    5772  const unsigned int current_indent = 0) const
    5773  {
    5774  // variable to hold indentation for recursive calls
    5775  unsigned int new_indent = current_indent;
    5776 
    5777  switch (m_type)
    5778  {
    5779  case value_t::object:
    5780  {
    5781  assert(m_value.object != nullptr);
    5782 
    5783  if (m_value.object->empty())
    5784  {
    5785  o << "{}";
    5786  return;
    5787  }
    5788 
    5789  o << "{";
    5790 
    5791  // increase indentation
    5792  if (pretty_print)
    5793  {
    5794  new_indent += indent_step;
    5795  o << "\n";
    5796  }
    5797 
    5798  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    5799  {
    5800  if (i != m_value.object->cbegin())
    5801  {
    5802  o << (pretty_print ? ",\n" : ",");
    5803  }
    5804  o << string_t(new_indent, ' ') << "\""
    5805  << escape_string(i->first) << "\":"
    5806  << (pretty_print ? " " : "");
    5807  i->second.dump(o, pretty_print, indent_step, new_indent);
    5808  }
    5809 
    5810  // decrease indentation
    5811  if (pretty_print)
    5812  {
    5813  new_indent -= indent_step;
    5814  o << "\n";
    5815  }
    5816 
    5817  o << string_t(new_indent, ' ') + "}";
    5818  return;
    5819  }
    5820 
    5821  case value_t::array:
    5822  {
    5823  assert(m_value.array != nullptr);
    5824 
    5825  if (m_value.array->empty())
    5826  {
    5827  o << "[]";
    5828  return;
    5829  }
    5830 
    5831  o << "[";
    5832 
    5833  // increase indentation
    5834  if (pretty_print)
    5835  {
    5836  new_indent += indent_step;
    5837  o << "\n";
    5838  }
    5839 
    5840  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    5841  {
    5842  if (i != m_value.array->cbegin())
    5843  {
    5844  o << (pretty_print ? ",\n" : ",");
    5845  }
    5846  o << string_t(new_indent, ' ');
    5847  i->dump(o, pretty_print, indent_step, new_indent);
    5848  }
    5849 
    5850  // decrease indentation
    5851  if (pretty_print)
    5852  {
    5853  new_indent -= indent_step;
    5854  o << "\n";
    5855  }
    5856 
    5857  o << string_t(new_indent, ' ') << "]";
    5858  return;
    5859  }
    5860 
    5861  case value_t::string:
    5862  {
    5863  assert(m_value.string != nullptr);
    5864  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    5865  return;
    5866  }
    5867 
    5868  case value_t::boolean:
    5869  {
    5870  o << (m_value.boolean ? "true" : "false");
    5871  return;
    5872  }
    5873 
    5874  case value_t::number_integer:
    5875  {
    5876  o << m_value.number_integer;
    5877  return;
    5878  }
    5879 
    5880  case value_t::number_unsigned:
    5881  {
    5882  o << m_value.number_unsigned;
    5883  return;
    5884  }
    5885 
    5886  case value_t::number_float:
    5887  {
    5888  // If the number is an integer then output as a fixed with with
    5889  // precision 1 to output "0.0", "1.0" etc as expected for some
    5890  // round trip tests otherwise 15 digits of precision allows
    5891  // round-trip IEEE 754 string->double->string; to be safe, we
    5892  // read this value from
    5893  // std::numeric_limits<number_float_t>::digits10
    5894  if (std::fmod(m_value.number_float, 1) == 0)
    5895  {
    5896  o << std::fixed << std::setprecision(1);
    5897  }
    5898  else
    5899  {
    5900  // std::defaultfloat not supported in gcc version < 5
    5901  o.unsetf(std::ios_base::floatfield);
    5902  o << std::setprecision(std::numeric_limits<double>::digits10);
    5903  }
    5904  o << m_value.number_float;
    5905  return;
    5906  }
    5907 
    5908  case value_t::discarded:
    5909  {
    5910  o << "<discarded>";
    5911  return;
    5912  }
    5913 
    5914  case value_t::null:
    5915  {
    5916  o << "null";
    5917  return;
    5918  }
    5919  }
    5920  }
    5921 
    5922  private:
    5924  // member variables //
    5926 
    5928  value_t m_type = value_t::null;
    5929 
    5931  json_value m_value = {};
    5932 
    5933 
    5934  private:
    5936  // iterators //
    5938 
    5948  class primitive_iterator_t
    5949  {
    5950  public:
    5952  void set_begin()
    5953  {
    5954  m_it = begin_value;
    5955  }
    5956 
    5958  void set_end()
    5959  {
    5960  m_it = end_value;
    5961  }
    5962 
    5964  bool is_begin() const
    5965  {
    5966  return (m_it == begin_value);
    5967  }
    5968 
    5970  bool is_end() const
    5971  {
    5972  return (m_it == end_value);
    5973  }
    5974 
    5976  operator difference_type& ()
    5977  {
    5978  return m_it;
    5979  }
    5980 
    5982  operator difference_type () const
    5983  {
    5984  return m_it;
    5985  }
    5986 
    5987  private:
    5988  static constexpr difference_type begin_value = 0;
    5989  static constexpr difference_type end_value = begin_value + 1;
    5990 
    5992  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    5993  };
    5994 
    6002  struct internal_iterator
    6003  {
    6005  typename object_t::iterator object_iterator;
    6007  typename array_t::iterator array_iterator;
    6009  primitive_iterator_t primitive_iterator;
    6010 
    6012  internal_iterator()
    6013  : object_iterator(), array_iterator(), primitive_iterator()
    6014  {}
    6015  };
    6016 
    6018  template<typename IteratorType>
    6019  class iteration_proxy
    6020  {
    6021  private:
    6023  class iteration_proxy_internal
    6024  {
    6025  private:
    6027  IteratorType anchor;
    6029  size_t array_index = 0;
    6030 
    6031  public:
    6032  iteration_proxy_internal(IteratorType it)
    6033  : anchor(it)
    6034  {}
    6035 
    6037  iteration_proxy_internal& operator*()
    6038  {
    6039  return *this;
    6040  }
    6041 
    6043  iteration_proxy_internal& operator++()
    6044  {
    6045  ++anchor;
    6046  ++array_index;
    6047 
    6048  return *this;
    6049  }
    6050 
    6052  bool operator!= (const iteration_proxy_internal& o) const
    6053  {
    6054  return anchor != o.anchor;
    6055  }
    6056 
    6058  typename basic_json::string_t key() const
    6059  {
    6060  assert(anchor.m_object != nullptr);
    6061 
    6062  switch (anchor.m_object->type())
    6063  {
    6064  // use integer array index as key
    6065  case value_t::array:
    6066  {
    6067  return std::to_string(array_index);
    6068  }
    6069 
    6070  // use key from the object
    6071  case value_t::object:
    6072  {
    6073  return anchor.key();
    6074  }
    6075 
    6076  // use an empty key for all primitive types
    6077  default:
    6078  {
    6079  return "";
    6080  }
    6081  }
    6082  }
    6083 
    6085  typename IteratorType::reference value() const
    6086  {
    6087  return anchor.value();
    6088  }
    6089  };
    6090 
    6092  typename IteratorType::reference container;
    6093 
    6094  public:
    6096  iteration_proxy(typename IteratorType::reference cont)
    6097  : container(cont)
    6098  {}
    6099 
    6101  iteration_proxy_internal begin()
    6102  {
    6103  return iteration_proxy_internal(container.begin());
    6104  }
    6105 
    6107  iteration_proxy_internal end()
    6108  {
    6109  return iteration_proxy_internal(container.end());
    6110  }
    6111  };
    6112 
    6113  public:
    6127  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6128  {
    6130  friend class basic_json;
    6131 
    6132  public:
    6142  using iterator_category = std::bidirectional_iterator_tag;
    6143 
    6145  const_iterator() = default;
    6146 
    6148  const_iterator(pointer object) : m_object(object)
    6149  {
    6150  assert(m_object != nullptr);
    6151 
    6152  switch (m_object->m_type)
    6153  {
    6155  {
    6156  m_it.object_iterator = typename object_t::iterator();
    6157  break;
    6158  }
    6159 
    6161  {
    6162  m_it.array_iterator = typename array_t::iterator();
    6163  break;
    6164  }
    6165 
    6166  default:
    6167  {
    6168  m_it.primitive_iterator = primitive_iterator_t();
    6169  break;
    6170  }
    6171  }
    6172  }
    6173 
    6175  const_iterator(const iterator& other) : m_object(other.m_object)
    6176  {
    6177  assert(m_object != nullptr);
    6178 
    6179  switch (m_object->m_type)
    6180  {
    6182  {
    6183  m_it.object_iterator = other.m_it.object_iterator;
    6184  break;
    6185  }
    6186 
    6188  {
    6189  m_it.array_iterator = other.m_it.array_iterator;
    6190  break;
    6191  }
    6192 
    6193  default:
    6194  {
    6195  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6196  break;
    6197  }
    6198  }
    6199  }
    6200 
    6202  const_iterator(const const_iterator& other) noexcept
    6203  : m_object(other.m_object), m_it(other.m_it)
    6204  {}
    6205 
    6208  std::is_nothrow_move_constructible<pointer>::value and
    6209  std::is_nothrow_move_assignable<pointer>::value and
    6210  std::is_nothrow_move_constructible<internal_iterator>::value and
    6211  std::is_nothrow_move_assignable<internal_iterator>::value
    6212  )
    6213  {
    6214  std::swap(m_object, other.m_object);
    6215  std::swap(m_it, other.m_it);
    6216  return *this;
    6217  }
    6218 
    6219  private:
    6221  void set_begin()
    6222  {
    6223  assert(m_object != nullptr);
    6224 
    6225  switch (m_object->m_type)
    6226  {
    6228  {
    6229  assert(m_object->m_value.object != nullptr);
    6230  m_it.object_iterator = m_object->m_value.object->begin();
    6231  break;
    6232  }
    6233 
    6235  {
    6236  assert(m_object->m_value.array != nullptr);
    6237  m_it.array_iterator = m_object->m_value.array->begin();
    6238  break;
    6239  }
    6240 
    6242  {
    6243  // set to end so begin()==end() is true: null is empty
    6244  m_it.primitive_iterator.set_end();
    6245  break;
    6246  }
    6247 
    6248  default:
    6249  {
    6250  m_it.primitive_iterator.set_begin();
    6251  break;
    6252  }
    6253  }
    6254  }
    6255 
    6257  void set_end()
    6258  {
    6259  assert(m_object != nullptr);
    6260 
    6261  switch (m_object->m_type)
    6262  {
    6264  {
    6265  assert(m_object->m_value.object != nullptr);
    6266  m_it.object_iterator = m_object->m_value.object->end();
    6267  break;
    6268  }
    6269 
    6271  {
    6272  assert(m_object->m_value.array != nullptr);
    6273  m_it.array_iterator = m_object->m_value.array->end();
    6274  break;
    6275  }
    6276 
    6277  default:
    6278  {
    6279  m_it.primitive_iterator.set_end();
    6280  break;
    6281  }
    6282  }
    6283  }
    6284 
    6285  public:
    6288  {
    6289  assert(m_object != nullptr);
    6290 
    6291  switch (m_object->m_type)
    6292  {
    6294  {
    6295  assert(m_object->m_value.object);
    6296  assert(m_it.object_iterator != m_object->m_value.object->end());
    6297  return m_it.object_iterator->second;
    6298  }
    6299 
    6301  {
    6302  assert(m_object->m_value.array);
    6303  assert(m_it.array_iterator != m_object->m_value.array->end());
    6304  return *m_it.array_iterator;
    6305  }
    6306 
    6308  {
    6309  throw std::out_of_range("cannot get value");
    6310  }
    6311 
    6312  default:
    6313  {
    6314  if (m_it.primitive_iterator.is_begin())
    6315  {
    6316  return *m_object;
    6317  }
    6318  else
    6319  {
    6320  throw std::out_of_range("cannot get value");
    6321  }
    6322  }
    6323  }
    6324  }
    6325 
    6328  {
    6329  assert(m_object != nullptr);
    6330 
    6331  switch (m_object->m_type)
    6332  {
    6334  {
    6335  assert(m_object->m_value.object);
    6336  assert(m_it.object_iterator != m_object->m_value.object->end());
    6337  return &(m_it.object_iterator->second);
    6338  }
    6339 
    6341  {
    6342  assert(m_object->m_value.array);
    6343  assert(m_it.array_iterator != m_object->m_value.array->end());
    6344  return &*m_it.array_iterator;
    6345  }
    6346 
    6347  default:
    6348  {
    6349  if (m_it.primitive_iterator.is_begin())
    6350  {
    6351  return m_object;
    6352  }
    6353  else
    6354  {
    6355  throw std::out_of_range("cannot get value");
    6356  }
    6357  }
    6358  }
    6359  }
    6360 
    6363  {
    6364  auto result = *this;
    6365  ++(*this);
    6366  return result;
    6367  }
    6368 
    6371  {
    6372  assert(m_object != nullptr);
    6373 
    6374  switch (m_object->m_type)
    6375  {
    6377  {
    6378  ++m_it.object_iterator;
    6379  break;
    6380  }
    6381 
    6383  {
    6384  ++m_it.array_iterator;
    6385  break;
    6386  }
    6387 
    6388  default:
    6389  {
    6390  ++m_it.primitive_iterator;
    6391  break;
    6392  }
    6393  }
    6394 
    6395  return *this;
    6396  }
    6397 
    6400  {
    6401  auto result = *this;
    6402  --(*this);
    6403  return result;
    6404  }
    6405 
    6408  {
    6409  assert(m_object != nullptr);
    6410 
    6411  switch (m_object->m_type)
    6412  {
    6414  {
    6415  --m_it.object_iterator;
    6416  break;
    6417  }
    6418 
    6420  {
    6421  --m_it.array_iterator;
    6422  break;
    6423  }
    6424 
    6425  default:
    6426  {
    6427  --m_it.primitive_iterator;
    6428  break;
    6429  }
    6430  }
    6431 
    6432  return *this;
    6433  }
    6434 
    6436  bool operator==(const const_iterator& other) const
    6437  {
    6438  // if objects are not the same, the comparison is undefined
    6439  if (m_object != other.m_object)
    6440  {
    6441  throw std::domain_error("cannot compare iterators of different containers");
    6442  }
    6443 
    6444  assert(m_object != nullptr);
    6445 
    6446  switch (m_object->m_type)
    6447  {
    6449  {
    6450  return (m_it.object_iterator == other.m_it.object_iterator);
    6451  }
    6452 
    6454  {
    6455  return (m_it.array_iterator == other.m_it.array_iterator);
    6456  }
    6457 
    6458  default:
    6459  {
    6460  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6461  }
    6462  }
    6463  }
    6464 
    6466  bool operator!=(const const_iterator& other) const
    6467  {
    6468  return not operator==(other);
    6469  }
    6470 
    6472  bool operator<(const const_iterator& other) const
    6473  {
    6474  // if objects are not the same, the comparison is undefined
    6475  if (m_object != other.m_object)
    6476  {
    6477  throw std::domain_error("cannot compare iterators of different containers");
    6478  }
    6479 
    6480  assert(m_object != nullptr);
    6481 
    6482  switch (m_object->m_type)
    6483  {
    6485  {
    6486  throw std::domain_error("cannot compare order of object iterators");
    6487  }
    6488 
    6490  {
    6491  return (m_it.array_iterator < other.m_it.array_iterator);
    6492  }
    6493 
    6494  default:
    6495  {
    6496  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6497  }
    6498  }
    6499  }
    6500 
    6502  bool operator<=(const const_iterator& other) const
    6503  {
    6504  return not other.operator < (*this);
    6505  }
    6506 
    6508  bool operator>(const const_iterator& other) const
    6509  {
    6510  return not operator<=(other);
    6511  }
    6512 
    6514  bool operator>=(const const_iterator& other) const
    6515  {
    6516  return not operator<(other);
    6517  }
    6518 
    6521  {
    6522  assert(m_object != nullptr);
    6523 
    6524  switch (m_object->m_type)
    6525  {
    6527  {
    6528  throw std::domain_error("cannot use offsets with object iterators");
    6529  }
    6530 
    6532  {
    6533  m_it.array_iterator += i;
    6534  break;
    6535  }
    6536 
    6537  default:
    6538  {
    6539  m_it.primitive_iterator += i;
    6540  break;
    6541  }
    6542  }
    6543 
    6544  return *this;
    6545  }
    6546 
    6549  {
    6550  return operator+=(-i);
    6551  }
    6552 
    6555  {
    6556  auto result = *this;
    6557  result += i;
    6558  return result;
    6559  }
    6560 
    6563  {
    6564  auto result = *this;
    6565  result -= i;
    6566  return result;
    6567  }
    6568 
    6571  {
    6572  assert(m_object != nullptr);
    6573 
    6574  switch (m_object->m_type)
    6575  {
    6577  {
    6578  throw std::domain_error("cannot use offsets with object iterators");
    6579  }
    6580 
    6582  {
    6583  return m_it.array_iterator - other.m_it.array_iterator;
    6584  }
    6585 
    6586  default:
    6587  {
    6588  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6589  }
    6590  }
    6591  }
    6592 
    6595  {
    6596  assert(m_object != nullptr);
    6597 
    6598  switch (m_object->m_type)
    6599  {
    6601  {
    6602  throw std::domain_error("cannot use operator[] for object iterators");
    6603  }
    6604 
    6606  {
    6607  return *(m_it.array_iterator + n);
    6608  }
    6609 
    6611  {
    6612  throw std::out_of_range("cannot get value");
    6613  }
    6614 
    6615  default:
    6616  {
    6617  if (m_it.primitive_iterator == -n)
    6618  {
    6619  return *m_object;
    6620  }
    6621  else
    6622  {
    6623  throw std::out_of_range("cannot get value");
    6624  }
    6625  }
    6626  }
    6627  }
    6628 
    6630  typename object_t::key_type key() const
    6631  {
    6632  assert(m_object != nullptr);
    6633 
    6634  if (m_object->is_object())
    6635  {
    6636  return m_it.object_iterator->first;
    6637  }
    6638  else
    6639  {
    6640  throw std::domain_error("cannot use key() for non-object iterators");
    6641  }
    6642  }
    6643 
    6646  {
    6647  return operator*();
    6648  }
    6649 
    6650  private:
    6652  pointer m_object = nullptr;
    6654  internal_iterator m_it = internal_iterator();
    6655  };
    6656 
    6669  class iterator : public const_iterator
    6670  {
    6671  public:
    6673  using pointer = typename basic_json::pointer;
    6675 
    6677  iterator() = default;
    6678 
    6680  iterator(pointer object) noexcept
    6681  : base_iterator(object)
    6682  {}
    6683 
    6685  iterator(const iterator& other) noexcept
    6686  : base_iterator(other)
    6687  {}
    6688 
    6690  iterator& operator=(iterator other) noexcept(
    6691  std::is_nothrow_move_constructible<pointer>::value and
    6692  std::is_nothrow_move_assignable<pointer>::value and
    6693  std::is_nothrow_move_constructible<internal_iterator>::value and
    6694  std::is_nothrow_move_assignable<internal_iterator>::value
    6695  )
    6696  {
    6697  base_iterator::operator=(other);
    6698  return *this;
    6699  }
    6700 
    6703  {
    6704  return const_cast<reference>(base_iterator::operator*());
    6705  }
    6706 
    6709  {
    6710  return const_cast<pointer>(base_iterator::operator->());
    6711  }
    6712 
    6715  {
    6716  iterator result = *this;
    6717  base_iterator::operator++();
    6718  return result;
    6719  }
    6720 
    6723  {
    6724  base_iterator::operator++();
    6725  return *this;
    6726  }
    6727 
    6730  {
    6731  iterator result = *this;
    6732  base_iterator::operator--();
    6733  return result;
    6734  }
    6735 
    6738  {
    6739  base_iterator::operator--();
    6740  return *this;
    6741  }
    6742 
    6745  {
    6746  base_iterator::operator+=(i);
    6747  return *this;
    6748  }
    6749 
    6752  {
    6753  base_iterator::operator-=(i);
    6754  return *this;
    6755  }
    6756 
    6759  {
    6760  auto result = *this;
    6761  result += i;
    6762  return result;
    6763  }
    6764 
    6767  {
    6768  auto result = *this;
    6769  result -= i;
    6770  return result;
    6771  }
    6772 
    6773  difference_type operator-(const iterator& other) const
    6774  {
    6775  return base_iterator::operator-(other);
    6776  }
    6777 
    6780  {
    6781  return const_cast<reference>(base_iterator::operator[](n));
    6782  }
    6783 
    6786  {
    6787  return const_cast<reference>(base_iterator::value());
    6788  }
    6789  };
    6790 
    6808  template<typename Base>
    6809  class json_reverse_iterator : public std::reverse_iterator<Base>
    6810  {
    6811  public:
    6813  using base_iterator = std::reverse_iterator<Base>;
    6815  using reference = typename Base::reference;
    6816 
    6818  json_reverse_iterator(const typename base_iterator::iterator_type& it)
    6819  : base_iterator(it)
    6820  {}
    6821 
    6824  : base_iterator(it)
    6825  {}
    6826 
    6829  {
    6830  return base_iterator::operator++(1);
    6831  }
    6832 
    6835  {
    6836  base_iterator::operator++();
    6837  return *this;
    6838  }
    6839 
    6842  {
    6843  return base_iterator::operator--(1);
    6844  }
    6845 
    6848  {
    6849  base_iterator::operator--();
    6850  return *this;
    6851  }
    6852 
    6855  {
    6856  base_iterator::operator+=(i);
    6857  return *this;
    6858  }
    6859 
    6862  {
    6863  auto result = *this;
    6864  result += i;
    6865  return result;
    6866  }
    6867 
    6870  {
    6871  auto result = *this;
    6872  result -= i;
    6873  return result;
    6874  }
    6875 
    6878  {
    6879  return this->base() - other.base();
    6880  }
    6881 
    6884  {
    6885  return *(this->operator+(n));
    6886  }
    6887 
    6889  typename object_t::key_type key() const
    6890  {
    6891  auto it = --this->base();
    6892  return it.key();
    6893  }
    6894 
    6897  {
    6898  auto it = --this->base();
    6899  return it.operator * ();
    6900  }
    6901  };
    6902 
    6903 
    6904  private:
    6906  // lexer and parser //
    6908 
    6916  class lexer
    6917  {
    6918  public:
    6920  enum class token_type
    6921  {
    6922  uninitialized,
    6923  literal_true,
    6924  literal_false,
    6925  literal_null,
    6926  value_string,
    6927  value_number,
    6928  begin_array,
    6929  begin_object,
    6930  end_array,
    6931  end_object,
    6932  name_separator,
    6933  value_separator,
    6934  parse_error,
    6935  end_of_input
    6936  };
    6937 
    6939  using lexer_char_t = unsigned char;
    6940 
    6942  explicit lexer(const string_t& s) noexcept
    6943  : m_stream(nullptr), m_buffer(s)
    6944  {
    6945  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    6946  assert(m_content != nullptr);
    6947  m_start = m_cursor = m_content;
    6948  m_limit = m_content + s.size();
    6949  }
    6950 
    6952  explicit lexer(std::istream* s) noexcept
    6953  : m_stream(s), m_buffer()
    6954  {
    6955  assert(m_stream != nullptr);
    6956  getline(*m_stream, m_buffer);
    6957  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    6958  assert(m_content != nullptr);
    6959  m_start = m_cursor = m_content;
    6960  m_limit = m_content + m_buffer.size();
    6961  }
    6962 
    6964  lexer() = default;
    6965 
    6966  // switch off unwanted functions
    6967  lexer(const lexer&) = delete;
    6968  lexer operator=(const lexer&) = delete;
    6969 
    6985  static string_t to_unicode(const std::size_t codepoint1,
    6986  const std::size_t codepoint2 = 0)
    6987  {
    6988  string_t result;
    6989 
    6990  // calculate the codepoint from the given code points
    6991  std::size_t codepoint = codepoint1;
    6992 
    6993  // check if codepoint1 is a high surrogate
    6994  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    6995  {
    6996  // check if codepoint2 is a low surrogate
    6997  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    6998  {
    6999  codepoint =
    7000  // high surrogate occupies the most significant 22 bits
    7001  (codepoint1 << 10)
    7002  // low surrogate occupies the least significant 15 bits
    7003  + codepoint2
    7004  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7005  // in the result so we have to subtract with:
    7006  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7007  - 0x35FDC00;
    7008  }
    7009  else
    7010  {
    7011  throw std::invalid_argument("missing or wrong low surrogate");
    7012  }
    7013  }
    7014 
    7015  if (codepoint < 0x80)
    7016  {
    7017  // 1-byte characters: 0xxxxxxx (ASCII)
    7018  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7019  }
    7020  else if (codepoint <= 0x7ff)
    7021  {
    7022  // 2-byte characters: 110xxxxx 10xxxxxx
    7023  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7024  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7025  }
    7026  else if (codepoint <= 0xffff)
    7027  {
    7028  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7029  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7030  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7031  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7032  }
    7033  else if (codepoint <= 0x10ffff)
    7034  {
    7035  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7036  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7037  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7038  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7039  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7040  }
    7041  else
    7042  {
    7043  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7044  }
    7045 
    7046  return result;
    7047  }
    7048 
    7050  static std::string token_type_name(token_type t)
    7051  {
    7052  switch (t)
    7053  {
    7054  case token_type::uninitialized:
    7055  return "<uninitialized>";
    7056  case token_type::literal_true:
    7057  return "true literal";
    7058  case token_type::literal_false:
    7059  return "false literal";
    7060  case token_type::literal_null:
    7061  return "null literal";
    7062  case token_type::value_string:
    7063  return "string literal";
    7064  case token_type::value_number:
    7065  return "number literal";
    7066  case token_type::begin_array:
    7067  return "'['";
    7068  case token_type::begin_object:
    7069  return "'{'";
    7070  case token_type::end_array:
    7071  return "']'";
    7072  case token_type::end_object:
    7073  return "'}'";
    7074  case token_type::name_separator:
    7075  return "':'";
    7076  case token_type::value_separator:
    7077  return "','";
    7078  case token_type::parse_error:
    7079  return "<parse error>";
    7080  case token_type::end_of_input:
    7081  return "end of input";
    7082  default:
    7083  {
    7084  // catch non-enum values
    7085  return "unknown token"; // LCOV_EXCL_LINE
    7086  }
    7087  }
    7088  }
    7089 
    7100  token_type scan() noexcept
    7101  {
    7102  // pointer for backtracking information
    7103  m_marker = nullptr;
    7104 
    7105  // remember the begin of the token
    7106  m_start = m_cursor;
    7107  assert(m_start != nullptr);
    7108 
    7109 
    7110  {
    7111  lexer_char_t yych;
    7112  unsigned int yyaccept = 0;
    7113  static const unsigned char yybm[] =
    7114  {
    7115  0, 0, 0, 0, 0, 0, 0, 0,
    7116  0, 32, 32, 0, 0, 32, 0, 0,
    7117  64, 64, 64, 64, 64, 64, 64, 64,
    7118  64, 64, 64, 64, 64, 64, 64, 64,
    7119  96, 64, 0, 64, 64, 64, 64, 64,
    7120  64, 64, 64, 64, 64, 64, 64, 64,
    7121  192, 192, 192, 192, 192, 192, 192, 192,
    7122  192, 192, 64, 64, 64, 64, 64, 64,
    7123  64, 64, 64, 64, 64, 64, 64, 64,
    7124  64, 64, 64, 64, 64, 64, 64, 64,
    7125  64, 64, 64, 64, 64, 64, 64, 64,
    7126  64, 64, 64, 64, 0, 64, 64, 64,
    7127  64, 64, 64, 64, 64, 64, 64, 64,
    7128  64, 64, 64, 64, 64, 64, 64, 64,
    7129  64, 64, 64, 64, 64, 64, 64, 64,
    7130  64, 64, 64, 64, 64, 64, 64, 64,
    7131  64, 64, 64, 64, 64, 64, 64, 64,
    7132  64, 64, 64, 64, 64, 64, 64, 64,
    7133  64, 64, 64, 64, 64, 64, 64, 64,
    7134  64, 64, 64, 64, 64, 64, 64, 64,
    7135  64, 64, 64, 64, 64, 64, 64, 64,
    7136  64, 64, 64, 64, 64, 64, 64, 64,
    7137  64, 64, 64, 64, 64, 64, 64, 64,
    7138  64, 64, 64, 64, 64, 64, 64, 64,
    7139  64, 64, 64, 64, 64, 64, 64, 64,
    7140  64, 64, 64, 64, 64, 64, 64, 64,
    7141  64, 64, 64, 64, 64, 64, 64, 64,
    7142  64, 64, 64, 64, 64, 64, 64, 64,
    7143  64, 64, 64, 64, 64, 64, 64, 64,
    7144  64, 64, 64, 64, 64, 64, 64, 64,
    7145  64, 64, 64, 64, 64, 64, 64, 64,
    7146  64, 64, 64, 64, 64, 64, 64, 64,
    7147  };
    7148  if ((m_limit - m_cursor) < 5)
    7149  {
    7150  yyfill(); // LCOV_EXCL_LINE;
    7151  }
    7152  yych = *m_cursor;
    7153  if (yych <= ':')
    7154  {
    7155  if (yych <= ' ')
    7156  {
    7157  if (yych <= '\n')
    7158  {
    7159  if (yych <= 0x00)
    7160  {
    7161  goto basic_json_parser_28;
    7162  }
    7163  if (yych <= 0x08)
    7164  {
    7165  goto basic_json_parser_30;
    7166  }
    7167  if (yych >= '\n')
    7168  {
    7169  goto basic_json_parser_4;
    7170  }
    7171  }
    7172  else
    7173  {
    7174  if (yych == '\r')
    7175  {
    7176  goto basic_json_parser_2;
    7177  }
    7178  if (yych <= 0x1F)
    7179  {
    7180  goto basic_json_parser_30;
    7181  }
    7182  }
    7183  }
    7184  else
    7185  {
    7186  if (yych <= ',')
    7187  {
    7188  if (yych == '"')
    7189  {
    7190  goto basic_json_parser_27;
    7191  }
    7192  if (yych <= '+')
    7193  {
    7194  goto basic_json_parser_30;
    7195  }
    7196  goto basic_json_parser_16;
    7197  }
    7198  else
    7199  {
    7200  if (yych <= '/')
    7201  {
    7202  if (yych <= '-')
    7203  {
    7204  goto basic_json_parser_23;
    7205  }
    7206  goto basic_json_parser_30;
    7207  }
    7208  else
    7209  {
    7210  if (yych <= '0')
    7211  {
    7212  goto basic_json_parser_24;
    7213  }
    7214  if (yych <= '9')
    7215  {
    7216  goto basic_json_parser_26;
    7217  }
    7218  goto basic_json_parser_18;
    7219  }
    7220  }
    7221  }
    7222  }
    7223  else
    7224  {
    7225  if (yych <= 'n')
    7226  {
    7227  if (yych <= ']')
    7228  {
    7229  if (yych == '[')
    7230  {
    7231  goto basic_json_parser_8;
    7232  }
    7233  if (yych <= '\\')
    7234  {
    7235  goto basic_json_parser_30;
    7236  }
    7237  goto basic_json_parser_10;
    7238  }
    7239  else
    7240  {
    7241  if (yych == 'f')
    7242  {
    7243  goto basic_json_parser_22;
    7244  }
    7245  if (yych <= 'm')
    7246  {
    7247  goto basic_json_parser_30;
    7248  }
    7249  goto basic_json_parser_20;
    7250  }
    7251  }
    7252  else
    7253  {
    7254  if (yych <= '{')
    7255  {
    7256  if (yych == 't')
    7257  {
    7258  goto basic_json_parser_21;
    7259  }
    7260  if (yych <= 'z')
    7261  {
    7262  goto basic_json_parser_30;
    7263  }
    7264  goto basic_json_parser_12;
    7265  }
    7266  else
    7267  {
    7268  if (yych <= '}')
    7269  {
    7270  if (yych <= '|')
    7271  {
    7272  goto basic_json_parser_30;
    7273  }
    7274  goto basic_json_parser_14;
    7275  }
    7276  else
    7277  {
    7278  if (yych == 0xEF)
    7279  {
    7280  goto basic_json_parser_6;
    7281  }
    7282  goto basic_json_parser_30;
    7283  }
    7284  }
    7285  }
    7286  }
    7287 basic_json_parser_2:
    7288  ++m_cursor;
    7289  yych = *m_cursor;
    7290  goto basic_json_parser_5;
    7291 basic_json_parser_3:
    7292  {
    7293  return scan();
    7294  }
    7295 basic_json_parser_4:
    7296  ++m_cursor;
    7297  if (m_limit <= m_cursor)
    7298  {
    7299  yyfill(); // LCOV_EXCL_LINE;
    7300  }
    7301  yych = *m_cursor;
    7302 basic_json_parser_5:
    7303  if (yybm[0 + yych] & 32)
    7304  {
    7305  goto basic_json_parser_4;
    7306  }
    7307  goto basic_json_parser_3;
    7308 basic_json_parser_6:
    7309  yyaccept = 0;
    7310  yych = *(m_marker = ++m_cursor);
    7311  if (yych == 0xBB)
    7312  {
    7313  goto basic_json_parser_64;
    7314  }
    7315 basic_json_parser_7:
    7316  {
    7317  return token_type::parse_error;
    7318  }
    7319 basic_json_parser_8:
    7320  ++m_cursor;
    7321  {
    7322  return token_type::begin_array;
    7323  }
    7324 basic_json_parser_10:
    7325  ++m_cursor;
    7326  {
    7327  return token_type::end_array;
    7328  }
    7329 basic_json_parser_12:
    7330  ++m_cursor;
    7331  {
    7332  return token_type::begin_object;
    7333  }
    7334 basic_json_parser_14:
    7335  ++m_cursor;
    7336  {
    7337  return token_type::end_object;
    7338  }
    7339 basic_json_parser_16:
    7340  ++m_cursor;
    7341  {
    7342  return token_type::value_separator;
    7343  }
    7344 basic_json_parser_18:
    7345  ++m_cursor;
    7346  {
    7347  return token_type::name_separator;
    7348  }
    7349 basic_json_parser_20:
    7350  yyaccept = 0;
    7351  yych = *(m_marker = ++m_cursor);
    7352  if (yych == 'u')
    7353  {
    7354  goto basic_json_parser_60;
    7355  }
    7356  goto basic_json_parser_7;
    7357 basic_json_parser_21:
    7358  yyaccept = 0;
    7359  yych = *(m_marker = ++m_cursor);
    7360  if (yych == 'r')
    7361  {
    7362  goto basic_json_parser_56;
    7363  }
    7364  goto basic_json_parser_7;
    7365 basic_json_parser_22:
    7366  yyaccept = 0;
    7367  yych = *(m_marker = ++m_cursor);
    7368  if (yych == 'a')
    7369  {
    7370  goto basic_json_parser_51;
    7371  }
    7372  goto basic_json_parser_7;
    7373 basic_json_parser_23:
    7374  yych = *++m_cursor;
    7375  if (yych <= '/')
    7376  {
    7377  goto basic_json_parser_7;
    7378  }
    7379  if (yych <= '0')
    7380  {
    7381  goto basic_json_parser_50;
    7382  }
    7383  if (yych <= '9')
    7384  {
    7385  goto basic_json_parser_41;
    7386  }
    7387  goto basic_json_parser_7;
    7388 basic_json_parser_24:
    7389  yyaccept = 1;
    7390  yych = *(m_marker = ++m_cursor);
    7391  if (yych <= 'D')
    7392  {
    7393  if (yych == '.')
    7394  {
    7395  goto basic_json_parser_43;
    7396  }
    7397  }
    7398  else
    7399  {
    7400  if (yych <= 'E')
    7401  {
    7402  goto basic_json_parser_44;
    7403  }
    7404  if (yych == 'e')
    7405  {
    7406  goto basic_json_parser_44;
    7407  }
    7408  }
    7409 basic_json_parser_25:
    7410  {
    7411  return token_type::value_number;
    7412  }
    7413 basic_json_parser_26:
    7414  yyaccept = 1;
    7415  yych = *(m_marker = ++m_cursor);
    7416  goto basic_json_parser_42;
    7417 basic_json_parser_27:
    7418  yyaccept = 0;
    7419  yych = *(m_marker = ++m_cursor);
    7420  if (yych <= 0x0F)
    7421  {
    7422  goto basic_json_parser_7;
    7423  }
    7424  goto basic_json_parser_32;
    7425 basic_json_parser_28:
    7426  ++m_cursor;
    7427  {
    7428  return token_type::end_of_input;
    7429  }
    7430 basic_json_parser_30:
    7431  yych = *++m_cursor;
    7432  goto basic_json_parser_7;
    7433 basic_json_parser_31:
    7434  ++m_cursor;
    7435  if (m_limit <= m_cursor)
    7436  {
    7437  yyfill(); // LCOV_EXCL_LINE;
    7438  }
    7439  yych = *m_cursor;
    7440 basic_json_parser_32:
    7441  if (yybm[0 + yych] & 64)
    7442  {
    7443  goto basic_json_parser_31;
    7444  }
    7445  if (yych <= 0x0F)
    7446  {
    7447  goto basic_json_parser_33;
    7448  }
    7449  if (yych <= '"')
    7450  {
    7451  goto basic_json_parser_35;
    7452  }
    7453  goto basic_json_parser_34;
    7454 basic_json_parser_33:
    7455  m_cursor = m_marker;
    7456  if (yyaccept == 0)
    7457  {
    7458  goto basic_json_parser_7;
    7459  }
    7460  else
    7461  {
    7462  goto basic_json_parser_25;
    7463  }
    7464 basic_json_parser_34:
    7465  ++m_cursor;
    7466  if (m_limit <= m_cursor)
    7467  {
    7468  yyfill(); // LCOV_EXCL_LINE;
    7469  }
    7470  yych = *m_cursor;
    7471  if (yych <= 'e')
    7472  {
    7473  if (yych <= '/')
    7474  {
    7475  if (yych == '"')
    7476  {
    7477  goto basic_json_parser_31;
    7478  }
    7479  if (yych <= '.')
    7480  {
    7481  goto basic_json_parser_33;
    7482  }
    7483  goto basic_json_parser_31;
    7484  }
    7485  else
    7486  {
    7487  if (yych <= '\\')
    7488  {
    7489  if (yych <= '[')
    7490  {
    7491  goto basic_json_parser_33;
    7492  }
    7493  goto basic_json_parser_31;
    7494  }
    7495  else
    7496  {
    7497  if (yych == 'b')
    7498  {
    7499  goto basic_json_parser_31;
    7500  }
    7501  goto basic_json_parser_33;
    7502  }
    7503  }
    7504  }
    7505  else
    7506  {
    7507  if (yych <= 'q')
    7508  {
    7509  if (yych <= 'f')
    7510  {
    7511  goto basic_json_parser_31;
    7512  }
    7513  if (yych == 'n')
    7514  {
    7515  goto basic_json_parser_31;
    7516  }
    7517  goto basic_json_parser_33;
    7518  }
    7519  else
    7520  {
    7521  if (yych <= 's')
    7522  {
    7523  if (yych <= 'r')
    7524  {
    7525  goto basic_json_parser_31;
    7526  }
    7527  goto basic_json_parser_33;
    7528  }
    7529  else
    7530  {
    7531  if (yych <= 't')
    7532  {
    7533  goto basic_json_parser_31;
    7534  }
    7535  if (yych <= 'u')
    7536  {
    7537  goto basic_json_parser_37;
    7538  }
    7539  goto basic_json_parser_33;
    7540  }
    7541  }
    7542  }
    7543 basic_json_parser_35:
    7544  ++m_cursor;
    7545  {
    7546  return token_type::value_string;
    7547  }
    7548 basic_json_parser_37:
    7549  ++m_cursor;
    7550  if (m_limit <= m_cursor)
    7551  {
    7552  yyfill(); // LCOV_EXCL_LINE;
    7553  }
    7554  yych = *m_cursor;
    7555  if (yych <= '@')
    7556  {
    7557  if (yych <= '/')
    7558  {
    7559  goto basic_json_parser_33;
    7560  }
    7561  if (yych >= ':')
    7562  {
    7563  goto basic_json_parser_33;
    7564  }
    7565  }
    7566  else
    7567  {
    7568  if (yych <= 'F')
    7569  {
    7570  goto basic_json_parser_38;
    7571  }
    7572  if (yych <= '`')
    7573  {
    7574  goto basic_json_parser_33;
    7575  }
    7576  if (yych >= 'g')
    7577  {
    7578  goto basic_json_parser_33;
    7579  }
    7580  }
    7581 basic_json_parser_38:
    7582  ++m_cursor;
    7583  if (m_limit <= m_cursor)
    7584  {
    7585  yyfill(); // LCOV_EXCL_LINE;
    7586  }
    7587  yych = *m_cursor;
    7588  if (yych <= '@')
    7589  {
    7590  if (yych <= '/')
    7591  {
    7592  goto basic_json_parser_33;
    7593  }
    7594  if (yych >= ':')
    7595  {
    7596  goto basic_json_parser_33;
    7597  }
    7598  }
    7599  else
    7600  {
    7601  if (yych <= 'F')
    7602  {
    7603  goto basic_json_parser_39;
    7604  }
    7605  if (yych <= '`')
    7606  {
    7607  goto basic_json_parser_33;
    7608  }
    7609  if (yych >= 'g')
    7610  {
    7611  goto basic_json_parser_33;
    7612  }
    7613  }
    7614 basic_json_parser_39:
    7615  ++m_cursor;
    7616  if (m_limit <= m_cursor)
    7617  {
    7618  yyfill(); // LCOV_EXCL_LINE;
    7619  }
    7620  yych = *m_cursor;
    7621  if (yych <= '@')
    7622  {
    7623  if (yych <= '/')
    7624  {
    7625  goto basic_json_parser_33;
    7626  }
    7627  if (yych >= ':')
    7628  {
    7629  goto basic_json_parser_33;
    7630  }
    7631  }
    7632  else
    7633  {
    7634  if (yych <= 'F')
    7635  {
    7636  goto basic_json_parser_40;
    7637  }
    7638  if (yych <= '`')
    7639  {
    7640  goto basic_json_parser_33;
    7641  }
    7642  if (yych >= 'g')
    7643  {
    7644  goto basic_json_parser_33;
    7645  }
    7646  }
    7647 basic_json_parser_40:
    7648  ++m_cursor;
    7649  if (m_limit <= m_cursor)
    7650  {
    7651  yyfill(); // LCOV_EXCL_LINE;
    7652  }
    7653  yych = *m_cursor;
    7654  if (yych <= '@')
    7655  {
    7656  if (yych <= '/')
    7657  {
    7658  goto basic_json_parser_33;
    7659  }
    7660  if (yych <= '9')
    7661  {
    7662  goto basic_json_parser_31;
    7663  }
    7664  goto basic_json_parser_33;
    7665  }
    7666  else
    7667  {
    7668  if (yych <= 'F')
    7669  {
    7670  goto basic_json_parser_31;
    7671  }
    7672  if (yych <= '`')
    7673  {
    7674  goto basic_json_parser_33;
    7675  }
    7676  if (yych <= 'f')
    7677  {
    7678  goto basic_json_parser_31;
    7679  }
    7680  goto basic_json_parser_33;
    7681  }
    7682 basic_json_parser_41:
    7683  yyaccept = 1;
    7684  m_marker = ++m_cursor;
    7685  if ((m_limit - m_cursor) < 3)
    7686  {
    7687  yyfill(); // LCOV_EXCL_LINE;
    7688  }
    7689  yych = *m_cursor;
    7690 basic_json_parser_42:
    7691  if (yybm[0 + yych] & 128)
    7692  {
    7693  goto basic_json_parser_41;
    7694  }
    7695  if (yych <= 'D')
    7696  {
    7697  if (yych != '.')
    7698  {
    7699  goto basic_json_parser_25;
    7700  }
    7701  }
    7702  else
    7703  {
    7704  if (yych <= 'E')
    7705  {
    7706  goto basic_json_parser_44;
    7707  }
    7708  if (yych == 'e')
    7709  {
    7710  goto basic_json_parser_44;
    7711  }
    7712  goto basic_json_parser_25;
    7713  }
    7714 basic_json_parser_43:
    7715  yych = *++m_cursor;
    7716  if (yych <= '/')
    7717  {
    7718  goto basic_json_parser_33;
    7719  }
    7720  if (yych <= '9')
    7721  {
    7722  goto basic_json_parser_48;
    7723  }
    7724  goto basic_json_parser_33;
    7725 basic_json_parser_44:
    7726  yych = *++m_cursor;
    7727  if (yych <= ',')
    7728  {
    7729  if (yych != '+')
    7730  {
    7731  goto basic_json_parser_33;
    7732  }
    7733  }
    7734  else
    7735  {
    7736  if (yych <= '-')
    7737  {
    7738  goto basic_json_parser_45;
    7739  }
    7740  if (yych <= '/')
    7741  {
    7742  goto basic_json_parser_33;
    7743  }
    7744  if (yych <= '9')
    7745  {
    7746  goto basic_json_parser_46;
    7747  }
    7748  goto basic_json_parser_33;
    7749  }
    7750 basic_json_parser_45:
    7751  yych = *++m_cursor;
    7752  if (yych <= '/')
    7753  {
    7754  goto basic_json_parser_33;
    7755  }
    7756  if (yych >= ':')
    7757  {
    7758  goto basic_json_parser_33;
    7759  }
    7760 basic_json_parser_46:
    7761  ++m_cursor;
    7762  if (m_limit <= m_cursor)
    7763  {
    7764  yyfill(); // LCOV_EXCL_LINE;
    7765  }
    7766  yych = *m_cursor;
    7767  if (yych <= '/')
    7768  {
    7769  goto basic_json_parser_25;
    7770  }
    7771  if (yych <= '9')
    7772  {
    7773  goto basic_json_parser_46;
    7774  }
    7775  goto basic_json_parser_25;
    7776 basic_json_parser_48:
    7777  yyaccept = 1;
    7778  m_marker = ++m_cursor;
    7779  if ((m_limit - m_cursor) < 3)
    7780  {
    7781  yyfill(); // LCOV_EXCL_LINE;
    7782  }
    7783  yych = *m_cursor;
    7784  if (yych <= 'D')
    7785  {
    7786  if (yych <= '/')
    7787  {
    7788  goto basic_json_parser_25;
    7789  }
    7790  if (yych <= '9')
    7791  {
    7792  goto basic_json_parser_48;
    7793  }
    7794  goto basic_json_parser_25;
    7795  }
    7796  else
    7797  {
    7798  if (yych <= 'E')
    7799  {
    7800  goto basic_json_parser_44;
    7801  }
    7802  if (yych == 'e')
    7803  {
    7804  goto basic_json_parser_44;
    7805  }
    7806  goto basic_json_parser_25;
    7807  }
    7808 basic_json_parser_50:
    7809  yyaccept = 1;
    7810  yych = *(m_marker = ++m_cursor);
    7811  if (yych <= 'D')
    7812  {
    7813  if (yych == '.')
    7814  {
    7815  goto basic_json_parser_43;
    7816  }
    7817  goto basic_json_parser_25;
    7818  }
    7819  else
    7820  {
    7821  if (yych <= 'E')
    7822  {
    7823  goto basic_json_parser_44;
    7824  }
    7825  if (yych == 'e')
    7826  {
    7827  goto basic_json_parser_44;
    7828  }
    7829  goto basic_json_parser_25;
    7830  }
    7831 basic_json_parser_51:
    7832  yych = *++m_cursor;
    7833  if (yych != 'l')
    7834  {
    7835  goto basic_json_parser_33;
    7836  }
    7837  yych = *++m_cursor;
    7838  if (yych != 's')
    7839  {
    7840  goto basic_json_parser_33;
    7841  }
    7842  yych = *++m_cursor;
    7843  if (yych != 'e')
    7844  {
    7845  goto basic_json_parser_33;
    7846  }
    7847  ++m_cursor;
    7848  {
    7849  return token_type::literal_false;
    7850  }
    7851 basic_json_parser_56:
    7852  yych = *++m_cursor;
    7853  if (yych != 'u')
    7854  {
    7855  goto basic_json_parser_33;
    7856  }
    7857  yych = *++m_cursor;
    7858  if (yych != 'e')
    7859  {
    7860  goto basic_json_parser_33;
    7861  }
    7862  ++m_cursor;
    7863  {
    7864  return token_type::literal_true;
    7865  }
    7866 basic_json_parser_60:
    7867  yych = *++m_cursor;
    7868  if (yych != 'l')
    7869  {
    7870  goto basic_json_parser_33;
    7871  }
    7872  yych = *++m_cursor;
    7873  if (yych != 'l')
    7874  {
    7875  goto basic_json_parser_33;
    7876  }
    7877  ++m_cursor;
    7878  {
    7879  return token_type::literal_null;
    7880  }
    7881 basic_json_parser_64:
    7882  yych = *++m_cursor;
    7883  if (yych != 0xBF)
    7884  {
    7885  goto basic_json_parser_33;
    7886  }
    7887  ++m_cursor;
    7888  {
    7889  return scan();
    7890  }
    7891  }
    7892 
    7893 
    7894  }
    7895 
    7897  void yyfill() noexcept
    7898  {
    7899  if (m_stream == nullptr or not * m_stream)
    7900  {
    7901  return;
    7902  }
    7903 
    7904  const ssize_t offset_start = m_start - m_content;
    7905  const ssize_t offset_marker = m_marker - m_start;
    7906  const ssize_t offset_cursor = m_cursor - m_start;
    7907 
    7908  m_buffer.erase(0, static_cast<size_t>(offset_start));
    7909  std::string line;
    7910  assert(m_stream != nullptr);
    7911  std::getline(*m_stream, line);
    7912  m_buffer += "\n" + line; // add line with newline symbol
    7913 
    7914  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7915  assert(m_content != nullptr);
    7916  m_start = m_content;
    7917  m_marker = m_start + offset_marker;
    7918  m_cursor = m_start + offset_cursor;
    7919  m_limit = m_start + m_buffer.size() - 1;
    7920  }
    7921 
    7923  string_t get_token() const noexcept
    7924  {
    7925  assert(m_start != nullptr);
    7926  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    7927  static_cast<size_t>(m_cursor - m_start));
    7928  }
    7929 
    7951  string_t get_string() const
    7952  {
    7953  string_t result;
    7954  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    7955 
    7956  // iterate the result between the quotes
    7957  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    7958  {
    7959  // process escaped characters
    7960  if (*i == '\\')
    7961  {
    7962  // read next character
    7963  ++i;
    7964 
    7965  switch (*i)
    7966  {
    7967  // the default escapes
    7968  case 't':
    7969  {
    7970  result += "\t";
    7971  break;
    7972  }
    7973  case 'b':
    7974  {
    7975  result += "\b";
    7976  break;
    7977  }
    7978  case 'f':
    7979  {
    7980  result += "\f";
    7981  break;
    7982  }
    7983  case 'n':
    7984  {
    7985  result += "\n";
    7986  break;
    7987  }
    7988  case 'r':
    7989  {
    7990  result += "\r";
    7991  break;
    7992  }
    7993  case '\\':
    7994  {
    7995  result += "\\";
    7996  break;
    7997  }
    7998  case '/':
    7999  {
    8000  result += "/";
    8001  break;
    8002  }
    8003  case '"':
    8004  {
    8005  result += "\"";
    8006  break;
    8007  }
    8008 
    8009  // unicode
    8010  case 'u':
    8011  {
    8012  // get code xxxx from uxxxx
    8013  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8014  4).c_str(), nullptr, 16);
    8015 
    8016  // check if codepoint is a high surrogate
    8017  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8018  {
    8019  // make sure there is a subsequent unicode
    8020  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8021  {
    8022  throw std::invalid_argument("missing low surrogate");
    8023  }
    8024 
    8025  // get code yyyy from uxxxx\uyyyy
    8026  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8027  (i + 7), 4).c_str(), nullptr, 16);
    8028  result += to_unicode(codepoint, codepoint2);
    8029  // skip the next 10 characters (xxxx\uyyyy)
    8030  i += 10;
    8031  }
    8032  else
    8033  {
    8034  // add unicode character(s)
    8035  result += to_unicode(codepoint);
    8036  // skip the next four characters (xxxx)
    8037  i += 4;
    8038  }
    8039  break;
    8040  }
    8041  }
    8042  }
    8043  else
    8044  {
    8045  // all other characters are just copied to the end of the
    8046  // string
    8047  result.append(1, static_cast<typename string_t::value_type>(*i));
    8048  }
    8049  }
    8050 
    8051  return result;
    8052  }
    8053 
    8074  long double str_to_float_t(long double* /* type */, char** endptr) const
    8075  {
    8076  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8077  }
    8078 
    8093  double str_to_float_t(double* /* type */, char** endptr) const
    8094  {
    8095  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8096  }
    8097 
    8112  float str_to_float_t(float* /* type */, char** endptr) const
    8113  {
    8114  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8115  }
    8116 
    8129  template <typename T_A, typename T_B>
    8130  bool attempt_cast(T_A source, T_B& dest) const
    8131  {
    8132  dest = static_cast<T_B>(source);
    8133  return (source == static_cast<T_A>(dest));
    8134  }
    8135 
    8174  void get_number(basic_json& result) const
    8175  {
    8176  typename string_t::value_type* endptr;
    8177  assert(m_start != nullptr);
    8178  errno = 0;
    8179 
    8180  // attempt to parse it as an integer - first checking for a
    8181  // negative number
    8182  if (*reinterpret_cast<typename string_t::const_pointer>(m_start) != '-')
    8183  {
    8184  // positive, parse with strtoull and attempt cast to
    8185  // number_unsigned_t
    8186  if (attempt_cast(std::strtoull(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
    8187  10), result.m_value.number_unsigned))
    8188  {
    8189  result.m_type = value_t::number_unsigned;
    8190  }
    8191  else
    8192  {
    8193  // cast failed due to overflow - store as float
    8194  result.m_type = value_t::number_float;
    8195  }
    8196  }
    8197  else
    8198  {
    8199  // Negative, parse with strtoll and attempt cast to
    8200  // number_integer_t
    8201  if (attempt_cast(std::strtoll(reinterpret_cast<typename string_t::const_pointer>(m_start), &endptr,
    8202  10), result.m_value.number_integer))
    8203  {
    8204  result.m_type = value_t::number_integer;
    8205  }
    8206  else
    8207  {
    8208  // cast failed due to overflow - store as float
    8209  result.m_type = value_t::number_float;
    8210  }
    8211  }
    8212 
    8213  // check the end of the number was reached and no range error
    8214  // occurred
    8215  if (reinterpret_cast<lexer_char_t*>(endptr) != m_cursor || errno == ERANGE)
    8216  {
    8217  result.m_type = value_t::number_float;
    8218  }
    8219 
    8220  if (result.m_type == value_t::number_float)
    8221  {
    8222  // either the number won't fit in an integer (range error from
    8223  // strtoull/strtoll or overflow on cast) or there was something
    8224  // else after the number, which could be an exponent
    8225 
    8226  // parse with strtod
    8227  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), &endptr);
    8228 
    8229  // anything after the number is an error
    8230  if (reinterpret_cast<lexer_char_t*>(endptr) != m_cursor)
    8231  {
    8232  throw std::invalid_argument(std::string("parse error - ") + get_token() + " is not a number");
    8233  }
    8234  }
    8235  }
    8236 
    8237  private:
    8239  std::istream* m_stream = nullptr;
    8241  string_t m_buffer;
    8243  const lexer_char_t* m_content = nullptr;
    8245  const lexer_char_t* m_start = nullptr;
    8247  const lexer_char_t* m_marker = nullptr;
    8249  const lexer_char_t* m_cursor = nullptr;
    8251  const lexer_char_t* m_limit = nullptr;
    8252  };
    8253 
    8259  class parser
    8260  {
    8261  public:
    8263  parser(const string_t& s, parser_callback_t cb = nullptr)
    8264  : callback(cb), m_lexer(s)
    8265  {
    8266  // read first token
    8267  get_token();
    8268  }
    8269 
    8271  parser(std::istream& _is, parser_callback_t cb = nullptr)
    8272  : callback(cb), m_lexer(&_is)
    8273  {
    8274  // read first token
    8275  get_token();
    8276  }
    8277 
    8279  basic_json parse()
    8280  {
    8281  basic_json result = parse_internal(true);
    8282 
    8283  expect(lexer::token_type::end_of_input);
    8284 
    8285  // return parser result and replace it with null in case the
    8286  // top-level value was discarded by the callback function
    8287  return result.is_discarded() ? basic_json() : result;
    8288  }
    8289 
    8290  private:
    8292  basic_json parse_internal(bool keep)
    8293  {
    8294  auto result = basic_json(value_t::discarded);
    8295 
    8296  switch (last_token)
    8297  {
    8298  case lexer::token_type::begin_object:
    8299  {
    8300  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    8301  {
    8302  // explicitly set result to object to cope with {}
    8303  result.m_type = value_t::object;
    8304  result.m_value = json_value(value_t::object);
    8305  }
    8306 
    8307  // read next token
    8308  get_token();
    8309 
    8310  // closing } -> we are done
    8311  if (last_token == lexer::token_type::end_object)
    8312  {
    8313  get_token();
    8314  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8315  {
    8316  result = basic_json(value_t::discarded);
    8317  }
    8318  return result;
    8319  }
    8320 
    8321  // no comma is expected here
    8322  unexpect(lexer::token_type::value_separator);
    8323 
    8324  // otherwise: parse key-value pairs
    8325  do
    8326  {
    8327  // ugly, but could be fixed with loop reorganization
    8328  if (last_token == lexer::token_type::value_separator)
    8329  {
    8330  get_token();
    8331  }
    8332 
    8333  // store key
    8334  expect(lexer::token_type::value_string);
    8335  const auto key = m_lexer.get_string();
    8336 
    8337  bool keep_tag = false;
    8338  if (keep)
    8339  {
    8340  if (callback)
    8341  {
    8342  basic_json k(key);
    8343  keep_tag = callback(depth, parse_event_t::key, k);
    8344  }
    8345  else
    8346  {
    8347  keep_tag = true;
    8348  }
    8349  }
    8350 
    8351  // parse separator (:)
    8352  get_token();
    8353  expect(lexer::token_type::name_separator);
    8354 
    8355  // parse and add value
    8356  get_token();
    8357  auto value = parse_internal(keep);
    8358  if (keep and keep_tag and not value.is_discarded())
    8359  {
    8360  result[key] = std::move(value);
    8361  }
    8362  }
    8363  while (last_token == lexer::token_type::value_separator);
    8364 
    8365  // closing }
    8366  expect(lexer::token_type::end_object);
    8367  get_token();
    8368  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8369  {
    8370  result = basic_json(value_t::discarded);
    8371  }
    8372 
    8373  return result;
    8374  }
    8375 
    8376  case lexer::token_type::begin_array:
    8377  {
    8378  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    8379  {
    8380  // explicitly set result to object to cope with []
    8381  result.m_type = value_t::array;
    8382  result.m_value = json_value(value_t::array);
    8383  }
    8384 
    8385  // read next token
    8386  get_token();
    8387 
    8388  // closing ] -> we are done
    8389  if (last_token == lexer::token_type::end_array)
    8390  {
    8391  get_token();
    8392  if (callback and not callback(--depth, parse_event_t::array_end, result))
    8393  {
    8394  result = basic_json(value_t::discarded);
    8395  }
    8396  return result;
    8397  }
    8398 
    8399  // no comma is expected here
    8400  unexpect(lexer::token_type::value_separator);
    8401 
    8402  // otherwise: parse values
    8403  do
    8404  {
    8405  // ugly, but could be fixed with loop reorganization
    8406  if (last_token == lexer::token_type::value_separator)
    8407  {
    8408  get_token();
    8409  }
    8410 
    8411  // parse value
    8412  auto value = parse_internal(keep);
    8413  if (keep and not value.is_discarded())
    8414  {
    8415  result.push_back(std::move(value));
    8416  }
    8417  }
    8418  while (last_token == lexer::token_type::value_separator);
    8419 
    8420  // closing ]
    8421  expect(lexer::token_type::end_array);
    8422  get_token();
    8423  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    8424  {
    8425  result = basic_json(value_t::discarded);
    8426  }
    8427 
    8428  return result;
    8429  }
    8430 
    8431  case lexer::token_type::literal_null:
    8432  {
    8433  get_token();
    8434  result.m_type = value_t::null;
    8435  break;
    8436  }
    8437 
    8438  case lexer::token_type::value_string:
    8439  {
    8440  const auto s = m_lexer.get_string();
    8441  get_token();
    8442  result = basic_json(s);
    8443  break;
    8444  }
    8445 
    8446  case lexer::token_type::literal_true:
    8447  {
    8448  get_token();
    8449  result.m_type = value_t::boolean;
    8450  result.m_value = true;
    8451  break;
    8452  }
    8453 
    8454  case lexer::token_type::literal_false:
    8455  {
    8456  get_token();
    8457  result.m_type = value_t::boolean;
    8458  result.m_value = false;
    8459  break;
    8460  }
    8461 
    8462  case lexer::token_type::value_number:
    8463  {
    8464  m_lexer.get_number(result);
    8465  get_token();
    8466  break;
    8467  }
    8468 
    8469  default:
    8470  {
    8471  // the last token was unexpected
    8472  unexpect(last_token);
    8473  }
    8474  }
    8475 
    8476  if (keep and callback and not callback(depth, parse_event_t::value, result))
    8477  {
    8478  result = basic_json(value_t::discarded);
    8479  }
    8480  return result;
    8481  }
    8482 
    8484  typename lexer::token_type get_token()
    8485  {
    8486  last_token = m_lexer.scan();
    8487  return last_token;
    8488  }
    8489 
    8490  void expect(typename lexer::token_type t) const
    8491  {
    8492  if (t != last_token)
    8493  {
    8494  std::string error_msg = "parse error - unexpected ";
    8495  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8496  lexer::token_type_name(last_token));
    8497  error_msg += "; expected " + lexer::token_type_name(t);
    8498  throw std::invalid_argument(error_msg);
    8499  }
    8500  }
    8501 
    8502  void unexpect(typename lexer::token_type t) const
    8503  {
    8504  if (t == last_token)
    8505  {
    8506  std::string error_msg = "parse error - unexpected ";
    8507  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8508  lexer::token_type_name(last_token));
    8509  throw std::invalid_argument(error_msg);
    8510  }
    8511  }
    8512 
    8513  private:
    8515  int depth = 0;
    8517  parser_callback_t callback;
    8519  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    8521  lexer m_lexer;
    8522  };
    8523 };
    8524 
    8525 
    8527 // presets //
    8529 
    8539 }
    8540 
    8541 
    8543 // nonmember functions //
    8545 
    8546 // specialization of std::swap, and std::hash
    8547 namespace std
    8548 {
    8554 template <>
    8555 inline void swap(nlohmann::json& j1,
    8556  nlohmann::json& j2) noexcept(
    8557  is_nothrow_move_constructible<nlohmann::json>::value and
    8558  is_nothrow_move_assignable<nlohmann::json>::value
    8559  )
    8560 {
    8561  j1.swap(j2);
    8562 }
    8563 
    8565 template <>
    8566 struct hash<nlohmann::json>
    8567 {
    8573  std::size_t operator()(const nlohmann::json& j) const
    8574  {
    8575  // a naive hashing via the string representation
    8576  const auto& h = hash<nlohmann::json::string_t>();
    8577  return h(j.dump());
    8578  }
    8579 };
    8580 }
    8581 
    8594 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    8595 {
    8596  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    8597 }
    8598 
    8599 // restore GCC/clang diagnostic settings
    8600 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    8601  #pragma GCC diagnostic pop
    8602 #endif
    8603 
    8604 #endif
    bool is_null() const noexcept
    return whether value is null
    Definition: json.hpp:2148
    reference operator*()
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:6702
    reverse_iterator rbegin()
    returns an iterator to the reverse-beginning
    Definition: json.hpp:4114
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:5341
    @@ -297,7 +297,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    diff --git a/namespacemembers.html b/namespacemembers.html index 70df59e82..679ef7278 100644 --- a/namespacemembers.html +++ b/namespacemembers.html @@ -94,7 +94,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    diff --git a/namespacemembers_type.html b/namespacemembers_type.html index af3d0e968..541cfba20 100644 --- a/namespacemembers_type.html +++ b/namespacemembers_type.html @@ -94,7 +94,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/namespacenlohmann.html b/namespacenlohmann.html index 89de15e45..1d78a80a6 100644 --- a/namespacenlohmann.html +++ b/namespacenlohmann.html @@ -116,7 +116,7 @@ Typedefs diff --git a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html index e14e6bb6c..0e5816afa 100644 --- a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html +++ b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html @@ -105,7 +105,7 @@ Classes diff --git a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html index 5566d8733..f8e5753f0 100644 --- a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html +++ b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html @@ -111,7 +111,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); 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 9cd0d0c4f..b1dce35ea 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4-members.html @@ -98,7 +98,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html index 5fedf952c..d00c82de1 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html @@ -115,7 +115,7 @@ struct std::hash< nlohmann::json > diff --git a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html index ee72c1ebe..883cbc345 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4_afd03f6ad53db22868ca4163a8200b2f9.html @@ -122,7 +122,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');