diff --git a/Nodes.xml b/Nodes.xml index ed33e1d38..0bc4125fc 100644 --- a/Nodes.xml +++ b/Nodes.xml @@ -1038,6 +1038,11 @@ classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html a9486a272e034c0548305d7a12f3045e6 + + operator+= + classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html + aa0033766b4d3134b9bb57d81762d75a2 + operator= classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html @@ -1128,6 +1133,11 @@ classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html a5212588544f6d2266384c3be9bfda0c5 + + push_back + classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html + a9c9b4932b26a9630e1a3f25ea42a2c43 + rbegin classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html diff --git a/Tokens.xml b/Tokens.xml index cd530706d..711e79d02 100644 --- a/Tokens.xml +++ b/Tokens.xml @@ -1443,6 +1443,30 @@ add an object to an object json.hpp + + + push_back + cpp + instm + nlohmann::basic_json + + classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html + a9c9b4932b26a9630e1a3f25ea42a2c43 + add an object to an object + json.hpp + + + + operator+= + cpp + instm + nlohmann::basic_json + + classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html + aa0033766b4d3134b9bb57d81762d75a2 + add an object to an object + json.hpp + insert diff --git a/annotated.html b/annotated.html index 143d7c45f..fd31f21c8 100644 --- a/annotated.html +++ b/annotated.html @@ -102,7 +102,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classes.html b/classes.html index 6a95fa47a..20e003172 100644 --- a/classes.html +++ b/classes.html @@ -106,7 +106,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 f304f454c..5dbf019e1 100644 --- a/classnlohmann_1_1basic__json-members.html +++ b/classnlohmann_1_1basic__json-members.html @@ -197,39 +197,41 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+=(basic_json &&val)nlohmann::basic_jsoninline operator+=(const basic_json &val)nlohmann::basic_jsoninline operator+=(const typename object_t::value_type &val)nlohmann::basic_jsoninline - operator<(const value_t lhs, const value_t rhs) noexceptnlohmann::basic_jsonfriend - operator<(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend - operator<<(std::ostream &o, const basic_json &j)nlohmann::basic_jsonfriend - operator<<(basic_json &j, std::istream &i)nlohmann::basic_jsonfriend - operator<=(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend - operator=(basic_json other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )nlohmann::basic_jsoninline - operator==(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend - operator==(const_reference v, std::nullptr_t) noexceptnlohmann::basic_jsonfriend - operator==(std::nullptr_t, const_reference v) noexceptnlohmann::basic_jsonfriend - operator>(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend - operator>=(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend - operator>>(const basic_json &j, std::ostream &o)nlohmann::basic_jsonfriend - operator>>(std::istream &i, basic_json &j)nlohmann::basic_jsonfriend - operator[](size_type idx)nlohmann::basic_jsoninline - operator[](size_type idx) const nlohmann::basic_jsoninline - operator[](const typename object_t::key_type &key)nlohmann::basic_jsoninline - operator[](const typename object_t::key_type &key) const nlohmann::basic_jsoninline - operator[](T *(&key)[n])nlohmann::basic_jsoninline - operator[](T *(&key)[n]) const nlohmann::basic_jsoninline - operator[](T *key)nlohmann::basic_jsoninline - operator[](T *key) const nlohmann::basic_jsoninline - operator[](const json_pointer &ptr)nlohmann::basic_jsoninline - operator[](const json_pointer &ptr) const nlohmann::basic_jsoninline - parse(const string_t &s, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic - parse(std::istream &i, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic - parse(std::istream &&i, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic - parse_event_t enum namenlohmann::basic_json - parser_callback_t typedefnlohmann::basic_json - patch(const basic_json &patch) const nlohmann::basic_jsoninline - pointer typedefnlohmann::basic_json - push_back(basic_json &&val)nlohmann::basic_jsoninline - push_back(const basic_json &val)nlohmann::basic_jsoninline - push_back(const typename object_t::value_type &val)nlohmann::basic_jsoninline + operator+=(std::initializer_list< basic_json > init)nlohmann::basic_jsoninline + operator<(const value_t lhs, const value_t rhs) noexceptnlohmann::basic_jsonfriend + operator<(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend + operator<<(std::ostream &o, const basic_json &j)nlohmann::basic_jsonfriend + operator<<(basic_json &j, std::istream &i)nlohmann::basic_jsonfriend + operator<=(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend + operator=(basic_json other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )nlohmann::basic_jsoninline + operator==(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend + operator==(const_reference v, std::nullptr_t) noexceptnlohmann::basic_jsonfriend + operator==(std::nullptr_t, const_reference v) noexceptnlohmann::basic_jsonfriend + operator>(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend + operator>=(const_reference lhs, const_reference rhs) noexceptnlohmann::basic_jsonfriend + operator>>(const basic_json &j, std::ostream &o)nlohmann::basic_jsonfriend + operator>>(std::istream &i, basic_json &j)nlohmann::basic_jsonfriend + operator[](size_type idx)nlohmann::basic_jsoninline + operator[](size_type idx) const nlohmann::basic_jsoninline + operator[](const typename object_t::key_type &key)nlohmann::basic_jsoninline + operator[](const typename object_t::key_type &key) const nlohmann::basic_jsoninline + operator[](T *(&key)[n])nlohmann::basic_jsoninline + operator[](T *(&key)[n]) const nlohmann::basic_jsoninline + operator[](T *key)nlohmann::basic_jsoninline + operator[](T *key) const nlohmann::basic_jsoninline + operator[](const json_pointer &ptr)nlohmann::basic_jsoninline + operator[](const json_pointer &ptr) const nlohmann::basic_jsoninline + parse(const string_t &s, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic + parse(std::istream &i, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic + parse(std::istream &&i, parser_callback_t cb=nullptr)nlohmann::basic_jsoninlinestatic + parse_event_t enum namenlohmann::basic_json + parser_callback_t typedefnlohmann::basic_json + patch(const basic_json &patch) const nlohmann::basic_jsoninline + pointer typedefnlohmann::basic_json + push_back(basic_json &&val)nlohmann::basic_jsoninline + push_back(const basic_json &val)nlohmann::basic_jsoninline + push_back(const typename object_t::value_type &val)nlohmann::basic_jsoninline + push_back(std::initializer_list< basic_json > init)nlohmann::basic_jsoninline rbegin() noexceptnlohmann::basic_jsoninline rbegin() const noexceptnlohmann::basic_jsoninline reference typedefnlohmann::basic_json @@ -253,7 +255,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json.html b/classnlohmann_1_1basic__json.html index 6d02811fc..b0362923a 100644 --- a/classnlohmann_1_1basic__json.html +++ b/classnlohmann_1_1basic__json.html @@ -561,6 +561,12 @@ modifiers reference operator+= (const typename object_t::value_type &val)  add an object to an object More...
  +void push_back (std::initializer_list< basic_json > init) + add an object to an object More...
+  +reference operator+= (std::initializer_list< basic_json > init) + add an object to an object More...
iterator insert (const_iterator pos, const basic_json &val)  inserts element More...
  @@ -734,7 +740,7 @@ class nlohmann::basic_json diff --git a/classnlohmann_1_1basic__json_1_1const__iterator-members.html b/classnlohmann_1_1basic__json_1_1const__iterator-members.html index 50183526c..e3e23da1a 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 4f3ac6d5d..589c3071f 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator.html @@ -215,11 +215,11 @@ class nlohmann::basic_json::const_iterator
Since
version 1.0.0
-

Definition at line 6426 of file json.hpp.

+

Definition at line 6474 of file json.hpp.

diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html index 4e35427fb..a5e785e07 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6821 of file json.hpp.

+

Definition at line 6869 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html index 363a8065e..a57d1f5be 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a18c35a6735d3da96b4fc026421c05dd8.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6503 of file json.hpp.

+

Definition at line 6551 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html index 22c971a97..6827d4802 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6437 of file json.hpp.

+

Definition at line 6485 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html b/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html index 141108618..81e0cf34b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a23de834b11bd895209aa65c100ab9ceb.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6447 of file json.hpp.

+

Definition at line 6495 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html index 7a3f9cb8b..a29b69e3b 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a49d7c3e9ef3280df03052cce988b792f.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6435 of file json.hpp.

+

Definition at line 6483 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html index f1cd5cc51..9fc8fb908 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5521515067b6597cb0b55a9c547a7a2b.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6508 of file json.hpp.

+

Definition at line 6556 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html index 1dfe6ae18..4b2e8343d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5d4320e24fcb7df041ff2c95d976dba0.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6931 of file json.hpp.

+

Definition at line 6979 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html b/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html index 34042d72a..c503178c5 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6871 of file json.hpp.

+

Definition at line 6919 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html b/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html index 6616d9491..074efd1f2 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a65f491b515e5967e9c0b40289e3c0ff3.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6773 of file json.hpp.

+

Definition at line 6821 of file json.hpp.

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

Definition at line 6803 of file json.hpp.

+

Definition at line 6851 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html index 06225cd69..1947672ec 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6b950c6bc081ac1ec1540ec05ceb2603.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6475 of file json.hpp.

+

Definition at line 6523 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html index ad2ce6738..3bbccbfc5 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6700 of file json.hpp.

+

Definition at line 6748 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html index fd6a26296..58ec7c2d5 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6855 of file json.hpp.

+

Definition at line 6903 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html b/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html index c91d283e5..4674cc6aa 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a7bd530bfbbc58ac77308c087120c21fa.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6895 of file json.hpp.

+

Definition at line 6943 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html index c88e98953..73d473b09 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a821560d64f50525162097f19b1392e7f.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6441 of file json.hpp.

+

Definition at line 6489 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html index abcab567b..3c9db0a21 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8be837e4d902887676dd837abe9098d3.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6628 of file json.hpp.

+

Definition at line 6676 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html index 5e6670ba0..ee1188160 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6663 of file json.hpp.

+

Definition at line 6711 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html index 88d3520f9..1d34ec713 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6671 of file json.hpp.

+

Definition at line 6719 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html b/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html index 6da6a3744..bcae1b43c 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a9e4c6e48e3c2f3ff357ef8215b8c8fca.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6767 of file json.hpp.

+

Definition at line 6815 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html index 426523d76..7bae81521 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_a9ea0497199b1e96ce9cadd1f202ec343.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6433 of file json.hpp.

+

Definition at line 6481 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html index 74288bf3c..579c283a5 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6588 of file json.hpp.

+

Definition at line 6636 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html b/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html index e219db328..35a5195f1 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ab4c0b9baaec9ebc4837158e272f6c803.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6737 of file json.hpp.

+

Definition at line 6785 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html index 89096a492..6d9eef315 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6863 of file json.hpp.

+

Definition at line 6911 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html b/classnlohmann_1_1basic__json_1_1const__iterator_ac6fdaff67857f82a623e5cc253917639.html index fcd034ae9..b46105247 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 2d24df610..79a4465b7 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_ac75e80d30b6169ee2a29ec93fb4d2acd.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6946 of file json.hpp.

+

Definition at line 6994 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html b/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html index 428c0d052..35cbf2e36 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_acb6cd0ff760933afeb7f93e5207f3646.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6809 of file json.hpp.

+

Definition at line 6857 of file json.hpp.

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

Definition at line 6429 of file json.hpp.

+

Definition at line 6477 of file json.hpp.

@@ -149,7 +149,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html index d890e888f..fdd505b81 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html @@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6708 of file json.hpp.

+

Definition at line 6756 of file json.hpp.

@@ -152,7 +152,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html index 52c3e8b3b..c59d072a9 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html @@ -143,7 +143,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6849 of file json.hpp.

+

Definition at line 6897 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html index ed1aa41f0..7c947371d 100644 --- a/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html +++ b/classnlohmann_1_1basic__json_1_1const__iterator_aefd248cac6493eed1e6ff53ba6a63eb2.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6439 of file json.hpp.

+

Definition at line 6487 of file json.hpp.

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

Definition at line 6815 of file json.hpp.

+

Definition at line 6863 of file json.hpp.

@@ -153,7 +153,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator-members.html b/classnlohmann_1_1basic__json_1_1iterator-members.html index 2afaee5c5..7e8e9c011 100644 --- a/classnlohmann_1_1basic__json_1_1iterator-members.html +++ b/classnlohmann_1_1basic__json_1_1iterator-members.html @@ -133,7 +133,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 37ceac50d..ae05da520 100644 --- a/classnlohmann_1_1basic__json_1_1iterator.html +++ b/classnlohmann_1_1basic__json_1_1iterator.html @@ -267,11 +267,11 @@ class nlohmann::basic_json::iterator
Since
version 1.0.0
-

Definition at line 6970 of file json.hpp.

+

Definition at line 7018 of file json.hpp.

diff --git a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html index ceac908a9..4012fc7ec 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7023 of file json.hpp.

+

Definition at line 7071 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html index dd7f9b672..e1078c6b7 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a085fe0d8cf459b5b1ae7b518b933ae7d.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6981 of file json.hpp.

+

Definition at line 7029 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html index 0cca87b15..9b51fdd11 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a1de0975e812c83e74d118b3e1063f335.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6986 of file json.hpp.

+

Definition at line 7034 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html index 1a2055f9d..6aea8bc1e 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7015 of file json.hpp.

+

Definition at line 7063 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html index c36ebbee4..fc25c16e9 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6974 of file json.hpp.

+

Definition at line 7022 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html b/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html index 111d2e216..18ba54768 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a3db892729714c4e7eaf60c00ee96e2e9.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6991 of file json.hpp.

+

Definition at line 7039 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html b/classnlohmann_1_1basic__json_1_1iterator_a47fb2dbbbfaf65c0ccfa99aeaed920a1.html index 60fb5c5a1..551a1db55 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 d48af6495..05bae72f8 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7059 of file json.hpp.

+

Definition at line 7107 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html index 640a59c34..020431531 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7067 of file json.hpp.

+

Definition at line 7115 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html b/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html index 852c76f25..ef1b6d07a 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a7e01532727c10f87926dac4eb8e170f4.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7081 of file json.hpp.

+

Definition at line 7129 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a8de46badb5b2177c85c672a71bcca017.html b/classnlohmann_1_1basic__json_1_1iterator_a8de46badb5b2177c85c672a71bcca017.html index 0cd584343..e6f29c7e7 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a8de46badb5b2177c85c672a71bcca017.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a8de46badb5b2177c85c672a71bcca017.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7009 of file json.hpp.

+

Definition at line 7057 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html b/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html index 39b59bde6..5c8f3066b 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a8ffbf287736048e683f58306fdb8701f.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7087 of file json.hpp.

+

Definition at line 7135 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html index 29b1da7f6..ce81bdb07 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a97aff5d71246774267a81066460dd1cf.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6975 of file json.hpp.

+

Definition at line 7023 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html b/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html index 3801fe5aa..2c4f31677 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7075 of file json.hpp.

+

Definition at line 7123 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html index dd8589e30..ee9066b7a 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7038 of file json.hpp.

+

Definition at line 7086 of file json.hpp.

@@ -141,7 +141,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html index 8f33ab8ce..bed4e36f7 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7030 of file json.hpp.

+

Definition at line 7078 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html index ffa26c293..889aa0b90 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html +++ b/classnlohmann_1_1basic__json_1_1iterator_ac48754e4dc48d65d95294bd170dcd857.html @@ -120,7 +120,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 6973 of file json.hpp.

+

Definition at line 7021 of file json.hpp.

@@ -130,7 +130,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html b/classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html index 4614ecba0..66edb7625 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html +++ b/classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html @@ -131,7 +131,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7003 of file json.hpp.

+

Definition at line 7051 of file json.hpp.

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

Definition at line 7045 of file json.hpp.

+

Definition at line 7093 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html index 052d66e12..334a875fb 100644 --- a/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html +++ b/classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html @@ -132,7 +132,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 7052 of file json.hpp.

+

Definition at line 7100 of file json.hpp.

@@ -142,7 +142,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_1_1json__pointer-members.html b/classnlohmann_1_1basic__json_1_1json__pointer-members.html index 41d84680c..1f7283fe9 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer-members.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer-members.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/classnlohmann_1_1basic__json_1_1json__pointer.html b/classnlohmann_1_1basic__json_1_1json__pointer.html index e40cb829b..7de2aea5a 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer.html @@ -127,11 +127,11 @@ class nlohmann::basic_json::json_pointer
See also
RFC 6901
Since
version 2.0.0
-

Definition at line 8829 of file json.hpp.

+

Definition at line 8873 of file json.hpp.

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

Definition at line 8880 of file json.hpp.

+

Definition at line 8924 of file json.hpp.

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

Definition at line 8893 of file json.hpp.

+

Definition at line 8937 of file json.hpp.

@@ -144,7 +144,7 @@ json_pointer__to_string diff --git a/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html b/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html index b760f0952..8dac9568f 100644 --- a/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html +++ b/classnlohmann_1_1basic__json_1_1json__pointer_ada3100cdb8700566051828f1355fa745.html @@ -112,7 +112,7 @@ template<template< typename U, typename V, typename...Args > class Obje
-

Definition at line 8832 of file json.hpp.

+

Definition at line 8876 of file json.hpp.

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

Definition at line 8857 of file json.hpp.

+

Definition at line 8901 of file json.hpp.

@@ -148,7 +148,7 @@ domain_error: escape error: '~' must be followed with '0' or '1' diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator-members.html index 3e8be1f8b..8eef2d462 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 c851fa9c0..70dbc033d 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator.html @@ -174,7 +174,7 @@ class nlohmann::basic_json::json_reverse_iterator< Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html index d003f36cf..bc2de4ceb 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7179 of file json.hpp.

+

Definition at line 7227 of file json.hpp.

@@ -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 2c32afbf3..7b2691ce4 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 7136 of file json.hpp.

+

Definition at line 7184 of file json.hpp.

@@ -138,7 +138,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html index 56e0edb5a..f13eb94fe 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a530f042e2ab1c83dddfc344931b0375a.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7125 of file json.hpp.

+

Definition at line 7173 of file json.hpp.

@@ -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 377d486af..012df7959 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7130 of file json.hpp.

+

Definition at line 7178 of file json.hpp.

@@ -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 e4ca9f43f..b449bf4d0 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 7149 of file json.hpp.

+

Definition at line 7197 of file json.hpp.

@@ -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 36e1445a8..39574d410 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7143 of file json.hpp.

+

Definition at line 7191 of file json.hpp.

@@ -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 919a66576..c6eff9598 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a7265535f39299824f9712a2ca15013c3.html @@ -117,7 +117,7 @@ template<typename Base >
-

Definition at line 7117 of file json.hpp.

+

Definition at line 7165 of file json.hpp.

@@ -127,7 +127,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html index 3a6c11c2b..c42cd4a85 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a86c97bbb8ebe19aef4656cf796e30e99.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7120 of file json.hpp.

+

Definition at line 7168 of file json.hpp.

@@ -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 46ead14b2..fccd15c59 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7163 of file json.hpp.

+

Definition at line 7211 of file json.hpp.

@@ -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 772cb5e17..2feb5ad3d 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7156 of file json.hpp.

+

Definition at line 7204 of file json.hpp.

@@ -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 c7bbc4507..895645510 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9ebc4c99e6fc90c965af0f39ad2ca70e.html @@ -117,7 +117,7 @@ template<typename Base >
-

Definition at line 7115 of file json.hpp.

+

Definition at line 7163 of file json.hpp.

@@ -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 73241a249..2773d19e9 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7171 of file json.hpp.

+

Definition at line 7219 of file json.hpp.

@@ -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 574c1723b..0f6f2b8ca 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_aca5116682e206dac48f8a56716a3280b.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 7198 of file json.hpp.

+

Definition at line 7246 of file json.hpp.

@@ -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 19c5434d6..821c1ddbc 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_acecae6d237fcf14c909fb42b9d2e2955.html @@ -128,7 +128,7 @@ template<typename Base >
-

Definition at line 7191 of file json.hpp.

+

Definition at line 7239 of file json.hpp.

@@ -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 0698cec95..8258cb9b4 100644 --- a/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html +++ b/classnlohmann_1_1basic__json_1_1json__reverse__iterator_ad4ec2bbb8347e7aa3b58e616fd6c7f40.html @@ -129,7 +129,7 @@ template<typename Base >
-

Definition at line 7185 of file json.hpp.

+

Definition at line 7233 of file json.hpp.

@@ -139,7 +139,7 @@ template<typename Base > diff --git a/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html b/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html index 98343aa02..3a4a87ab5 100644 --- a/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html +++ b/classnlohmann_1_1basic__json_a01833b332b68d9af1f7cd7a816c39e49.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -290,7 +292,7 @@ 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 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:10058
    +
    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:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    0
    @@ -318,7 +320,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    diff --git a/classnlohmann_1_1basic__json_a018ea61dbc973192d2ffc6bccc50696b.html b/classnlohmann_1_1basic__json_a018ea61dbc973192d2ffc6bccc50696b.html index 99ea853bc..26b841fc9 100644 --- a/classnlohmann_1_1basic__json_a018ea61dbc973192d2ffc6bccc50696b.html +++ b/classnlohmann_1_1basic__json_a018ea61dbc973192d2ffc6bccc50696b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rend().
  • -
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    11  json::const_reverse_iterator it = array.crend();
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:240
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a0389c5dd86adc512e5826d7ff610f776.html b/classnlohmann_1_1basic__json_a0389c5dd86adc512e5826d7ff610f776.html index b34ad95ed..8925a5bd5 100644 --- a/classnlohmann_1_1basic__json_a0389c5dd86adc512e5826d7ff610f776.html +++ b/classnlohmann_1_1basic__json_a0389c5dd86adc512e5826d7ff610f776.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -274,7 +276,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    the original JSON from a flattened version
    Note
    Empty objects and arrays are flattened by flatten() to null values and can not unflattened to their original type. Apart from this example, for a JSON value j, the following is always true: j == j.flatten().unflatten().
    Complexity
    Linear in the size the JSON value.
    -
    Example
    The following code shows how a flattened JSON object is unflattened into the original nested JSON object.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j_flattened =
    9  {
    10  {"/answer/everything", 42},
    11  {"/happy", true},
    12  {"/list/0", 1},
    13  {"/list/1", 0},
    14  {"/list/2", 2},
    15  {"/name", "Niels"},
    16  {"/nothing", nullptr},
    17  {"/object/currency", "USD"},
    18  {"/object/value", 42.99},
    19  {"/pi", 3.141}
    20  };
    21 
    22  // call unflatten()
    23  std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows how a flattened JSON object is unflattened into the original nested JSON object.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j_flattened =
    9  {
    10  {"/answer/everything", 42},
    11  {"/happy", true},
    12  {"/list/0", 1},
    13  {"/list/1", 0},
    14  {"/list/2", 2},
    15  {"/name", "Niels"},
    16  {"/nothing", nullptr},
    17  {"/object/currency", "USD"},
    18  {"/object/value", 42.99},
    19  {"/pi", 3.141}
    20  };
    21 
    22  // call unflatten()
    23  std::cout << std::setw(4) << j_flattened.unflatten() << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    {
         "answer": {
             "everything": 42
    @@ -297,7 +299,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    See also
    flatten() for the reverse function
    Since
    version 2.0.0
    -

    Definition at line 9570 of file json.hpp.

    +

    Definition at line 9614 of file json.hpp.

    @@ -307,7 +309,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 c293b72fe..f0680caf3 100644 --- a/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html +++ b/classnlohmann_1_1basic__json_a06efb200b69942eacd1ea22d0f6ccebb.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html b/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html index c32313f63..749b90456 100644 --- a/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html +++ b/classnlohmann_1_1basic__json_a098482190447461f47f80b99bf2519f6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -299,7 +301,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 64bdb4927..617088611 100644 --- a/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html +++ b/classnlohmann_1_1basic__json_a0a2cbbd95862a623e7dc5c37e67dead0.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -305,7 +307,7 @@ value() with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object with different entry types
    8  json j =
    9  {
    10  {"integer", 1},
    11  {"floating", 42.23},
    12  {"string", "hello world"},
    13  {"boolean", true},
    14  {"object", {{"key1", 1}, {"key2", 2}}},
    15  {"array", {1, 2, 3}}
    16  };
    17 
    18  // access existing values
    19  int v_integer = j.value("integer", 0);
    20  double v_floating = j.value("floating", 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("nonexisting", "oops");
    24  bool v_boolean = j.value("nonexisting", false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -323,7 +325,7 @@ value() with null"
    diff --git a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html index 278f2b716..45d9161d1 100644 --- a/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html +++ b/classnlohmann_1_1basic__json_a0ac9894c9de8dc551cf2e5f1c605537f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -298,7 +300,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a0d46dd5ef4992fb80f9f0d9f56f16eae.html b/classnlohmann_1_1basic__json_a0d46dd5ef4992fb80f9f0d9f56f16eae.html index 911230675..d9e6a167c 100644 --- a/classnlohmann_1_1basic__json_a0d46dd5ef4992fb80f9f0d9f56f16eae.html +++ b/classnlohmann_1_1basic__json_a0d46dd5ef4992fb80f9f0d9f56f16eae.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -292,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at_json_pointer_const.cpp -o at_json_pointer_const 
    Since
    version 2.0.0
    -

    Definition at line 9509 of file json.hpp.

    +

    Definition at line 9553 of file json.hpp.

    @@ -302,7 +304,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html b/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html index fcc584421..60f6803de 100644 --- a/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html +++ b/classnlohmann_1_1basic__json_a0d838bc7ffca6017f51167e0a8ffd9b6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<typename T , typename std::enable_if<
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of an integer number value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON number from number_integer_t
    8  json::number_integer_t value = 42;
    9 
    10  json j(value);
    11 
    12  // serialize the JSON numbers
    13  std::cout << j << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows the construction of an integer number value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON number from number_integer_t
    8  json::number_integer_t value = 42;
    9 
    10  json j(value);
    11 
    12  // serialize the JSON numbers
    13  std::cout << j << '\n';
    14 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    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 
    @@ -302,7 +304,7 @@ template<typename T , typename std::enable_if<
    diff --git a/classnlohmann_1_1basic__json_a0d96ff13001977a93d65f0a97279d316.html b/classnlohmann_1_1basic__json_a0d96ff13001977a93d65f0a97279d316.html index 3e79c31e0..de804513b 100644 --- a/classnlohmann_1_1basic__json_a0d96ff13001977a93d65f0a97279d316.html +++ b/classnlohmann_1_1basic__json_a0d96ff13001977a93d65f0a97279d316.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is object, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_object() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_object()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_object() << '\n';
    20  std::cout << j_boolean.is_object() << '\n';
    21  std::cout << j_number_integer.is_object() << '\n';
    22  std::cout << j_number_unsigned_integer.is_object() << '\n';
    23  std::cout << j_number_float.is_object() << '\n';
    24  std::cout << j_object.is_object() << '\n';
    25  std::cout << j_array.is_object() << '\n';
    26  std::cout << j_string.is_object() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -292,7 +294,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a101cd941eb8a5c299660449c71d0e75e.html b/classnlohmann_1_1basic__json_a101cd941eb8a5c299660449c71d0e75e.html index 6bc4b5f4e..6bc598c77 100644 --- a/classnlohmann_1_1basic__json_a101cd941eb8a5c299660449c71d0e75e.html +++ b/classnlohmann_1_1basic__json_a101cd941eb8a5c299660449c71d0e75e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    the type of the JSON value
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies the value_t operator for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call operator value_t()
    17  json::value_t t_null = j_null;
    18  json::value_t t_boolean = j_boolean;
    19  json::value_t t_number_integer = j_number_integer;
    20  json::value_t t_number_float = j_number_float;
    21  json::value_t t_object = j_object;
    22  json::value_t t_array = j_array;
    23  json::value_t t_string = j_string;
    24 
    25  // print types
    26  std::cout << std::boolalpha;
    27  std::cout << (t_null == json::value_t::null) << '\n';
    28  std::cout << (t_boolean == json::value_t::boolean) << '\n';
    29  std::cout << (t_number_integer == json::value_t::number_integer) << '\n';
    30  std::cout << (t_number_float == json::value_t::number_float) << '\n';
    31  std::cout << (t_object == json::value_t::object) << '\n';
    32  std::cout << (t_array == json::value_t::array) << '\n';
    33  std::cout << (t_string == json::value_t::string) << '\n';
    34 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    object (unordered set of name/value pairs)
    value_t
    the JSON type enumeration
    Definition: json.hpp:696
    @@ -299,7 +301,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html index a6799f6ac..f0f1ff63d 100644 --- a/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html +++ b/classnlohmann_1_1basic__json_a112a2d8e76345ea64f71e2985fee4c52.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -286,7 +288,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Linear in cnt.
    -
    Example
    The following code shows examples for the basic_json(size_type, const basic_json&) constructor.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    []
     ["Hello"]
     ["Hello","Hello","Hello","Hello","Hello"]
    @@ -303,7 +305,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 d6b7029d9..43ec95901 100644 --- a/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html +++ b/classnlohmann_1_1basic__json_a122640e7e2db1814fc7bbb3c122ec76e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -291,7 +293,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3] == [1,2,4] false
     {"A":"a","B":"b"} == {"A":"a","B":"b"} true
     17 == 17 true
    @@ -299,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__equal.cpp -o operator__equal 
    Since
    version 1.0.0
    -

    Definition at line 5291 of file json.hpp.

    +

    Definition at line 5339 of file json.hpp.

    @@ -309,7 +311,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html b/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html index c0a03721f..31b45cc5e 100644 --- a/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html +++ b/classnlohmann_1_1basic__json_a12ccf14d39ddae52f6c7e126105a230b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • The complexity is constant.
  • -
    Example
    The following code shows an example for end().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::iterator it = array.end();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/end.cpp -o end 
    See also
    cend() – returns a const iterator to the end
    @@ -297,7 +299,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html b/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html index 3646e04b0..193725b22 100644 --- a/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html +++ b/classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,8 +289,8 @@ 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 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:10058
    -
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5720
    +
    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:10102
    +
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5768
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:983
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:918
    @@ -330,7 +332,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    See also
    parse(const string_t&, parser_callback_t) for a version that reads from a string
    Since
    version 1.0.0
    -

    Definition at line 5749 of file json.hpp.

    +

    Definition at line 5797 of file json.hpp.

    @@ -340,7 +342,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a1407f91b4689bbc56d1a3c401a5bb649.html b/classnlohmann_1_1basic__json_a1407f91b4689bbc56d1a3c401a5bb649.html index 78df71bf4..926d43a52 100644 --- a/classnlohmann_1_1basic__json_a1407f91b4689bbc56d1a3c401a5bb649.html +++ b/classnlohmann_1_1basic__json_a1407f91b4689bbc56d1a3c401a5bb649.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is number (regardless whether integer, unsigned integer or floating-type), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number() << '\n';
    20  std::cout << j_boolean.is_number() << '\n';
    21  std::cout << j_number_integer.is_number() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number() << '\n';
    23  std::cout << j_number_float.is_number() << '\n';
    24  std::cout << j_object.is_number() << '\n';
    25  std::cout << j_array.is_number() << '\n';
    26  std::cout << j_string.is_number() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     true
    @@ -297,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html index 4adc0fb90..ed0850cf9 100644 --- a/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html +++ b/classnlohmann_1_1basic__json_a140b8251f82e99ad279dcad5c977e26b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -285,7 +287,7 @@ template<typename T , std::size_t n>
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    2
     
     {
    @@ -321,7 +323,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 8cea0b59d..38328c8cd 100644 --- a/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html +++ b/classnlohmann_1_1basic__json_a1579a8f72a230358d6cd1a6e8a62859b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a19dfb04c297ffb5f0ef84abfa4a5a087.html b/classnlohmann_1_1basic__json_a19dfb04c297ffb5f0ef84abfa4a5a087.html index 3c2f99b46..88ad3904b 100644 --- a/classnlohmann_1_1basic__json_a19dfb04c297ffb5f0ef84abfa4a5a087.html +++ b/classnlohmann_1_1basic__json_a19dfb04c297ffb5f0ef84abfa4a5a087.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).end().
  • -
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::const_iterator it = array.cend();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
    See also
    end() – returns an iterator to the end
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html index a89a0d2ec..3a6931301 100644 --- a/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html +++ b/classnlohmann_1_1basic__json_a1a446a48beed4ea564addfd12d235793.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a1af360cb513cc32f28e80ddd0b9d7666.html b/classnlohmann_1_1basic__json_a1af360cb513cc32f28e80ddd0b9d7666.html index eed2bf59e..f37a79b29 100644 --- a/classnlohmann_1_1basic__json_a1af360cb513cc32f28e80ddd0b9d7666.html +++ b/classnlohmann_1_1basic__json_a1af360cb513cc32f28e80ddd0b9d7666.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is array, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_array() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_array()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_array() << '\n';
    20  std::cout << j_boolean.is_array() << '\n';
    21  std::cout << j_number_integer.is_array() << '\n';
    22  std::cout << j_number_unsigned_integer.is_array() << '\n';
    23  std::cout << j_number_float.is_array() << '\n';
    24  std::cout << j_object.is_array() << '\n';
    25  std::cout << j_array.is_array() << '\n';
    26  std::cout << j_string.is_array() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -292,7 +294,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html index 8c855c36a..d57e7f93d 100644 --- a/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html +++ b/classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html b/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html index 2101d5e6f..e2fa0b24a 100644 --- a/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html +++ b/classnlohmann_1_1basic__json_a20bfb2ca6d4c421c74bb3e53328cd437.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<typename ValueType , typename std::enable_if<
    Complexity
    Linear in the size of the JSON value.
    -
    Example
    The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard std::vector<short>, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string, json>.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using 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:10058
    +
    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:10102
    Output (play with this example online):
    1
     42 42
     17.23 17
    @@ -311,7 +313,7 @@ array: [1,2,3,4,5]
     
    diff --git a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html index 2dc671d81..03b4d1a59 100644 --- a/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html +++ b/classnlohmann_1_1basic__json_a214a8c22d616fd3567b88932c07436c9.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read and written using at().
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    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:1709
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:3101
    Output (play with this example online):
    "third"
    @@ -302,7 +304,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 b5a254576..31463786c 100644 --- a/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html +++ b/classnlohmann_1_1basic__json_a231b02148577b69a154b2ce2c87a5522.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html b/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html index 8894993db..14144b375 100644 --- a/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html +++ b/classnlohmann_1_1basic__json_a24d7df0b5b41319dbab2713d3641faf7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Since
    version 1.0.0
    -

    Definition at line 5244 of file json.hpp.

    +

    Definition at line 5292 of file json.hpp.

    @@ -293,7 +295,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html b/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html index 9f99b5845..ee73a9fd6 100644 --- a/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html +++ b/classnlohmann_1_1basic__json_a263a9ecde33a1f2ff63dcd15d5e42cb7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -312,7 +314,7 @@ erase() with null"
  • other types: constant
  • -
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_boolean = true;
    9  json j_number_integer = 17;
    10  json j_number_float = 23.42;
    11  json j_object = {{"one", 1}, {"two", 2}};
    12  json j_array = {1, 2, 4, 8, 16};
    13  json j_string = "Hello, world";
    14 
    15  // call erase
    16  j_boolean.erase(j_boolean.begin(), j_boolean.end());
    17  j_number_integer.erase(j_number_integer.begin(), j_number_integer.end());
    18  j_number_float.erase(j_number_float.begin(), j_number_float.end());
    19  j_object.erase(j_object.find("two"), j_object.end());
    20  j_array.erase(j_array.begin() + 1, j_array.begin() + 3);
    21  j_string.erase(j_string.begin(), j_string.end());
    22 
    23  // print values
    24  std::cout << j_boolean << '\n';
    25  std::cout << j_number_integer << '\n';
    26  std::cout << j_number_float << '\n';
    27  std::cout << j_object << '\n';
    28  std::cout << j_array << '\n';
    29  std::cout << j_string << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    null
     null
     null
    @@ -337,7 +339,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html b/classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html index 67bde844a..c3fd19a08 100644 --- a/classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html +++ b/classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -285,7 +287,7 @@ not found"
    Complexity
    Linear in the size of the JSON value and the length of the JSON patch. As usually only a fraction of the JSON value is affected by the patch, the complexity can usually be neglected.
    -
    Example
    The following code shows how a JSON patch is applied to a value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the original document
    8  json doc = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the patch
    16  json patch = R"(
    17  [
    18  { "op": "replace", "path": "/baz", "value": "boo" },
    19  { "op": "add", "path": "/hello", "value": ["world"] },
    20  { "op": "remove", "path": "/foo"}
    21  ]
    22  )"_json;
    23 
    24  // apply the patch
    25  json patched_doc = doc.patch(patch);
    26 
    27  // output original and patched document
    28  std::cout << std::setw(4) << doc << "\n\n"
    29  << std::setw(4) << patched_doc << std::endl;
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows how a JSON patch is applied to a value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the original document
    8  json doc = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the patch
    16  json patch = R"(
    17  [
    18  { "op": "replace", "path": "/baz", "value": "boo" },
    19  { "op": "add", "path": "/hello", "value": ["world"] },
    20  { "op": "remove", "path": "/foo"}
    21  ]
    22  )"_json;
    23 
    24  // apply the patch
    25  json patched_doc = doc.patch(patch);
    26 
    27  // output original and patched document
    28  std::cout << std::setw(4) << doc << "\n\n"
    29  << std::setw(4) << patched_doc << std::endl;
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    {
         "baz": "qux",
         "foo": "bar"
    @@ -305,7 +307,7 @@ not found" 
     RFC 6901 (JSON Pointer)
    Since
    version 2.0.0
    -

    Definition at line 9620 of file json.hpp.

    +

    Definition at line 9664 of file json.hpp.

    @@ -315,7 +317,7 @@ not found" diff --git a/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html b/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html index b1f04f38c..d349363f3 100644 --- a/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html +++ b/classnlohmann_1_1basic__json_a2badcf191deabf579abcf8d3654da26f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -279,7 +281,7 @@ 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 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:10058
    +
    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:10102
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    3.14159265358979
     null
    @@ -298,7 +300,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html b/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html index d303724a2..8ac29b996 100644 --- a/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html +++ b/classnlohmann_1_1basic__json_a2e26bd0b0168abb61f67ad5bcd5b9fa1.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -302,7 +304,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html index 6b5997986..10312c570 100644 --- a/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html +++ b/classnlohmann_1_1basic__json_a2f1f83aa187a56dc5ec7a7027065ac8a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 b8deab74d..448ca796e 100644 --- a/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html +++ b/classnlohmann_1_1basic__json_a34d6a60dd99e9f33b8273a1c8db5669b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
    @@ -308,7 +310,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator_serialize.cpp -o operator_serialize 
    Since
    version 1.0.0
    -

    Definition at line 5681 of file json.hpp.

    +

    Definition at line 5729 of file json.hpp.

    @@ -318,7 +320,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 e7319e16c..591c844fb 100644 --- a/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html +++ b/classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,8 +289,8 @@ 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 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:10058
    -
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5720
    +
    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:10102
    +
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5768
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:983
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:918
    @@ -330,7 +332,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    See also
    parse(std::istream&, parser_callback_t) for a version that reads from an input stream
    Since
    version 1.0.0
    -

    Definition at line 5720 of file json.hpp.

    +

    Definition at line 5768 of file json.hpp.

    @@ -340,7 +342,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a363da77bc39cae041d59ee334ac4f41b.html b/classnlohmann_1_1basic__json_a363da77bc39cae041d59ee334ac4f41b.html index dd92991d1..1342f21fa 100644 --- a/classnlohmann_1_1basic__json_a363da77bc39cae041d59ee334ac4f41b.html +++ b/classnlohmann_1_1basic__json_a363da77bc39cae041d59ee334ac4f41b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17 17 17
    @@ -297,7 +299,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html index 198906996..43d27e16c 100644 --- a/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html +++ b/classnlohmann_1_1basic__json_a3654da9a84deaf61899c4eee5b93c2c5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -299,7 +301,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 dd6a08008..211ec4833 100644 --- a/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html +++ b/classnlohmann_1_1basic__json_a38ee0f09a318d003add75e0787040794.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,14 +283,14 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant.
    -
    Example
    The example below shows how objects can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
    9 
    10  // create an object_t
    11  json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
    12 
    13  // swap the object stored in the JSON value
    14  value["translation"].swap(object);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "object = " << object << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows how objects can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { {"translation", {{"one", "eins"}, {"two", "zwei"}}} };
    9 
    10  // create an object_t
    11  json::object_t object = {{"cow", "Kuh"}, {"dog", "Hund"}};
    12 
    13  // swap the object stored in the JSON value
    14  value["translation"].swap(object);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "object = " << object << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:347
    Output (play with this example online):
    value = {"translation":{"cow":"Kuh","dog":"Hund"}}
     object = {"one":"eins","two":"zwei"}
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__object_t.cpp -o swap__object_t 
    Since
    version 1.0.0
    -

    Definition at line 5176 of file json.hpp.

    +

    Definition at line 5224 of file json.hpp.

    @@ -298,7 +300,7 @@ object = {"one":"eins","two":"zwei"} diff --git a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html index 1bab518dc..b599459c8 100644 --- a/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html +++ b/classnlohmann_1_1basic__json_a3aaf41d385f0d9a93deb92f9b14ae0cf.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ 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 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:10058
    +
    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:10102
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:393
    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 
    @@ -298,7 +300,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html index d4efd10e0..0fdd3d7e1 100644 --- a/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html +++ b/classnlohmann_1_1basic__json_a3da254c422ede5495f2815c5e48c00c5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ is out of range"
    Complexity
    Linear in distance between idx and the end of the container.
    -
    Example
    The example shows the effect of erase().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json j_array = {0, 1, 2, 3, 4, 5};
    9 
    10  // call erase
    11  j_array.erase(2);
    12 
    13  // print values
    14  std::cout << j_array << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -303,7 +305,7 @@ is out of range"
    diff --git a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html index 2a6da537b..570bef851 100644 --- a/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html +++ b/classnlohmann_1_1basic__json_a3ec8e17be8732fe436e9d6733f52b7a3.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a43c08a393368eb674d0dcdbe301aafe3.html b/classnlohmann_1_1basic__json_a43c08a393368eb674d0dcdbe301aafe3.html index ae877ecc5..a378e0b5f 100644 --- a/classnlohmann_1_1basic__json_a43c08a393368eb674d0dcdbe301aafe3.html +++ b/classnlohmann_1_1basic__json_a43c08a393368eb674d0dcdbe301aafe3.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().
  • -
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    11  json::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:240
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html b/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html index 172384268..056e725f3 100644 --- a/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html +++ b/classnlohmann_1_1basic__json_a45e789042a23138eba2b69f34df9fc45.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -302,7 +304,7 @@ out of range"
  • other types: constant
  • -
    Example
    The example shows the result of erase() for different JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_boolean = true;
    9  json j_number_integer = 17;
    10  json j_number_float = 23.42;
    11  json j_object = {{"one", 1}, {"two", 2}};
    12  json j_array = {1, 2, 4, 8, 16};
    13  json j_string = "Hello, world";
    14 
    15  // call erase
    16  j_boolean.erase(j_boolean.begin());
    17  j_number_integer.erase(j_number_integer.begin());
    18  j_number_float.erase(j_number_float.begin());
    19  j_object.erase(j_object.find("two"));
    20  j_array.erase(j_array.begin() + 2);
    21  j_string.erase(j_string.begin());
    22 
    23  // print values
    24  std::cout << j_boolean << '\n';
    25  std::cout << j_number_integer << '\n';
    26  std::cout << j_number_float << '\n';
    27  std::cout << j_object << '\n';
    28  std::cout << j_array << '\n';
    29  std::cout << j_string << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    null
     null
     null
    @@ -327,7 +329,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a4635e8c6d5a4599f12a76368e325acd8.html b/classnlohmann_1_1basic__json_a4635e8c6d5a4599f12a76368e325acd8.html index a3c439762..2dcf958f5 100644 --- a/classnlohmann_1_1basic__json_a4635e8c6d5a4599f12a76368e325acd8.html +++ b/classnlohmann_1_1basic__json_a4635e8c6d5a4599f12a76368e325acd8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rbegin().
  • -
    Example
    The following code shows an example for crbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    11  json::const_reverse_iterator it = array.crbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:240
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html index 92a743c86..ca46f8190 100644 --- a/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html +++ b/classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html index 93b8e8e89..bbf18f031 100644 --- a/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html +++ b/classnlohmann_1_1basic__json_a4ab93491f82545342562c7ee7e3166c7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -286,7 +288,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -302,7 +304,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html index d0bc9f30c..63a1759b1 100644 --- a/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html +++ b/classnlohmann_1_1basic__json_a4bbdfd6dd8d2e6fc9ac5d81ef61ba3fe.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ template<typename CompatibleNumberFloatType , typename = typename std::enabl In case the parameter val is not a number, a JSON null value is created instead.
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of several floating-point number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  float f42 = 42.23;
    9  float f_nan = 1.0f / 0.0f;
    10  double f23 = 23.42;
    11 
    12  // create JSON numbers
    13  json j42(f42);
    14  json j_nan(f_nan);
    15  json j23(f23);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j42 << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j23 << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows the construction of several floating-point number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different floating-point types
    8  float f42 = 42.23;
    9  float f_nan = 1.0f / 0.0f;
    10  double f23 = 23.42;
    11 
    12  // create JSON numbers
    13  json j42(f42);
    14  json j_nan(f_nan);
    15  json j23(f23);
    16 
    17  // serialize the JSON numbers
    18  std::cout << j42 << '\n';
    19  std::cout << j_nan << '\n';
    20  std::cout << j23 << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    42.2299995422363
     null
     23.42
    @@ -305,7 +307,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html index ab06899e4..86f41e4c9 100644 --- a/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html +++ b/classnlohmann_1_1basic__json_a4f332e90f3cae562d0c3fa6ba48f74f9.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17
    @@ -302,7 +304,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 fe741cc27..bbcf15278 100644 --- a/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html +++ b/classnlohmann_1_1basic__json_a51b0036310d8aa5858fecc0d91127f27.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -292,7 +294,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 76428037b..ba99e89f2 100644 --- a/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html +++ b/classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container, O(log(size())).
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a5327abb014dec211593b00959830650e.html b/classnlohmann_1_1basic__json_a5327abb014dec211593b00959830650e.html index 6b08f2bc3..17ebda42e 100644 --- a/classnlohmann_1_1basic__json_a5327abb014dec211593b00959830650e.html +++ b/classnlohmann_1_1basic__json_a5327abb014dec211593b00959830650e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    an object that maps JSON pointers to primitve values
    Note
    Empty objects and arrays are flattened to null and will not be reconstructed correctly by the unflatten() function.
    Complexity
    Linear in the size the JSON value.
    -
    Example
    The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j =
    9  {
    10  {"pi", 3.141},
    11  {"happy", true},
    12  {"name", "Niels"},
    13  {"nothing", nullptr},
    14  {
    15  "answer", {
    16  {"everything", 42}
    17  }
    18  },
    19  {"list", {1, 0, 2}},
    20  {
    21  "object", {
    22  {"currency", "USD"},
    23  {"value", 42.99}
    24  }
    25  }
    26  };
    27 
    28  // call flatten()
    29  std::cout << std::setw(4) << j.flatten() << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows how a JSON object is flattened to an object whose keys consist of JSON pointers.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON value
    8  json j =
    9  {
    10  {"pi", 3.141},
    11  {"happy", true},
    12  {"name", "Niels"},
    13  {"nothing", nullptr},
    14  {
    15  "answer", {
    16  {"everything", 42}
    17  }
    18  },
    19  {"list", {1, 0, 2}},
    20  {
    21  "object", {
    22  {"currency", "USD"},
    23  {"value", 42.99}
    24  }
    25  }
    26  };
    27 
    28  // call flatten()
    29  std::cout << std::setw(4) << j.flatten() << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    {
         "/answer/everything": 42,
         "/happy": true,
    @@ -287,7 +289,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    See also
    unflatten() for the reverse function
    Since
    version 2.0.0
    -

    Definition at line 9536 of file json.hpp.

    +

    Definition at line 9580 of file json.hpp.

    @@ -297,7 +299,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a53771a7a4f2787125e55f64448f24ce6.html b/classnlohmann_1_1basic__json_a53771a7a4f2787125e55f64448f24ce6.html index 8429229cb..8ec06aa03 100644 --- a/classnlohmann_1_1basic__json_a53771a7a4f2787125e55f64448f24ce6.html +++ b/classnlohmann_1_1basic__json_a53771a7a4f2787125e55f64448f24ce6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -274,7 +276,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -288,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a558b345044c38a9f6ad522592cc700c8.html b/classnlohmann_1_1basic__json_a558b345044c38a9f6ad522592cc700c8.html index b297ff14a..3663e3fed 100644 --- a/classnlohmann_1_1basic__json_a558b345044c38a9f6ad522592cc700c8.html +++ b/classnlohmann_1_1basic__json_a558b345044c38a9f6ad522592cc700c8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is structured (array or object), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_structured() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_structured()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_structured() << '\n';
    20  std::cout << j_boolean.is_structured() << '\n';
    21  std::cout << j_number_integer.is_structured() << '\n';
    22  std::cout << j_number_unsigned_integer.is_structured() << '\n';
    23  std::cout << j_number_float.is_structured() << '\n';
    24  std::cout << j_object.is_structured() << '\n';
    25  std::cout << j_array.is_structured() << '\n';
    26  std::cout << j_string.is_structured() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -297,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html index 48c7553f5..b198511a1 100644 --- a/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html +++ b/classnlohmann_1_1basic__json_a5685815624b086caa532f41e853d4b0f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ 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 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:10058
    +
    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:10102
    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:1709
    Output (play with this example online):
    []
     []
    @@ -303,7 +305,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    diff --git a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html index bee6ccc57..c41ecb900 100644 --- a/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html +++ b/classnlohmann_1_1basic__json_a59732a1de287a7301cca19a7a7748159.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant if idx is in the range of the array. Otherwise linear in idx - size().
    -
    Example
    The example below shows how array elements can be read and written using [] operator. Note the addition of null values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // output element at index 3 (fourth element)
    11  std::cout << array[3] << '\n';
    12 
    13  // change last element to 6
    14  array[array.size() - 1] = 6;
    15 
    16  // output changed array
    17  std::cout << array << '\n';
    18 
    19  // write beyond array limit
    20  array[10] = 11;
    21 
    22  // output changed array
    23  std::cout << array << '\n';
    24 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    4
     [1,2,3,4,6]
     [1,2,3,4,6,null,null,null,null,null,11]
    @@ -300,7 +302,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    diff --git a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html index 2c233118c..7e3f8d003 100644 --- a/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html +++ b/classnlohmann_1_1basic__json_a5c8bb5200f5eac10d31e26be46e5b1ac.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__greater.cpp -o operator__greater 
    Since
    version 1.0.0
    -

    Definition at line 5582 of file json.hpp.

    +

    Definition at line 5630 of file json.hpp.

    @@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html index 2d1bf048f..18e8e9efa 100644 --- a/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html +++ b/classnlohmann_1_1basic__json_a5e34c5435e557d0bf666bd7311211405.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    {"one":1,"two":2}
     
     [1,2,4,8,16]
    @@ -308,7 +310,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator_serialize.cpp -o operator_serialize 
    Since
    version 1.0.0
    -

    Definition at line 5663 of file json.hpp.

    +

    Definition at line 5711 of file json.hpp.

    @@ -318,7 +320,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html index 5ebd27ef3..ec6313d83 100644 --- a/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html +++ b/classnlohmann_1_1basic__json_a60a04166c122072ab11eaf9845d9cd1d.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -293,7 +295,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 08209d93d..66bdba268 100644 --- a/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html +++ b/classnlohmann_1_1basic__json_a60ca396028b8d9714c6e10efbf475af6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -293,7 +295,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    {
       "array": [
         1,
    @@ -311,7 +313,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    See also
    parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
    Since
    version 1.0.0
    -

    Definition at line 5785 of file json.hpp.

    +

    Definition at line 5833 of file json.hpp.

    @@ -321,7 +323,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html index 3c229f1e6..4e9e0d355 100644 --- a/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html +++ b/classnlohmann_1_1basic__json_a624025acfcf64364d98424402b837bc6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -301,13 +303,13 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    7
     [1,2,7,7,7,7,7,7,7,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__count.cpp -o insert__count 
    Since
    version 1.0.0
    -

    Definition at line 4962 of file json.hpp.

    +

    Definition at line 5010 of file json.hpp.

    @@ -317,7 +319,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a628733b45cd0e32bd59efea149f40b4b.html b/classnlohmann_1_1basic__json_a628733b45cd0e32bd59efea149f40b4b.html index 6ccd55e37..abf2cc157 100644 --- a/classnlohmann_1_1basic__json_a628733b45cd0e32bd59efea149f40b4b.html +++ b/classnlohmann_1_1basic__json_a628733b45cd0e32bd59efea149f40b4b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is a floating-point number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_float() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_float()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_float() << '\n';
    20  std::cout << j_boolean.is_number_float() << '\n';
    21  std::cout << j_number_integer.is_number_float() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_float() << '\n';
    23  std::cout << j_number_float.is_number_float() << '\n';
    24  std::cout << j_object.is_number_float() << '\n';
    25  std::cout << j_array.is_number_float() << '\n';
    26  std::cout << j_string.is_number_float() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -297,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html b/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html index 0851d87c3..4c874948f 100644 --- a/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html +++ b/classnlohmann_1_1basic__json_a62ccf5b9b3674aec2403fbc02da03db8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of reverse_iterator(end()).
  • -
    Example
    The following code shows an example for rbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-beginning
    11  json::reverse_iterator it = array.rbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:238
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html b/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html index dbe9ec7ae..bef41c2b2 100644 --- a/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html +++ b/classnlohmann_1_1basic__json_a649aef71e5d952499da7ad3b8e7c9236.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j.at("/string"_json_pointer) = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // change an array element
    32  j.at("/array/1"_json_pointer) = 21;
    33  // output the changed array
    34  std::cout << j["array"] << '\n';
    35 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j.at("/number"_json_pointer) << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j.at("/string"_json_pointer) << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j.at("/array"_json_pointer) << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j.at("/array/1"_json_pointer) << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j.at("/string"_json_pointer) = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // change an array element
    32  j.at("/array/1"_json_pointer) = 21;
    33  // output the changed array
    34  std::cout << j["array"] << '\n';
    35 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -294,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/at_json_pointer.cpp -o at_json_pointer 
    Since
    version 2.0.0
    -

    Definition at line 9484 of file json.hpp.

    +

    Definition at line 9528 of file json.hpp.

    @@ -304,7 +306,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a66c051561828b2c4eeaad896a72bec99.html b/classnlohmann_1_1basic__json_a66c051561828b2c4eeaad896a72bec99.html index b29880fd5..9fd890fd4 100644 --- a/classnlohmann_1_1basic__json_a66c051561828b2c4eeaad896a72bec99.html +++ b/classnlohmann_1_1basic__json_a66c051561828b2c4eeaad896a72bec99.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -271,7 +273,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is discarded, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_discarded() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_discarded()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_discarded() << '\n';
    20  std::cout << j_boolean.is_discarded() << '\n';
    21  std::cout << j_number_integer.is_discarded() << '\n';
    22  std::cout << j_number_unsigned_integer.is_discarded() << '\n';
    23  std::cout << j_number_float.is_discarded() << '\n';
    24  std::cout << j_object.is_discarded() << '\n';
    25  std::cout << j_array.is_discarded() << '\n';
    26  std::cout << j_string.is_discarded() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -293,7 +295,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html b/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html index 4ff09824b..2ed27bdbe 100644 --- a/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html +++ b/classnlohmann_1_1basic__json_a674de1ee73e6bf4843fc5dc1351fb726.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using at().
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    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 
    @@ -302,7 +304,7 @@ out of range
    diff --git a/classnlohmann_1_1basic__json_a685d9d6a8a45bfcb8455b147257cdffb.html b/classnlohmann_1_1basic__json_a685d9d6a8a45bfcb8455b147257cdffb.html index 88b202f95..7ac8b3eaa 100644 --- a/classnlohmann_1_1basic__json_a685d9d6a8a45bfcb8455b147257cdffb.html +++ b/classnlohmann_1_1basic__json_a685d9d6a8a45bfcb8455b147257cdffb.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is null, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_null() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_null()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_null() << '\n';
    20  std::cout << j_boolean.is_null() << '\n';
    21  std::cout << j_number_integer.is_null() << '\n';
    22  std::cout << j_number_unsigned_integer.is_null() << '\n';
    23  std::cout << j_number_float.is_null() << '\n';
    24  std::cout << j_object.is_null() << '\n';
    25  std::cout << j_array.is_null() << '\n';
    26  std::cout << j_string.is_null() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    true
     false
     false
    @@ -292,7 +294,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html index b01a75350..f83d26cd7 100644 --- a/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html +++ b/classnlohmann_1_1basic__json_a68a5f34b164a07b8ced13fcf2b7ec834.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -296,7 +298,7 @@ template<typename CompatibleNumberUnsignedType , typename std::enable_if< diff --git a/classnlohmann_1_1basic__json_a68f0a8c4618d57523384ec7ecd2f5819.html b/classnlohmann_1_1basic__json_a68f0a8c4618d57523384ec7ecd2f5819.html index 71cec2d38..646335211 100644 --- a/classnlohmann_1_1basic__json_a68f0a8c4618d57523384ec7ecd2f5819.html +++ b/classnlohmann_1_1basic__json_a68f0a8c4618d57523384ec7ecd2f5819.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).end().
  • -
    Example
    The following code shows an example for cend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to one past the last element
    11  json::const_iterator it = array.cend();
    12 
    13  // decrement the iterator to point to the last element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    5
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cend.cpp -o cend 
    See also
    end() – returns an iterator to the end
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a693b411d9c5ad0d168a0013cfb80b8e5.html b/classnlohmann_1_1basic__json_a693b411d9c5ad0d168a0013cfb80b8e5.html index d1c63048e..97724d808 100644 --- a/classnlohmann_1_1basic__json_a693b411d9c5ad0d168a0013cfb80b8e5.html +++ b/classnlohmann_1_1basic__json_a693b411d9c5ad0d168a0013cfb80b8e5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is an unsigned integer number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_unsigned() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_unsigned()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_unsigned() << '\n';
    20  std::cout << j_boolean.is_number_unsigned() << '\n';
    21  std::cout << j_number_integer.is_number_unsigned() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_unsigned() << '\n';
    23  std::cout << j_number_float.is_number_unsigned() << '\n';
    24  std::cout << j_object.is_number_unsigned() << '\n';
    25  std::cout << j_array.is_number_unsigned() << '\n';
    26  std::cout << j_string.is_number_unsigned() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -297,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html index 1e0166e4e..0aab94634 100644 --- a/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html +++ b/classnlohmann_1_1basic__json_a6e2e21da48f5d9471716cd868a068327.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3] == [1,2,4] true
     {"A":"a","B":"b"} == {"A":"a","B":"b"} false
     17 == 17 false
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__notequal.cpp -o operator__notequal 
    Since
    version 1.0.0
    -

    Definition at line 5420 of file json.hpp.

    +

    Definition at line 5468 of file json.hpp.

    @@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html index 9dfed2953..33e264e47 100644 --- a/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html +++ b/classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html b/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html index 71edb8d3b..70920400a 100644 --- a/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html +++ b/classnlohmann_1_1basic__json_a70ae1f0747f5b7a89979512866474f1a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 an integer number value from an anonymous enum.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // an anonymous enum
    8  enum { t = 17 };
    9 
    10  // create a JSON number from the enum
    11  json j(t);
    12 
    13  // serialize the JSON numbers
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows the construction of an integer number value from an anonymous enum.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // an anonymous enum
    8  enum { t = 17 };
    9 
    10  // create a JSON number from the enum
    11  json j(t);
    12 
    13  // serialize the JSON numbers
    14  std::cout << j << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    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)
    @@ -294,7 +296,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html index 6d4121228..f884a88f9 100644 --- a/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html +++ b/classnlohmann_1_1basic__json_a71b1d38ef402dfee58fba1fe01fa67f5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows an example for back().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call back()
    19  //std::cout << j_null.back() << '\n'; // would throw
    20  std::cout << j_boolean.back() << '\n';
    21  std::cout << j_number_integer.back() << '\n';
    22  std::cout << j_number_float.back() << '\n';
    23  std::cout << j_object.back() << '\n';
    24  //std::cout << j_object_empty.back() << '\n'; // undefined behavior
    25  std::cout << j_array.back() << '\n';
    26  //std::cout << j_array_empty.back() << '\n'; // undefined behavior
    27  std::cout << j_string.back() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -299,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    diff --git a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html index 353bce8ef..6f1107b13 100644 --- a/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html +++ b/classnlohmann_1_1basic__json_a73e150cbcba5643cb89de8f515eb64e2.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -292,7 +294,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 a6bde1a2a..195d4742b 100644 --- a/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html +++ b/classnlohmann_1_1basic__json_a74a0013e847fdc574b48f931f0e757e1.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -289,7 +291,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 51305324c..d7d9c6985 100644 --- a/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html +++ b/classnlohmann_1_1basic__json_a74a943800c7f103d0990d7eef82c6453.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__greaterequal.cpp -o operator__greaterequal 
    Since
    version 1.0.0
    -

    Definition at line 5626 of file json.hpp.

    +

    Definition at line 5674 of file json.hpp.

    @@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html b/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html index d569a3e80..9dfe9b5ad 100644 --- a/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html +++ b/classnlohmann_1_1basic__json_a7605b20debcc12fc44bd9f2075122a87.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -289,7 +291,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j["/string"_json_pointer] = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // "change" a nonexisting object entry
    32  j["/boolean"_json_pointer] = true;
    33  // output the changed object
    34  std::cout << j << '\n';
    35 
    36  // change an array element
    37  j["/array/1"_json_pointer] = 21;
    38  // "change" an array element with nonexisting index
    39  j["/array/4"_json_pointer] = 44;
    40  // output the changed array
    41  std::cout << j["array"] << '\n';
    42 
    43  // "change" the arry element past the end
    44  j["/array/-"_json_pointer] = 55;
    45  // output the changed array
    46  std::cout << j["array"] << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 
    24  // writing access
    25 
    26  // change the string
    27  j["/string"_json_pointer] = "bar";
    28  // output the changed string
    29  std::cout << j["string"] << '\n';
    30 
    31  // "change" a nonexisting object entry
    32  j["/boolean"_json_pointer] = true;
    33  // output the changed object
    34  std::cout << j << '\n';
    35 
    36  // change an array element
    37  j["/array/1"_json_pointer] = 21;
    38  // "change" an array element with nonexisting index
    39  j["/array/4"_json_pointer] = 44;
    40  // output the changed array
    41  std::cout << j["array"] << '\n';
    42 
    43  // "change" the arry element past the end
    44  j["/array/-"_json_pointer] = 55;
    45  // output the changed array
    46  std::cout << j["array"] << '\n';
    47 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -301,7 +303,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorjson_pointer.cpp -o operatorjson_pointer 
    Since
    version 2.0.0
    -

    Definition at line 9432 of file json.hpp.

    +

    Definition at line 9476 of file json.hpp.

    @@ -311,7 +313,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a76347b37f07c75049f5164053a6cf81a.html b/classnlohmann_1_1basic__json_a76347b37f07c75049f5164053a6cf81a.html index fa65ba7f8..747b78b6b 100644 --- a/classnlohmann_1_1basic__json_a76347b37f07c75049f5164053a6cf81a.html +++ b/classnlohmann_1_1basic__json_a76347b37f07c75049f5164053a6cf81a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  const json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The behavior is shown in the example.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  const json j =
    9  {
    10  {"number", 1}, {"string", "foo"}, {"array", {1, 2}}
    11  };
    12 
    13  // read-only access
    14 
    15  // output element with JSON pointer "/number"
    16  std::cout << j["/number"_json_pointer] << '\n';
    17  // output element with JSON pointer "/string"
    18  std::cout << j["/string"_json_pointer] << '\n';
    19  // output element with JSON pointer "/array"
    20  std::cout << j["/array"_json_pointer] << '\n';
    21  // output element with JSON pointer "/array/1"
    22  std::cout << j["/array/1"_json_pointer] << '\n';
    23 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    1
     "foo"
     [1,2]
    @@ -292,7 +294,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operatorjson_pointer_const.cpp -o operatorjson_pointer_const 
    Since
    version 2.0.0
    -

    Definition at line 9459 of file json.hpp.

    +

    Definition at line 9503 of file json.hpp.

    @@ -302,7 +304,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html index 994d099e4..992e4d86b 100644 --- a/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html +++ b/classnlohmann_1_1basic__json_a7ab11375ed2e29c2fcb6119386851445.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17 17 17
    @@ -296,7 +298,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html b/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html index 62f57531e..6a342ba69 100644 --- a/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html +++ b/classnlohmann_1_1basic__json_a7c3182cfabc0bdd9f3a14216fe0e8154.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -279,7 +281,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a7c774ef0eceff6d06095f617e2dbd488.html b/classnlohmann_1_1basic__json_a7c774ef0eceff6d06095f617e2dbd488.html index f50108b9e..474b0da08 100644 --- a/classnlohmann_1_1basic__json_a7c774ef0eceff6d06095f617e2dbd488.html +++ b/classnlohmann_1_1basic__json_a7c774ef0eceff6d06095f617e2dbd488.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is primitive (string, number, boolean, or null), false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_primitive() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_primitive()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_primitive() << '\n';
    20  std::cout << j_boolean.is_primitive() << '\n';
    21  std::cout << j_number_integer.is_primitive() << '\n';
    22  std::cout << j_number_unsigned_integer.is_primitive() << '\n';
    23  std::cout << j_number_float.is_primitive() << '\n';
    24  std::cout << j_object.is_primitive() << '\n';
    25  std::cout << j_array.is_primitive() << '\n';
    26  std::cout << j_string.is_primitive() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    true
     true
     true
    @@ -301,7 +303,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html index cf5fab034..bc91671ed 100644 --- a/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html +++ b/classnlohmann_1_1basic__json_a7ed92d56cb313b243c1917696ffdf074.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using at().
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    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
    @@ -303,7 +305,7 @@ out of range: key 'the fast' not found
     
    diff --git a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html index 82f37cfab..0c606691a 100644 --- a/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html +++ b/classnlohmann_1_1basic__json_a7f7bbb3a9efef2e2442f538a24c1c47b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -294,13 +296,13 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    10
     [1,2,10,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
    Since
    version 1.0.0
    -

    Definition at line 4906 of file json.hpp.

    +

    Definition at line 4954 of file json.hpp.

    @@ -310,7 +312,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 69581c6db..32be046ce 100644 --- a/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html +++ b/classnlohmann_1_1basic__json_a7f97a91ad8f1d5cf0b9213bd24f247c4.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     null != nullptr false
     

    The example code above can be translated with

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

    Definition at line 5452 of file json.hpp.

    +

    Definition at line 5500 of file json.hpp.

    @@ -305,7 +307,7 @@ null != nullptr false diff --git a/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html b/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html index f1c99ac34..c32256479 100644 --- a/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html +++ b/classnlohmann_1_1basic__json_a8032645ce3109a7a4899badd90fa3480.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -300,7 +302,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 7c76ccd6c..8e267c9ff 100644 --- a/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html +++ b/classnlohmann_1_1basic__json_a805e3f3a2f374da0e14942eec7400e40.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    {"one":1,"two":2}
     
     {"one":1,"two":2}
    @@ -325,7 +327,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 8e59085d2..56b4a602f 100644 --- a/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html +++ b/classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Amortized constant.
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON array. Note how the null value was silently converted to a JSON array.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3,4,5]
     null
     [1,2,3,4,5,6,7]
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html index 19fd8dc0f..e89a15b4d 100644 --- a/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html +++ b/classnlohmann_1_1basic__json_a81aaaab0f3b326afda2d226daab4f1e1.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -289,7 +291,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    [1,2,3,4]
     [1.2,2.3,3.4,5.6]
     [true,true,false,true]
    @@ -313,7 +315,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 5ef5bc101..80e5ae727 100644 --- a/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html +++ b/classnlohmann_1_1basic__json_a8209621de6184d9eabe136b7c8f61935.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -282,14 +284,14 @@ use swap() with string"
    Complexity
    Constant.
    -
    Example
    The example below shows how arrays can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = {{"array", {1, 2, 3, 4}}};
    9 
    10  // create an array_t
    11  json::array_t array = {"Snap", "Crackle", "Pop"};
    12 
    13  // swap the array stored in the JSON value
    14  value["array"].swap(array);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "array = " << array << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows how arrays can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = {{"array", {1, 2, 3, 4}}};
    9 
    10  // create an array_t
    11  json::array_t array = {"Snap", "Crackle", "Pop"};
    12 
    13  // swap the array stored in the JSON value
    14  value["array"].swap(array);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "array = " << array << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:393
    Output (play with this example online):
    value = {"array":["Snap","Crackle","Pop"]}
     array = [1,2,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__array_t.cpp -o swap__array_t 
    Since
    version 1.0.0
    -

    Definition at line 5142 of file json.hpp.

    +

    Definition at line 5190 of file json.hpp.

    @@ -299,7 +301,7 @@ array = [1,2,3,4] diff --git a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html index fe41dc9d3..11ac08a31 100644 --- a/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html +++ b/classnlohmann_1_1basic__json_a8468efcfcd95db15f46887b29924ed5c.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -294,13 +296,13 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    10
     [1,2,10,3,4]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert.cpp -o insert 
    Since
    version 1.0.0
    -

    Definition at line 4933 of file json.hpp.

    +

    Definition at line 4981 of file json.hpp.

    @@ -310,7 +312,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a848cbae3bd3502ffbf738320bf5eb3aa.html b/classnlohmann_1_1basic__json_a848cbae3bd3502ffbf738320bf5eb3aa.html index 4267cdc7e..f042bd76c 100644 --- a/classnlohmann_1_1basic__json_a848cbae3bd3502ffbf738320bf5eb3aa.html +++ b/classnlohmann_1_1basic__json_a848cbae3bd3502ffbf738320bf5eb3aa.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    the type of the JSON value
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies type() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_array = {1, 2, 4, 8, 16};
    14  json j_string = "Hello, world";
    15 
    16  // call type()
    17  std::cout << std::boolalpha;
    18  std::cout << (j_null.type() == json::value_t::null) << '\n';
    19  std::cout << (j_boolean.type() == json::value_t::boolean) << '\n';
    20  std::cout << (j_number_integer.type() == json::value_t::number_integer) << '\n';
    21  std::cout << (j_number_float.type() == json::value_t::number_float) << '\n';
    22  std::cout << (j_object.type() == json::value_t::object) << '\n';
    23  std::cout << (j_array.type() == json::value_t::array) << '\n';
    24  std::cout << (j_string.type() == json::value_t::string) << '\n';
    25 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    @@ -298,7 +300,7 @@ true
    diff --git a/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html b/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html index dfd667ef9..05a56422d 100644 --- a/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html +++ b/classnlohmann_1_1basic__json_a85b09b03916d3d1e73373f49cdd4136d.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -296,7 +298,7 @@ template<typename T , typename std::enable_if<
    diff --git a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html index bd6f4ad6c..aae6b46d6 100644 --- a/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html +++ b/classnlohmann_1_1basic__json_a86089c703a2e563b9f760c2f8408efa7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -282,14 +284,14 @@ use swap() with boolean"
    Complexity
    Constant.
    -
    Example
    The example below shows how strings can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { "the good", "the bad", "the ugly" };
    9 
    10  // create string_t
    11  json::string_t string = "the fast";
    12 
    13  // swap the object stored in the JSON value
    14  value[1].swap(string);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "string = " << string << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows how strings can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON value
    8  json value = { "the good", "the bad", "the ugly" };
    9 
    10  // create string_t
    11  json::string_t string = "the fast";
    12 
    13  // swap the object stored in the JSON value
    14  value[1].swap(string);
    15 
    16  // output the values
    17  std::cout << "value = " << value << '\n';
    18  std::cout << "string = " << string << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    StringType string_t
    a type for a string
    Definition: json.hpp:440
    Output (play with this example online):
    value = ["the good","the fast","the ugly"]
     string = the bad
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__string_t.cpp -o swap__string_t 
    Since
    version 1.0.0
    -

    Definition at line 5210 of file json.hpp.

    +

    Definition at line 5258 of file json.hpp.

    @@ -299,7 +301,7 @@ string = the bad diff --git a/classnlohmann_1_1basic__json_a86a477c16dac3bdd4929fee2db394256.html b/classnlohmann_1_1basic__json_a86a477c16dac3bdd4929fee2db394256.html index aee523e16..0d0989b7d 100644 --- a/classnlohmann_1_1basic__json_a86a477c16dac3bdd4929fee2db394256.html +++ b/classnlohmann_1_1basic__json_a86a477c16dac3bdd4929fee2db394256.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).begin().
  • -
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  const json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::const_iterator it = array.cbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
    See also
    begin() – returns an iterator to the beginning
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_a87499fdb56ca6f0df2242c3335c3dc9b.html b/classnlohmann_1_1basic__json_a87499fdb56ca6f0df2242c3335c3dc9b.html index 13786ece3..fd274f2e4 100644 --- a/classnlohmann_1_1basic__json_a87499fdb56ca6f0df2242c3335c3dc9b.html +++ b/classnlohmann_1_1basic__json_a87499fdb56ca6f0df2242c3335c3dc9b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is an integer or unsigned integer number, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_number_integer() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_number_integer()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_number_integer() << '\n';
    20  std::cout << j_boolean.is_number_integer() << '\n';
    21  std::cout << j_number_integer.is_number_integer() << '\n';
    22  std::cout << j_number_unsigned_integer.is_number_integer() << '\n';
    23  std::cout << j_number_float.is_number_integer() << '\n';
    24  std::cout << j_object.is_number_integer() << '\n';
    25  std::cout << j_array.is_number_integer() << '\n';
    26  std::cout << j_string.is_number_integer() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     true
    @@ -297,7 +299,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html index 3ea51d5d6..874ba5f3b 100644 --- a/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html +++ b/classnlohmann_1_1basic__json_a87db51b6b936fb2ea293cdbc8702dcb8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__lessequal.cpp -o operator__lessequal 
    Since
    version 1.0.0
    -

    Definition at line 5604 of file json.hpp.

    +

    Definition at line 5652 of file json.hpp.

    @@ -305,7 +307,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html index 327b548db..b75685fcd 100644 --- a/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html +++ b/classnlohmann_1_1basic__json_a8f77085bd98c97a983d9ba12efbf6148.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -297,7 +299,7 @@ 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 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:10058
    +
    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:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    @@ -340,7 +342,7 @@ false
    diff --git a/classnlohmann_1_1basic__json_a8f7e67d903f918cd08261219fb47a9f0.html b/classnlohmann_1_1basic__json_a8f7e67d903f918cd08261219fb47a9f0.html index 6b9ac067b..c18717eb9 100644 --- a/classnlohmann_1_1basic__json_a8f7e67d903f918cd08261219fb47a9f0.html +++ b/classnlohmann_1_1basic__json_a8f7e67d903f918cd08261219fb47a9f0.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is boolean, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_boolean() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_unsigned_integer = 12345678987654321u;
    12  json j_number_float = 23.42;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_boolean()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_boolean() << '\n';
    20  std::cout << j_boolean.is_boolean() << '\n';
    21  std::cout << j_number_integer.is_boolean() << '\n';
    22  std::cout << j_number_unsigned_integer.is_boolean() << '\n';
    23  std::cout << j_number_float.is_boolean() << '\n';
    24  std::cout << j_object.is_boolean() << '\n';
    25  std::cout << j_array.is_boolean() << '\n';
    26  std::cout << j_string.is_boolean() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     true
     false
    @@ -292,7 +294,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html b/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html index d0e93450f..0629e6288 100644 --- a/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html +++ b/classnlohmann_1_1basic__json_a90239431815c94b0a334f7f4c55eb859.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -290,7 +292,7 @@ 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 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:10058
    +
    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:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -316,7 +318,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_a928b98a9b2e7f23d93ffba4024cbcaf5.html b/classnlohmann_1_1basic__json_a928b98a9b2e7f23d93ffba4024cbcaf5.html index 414cd6ee7..ebd5b3ff1 100644 --- a/classnlohmann_1_1basic__json_a928b98a9b2e7f23d93ffba4024cbcaf5.html +++ b/classnlohmann_1_1basic__json_a928b98a9b2e7f23d93ffba4024cbcaf5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -296,9 +298,9 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    a JSON patch to convert the source to target
    Complexity
    Linear in the lengths of source and target.
    -
    Example
    The following code shows how a JSON patch is created as a diff for two JSON values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the source document
    8  json source = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the target document
    16  json target = R"(
    17  {
    18  "baz": "boo",
    19  "hello": [
    20  "world"
    21  ]
    22  }
    23  )"_json;
    24 
    25  // create the patch
    26  json patch = json::diff(source, target);
    27 
    28  // roundtrip
    29  json patched_source = source.patch(patch);
    30 
    31  // output patch and roundtrip result
    32  std::cout << std::setw(4) << patch << "\n\n"
    33  << std::setw(4) << patched_source << std::endl;
    34 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    -
    static basic_json diff(const basic_json &source, const basic_json &target, std::string path="") noexcept
    creates a diff as a JSON patch
    Definition: json.hpp:9913
    -
    basic_json patch(const basic_json &patch) const
    applies a JSON patch
    Definition: json.hpp:9620
    +
    Example
    The following code shows how a JSON patch is created as a diff for two JSON values.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // the source document
    8  json source = R"(
    9  {
    10  "baz": "qux",
    11  "foo": "bar"
    12  }
    13  )"_json;
    14 
    15  // the target document
    16  json target = R"(
    17  {
    18  "baz": "boo",
    19  "hello": [
    20  "world"
    21  ]
    22  }
    23  )"_json;
    24 
    25  // create the patch
    26  json patch = json::diff(source, target);
    27 
    28  // roundtrip
    29  json patched_source = source.patch(patch);
    30 
    31  // output patch and roundtrip result
    32  std::cout << std::setw(4) << patch << "\n\n"
    33  << std::setw(4) << patched_source << std::endl;
    34 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    +
    static basic_json diff(const basic_json &source, const basic_json &target, std::string path="") noexcept
    creates a diff as a JSON patch
    Definition: json.hpp:9957
    +
    basic_json patch(const basic_json &patch) const
    applies a JSON patch
    Definition: json.hpp:9664
    Output (play with this example online):
    [
         {
             "op": "replace",
    @@ -330,7 +332,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     RFC 6902 (JSON Patch)
    Since
    version 2.0.0
    -

    Definition at line 9913 of file json.hpp.

    +

    Definition at line 9957 of file json.hpp.

    @@ -340,7 +342,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html index 0787ca836..58ee3ff17 100644 --- a/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html +++ b/classnlohmann_1_1basic__json_a92fbb711a36b5ce78ee228b26787c034.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using 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:10058
    +
    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:10102
    Output (play with this example online):
    2
     
     {
    @@ -319,7 +321,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 c92c31048..cdc3b3f85 100644 --- a/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html +++ b/classnlohmann_1_1basic__json_a947b5b2a832e490858dbdddfe7085831.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -285,7 +287,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 45bfa6f86..43d122411 100644 --- a/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html +++ b/classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Logarithmic in the size of the container, O(log(size())).
    -
    Example
    The example shows how push_back() and += can be used to add elements to a JSON object. Note how the null value was silently converted to a JSON object.
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    Output (play with this example online):
    {"one":1,"two":2}
     null
     {"four":4,"one":1,"three":3,"two":2}
    @@ -299,7 +301,7 @@ null
     
    diff --git a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html index c1bdb9f2a..1ccb22c5c 100644 --- a/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html +++ b/classnlohmann_1_1basic__json_a9730b9f7bc2150e641fe20198d4477c7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     null == nullptr true
     

    The example code above can be translated with

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

    Definition at line 5390 of file json.hpp.

    +

    Definition at line 5438 of file json.hpp.

    @@ -305,7 +307,7 @@ null == nullptr true diff --git a/classnlohmann_1_1basic__json_a9857835334d38ba04959e348ca6be208.html b/classnlohmann_1_1basic__json_a9857835334d38ba04959e348ca6be208.html index 9db335efc..e71f3a0ae 100644 --- a/classnlohmann_1_1basic__json_a9857835334d38ba04959e348ca6be208.html +++ b/classnlohmann_1_1basic__json_a9857835334d38ba04959e348ca6be208.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -286,7 +288,7 @@ 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. 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 constructing a JSON value from a std::stringstream with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  auto text = R"(
    9  {
    10  "Image": {
    11  "Width": 800,
    12  "Height": 600,
    13  "Title": "View from 15th Floor",
    14  "Thumbnail": {
    15  "Url": "http://www.example.com/image/481989943",
    16  "Height": 125,
    17  "Width": 100
    18  },
    19  "Animated" : false,
    20  "IDs": [116, 943, 234, 38793]
    21  }
    22  }
    23  )";
    24 
    25  // fill a stream with JSON text
    26  std::stringstream ss;
    27  ss << text;
    28 
    29  // create JSON from stream
    30  json j_complete(ss);
    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  // create JSON from stream (with callback)
    53  json j_filtered(ss, cb);
    54  std::cout << std::setw(4) << j_filtered << '\n';
    55 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below demonstrates constructing a JSON value from a std::stringstream with and without callback function.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // a JSON text
    8  auto text = R"(
    9  {
    10  "Image": {
    11  "Width": 800,
    12  "Height": 600,
    13  "Title": "View from 15th Floor",
    14  "Thumbnail": {
    15  "Url": "http://www.example.com/image/481989943",
    16  "Height": 125,
    17  "Width": 100
    18  },
    19  "Animated" : false,
    20  "IDs": [116, 943, 234, 38793]
    21  }
    22  }
    23  )";
    24 
    25  // fill a stream with JSON text
    26  std::stringstream ss;
    27  ss << text;
    28 
    29  // create JSON from stream
    30  json j_complete(ss);
    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  // create JSON from stream (with callback)
    53  json j_filtered(ss, cb);
    54  std::cout << std::setw(4) << j_filtered << '\n';
    55 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:983
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:918
    @@ -337,7 +339,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html index 4d02babbb..cacf03972 100644 --- a/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html +++ b/classnlohmann_1_1basic__json_a98e05a2c9b8f74bd60442772cddeee52.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102

    Output (play with this example online):

    [1,2,3] == nullptr false
     {"A":"a","B":"b"} == nullptr false
     17 == nullptr false
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     null == nullptr true
     

    The example code above can be translated with

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

    Definition at line 5399 of file json.hpp.

    +

    Definition at line 5447 of file json.hpp.

    @@ -305,7 +307,7 @@ null == nullptr true diff --git a/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html b/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html index 7efe92792..565ac6984 100644 --- a/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html +++ b/classnlohmann_1_1basic__json_a99f2e765029e51dd0fff018650f92eea.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ operator[] with null"
    Complexity
    Constant.
    -
    Example
    The example below shows how array elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON array
    8  json array = {"first", "2nd", "third", "fourth"};
    9 
    10  // output element at index 2 (third element)
    11  std::cout << array.at(2) << '\n';
    12 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -298,7 +300,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html index a455c2914..6e426563e 100644 --- a/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html +++ b/classnlohmann_1_1basic__json_a9af5ea68c88f423ddf35216aff7f1813.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ 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 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:10058
    +
    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:10102
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:347
    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 
    @@ -298,7 +300,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html b/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html new file mode 100644 index 000000000..ea3952c74 --- /dev/null +++ b/classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html @@ -0,0 +1,309 @@ + + + + + + +JSON for Modern C++: nlohmann::basic_json::push_back + + + + + + + + + + + +
    +
    + + + + + + +
    +
    JSON for Modern C++ +  2.0.0 +
    +
    +
    + + + + + +
    +
    + + +
    + +
    + + +
    +
    + + + + + +
    + + + +
    +
    +
    +template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
    + + + + + +
    + + + + + + + + +
    void nlohmann::basic_json::push_back (std::initializer_list< basic_jsoninit)
    +
    +inline
    +
    +

    This function allows to use push_back with an initializer list. In case

    +
      +
    1. the current value is an object,
    2. +
    3. the initializer list init contains only two elements, and
    4. +
    5. the first element of init is a string,
    6. +
    +

    init is converted into an object element and added using push_back(const typename object_t::value_type&). Otherwise, init is converted to a JSON value and added using push_back(basic_json&&).

    +
    Parameters
    + + +
    initan initializer list
    +
    +
    +
    Complexity
    Linear in the size of the initializer list init.
    +
    Note
    This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.
    +
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json object = {{"one", 1}, {"two", 2}};
    9  json null;
    10 
    11  // print values
    12  std::cout << object << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values:
    16  object.push_back({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    +
    Output (play with this example online):
    {"one":1,"two":2}
    +null
    +{"four":4,"one":1,"three":3,"two":2}
    +[["five",5]]
    +
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/push_back__initializer_list.cpp -o push_back__initializer_list 
    + +

    Definition at line 4909 of file json.hpp.

    + +
    +
    +
    +
    + + + + diff --git a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html index c99799ce8..0692b6f63 100644 --- a/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html +++ b/classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 04e6767fd..d5d2888bf 100644 --- a/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html +++ b/classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -300,7 +302,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html b/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html new file mode 100644 index 000000000..1a5d3e2c3 --- /dev/null +++ b/classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html @@ -0,0 +1,309 @@ + + + + + + +JSON for Modern C++: nlohmann::basic_json::operator+= + + + + + + + + + + + +
    +
    + + + + + + +
    +
    JSON for Modern C++ +  2.0.0 +
    +
    +
    + + + + + +
    +
    + + +
    + +
    + + +
    +
    + + + + + +
    + + + +
    +
    +
    +template<template< typename U, typename V, typename...Args > class ObjectType = std::map, template< typename U, typename...Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
    + + + + + +
    + + + + + + + + +
    reference nlohmann::basic_json::operator+= (std::initializer_list< basic_jsoninit)
    +
    +inline
    +
    +

    add an object to an object This function allows to use push_back with an initializer list. In case

    +
      +
    1. the current value is an object,
    2. +
    3. the initializer list init contains only two elements, and
    4. +
    5. the first element of init is a string,
    6. +
    +

    init is converted into an object element and added using push_back(const typename object_t::value_type&). Otherwise, init is converted to a JSON value and added using push_back(basic_json&&).

    +
    Parameters
    + + +
    initan initializer list
    +
    +
    +
    Complexity
    Linear in the size of the initializer list init.
    +
    Note
    This function is required to resolve an ambiguous overload error, because pairs like {"key", "value"} can be both interpreted as object_t::value_type or std::initializer_list<basic_json>, see https://github.com/nlohmann/json/issues/235 for more information.
    +
    Example
    The example shows how initializer lists are treated as objects when possible.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json object = {{"one", 1}, {"two", 2}};
    9  json null;
    10 
    11  // print values
    12  std::cout << object << '\n';
    13  std::cout << null << '\n';
    14 
    15  // add values:
    16  object.push_back({"three", 3}); // object is extended
    17  object += {"four", 4}; // object is extended
    18  null.push_back({"five", 5}); // null is converted to array
    19 
    20  // print values
    21  std::cout << object << '\n';
    22  std::cout << null << '\n';
    23 
    24  // would throw:
    25  //object.push_back({1, 2, 3});
    26 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    +
    Output (play with this example online):
    {"one":1,"two":2}
    +null
    +{"four":4,"one":1,"three":3,"two":2}
    +[["five",5]]
    +
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/push_back__initializer_list.cpp -o push_back__initializer_list 
    + +

    Definition at line 4926 of file json.hpp.

    + +
    +
    +
    +
    + + + + diff --git a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html index 6b6dbdba5..79d4c3d89 100644 --- a/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html +++ b/classnlohmann_1_1basic__json_aa36e72ffc3241b960fe9186d19e03bc3.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    log(size()) + count(key)
    -
    Example
    The example shows the effect of erase().
    1 #include <json.hpp>
    2 
    3 using 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:10058
    +
    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:10102
    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 
    @@ -304,7 +306,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 192cad11d..16c271592 100644 --- a/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html +++ b/classnlohmann_1_1basic__json_aa44ce84b9ac506b905b8fb56c9a0989d.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 2c7866114..5abf15791 100644 --- a/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html +++ b/classnlohmann_1_1basic__json_aa45753034bea87f9d2c0c42ace9ff75c.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    -
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The following code shows an example for front().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_object = {{"one", 1}, {"two", 2}};
    13  json j_object_empty(json::value_t::object);
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_array_empty(json::value_t::array);
    16  json j_string = "Hello, world";
    17 
    18  // call front()
    19  //std::cout << j_null.front() << '\n'; // would throw
    20  std::cout << j_boolean.front() << '\n';
    21  std::cout << j_number_integer.front() << '\n';
    22  std::cout << j_number_float.front() << '\n';
    23  std::cout << j_object.front() << '\n';
    24  //std::cout << j_object_empty.front() << '\n'; // undefined behavior
    25  std::cout << j_array.front() << '\n';
    26  //std::cout << j_array_empty.front() << '\n'; // undefined behavior
    27  std::cout << j_string.front() << '\n';
    28 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    object (unordered set of name/value pairs)
    array (ordered collection of values)
    Output (play with this example online):
    true
    @@ -300,7 +302,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 08a5d06a5..1bc3919e1 100644 --- a/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html +++ b/classnlohmann_1_1basic__json_aa669d997ddc03566de5438781254b32b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17
    @@ -302,7 +304,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 841057341..a80835e0b 100644 --- a/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html +++ b/classnlohmann_1_1basic__json_aa6fd72df1ce9f80e61012784c598456e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -286,7 +288,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -304,7 +306,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_aa7205e1926d3aea98adeced91b0ff5fb.html b/classnlohmann_1_1basic__json_aa7205e1926d3aea98adeced91b0ff5fb.html index 0b7aa5946..117e9ca0f 100644 --- a/classnlohmann_1_1basic__json_aa7205e1926d3aea98adeced91b0ff5fb.html +++ b/classnlohmann_1_1basic__json_aa7205e1926d3aea98adeced91b0ff5fb.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).begin().
  • -
    Example
    The following code shows an example for cbegin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  const json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::const_iterator it = array.cbegin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/cbegin.cpp -o cbegin 
    See also
    begin() – returns an iterator to the beginning
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html b/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html index c28e7665d..a5e9b84d9 100644 --- a/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html +++ b/classnlohmann_1_1basic__json_aaa160a960dd3dd90856a72b1d8dbe707.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of reverse_iterator(begin()).
  • -
    Example
    The following code shows an example for rend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    11  json::reverse_iterator it = array.rend();
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::iterator > reverse_iterator
    a reverse iterator for a basic_json container
    Definition: json.hpp:238
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html b/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html index 4917eea2a..77c63e1cd 100644 --- a/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html +++ b/classnlohmann_1_1basic__json_aaa687595d7627925fbf6d6eb97e2021e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
    @@ -293,7 +295,7 @@ value at key "two": 2
     
    diff --git a/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html b/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html index 68358c6f4..87a5acd61 100644 --- a/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html +++ b/classnlohmann_1_1basic__json_aac36af84d907b5c3e469af889661620a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -275,7 +277,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -291,7 +293,7 @@ false
    diff --git a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html index f9206e708..4ab5eb670 100644 --- a/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html +++ b/classnlohmann_1_1basic__json_aacd442b66140c764c594ac8ad7dfd5b3.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -291,7 +293,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -299,7 +301,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/operator__less.cpp -o operator__less 
    Since
    version 1.0.0
    -

    Definition at line 5481 of file json.hpp.

    +

    Definition at line 5529 of file json.hpp.

    @@ -309,7 +311,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aad65e0bc388897192bf361c24c1d6dda.html b/classnlohmann_1_1basic__json_aad65e0bc388897192bf361c24c1d6dda.html index 3b820a387..910486db7 100644 --- a/classnlohmann_1_1basic__json_aad65e0bc388897192bf361c24c1d6dda.html +++ b/classnlohmann_1_1basic__json_aad65e0bc388897192bf361c24c1d6dda.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17 17 17
    @@ -296,7 +298,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html index 636cdc46e..1baa64a10 100644 --- a/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html +++ b/classnlohmann_1_1basic__json_aadb4e5be88221e5e28cdb752332f3d13.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -294,13 +296,13 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    7
     [1,2,3,4,7,8,9]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__ilist.cpp -o insert__ilist 
    Since
    version 1.0.0
    -

    Definition at line 5073 of file json.hpp.

    +

    Definition at line 5121 of file json.hpp.

    @@ -310,7 +312,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_aae7eb3b91d7f68e86396c5c6b683445f.html b/classnlohmann_1_1basic__json_aae7eb3b91d7f68e86396c5c6b683445f.html index 1cf7bc2f7..e3a27ac1b 100644 --- a/classnlohmann_1_1basic__json_aae7eb3b91d7f68e86396c5c6b683445f.html +++ b/classnlohmann_1_1basic__json_aae7eb3b91d7f68e86396c5c6b683445f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • Has the semantics of const_cast<const basic_json&>(*this).rend().
  • -
    Example
    The following code shows an example for crend().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get an iterator to the reverse-end
    11  json::const_reverse_iterator it = array.crend();
    12 
    13  // increment the iterator to point to the first element
    14  --it;
    15 
    16  // serialize the element that the iterator points to
    17  std::cout << *it << '\n';
    18 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    json_reverse_iterator< typename basic_json::const_iterator > const_reverse_iterator
    a const reverse iterator for a basic_json container
    Definition: json.hpp:240
    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 
    @@ -298,7 +300,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html index 74eee785c..b90a79174 100644 --- a/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html +++ b/classnlohmann_1_1basic__json_aaf363408931d76472ded14017e59c9e8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -293,7 +295,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    {
       "array": [
         1,
    @@ -311,7 +313,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     
    See also
    parse(std::istream&, parser_callback_t) for a variant with a parser callback function to filter values while parsing
    Since
    version 1.0.0
    -

    Definition at line 5795 of file json.hpp.

    +

    Definition at line 5843 of file json.hpp.

    @@ -321,7 +323,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 4f7438086..44be4d6fa 100644 --- a/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html +++ b/classnlohmann_1_1basic__json_ab00b882d39306d663c23dab110f5cae0.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -288,7 +290,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab22c8d61eca51f0308c263487bd35f03.html b/classnlohmann_1_1basic__json_ab22c8d61eca51f0308c263487bd35f03.html index 3ca7e97b6..bf0b27a92 100644 --- a/classnlohmann_1_1basic__json_ab22c8d61eca51f0308c263487bd35f03.html +++ b/classnlohmann_1_1basic__json_ab22c8d61eca51f0308c263487bd35f03.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    Returns
    true if type is string, false otherwise.
    Complexity
    Constant.
    Exception safety
    No-throw guarantee: this member function never throws exceptions.
    -
    Example
    The following code exemplifies is_string() for all JSON types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_null;
    9  json j_boolean = true;
    10  json j_number_integer = 17;
    11  json j_number_float = 23.42;
    12  json j_number_unsigned_integer = 12345678987654321u;
    13  json j_object = {{"one", 1}, {"two", 2}};
    14  json j_array = {1, 2, 4, 8, 16};
    15  json j_string = "Hello, world";
    16 
    17  // call is_string()
    18  std::cout << std::boolalpha;
    19  std::cout << j_null.is_string() << '\n';
    20  std::cout << j_boolean.is_string() << '\n';
    21  std::cout << j_number_integer.is_string() << '\n';
    22  std::cout << j_number_unsigned_integer.is_string() << '\n';
    23  std::cout << j_number_float.is_string() << '\n';
    24  std::cout << j_object.is_string() << '\n';
    25  std::cout << j_array.is_string() << '\n';
    26  std::cout << j_string.is_string() << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    false
     false
     false
    @@ -292,7 +294,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html b/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html index 73c7b40f8..f57a869fc 100644 --- a/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html +++ b/classnlohmann_1_1basic__json_ab31368c0b67f8e4f291a45e6498018be.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ 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 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:10058
    +
    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:10102
    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 
    @@ -299,7 +301,7 @@ out of range
    diff --git a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html index 93568d6e9..22872c0c8 100644 --- a/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html +++ b/classnlohmann_1_1basic__json_ab63e618bbb0371042b1bec17f5891f42.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -286,7 +288,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html index d7a3a8ce2..cd8b64522 100644 --- a/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html +++ b/classnlohmann_1_1basic__json_ab7be2bc58ae0c2c2c30d40f15d6399f8.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -289,7 +291,7 @@ 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 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:10058
    +
    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:10102
    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}
    @@ -308,7 +310,7 @@ template<class CompatibleObjectType , typename std::enable_if<
     
    diff --git a/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html b/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html index b16116a19..68e075075 100644 --- a/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html +++ b/classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,8 +289,8 @@ 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 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:10058
    -
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5720
    +
    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:10102
    +
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5768
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:983
    the parser read a key of a value in an object
    parse_event_t
    JSON callback events.
    Definition: json.hpp:918
    @@ -330,7 +332,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    See also
    parse(const string_t&, parser_callback_t) for a version that reads from a string
    Since
    version 1.0.0
    -

    Definition at line 5757 of file json.hpp.

    +

    Definition at line 5805 of file json.hpp.

    @@ -340,7 +342,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html index b6a897e03..22a1902e2 100644 --- a/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html +++ b/classnlohmann_1_1basic__json_ab8b43d92a042dde96c28aeea81dd52de.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -281,7 +283,7 @@ 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 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:10058
    +
    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:10102
    StringType string_t
    a type for a string
    Definition: json.hpp:440
    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 
    @@ -300,7 +302,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 58918c601..891a3075f 100644 --- a/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html +++ b/classnlohmann_1_1basic__json_ab936779c70bec68343ef440ed13251e5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -280,7 +282,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html index 46f881ccd..358218704 100644 --- a/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html +++ b/classnlohmann_1_1basic__json_ac4b10b2364f26ce47bdb9a413ff04a59.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -293,7 +295,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 4cce3f7dd..63c6423e6 100644 --- a/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html +++ b/classnlohmann_1_1basic__json_ac5693cff1df0775cd3fbe960412cde4b.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -278,7 +280,7 @@ 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 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:10058
    +
    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:10102
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    Output (play with this example online):
    17 17 17 17
    @@ -297,7 +299,7 @@ true
     
    diff --git a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html index a2c594e95..f61eea41c 100644 --- a/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html +++ b/classnlohmann_1_1basic__json_ac7c006e2345a76859c4802db7d130e0e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -285,7 +287,7 @@ template<typename T >
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read and written using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << "\n\n";
    15 
    16  // change element with key "three"
    17  object["three"] = 3;
    18 
    19  // output changed array
    20  std::cout << std::setw(4) << object << "\n\n";
    21 
    22  // mention nonexisting key
    23  object["four"];
    24 
    25  // write to nonexisting key
    26  object["five"]["really"]["nested"] = true;
    27 
    28  // output changed object
    29  std::cout << std::setw(4) << object << '\n';
    30 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    2
     
     {
    @@ -321,7 +323,7 @@ template<typename T > 
    diff --git a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html index 481f79c3c..e75cdc81f 100644 --- a/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html +++ b/classnlohmann_1_1basic__json_ac8d45b57874b4a6e9c07f7d3b5daa1f9.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,7 @@ template<template< typename U, typename V, typename...Args > class Obje diff --git a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html index 05adff15a..cfba59ca5 100644 --- a/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html +++ b/classnlohmann_1_1basic__json_ad25b2f8c21e241e2d63455537a9294ff.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -284,7 +286,7 @@ 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 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:1749
    -
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    {}
     {}
     {"one":1,"two":2}
    @@ -304,7 +306,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 71dd93c15..35accc196 100644
    --- a/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html
    +++ b/classnlohmann_1_1basic__json_ad2eddc2c13ab084f067eaba65d381ad2.html
    @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
               operator+=
               operator+=
               operator+=
    +          operator+=
               operator<
               operator<
               operator<<
    @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
               push_back
               push_back
               push_back
    +          push_back
               rbegin
               rbegin
               reference
    @@ -283,7 +285,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if<
       
    Complexity
    Constant.
    -
    Example
    The example below shows the construction of several integer number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different integer types
    8  short n42 = 42;
    9  int n23 = 23;
    10  long n1024 = 1024;
    11  int_least32_t n17 = 17;
    12  uint8_t n8 = 8;
    13 
    14  // create JSON numbers
    15  json j42(n42);
    16  json j23(n23);
    17  json j1024(n1024);
    18  json j17(n17);
    19  json j8(n8);
    20 
    21  // serialize the JSON numbers
    22  std::cout << j42 << '\n';
    23  std::cout << j23 << '\n';
    24  std::cout << j1024 << '\n';
    25  std::cout << j17 << '\n';
    26  std::cout << j8 << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows the construction of several integer number values from compatible types.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create values of different integer types
    8  short n42 = 42;
    9  int n23 = 23;
    10  long n1024 = 1024;
    11  int_least32_t n17 = 17;
    12  uint8_t n8 = 8;
    13 
    14  // create JSON numbers
    15  json j42(n42);
    16  json j23(n23);
    17  json j1024(n1024);
    18  json j17(n17);
    19  json j8(n8);
    20 
    21  // serialize the JSON numbers
    22  std::cout << j42 << '\n';
    23  std::cout << j23 << '\n';
    24  std::cout << j1024 << '\n';
    25  std::cout << j17 << '\n';
    26  std::cout << j8 << '\n';
    27 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    42
     23
     1024
    @@ -305,7 +307,7 @@ template<typename CompatibleNumberIntegerType , typename std::enable_if<
     
    diff --git a/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html b/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html index 0a2c253a5..2341c812b 100644 --- a/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html +++ b/classnlohmann_1_1basic__json_ad4e381c54039607be08d7af41a1f6ad1.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -277,7 +279,7 @@ Illustration from cppreference.com
  • The complexity is constant.
  • -
    Example
    The following code shows an example for begin().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create an array value
    8  json array = {1, 2, 3, 4, 5};
    9 
    10  // get am iterator to the first element
    11  json::iterator it = array.begin();
    12 
    13  // serialize the element that the iterator points to
    14  std::cout << *it << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    1
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/begin.cpp -o begin 
    See also
    cbegin() – returns a const iterator to the beginning
    @@ -297,7 +299,7 @@ Illustration from cppreference.com
    diff --git a/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html b/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html index 25d0caa1f..1ea5b35b7 100644 --- a/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html +++ b/classnlohmann_1_1basic__json_ad5514a7435f246fc5335856465022a7a.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -290,7 +292,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    0
     1
     1
    @@ -312,7 +314,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 7b7b747e6..f4294774a 100644 --- a/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html +++ b/classnlohmann_1_1basic__json_ad6e51670e9c0052856f3fee01df5c44f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -285,7 +287,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    null
     false
     0
    @@ -306,7 +308,7 @@ false
     
    diff --git a/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html b/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html index 6fe03c10c..d1e17e05b 100644 --- a/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html +++ b/classnlohmann_1_1basic__json_ad9cd312208273fb3fb2adf1f6d8d34ae.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ operator[] with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be read using the [] operator.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object
    8  const json object =
    9  {
    10  {"one", 1}, {"two", 2}, {"three", 2.9}
    11  };
    12 
    13  // output element with key "two"
    14  std::cout << object["two"] << '\n';
    15 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -305,7 +307,7 @@ operator[] with null"
    diff --git a/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html b/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html index cd0971e2d..087391057 100644 --- a/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html +++ b/classnlohmann_1_1basic__json_ade0e56c8c320d7f342e7a5697e6d6f7e.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -270,7 +272,7 @@ 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.
    Exception safety
    No-throw guarantee: this constructor never throws exceptions.
    -
    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:10058
    +
    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:10102
    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)
    @@ -286,7 +288,7 @@ template<template< typename U, typename V, typename...Args > class Obje
    diff --git a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html index 6b938a310..b9d798db7 100644 --- a/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html +++ b/classnlohmann_1_1basic__json_ae336fff01f4b78e3e16e5008dc8dbc00.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 502b75227..8a0c5a29c 100644 --- a/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html +++ b/classnlohmann_1_1basic__json_ae347859ec88176ef76a0cbe5b4514fcf.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -287,7 +289,7 @@ 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 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:10058
    +
    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:10102

    Output (play with this example online):

    [1,2,3] != nullptr true
     {"A":"a","B":"b"} != nullptr true
     17 != nullptr true
    @@ -295,7 +297,7 @@ template<template< typename U, typename V, typename...Args > class Obje
     null != nullptr false
     

    The example code above can be translated with

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

    Definition at line 5443 of file json.hpp.

    +

    Definition at line 5491 of file json.hpp.

    @@ -305,7 +307,7 @@ null != nullptr false diff --git a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html index c7c1413fd..9c54768cf 100644 --- a/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html +++ b/classnlohmann_1_1basic__json_ae85d91b0620650bcd9993e09d0e287d9.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -289,7 +291,7 @@ 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 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:10058
    +
    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:10102
    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
    @@ -307,7 +309,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 5dd65d10b..0d8e920c9 100644 --- a/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html +++ b/classnlohmann_1_1basic__json_aea1c863b719b4ca5b77188c171bbfafe.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -296,7 +298,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 33fe12663..53b91f0c5 100644 --- a/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html +++ b/classnlohmann_1_1basic__json_aeaa0644fd6b99af364e772092268dfd6.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -304,13 +306,13 @@ belong to container"
    Returns
    iterator pointing to the first element inserted, or pos if first==last
    Complexity
    Linear in std::distance(first, last) plus linear in the distance between pos and end of the container.
    -
    Example
    The example shows how insert() is used.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON array
    8  json v = {1, 2, 3, 4};
    9 
    10  // create a JSON array to copy values from
    11  json v2 = {"one", "two", "three", "four"};
    12 
    13  // insert range from v2 before the end of array v
    14  auto new_pos = v.insert(v.end(), v2.begin(), v2.end());
    15 
    16  // output new array and result of insert call
    17  std::cout << *new_pos << '\n';
    18  std::cout << v << '\n';
    19 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    "one"
     [1,2,3,4,"one","two","three","four"]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/insert__range.cpp -o insert__range 
    Since
    version 1.0.0
    -

    Definition at line 5015 of file json.hpp.

    +

    Definition at line 5063 of file json.hpp.

    @@ -320,7 +322,7 @@ belong to container" diff --git a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html index 0c46c2aa4..55ba7698c 100644 --- a/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html +++ b/classnlohmann_1_1basic__json_aec316934a555dd1acdd3600e5d4a4cdf.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 d1d620123..3d78995a7 100644 --- a/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html +++ b/classnlohmann_1_1basic__json_aef496a56163710084e13612ab73e6ed2.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -283,7 +285,7 @@ template<typename ValueType , typename std::enable_if<
    Complexity
    Linear in the size of the JSON value.
    -
    Example
    The example below shows several conversions from JSON values to other types. There a few things to note: (1) Floating-point numbers can be converted to integers, (2) A JSON array can be converted to a standard std::vector<short>, (3) A JSON object can be converted to C++ associative containers such as std::unordered_map<std::string, json>.
    1 #include <json.hpp>
    2 #include <unordered_map>
    3 
    4 using 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:10058
    +
    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:10102
    Output (play with this example online):
    1
     42 42
     17.23 17
    @@ -308,7 +310,7 @@ array: [1,2,3,4,5]
     
    diff --git a/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html b/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html index bf7cdb865..8d5ae7332 100644 --- a/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html +++ b/classnlohmann_1_1basic__json_af071057ebab57744f5767eb369e99d42.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -303,7 +305,7 @@ value() with null"
    Complexity
    Logarithmic in the size of the container.
    -
    Example
    The example below shows how object elements can be queried with a default value.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create a JSON object with different entry types
    8  json j =
    9  {
    10  {"integer", 1},
    11  {"floating", 42.23},
    12  {"string", "hello world"},
    13  {"boolean", true},
    14  {"object", {{"key1", 1}, {"key2", 2}}},
    15  {"array", {1, 2, 3}}
    16  };
    17 
    18  // access existing values
    19  int v_integer = j.value("integer", 0);
    20  double v_floating = j.value("floating", 47.11);
    21 
    22  // access nonexisting values and rely on default value
    23  std::string v_string = j.value("nonexisting", "oops");
    24  bool v_boolean = j.value("nonexisting", false);
    25 
    26  // output values
    27  std::cout << std::boolalpha << v_integer << " " << v_floating
    28  << " " << v_string << " " << v_boolean << "\n";
    29 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    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
    @@ -321,7 +323,7 @@ value() with null"
    diff --git a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html index a8e53b1f6..cc87f6e44 100644 --- a/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html +++ b/classnlohmann_1_1basic__json_af148cdab12df5bf86119fac735ccaac5.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -280,7 +282,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 3f8a51a46..4a259485b 100644 --- a/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html +++ b/classnlohmann_1_1basic__json_af3bc3e83aa162d7ba4df16a949872723.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -273,7 +275,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 8b9a5d7a1..55b7aa944 100644 --- a/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html +++ b/classnlohmann_1_1basic__json_af677a29b0e66edc9f66e5167e4667071.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -266,7 +268,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 514976773..624f7af15 100644 --- a/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html +++ b/classnlohmann_1_1basic__json_af77614992e38b355b9213940051cc582.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -275,13 +277,13 @@ template<template< typename U, typename V, typename...Args > class Obje
    Complexity
    Constant.
    -
    Example
    The example below shows how JSON values can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create two JSON values
    8  json j1 = {1, 2, 3, 4, 5};
    9  json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}};
    10 
    11  // swap the values
    12  j1.swap(j2);
    13 
    14  // output the values
    15  std::cout << "j1 = " << j1 << '\n';
    16  std::cout << "j2 = " << j2 << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    Example
    The example below shows how JSON values can be swapped with swap().
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create two JSON values
    8  json j1 = {1, 2, 3, 4, 5};
    9  json j2 = {{"pi", 3.141592653589793}, {"e", 2.718281828459045}};
    10 
    11  // swap the values
    12  j1.swap(j2);
    13 
    14  // output the values
    15  std::cout << "j1 = " << j1 << '\n';
    16  std::cout << "j2 = " << j2 << '\n';
    17 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10102
    Output (play with this example online):
    j1 = {"e":2.71828182845905,"pi":3.14159265358979}
     j2 = [1,2,3,4,5]
     
    The example code above can be translated with
    g++ -std=c++11 -Isrc doc/examples/swap__reference.cpp -o swap__reference 
    Since
    version 1.0.0
    -

    Definition at line 5111 of file json.hpp.

    +

    Definition at line 5159 of file json.hpp.

    @@ -291,7 +293,7 @@ j2 = [1,2,3,4,5] diff --git a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html index 42d58ad33..c8fd03ae7 100644 --- a/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html +++ b/classnlohmann_1_1basic__json_af7acf3838a79363356f24538941a559c.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -308,7 +310,7 @@ construct with iterators from null"
    Complexity
    Linear in distance between first and last.
    -
    Example
    The example below shows several ways to create JSON values by specifying a subrange with iterators.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_array = {"alpha", "bravo", "charly", "delta", "easy"};
    9  json j_number = 42;
    10  json j_object = {{"one", "eins"}, {"two", "zwei"}};
    11 
    12  // create copies using iterators
    13  json j_array_range(j_array.begin() + 1, j_array.end() - 2);
    14  json j_number_range(j_number.begin(), j_number.end());
    15  json j_object_range(j_object.begin(), j_object.find("two"));
    16 
    17  // serialize the values
    18  std::cout << j_array_range << '\n';
    19  std::cout << j_number_range << '\n';
    20  std::cout << j_object_range << '\n';
    21 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    ["bravo","charly"]
     42
     {"one":"eins"}
    @@ -325,7 +327,7 @@ construct with iterators from null"
     
    diff --git a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html index 3f5c47ec9..8ab48f89b 100644 --- a/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html +++ b/classnlohmann_1_1basic__json_afeb998aec45296bc2050bd1c41ef41eb.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -317,7 +319,7 @@ initializer list"
    Complexity
    Linear in the size of the initializer list init.
    -
    Example
    The example below shows how JSON values are created from initializer lists.
    1 #include <json.hpp>
    2 
    3 using json = nlohmann::json;
    4 
    5 int main()
    6 {
    7  // create JSON values
    8  json j_empty_init_list = json({});
    9  json j_object = { {"one", 1}, {"two", 2} };
    10  json j_array = {1, 2, 3, 4};
    11  json j_nested_object = { {"one", {1}}, {"two", {1, 2}} };
    12  json j_nested_array = { {{1}, "one"}, {{1, 2}, "two"} };
    13 
    14  // serialize the JSON value
    15  std::cout << j_empty_init_list << '\n';
    16  std::cout << j_object << '\n';
    17  std::cout << j_array << '\n';
    18  std::cout << j_nested_object << '\n';
    19  std::cout << j_nested_array << '\n';
    20 }
    basic_json<> json
    default JSON class
    Definition: json.hpp:10058
    +
    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:10102
    Output (play with this example online):
    {}
     {"one":1,"two":2}
     [1,2,3,4]
    @@ -339,7 +341,7 @@ initializer list"
     
    diff --git a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html index ef889adcb..5e9f32fb3 100644 --- a/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html +++ b/classnlohmann_1_1basic__json_affe7e160e7bb06eed83c8b437af4692f.html @@ -187,6 +187,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); operator+= operator+= operator+= + operator+= operator< operator< operator<< @@ -220,6 +221,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); push_back push_back push_back + push_back rbegin rbegin reference @@ -276,7 +278,7 @@ 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 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:10058
    +
    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:10102
    Output (play with this example online):
    "two" was found: true
     value at key "two": 2
     "three" was found: false
    @@ -293,7 +295,7 @@ value at key "two": 2
     
    diff --git a/dir_68267d1309a1af8e8297ef4c3efbcdba.html b/dir_68267d1309a1af8e8297ef4c3efbcdba.html index 60f8ce9e4..ae5f70b97 100644 --- a/dir_68267d1309a1af8e8297ef4c3efbcdba.html +++ b/dir_68267d1309a1af8e8297ef4c3efbcdba.html @@ -92,7 +92,7 @@ Files diff --git a/functions.html b/functions.html index 98462cb35..28e621fa5 100644 --- a/functions.html +++ b/functions.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_0x7e.html b/functions_0x7e.html index 0bef73cec..3d204e2bd 100644 --- a/functions_0x7e.html +++ b/functions_0x7e.html @@ -126,7 +126,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_b.html b/functions_b.html index 5123f53fb..31fce625e 100644 --- a/functions_b.html +++ b/functions_b.html @@ -141,7 +141,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_c.html b/functions_c.html index ef1d1f75f..9729c9d2f 100644 --- a/functions_c.html +++ b/functions_c.html @@ -153,7 +153,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_d.html b/functions_d.html index 33fecfe7b..acadcc64c 100644 --- a/functions_d.html +++ b/functions_d.html @@ -133,7 +133,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_e.html b/functions_e.html index b4a271bc0..9579ce29f 100644 --- a/functions_e.html +++ b/functions_e.html @@ -132,7 +132,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_enum.html b/functions_enum.html index d7b8fceab..32bbd4052 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 7327e626a..1eafe7afb 100644 --- a/functions_f.html +++ b/functions_f.html @@ -132,7 +132,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_func.html b/functions_func.html index c14645b67..54ff6ffba 100644 --- a/functions_func.html +++ b/functions_func.html @@ -336,7 +336,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); , nlohmann::basic_json::json_reverse_iterator< Base >
  • operator--() -: nlohmann::basic_json::const_iterator +: nlohmann::basic_json::const_iterator , nlohmann::basic_json::iterator , nlohmann::basic_json::json_reverse_iterator< Base >
  • @@ -372,7 +372,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); : nlohmann::basic_json::const_iterator , nlohmann::basic_json::iterator , nlohmann::basic_json::json_reverse_iterator< Base > -, nlohmann::basic_json +, nlohmann::basic_json @@ -385,7 +385,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); : nlohmann::basic_json
  • push_back() -: nlohmann::basic_json +: nlohmann::basic_json
  • @@ -445,7 +445,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_g.html b/functions_g.html index e1bf6ec3d..0efc3af56 100644 --- a/functions_g.html +++ b/functions_g.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_i.html b/functions_i.html index e99d684a4..1abb7192d 100644 --- a/functions_i.html +++ b/functions_i.html @@ -171,7 +171,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_j.html b/functions_j.html index 0adae6276..ba0cae8f3 100644 --- a/functions_j.html +++ b/functions_j.html @@ -129,7 +129,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_k.html b/functions_k.html index 5a7924cb9..e6a6d17d9 100644 --- a/functions_k.html +++ b/functions_k.html @@ -127,7 +127,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_m.html b/functions_m.html index a23277188..8036fc0a0 100644 --- a/functions_m.html +++ b/functions_m.html @@ -126,7 +126,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_n.html b/functions_n.html index 3c3432628..c8e295a2f 100644 --- a/functions_n.html +++ b/functions_n.html @@ -132,7 +132,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_o.html b/functions_o.html index ffe891127..2a9286781 100644 --- a/functions_o.html +++ b/functions_o.html @@ -163,7 +163,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
  • operator-() : nlohmann::basic_json::const_iterator -, nlohmann::basic_json::iterator +, nlohmann::basic_json::iterator , nlohmann::basic_json::json_reverse_iterator< Base >
  • operator--() @@ -197,7 +197,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
  • operator==() : nlohmann::basic_json::const_iterator -, nlohmann::basic_json +, nlohmann::basic_json
  • operator>() : nlohmann::basic_json::const_iterator @@ -208,19 +208,19 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); , nlohmann::basic_json
  • operator>> -: nlohmann::basic_json +: nlohmann::basic_json
  • operator[]() : nlohmann::basic_json::const_iterator , nlohmann::basic_json::iterator , nlohmann::basic_json::json_reverse_iterator< Base > -, nlohmann::basic_json +, nlohmann::basic_json
  • diff --git a/functions_p.html b/functions_p.html index f0fbae639..8dcff6abd 100644 --- a/functions_p.html +++ b/functions_p.html @@ -137,13 +137,13 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); , nlohmann::basic_json
  • push_back() -: nlohmann::basic_json +: nlohmann::basic_json
  • diff --git a/functions_r.html b/functions_r.html index b3bc0176a..3893df40f 100644 --- a/functions_r.html +++ b/functions_r.html @@ -138,7 +138,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_rela.html b/functions_rela.html index bda57a740..90b94156d 100644 --- a/functions_rela.html +++ b/functions_rela.html @@ -125,7 +125,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_s.html b/functions_s.html index 79be22925..420295a57 100644 --- a/functions_s.html +++ b/functions_s.html @@ -135,7 +135,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_t.html b/functions_t.html index 7970f6df7..b5f50a71d 100644 --- a/functions_t.html +++ b/functions_t.html @@ -129,7 +129,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_type.html b/functions_type.html index c89527469..41c00b52e 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_u.html b/functions_u.html index 7e617aa6f..d57af42f4 100644 --- a/functions_u.html +++ b/functions_u.html @@ -126,7 +126,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/functions_v.html b/functions_v.html index 44064e611..c1e0293ea 100644 --- a/functions_v.html +++ b/functions_v.html @@ -136,7 +136,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/graph_legend.html b/graph_legend.html index c52c10445..8622678fd 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 c7889d8a8..4b1d8a834 100644 --- a/hierarchy.html +++ b/hierarchy.html @@ -102,7 +102,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/index.html b/index.html index 860d3f4b2..67bea6930 100644 --- a/index.html +++ b/index.html @@ -179,7 +179,7 @@ access at diff --git a/index_8md_source.html b/index_8md_source.html index 2ff4f3f73..62f2cf503 100644 --- a/index_8md_source.html +++ b/index_8md_source.html @@ -82,7 +82,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    1 # JSON for Modern C++
    2 
    3 These pages contain the API documentation of JSON for Modern C++, a C++11 header-only JSON class.
    4 
    5 # Contents
    6 
    7 - @link nlohmann::basic_json `basic_json` class @endlink
    8 - [Functions](functions_func.html)
    9  - object inspection
    10  - @link nlohmann::basic_json::dump dump @endlink -- value serialization
    11  - @link nlohmann::basic_json::type type @endlink -- type of the value
    12  - @link nlohmann::basic_json::is_primitive is_primitive @endlink,
    13  @link nlohmann::basic_json::is_structured is_structured @endlink,
    14  @link nlohmann::basic_json::is_null is_null @endlink,
    15  @link nlohmann::basic_json::is_boolean is_boolean @endlink,
    16  @link nlohmann::basic_json::is_number is_number @endlink,
    17  @link nlohmann::basic_json::is_number_integer is_number_integer @endlink,
    18  @link nlohmann::basic_json::is_number_unsigned is_number_unsigned @endlink,
    19  @link nlohmann::basic_json::is_number_float is_number_float @endlink,
    20  @link nlohmann::basic_json::is_object is_object @endlink,
    21  @link nlohmann::basic_json::is_array is_array @endlink,
    22  @link nlohmann::basic_json::is_string is_string @endlink,
    23  @link nlohmann::basic_json::is_discarded is_discarded @endlink -- check for value type
    24  - @link nlohmann::basic_json::operator value_t() const operator value_t @endlink -- type of the value (implicit conversion)
    25  - value access
    26  - @link nlohmann::basic_json::get get @endlink -- get a value
    27  - @link nlohmann::basic_json::get_ptr get_ptr @endlink -- get a value pointer
    28  - @link nlohmann::basic_json::get_ref get_ref @endlink -- get a value reference
    29  - @link nlohmann::basic_json::operator ValueType() const operator ValueType @endlink -- get a value (implicit conversion)
    30  - lexicographical comparison operators
    31  - serialization
    32  - deserialization
    33 - Types
    34  - @link nlohmann::basic_json::array_t arrays @endlink
    35  - @link nlohmann::basic_json::object_t objects @endlink
    36  - @link nlohmann::basic_json::string_t strings @endlink
    37  - @link nlohmann::basic_json::boolean_t booleans @endlink
    38  - numbers
    39  - @link nlohmann::basic_json::number_integer_t signed integers @endlink
    40  - @link nlohmann::basic_json::number_unsigned_t unsigned integers @endlink
    41  - @link nlohmann::basic_json::number_float_t floating-point @endlink
    42 
    43 # Container function overview
    44 
    45 The container functions known from STL have been extended to support the different value types from JSON. However, not all functions can be applied to all value types. Note that the signature of some functions differ between the types; for instance, `at` may be called with either a string to address a key in an object or with an integer to address a value in an array.
    46 
    47 <table>
    48  <tr>
    49  <th rowspan="2">group</td>
    50  <th rowspan="2">function</td>
    51  <th colspan="6">JSON value type</th>
    52  </tr>
    53  <tr>
    54  <th>object</th>
    55  <th>array</th>
    56  <th>string</th>
    57  <th>number</th>
    58  <th>boolean</th>
    59  <th>null</th>
    60  </tr>
    61  <tr>
    62  <td rowspan="8">iterators</td>
    63  <td>`begin`</td>
    64  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    65  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    66  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    67  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    68  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink</td>
    69  <td class="ok_green">@link nlohmann::basic_json::begin `begin` @endlink (returns `end()`)</td>
    70  </tr>
    71  <tr>
    72  <td>`cbegin`</td>
    73  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    74  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    75  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    76  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    77  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink</td>
    78  <td class="ok_green">@link nlohmann::basic_json::cbegin `cbegin` @endlink (returns `cend()`)</td>
    79  </tr>
    80  <tr>
    81  <td>`end`</td>
    82  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    83  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    84  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    85  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    86  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    87  <td class="ok_green">@link nlohmann::basic_json::end `end` @endlink</td>
    88  </tr>
    89  <tr>
    90  <td>`cend`</td>
    91  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    92  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    93  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    94  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    95  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    96  <td class="ok_green">@link nlohmann::basic_json::cend `cend` @endlink</td>
    97  </tr>
    98  <tr>
    99  <td>`rbegin`</td>
    100  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    101  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    102  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    103  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    104  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    105  <td class="ok_green">@link nlohmann::basic_json::rbegin `rbegin` @endlink</td>
    106  </tr>
    107  <tr>
    108  <td>`crbegin`</td>
    109  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    110  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    111  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    112  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    113  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    114  <td class="ok_green">@link nlohmann::basic_json::crbegin `crbegin` @endlink</td>
    115  </tr>
    116  <tr>
    117  <td>`rend`</td>
    118  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    119  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    120  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    121  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    122  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    123  <td class="ok_green">@link nlohmann::basic_json::rend `rend` @endlink</td>
    124  </tr>
    125  <tr>
    126  <td>`crend`</td>
    127  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    128  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    129  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    130  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    131  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    132  <td class="ok_green">@link nlohmann::basic_json::crend `crend` @endlink</td>
    133  </tr>
    134  <tr>
    135  <td rowspan="4">element<br>access</td>
    136  <td>`at`</td>
    137  <td class="ok_green">@link nlohmann::basic_json::at(const typename object_t::key_type & key) `at` @endlink</td>
    138  <td class="ok_green">@link nlohmann::basic_json::at(size_type) `at` @endlink</td>
    139  <td class="nok_throws">throws `std::domain_error`</td>
    140  <td class="nok_throws">throws `std::domain_error`</td>
    141  <td class="nok_throws">throws `std::domain_error`</td>
    142  <td class="nok_throws">throws `std::domain_error`</td>
    143  </tr>
    144  <tr>
    145  <td>`operator[]`</td>
    146  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type &key) `operator[]` @endlink</td>
    147  <td class="ok_green">@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink</td>
    148  <td class="nok_throws">throws `std::domain_error`</td>
    149  <td class="nok_throws">throws `std::domain_error`</td>
    150  <td class="nok_throws">throws `std::domain_error`</td>
    151  <td class="ok_green">@link nlohmann::basic_json::operator[](const typename object_t::key_type & key) `operator[]` @endlink (creates object)<br>@link nlohmann::basic_json::operator[](size_type) `operator[]` @endlink (creates array)</td>
    152  </tr>
    153  <tr>
    154  <td>`front`</td>
    155  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    156  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    157  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    158  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    159  <td class="ok_green">@link nlohmann::basic_json::front `front` @endlink</td>
    160  <td class="nok_throws">throws `std::out_of_range`</td>
    161  </tr>
    162  <tr>
    163  <td>`back`</td>
    164  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    165  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    166  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    167  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    168  <td class="ok_green">@link nlohmann::basic_json::back `back` @endlink</td>
    169  <td class="nok_throws">throws `std::out_of_range`</td>
    170  </tr>
    171  <tr>
    172  <td rowspan="3">capacity</td>
    173  <td>`empty`</td>
    174  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    175  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink</td>
    176  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    177  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    178  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `false`)</td>
    179  <td class="ok_green">@link nlohmann::basic_json::empty `empty` @endlink (returns `true`)</td>
    180  </tr>
    181  <tr>
    182  <td>`size`</td>
    183  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    184  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink</td>
    185  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    186  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    187  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `1`)</td>
    188  <td class="ok_green">@link nlohmann::basic_json::size `size` @endlink (returns `0`)</td>
    189  </tr>
    190  <tr>
    191  <td>`max_size_`</td>
    192  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    193  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink</td>
    194  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    195  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    196  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `1`)</td>
    197  <td class="ok_green">@link nlohmann::basic_json::max_size `max_size` @endlink (returns `0`)</td>
    198  </tr>
    199  <tr>
    200  <td rowspan="5">modifiers</td>
    201  <td>`clear`</td>
    202  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    203  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    204  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    205  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    206  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    207  <td class="ok_green">@link nlohmann::basic_json::clear `clear` @endlink</td>
    208  </tr>
    209  <tr>
    210  <td>`insert`</td>
    211  <td class="nok_throws">throws `std::domain_error`</td>
    212  <td class="ok_green">@link nlohmann::basic_json::insert `insert` @endlink</td>
    213  <td class="nok_throws">throws `std::domain_error`</td>
    214  <td class="nok_throws">throws `std::domain_error`</td>
    215  <td class="nok_throws">throws `std::domain_error`</td>
    216  <td class="nok_throws">throws `std::domain_error`</td>
    217  </tr>
    218  <tr>
    219  <td>`erase`</td>
    220  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    221  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink</td>
    222  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    223  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    224  <td class="ok_green">@link nlohmann::basic_json::erase `erase` @endlink (converts to null)</td>
    225  <td class="nok_throws">throws</td>
    226  </tr>
    227  <tr>
    228  <td>`push_back`</td>
    229  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink</td>
    230  <td class="ok_green">@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink</td>
    231  <td class="nok_throws">throws `std::domain_error`</td>
    232  <td class="nok_throws">throws `std::domain_error`</td>
    233  <td class="nok_throws">throws `std::domain_error`</td>
    234  <td class="ok_green">@link nlohmann::basic_json::push_back(const typename object_t::value_type & val) `push_back` @endlink (creates object)<br>@link nlohmann::basic_json::push_back(const nlohmann::basic_json &) `push_back` @endlink (creates array)</td>
    235  </tr>
    236  <tr>
    237  <td>`swap`</td>
    238  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    239  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    240  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    241  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    242  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    243  <td class="ok_green">@link nlohmann::basic_json::swap `swap` @endlink</td>
    244  </tr>
    245  <tr>
    246  <td rowspan="2">lookup</td>
    247  <td>`find`</td>
    248  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    249  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink</td>
    250  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    251  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    252  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    253  <td class="ok_green">@link nlohmann::basic_json::find `find` @endlink (returns `end()`)</td>
    254  </tr>
    255  <tr>
    256  <td>`count`</td>
    257  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    258  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink</td>
    259  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    260  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    261  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    262  <td class="ok_green">@link nlohmann::basic_json::count `count` @endlink (returns `0`)</td>
    263  </tr>
    264 </table>
    265 
    266 @copyright Copyright &copy; 2013-2016 Niels Lohmann. The code is licensed under the [MIT License](http://opensource.org/licenses/MIT).
    267 
    268 @author [Niels Lohmann](http://nlohmann.me)
    269 @see https://github.com/nlohmann/json to download the source code
    270 
    271 @version 2.0.0
    diff --git a/json_8hpp_source.html b/json_8hpp_source.html index 83a92f93b..68ee15b6c 100644 --- a/json_8hpp_source.html +++ b/json_8hpp_source.html @@ -83,53 +83,53 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    json.hpp
    -
    1 /*
    2  __ _____ _____ _____
    3  __| | __| | | | JSON for Modern C++
    4 | | |__ | | | | | | version 2.0.0
    5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
    6 
    7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
    8 Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
    9 
    10 Permission is hereby granted, free of charge, to any person obtaining a copy
    11 of this software and associated documentation files (the "Software"), to deal
    12 in the Software without restriction, including without limitation the rights
    13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    14 copies of the Software, and to permit persons to whom the Software is
    15 furnished to do so, subject to the following conditions:
    16 
    17 The above copyright notice and this permission notice shall be included in all
    18 copies or substantial portions of the Software.
    19 
    20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    26 SOFTWARE.
    27 */
    28 
    29 #ifndef NLOHMANN_JSON_HPP
    30 #define NLOHMANN_JSON_HPP
    31 
    32 #include <algorithm>
    33 #include <array>
    34 #include <cassert>
    35 #include <cerrno>
    36 #include <ciso646>
    37 #include <cmath>
    38 #include <cstddef>
    39 #include <cstdio>
    40 #include <cstdlib>
    41 #include <functional>
    42 #include <initializer_list>
    43 #include <iomanip>
    44 #include <iostream>
    45 #include <iterator>
    46 #include <limits>
    47 #include <map>
    48 #include <memory>
    49 #include <sstream>
    50 #include <stdexcept>
    51 #include <string>
    52 #include <type_traits>
    53 #include <utility>
    54 #include <vector>
    55 
    56 // disable float-equal warnings on GCC/clang
    57 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    58  #pragma GCC diagnostic push
    59  #pragma GCC diagnostic ignored "-Wfloat-equal"
    60 #endif
    61 
    67 namespace nlohmann
    68 {
    69 
    70 
    75 namespace
    76 {
    81 template<typename T>
    82 struct has_mapped_type
    83 {
    84  private:
    85  template<typename C> static char test(typename C::mapped_type*);
    86  template<typename C> static char (&test(...))[2];
    87  public:
    88  static constexpr bool value = sizeof(test<T>(0)) == 1;
    89 };
    90 
    95 class DecimalSeparator : public std::numpunct<char>
    96 {
    97  protected:
    98  char do_decimal_point() const
    99  {
    100  return '.';
    101  }
    102 };
    103 
    104 }
    105 
    177 template <
    178  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    179  template<typename U, typename... Args> class ArrayType = std::vector,
    180  class StringType = std::string,
    181  class BooleanType = bool,
    182  class NumberIntegerType = std::int64_t,
    183  class NumberUnsignedType = std::uint64_t,
    184  class NumberFloatType = double,
    185  template<typename U> class AllocatorType = std::allocator
    186  >
    188 {
    189  private:
    191  using basic_json_t = basic_json<ObjectType,
    192  ArrayType,
    193  StringType,
    194  BooleanType,
    195  NumberIntegerType,
    196  NumberUnsignedType,
    197  NumberFloatType,
    198  AllocatorType>;
    199 
    200  public:
    201  // forward declarations
    202  template<typename Base> class json_reverse_iterator;
    203  class json_pointer;
    204 
    206  // container types //
    208 
    211 
    214 
    218  using const_reference = const value_type&;
    219 
    221  using difference_type = std::ptrdiff_t;
    223  using size_type = std::size_t;
    224 
    226  using allocator_type = AllocatorType<basic_json>;
    227 
    229  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    231  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    232 
    234  class iterator;
    236  class const_iterator;
    241 
    243 
    244 
    249  {
    250  return allocator_type();
    251  }
    252 
    253 
    255  // JSON value data types //
    257 
    260 
    343  using object_t = ObjectType<StringType,
    344  basic_json,
    345  std::less<StringType>,
    346  AllocatorType<std::pair<const StringType,
    347  basic_json>>>;
    348 
    393  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    394 
    440  using string_t = StringType;
    441 
    466  using boolean_t = BooleanType;
    467 
    537  using number_integer_t = NumberIntegerType;
    538 
    609  using number_unsigned_t = NumberUnsignedType;
    610 
    677  using number_float_t = NumberFloatType;
    678 
    680 
    681 
    683  // JSON type enumeration //
    685 
    696  enum class value_t : uint8_t
    697  {
    698  null,
    699  object,
    700  array,
    701  string,
    702  boolean,
    703  number_integer,
    704  number_unsigned,
    705  number_float,
    706  discarded
    707  };
    708 
    709 
    710  private:
    711 
    726  union type_data_t
    727  {
    728  struct
    729  {
    731  uint16_t type : 4;
    733  uint16_t parsed : 1;
    735  uint16_t has_exp : 1;
    737  uint16_t exp_plus : 1;
    739  uint16_t exp_cap : 1;
    741  uint16_t precision : 8;
    742  } bits;
    743  uint16_t data;
    744 
    746  operator value_t() const
    747  {
    748  return static_cast<value_t>(bits.type);
    749  }
    750 
    752  bool operator==(const value_t& rhs) const
    753  {
    754  return static_cast<value_t>(bits.type) == rhs;
    755  }
    756 
    758  type_data_t& operator=(value_t rhs)
    759  {
    760  bits.type = static_cast<uint16_t>(rhs);
    761  return *this;
    762  }
    763 
    765  type_data_t(value_t t) noexcept
    766  {
    767  *reinterpret_cast<uint16_t*>(this) = 0;
    768  bits.type = static_cast<uint16_t>(t);
    769  }
    770 
    772  type_data_t() noexcept
    773  {
    774  data = 0;
    775  bits.type = reinterpret_cast<uint16_t>(value_t::null);
    776  }
    777  };
    778 
    780  template<typename T, typename... Args>
    781  static T* create(Args&& ... args)
    782  {
    783  AllocatorType<T> alloc;
    784  auto deleter = [&](T * object)
    785  {
    786  alloc.deallocate(object, 1);
    787  };
    788  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    789  alloc.construct(object.get(), std::forward<Args>(args)...);
    790  return object.release();
    791  }
    792 
    794  // JSON value storage //
    796 
    804  union json_value
    805  {
    807  object_t* object;
    809  array_t* array;
    811  string_t* string;
    813  boolean_t boolean;
    815  number_integer_t number_integer;
    817  number_unsigned_t number_unsigned;
    819  number_float_t number_float;
    820 
    822  json_value() = default;
    824  json_value(boolean_t v) noexcept : boolean(v) {}
    826  json_value(number_integer_t v) noexcept : number_integer(v) {}
    828  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    830  json_value(number_float_t v) noexcept : number_float(v) {}
    832  json_value(value_t t)
    833  {
    834  switch (t)
    835  {
    836  case value_t::object:
    837  {
    838  object = create<object_t>();
    839  break;
    840  }
    841 
    842  case value_t::array:
    843  {
    844  array = create<array_t>();
    845  break;
    846  }
    847 
    848  case value_t::string:
    849  {
    850  string = create<string_t>("");
    851  break;
    852  }
    853 
    854  case value_t::boolean:
    855  {
    856  boolean = boolean_t(false);
    857  break;
    858  }
    859 
    860  case value_t::number_integer:
    861  {
    862  number_integer = number_integer_t(0);
    863  break;
    864  }
    865 
    866  case value_t::number_unsigned:
    867  {
    868  number_unsigned = number_unsigned_t(0);
    869  break;
    870  }
    871 
    872  case value_t::number_float:
    873  {
    874  number_float = number_float_t(0.0);
    875  break;
    876  }
    877 
    878  default:
    879  {
    880  break;
    881  }
    882  }
    883  }
    884 
    886  json_value(const string_t& value)
    887  {
    888  string = create<string_t>(value);
    889  }
    890 
    892  json_value(const object_t& value)
    893  {
    894  object = create<object_t>(value);
    895  }
    896 
    898  json_value(const array_t& value)
    899  {
    900  array = create<array_t>(value);
    901  }
    902  };
    903 
    904 
    905  public:
    907  // JSON parser callback //
    909 
    918  enum class parse_event_t : uint8_t
    919  {
    921  object_start,
    923  object_end,
    925  array_start,
    927  array_end,
    929  key,
    931  value
    932  };
    933 
    983  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    984 
    985 
    987  // constructors //
    989 
    992 
    1033  : m_type(value_type), m_value(value_type)
    1034  {}
    1035 
    1060  basic_json() = default;
    1061 
    1084  basic_json(std::nullptr_t) noexcept
    1085  : basic_json(value_t::null)
    1086  {}
    1087 
    1107  basic_json(const object_t& val)
    1108  : m_type(value_t::object), m_value(val)
    1109  {}
    1110 
    1137  template <class CompatibleObjectType, typename
    1138  std::enable_if<
    1139  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1140  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    1141  = 0>
    1142  basic_json(const CompatibleObjectType& val)
    1143  : m_type(value_t::object)
    1144  {
    1145  using std::begin;
    1146  using std::end;
    1147  m_value.object = create<object_t>(begin(val), end(val));
    1148  }
    1149 
    1169  basic_json(const array_t& val)
    1170  : m_type(value_t::array), m_value(val)
    1171  {}
    1172 
    1199  template <class CompatibleArrayType, typename
    1200  std::enable_if<
    1201  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1202  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1203  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1204  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1205  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1206  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1207  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1208  = 0>
    1209  basic_json(const CompatibleArrayType& val)
    1210  : m_type(value_t::array)
    1211  {
    1212  using std::begin;
    1213  using std::end;
    1214  m_value.array = create<array_t>(begin(val), end(val));
    1215  }
    1216 
    1238  basic_json(const string_t& val)
    1239  : m_type(value_t::string), m_value(val)
    1240  {}
    1241 
    1262  basic_json(const typename string_t::value_type* val)
    1263  : basic_json(string_t(val))
    1264  {}
    1265 
    1289  template <class CompatibleStringType, typename
    1290  std::enable_if<
    1291  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1292  = 0>
    1293  basic_json(const CompatibleStringType& val)
    1294  : basic_json(string_t(val))
    1295  {}
    1296 
    1311  basic_json(boolean_t val) noexcept
    1312  : m_type(value_t::boolean), m_value(val)
    1313  {}
    1314 
    1338  template<typename T,
    1339  typename std::enable_if<
    1340  not (std::is_same<T, int>::value)
    1341  and std::is_same<T, number_integer_t>::value
    1342  , int>::type
    1343  = 0>
    1344  basic_json(const number_integer_t val) noexcept
    1345  : m_type(value_t::number_integer), m_value(val)
    1346  {}
    1347 
    1373  basic_json(const int val) noexcept
    1374  : m_type(value_t::number_integer),
    1375  m_value(static_cast<number_integer_t>(val))
    1376  {}
    1377 
    1403  template<typename CompatibleNumberIntegerType, typename
    1404  std::enable_if<
    1405  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1406  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1407  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1408  CompatibleNumberIntegerType>::type
    1409  = 0>
    1410  basic_json(const CompatibleNumberIntegerType val) noexcept
    1411  : m_type(value_t::number_integer),
    1412  m_value(static_cast<number_integer_t>(val))
    1413  {}
    1414 
    1432  template<typename T,
    1433  typename std::enable_if<
    1434  not (std::is_same<T, int>::value)
    1435  and std::is_same<T, number_unsigned_t>::value
    1436  , int>::type
    1437  = 0>
    1438  basic_json(const number_unsigned_t val) noexcept
    1439  : m_type(value_t::number_unsigned), m_value(val)
    1440  {}
    1441 
    1462  template < typename CompatibleNumberUnsignedType, typename
    1463  std::enable_if <
    1464  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1465  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1466  !std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1467  CompatibleNumberUnsignedType >::type
    1468  = 0 >
    1469  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1470  : m_type(value_t::number_unsigned),
    1471  m_value(static_cast<number_unsigned_t>(val))
    1472  {}
    1473 
    1498  basic_json(const number_float_t val) noexcept
    1499  : m_type(value_t::number_float), m_value(val)
    1500  {
    1501  // replace infinity and NAN by null
    1502  if (not std::isfinite(val))
    1503  {
    1504  m_type = value_t::null;
    1505  m_value = json_value();
    1506  }
    1507  }
    1508 
    1539  template<typename CompatibleNumberFloatType, typename = typename
    1540  std::enable_if<
    1541  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1542  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1543  >
    1544  basic_json(const CompatibleNumberFloatType val) noexcept
    1545  : basic_json(number_float_t(val))
    1546  {}
    1547 
    1617  basic_json(std::initializer_list<basic_json> init,
    1618  bool type_deduction = true,
    1619  value_t manual_type = value_t::array)
    1620  {
    1621  // the initializer list could describe an object
    1622  bool is_an_object = true;
    1623 
    1624  // check if each element is an array with two elements whose first
    1625  // element is a string
    1626  for (const auto& element : init)
    1627  {
    1628  if (not element.is_array() or element.size() != 2
    1629  or not element[0].is_string())
    1630  {
    1631  // we found an element that makes it impossible to use the
    1632  // initializer list as object
    1633  is_an_object = false;
    1634  break;
    1635  }
    1636  }
    1637 
    1638  // adjust type if type deduction is not wanted
    1639  if (not type_deduction)
    1640  {
    1641  // if array is wanted, do not create an object though possible
    1642  if (manual_type == value_t::array)
    1643  {
    1644  is_an_object = false;
    1645  }
    1646 
    1647  // if object is wanted but impossible, throw an exception
    1648  if (manual_type == value_t::object and not is_an_object)
    1649  {
    1650  throw std::domain_error("cannot create object from initializer list");
    1651  }
    1652  }
    1653 
    1654  if (is_an_object)
    1655  {
    1656  // the initializer list is a list of pairs -> create object
    1657  m_type = value_t::object;
    1658  m_value = value_t::object;
    1659 
    1660  assert(m_value.object != nullptr);
    1661 
    1662  for (auto& element : init)
    1663  {
    1664  m_value.object->emplace(*(element[0].m_value.string), element[1]);
    1665  }
    1666  }
    1667  else
    1668  {
    1669  // the initializer list describes an array -> create array
    1670  m_type = value_t::array;
    1671  m_value.array = create<array_t>(init);
    1672  }
    1673  }
    1674 
    1709  static basic_json array(std::initializer_list<basic_json> init =
    1710  std::initializer_list<basic_json>())
    1711  {
    1712  return basic_json(init, false, value_t::array);
    1713  }
    1714 
    1749  static basic_json object(std::initializer_list<basic_json> init =
    1750  std::initializer_list<basic_json>())
    1751  {
    1752  return basic_json(init, false, value_t::object);
    1753  }
    1754 
    1773  basic_json(size_type cnt, const basic_json& val)
    1774  : m_type(value_t::array)
    1775  {
    1776  m_value.array = create<array_t>(cnt, val);
    1777  }
    1778 
    1813  template <class InputIT, typename
    1814  std::enable_if<
    1815  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1816  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1817  , int>::type
    1818  = 0>
    1819  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1820  {
    1821  // make sure iterator fits the current value
    1822  if (first.m_object != last.m_object)
    1823  {
    1824  throw std::domain_error("iterators are not compatible");
    1825  }
    1826 
    1827  // check if iterator range is complete for primitive values
    1828  switch (m_type)
    1829  {
    1830  case value_t::boolean:
    1831  case value_t::number_float:
    1832  case value_t::number_integer:
    1833  case value_t::number_unsigned:
    1834  case value_t::string:
    1835  {
    1836  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1837  {
    1838  throw std::out_of_range("iterators out of range");
    1839  }
    1840  break;
    1841  }
    1842 
    1843  default:
    1844  {
    1845  break;
    1846  }
    1847  }
    1848 
    1849  switch (m_type)
    1850  {
    1851  case value_t::number_integer:
    1852  {
    1853  assert(first.m_object != nullptr);
    1854  m_value.number_integer = first.m_object->m_value.number_integer;
    1855  break;
    1856  }
    1857 
    1858  case value_t::number_unsigned:
    1859  {
    1860  assert(first.m_object != nullptr);
    1861  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1862  break;
    1863  }
    1864 
    1865  case value_t::number_float:
    1866  {
    1867  assert(first.m_object != nullptr);
    1868  m_value.number_float = first.m_object->m_value.number_float;
    1869  break;
    1870  }
    1871 
    1872  case value_t::boolean:
    1873  {
    1874  assert(first.m_object != nullptr);
    1875  m_value.boolean = first.m_object->m_value.boolean;
    1876  break;
    1877  }
    1878 
    1879  case value_t::string:
    1880  {
    1881  assert(first.m_object != nullptr);
    1882  m_value = *first.m_object->m_value.string;
    1883  break;
    1884  }
    1885 
    1886  case value_t::object:
    1887  {
    1888  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1889  break;
    1890  }
    1891 
    1892  case value_t::array:
    1893  {
    1894  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1895  break;
    1896  }
    1897 
    1898  default:
    1899  {
    1900  assert(first.m_object != nullptr);
    1901  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1902  }
    1903  }
    1904  }
    1905 
    1926  explicit basic_json(std::istream& i, parser_callback_t cb = nullptr)
    1927  {
    1928  *this = parser(i, cb).parse();
    1929  }
    1930 
    1932  // other constructors and destructor //
    1934 
    1957  basic_json(const basic_json& other)
    1958  : m_type(other.m_type)
    1959  {
    1960  switch (m_type)
    1961  {
    1962  case value_t::object:
    1963  {
    1964  assert(other.m_value.object != nullptr);
    1965  m_value = *other.m_value.object;
    1966  break;
    1967  }
    1968 
    1969  case value_t::array:
    1970  {
    1971  assert(other.m_value.array != nullptr);
    1972  m_value = *other.m_value.array;
    1973  break;
    1974  }
    1975 
    1976  case value_t::string:
    1977  {
    1978  assert(other.m_value.string != nullptr);
    1979  m_value = *other.m_value.string;
    1980  break;
    1981  }
    1982 
    1983  case value_t::boolean:
    1984  {
    1985  m_value = other.m_value.boolean;
    1986  break;
    1987  }
    1988 
    1989  case value_t::number_integer:
    1990  {
    1991  m_value = other.m_value.number_integer;
    1992  break;
    1993  }
    1994 
    1995  case value_t::number_unsigned:
    1996  {
    1997  m_value = other.m_value.number_unsigned;
    1998  break;
    1999  }
    2000 
    2001  case value_t::number_float:
    2002  {
    2003  m_value = other.m_value.number_float;
    2004  break;
    2005  }
    2006 
    2007  default:
    2008  {
    2009  break;
    2010  }
    2011  }
    2012  }
    2013 
    2032  basic_json(basic_json&& other) noexcept
    2033  : m_type(std::move(other.m_type)),
    2034  m_value(std::move(other.m_value))
    2035  {
    2036  // invalidate payload
    2037  other.m_type = value_t::null;
    2038  other.m_value = {};
    2039  }
    2040 
    2064  reference& operator=(basic_json other) noexcept (
    2065  std::is_nothrow_move_constructible<value_t>::value and
    2066  std::is_nothrow_move_assignable<value_t>::value and
    2067  std::is_nothrow_move_constructible<json_value>::value and
    2068  std::is_nothrow_move_assignable<json_value>::value
    2069  )
    2070  {
    2071  using std::swap;
    2072  swap(m_type, other.m_type);
    2073  swap(m_value, other.m_value);
    2074  return *this;
    2075  }
    2076 
    2093  {
    2094  switch (m_type)
    2095  {
    2096  case value_t::object:
    2097  {
    2098  AllocatorType<object_t> alloc;
    2099  alloc.destroy(m_value.object);
    2100  alloc.deallocate(m_value.object, 1);
    2101  break;
    2102  }
    2103 
    2104  case value_t::array:
    2105  {
    2106  AllocatorType<array_t> alloc;
    2107  alloc.destroy(m_value.array);
    2108  alloc.deallocate(m_value.array, 1);
    2109  break;
    2110  }
    2111 
    2112  case value_t::string:
    2113  {
    2114  AllocatorType<string_t> alloc;
    2115  alloc.destroy(m_value.string);
    2116  alloc.deallocate(m_value.string, 1);
    2117  break;
    2118  }
    2119 
    2120  default:
    2121  {
    2122  // all other types need no specific destructor
    2123  break;
    2124  }
    2125  }
    2126  }
    2127 
    2129 
    2130  public:
    2132  // object inspection //
    2134 
    2137 
    2161  string_t dump(const int indent = -1) const
    2162  {
    2163  std::stringstream ss;
    2164 
    2165  if (indent >= 0)
    2166  {
    2167  dump(ss, true, static_cast<unsigned int>(indent));
    2168  }
    2169  else
    2170  {
    2171  dump(ss, false, 0);
    2172  }
    2173 
    2174  return ss.str();
    2175  }
    2176 
    2195  constexpr value_t type() const noexcept
    2196  {
    2197  return m_type;
    2198  }
    2199 
    2225  constexpr bool is_primitive() const noexcept
    2226  {
    2227  return is_null() or is_string() or is_boolean() or is_number();
    2228  }
    2229 
    2252  constexpr bool is_structured() const noexcept
    2253  {
    2254  return is_array() or is_object();
    2255  }
    2256 
    2274  constexpr bool is_null() const noexcept
    2275  {
    2276  return m_type == value_t::null;
    2277  }
    2278 
    2296  constexpr bool is_boolean() const noexcept
    2297  {
    2298  return m_type == value_t::boolean;
    2299  }
    2300 
    2326  constexpr bool is_number() const noexcept
    2327  {
    2328  return is_number_integer() or is_number_float();
    2329  }
    2330 
    2355  constexpr bool is_number_integer() const noexcept
    2356  {
    2357  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2358  }
    2359 
    2383  constexpr bool is_number_unsigned() const noexcept
    2384  {
    2385  return m_type == value_t::number_unsigned;
    2386  }
    2387 
    2411  constexpr bool is_number_float() const noexcept
    2412  {
    2413  return m_type == value_t::number_float;
    2414  }
    2415 
    2433  constexpr bool is_object() const noexcept
    2434  {
    2435  return m_type == value_t::object;
    2436  }
    2437 
    2455  constexpr bool is_array() const noexcept
    2456  {
    2457  return m_type == value_t::array;
    2458  }
    2459 
    2477  constexpr bool is_string() const noexcept
    2478  {
    2479  return m_type == value_t::string;
    2480  }
    2481 
    2504  constexpr bool is_discarded() const noexcept
    2505  {
    2506  return m_type == value_t::discarded;
    2507  }
    2508 
    2527  constexpr operator value_t() const noexcept
    2528  {
    2529  return m_type;
    2530  }
    2531 
    2533 
    2534  private:
    2536  // value access //
    2538 
    2540  template <class T, typename
    2541  std::enable_if<
    2542  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2543  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2544  , int>::type = 0>
    2545  T get_impl(T*) const
    2546  {
    2547  if (is_object())
    2548  {
    2549  assert(m_value.object != nullptr);
    2550  return T(m_value.object->begin(), m_value.object->end());
    2551  }
    2552  else
    2553  {
    2554  throw std::domain_error("type must be object, but is " + type_name());
    2555  }
    2556  }
    2557 
    2559  object_t get_impl(object_t*) const
    2560  {
    2561  if (is_object())
    2562  {
    2563  assert(m_value.object != nullptr);
    2564  return *(m_value.object);
    2565  }
    2566  else
    2567  {
    2568  throw std::domain_error("type must be object, but is " + type_name());
    2569  }
    2570  }
    2571 
    2573  template <class T, typename
    2574  std::enable_if<
    2575  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2576  not std::is_same<basic_json_t, typename T::value_type>::value and
    2577  not std::is_arithmetic<T>::value and
    2578  not std::is_convertible<std::string, T>::value and
    2579  not has_mapped_type<T>::value
    2580  , int>::type = 0>
    2581  T get_impl(T*) const
    2582  {
    2583  if (is_array())
    2584  {
    2585  T to_vector;
    2586  assert(m_value.array != nullptr);
    2587  std::transform(m_value.array->begin(), m_value.array->end(),
    2588  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2589  {
    2590  return i.get<typename T::value_type>();
    2591  });
    2592  return to_vector;
    2593  }
    2594  else
    2595  {
    2596  throw std::domain_error("type must be array, but is " + type_name());
    2597  }
    2598  }
    2599 
    2601  template <class T, typename
    2602  std::enable_if<
    2603  std::is_convertible<basic_json_t, T>::value and
    2604  not std::is_same<basic_json_t, T>::value
    2605  , int>::type = 0>
    2606  std::vector<T> get_impl(std::vector<T>*) const
    2607  {
    2608  if (is_array())
    2609  {
    2610  std::vector<T> to_vector;
    2611  assert(m_value.array != nullptr);
    2612  to_vector.reserve(m_value.array->size());
    2613  std::transform(m_value.array->begin(), m_value.array->end(),
    2614  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2615  {
    2616  return i.get<T>();
    2617  });
    2618  return to_vector;
    2619  }
    2620  else
    2621  {
    2622  throw std::domain_error("type must be array, but is " + type_name());
    2623  }
    2624  }
    2625 
    2627  template <class T, typename
    2628  std::enable_if<
    2629  std::is_same<basic_json, typename T::value_type>::value and
    2630  not has_mapped_type<T>::value
    2631  , int>::type = 0>
    2632  T get_impl(T*) const
    2633  {
    2634  if (is_array())
    2635  {
    2636  assert(m_value.array != nullptr);
    2637  return T(m_value.array->begin(), m_value.array->end());
    2638  }
    2639  else
    2640  {
    2641  throw std::domain_error("type must be array, but is " + type_name());
    2642  }
    2643  }
    2644 
    2646  array_t get_impl(array_t*) const
    2647  {
    2648  if (is_array())
    2649  {
    2650  assert(m_value.array != nullptr);
    2651  return *(m_value.array);
    2652  }
    2653  else
    2654  {
    2655  throw std::domain_error("type must be array, but is " + type_name());
    2656  }
    2657  }
    2658 
    2660  template <typename T, typename
    2661  std::enable_if<
    2662  std::is_convertible<string_t, T>::value
    2663  , int>::type = 0>
    2664  T get_impl(T*) const
    2665  {
    2666  if (is_string())
    2667  {
    2668  assert(m_value.string != nullptr);
    2669  return *m_value.string;
    2670  }
    2671  else
    2672  {
    2673  throw std::domain_error("type must be string, but is " + type_name());
    2674  }
    2675  }
    2676 
    2678  template<typename T, typename
    2679  std::enable_if<
    2680  std::is_arithmetic<T>::value
    2681  , int>::type = 0>
    2682  T get_impl(T*) const
    2683  {
    2684  switch (m_type)
    2685  {
    2686  case value_t::number_integer:
    2687  {
    2688  return static_cast<T>(m_value.number_integer);
    2689  }
    2690 
    2691  case value_t::number_unsigned:
    2692  {
    2693  return static_cast<T>(m_value.number_unsigned);
    2694  }
    2695 
    2696  case value_t::number_float:
    2697  {
    2698  return static_cast<T>(m_value.number_float);
    2699  }
    2700 
    2701  default:
    2702  {
    2703  throw std::domain_error("type must be number, but is " + type_name());
    2704  }
    2705  }
    2706  }
    2707 
    2709  constexpr boolean_t get_impl(boolean_t*) const
    2710  {
    2711  return is_boolean()
    2712  ? m_value.boolean
    2713  : throw std::domain_error("type must be boolean, but is " + type_name());
    2714  }
    2715 
    2717  object_t* get_impl_ptr(object_t*) noexcept
    2718  {
    2719  return is_object() ? m_value.object : nullptr;
    2720  }
    2721 
    2723  constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
    2724  {
    2725  return is_object() ? m_value.object : nullptr;
    2726  }
    2727 
    2729  array_t* get_impl_ptr(array_t*) noexcept
    2730  {
    2731  return is_array() ? m_value.array : nullptr;
    2732  }
    2733 
    2735  constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
    2736  {
    2737  return is_array() ? m_value.array : nullptr;
    2738  }
    2739 
    2741  string_t* get_impl_ptr(string_t*) noexcept
    2742  {
    2743  return is_string() ? m_value.string : nullptr;
    2744  }
    2745 
    2747  constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
    2748  {
    2749  return is_string() ? m_value.string : nullptr;
    2750  }
    2751 
    2753  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2754  {
    2755  return is_boolean() ? &m_value.boolean : nullptr;
    2756  }
    2757 
    2759  constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2760  {
    2761  return is_boolean() ? &m_value.boolean : nullptr;
    2762  }
    2763 
    2765  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2766  {
    2767  return is_number_integer() ? &m_value.number_integer : nullptr;
    2768  }
    2769 
    2771  constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2772  {
    2773  return is_number_integer() ? &m_value.number_integer : nullptr;
    2774  }
    2775 
    2777  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2778  {
    2779  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2780  }
    2781 
    2783  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2784  {
    2785  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2786  }
    2787 
    2789  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2790  {
    2791  return is_number_float() ? &m_value.number_float : nullptr;
    2792  }
    2793 
    2795  constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2796  {
    2797  return is_number_float() ? &m_value.number_float : nullptr;
    2798  }
    2799 
    2811  template<typename ReferenceType, typename ThisType>
    2812  static ReferenceType get_ref_impl(ThisType& obj)
    2813  {
    2814  // delegate the call to get_ptr<>()
    2815  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2816  auto ptr = obj.template get_ptr<PointerType>();
    2817 
    2818  if (ptr != nullptr)
    2819  {
    2820  return *ptr;
    2821  }
    2822  else
    2823  {
    2824  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2825  obj.type_name());
    2826  }
    2827  }
    2828 
    2829  public:
    2830 
    2833 
    2867  template<typename ValueType, typename
    2868  std::enable_if<
    2869  not std::is_pointer<ValueType>::value
    2870  , int>::type = 0>
    2871  ValueType get() const
    2872  {
    2873  return get_impl(static_cast<ValueType*>(nullptr));
    2874  }
    2875 
    2902  template<typename PointerType, typename
    2903  std::enable_if<
    2904  std::is_pointer<PointerType>::value
    2905  , int>::type = 0>
    2906  PointerType get() noexcept
    2907  {
    2908  // delegate the call to get_ptr
    2909  return get_ptr<PointerType>();
    2910  }
    2911 
    2916  template<typename PointerType, typename
    2917  std::enable_if<
    2918  std::is_pointer<PointerType>::value
    2919  , int>::type = 0>
    2920  constexpr const PointerType get() const noexcept
    2921  {
    2922  // delegate the call to get_ptr
    2923  return get_ptr<PointerType>();
    2924  }
    2925 
    2951  template<typename PointerType, typename
    2952  std::enable_if<
    2953  std::is_pointer<PointerType>::value
    2954  , int>::type = 0>
    2955  PointerType get_ptr() noexcept
    2956  {
    2957  // delegate the call to get_impl_ptr<>()
    2958  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2959  }
    2960 
    2965  template<typename PointerType, typename
    2966  std::enable_if<
    2967  std::is_pointer<PointerType>::value
    2968  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2969  , int>::type = 0>
    2970  constexpr const PointerType get_ptr() const noexcept
    2971  {
    2972  // delegate the call to get_impl_ptr<>() const
    2973  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2974  }
    2975 
    3002  template<typename ReferenceType, typename
    3003  std::enable_if<
    3004  std::is_reference<ReferenceType>::value
    3005  , int>::type = 0>
    3006  ReferenceType get_ref()
    3007  {
    3008  // delegate call to get_ref_impl
    3009  return get_ref_impl<ReferenceType>(*this);
    3010  }
    3011 
    3016  template<typename ReferenceType, typename
    3017  std::enable_if<
    3018  std::is_reference<ReferenceType>::value
    3019  and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
    3020  , int>::type = 0>
    3021  ReferenceType get_ref() const
    3022  {
    3023  // delegate call to get_ref_impl
    3024  return get_ref_impl<ReferenceType>(*this);
    3025  }
    3026 
    3055  template < typename ValueType, typename
    3056  std::enable_if <
    3057  not std::is_pointer<ValueType>::value
    3058  and not std::is_same<ValueType, typename string_t::value_type>::value
    3059 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    3060  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    3061 #endif
    3062  , int >::type = 0 >
    3063  operator ValueType() const
    3064  {
    3065  // delegate the call to get<>() const
    3066  return get<ValueType>();
    3067  }
    3068 
    3070 
    3071 
    3073  // element access //
    3075 
    3078 
    3102  {
    3103  // at only works for arrays
    3104  if (is_array())
    3105  {
    3106  try
    3107  {
    3108  assert(m_value.array != nullptr);
    3109  return m_value.array->at(idx);
    3110  }
    3111  catch (std::out_of_range&)
    3112  {
    3113  // create better exception explanation
    3114  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3115  }
    3116  }
    3117  else
    3118  {
    3119  throw std::domain_error("cannot use at() with " + type_name());
    3120  }
    3121  }
    3122 
    3146  {
    3147  // at only works for arrays
    3148  if (is_array())
    3149  {
    3150  try
    3151  {
    3152  assert(m_value.array != nullptr);
    3153  return m_value.array->at(idx);
    3154  }
    3155  catch (std::out_of_range&)
    3156  {
    3157  // create better exception explanation
    3158  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3159  }
    3160  }
    3161  else
    3162  {
    3163  throw std::domain_error("cannot use at() with " + type_name());
    3164  }
    3165  }
    3166 
    3193  reference at(const typename object_t::key_type& key)
    3194  {
    3195  // at only works for objects
    3196  if (is_object())
    3197  {
    3198  try
    3199  {
    3200  assert(m_value.object != nullptr);
    3201  return m_value.object->at(key);
    3202  }
    3203  catch (std::out_of_range&)
    3204  {
    3205  // create better exception explanation
    3206  throw std::out_of_range("key '" + key + "' not found");
    3207  }
    3208  }
    3209  else
    3210  {
    3211  throw std::domain_error("cannot use at() with " + type_name());
    3212  }
    3213  }
    3214 
    3241  const_reference at(const typename object_t::key_type& key) const
    3242  {
    3243  // at only works for objects
    3244  if (is_object())
    3245  {
    3246  try
    3247  {
    3248  assert(m_value.object != nullptr);
    3249  return m_value.object->at(key);
    3250  }
    3251  catch (std::out_of_range&)
    3252  {
    3253  // create better exception explanation
    3254  throw std::out_of_range("key '" + key + "' not found");
    3255  }
    3256  }
    3257  else
    3258  {
    3259  throw std::domain_error("cannot use at() with " + type_name());
    3260  }
    3261  }
    3262 
    3289  {
    3290  // implicitly convert null value to an empty array
    3291  if (is_null())
    3292  {
    3293  m_type = value_t::array;
    3294  m_value.array = create<array_t>();
    3295  }
    3296 
    3297  // operator[] only works for arrays
    3298  if (is_array())
    3299  {
    3300  // fill up array with null values until given idx is reached
    3301  assert(m_value.array != nullptr);
    3302  for (size_t i = m_value.array->size(); i <= idx; ++i)
    3303  {
    3304  m_value.array->push_back(basic_json());
    3305  }
    3306 
    3307  return m_value.array->operator[](idx);
    3308  }
    3309  else
    3310  {
    3311  throw std::domain_error("cannot use operator[] with " + type_name());
    3312  }
    3313  }
    3314 
    3335  {
    3336  // const operator[] only works for arrays
    3337  if (is_array())
    3338  {
    3339  assert(m_value.array != nullptr);
    3340  return m_value.array->operator[](idx);
    3341  }
    3342  else
    3343  {
    3344  throw std::domain_error("cannot use operator[] with " + type_name());
    3345  }
    3346  }
    3347 
    3375  reference operator[](const typename object_t::key_type& key)
    3376  {
    3377  // implicitly convert null value to an empty object
    3378  if (is_null())
    3379  {
    3380  m_type = value_t::object;
    3381  m_value.object = create<object_t>();
    3382  }
    3383 
    3384  // operator[] only works for objects
    3385  if (is_object())
    3386  {
    3387  assert(m_value.object != nullptr);
    3388  return m_value.object->operator[](key);
    3389  }
    3390  else
    3391  {
    3392  throw std::domain_error("cannot use operator[] with " + type_name());
    3393  }
    3394  }
    3395 
    3423  const_reference operator[](const typename object_t::key_type& key) const
    3424  {
    3425  // const operator[] only works for objects
    3426  if (is_object())
    3427  {
    3428  assert(m_value.object != nullptr);
    3429  assert(m_value.object->find(key) != m_value.object->end());
    3430  return m_value.object->find(key)->second;
    3431  }
    3432  else
    3433  {
    3434  throw std::domain_error("cannot use operator[] with " + type_name());
    3435  }
    3436  }
    3437 
    3465  template<typename T, std::size_t n>
    3466  reference operator[](T * (&key)[n])
    3467  {
    3468  return operator[](static_cast<const T>(key));
    3469  }
    3470 
    3500  template<typename T, std::size_t n>
    3501  const_reference operator[](T * (&key)[n]) const
    3502  {
    3503  return operator[](static_cast<const T>(key));
    3504  }
    3505 
    3533  template<typename T>
    3535  {
    3536  // implicitly convert null to object
    3537  if (is_null())
    3538  {
    3539  m_type = value_t::object;
    3540  m_value = value_t::object;
    3541  }
    3542 
    3543  // at only works for objects
    3544  if (is_object())
    3545  {
    3546  assert(m_value.object != nullptr);
    3547  return m_value.object->operator[](key);
    3548  }
    3549  else
    3550  {
    3551  throw std::domain_error("cannot use operator[] with " + type_name());
    3552  }
    3553  }
    3554 
    3582  template<typename T>
    3584  {
    3585  // at only works for objects
    3586  if (is_object())
    3587  {
    3588  assert(m_value.object != nullptr);
    3589  assert(m_value.object->find(key) != m_value.object->end());
    3590  return m_value.object->find(key)->second;
    3591  }
    3592  else
    3593  {
    3594  throw std::domain_error("cannot use operator[] with " + type_name());
    3595  }
    3596  }
    3597 
    3646  template <class ValueType, typename
    3647  std::enable_if<
    3648  std::is_convertible<basic_json_t, ValueType>::value
    3649  , int>::type = 0>
    3650  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3651  {
    3652  // at only works for objects
    3653  if (is_object())
    3654  {
    3655  // if key is found, return value and given default value otherwise
    3656  const auto it = find(key);
    3657  if (it != end())
    3658  {
    3659  return *it;
    3660  }
    3661  else
    3662  {
    3663  return default_value;
    3664  }
    3665  }
    3666  else
    3667  {
    3668  throw std::domain_error("cannot use value() with " + type_name());
    3669  }
    3670  }
    3671 
    3676  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3677  {
    3678  return value(key, string_t(default_value));
    3679  }
    3680 
    3706  {
    3707  return *begin();
    3708  }
    3709 
    3714  {
    3715  return *cbegin();
    3716  }
    3717 
    3748  {
    3749  auto tmp = end();
    3750  --tmp;
    3751  return *tmp;
    3752  }
    3753 
    3758  {
    3759  auto tmp = cend();
    3760  --tmp;
    3761  return *tmp;
    3762  }
    3763 
    3809  template <class InteratorType, typename
    3810  std::enable_if<
    3811  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3812  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3813  , int>::type
    3814  = 0>
    3815  InteratorType erase(InteratorType pos)
    3816  {
    3817  // make sure iterator fits the current value
    3818  if (this != pos.m_object)
    3819  {
    3820  throw std::domain_error("iterator does not fit current value");
    3821  }
    3822 
    3823  InteratorType result = end();
    3824 
    3825  switch (m_type)
    3826  {
    3827  case value_t::boolean:
    3828  case value_t::number_float:
    3829  case value_t::number_integer:
    3830  case value_t::number_unsigned:
    3831  case value_t::string:
    3832  {
    3833  if (not pos.m_it.primitive_iterator.is_begin())
    3834  {
    3835  throw std::out_of_range("iterator out of range");
    3836  }
    3837 
    3838  if (is_string())
    3839  {
    3840  delete m_value.string;
    3841  m_value.string = nullptr;
    3842  }
    3843 
    3844  m_type = value_t::null;
    3845  break;
    3846  }
    3847 
    3848  case value_t::object:
    3849  {
    3850  assert(m_value.object != nullptr);
    3851  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3852  break;
    3853  }
    3854 
    3855  case value_t::array:
    3856  {
    3857  assert(m_value.array != nullptr);
    3858  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3859  break;
    3860  }
    3861 
    3862  default:
    3863  {
    3864  throw std::domain_error("cannot use erase() with " + type_name());
    3865  }
    3866  }
    3867 
    3868  return result;
    3869  }
    3870 
    3917  template <class InteratorType, typename
    3918  std::enable_if<
    3919  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3920  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3921  , int>::type
    3922  = 0>
    3923  InteratorType erase(InteratorType first, InteratorType last)
    3924  {
    3925  // make sure iterator fits the current value
    3926  if (this != first.m_object or this != last.m_object)
    3927  {
    3928  throw std::domain_error("iterators do not fit current value");
    3929  }
    3930 
    3931  InteratorType result = end();
    3932 
    3933  switch (m_type)
    3934  {
    3935  case value_t::boolean:
    3936  case value_t::number_float:
    3937  case value_t::number_integer:
    3938  case value_t::number_unsigned:
    3939  case value_t::string:
    3940  {
    3941  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3942  {
    3943  throw std::out_of_range("iterators out of range");
    3944  }
    3945 
    3946  if (is_string())
    3947  {
    3948  delete m_value.string;
    3949  m_value.string = nullptr;
    3950  }
    3951 
    3952  m_type = value_t::null;
    3953  break;
    3954  }
    3955 
    3956  case value_t::object:
    3957  {
    3958  assert(m_value.object != nullptr);
    3959  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3960  last.m_it.object_iterator);
    3961  break;
    3962  }
    3963 
    3964  case value_t::array:
    3965  {
    3966  assert(m_value.array != nullptr);
    3967  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3968  last.m_it.array_iterator);
    3969  break;
    3970  }
    3971 
    3972  default:
    3973  {
    3974  throw std::domain_error("cannot use erase() with " + type_name());
    3975  }
    3976  }
    3977 
    3978  return result;
    3979  }
    3980 
    4010  size_type erase(const typename object_t::key_type& key)
    4011  {
    4012  // this erase only works for objects
    4013  if (is_object())
    4014  {
    4015  assert(m_value.object != nullptr);
    4016  return m_value.object->erase(key);
    4017  }
    4018  else
    4019  {
    4020  throw std::domain_error("cannot use erase() with " + type_name());
    4021  }
    4022  }
    4023 
    4048  void erase(const size_type idx)
    4049  {
    4050  // this erase only works for arrays
    4051  if (is_array())
    4052  {
    4053  if (idx >= size())
    4054  {
    4055  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    4056  }
    4057 
    4058  assert(m_value.array != nullptr);
    4059  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    4060  }
    4061  else
    4062  {
    4063  throw std::domain_error("cannot use erase() with " + type_name());
    4064  }
    4065  }
    4066 
    4068 
    4069 
    4071  // lookup //
    4073 
    4076 
    4094  iterator find(typename object_t::key_type key)
    4095  {
    4096  auto result = end();
    4097 
    4098  if (is_object())
    4099  {
    4100  assert(m_value.object != nullptr);
    4101  result.m_it.object_iterator = m_value.object->find(key);
    4102  }
    4103 
    4104  return result;
    4105  }
    4106 
    4111  const_iterator find(typename object_t::key_type key) const
    4112  {
    4113  auto result = cend();
    4114 
    4115  if (is_object())
    4116  {
    4117  assert(m_value.object != nullptr);
    4118  result.m_it.object_iterator = m_value.object->find(key);
    4119  }
    4120 
    4121  return result;
    4122  }
    4123 
    4142  size_type count(typename object_t::key_type key) const
    4143  {
    4144  // return 0 for all nonobject types
    4145  assert(not is_object() or m_value.object != nullptr);
    4146  return is_object() ? m_value.object->count(key) : 0;
    4147  }
    4148 
    4150 
    4151 
    4153  // iterators //
    4155 
    4158 
    4183  iterator begin() noexcept
    4184  {
    4185  iterator result(this);
    4186  result.set_begin();
    4187  return result;
    4188  }
    4189 
    4193  const_iterator begin() const noexcept
    4194  {
    4195  return cbegin();
    4196  }
    4197 
    4223  const_iterator cbegin() const noexcept
    4224  {
    4225  const_iterator result(this);
    4226  result.set_begin();
    4227  return result;
    4228  }
    4229 
    4254  iterator end() noexcept
    4255  {
    4256  iterator result(this);
    4257  result.set_end();
    4258  return result;
    4259  }
    4260 
    4264  const_iterator end() const noexcept
    4265  {
    4266  return cend();
    4267  }
    4268 
    4294  const_iterator cend() const noexcept
    4295  {
    4296  const_iterator result(this);
    4297  result.set_end();
    4298  return result;
    4299  }
    4300 
    4325  {
    4326  return reverse_iterator(end());
    4327  }
    4328 
    4333  {
    4334  return crbegin();
    4335  }
    4336 
    4362  {
    4363  return reverse_iterator(begin());
    4364  }
    4365 
    4369  const_reverse_iterator rend() const noexcept
    4370  {
    4371  return crend();
    4372  }
    4373 
    4399  {
    4400  return const_reverse_iterator(cend());
    4401  }
    4402 
    4428  {
    4429  return const_reverse_iterator(cbegin());
    4430  }
    4431 
    4432  private:
    4433  // forward declaration
    4434  template<typename IteratorType> class iteration_proxy;
    4435 
    4436  public:
    4448  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4449  {
    4450  return iteration_proxy<iterator>(cont);
    4451  }
    4452 
    4456  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4457  {
    4458  return iteration_proxy<const_iterator>(cont);
    4459  }
    4460 
    4462 
    4463 
    4465  // capacity //
    4467 
    4470 
    4504  bool empty() const noexcept
    4505  {
    4506  switch (m_type)
    4507  {
    4508  case value_t::null:
    4509  {
    4510  // null values are empty
    4511  return true;
    4512  }
    4513 
    4514  case value_t::array:
    4515  {
    4516  assert(m_value.array != nullptr);
    4517  return m_value.array->empty();
    4518  }
    4519 
    4520  case value_t::object:
    4521  {
    4522  assert(m_value.object != nullptr);
    4523  return m_value.object->empty();
    4524  }
    4525 
    4526  default:
    4527  {
    4528  // all other types are nonempty
    4529  return false;
    4530  }
    4531  }
    4532  }
    4533 
    4567  size_type size() const noexcept
    4568  {
    4569  switch (m_type)
    4570  {
    4571  case value_t::null:
    4572  {
    4573  // null values are empty
    4574  return 0;
    4575  }
    4576 
    4577  case value_t::array:
    4578  {
    4579  assert(m_value.array != nullptr);
    4580  return m_value.array->size();
    4581  }
    4582 
    4583  case value_t::object:
    4584  {
    4585  assert(m_value.object != nullptr);
    4586  return m_value.object->size();
    4587  }
    4588 
    4589  default:
    4590  {
    4591  // all other types have size 1
    4592  return 1;
    4593  }
    4594  }
    4595  }
    4596 
    4633  size_type max_size() const noexcept
    4634  {
    4635  switch (m_type)
    4636  {
    4637  case value_t::array:
    4638  {
    4639  assert(m_value.array != nullptr);
    4640  return m_value.array->max_size();
    4641  }
    4642 
    4643  case value_t::object:
    4644  {
    4645  assert(m_value.object != nullptr);
    4646  return m_value.object->max_size();
    4647  }
    4648 
    4649  default:
    4650  {
    4651  // all other types have max_size() == size()
    4652  return size();
    4653  }
    4654  }
    4655  }
    4656 
    4658 
    4659 
    4661  // modifiers //
    4663 
    4666 
    4692  void clear() noexcept
    4693  {
    4694  switch (m_type)
    4695  {
    4696  case value_t::number_integer:
    4697  {
    4698  m_value.number_integer = 0;
    4699  break;
    4700  }
    4701 
    4702  case value_t::number_unsigned:
    4703  {
    4704  m_value.number_unsigned = 0;
    4705  break;
    4706  }
    4707 
    4708  case value_t::number_float:
    4709  {
    4710  m_value.number_float = 0.0;
    4711  break;
    4712  }
    4713 
    4714  case value_t::boolean:
    4715  {
    4716  m_value.boolean = false;
    4717  break;
    4718  }
    4719 
    4720  case value_t::string:
    4721  {
    4722  assert(m_value.string != nullptr);
    4723  m_value.string->clear();
    4724  break;
    4725  }
    4726 
    4727  case value_t::array:
    4728  {
    4729  assert(m_value.array != nullptr);
    4730  m_value.array->clear();
    4731  break;
    4732  }
    4733 
    4734  case value_t::object:
    4735  {
    4736  assert(m_value.object != nullptr);
    4737  m_value.object->clear();
    4738  break;
    4739  }
    4740 
    4741  default:
    4742  {
    4743  break;
    4744  }
    4745  }
    4746  }
    4747 
    4768  void push_back(basic_json&& val)
    4769  {
    4770  // push_back only works for null objects or arrays
    4771  if (not(is_null() or is_array()))
    4772  {
    4773  throw std::domain_error("cannot use push_back() with " + type_name());
    4774  }
    4775 
    4776  // transform null object into an array
    4777  if (is_null())
    4778  {
    4779  m_type = value_t::array;
    4780  m_value = value_t::array;
    4781  }
    4782 
    4783  // add element to array (move semantics)
    4784  assert(m_value.array != nullptr);
    4785  m_value.array->push_back(std::move(val));
    4786  // invalidate object
    4787  val.m_type = value_t::null;
    4788  }
    4789 
    4794  reference operator+=(basic_json&& val)
    4795  {
    4796  push_back(std::move(val));
    4797  return *this;
    4798  }
    4799 
    4804  void push_back(const basic_json& val)
    4805  {
    4806  // push_back only works for null objects or arrays
    4807  if (not(is_null() or is_array()))
    4808  {
    4809  throw std::domain_error("cannot use push_back() with " + type_name());
    4810  }
    4811 
    4812  // transform null object into an array
    4813  if (is_null())
    4814  {
    4815  m_type = value_t::array;
    4816  m_value = value_t::array;
    4817  }
    4818 
    4819  // add element to array
    4820  assert(m_value.array != nullptr);
    4821  m_value.array->push_back(val);
    4822  }
    4823 
    4828  reference operator+=(const basic_json& val)
    4829  {
    4830  push_back(val);
    4831  return *this;
    4832  }
    4833 
    4854  void push_back(const typename object_t::value_type& val)
    4855  {
    4856  // push_back only works for null objects or objects
    4857  if (not(is_null() or is_object()))
    4858  {
    4859  throw std::domain_error("cannot use push_back() with " + type_name());
    4860  }
    4861 
    4862  // transform null object into an object
    4863  if (is_null())
    4864  {
    4865  m_type = value_t::object;
    4866  m_value = value_t::object;
    4867  }
    4868 
    4869  // add element to array
    4870  assert(m_value.object != nullptr);
    4871  m_value.object->insert(val);
    4872  }
    4873 
    4878  reference operator+=(const typename object_t::value_type& val)
    4879  {
    4880  push_back(val);
    4881  return operator[](val.first);
    4882  }
    4883 
    4906  iterator insert(const_iterator pos, const basic_json& val)
    4907  {
    4908  // insert only works for arrays
    4909  if (is_array())
    4910  {
    4911  // check if iterator pos fits to this JSON value
    4912  if (pos.m_object != this)
    4913  {
    4914  throw std::domain_error("iterator does not fit current value");
    4915  }
    4916 
    4917  // insert to array and return iterator
    4918  iterator result(this);
    4919  assert(m_value.array != nullptr);
    4920  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4921  return result;
    4922  }
    4923  else
    4924  {
    4925  throw std::domain_error("cannot use insert() with " + type_name());
    4926  }
    4927  }
    4928 
    4933  iterator insert(const_iterator pos, basic_json&& val)
    4934  {
    4935  return insert(pos, val);
    4936  }
    4937 
    4962  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    4963  {
    4964  // insert only works for arrays
    4965  if (is_array())
    4966  {
    4967  // check if iterator pos fits to this JSON value
    4968  if (pos.m_object != this)
    4969  {
    4970  throw std::domain_error("iterator does not fit current value");
    4971  }
    4972 
    4973  // insert to array and return iterator
    4974  iterator result(this);
    4975  assert(m_value.array != nullptr);
    4976  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    4977  return result;
    4978  }
    4979  else
    4980  {
    4981  throw std::domain_error("cannot use insert() with " + type_name());
    4982  }
    4983  }
    4984 
    5016  {
    5017  // insert only works for arrays
    5018  if (not is_array())
    5019  {
    5020  throw std::domain_error("cannot use insert() with " + type_name());
    5021  }
    5022 
    5023  // check if iterator pos fits to this JSON value
    5024  if (pos.m_object != this)
    5025  {
    5026  throw std::domain_error("iterator does not fit current value");
    5027  }
    5028 
    5029  if (first.m_object != last.m_object)
    5030  {
    5031  throw std::domain_error("iterators do not fit");
    5032  }
    5033 
    5034  if (first.m_object == this or last.m_object == this)
    5035  {
    5036  throw std::domain_error("passed iterators may not belong to container");
    5037  }
    5038 
    5039  // insert to array and return iterator
    5040  iterator result(this);
    5041  assert(m_value.array != nullptr);
    5042  result.m_it.array_iterator = m_value.array->insert(
    5043  pos.m_it.array_iterator,
    5044  first.m_it.array_iterator,
    5045  last.m_it.array_iterator);
    5046  return result;
    5047  }
    5048 
    5073  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    5074  {
    5075  // insert only works for arrays
    5076  if (not is_array())
    5077  {
    5078  throw std::domain_error("cannot use insert() with " + type_name());
    5079  }
    5080 
    5081  // check if iterator pos fits to this JSON value
    5082  if (pos.m_object != this)
    5083  {
    5084  throw std::domain_error("iterator does not fit current value");
    5085  }
    5086 
    5087  // insert to array and return iterator
    5088  iterator result(this);
    5089  assert(m_value.array != nullptr);
    5090  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    5091  return result;
    5092  }
    5093 
    5111  void swap(reference other) noexcept (
    5112  std::is_nothrow_move_constructible<value_t>::value and
    5113  std::is_nothrow_move_assignable<value_t>::value and
    5114  std::is_nothrow_move_constructible<json_value>::value and
    5115  std::is_nothrow_move_assignable<json_value>::value
    5116  )
    5117  {
    5118  std::swap(m_type, other.m_type);
    5119  std::swap(m_value, other.m_value);
    5120  }
    5121 
    5142  void swap(array_t& other)
    5143  {
    5144  // swap only works for arrays
    5145  if (is_array())
    5146  {
    5147  assert(m_value.array != nullptr);
    5148  std::swap(*(m_value.array), other);
    5149  }
    5150  else
    5151  {
    5152  throw std::domain_error("cannot use swap() with " + type_name());
    5153  }
    5154  }
    5155 
    5176  void swap(object_t& other)
    5177  {
    5178  // swap only works for objects
    5179  if (is_object())
    5180  {
    5181  assert(m_value.object != nullptr);
    5182  std::swap(*(m_value.object), other);
    5183  }
    5184  else
    5185  {
    5186  throw std::domain_error("cannot use swap() with " + type_name());
    5187  }
    5188  }
    5189 
    5210  void swap(string_t& other)
    5211  {
    5212  // swap only works for strings
    5213  if (is_string())
    5214  {
    5215  assert(m_value.string != nullptr);
    5216  std::swap(*(m_value.string), other);
    5217  }
    5218  else
    5219  {
    5220  throw std::domain_error("cannot use swap() with " + type_name());
    5221  }
    5222  }
    5223 
    5225 
    5226 
    5228  // lexicographical comparison operators //
    5230 
    5233 
    5234  private:
    5244  friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    5245  {
    5246  static constexpr std::array<uint8_t, 8> order = {{
    5247  0, // null
    5248  3, // object
    5249  4, // array
    5250  5, // string
    5251  1, // boolean
    5252  2, // integer
    5253  2, // unsigned
    5254  2, // float
    5255  }
    5256  };
    5257 
    5258  // discarded values are not comparable
    5259  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5260  {
    5261  return false;
    5262  }
    5263 
    5264  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5265  }
    5266 
    5267  public:
    5291  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5292  {
    5293  const auto lhs_type = lhs.type();
    5294  const auto rhs_type = rhs.type();
    5295 
    5296  if (lhs_type == rhs_type)
    5297  {
    5298  switch (lhs_type)
    5299  {
    5300  case value_t::array:
    5301  {
    5302  assert(lhs.m_value.array != nullptr);
    5303  assert(rhs.m_value.array != nullptr);
    5304  return *lhs.m_value.array == *rhs.m_value.array;
    5305  }
    5306  case value_t::object:
    5307  {
    5308  assert(lhs.m_value.object != nullptr);
    5309  assert(rhs.m_value.object != nullptr);
    5310  return *lhs.m_value.object == *rhs.m_value.object;
    5311  }
    5312  case value_t::null:
    5313  {
    5314  return true;
    5315  }
    5316  case value_t::string:
    5317  {
    5318  assert(lhs.m_value.string != nullptr);
    5319  assert(rhs.m_value.string != nullptr);
    5320  return *lhs.m_value.string == *rhs.m_value.string;
    5321  }
    5322  case value_t::boolean:
    5323  {
    5324  return lhs.m_value.boolean == rhs.m_value.boolean;
    5325  }
    5326  case value_t::number_integer:
    5327  {
    5328  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5329  }
    5330  case value_t::number_unsigned:
    5331  {
    5332  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5333  }
    5334  case value_t::number_float:
    5335  {
    5336  return lhs.m_value.number_float == rhs.m_value.number_float;
    5337  }
    5338  default:
    5339  {
    5340  return false;
    5341  }
    5342  }
    5343  }
    5344  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5345  {
    5346  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5347  }
    5348  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5349  {
    5350  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5351  }
    5352  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5353  {
    5354  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5355  }
    5356  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5357  {
    5358  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5359  }
    5360  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5361  {
    5362  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5363  }
    5364  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5365  {
    5366  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5367  }
    5368 
    5369  return false;
    5370  }
    5371 
    5390  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5391  {
    5392  return v.is_null();
    5393  }
    5394 
    5399  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5400  {
    5401  return v.is_null();
    5402  }
    5403 
    5420  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5421  {
    5422  return not (lhs == rhs);
    5423  }
    5424 
    5443  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5444  {
    5445  return not v.is_null();
    5446  }
    5447 
    5452  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5453  {
    5454  return not v.is_null();
    5455  }
    5456 
    5481  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5482  {
    5483  const auto lhs_type = lhs.type();
    5484  const auto rhs_type = rhs.type();
    5485 
    5486  if (lhs_type == rhs_type)
    5487  {
    5488  switch (lhs_type)
    5489  {
    5490  case value_t::array:
    5491  {
    5492  assert(lhs.m_value.array != nullptr);
    5493  assert(rhs.m_value.array != nullptr);
    5494  return *lhs.m_value.array < *rhs.m_value.array;
    5495  }
    5496  case value_t::object:
    5497  {
    5498  assert(lhs.m_value.object != nullptr);
    5499  assert(rhs.m_value.object != nullptr);
    5500  return *lhs.m_value.object < *rhs.m_value.object;
    5501  }
    5502  case value_t::null:
    5503  {
    5504  return false;
    5505  }
    5506  case value_t::string:
    5507  {
    5508  assert(lhs.m_value.string != nullptr);
    5509  assert(rhs.m_value.string != nullptr);
    5510  return *lhs.m_value.string < *rhs.m_value.string;
    5511  }
    5512  case value_t::boolean:
    5513  {
    5514  return lhs.m_value.boolean < rhs.m_value.boolean;
    5515  }
    5516  case value_t::number_integer:
    5517  {
    5518  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5519  }
    5520  case value_t::number_unsigned:
    5521  {
    5522  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5523  }
    5524  case value_t::number_float:
    5525  {
    5526  return lhs.m_value.number_float < rhs.m_value.number_float;
    5527  }
    5528  default:
    5529  {
    5530  return false;
    5531  }
    5532  }
    5533  }
    5534  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5535  {
    5536  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5537  }
    5538  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5539  {
    5540  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5541  }
    5542  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5543  {
    5544  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5545  }
    5546  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5547  {
    5548  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5549  }
    5550  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5551  {
    5552  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5553  }
    5554  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5555  {
    5556  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5557  }
    5558 
    5559  // We only reach this line if we cannot compare values. In that case,
    5560  // we compare types. Note we have to call the operator explicitly,
    5561  // because MSVC has problems otherwise.
    5562  return operator<(lhs_type, rhs_type);
    5563  }
    5564 
    5582  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5583  {
    5584  return not (rhs < lhs);
    5585  }
    5586 
    5604  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5605  {
    5606  return not (lhs <= rhs);
    5607  }
    5608 
    5626  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5627  {
    5628  return not (lhs < rhs);
    5629  }
    5630 
    5632 
    5633 
    5635  // serialization //
    5637 
    5640 
    5663  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5664  {
    5665  // read width member and use it as indentation parameter if nonzero
    5666  const bool pretty_print = (o.width() > 0);
    5667  const auto indentation = (pretty_print ? o.width() : 0);
    5668 
    5669  // reset width to 0 for subsequent calls to this stream
    5670  o.width(0);
    5671 
    5672  // do the actual serialization
    5673  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5674  return o;
    5675  }
    5676 
    5681  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5682  {
    5683  return o << j;
    5684  }
    5685 
    5687 
    5688 
    5690  // deserialization //
    5692 
    5695 
    5720  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5721  {
    5722  return parser(s, cb).parse();
    5723  }
    5724 
    5749  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5750  {
    5751  return parser(i, cb).parse();
    5752  }
    5753 
    5757  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5758  {
    5759  return parser(i, cb).parse();
    5760  }
    5761 
    5785  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5786  {
    5787  j = parser(i).parse();
    5788  return i;
    5789  }
    5790 
    5795  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5796  {
    5797  j = parser(i).parse();
    5798  return i;
    5799  }
    5800 
    5802 
    5803 
    5804  private:
    5806  // convenience functions //
    5808 
    5810  string_t type_name() const noexcept
    5811  {
    5812  switch (m_type)
    5813  {
    5814  case value_t::null:
    5815  return "null";
    5816  case value_t::object:
    5817  return "object";
    5818  case value_t::array:
    5819  return "array";
    5820  case value_t::string:
    5821  return "string";
    5822  case value_t::boolean:
    5823  return "boolean";
    5824  case value_t::discarded:
    5825  return "discarded";
    5826  default:
    5827  return "number";
    5828  }
    5829  }
    5830 
    5839  static std::size_t extra_space(const string_t& s) noexcept
    5840  {
    5841  std::size_t result = 0;
    5842 
    5843  for (const auto& c : s)
    5844  {
    5845  switch (c)
    5846  {
    5847  case '"':
    5848  case '\\':
    5849  case '\b':
    5850  case '\f':
    5851  case '\n':
    5852  case '\r':
    5853  case '\t':
    5854  {
    5855  // from c (1 byte) to \x (2 bytes)
    5856  result += 1;
    5857  break;
    5858  }
    5859 
    5860  default:
    5861  {
    5862  if (c >= 0x00 and c <= 0x1f)
    5863  {
    5864  // from c (1 byte) to \uxxxx (6 bytes)
    5865  result += 5;
    5866  }
    5867  break;
    5868  }
    5869  }
    5870  }
    5871 
    5872  return result;
    5873  }
    5874 
    5888  static string_t escape_string(const string_t& s)
    5889  {
    5890  const auto space = extra_space(s);
    5891  if (space == 0)
    5892  {
    5893  return s;
    5894  }
    5895 
    5896  // create a result string of necessary size
    5897  string_t result(s.size() + space, '\\');
    5898  std::size_t pos = 0;
    5899 
    5900  for (const auto& c : s)
    5901  {
    5902  switch (c)
    5903  {
    5904  // quotation mark (0x22)
    5905  case '"':
    5906  {
    5907  result[pos + 1] = '"';
    5908  pos += 2;
    5909  break;
    5910  }
    5911 
    5912  // reverse solidus (0x5c)
    5913  case '\\':
    5914  {
    5915  // nothing to change
    5916  pos += 2;
    5917  break;
    5918  }
    5919 
    5920  // backspace (0x08)
    5921  case '\b':
    5922  {
    5923  result[pos + 1] = 'b';
    5924  pos += 2;
    5925  break;
    5926  }
    5927 
    5928  // formfeed (0x0c)
    5929  case '\f':
    5930  {
    5931  result[pos + 1] = 'f';
    5932  pos += 2;
    5933  break;
    5934  }
    5935 
    5936  // newline (0x0a)
    5937  case '\n':
    5938  {
    5939  result[pos + 1] = 'n';
    5940  pos += 2;
    5941  break;
    5942  }
    5943 
    5944  // carriage return (0x0d)
    5945  case '\r':
    5946  {
    5947  result[pos + 1] = 'r';
    5948  pos += 2;
    5949  break;
    5950  }
    5951 
    5952  // horizontal tab (0x09)
    5953  case '\t':
    5954  {
    5955  result[pos + 1] = 't';
    5956  pos += 2;
    5957  break;
    5958  }
    5959 
    5960  default:
    5961  {
    5962  if (c >= 0x00 and c <= 0x1f)
    5963  {
    5964  // convert a number 0..15 to its hex representation
    5965  // (0..f)
    5966  auto hexify = [](const char v) -> char
    5967  {
    5968  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    5969  };
    5970 
    5971  // print character c as \uxxxx
    5972  for (const char m :
    5973  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    5974  })
    5975  {
    5976  result[++pos] = m;
    5977  }
    5978 
    5979  ++pos;
    5980  }
    5981  else
    5982  {
    5983  // all other characters are added as-is
    5984  result[pos++] = c;
    5985  }
    5986  break;
    5987  }
    5988  }
    5989  }
    5990 
    5991  return result;
    5992  }
    5993 
    6011  void dump(std::ostream& o,
    6012  const bool pretty_print,
    6013  const unsigned int indent_step,
    6014  const unsigned int current_indent = 0) const
    6015  {
    6016  // variable to hold indentation for recursive calls
    6017  unsigned int new_indent = current_indent;
    6018 
    6019  switch (m_type)
    6020  {
    6021  case value_t::object:
    6022  {
    6023  assert(m_value.object != nullptr);
    6024 
    6025  if (m_value.object->empty())
    6026  {
    6027  o << "{}";
    6028  return;
    6029  }
    6030 
    6031  o << "{";
    6032 
    6033  // increase indentation
    6034  if (pretty_print)
    6035  {
    6036  new_indent += indent_step;
    6037  o << "\n";
    6038  }
    6039 
    6040  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    6041  {
    6042  if (i != m_value.object->cbegin())
    6043  {
    6044  o << (pretty_print ? ",\n" : ",");
    6045  }
    6046  o << string_t(new_indent, ' ') << "\""
    6047  << escape_string(i->first) << "\":"
    6048  << (pretty_print ? " " : "");
    6049  i->second.dump(o, pretty_print, indent_step, new_indent);
    6050  }
    6051 
    6052  // decrease indentation
    6053  if (pretty_print)
    6054  {
    6055  new_indent -= indent_step;
    6056  o << "\n";
    6057  }
    6058 
    6059  o << string_t(new_indent, ' ') + "}";
    6060  return;
    6061  }
    6062 
    6063  case value_t::array:
    6064  {
    6065  assert(m_value.array != nullptr);
    6066 
    6067  if (m_value.array->empty())
    6068  {
    6069  o << "[]";
    6070  return;
    6071  }
    6072 
    6073  o << "[";
    6074 
    6075  // increase indentation
    6076  if (pretty_print)
    6077  {
    6078  new_indent += indent_step;
    6079  o << "\n";
    6080  }
    6081 
    6082  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    6083  {
    6084  if (i != m_value.array->cbegin())
    6085  {
    6086  o << (pretty_print ? ",\n" : ",");
    6087  }
    6088  o << string_t(new_indent, ' ');
    6089  i->dump(o, pretty_print, indent_step, new_indent);
    6090  }
    6091 
    6092  // decrease indentation
    6093  if (pretty_print)
    6094  {
    6095  new_indent -= indent_step;
    6096  o << "\n";
    6097  }
    6098 
    6099  o << string_t(new_indent, ' ') << "]";
    6100  return;
    6101  }
    6102 
    6103  case value_t::string:
    6104  {
    6105  assert(m_value.string != nullptr);
    6106  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    6107  return;
    6108  }
    6109 
    6110  case value_t::boolean:
    6111  {
    6112  o << (m_value.boolean ? "true" : "false");
    6113  return;
    6114  }
    6115 
    6116  case value_t::number_integer:
    6117  {
    6118  o << m_value.number_integer;
    6119  return;
    6120  }
    6121 
    6122  case value_t::number_unsigned:
    6123  {
    6124  o << m_value.number_unsigned;
    6125  return;
    6126  }
    6127 
    6128  case value_t::number_float:
    6129  {
    6130  // check if number was parsed from a string
    6131  if (m_type.bits.parsed)
    6132  {
    6133  // check if parsed number had an exponent given
    6134  if (m_type.bits.has_exp)
    6135  {
    6136  // buffer size: precision (2^8-1 = 255) + other ('-.e-xxx' = 7) + null (1)
    6137  char buf[263];
    6138  int len;
    6139 
    6140  // handle capitalization of the exponent
    6141  if (m_type.bits.exp_cap)
    6142  {
    6143  len = snprintf(buf, sizeof(buf), "%.*E",
    6144  m_type.bits.precision, m_value.number_float) + 1;
    6145  }
    6146  else
    6147  {
    6148  len = snprintf(buf, sizeof(buf), "%.*e",
    6149  m_type.bits.precision, m_value.number_float) + 1;
    6150  }
    6151 
    6152  // remove '+' sign from the exponent if necessary
    6153  if (not m_type.bits.exp_plus)
    6154  {
    6155  if (len > static_cast<int>(sizeof(buf)))
    6156  {
    6157  len = sizeof(buf);
    6158  }
    6159  for (int i = 0; i < len; i++)
    6160  {
    6161  if (buf[i] == '+')
    6162  {
    6163  for (; i + 1 < len; i++)
    6164  {
    6165  buf[i] = buf[i + 1];
    6166  }
    6167  }
    6168  }
    6169  }
    6170 
    6171  o << buf;
    6172  }
    6173  else
    6174  {
    6175  // no exponent - output as a decimal
    6176  std::stringstream ss;
    6177  ss.imbue(std::locale(std::locale(), new DecimalSeparator)); // fix locale problems
    6178  ss << std::setprecision(m_type.bits.precision)
    6179  << std::fixed << m_value.number_float;
    6180  o << ss.str();
    6181  }
    6182  }
    6183  else
    6184  {
    6185  if (m_value.number_float == 0)
    6186  {
    6187  // special case for zero to get "0.0"/"-0.0"
    6188  o << (std::signbit(m_value.number_float) ? "-0.0" : "0.0");
    6189  }
    6190  else
    6191  {
    6192  // Otherwise 6, 15 or 16 digits of precision allows
    6193  // round-trip IEEE 754 string->float->string,
    6194  // string->double->string or string->long double->string;
    6195  // to be safe, we read this value from
    6196  // std::numeric_limits<number_float_t>::digits10
    6197  std::stringstream ss;
    6198  ss.imbue(std::locale(std::locale(), new DecimalSeparator)); // fix locale problems
    6199  ss << std::setprecision(std::numeric_limits<double>::digits10)
    6200  << m_value.number_float;
    6201  o << ss.str();
    6202  }
    6203  }
    6204  return;
    6205  }
    6206 
    6207  case value_t::discarded:
    6208  {
    6209  o << "<discarded>";
    6210  return;
    6211  }
    6212 
    6213  case value_t::null:
    6214  {
    6215  o << "null";
    6216  return;
    6217  }
    6218  }
    6219  }
    6220 
    6221  private:
    6223  // member variables //
    6225 
    6227  type_data_t m_type = value_t::null;
    6228 
    6230  json_value m_value = {};
    6231 
    6232 
    6233  private:
    6235  // iterators //
    6237 
    6247  class primitive_iterator_t
    6248  {
    6249  public:
    6251  void set_begin() noexcept
    6252  {
    6253  m_it = begin_value;
    6254  }
    6255 
    6257  void set_end() noexcept
    6258  {
    6259  m_it = end_value;
    6260  }
    6261 
    6263  constexpr bool is_begin() const noexcept
    6264  {
    6265  return (m_it == begin_value);
    6266  }
    6267 
    6269  constexpr bool is_end() const noexcept
    6270  {
    6271  return (m_it == end_value);
    6272  }
    6273 
    6275  operator difference_type& () noexcept
    6276  {
    6277  return m_it;
    6278  }
    6279 
    6281  constexpr operator difference_type () const noexcept
    6282  {
    6283  return m_it;
    6284  }
    6285 
    6286  private:
    6287  static constexpr difference_type begin_value = 0;
    6288  static constexpr difference_type end_value = begin_value + 1;
    6289 
    6291  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    6292  };
    6293 
    6301  struct internal_iterator
    6302  {
    6304  typename object_t::iterator object_iterator;
    6306  typename array_t::iterator array_iterator;
    6308  primitive_iterator_t primitive_iterator;
    6309 
    6311  internal_iterator() noexcept
    6312  : object_iterator(), array_iterator(), primitive_iterator()
    6313  {}
    6314  };
    6315 
    6317  template<typename IteratorType>
    6318  class iteration_proxy
    6319  {
    6320  private:
    6322  class iteration_proxy_internal
    6323  {
    6324  private:
    6326  IteratorType anchor;
    6328  size_t array_index = 0;
    6329 
    6330  public:
    6331  explicit iteration_proxy_internal(IteratorType it) noexcept
    6332  : anchor(it)
    6333  {}
    6334 
    6336  iteration_proxy_internal& operator*()
    6337  {
    6338  return *this;
    6339  }
    6340 
    6342  iteration_proxy_internal& operator++()
    6343  {
    6344  ++anchor;
    6345  ++array_index;
    6346 
    6347  return *this;
    6348  }
    6349 
    6351  bool operator!= (const iteration_proxy_internal& o) const
    6352  {
    6353  return anchor != o.anchor;
    6354  }
    6355 
    6357  typename basic_json::string_t key() const
    6358  {
    6359  assert(anchor.m_object != nullptr);
    6360 
    6361  switch (anchor.m_object->type())
    6362  {
    6363  // use integer array index as key
    6364  case value_t::array:
    6365  {
    6366  return std::to_string(array_index);
    6367  }
    6368 
    6369  // use key from the object
    6370  case value_t::object:
    6371  {
    6372  return anchor.key();
    6373  }
    6374 
    6375  // use an empty key for all primitive types
    6376  default:
    6377  {
    6378  return "";
    6379  }
    6380  }
    6381  }
    6382 
    6384  typename IteratorType::reference value() const
    6385  {
    6386  return anchor.value();
    6387  }
    6388  };
    6389 
    6391  typename IteratorType::reference container;
    6392 
    6393  public:
    6395  explicit iteration_proxy(typename IteratorType::reference cont)
    6396  : container(cont)
    6397  {}
    6398 
    6400  iteration_proxy_internal begin() noexcept
    6401  {
    6402  return iteration_proxy_internal(container.begin());
    6403  }
    6404 
    6406  iteration_proxy_internal end() noexcept
    6407  {
    6408  return iteration_proxy_internal(container.end());
    6409  }
    6410  };
    6411 
    6412  public:
    6426  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6427  {
    6429  friend class basic_json;
    6430 
    6431  public:
    6441  using iterator_category = std::bidirectional_iterator_tag;
    6442 
    6444  const_iterator() = default;
    6445 
    6447  explicit const_iterator(pointer object) noexcept
    6448  : m_object(object)
    6449  {
    6450  assert(m_object != nullptr);
    6451 
    6452  switch (m_object->m_type)
    6453  {
    6455  {
    6456  m_it.object_iterator = typename object_t::iterator();
    6457  break;
    6458  }
    6459 
    6461  {
    6462  m_it.array_iterator = typename array_t::iterator();
    6463  break;
    6464  }
    6465 
    6466  default:
    6467  {
    6468  m_it.primitive_iterator = primitive_iterator_t();
    6469  break;
    6470  }
    6471  }
    6472  }
    6473 
    6475  explicit const_iterator(const iterator& other) noexcept
    6476  : m_object(other.m_object)
    6477  {
    6478  assert(m_object != nullptr);
    6479 
    6480  switch (m_object->m_type)
    6481  {
    6483  {
    6484  m_it.object_iterator = other.m_it.object_iterator;
    6485  break;
    6486  }
    6487 
    6489  {
    6490  m_it.array_iterator = other.m_it.array_iterator;
    6491  break;
    6492  }
    6493 
    6494  default:
    6495  {
    6496  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6497  break;
    6498  }
    6499  }
    6500  }
    6501 
    6503  const_iterator(const const_iterator& other) noexcept
    6504  : m_object(other.m_object), m_it(other.m_it)
    6505  {}
    6506 
    6509  std::is_nothrow_move_constructible<pointer>::value and
    6510  std::is_nothrow_move_assignable<pointer>::value and
    6511  std::is_nothrow_move_constructible<internal_iterator>::value and
    6512  std::is_nothrow_move_assignable<internal_iterator>::value
    6513  )
    6514  {
    6515  std::swap(m_object, other.m_object);
    6516  std::swap(m_it, other.m_it);
    6517  return *this;
    6518  }
    6519 
    6520  private:
    6522  void set_begin() noexcept
    6523  {
    6524  assert(m_object != nullptr);
    6525 
    6526  switch (m_object->m_type)
    6527  {
    6529  {
    6530  assert(m_object->m_value.object != nullptr);
    6531  m_it.object_iterator = m_object->m_value.object->begin();
    6532  break;
    6533  }
    6534 
    6536  {
    6537  assert(m_object->m_value.array != nullptr);
    6538  m_it.array_iterator = m_object->m_value.array->begin();
    6539  break;
    6540  }
    6541 
    6543  {
    6544  // set to end so begin()==end() is true: null is empty
    6545  m_it.primitive_iterator.set_end();
    6546  break;
    6547  }
    6548 
    6549  default:
    6550  {
    6551  m_it.primitive_iterator.set_begin();
    6552  break;
    6553  }
    6554  }
    6555  }
    6556 
    6558  void set_end() noexcept
    6559  {
    6560  assert(m_object != nullptr);
    6561 
    6562  switch (m_object->m_type)
    6563  {
    6565  {
    6566  assert(m_object->m_value.object != nullptr);
    6567  m_it.object_iterator = m_object->m_value.object->end();
    6568  break;
    6569  }
    6570 
    6572  {
    6573  assert(m_object->m_value.array != nullptr);
    6574  m_it.array_iterator = m_object->m_value.array->end();
    6575  break;
    6576  }
    6577 
    6578  default:
    6579  {
    6580  m_it.primitive_iterator.set_end();
    6581  break;
    6582  }
    6583  }
    6584  }
    6585 
    6586  public:
    6589  {
    6590  assert(m_object != nullptr);
    6591 
    6592  switch (m_object->m_type)
    6593  {
    6595  {
    6596  assert(m_object->m_value.object);
    6597  assert(m_it.object_iterator != m_object->m_value.object->end());
    6598  return m_it.object_iterator->second;
    6599  }
    6600 
    6602  {
    6603  assert(m_object->m_value.array);
    6604  assert(m_it.array_iterator != m_object->m_value.array->end());
    6605  return *m_it.array_iterator;
    6606  }
    6607 
    6609  {
    6610  throw std::out_of_range("cannot get value");
    6611  }
    6612 
    6613  default:
    6614  {
    6615  if (m_it.primitive_iterator.is_begin())
    6616  {
    6617  return *m_object;
    6618  }
    6619  else
    6620  {
    6621  throw std::out_of_range("cannot get value");
    6622  }
    6623  }
    6624  }
    6625  }
    6626 
    6629  {
    6630  assert(m_object != nullptr);
    6631 
    6632  switch (m_object->m_type)
    6633  {
    6635  {
    6636  assert(m_object->m_value.object);
    6637  assert(m_it.object_iterator != m_object->m_value.object->end());
    6638  return &(m_it.object_iterator->second);
    6639  }
    6640 
    6642  {
    6643  assert(m_object->m_value.array);
    6644  assert(m_it.array_iterator != m_object->m_value.array->end());
    6645  return &*m_it.array_iterator;
    6646  }
    6647 
    6648  default:
    6649  {
    6650  if (m_it.primitive_iterator.is_begin())
    6651  {
    6652  return m_object;
    6653  }
    6654  else
    6655  {
    6656  throw std::out_of_range("cannot get value");
    6657  }
    6658  }
    6659  }
    6660  }
    6661 
    6664  {
    6665  auto result = *this;
    6666  ++(*this);
    6667  return result;
    6668  }
    6669 
    6672  {
    6673  assert(m_object != nullptr);
    6674 
    6675  switch (m_object->m_type)
    6676  {
    6678  {
    6679  ++m_it.object_iterator;
    6680  break;
    6681  }
    6682 
    6684  {
    6685  ++m_it.array_iterator;
    6686  break;
    6687  }
    6688 
    6689  default:
    6690  {
    6691  ++m_it.primitive_iterator;
    6692  break;
    6693  }
    6694  }
    6695 
    6696  return *this;
    6697  }
    6698 
    6701  {
    6702  auto result = *this;
    6703  --(*this);
    6704  return result;
    6705  }
    6706 
    6709  {
    6710  assert(m_object != nullptr);
    6711 
    6712  switch (m_object->m_type)
    6713  {
    6715  {
    6716  --m_it.object_iterator;
    6717  break;
    6718  }
    6719 
    6721  {
    6722  --m_it.array_iterator;
    6723  break;
    6724  }
    6725 
    6726  default:
    6727  {
    6728  --m_it.primitive_iterator;
    6729  break;
    6730  }
    6731  }
    6732 
    6733  return *this;
    6734  }
    6735 
    6737  bool operator==(const const_iterator& other) const
    6738  {
    6739  // if objects are not the same, the comparison is undefined
    6740  if (m_object != other.m_object)
    6741  {
    6742  throw std::domain_error("cannot compare iterators of different containers");
    6743  }
    6744 
    6745  assert(m_object != nullptr);
    6746 
    6747  switch (m_object->m_type)
    6748  {
    6750  {
    6751  return (m_it.object_iterator == other.m_it.object_iterator);
    6752  }
    6753 
    6755  {
    6756  return (m_it.array_iterator == other.m_it.array_iterator);
    6757  }
    6758 
    6759  default:
    6760  {
    6761  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6762  }
    6763  }
    6764  }
    6765 
    6767  bool operator!=(const const_iterator& other) const
    6768  {
    6769  return not operator==(other);
    6770  }
    6771 
    6773  bool operator<(const const_iterator& other) const
    6774  {
    6775  // if objects are not the same, the comparison is undefined
    6776  if (m_object != other.m_object)
    6777  {
    6778  throw std::domain_error("cannot compare iterators of different containers");
    6779  }
    6780 
    6781  assert(m_object != nullptr);
    6782 
    6783  switch (m_object->m_type)
    6784  {
    6786  {
    6787  throw std::domain_error("cannot compare order of object iterators");
    6788  }
    6789 
    6791  {
    6792  return (m_it.array_iterator < other.m_it.array_iterator);
    6793  }
    6794 
    6795  default:
    6796  {
    6797  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6798  }
    6799  }
    6800  }
    6801 
    6803  bool operator<=(const const_iterator& other) const
    6804  {
    6805  return not other.operator < (*this);
    6806  }
    6807 
    6809  bool operator>(const const_iterator& other) const
    6810  {
    6811  return not operator<=(other);
    6812  }
    6813 
    6815  bool operator>=(const const_iterator& other) const
    6816  {
    6817  return not operator<(other);
    6818  }
    6819 
    6822  {
    6823  assert(m_object != nullptr);
    6824 
    6825  switch (m_object->m_type)
    6826  {
    6828  {
    6829  throw std::domain_error("cannot use offsets with object iterators");
    6830  }
    6831 
    6833  {
    6834  m_it.array_iterator += i;
    6835  break;
    6836  }
    6837 
    6838  default:
    6839  {
    6840  m_it.primitive_iterator += i;
    6841  break;
    6842  }
    6843  }
    6844 
    6845  return *this;
    6846  }
    6847 
    6850  {
    6851  return operator+=(-i);
    6852  }
    6853 
    6856  {
    6857  auto result = *this;
    6858  result += i;
    6859  return result;
    6860  }
    6861 
    6864  {
    6865  auto result = *this;
    6866  result -= i;
    6867  return result;
    6868  }
    6869 
    6872  {
    6873  assert(m_object != nullptr);
    6874 
    6875  switch (m_object->m_type)
    6876  {
    6878  {
    6879  throw std::domain_error("cannot use offsets with object iterators");
    6880  }
    6881 
    6883  {
    6884  return m_it.array_iterator - other.m_it.array_iterator;
    6885  }
    6886 
    6887  default:
    6888  {
    6889  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6890  }
    6891  }
    6892  }
    6893 
    6896  {
    6897  assert(m_object != nullptr);
    6898 
    6899  switch (m_object->m_type)
    6900  {
    6902  {
    6903  throw std::domain_error("cannot use operator[] for object iterators");
    6904  }
    6905 
    6907  {
    6908  return *(m_it.array_iterator + n);
    6909  }
    6910 
    6912  {
    6913  throw std::out_of_range("cannot get value");
    6914  }
    6915 
    6916  default:
    6917  {
    6918  if (m_it.primitive_iterator == -n)
    6919  {
    6920  return *m_object;
    6921  }
    6922  else
    6923  {
    6924  throw std::out_of_range("cannot get value");
    6925  }
    6926  }
    6927  }
    6928  }
    6929 
    6931  typename object_t::key_type key() const
    6932  {
    6933  assert(m_object != nullptr);
    6934 
    6935  if (m_object->is_object())
    6936  {
    6937  return m_it.object_iterator->first;
    6938  }
    6939  else
    6940  {
    6941  throw std::domain_error("cannot use key() for non-object iterators");
    6942  }
    6943  }
    6944 
    6947  {
    6948  return operator*();
    6949  }
    6950 
    6951  private:
    6953  pointer m_object = nullptr;
    6955  internal_iterator m_it = internal_iterator();
    6956  };
    6957 
    6970  class iterator : public const_iterator
    6971  {
    6972  public:
    6974  using pointer = typename basic_json::pointer;
    6976 
    6978  iterator() = default;
    6979 
    6981  explicit iterator(pointer object) noexcept
    6982  : base_iterator(object)
    6983  {}
    6984 
    6986  iterator(const iterator& other) noexcept
    6987  : base_iterator(other)
    6988  {}
    6989 
    6991  iterator& operator=(iterator other) noexcept(
    6992  std::is_nothrow_move_constructible<pointer>::value and
    6993  std::is_nothrow_move_assignable<pointer>::value and
    6994  std::is_nothrow_move_constructible<internal_iterator>::value and
    6995  std::is_nothrow_move_assignable<internal_iterator>::value
    6996  )
    6997  {
    6998  base_iterator::operator=(other);
    6999  return *this;
    7000  }
    7001 
    7004  {
    7005  return const_cast<reference>(base_iterator::operator*());
    7006  }
    7007 
    7010  {
    7011  return const_cast<pointer>(base_iterator::operator->());
    7012  }
    7013 
    7016  {
    7017  iterator result = *this;
    7018  base_iterator::operator++();
    7019  return result;
    7020  }
    7021 
    7024  {
    7025  base_iterator::operator++();
    7026  return *this;
    7027  }
    7028 
    7031  {
    7032  iterator result = *this;
    7033  base_iterator::operator--();
    7034  return result;
    7035  }
    7036 
    7039  {
    7040  base_iterator::operator--();
    7041  return *this;
    7042  }
    7043 
    7046  {
    7047  base_iterator::operator+=(i);
    7048  return *this;
    7049  }
    7050 
    7053  {
    7054  base_iterator::operator-=(i);
    7055  return *this;
    7056  }
    7057 
    7060  {
    7061  auto result = *this;
    7062  result += i;
    7063  return result;
    7064  }
    7065 
    7068  {
    7069  auto result = *this;
    7070  result -= i;
    7071  return result;
    7072  }
    7073 
    7075  difference_type operator-(const iterator& other) const
    7076  {
    7077  return base_iterator::operator-(other);
    7078  }
    7079 
    7082  {
    7083  return const_cast<reference>(base_iterator::operator[](n));
    7084  }
    7085 
    7088  {
    7089  return const_cast<reference>(base_iterator::value());
    7090  }
    7091  };
    7092 
    7110  template<typename Base>
    7111  class json_reverse_iterator : public std::reverse_iterator<Base>
    7112  {
    7113  public:
    7115  using base_iterator = std::reverse_iterator<Base>;
    7117  using reference = typename Base::reference;
    7118 
    7120  json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
    7121  : base_iterator(it)
    7122  {}
    7123 
    7126  : base_iterator(it)
    7127  {}
    7128 
    7131  {
    7132  return base_iterator::operator++(1);
    7133  }
    7134 
    7137  {
    7138  base_iterator::operator++();
    7139  return *this;
    7140  }
    7141 
    7144  {
    7145  return base_iterator::operator--(1);
    7146  }
    7147 
    7150  {
    7151  base_iterator::operator--();
    7152  return *this;
    7153  }
    7154 
    7157  {
    7158  base_iterator::operator+=(i);
    7159  return *this;
    7160  }
    7161 
    7164  {
    7165  auto result = *this;
    7166  result += i;
    7167  return result;
    7168  }
    7169 
    7172  {
    7173  auto result = *this;
    7174  result -= i;
    7175  return result;
    7176  }
    7177 
    7180  {
    7181  return this->base() - other.base();
    7182  }
    7183 
    7186  {
    7187  return *(this->operator+(n));
    7188  }
    7189 
    7191  typename object_t::key_type key() const
    7192  {
    7193  auto it = --this->base();
    7194  return it.key();
    7195  }
    7196 
    7199  {
    7200  auto it = --this->base();
    7201  return it.operator * ();
    7202  }
    7203  };
    7204 
    7205 
    7206  private:
    7208  // lexer and parser //
    7210 
    7218  class lexer
    7219  {
    7220  public:
    7222  enum class token_type
    7223  {
    7224  uninitialized,
    7225  literal_true,
    7226  literal_false,
    7227  literal_null,
    7228  value_string,
    7229  value_number,
    7230  begin_array,
    7231  begin_object,
    7232  end_array,
    7233  end_object,
    7234  name_separator,
    7235  value_separator,
    7236  parse_error,
    7237  end_of_input
    7238  };
    7239 
    7241  using lexer_char_t = unsigned char;
    7242 
    7244  explicit lexer(const string_t& s) noexcept
    7245  : m_stream(nullptr), m_buffer(s)
    7246  {
    7247  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    7248  assert(m_content != nullptr);
    7249  m_start = m_cursor = m_content;
    7250  m_limit = m_content + s.size();
    7251  }
    7252 
    7254  explicit lexer(std::istream* s) noexcept
    7255  : m_stream(s), m_buffer()
    7256  {
    7257  assert(m_stream != nullptr);
    7258  getline(*m_stream, m_buffer);
    7259  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7260  assert(m_content != nullptr);
    7261  m_start = m_cursor = m_content;
    7262  m_limit = m_content + m_buffer.size();
    7263  }
    7264 
    7266  lexer() = default;
    7267 
    7268  // switch off unwanted functions
    7269  lexer(const lexer&) = delete;
    7270  lexer operator=(const lexer&) = delete;
    7271 
    7287  static string_t to_unicode(const std::size_t codepoint1,
    7288  const std::size_t codepoint2 = 0)
    7289  {
    7290  // calculate the codepoint from the given code points
    7291  std::size_t codepoint = codepoint1;
    7292 
    7293  // check if codepoint1 is a high surrogate
    7294  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    7295  {
    7296  // check if codepoint2 is a low surrogate
    7297  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    7298  {
    7299  codepoint =
    7300  // high surrogate occupies the most significant 22 bits
    7301  (codepoint1 << 10)
    7302  // low surrogate occupies the least significant 15 bits
    7303  + codepoint2
    7304  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7305  // in the result so we have to subtract with:
    7306  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7307  - 0x35FDC00;
    7308  }
    7309  else
    7310  {
    7311  throw std::invalid_argument("missing or wrong low surrogate");
    7312  }
    7313  }
    7314 
    7315  string_t result;
    7316 
    7317  if (codepoint < 0x80)
    7318  {
    7319  // 1-byte characters: 0xxxxxxx (ASCII)
    7320  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7321  }
    7322  else if (codepoint <= 0x7ff)
    7323  {
    7324  // 2-byte characters: 110xxxxx 10xxxxxx
    7325  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7326  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7327  }
    7328  else if (codepoint <= 0xffff)
    7329  {
    7330  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7331  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7332  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7333  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7334  }
    7335  else if (codepoint <= 0x10ffff)
    7336  {
    7337  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7338  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7339  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7340  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7341  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7342  }
    7343  else
    7344  {
    7345  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7346  }
    7347 
    7348  return result;
    7349  }
    7350 
    7352  static std::string token_type_name(token_type t)
    7353  {
    7354  switch (t)
    7355  {
    7356  case token_type::uninitialized:
    7357  return "<uninitialized>";
    7358  case token_type::literal_true:
    7359  return "true literal";
    7360  case token_type::literal_false:
    7361  return "false literal";
    7362  case token_type::literal_null:
    7363  return "null literal";
    7364  case token_type::value_string:
    7365  return "string literal";
    7366  case token_type::value_number:
    7367  return "number literal";
    7368  case token_type::begin_array:
    7369  return "'['";
    7370  case token_type::begin_object:
    7371  return "'{'";
    7372  case token_type::end_array:
    7373  return "']'";
    7374  case token_type::end_object:
    7375  return "'}'";
    7376  case token_type::name_separator:
    7377  return "':'";
    7378  case token_type::value_separator:
    7379  return "','";
    7380  case token_type::parse_error:
    7381  return "<parse error>";
    7382  case token_type::end_of_input:
    7383  return "end of input";
    7384  default:
    7385  {
    7386  // catch non-enum values
    7387  return "unknown token"; // LCOV_EXCL_LINE
    7388  }
    7389  }
    7390  }
    7391 
    7402  token_type scan() noexcept
    7403  {
    7404  // pointer for backtracking information
    7405  m_marker = nullptr;
    7406 
    7407  // remember the begin of the token
    7408  m_start = m_cursor;
    7409  assert(m_start != nullptr);
    7410 
    7411 
    7412  {
    7413  lexer_char_t yych;
    7414  unsigned int yyaccept = 0;
    7415  static const unsigned char yybm[] =
    7416  {
    7417  0, 0, 0, 0, 0, 0, 0, 0,
    7418  0, 32, 32, 0, 0, 32, 0, 0,
    7419  128, 128, 128, 128, 128, 128, 128, 128,
    7420  128, 128, 128, 128, 128, 128, 128, 128,
    7421  160, 128, 0, 128, 128, 128, 128, 128,
    7422  128, 128, 128, 128, 128, 128, 128, 128,
    7423  192, 192, 192, 192, 192, 192, 192, 192,
    7424  192, 192, 128, 128, 128, 128, 128, 128,
    7425  128, 128, 128, 128, 128, 128, 128, 128,
    7426  128, 128, 128, 128, 128, 128, 128, 128,
    7427  128, 128, 128, 128, 128, 128, 128, 128,
    7428  128, 128, 128, 128, 0, 128, 128, 128,
    7429  128, 128, 128, 128, 128, 128, 128, 128,
    7430  128, 128, 128, 128, 128, 128, 128, 128,
    7431  128, 128, 128, 128, 128, 128, 128, 128,
    7432  128, 128, 128, 128, 128, 128, 128, 128,
    7433  128, 128, 128, 128, 128, 128, 128, 128,
    7434  128, 128, 128, 128, 128, 128, 128, 128,
    7435  128, 128, 128, 128, 128, 128, 128, 128,
    7436  128, 128, 128, 128, 128, 128, 128, 128,
    7437  128, 128, 128, 128, 128, 128, 128, 128,
    7438  128, 128, 128, 128, 128, 128, 128, 128,
    7439  128, 128, 128, 128, 128, 128, 128, 128,
    7440  128, 128, 128, 128, 128, 128, 128, 128,
    7441  128, 128, 128, 128, 128, 128, 128, 128,
    7442  128, 128, 128, 128, 128, 128, 128, 128,
    7443  128, 128, 128, 128, 128, 128, 128, 128,
    7444  128, 128, 128, 128, 128, 128, 128, 128,
    7445  128, 128, 128, 128, 128, 128, 128, 128,
    7446  128, 128, 128, 128, 128, 128, 128, 128,
    7447  128, 128, 128, 128, 128, 128, 128, 128,
    7448  128, 128, 128, 128, 128, 128, 128, 128,
    7449  };
    7450  if ((m_limit - m_cursor) < 5)
    7451  {
    7452  yyfill(); // LCOV_EXCL_LINE;
    7453  }
    7454  yych = *m_cursor;
    7455  if (yybm[0 + yych] & 32)
    7456  {
    7457  goto basic_json_parser_6;
    7458  }
    7459  if (yych <= '\\')
    7460  {
    7461  if (yych <= '-')
    7462  {
    7463  if (yych <= '"')
    7464  {
    7465  if (yych <= 0x00)
    7466  {
    7467  goto basic_json_parser_2;
    7468  }
    7469  if (yych <= '!')
    7470  {
    7471  goto basic_json_parser_4;
    7472  }
    7473  goto basic_json_parser_9;
    7474  }
    7475  else
    7476  {
    7477  if (yych <= '+')
    7478  {
    7479  goto basic_json_parser_4;
    7480  }
    7481  if (yych <= ',')
    7482  {
    7483  goto basic_json_parser_10;
    7484  }
    7485  goto basic_json_parser_12;
    7486  }
    7487  }
    7488  else
    7489  {
    7490  if (yych <= '9')
    7491  {
    7492  if (yych <= '/')
    7493  {
    7494  goto basic_json_parser_4;
    7495  }
    7496  if (yych <= '0')
    7497  {
    7498  goto basic_json_parser_13;
    7499  }
    7500  goto basic_json_parser_15;
    7501  }
    7502  else
    7503  {
    7504  if (yych <= ':')
    7505  {
    7506  goto basic_json_parser_17;
    7507  }
    7508  if (yych == '[')
    7509  {
    7510  goto basic_json_parser_19;
    7511  }
    7512  goto basic_json_parser_4;
    7513  }
    7514  }
    7515  }
    7516  else
    7517  {
    7518  if (yych <= 't')
    7519  {
    7520  if (yych <= 'f')
    7521  {
    7522  if (yych <= ']')
    7523  {
    7524  goto basic_json_parser_21;
    7525  }
    7526  if (yych <= 'e')
    7527  {
    7528  goto basic_json_parser_4;
    7529  }
    7530  goto basic_json_parser_23;
    7531  }
    7532  else
    7533  {
    7534  if (yych == 'n')
    7535  {
    7536  goto basic_json_parser_24;
    7537  }
    7538  if (yych <= 's')
    7539  {
    7540  goto basic_json_parser_4;
    7541  }
    7542  goto basic_json_parser_25;
    7543  }
    7544  }
    7545  else
    7546  {
    7547  if (yych <= '|')
    7548  {
    7549  if (yych == '{')
    7550  {
    7551  goto basic_json_parser_26;
    7552  }
    7553  goto basic_json_parser_4;
    7554  }
    7555  else
    7556  {
    7557  if (yych <= '}')
    7558  {
    7559  goto basic_json_parser_28;
    7560  }
    7561  if (yych == 0xEF)
    7562  {
    7563  goto basic_json_parser_30;
    7564  }
    7565  goto basic_json_parser_4;
    7566  }
    7567  }
    7568  }
    7569 basic_json_parser_2:
    7570  ++m_cursor;
    7571  {
    7572  return token_type::end_of_input;
    7573  }
    7574 basic_json_parser_4:
    7575  ++m_cursor;
    7576 basic_json_parser_5:
    7577  {
    7578  return token_type::parse_error;
    7579  }
    7580 basic_json_parser_6:
    7581  ++m_cursor;
    7582  if (m_limit <= m_cursor)
    7583  {
    7584  yyfill(); // LCOV_EXCL_LINE;
    7585  }
    7586  yych = *m_cursor;
    7587  if (yybm[0 + yych] & 32)
    7588  {
    7589  goto basic_json_parser_6;
    7590  }
    7591  {
    7592  return scan();
    7593  }
    7594 basic_json_parser_9:
    7595  yyaccept = 0;
    7596  yych = *(m_marker = ++m_cursor);
    7597  if (yych <= 0x0F)
    7598  {
    7599  goto basic_json_parser_5;
    7600  }
    7601  goto basic_json_parser_32;
    7602 basic_json_parser_10:
    7603  ++m_cursor;
    7604  {
    7605  return token_type::value_separator;
    7606  }
    7607 basic_json_parser_12:
    7608  yych = *++m_cursor;
    7609  if (yych <= '/')
    7610  {
    7611  goto basic_json_parser_5;
    7612  }
    7613  if (yych <= '0')
    7614  {
    7615  goto basic_json_parser_13;
    7616  }
    7617  if (yych <= '9')
    7618  {
    7619  goto basic_json_parser_15;
    7620  }
    7621  goto basic_json_parser_5;
    7622 basic_json_parser_13:
    7623  yyaccept = 1;
    7624  yych = *(m_marker = ++m_cursor);
    7625  if (yych <= 'D')
    7626  {
    7627  if (yych == '.')
    7628  {
    7629  goto basic_json_parser_37;
    7630  }
    7631  }
    7632  else
    7633  {
    7634  if (yych <= 'E')
    7635  {
    7636  goto basic_json_parser_38;
    7637  }
    7638  if (yych == 'e')
    7639  {
    7640  goto basic_json_parser_38;
    7641  }
    7642  }
    7643 basic_json_parser_14:
    7644  {
    7645  return token_type::value_number;
    7646  }
    7647 basic_json_parser_15:
    7648  yyaccept = 1;
    7649  m_marker = ++m_cursor;
    7650  if ((m_limit - m_cursor) < 3)
    7651  {
    7652  yyfill(); // LCOV_EXCL_LINE;
    7653  }
    7654  yych = *m_cursor;
    7655  if (yybm[0 + yych] & 64)
    7656  {
    7657  goto basic_json_parser_15;
    7658  }
    7659  if (yych <= 'D')
    7660  {
    7661  if (yych == '.')
    7662  {
    7663  goto basic_json_parser_37;
    7664  }
    7665  goto basic_json_parser_14;
    7666  }
    7667  else
    7668  {
    7669  if (yych <= 'E')
    7670  {
    7671  goto basic_json_parser_38;
    7672  }
    7673  if (yych == 'e')
    7674  {
    7675  goto basic_json_parser_38;
    7676  }
    7677  goto basic_json_parser_14;
    7678  }
    7679 basic_json_parser_17:
    7680  ++m_cursor;
    7681  {
    7682  return token_type::name_separator;
    7683  }
    7684 basic_json_parser_19:
    7685  ++m_cursor;
    7686  {
    7687  return token_type::begin_array;
    7688  }
    7689 basic_json_parser_21:
    7690  ++m_cursor;
    7691  {
    7692  return token_type::end_array;
    7693  }
    7694 basic_json_parser_23:
    7695  yyaccept = 0;
    7696  yych = *(m_marker = ++m_cursor);
    7697  if (yych == 'a')
    7698  {
    7699  goto basic_json_parser_39;
    7700  }
    7701  goto basic_json_parser_5;
    7702 basic_json_parser_24:
    7703  yyaccept = 0;
    7704  yych = *(m_marker = ++m_cursor);
    7705  if (yych == 'u')
    7706  {
    7707  goto basic_json_parser_40;
    7708  }
    7709  goto basic_json_parser_5;
    7710 basic_json_parser_25:
    7711  yyaccept = 0;
    7712  yych = *(m_marker = ++m_cursor);
    7713  if (yych == 'r')
    7714  {
    7715  goto basic_json_parser_41;
    7716  }
    7717  goto basic_json_parser_5;
    7718 basic_json_parser_26:
    7719  ++m_cursor;
    7720  {
    7721  return token_type::begin_object;
    7722  }
    7723 basic_json_parser_28:
    7724  ++m_cursor;
    7725  {
    7726  return token_type::end_object;
    7727  }
    7728 basic_json_parser_30:
    7729  yyaccept = 0;
    7730  yych = *(m_marker = ++m_cursor);
    7731  if (yych == 0xBB)
    7732  {
    7733  goto basic_json_parser_42;
    7734  }
    7735  goto basic_json_parser_5;
    7736 basic_json_parser_31:
    7737  ++m_cursor;
    7738  if (m_limit <= m_cursor)
    7739  {
    7740  yyfill(); // LCOV_EXCL_LINE;
    7741  }
    7742  yych = *m_cursor;
    7743 basic_json_parser_32:
    7744  if (yybm[0 + yych] & 128)
    7745  {
    7746  goto basic_json_parser_31;
    7747  }
    7748  if (yych <= 0x0F)
    7749  {
    7750  goto basic_json_parser_33;
    7751  }
    7752  if (yych <= '"')
    7753  {
    7754  goto basic_json_parser_34;
    7755  }
    7756  goto basic_json_parser_36;
    7757 basic_json_parser_33:
    7758  m_cursor = m_marker;
    7759  if (yyaccept == 0)
    7760  {
    7761  goto basic_json_parser_5;
    7762  }
    7763  else
    7764  {
    7765  goto basic_json_parser_14;
    7766  }
    7767 basic_json_parser_34:
    7768  ++m_cursor;
    7769  {
    7770  return token_type::value_string;
    7771  }
    7772 basic_json_parser_36:
    7773  ++m_cursor;
    7774  if (m_limit <= m_cursor)
    7775  {
    7776  yyfill(); // LCOV_EXCL_LINE;
    7777  }
    7778  yych = *m_cursor;
    7779  if (yych <= 'e')
    7780  {
    7781  if (yych <= '/')
    7782  {
    7783  if (yych == '"')
    7784  {
    7785  goto basic_json_parser_31;
    7786  }
    7787  if (yych <= '.')
    7788  {
    7789  goto basic_json_parser_33;
    7790  }
    7791  goto basic_json_parser_31;
    7792  }
    7793  else
    7794  {
    7795  if (yych <= '\\')
    7796  {
    7797  if (yych <= '[')
    7798  {
    7799  goto basic_json_parser_33;
    7800  }
    7801  goto basic_json_parser_31;
    7802  }
    7803  else
    7804  {
    7805  if (yych == 'b')
    7806  {
    7807  goto basic_json_parser_31;
    7808  }
    7809  goto basic_json_parser_33;
    7810  }
    7811  }
    7812  }
    7813  else
    7814  {
    7815  if (yych <= 'q')
    7816  {
    7817  if (yych <= 'f')
    7818  {
    7819  goto basic_json_parser_31;
    7820  }
    7821  if (yych == 'n')
    7822  {
    7823  goto basic_json_parser_31;
    7824  }
    7825  goto basic_json_parser_33;
    7826  }
    7827  else
    7828  {
    7829  if (yych <= 's')
    7830  {
    7831  if (yych <= 'r')
    7832  {
    7833  goto basic_json_parser_31;
    7834  }
    7835  goto basic_json_parser_33;
    7836  }
    7837  else
    7838  {
    7839  if (yych <= 't')
    7840  {
    7841  goto basic_json_parser_31;
    7842  }
    7843  if (yych <= 'u')
    7844  {
    7845  goto basic_json_parser_43;
    7846  }
    7847  goto basic_json_parser_33;
    7848  }
    7849  }
    7850  }
    7851 basic_json_parser_37:
    7852  yych = *++m_cursor;
    7853  if (yych <= '/')
    7854  {
    7855  goto basic_json_parser_33;
    7856  }
    7857  if (yych <= '9')
    7858  {
    7859  goto basic_json_parser_44;
    7860  }
    7861  goto basic_json_parser_33;
    7862 basic_json_parser_38:
    7863  yych = *++m_cursor;
    7864  if (yych <= ',')
    7865  {
    7866  if (yych == '+')
    7867  {
    7868  goto basic_json_parser_46;
    7869  }
    7870  goto basic_json_parser_33;
    7871  }
    7872  else
    7873  {
    7874  if (yych <= '-')
    7875  {
    7876  goto basic_json_parser_46;
    7877  }
    7878  if (yych <= '/')
    7879  {
    7880  goto basic_json_parser_33;
    7881  }
    7882  if (yych <= '9')
    7883  {
    7884  goto basic_json_parser_47;
    7885  }
    7886  goto basic_json_parser_33;
    7887  }
    7888 basic_json_parser_39:
    7889  yych = *++m_cursor;
    7890  if (yych == 'l')
    7891  {
    7892  goto basic_json_parser_49;
    7893  }
    7894  goto basic_json_parser_33;
    7895 basic_json_parser_40:
    7896  yych = *++m_cursor;
    7897  if (yych == 'l')
    7898  {
    7899  goto basic_json_parser_50;
    7900  }
    7901  goto basic_json_parser_33;
    7902 basic_json_parser_41:
    7903  yych = *++m_cursor;
    7904  if (yych == 'u')
    7905  {
    7906  goto basic_json_parser_51;
    7907  }
    7908  goto basic_json_parser_33;
    7909 basic_json_parser_42:
    7910  yych = *++m_cursor;
    7911  if (yych == 0xBF)
    7912  {
    7913  goto basic_json_parser_52;
    7914  }
    7915  goto basic_json_parser_33;
    7916 basic_json_parser_43:
    7917  ++m_cursor;
    7918  if (m_limit <= m_cursor)
    7919  {
    7920  yyfill(); // LCOV_EXCL_LINE;
    7921  }
    7922  yych = *m_cursor;
    7923  if (yych <= '@')
    7924  {
    7925  if (yych <= '/')
    7926  {
    7927  goto basic_json_parser_33;
    7928  }
    7929  if (yych <= '9')
    7930  {
    7931  goto basic_json_parser_54;
    7932  }
    7933  goto basic_json_parser_33;
    7934  }
    7935  else
    7936  {
    7937  if (yych <= 'F')
    7938  {
    7939  goto basic_json_parser_54;
    7940  }
    7941  if (yych <= '`')
    7942  {
    7943  goto basic_json_parser_33;
    7944  }
    7945  if (yych <= 'f')
    7946  {
    7947  goto basic_json_parser_54;
    7948  }
    7949  goto basic_json_parser_33;
    7950  }
    7951 basic_json_parser_44:
    7952  yyaccept = 1;
    7953  m_marker = ++m_cursor;
    7954  if ((m_limit - m_cursor) < 3)
    7955  {
    7956  yyfill(); // LCOV_EXCL_LINE;
    7957  }
    7958  yych = *m_cursor;
    7959  if (yych <= 'D')
    7960  {
    7961  if (yych <= '/')
    7962  {
    7963  goto basic_json_parser_14;
    7964  }
    7965  if (yych <= '9')
    7966  {
    7967  goto basic_json_parser_44;
    7968  }
    7969  goto basic_json_parser_14;
    7970  }
    7971  else
    7972  {
    7973  if (yych <= 'E')
    7974  {
    7975  goto basic_json_parser_38;
    7976  }
    7977  if (yych == 'e')
    7978  {
    7979  goto basic_json_parser_38;
    7980  }
    7981  goto basic_json_parser_14;
    7982  }
    7983 basic_json_parser_46:
    7984  yych = *++m_cursor;
    7985  if (yych <= '/')
    7986  {
    7987  goto basic_json_parser_33;
    7988  }
    7989  if (yych >= ':')
    7990  {
    7991  goto basic_json_parser_33;
    7992  }
    7993 basic_json_parser_47:
    7994  ++m_cursor;
    7995  if (m_limit <= m_cursor)
    7996  {
    7997  yyfill(); // LCOV_EXCL_LINE;
    7998  }
    7999  yych = *m_cursor;
    8000  if (yych <= '/')
    8001  {
    8002  goto basic_json_parser_14;
    8003  }
    8004  if (yych <= '9')
    8005  {
    8006  goto basic_json_parser_47;
    8007  }
    8008  goto basic_json_parser_14;
    8009 basic_json_parser_49:
    8010  yych = *++m_cursor;
    8011  if (yych == 's')
    8012  {
    8013  goto basic_json_parser_55;
    8014  }
    8015  goto basic_json_parser_33;
    8016 basic_json_parser_50:
    8017  yych = *++m_cursor;
    8018  if (yych == 'l')
    8019  {
    8020  goto basic_json_parser_56;
    8021  }
    8022  goto basic_json_parser_33;
    8023 basic_json_parser_51:
    8024  yych = *++m_cursor;
    8025  if (yych == 'e')
    8026  {
    8027  goto basic_json_parser_58;
    8028  }
    8029  goto basic_json_parser_33;
    8030 basic_json_parser_52:
    8031  ++m_cursor;
    8032  {
    8033  return scan();
    8034  }
    8035 basic_json_parser_54:
    8036  ++m_cursor;
    8037  if (m_limit <= m_cursor)
    8038  {
    8039  yyfill(); // LCOV_EXCL_LINE;
    8040  }
    8041  yych = *m_cursor;
    8042  if (yych <= '@')
    8043  {
    8044  if (yych <= '/')
    8045  {
    8046  goto basic_json_parser_33;
    8047  }
    8048  if (yych <= '9')
    8049  {
    8050  goto basic_json_parser_60;
    8051  }
    8052  goto basic_json_parser_33;
    8053  }
    8054  else
    8055  {
    8056  if (yych <= 'F')
    8057  {
    8058  goto basic_json_parser_60;
    8059  }
    8060  if (yych <= '`')
    8061  {
    8062  goto basic_json_parser_33;
    8063  }
    8064  if (yych <= 'f')
    8065  {
    8066  goto basic_json_parser_60;
    8067  }
    8068  goto basic_json_parser_33;
    8069  }
    8070 basic_json_parser_55:
    8071  yych = *++m_cursor;
    8072  if (yych == 'e')
    8073  {
    8074  goto basic_json_parser_61;
    8075  }
    8076  goto basic_json_parser_33;
    8077 basic_json_parser_56:
    8078  ++m_cursor;
    8079  {
    8080  return token_type::literal_null;
    8081  }
    8082 basic_json_parser_58:
    8083  ++m_cursor;
    8084  {
    8085  return token_type::literal_true;
    8086  }
    8087 basic_json_parser_60:
    8088  ++m_cursor;
    8089  if (m_limit <= m_cursor)
    8090  {
    8091  yyfill(); // LCOV_EXCL_LINE;
    8092  }
    8093  yych = *m_cursor;
    8094  if (yych <= '@')
    8095  {
    8096  if (yych <= '/')
    8097  {
    8098  goto basic_json_parser_33;
    8099  }
    8100  if (yych <= '9')
    8101  {
    8102  goto basic_json_parser_63;
    8103  }
    8104  goto basic_json_parser_33;
    8105  }
    8106  else
    8107  {
    8108  if (yych <= 'F')
    8109  {
    8110  goto basic_json_parser_63;
    8111  }
    8112  if (yych <= '`')
    8113  {
    8114  goto basic_json_parser_33;
    8115  }
    8116  if (yych <= 'f')
    8117  {
    8118  goto basic_json_parser_63;
    8119  }
    8120  goto basic_json_parser_33;
    8121  }
    8122 basic_json_parser_61:
    8123  ++m_cursor;
    8124  {
    8125  return token_type::literal_false;
    8126  }
    8127 basic_json_parser_63:
    8128  ++m_cursor;
    8129  if (m_limit <= m_cursor)
    8130  {
    8131  yyfill(); // LCOV_EXCL_LINE;
    8132  }
    8133  yych = *m_cursor;
    8134  if (yych <= '@')
    8135  {
    8136  if (yych <= '/')
    8137  {
    8138  goto basic_json_parser_33;
    8139  }
    8140  if (yych <= '9')
    8141  {
    8142  goto basic_json_parser_31;
    8143  }
    8144  goto basic_json_parser_33;
    8145  }
    8146  else
    8147  {
    8148  if (yych <= 'F')
    8149  {
    8150  goto basic_json_parser_31;
    8151  }
    8152  if (yych <= '`')
    8153  {
    8154  goto basic_json_parser_33;
    8155  }
    8156  if (yych <= 'f')
    8157  {
    8158  goto basic_json_parser_31;
    8159  }
    8160  goto basic_json_parser_33;
    8161  }
    8162  }
    8163 
    8164  }
    8165 
    8167  void yyfill() noexcept
    8168  {
    8169  if (m_stream == nullptr or not * m_stream)
    8170  {
    8171  return;
    8172  }
    8173 
    8174  const auto offset_start = m_start - m_content;
    8175  const auto offset_marker = m_marker - m_start;
    8176  const auto offset_cursor = m_cursor - m_start;
    8177 
    8178  m_buffer.erase(0, static_cast<size_t>(offset_start));
    8179  std::string line;
    8180  assert(m_stream != nullptr);
    8181  std::getline(*m_stream, line);
    8182  m_buffer += "\n" + line; // add line with newline symbol
    8183 
    8184  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    8185  assert(m_content != nullptr);
    8186  m_start = m_content;
    8187  m_marker = m_start + offset_marker;
    8188  m_cursor = m_start + offset_cursor;
    8189  m_limit = m_start + m_buffer.size() - 1;
    8190  }
    8191 
    8193  string_t get_token() const
    8194  {
    8195  assert(m_start != nullptr);
    8196  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    8197  static_cast<size_t>(m_cursor - m_start));
    8198  }
    8199 
    8221  string_t get_string() const
    8222  {
    8223  string_t result;
    8224  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    8225 
    8226  // iterate the result between the quotes
    8227  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    8228  {
    8229  // process escaped characters
    8230  if (*i == '\\')
    8231  {
    8232  // read next character
    8233  ++i;
    8234 
    8235  switch (*i)
    8236  {
    8237  // the default escapes
    8238  case 't':
    8239  {
    8240  result += "\t";
    8241  break;
    8242  }
    8243  case 'b':
    8244  {
    8245  result += "\b";
    8246  break;
    8247  }
    8248  case 'f':
    8249  {
    8250  result += "\f";
    8251  break;
    8252  }
    8253  case 'n':
    8254  {
    8255  result += "\n";
    8256  break;
    8257  }
    8258  case 'r':
    8259  {
    8260  result += "\r";
    8261  break;
    8262  }
    8263  case '\\':
    8264  {
    8265  result += "\\";
    8266  break;
    8267  }
    8268  case '/':
    8269  {
    8270  result += "/";
    8271  break;
    8272  }
    8273  case '"':
    8274  {
    8275  result += "\"";
    8276  break;
    8277  }
    8278 
    8279  // unicode
    8280  case 'u':
    8281  {
    8282  // get code xxxx from uxxxx
    8283  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8284  4).c_str(), nullptr, 16);
    8285 
    8286  // check if codepoint is a high surrogate
    8287  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8288  {
    8289  // make sure there is a subsequent unicode
    8290  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8291  {
    8292  throw std::invalid_argument("missing low surrogate");
    8293  }
    8294 
    8295  // get code yyyy from uxxxx\uyyyy
    8296  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8297  (i + 7), 4).c_str(), nullptr, 16);
    8298  result += to_unicode(codepoint, codepoint2);
    8299  // skip the next 10 characters (xxxx\uyyyy)
    8300  i += 10;
    8301  }
    8302  else
    8303  {
    8304  // add unicode character(s)
    8305  result += to_unicode(codepoint);
    8306  // skip the next four characters (xxxx)
    8307  i += 4;
    8308  }
    8309  break;
    8310  }
    8311  }
    8312  }
    8313  else
    8314  {
    8315  // all other characters are just copied to the end of the
    8316  // string
    8317  result.append(1, static_cast<typename string_t::value_type>(*i));
    8318  }
    8319  }
    8320 
    8321  return result;
    8322  }
    8323 
    8344  long double str_to_float_t(long double* /* type */, char** endptr) const
    8345  {
    8346  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8347  }
    8348 
    8364  double str_to_float_t(double* /* type */, char** endptr) const
    8365  {
    8366  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8367  }
    8368 
    8384  float str_to_float_t(float* /* type */, char** endptr) const
    8385  {
    8386  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8387  }
    8388 
    8416  void get_number(basic_json& result) const
    8417  {
    8418  assert(m_start != nullptr);
    8419 
    8420  const lexer::lexer_char_t* curptr = m_start;
    8421 
    8422  // remember this number was parsed (for later serialization)
    8423  result.m_type.bits.parsed = true;
    8424 
    8425  // 'found_radix_point' will be set to 0xFF upon finding a radix
    8426  // point and later used to mask in/out the precision depending
    8427  // whether a radix is found i.e. 'precision &= found_radix_point'
    8428  uint8_t found_radix_point = 0;
    8429  uint8_t precision = 0;
    8430 
    8431  // accumulate the integer conversion result (unsigned for now)
    8432  number_unsigned_t value = 0;
    8433 
    8434  // maximum absolute value of the relevant integer type
    8435  number_unsigned_t max;
    8436 
    8437  // temporarily store the type to avoid unecessary bitfield access
    8438  value_t type;
    8439 
    8440  // look for sign
    8441  if (*curptr == '-')
    8442  {
    8443  type = value_t::number_integer;
    8444  max = static_cast<uint64_t>(std::numeric_limits<number_integer_t>::max()) + 1;
    8445  curptr++;
    8446  }
    8447  else
    8448  {
    8449  type = value_t::number_unsigned;
    8450  max = static_cast<uint64_t>(std::numeric_limits<number_unsigned_t>::max());
    8451  if (*curptr == '+')
    8452  {
    8453  curptr++;
    8454  }
    8455  }
    8456 
    8457  // count the significant figures
    8458  for (; curptr < m_cursor; curptr++)
    8459  {
    8460  // quickly skip tests if a digit
    8461  if (*curptr < '0' || *curptr > '9')
    8462  {
    8463  if (*curptr == '.')
    8464  {
    8465  // don't count '.' but change to float
    8466  type = value_t::number_float;
    8467 
    8468  // reset precision count
    8469  precision = 0;
    8470  found_radix_point = 0xFF;
    8471  continue;
    8472  }
    8473  // assume exponent (if not then will fail parse): change to
    8474  // float, stop counting and record exponent details
    8475  type = value_t::number_float;
    8476  result.m_type.bits.has_exp = true;
    8477 
    8478  // exponent capitalization
    8479  result.m_type.bits.exp_cap = (*curptr == 'E');
    8480 
    8481  // exponent '+' sign
    8482  result.m_type.bits.exp_plus = (*(++curptr) == '+');
    8483  break;
    8484  }
    8485 
    8486  // skip if definitely not an integer
    8487  if (type != value_t::number_float)
    8488  {
    8489  // multiply last value by ten and add the new digit
    8490  auto temp = value * 10 + *curptr - 0x30;
    8491 
    8492  // test for overflow
    8493  if (temp < value || temp > max)
    8494  {
    8495  // overflow
    8496  type = value_t::number_float;
    8497  }
    8498  else
    8499  {
    8500  // no overflow - save it
    8501  value = temp;
    8502  }
    8503  }
    8504  ++precision;
    8505  }
    8506 
    8507  // If no radix point was found then precision would now be set to
    8508  // the number of digits, which is wrong - clear it.
    8509  result.m_type.bits.precision = precision & found_radix_point;
    8510 
    8511  // save the value (if not a float)
    8512  if (type == value_t::number_unsigned)
    8513  {
    8514  result.m_value.number_unsigned = value;
    8515  }
    8516  else if (type == value_t::number_integer)
    8517  {
    8518  result.m_value.number_integer = -static_cast<number_integer_t>(value);
    8519  }
    8520  else
    8521  {
    8522  // parse with strtod
    8523  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
    8524  }
    8525 
    8526  // save the type
    8527  result.m_type = type;
    8528  }
    8529 
    8530  private:
    8532  std::istream* m_stream = nullptr;
    8534  string_t m_buffer;
    8536  const lexer_char_t* m_content = nullptr;
    8538  const lexer_char_t* m_start = nullptr;
    8540  const lexer_char_t* m_marker = nullptr;
    8542  const lexer_char_t* m_cursor = nullptr;
    8544  const lexer_char_t* m_limit = nullptr;
    8545  };
    8546 
    8552  class parser
    8553  {
    8554  public:
    8556  parser(const string_t& s, parser_callback_t cb = nullptr) noexcept
    8557  : callback(cb), m_lexer(s)
    8558  {
    8559  // read first token
    8560  get_token();
    8561  }
    8562 
    8564  parser(std::istream& _is, parser_callback_t cb = nullptr) noexcept
    8565  : callback(cb), m_lexer(&_is)
    8566  {
    8567  // read first token
    8568  get_token();
    8569  }
    8570 
    8572  basic_json parse()
    8573  {
    8574  basic_json result = parse_internal(true);
    8575 
    8576  expect(lexer::token_type::end_of_input);
    8577 
    8578  // return parser result and replace it with null in case the
    8579  // top-level value was discarded by the callback function
    8580  return result.is_discarded() ? basic_json() : result;
    8581  }
    8582 
    8583  private:
    8585  basic_json parse_internal(bool keep)
    8586  {
    8587  auto result = basic_json(value_t::discarded);
    8588 
    8589  switch (last_token)
    8590  {
    8591  case lexer::token_type::begin_object:
    8592  {
    8593  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    8594  {
    8595  // explicitly set result to object to cope with {}
    8596  result.m_type = value_t::object;
    8597  result.m_value = json_value(value_t::object);
    8598  }
    8599 
    8600  // read next token
    8601  get_token();
    8602 
    8603  // closing } -> we are done
    8604  if (last_token == lexer::token_type::end_object)
    8605  {
    8606  get_token();
    8607  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8608  {
    8609  result = basic_json(value_t::discarded);
    8610  }
    8611  return result;
    8612  }
    8613 
    8614  // no comma is expected here
    8615  unexpect(lexer::token_type::value_separator);
    8616 
    8617  // otherwise: parse key-value pairs
    8618  do
    8619  {
    8620  // ugly, but could be fixed with loop reorganization
    8621  if (last_token == lexer::token_type::value_separator)
    8622  {
    8623  get_token();
    8624  }
    8625 
    8626  // store key
    8627  expect(lexer::token_type::value_string);
    8628  const auto key = m_lexer.get_string();
    8629 
    8630  bool keep_tag = false;
    8631  if (keep)
    8632  {
    8633  if (callback)
    8634  {
    8635  basic_json k(key);
    8636  keep_tag = callback(depth, parse_event_t::key, k);
    8637  }
    8638  else
    8639  {
    8640  keep_tag = true;
    8641  }
    8642  }
    8643 
    8644  // parse separator (:)
    8645  get_token();
    8646  expect(lexer::token_type::name_separator);
    8647 
    8648  // parse and add value
    8649  get_token();
    8650  auto value = parse_internal(keep);
    8651  if (keep and keep_tag and not value.is_discarded())
    8652  {
    8653  result[key] = std::move(value);
    8654  }
    8655  }
    8656  while (last_token == lexer::token_type::value_separator);
    8657 
    8658  // closing }
    8659  expect(lexer::token_type::end_object);
    8660  get_token();
    8661  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8662  {
    8663  result = basic_json(value_t::discarded);
    8664  }
    8665 
    8666  return result;
    8667  }
    8668 
    8669  case lexer::token_type::begin_array:
    8670  {
    8671  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    8672  {
    8673  // explicitly set result to object to cope with []
    8674  result.m_type = value_t::array;
    8675  result.m_value = json_value(value_t::array);
    8676  }
    8677 
    8678  // read next token
    8679  get_token();
    8680 
    8681  // closing ] -> we are done
    8682  if (last_token == lexer::token_type::end_array)
    8683  {
    8684  get_token();
    8685  if (callback and not callback(--depth, parse_event_t::array_end, result))
    8686  {
    8687  result = basic_json(value_t::discarded);
    8688  }
    8689  return result;
    8690  }
    8691 
    8692  // no comma is expected here
    8693  unexpect(lexer::token_type::value_separator);
    8694 
    8695  // otherwise: parse values
    8696  do
    8697  {
    8698  // ugly, but could be fixed with loop reorganization
    8699  if (last_token == lexer::token_type::value_separator)
    8700  {
    8701  get_token();
    8702  }
    8703 
    8704  // parse value
    8705  auto value = parse_internal(keep);
    8706  if (keep and not value.is_discarded())
    8707  {
    8708  result.push_back(std::move(value));
    8709  }
    8710  }
    8711  while (last_token == lexer::token_type::value_separator);
    8712 
    8713  // closing ]
    8714  expect(lexer::token_type::end_array);
    8715  get_token();
    8716  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    8717  {
    8718  result = basic_json(value_t::discarded);
    8719  }
    8720 
    8721  return result;
    8722  }
    8723 
    8724  case lexer::token_type::literal_null:
    8725  {
    8726  get_token();
    8727  result.m_type = value_t::null;
    8728  break;
    8729  }
    8730 
    8731  case lexer::token_type::value_string:
    8732  {
    8733  const auto s = m_lexer.get_string();
    8734  get_token();
    8735  result = basic_json(s);
    8736  break;
    8737  }
    8738 
    8739  case lexer::token_type::literal_true:
    8740  {
    8741  get_token();
    8742  result.m_type = value_t::boolean;
    8743  result.m_value = true;
    8744  break;
    8745  }
    8746 
    8747  case lexer::token_type::literal_false:
    8748  {
    8749  get_token();
    8750  result.m_type = value_t::boolean;
    8751  result.m_value = false;
    8752  break;
    8753  }
    8754 
    8755  case lexer::token_type::value_number:
    8756  {
    8757  m_lexer.get_number(result);
    8758  get_token();
    8759  break;
    8760  }
    8761 
    8762  default:
    8763  {
    8764  // the last token was unexpected
    8765  unexpect(last_token);
    8766  }
    8767  }
    8768 
    8769  if (keep and callback and not callback(depth, parse_event_t::value, result))
    8770  {
    8771  result = basic_json(value_t::discarded);
    8772  }
    8773  return result;
    8774  }
    8775 
    8777  typename lexer::token_type get_token() noexcept
    8778  {
    8779  last_token = m_lexer.scan();
    8780  return last_token;
    8781  }
    8782 
    8783  void expect(typename lexer::token_type t) const
    8784  {
    8785  if (t != last_token)
    8786  {
    8787  std::string error_msg = "parse error - unexpected ";
    8788  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8789  lexer::token_type_name(last_token));
    8790  error_msg += "; expected " + lexer::token_type_name(t);
    8791  throw std::invalid_argument(error_msg);
    8792  }
    8793  }
    8794 
    8795  void unexpect(typename lexer::token_type t) const
    8796  {
    8797  if (t == last_token)
    8798  {
    8799  std::string error_msg = "parse error - unexpected ";
    8800  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8801  lexer::token_type_name(last_token));
    8802  throw std::invalid_argument(error_msg);
    8803  }
    8804  }
    8805 
    8806  private:
    8808  int depth = 0;
    8810  parser_callback_t callback;
    8812  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    8814  lexer m_lexer;
    8815  };
    8816 
    8817  public:
    8830  {
    8832  friend class basic_json;
    8833 
    8834  public:
    8857  explicit json_pointer(const std::string& s = "")
    8858  : reference_tokens(split(s))
    8859  {}
    8860 
    8876  std::string to_string() const noexcept
    8877  {
    8878  std::string result;
    8879 
    8880  for (const auto& reference_token : reference_tokens)
    8881  {
    8882  result += "/" + escape(reference_token);
    8883  }
    8884 
    8885  return result;
    8886  }
    8887 
    8889  operator std::string() const
    8890  {
    8891  return to_string();
    8892  }
    8894  private:
    8896  std::string pop_back()
    8897  {
    8898  if (is_root())
    8899  {
    8900  throw std::domain_error("JSON pointer has no parent");
    8901  }
    8902 
    8903  auto last = reference_tokens.back();
    8904  reference_tokens.pop_back();
    8905  return last;
    8906  }
    8907 
    8909  bool is_root() const
    8910  {
    8911  return reference_tokens.empty();
    8912  }
    8913 
    8914  json_pointer top() const
    8915  {
    8916  if (is_root())
    8917  {
    8918  throw std::domain_error("JSON pointer has no parent");
    8919  }
    8920 
    8921  json_pointer result = *this;
    8922  result.reference_tokens = {reference_tokens[0]};
    8923  return result;
    8924  }
    8925 
    8929  reference get_and_create(reference j) const
    8930  {
    8931  pointer result = &j;
    8932 
    8933  // in case no reference tokens exist, return a reference to the
    8934  // JSON value j which will be overwritten by a primitive value
    8935  for (const auto& reference_token : reference_tokens)
    8936  {
    8937  switch (result->m_type)
    8938  {
    8939  case value_t::null:
    8940  {
    8941  if (reference_token == "0")
    8942  {
    8943  // start a new array if reference token is 0
    8944  result = &result->operator[](0);
    8945  }
    8946  else
    8947  {
    8948  // start a new object otherwise
    8949  result = &result->operator[](reference_token);
    8950  }
    8951  break;
    8952  }
    8953 
    8954  case value_t::object:
    8955  {
    8956  // create an entry in the object
    8957  result = &result->operator[](reference_token);
    8958  break;
    8959  }
    8960 
    8961  case value_t::array:
    8962  {
    8963  // create an entry in the array
    8964  result = &result->operator[](static_cast<size_type>(std::stoi(reference_token)));
    8965  break;
    8966  }
    8967 
    8968  /*
    8969  The following code is only reached if there exists a
    8970  reference token _and_ the current value is primitive. In
    8971  this case, we have an error situation, because primitive
    8972  values may only occur as single value; that is, with an
    8973  empty list of reference tokens.
    8974  */
    8975  default:
    8976  {
    8977  throw std::domain_error("invalid value to unflatten");
    8978  }
    8979  }
    8980  }
    8981 
    8982  return *result;
    8983  }
    8984 
    8998  reference get_unchecked(pointer ptr) const
    8999  {
    9000  for (const auto& reference_token : reference_tokens)
    9001  {
    9002  switch (ptr->m_type)
    9003  {
    9004  case value_t::object:
    9005  {
    9006  // use unchecked object access
    9007  ptr = &ptr->operator[](reference_token);
    9008  break;
    9009  }
    9010 
    9011  case value_t::array:
    9012  {
    9013  // error condition (cf. RFC 6901, Sect. 4)
    9014  if (reference_token.size() > 1 and reference_token[0] == '0')
    9015  {
    9016  throw std::domain_error("array index must not begin with '0'");
    9017  }
    9018 
    9019  if (reference_token == "-")
    9020  {
    9021  // explicityly treat "-" as index beyond the end
    9022  ptr = &ptr->operator[](ptr->m_value.array->size());
    9023  }
    9024  else
    9025  {
    9026  // convert array index to number; unchecked access
    9027  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9028  }
    9029  break;
    9030  }
    9031 
    9032  default:
    9033  {
    9034  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9035  }
    9036  }
    9037  }
    9038 
    9039  return *ptr;
    9040  }
    9041 
    9042  reference get_checked(pointer ptr) const
    9043  {
    9044  for (const auto& reference_token : reference_tokens)
    9045  {
    9046  switch (ptr->m_type)
    9047  {
    9048  case value_t::object:
    9049  {
    9050  // note: at performs range check
    9051  ptr = &ptr->at(reference_token);
    9052  break;
    9053  }
    9054 
    9055  case value_t::array:
    9056  {
    9057  if (reference_token == "-")
    9058  {
    9059  // "-" always fails the range check
    9060  throw std::out_of_range("array index '-' (" +
    9061  std::to_string(ptr->m_value.array->size()) +
    9062  ") is out of range");
    9063  }
    9064 
    9065  // error condition (cf. RFC 6901, Sect. 4)
    9066  if (reference_token.size() > 1 and reference_token[0] == '0')
    9067  {
    9068  throw std::domain_error("array index must not begin with '0'");
    9069  }
    9070 
    9071  // note: at performs range check
    9072  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9073  break;
    9074  }
    9075 
    9076  default:
    9077  {
    9078  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9079  }
    9080  }
    9081  }
    9082 
    9083  return *ptr;
    9084  }
    9085 
    9094  const_reference get_unchecked(const_pointer ptr) const
    9095  {
    9096  for (const auto& reference_token : reference_tokens)
    9097  {
    9098  switch (ptr->m_type)
    9099  {
    9100  case value_t::object:
    9101  {
    9102  // use unchecked object access
    9103  ptr = &ptr->operator[](reference_token);
    9104  break;
    9105  }
    9106 
    9107  case value_t::array:
    9108  {
    9109  if (reference_token == "-")
    9110  {
    9111  // "-" cannot be used for const access
    9112  throw std::out_of_range("array index '-' (" +
    9113  std::to_string(ptr->m_value.array->size()) +
    9114  ") is out of range");
    9115  }
    9116 
    9117  // error condition (cf. RFC 6901, Sect. 4)
    9118  if (reference_token.size() > 1 and reference_token[0] == '0')
    9119  {
    9120  throw std::domain_error("array index must not begin with '0'");
    9121  }
    9122 
    9123  // use unchecked array access
    9124  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9125  break;
    9126  }
    9127 
    9128  default:
    9129  {
    9130  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9131  }
    9132  }
    9133  }
    9134 
    9135  return *ptr;
    9136  }
    9137 
    9138  const_reference get_checked(const_pointer ptr) const
    9139  {
    9140  for (const auto& reference_token : reference_tokens)
    9141  {
    9142  switch (ptr->m_type)
    9143  {
    9144  case value_t::object:
    9145  {
    9146  // note: at performs range check
    9147  ptr = &ptr->at(reference_token);
    9148  break;
    9149  }
    9150 
    9151  case value_t::array:
    9152  {
    9153  if (reference_token == "-")
    9154  {
    9155  // "-" always fails the range check
    9156  throw std::out_of_range("array index '-' (" +
    9157  std::to_string(ptr->m_value.array->size()) +
    9158  ") is out of range");
    9159  }
    9160 
    9161  // error condition (cf. RFC 6901, Sect. 4)
    9162  if (reference_token.size() > 1 and reference_token[0] == '0')
    9163  {
    9164  throw std::domain_error("array index must not begin with '0'");
    9165  }
    9166 
    9167  // note: at performs range check
    9168  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9169  break;
    9170  }
    9171 
    9172  default:
    9173  {
    9174  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9175  }
    9176  }
    9177  }
    9178 
    9179  return *ptr;
    9180  }
    9181 
    9183  static std::vector<std::string> split(std::string reference_string)
    9184  {
    9185  std::vector<std::string> result;
    9186 
    9187  // special case: empty reference string -> no reference tokens
    9188  if (reference_string.empty())
    9189  {
    9190  return result;
    9191  }
    9192 
    9193  // check if nonempty reference string begins with slash
    9194  if (reference_string[0] != '/')
    9195  {
    9196  throw std::domain_error("JSON pointer must be empty or begin with '/'");
    9197  }
    9198 
    9199  // extract the reference tokens:
    9200  // - slash: position of the last read slash (or end of string)
    9201  // - start: position after the previous slash
    9202  for (
    9203  // search for the first slash after the first character
    9204  size_t slash = reference_string.find_first_of("/", 1),
    9205  // set the beginning of the first reference token
    9206  start = 1;
    9207  // we can stop if start == string::npos+1 = 0
    9208  start != 0;
    9209  // set the beginning of the next reference token
    9210  // (will eventually be 0 if slash == std::string::npos)
    9211  start = slash + 1,
    9212  // find next slash
    9213  slash = reference_string.find_first_of("/", start))
    9214  {
    9215  // use the text between the beginning of the reference token
    9216  // (start) and the last slash (slash).
    9217  auto reference_token = reference_string.substr(start, slash - start);
    9218 
    9219  // check reference tokens are properly escaped
    9220  for (size_t pos = reference_token.find_first_of("~");
    9221  pos != std::string::npos;
    9222  pos = reference_token.find_first_of("~", pos + 1))
    9223  {
    9224  assert(reference_token[pos] == '~');
    9225 
    9226  // ~ must be followed by 0 or 1
    9227  if (pos == reference_token.size() - 1 or
    9228  (reference_token[pos + 1] != '0' and
    9229  reference_token[pos + 1] != '1'))
    9230  {
    9231  throw std::domain_error("escape error: '~' must be followed with '0' or '1'");
    9232  }
    9233  }
    9234 
    9235  // finally, store the reference token
    9236  unescape(reference_token);
    9237  result.push_back(reference_token);
    9238  }
    9239 
    9240  return result;
    9241  }
    9242 
    9243  private:
    9258  static void replace_substring(std::string& s,
    9259  const std::string& f,
    9260  const std::string& t)
    9261  {
    9262  assert(not f.empty());
    9263 
    9264  for (
    9265  size_t pos = s.find(f); // find first occurrence of f
    9266  pos != std::string::npos; // make sure f was found
    9267  s.replace(pos, f.size(), t), // replace with t
    9268  pos = s.find(f, pos + t.size()) // find next occurrence of f
    9269  );
    9270  }
    9271 
    9273  static std::string escape(std::string s)
    9274  {
    9275  // escape "~"" to "~0" and "/" to "~1"
    9276  replace_substring(s, "~", "~0");
    9277  replace_substring(s, "/", "~1");
    9278  return s;
    9279  }
    9280 
    9282  static void unescape(std::string& s)
    9283  {
    9284  // first transform any occurrence of the sequence '~1' to '/'
    9285  replace_substring(s, "~1", "/");
    9286  // then transform any occurrence of the sequence '~0' to '~'
    9287  replace_substring(s, "~0", "~");
    9288  }
    9289 
    9297  static void flatten(const std::string& reference_string,
    9298  const basic_json& value,
    9299  basic_json& result)
    9300  {
    9301  switch (value.m_type)
    9302  {
    9303  case value_t::array:
    9304  {
    9305  if (value.m_value.array->empty())
    9306  {
    9307  // flatten empty array as null
    9308  result[reference_string] = nullptr;
    9309  }
    9310  else
    9311  {
    9312  // iterate array and use index as reference string
    9313  for (size_t i = 0; i < value.m_value.array->size(); ++i)
    9314  {
    9315  flatten(reference_string + "/" + std::to_string(i),
    9316  value.m_value.array->operator[](i), result);
    9317  }
    9318  }
    9319  break;
    9320  }
    9321 
    9322  case value_t::object:
    9323  {
    9324  if (value.m_value.object->empty())
    9325  {
    9326  // flatten empty object as null
    9327  result[reference_string] = nullptr;
    9328  }
    9329  else
    9330  {
    9331  // iterate object and use keys as reference string
    9332  for (const auto& element : *value.m_value.object)
    9333  {
    9334  flatten(reference_string + "/" + escape(element.first),
    9335  element.second, result);
    9336  }
    9337  }
    9338  break;
    9339  }
    9340 
    9341  default:
    9342  {
    9343  // add primitive value with its reference string
    9344  result[reference_string] = value;
    9345  break;
    9346  }
    9347  }
    9348  }
    9349 
    9355  static basic_json unflatten(const basic_json& value)
    9356  {
    9357  if (not value.is_object())
    9358  {
    9359  throw std::domain_error("only objects can be unflattened");
    9360  }
    9361 
    9362  basic_json result;
    9363 
    9364  // iterate the JSON object values
    9365  for (const auto& element : *value.m_value.object)
    9366  {
    9367  if (not element.second.is_primitive())
    9368  {
    9369  throw std::domain_error("values in object must be primitive");
    9370  }
    9371 
    9372  // assign value to reference pointed to by JSON pointer;
    9373  // Note that if the JSON pointer is "" (i.e., points to the
    9374  // whole value), function get_and_create returns a reference
    9375  // to result itself. An assignment will then create a
    9376  // primitive value.
    9377  json_pointer(element.first).get_and_create(result) = element.second;
    9378  }
    9379 
    9380  return result;
    9381  }
    9382 
    9383  private:
    9385  std::vector<std::string> reference_tokens {};
    9386  };
    9387 
    9389  // JSON Pointer support //
    9391 
    9394 
    9428  reference operator[](const json_pointer& ptr)
    9429  {
    9430  return ptr.get_unchecked(this);
    9431  }
    9455  const_reference operator[](const json_pointer& ptr) const
    9456  {
    9457  return ptr.get_unchecked(this);
    9458  }
    9480  reference at(const json_pointer& ptr)
    9481  {
    9482  return ptr.get_checked(this);
    9483  }
    9505  const_reference at(const json_pointer& ptr) const
    9506  {
    9507  return ptr.get_checked(this);
    9508  }
    9532  basic_json flatten() const
    9533  {
    9534  basic_json result(value_t::object);
    9535  json_pointer::flatten("", *this, result);
    9536  return result;
    9537  }
    9538 
    9566  basic_json unflatten() const
    9567  {
    9568  return json_pointer::unflatten(*this);
    9569  }
    9572 
    9574  // JSON Patch functions //
    9576 
    9579 
    9616  basic_json patch(const basic_json& patch) const
    9617  {
    9618  // make a working copy to apply the patch to
    9619  basic_json result = *this;
    9621  // the valid JSON Patch operations
    9622  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
    9623 
    9624  const auto get_op = [](const std::string op)
    9625  {
    9626  if (op == "add")
    9627  {
    9628  return patch_operations::add;
    9629  }
    9630  if (op == "remove")
    9631  {
    9632  return patch_operations::remove;
    9633  }
    9634  if (op == "replace")
    9635  {
    9636  return patch_operations::replace;
    9637  }
    9638  if (op == "move")
    9639  {
    9640  return patch_operations::move;
    9641  }
    9642  if (op == "copy")
    9643  {
    9644  return patch_operations::copy;
    9645  }
    9646  if (op == "test")
    9647  {
    9648  return patch_operations::test;
    9649  }
    9650 
    9651  return patch_operations::invalid;
    9652  };
    9653 
    9654  // wrapper for "add" operation; add value at ptr
    9655  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
    9656  {
    9657  // adding to the root of the target document means replacing it
    9658  if (ptr.is_root())
    9659  {
    9660  result = val;
    9661  }
    9662  else
    9663  {
    9664  // make sure the top element of the pointer exists
    9665  json_pointer top_pointer = ptr.top();
    9666  if (top_pointer != ptr)
    9667  {
    9668  basic_json& x = result.at(top_pointer);
    9669  }
    9670 
    9671  // get reference to parent of JSON pointer ptr
    9672  const auto last_path = ptr.pop_back();
    9673  basic_json& parent = result[ptr];
    9674 
    9675  switch (parent.m_type)
    9676  {
    9677  case value_t::null:
    9678  case value_t::object:
    9679  {
    9680  // use operator[] to add value
    9681  parent[last_path] = val;
    9682  break;
    9683  }
    9684 
    9685  case value_t::array:
    9686  {
    9687  if (last_path == "-")
    9688  {
    9689  // special case: append to back
    9690  parent.push_back(val);
    9691  }
    9692  else
    9693  {
    9694  const auto idx = std::stoi(last_path);
    9695  if (static_cast<size_type>(idx) > parent.size())
    9696  {
    9697  // avoid undefined behavior
    9698  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    9699  }
    9700  else
    9701  {
    9702  // default case: insert add offset
    9703  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
    9704  }
    9705  }
    9706  break;
    9707  }
    9708 
    9709  default:
    9710  {
    9711  // if there exists a parent it cannot be primitive
    9712  assert(false); // LCOV_EXCL_LINE
    9713  }
    9714  }
    9715  }
    9716  };
    9717 
    9718  // wrapper for "remove" operation; remove value at ptr
    9719  const auto operation_remove = [&result](json_pointer & ptr)
    9720  {
    9721  // get reference to parent of JSON pointer ptr
    9722  const auto last_path = ptr.pop_back();
    9723  basic_json& parent = result.at(ptr);
    9724 
    9725  // remove child
    9726  if (parent.is_object())
    9727  {
    9728  // perform range check
    9729  auto it = parent.find(last_path);
    9730  if (it != parent.end())
    9731  {
    9732  parent.erase(it);
    9733  }
    9734  else
    9735  {
    9736  throw std::out_of_range("key '" + last_path + "' not found");
    9737  }
    9738  }
    9739  else if (parent.is_array())
    9740  {
    9741  // note erase performs range check
    9742  parent.erase(static_cast<size_type>(std::stoi(last_path)));
    9743  }
    9744  };
    9745 
    9746  // type check
    9747  if (not patch.is_array())
    9748  {
    9749  // a JSON patch must be an array of objects
    9750  throw std::invalid_argument("JSON patch must be an array of objects");
    9751  }
    9752 
    9753  // iterate and apply th eoperations
    9754  for (const auto& val : patch)
    9755  {
    9756  // wrapper to get a value for an operation
    9757  const auto get_value = [&val](const std::string & op,
    9758  const std::string & member,
    9759  bool string_type) -> basic_json&
    9760  {
    9761  // find value
    9762  auto it = val.m_value.object->find(member);
    9763 
    9764  // context-sensitive error message
    9765  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
    9766 
    9767  // check if desired value is present
    9768  if (it == val.m_value.object->end())
    9769  {
    9770  throw std::invalid_argument(error_msg + " must have member '" + member + "'");
    9771  }
    9772 
    9773  // check if result is of type string
    9774  if (string_type and not it->second.is_string())
    9775  {
    9776  throw std::invalid_argument(error_msg + " must have string member '" + member + "'");
    9777  }
    9778 
    9779  // no error: return value
    9780  return it->second;
    9781  };
    9782 
    9783  // type check
    9784  if (not val.is_object())
    9785  {
    9786  throw std::invalid_argument("JSON patch must be an array of objects");
    9787  }
    9788 
    9789  // collect mandatory members
    9790  const std::string op = get_value("op", "op", true);
    9791  const std::string path = get_value(op, "path", true);
    9792  json_pointer ptr(path);
    9793 
    9794  switch (get_op(op))
    9795  {
    9796  case patch_operations::add:
    9797  {
    9798  operation_add(ptr, get_value("add", "value", false));
    9799  break;
    9800  }
    9801 
    9802  case patch_operations::remove:
    9803  {
    9804  operation_remove(ptr);
    9805  break;
    9806  }
    9807 
    9808  case patch_operations::replace:
    9809  {
    9810  // the "path" location must exist - use at()
    9811  result.at(ptr) = get_value("replace", "value", false);
    9812  break;
    9813  }
    9814 
    9815  case patch_operations::move:
    9816  {
    9817  const std::string from_path = get_value("move", "from", true);
    9818  json_pointer from_ptr(from_path);
    9819 
    9820  // the "from" location must exist - use at()
    9821  basic_json v = result.at(from_ptr);
    9822 
    9823  // The move operation is functionally identical to a
    9824  // "remove" operation on the "from" location, followed
    9825  // immediately by an "add" operation at the target
    9826  // location with the value that was just removed.
    9827  operation_remove(from_ptr);
    9828  operation_add(ptr, v);
    9829  break;
    9830  }
    9831 
    9832  case patch_operations::copy:
    9833  {
    9834  const std::string from_path = get_value("copy", "from", true);;
    9835  const json_pointer from_ptr(from_path);
    9836 
    9837  // the "from" location must exist - use at()
    9838  result[ptr] = result.at(from_ptr);
    9839  break;
    9840  }
    9841 
    9842  case patch_operations::test:
    9843  {
    9844  bool success = false;
    9845  try
    9846  {
    9847  // check if "value" matches the one at "path"
    9848  // the "path" location must exist - use at()
    9849  success = (result.at(ptr) == get_value("test", "value", false));
    9850  }
    9851  catch (std::out_of_range&)
    9852  {
    9853  // ignore out of range errors: success remains false
    9854  }
    9855 
    9856  // throw an exception if test fails
    9857  if (not success)
    9858  {
    9859  throw std::domain_error("unsuccessful: " + val.dump());
    9860  }
    9861 
    9862  break;
    9863  }
    9864 
    9865  case patch_operations::invalid:
    9866  {
    9867  // op must be "add", "remove", "replace", "move", "copy", or
    9868  // "test"
    9869  throw std::invalid_argument("operation value '" + op + "' is invalid");
    9870  }
    9871  }
    9872  }
    9873 
    9874  return result;
    9875  }
    9876 
    9909  static basic_json diff(const basic_json& source,
    9910  const basic_json& target,
    9911  std::string path = "") noexcept
    9912  {
    9913  // the patch
    9914  basic_json result(value_t::array);
    9915 
    9916  // if the values are the same, return empty patch
    9917  if (source == target)
    9918  {
    9919  return result;
    9920  }
    9921 
    9922  if (source.type() != target.type())
    9923  {
    9924  // different types: replace value
    9925  result.push_back(
    9926  {
    9927  {"op", "replace"},
    9928  {"path", path},
    9929  {"value", target}
    9930  });
    9931  }
    9932  else
    9933  {
    9934  switch (source.type())
    9935  {
    9936  case value_t::array:
    9937  {
    9938  // first pass: traverse common elements
    9939  size_t i = 0;
    9940  while (i < source.size() and i < target.size())
    9941  {
    9942  // recursive call to compare array values at index i
    9943  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
    9944  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    9945  ++i;
    9946  }
    9947 
    9948  // i now reached the end of at least one array
    9949  // in a second pass, traverse the remaining elements
    9950 
    9951  // remove my remaining elements
    9952  while (i < source.size())
    9953  {
    9954  result.push_back(object(
    9955  {
    9956  {"op", "remove"},
    9957  {"path", path + "/" + std::to_string(i)}
    9958  }));
    9959  ++i;
    9960  }
    9961 
    9962  // add other remaining elements
    9963  while (i < target.size())
    9964  {
    9965  result.push_back(
    9966  {
    9967  {"op", "add"},
    9968  {"path", path + "/" + std::to_string(i)},
    9969  {"value", target[i]}
    9970  });
    9971  ++i;
    9972  }
    9973 
    9974  break;
    9975  }
    9976 
    9977  case value_t::object:
    9978  {
    9979  // first pass: traverse this object's elements
    9980  for (auto it = source.begin(); it != source.end(); ++it)
    9981  {
    9982  // escape the key name to be used in a JSON patch
    9983  const auto key = json_pointer::escape(it.key());
    9984 
    9985  if (target.find(it.key()) != target.end())
    9986  {
    9987  // recursive call to compare object values at key it
    9988  auto temp_diff = diff(it.value(), target[it.key()], path + "/" + key);
    9989  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    9990  }
    9991  else
    9992  {
    9993  // found a key that is not in o -> remove it
    9994  result.push_back(object(
    9995  {
    9996  {"op", "remove"},
    9997  {"path", path + "/" + key}
    9998  }));
    9999  }
    10000  }
    10001 
    10002  // second pass: traverse other object's elements
    10003  for (auto it = target.begin(); it != target.end(); ++it)
    10004  {
    10005  if (source.find(it.key()) == source.end())
    10006  {
    10007  // found a key that is not in this -> add it
    10008  const auto key = json_pointer::escape(it.key());
    10009  result.push_back(
    10010  {
    10011  {"op", "add"},
    10012  {"path", path + "/" + key},
    10013  {"value", it.value()}
    10014  });
    10015  }
    10016  }
    10017 
    10018  break;
    10019  }
    10020 
    10021  default:
    10022  {
    10023  // both primitive type: replace value
    10024  result.push_back(
    10025  {
    10026  {"op", "replace"},
    10027  {"path", path},
    10028  {"value", target}
    10029  });
    10030  break;
    10031  }
    10032  }
    10033  }
    10034 
    10035  return result;
    10036  }
    10037 
    10039 };
    10040 
    10041 
    10043 // presets //
    10045 
    10054 using json = basic_json<>;
    10055 }
    10056 
    10057 
    10059 // nonmember support //
    10061 
    10062 // specialization of std::swap, and std::hash
    10063 namespace std
    10064 {
    10070 template <>
    10071 inline void swap(nlohmann::json& j1,
    10072  nlohmann::json& j2) noexcept(
    10073  is_nothrow_move_constructible<nlohmann::json>::value and
    10074  is_nothrow_move_assignable<nlohmann::json>::value
    10075  )
    10076 {
    10077  j1.swap(j2);
    10078 }
    10079 
    10081 template <>
    10082 struct hash<nlohmann::json>
    10083 {
    10089  std::size_t operator()(const nlohmann::json& j) const
    10090  {
    10091  // a naive hashing via the string representation
    10092  const auto& h = hash<nlohmann::json::string_t>();
    10093  return h(j.dump());
    10094  }
    10095 };
    10096 }
    10097 
    10110 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    10111 {
    10112  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    10113 }
    10114 
    10120 inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
    10121 {
    10122  return nlohmann::json::json_pointer(s);
    10123 }
    10124 
    10125 // restore GCC/clang diagnostic settings
    10126 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    10127  #pragma GCC diagnostic pop
    10128 #endif
    10129 
    10130 #endif
    const_iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6447
    -
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:5582
    +
    1 /*
    2  __ _____ _____ _____
    3  __| | __| | | | JSON for Modern C++
    4 | | |__ | | | | | | version 2.0.0
    5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
    6 
    7 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
    8 Copyright (c) 2013-2016 Niels Lohmann <http://nlohmann.me>.
    9 
    10 Permission is hereby granted, free of charge, to any person obtaining a copy
    11 of this software and associated documentation files (the "Software"), to deal
    12 in the Software without restriction, including without limitation the rights
    13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    14 copies of the Software, and to permit persons to whom the Software is
    15 furnished to do so, subject to the following conditions:
    16 
    17 The above copyright notice and this permission notice shall be included in all
    18 copies or substantial portions of the Software.
    19 
    20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    26 SOFTWARE.
    27 */
    28 
    29 #ifndef NLOHMANN_JSON_HPP
    30 #define NLOHMANN_JSON_HPP
    31 
    32 #include <algorithm>
    33 #include <array>
    34 #include <cassert>
    35 #include <cerrno>
    36 #include <ciso646>
    37 #include <cmath>
    38 #include <cstddef>
    39 #include <cstdio>
    40 #include <cstdlib>
    41 #include <functional>
    42 #include <initializer_list>
    43 #include <iomanip>
    44 #include <iostream>
    45 #include <iterator>
    46 #include <limits>
    47 #include <map>
    48 #include <memory>
    49 #include <sstream>
    50 #include <stdexcept>
    51 #include <string>
    52 #include <type_traits>
    53 #include <utility>
    54 #include <vector>
    55 
    56 // disable float-equal warnings on GCC/clang
    57 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    58  #pragma GCC diagnostic push
    59  #pragma GCC diagnostic ignored "-Wfloat-equal"
    60 #endif
    61 
    67 namespace nlohmann
    68 {
    69 
    70 
    75 namespace
    76 {
    81 template<typename T>
    82 struct has_mapped_type
    83 {
    84  private:
    85  template<typename C> static char test(typename C::mapped_type*);
    86  template<typename C> static char (&test(...))[2];
    87  public:
    88  static constexpr bool value = sizeof(test<T>(0)) == 1;
    89 };
    90 
    95 class DecimalSeparator : public std::numpunct<char>
    96 {
    97  protected:
    98  char do_decimal_point() const
    99  {
    100  return '.';
    101  }
    102 };
    103 
    104 }
    105 
    177 template <
    178  template<typename U, typename V, typename... Args> class ObjectType = std::map,
    179  template<typename U, typename... Args> class ArrayType = std::vector,
    180  class StringType = std::string,
    181  class BooleanType = bool,
    182  class NumberIntegerType = std::int64_t,
    183  class NumberUnsignedType = std::uint64_t,
    184  class NumberFloatType = double,
    185  template<typename U> class AllocatorType = std::allocator
    186  >
    188 {
    189  private:
    191  using basic_json_t = basic_json<ObjectType,
    192  ArrayType,
    193  StringType,
    194  BooleanType,
    195  NumberIntegerType,
    196  NumberUnsignedType,
    197  NumberFloatType,
    198  AllocatorType>;
    199 
    200  public:
    201  // forward declarations
    202  template<typename Base> class json_reverse_iterator;
    203  class json_pointer;
    204 
    206  // container types //
    208 
    211 
    214 
    218  using const_reference = const value_type&;
    219 
    221  using difference_type = std::ptrdiff_t;
    223  using size_type = std::size_t;
    224 
    226  using allocator_type = AllocatorType<basic_json>;
    227 
    229  using pointer = typename std::allocator_traits<allocator_type>::pointer;
    231  using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;
    232 
    234  class iterator;
    236  class const_iterator;
    241 
    243 
    244 
    249  {
    250  return allocator_type();
    251  }
    252 
    253 
    255  // JSON value data types //
    257 
    260 
    343  using object_t = ObjectType<StringType,
    344  basic_json,
    345  std::less<StringType>,
    346  AllocatorType<std::pair<const StringType,
    347  basic_json>>>;
    348 
    393  using array_t = ArrayType<basic_json, AllocatorType<basic_json>>;
    394 
    440  using string_t = StringType;
    441 
    466  using boolean_t = BooleanType;
    467 
    537  using number_integer_t = NumberIntegerType;
    538 
    609  using number_unsigned_t = NumberUnsignedType;
    610 
    677  using number_float_t = NumberFloatType;
    678 
    680 
    681 
    683  // JSON type enumeration //
    685 
    696  enum class value_t : uint8_t
    697  {
    698  null,
    699  object,
    700  array,
    701  string,
    702  boolean,
    703  number_integer,
    704  number_unsigned,
    705  number_float,
    706  discarded
    707  };
    708 
    709 
    710  private:
    711 
    726  union type_data_t
    727  {
    728  struct
    729  {
    731  uint16_t type : 4;
    733  uint16_t parsed : 1;
    735  uint16_t has_exp : 1;
    737  uint16_t exp_plus : 1;
    739  uint16_t exp_cap : 1;
    741  uint16_t precision : 8;
    742  } bits;
    743  uint16_t data;
    744 
    746  operator value_t() const
    747  {
    748  return static_cast<value_t>(bits.type);
    749  }
    750 
    752  bool operator==(const value_t& rhs) const
    753  {
    754  return static_cast<value_t>(bits.type) == rhs;
    755  }
    756 
    758  type_data_t& operator=(value_t rhs)
    759  {
    760  bits.type = static_cast<uint16_t>(rhs);
    761  return *this;
    762  }
    763 
    765  type_data_t(value_t t) noexcept
    766  {
    767  *reinterpret_cast<uint16_t*>(this) = 0;
    768  bits.type = static_cast<uint16_t>(t);
    769  }
    770 
    772  type_data_t() noexcept
    773  {
    774  data = 0;
    775  bits.type = reinterpret_cast<uint16_t>(value_t::null);
    776  }
    777  };
    778 
    780  template<typename T, typename... Args>
    781  static T* create(Args&& ... args)
    782  {
    783  AllocatorType<T> alloc;
    784  auto deleter = [&](T * object)
    785  {
    786  alloc.deallocate(object, 1);
    787  };
    788  std::unique_ptr<T, decltype(deleter)> object(alloc.allocate(1), deleter);
    789  alloc.construct(object.get(), std::forward<Args>(args)...);
    790  return object.release();
    791  }
    792 
    794  // JSON value storage //
    796 
    804  union json_value
    805  {
    807  object_t* object;
    809  array_t* array;
    811  string_t* string;
    813  boolean_t boolean;
    815  number_integer_t number_integer;
    817  number_unsigned_t number_unsigned;
    819  number_float_t number_float;
    820 
    822  json_value() = default;
    824  json_value(boolean_t v) noexcept : boolean(v) {}
    826  json_value(number_integer_t v) noexcept : number_integer(v) {}
    828  json_value(number_unsigned_t v) noexcept : number_unsigned(v) {}
    830  json_value(number_float_t v) noexcept : number_float(v) {}
    832  json_value(value_t t)
    833  {
    834  switch (t)
    835  {
    836  case value_t::object:
    837  {
    838  object = create<object_t>();
    839  break;
    840  }
    841 
    842  case value_t::array:
    843  {
    844  array = create<array_t>();
    845  break;
    846  }
    847 
    848  case value_t::string:
    849  {
    850  string = create<string_t>("");
    851  break;
    852  }
    853 
    854  case value_t::boolean:
    855  {
    856  boolean = boolean_t(false);
    857  break;
    858  }
    859 
    860  case value_t::number_integer:
    861  {
    862  number_integer = number_integer_t(0);
    863  break;
    864  }
    865 
    866  case value_t::number_unsigned:
    867  {
    868  number_unsigned = number_unsigned_t(0);
    869  break;
    870  }
    871 
    872  case value_t::number_float:
    873  {
    874  number_float = number_float_t(0.0);
    875  break;
    876  }
    877 
    878  default:
    879  {
    880  break;
    881  }
    882  }
    883  }
    884 
    886  json_value(const string_t& value)
    887  {
    888  string = create<string_t>(value);
    889  }
    890 
    892  json_value(const object_t& value)
    893  {
    894  object = create<object_t>(value);
    895  }
    896 
    898  json_value(const array_t& value)
    899  {
    900  array = create<array_t>(value);
    901  }
    902  };
    903 
    904 
    905  public:
    907  // JSON parser callback //
    909 
    918  enum class parse_event_t : uint8_t
    919  {
    921  object_start,
    923  object_end,
    925  array_start,
    927  array_end,
    929  key,
    931  value
    932  };
    933 
    983  using parser_callback_t = std::function<bool(int depth, parse_event_t event, basic_json& parsed)>;
    984 
    985 
    987  // constructors //
    989 
    992 
    1033  : m_type(value_type), m_value(value_type)
    1034  {}
    1035 
    1060  basic_json() = default;
    1061 
    1084  basic_json(std::nullptr_t) noexcept
    1085  : basic_json(value_t::null)
    1086  {}
    1087 
    1107  basic_json(const object_t& val)
    1108  : m_type(value_t::object), m_value(val)
    1109  {}
    1110 
    1137  template <class CompatibleObjectType, typename
    1138  std::enable_if<
    1139  std::is_constructible<typename object_t::key_type, typename CompatibleObjectType::key_type>::value and
    1140  std::is_constructible<basic_json, typename CompatibleObjectType::mapped_type>::value, int>::type
    1141  = 0>
    1142  basic_json(const CompatibleObjectType& val)
    1143  : m_type(value_t::object)
    1144  {
    1145  using std::begin;
    1146  using std::end;
    1147  m_value.object = create<object_t>(begin(val), end(val));
    1148  }
    1149 
    1169  basic_json(const array_t& val)
    1170  : m_type(value_t::array), m_value(val)
    1171  {}
    1172 
    1199  template <class CompatibleArrayType, typename
    1200  std::enable_if<
    1201  not std::is_same<CompatibleArrayType, typename basic_json_t::iterator>::value and
    1202  not std::is_same<CompatibleArrayType, typename basic_json_t::const_iterator>::value and
    1203  not std::is_same<CompatibleArrayType, typename basic_json_t::reverse_iterator>::value and
    1204  not std::is_same<CompatibleArrayType, typename basic_json_t::const_reverse_iterator>::value and
    1205  not std::is_same<CompatibleArrayType, typename array_t::iterator>::value and
    1206  not std::is_same<CompatibleArrayType, typename array_t::const_iterator>::value and
    1207  std::is_constructible<basic_json, typename CompatibleArrayType::value_type>::value, int>::type
    1208  = 0>
    1209  basic_json(const CompatibleArrayType& val)
    1210  : m_type(value_t::array)
    1211  {
    1212  using std::begin;
    1213  using std::end;
    1214  m_value.array = create<array_t>(begin(val), end(val));
    1215  }
    1216 
    1238  basic_json(const string_t& val)
    1239  : m_type(value_t::string), m_value(val)
    1240  {}
    1241 
    1262  basic_json(const typename string_t::value_type* val)
    1263  : basic_json(string_t(val))
    1264  {}
    1265 
    1289  template <class CompatibleStringType, typename
    1290  std::enable_if<
    1291  std::is_constructible<string_t, CompatibleStringType>::value, int>::type
    1292  = 0>
    1293  basic_json(const CompatibleStringType& val)
    1294  : basic_json(string_t(val))
    1295  {}
    1296 
    1311  basic_json(boolean_t val) noexcept
    1312  : m_type(value_t::boolean), m_value(val)
    1313  {}
    1314 
    1338  template<typename T,
    1339  typename std::enable_if<
    1340  not (std::is_same<T, int>::value)
    1341  and std::is_same<T, number_integer_t>::value
    1342  , int>::type
    1343  = 0>
    1344  basic_json(const number_integer_t val) noexcept
    1345  : m_type(value_t::number_integer), m_value(val)
    1346  {}
    1347 
    1373  basic_json(const int val) noexcept
    1374  : m_type(value_t::number_integer),
    1375  m_value(static_cast<number_integer_t>(val))
    1376  {}
    1377 
    1403  template<typename CompatibleNumberIntegerType, typename
    1404  std::enable_if<
    1405  std::is_constructible<number_integer_t, CompatibleNumberIntegerType>::value and
    1406  std::numeric_limits<CompatibleNumberIntegerType>::is_integer and
    1407  std::numeric_limits<CompatibleNumberIntegerType>::is_signed,
    1408  CompatibleNumberIntegerType>::type
    1409  = 0>
    1410  basic_json(const CompatibleNumberIntegerType val) noexcept
    1411  : m_type(value_t::number_integer),
    1412  m_value(static_cast<number_integer_t>(val))
    1413  {}
    1414 
    1432  template<typename T,
    1433  typename std::enable_if<
    1434  not (std::is_same<T, int>::value)
    1435  and std::is_same<T, number_unsigned_t>::value
    1436  , int>::type
    1437  = 0>
    1438  basic_json(const number_unsigned_t val) noexcept
    1439  : m_type(value_t::number_unsigned), m_value(val)
    1440  {}
    1441 
    1462  template < typename CompatibleNumberUnsignedType, typename
    1463  std::enable_if <
    1464  std::is_constructible<number_unsigned_t, CompatibleNumberUnsignedType>::value and
    1465  std::numeric_limits<CompatibleNumberUnsignedType>::is_integer and
    1466  !std::numeric_limits<CompatibleNumberUnsignedType>::is_signed,
    1467  CompatibleNumberUnsignedType >::type
    1468  = 0 >
    1469  basic_json(const CompatibleNumberUnsignedType val) noexcept
    1470  : m_type(value_t::number_unsigned),
    1471  m_value(static_cast<number_unsigned_t>(val))
    1472  {}
    1473 
    1498  basic_json(const number_float_t val) noexcept
    1499  : m_type(value_t::number_float), m_value(val)
    1500  {
    1501  // replace infinity and NAN by null
    1502  if (not std::isfinite(val))
    1503  {
    1504  m_type = value_t::null;
    1505  m_value = json_value();
    1506  }
    1507  }
    1508 
    1539  template<typename CompatibleNumberFloatType, typename = typename
    1540  std::enable_if<
    1541  std::is_constructible<number_float_t, CompatibleNumberFloatType>::value and
    1542  std::is_floating_point<CompatibleNumberFloatType>::value>::type
    1543  >
    1544  basic_json(const CompatibleNumberFloatType val) noexcept
    1545  : basic_json(number_float_t(val))
    1546  {}
    1547 
    1617  basic_json(std::initializer_list<basic_json> init,
    1618  bool type_deduction = true,
    1619  value_t manual_type = value_t::array)
    1620  {
    1621  // the initializer list could describe an object
    1622  bool is_an_object = true;
    1623 
    1624  // check if each element is an array with two elements whose first
    1625  // element is a string
    1626  for (const auto& element : init)
    1627  {
    1628  if (not element.is_array() or element.size() != 2
    1629  or not element[0].is_string())
    1630  {
    1631  // we found an element that makes it impossible to use the
    1632  // initializer list as object
    1633  is_an_object = false;
    1634  break;
    1635  }
    1636  }
    1637 
    1638  // adjust type if type deduction is not wanted
    1639  if (not type_deduction)
    1640  {
    1641  // if array is wanted, do not create an object though possible
    1642  if (manual_type == value_t::array)
    1643  {
    1644  is_an_object = false;
    1645  }
    1646 
    1647  // if object is wanted but impossible, throw an exception
    1648  if (manual_type == value_t::object and not is_an_object)
    1649  {
    1650  throw std::domain_error("cannot create object from initializer list");
    1651  }
    1652  }
    1653 
    1654  if (is_an_object)
    1655  {
    1656  // the initializer list is a list of pairs -> create object
    1657  m_type = value_t::object;
    1658  m_value = value_t::object;
    1659 
    1660  assert(m_value.object != nullptr);
    1661 
    1662  for (auto& element : init)
    1663  {
    1664  m_value.object->emplace(*(element[0].m_value.string), element[1]);
    1665  }
    1666  }
    1667  else
    1668  {
    1669  // the initializer list describes an array -> create array
    1670  m_type = value_t::array;
    1671  m_value.array = create<array_t>(init);
    1672  }
    1673  }
    1674 
    1709  static basic_json array(std::initializer_list<basic_json> init =
    1710  std::initializer_list<basic_json>())
    1711  {
    1712  return basic_json(init, false, value_t::array);
    1713  }
    1714 
    1749  static basic_json object(std::initializer_list<basic_json> init =
    1750  std::initializer_list<basic_json>())
    1751  {
    1752  return basic_json(init, false, value_t::object);
    1753  }
    1754 
    1773  basic_json(size_type cnt, const basic_json& val)
    1774  : m_type(value_t::array)
    1775  {
    1776  m_value.array = create<array_t>(cnt, val);
    1777  }
    1778 
    1813  template <class InputIT, typename
    1814  std::enable_if<
    1815  std::is_same<InputIT, typename basic_json_t::iterator>::value or
    1816  std::is_same<InputIT, typename basic_json_t::const_iterator>::value
    1817  , int>::type
    1818  = 0>
    1819  basic_json(InputIT first, InputIT last) : m_type(first.m_object->m_type)
    1820  {
    1821  // make sure iterator fits the current value
    1822  if (first.m_object != last.m_object)
    1823  {
    1824  throw std::domain_error("iterators are not compatible");
    1825  }
    1826 
    1827  // check if iterator range is complete for primitive values
    1828  switch (m_type)
    1829  {
    1830  case value_t::boolean:
    1831  case value_t::number_float:
    1832  case value_t::number_integer:
    1833  case value_t::number_unsigned:
    1834  case value_t::string:
    1835  {
    1836  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    1837  {
    1838  throw std::out_of_range("iterators out of range");
    1839  }
    1840  break;
    1841  }
    1842 
    1843  default:
    1844  {
    1845  break;
    1846  }
    1847  }
    1848 
    1849  switch (m_type)
    1850  {
    1851  case value_t::number_integer:
    1852  {
    1853  assert(first.m_object != nullptr);
    1854  m_value.number_integer = first.m_object->m_value.number_integer;
    1855  break;
    1856  }
    1857 
    1858  case value_t::number_unsigned:
    1859  {
    1860  assert(first.m_object != nullptr);
    1861  m_value.number_unsigned = first.m_object->m_value.number_unsigned;
    1862  break;
    1863  }
    1864 
    1865  case value_t::number_float:
    1866  {
    1867  assert(first.m_object != nullptr);
    1868  m_value.number_float = first.m_object->m_value.number_float;
    1869  break;
    1870  }
    1871 
    1872  case value_t::boolean:
    1873  {
    1874  assert(first.m_object != nullptr);
    1875  m_value.boolean = first.m_object->m_value.boolean;
    1876  break;
    1877  }
    1878 
    1879  case value_t::string:
    1880  {
    1881  assert(first.m_object != nullptr);
    1882  m_value = *first.m_object->m_value.string;
    1883  break;
    1884  }
    1885 
    1886  case value_t::object:
    1887  {
    1888  m_value.object = create<object_t>(first.m_it.object_iterator, last.m_it.object_iterator);
    1889  break;
    1890  }
    1891 
    1892  case value_t::array:
    1893  {
    1894  m_value.array = create<array_t>(first.m_it.array_iterator, last.m_it.array_iterator);
    1895  break;
    1896  }
    1897 
    1898  default:
    1899  {
    1900  assert(first.m_object != nullptr);
    1901  throw std::domain_error("cannot use construct with iterators from " + first.m_object->type_name());
    1902  }
    1903  }
    1904  }
    1905 
    1926  explicit basic_json(std::istream& i, parser_callback_t cb = nullptr)
    1927  {
    1928  *this = parser(i, cb).parse();
    1929  }
    1930 
    1932  // other constructors and destructor //
    1934 
    1957  basic_json(const basic_json& other)
    1958  : m_type(other.m_type)
    1959  {
    1960  switch (m_type)
    1961  {
    1962  case value_t::object:
    1963  {
    1964  assert(other.m_value.object != nullptr);
    1965  m_value = *other.m_value.object;
    1966  break;
    1967  }
    1968 
    1969  case value_t::array:
    1970  {
    1971  assert(other.m_value.array != nullptr);
    1972  m_value = *other.m_value.array;
    1973  break;
    1974  }
    1975 
    1976  case value_t::string:
    1977  {
    1978  assert(other.m_value.string != nullptr);
    1979  m_value = *other.m_value.string;
    1980  break;
    1981  }
    1982 
    1983  case value_t::boolean:
    1984  {
    1985  m_value = other.m_value.boolean;
    1986  break;
    1987  }
    1988 
    1989  case value_t::number_integer:
    1990  {
    1991  m_value = other.m_value.number_integer;
    1992  break;
    1993  }
    1994 
    1995  case value_t::number_unsigned:
    1996  {
    1997  m_value = other.m_value.number_unsigned;
    1998  break;
    1999  }
    2000 
    2001  case value_t::number_float:
    2002  {
    2003  m_value = other.m_value.number_float;
    2004  break;
    2005  }
    2006 
    2007  default:
    2008  {
    2009  break;
    2010  }
    2011  }
    2012  }
    2013 
    2032  basic_json(basic_json&& other) noexcept
    2033  : m_type(std::move(other.m_type)),
    2034  m_value(std::move(other.m_value))
    2035  {
    2036  // invalidate payload
    2037  other.m_type = value_t::null;
    2038  other.m_value = {};
    2039  }
    2040 
    2064  reference& operator=(basic_json other) noexcept (
    2065  std::is_nothrow_move_constructible<value_t>::value and
    2066  std::is_nothrow_move_assignable<value_t>::value and
    2067  std::is_nothrow_move_constructible<json_value>::value and
    2068  std::is_nothrow_move_assignable<json_value>::value
    2069  )
    2070  {
    2071  using std::swap;
    2072  swap(m_type, other.m_type);
    2073  swap(m_value, other.m_value);
    2074  return *this;
    2075  }
    2076 
    2093  {
    2094  switch (m_type)
    2095  {
    2096  case value_t::object:
    2097  {
    2098  AllocatorType<object_t> alloc;
    2099  alloc.destroy(m_value.object);
    2100  alloc.deallocate(m_value.object, 1);
    2101  break;
    2102  }
    2103 
    2104  case value_t::array:
    2105  {
    2106  AllocatorType<array_t> alloc;
    2107  alloc.destroy(m_value.array);
    2108  alloc.deallocate(m_value.array, 1);
    2109  break;
    2110  }
    2111 
    2112  case value_t::string:
    2113  {
    2114  AllocatorType<string_t> alloc;
    2115  alloc.destroy(m_value.string);
    2116  alloc.deallocate(m_value.string, 1);
    2117  break;
    2118  }
    2119 
    2120  default:
    2121  {
    2122  // all other types need no specific destructor
    2123  break;
    2124  }
    2125  }
    2126  }
    2127 
    2129 
    2130  public:
    2132  // object inspection //
    2134 
    2137 
    2161  string_t dump(const int indent = -1) const
    2162  {
    2163  std::stringstream ss;
    2164 
    2165  if (indent >= 0)
    2166  {
    2167  dump(ss, true, static_cast<unsigned int>(indent));
    2168  }
    2169  else
    2170  {
    2171  dump(ss, false, 0);
    2172  }
    2173 
    2174  return ss.str();
    2175  }
    2176 
    2195  constexpr value_t type() const noexcept
    2196  {
    2197  return m_type;
    2198  }
    2199 
    2225  constexpr bool is_primitive() const noexcept
    2226  {
    2227  return is_null() or is_string() or is_boolean() or is_number();
    2228  }
    2229 
    2252  constexpr bool is_structured() const noexcept
    2253  {
    2254  return is_array() or is_object();
    2255  }
    2256 
    2274  constexpr bool is_null() const noexcept
    2275  {
    2276  return m_type == value_t::null;
    2277  }
    2278 
    2296  constexpr bool is_boolean() const noexcept
    2297  {
    2298  return m_type == value_t::boolean;
    2299  }
    2300 
    2326  constexpr bool is_number() const noexcept
    2327  {
    2328  return is_number_integer() or is_number_float();
    2329  }
    2330 
    2355  constexpr bool is_number_integer() const noexcept
    2356  {
    2357  return m_type == value_t::number_integer or m_type == value_t::number_unsigned;
    2358  }
    2359 
    2383  constexpr bool is_number_unsigned() const noexcept
    2384  {
    2385  return m_type == value_t::number_unsigned;
    2386  }
    2387 
    2411  constexpr bool is_number_float() const noexcept
    2412  {
    2413  return m_type == value_t::number_float;
    2414  }
    2415 
    2433  constexpr bool is_object() const noexcept
    2434  {
    2435  return m_type == value_t::object;
    2436  }
    2437 
    2455  constexpr bool is_array() const noexcept
    2456  {
    2457  return m_type == value_t::array;
    2458  }
    2459 
    2477  constexpr bool is_string() const noexcept
    2478  {
    2479  return m_type == value_t::string;
    2480  }
    2481 
    2504  constexpr bool is_discarded() const noexcept
    2505  {
    2506  return m_type == value_t::discarded;
    2507  }
    2508 
    2527  constexpr operator value_t() const noexcept
    2528  {
    2529  return m_type;
    2530  }
    2531 
    2533 
    2534  private:
    2536  // value access //
    2538 
    2540  template <class T, typename
    2541  std::enable_if<
    2542  std::is_convertible<typename object_t::key_type, typename T::key_type>::value and
    2543  std::is_convertible<basic_json_t, typename T::mapped_type>::value
    2544  , int>::type = 0>
    2545  T get_impl(T*) const
    2546  {
    2547  if (is_object())
    2548  {
    2549  assert(m_value.object != nullptr);
    2550  return T(m_value.object->begin(), m_value.object->end());
    2551  }
    2552  else
    2553  {
    2554  throw std::domain_error("type must be object, but is " + type_name());
    2555  }
    2556  }
    2557 
    2559  object_t get_impl(object_t*) const
    2560  {
    2561  if (is_object())
    2562  {
    2563  assert(m_value.object != nullptr);
    2564  return *(m_value.object);
    2565  }
    2566  else
    2567  {
    2568  throw std::domain_error("type must be object, but is " + type_name());
    2569  }
    2570  }
    2571 
    2573  template <class T, typename
    2574  std::enable_if<
    2575  std::is_convertible<basic_json_t, typename T::value_type>::value and
    2576  not std::is_same<basic_json_t, typename T::value_type>::value and
    2577  not std::is_arithmetic<T>::value and
    2578  not std::is_convertible<std::string, T>::value and
    2579  not has_mapped_type<T>::value
    2580  , int>::type = 0>
    2581  T get_impl(T*) const
    2582  {
    2583  if (is_array())
    2584  {
    2585  T to_vector;
    2586  assert(m_value.array != nullptr);
    2587  std::transform(m_value.array->begin(), m_value.array->end(),
    2588  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2589  {
    2590  return i.get<typename T::value_type>();
    2591  });
    2592  return to_vector;
    2593  }
    2594  else
    2595  {
    2596  throw std::domain_error("type must be array, but is " + type_name());
    2597  }
    2598  }
    2599 
    2601  template <class T, typename
    2602  std::enable_if<
    2603  std::is_convertible<basic_json_t, T>::value and
    2604  not std::is_same<basic_json_t, T>::value
    2605  , int>::type = 0>
    2606  std::vector<T> get_impl(std::vector<T>*) const
    2607  {
    2608  if (is_array())
    2609  {
    2610  std::vector<T> to_vector;
    2611  assert(m_value.array != nullptr);
    2612  to_vector.reserve(m_value.array->size());
    2613  std::transform(m_value.array->begin(), m_value.array->end(),
    2614  std::inserter(to_vector, to_vector.end()), [](basic_json i)
    2615  {
    2616  return i.get<T>();
    2617  });
    2618  return to_vector;
    2619  }
    2620  else
    2621  {
    2622  throw std::domain_error("type must be array, but is " + type_name());
    2623  }
    2624  }
    2625 
    2627  template <class T, typename
    2628  std::enable_if<
    2629  std::is_same<basic_json, typename T::value_type>::value and
    2630  not has_mapped_type<T>::value
    2631  , int>::type = 0>
    2632  T get_impl(T*) const
    2633  {
    2634  if (is_array())
    2635  {
    2636  assert(m_value.array != nullptr);
    2637  return T(m_value.array->begin(), m_value.array->end());
    2638  }
    2639  else
    2640  {
    2641  throw std::domain_error("type must be array, but is " + type_name());
    2642  }
    2643  }
    2644 
    2646  array_t get_impl(array_t*) const
    2647  {
    2648  if (is_array())
    2649  {
    2650  assert(m_value.array != nullptr);
    2651  return *(m_value.array);
    2652  }
    2653  else
    2654  {
    2655  throw std::domain_error("type must be array, but is " + type_name());
    2656  }
    2657  }
    2658 
    2660  template <typename T, typename
    2661  std::enable_if<
    2662  std::is_convertible<string_t, T>::value
    2663  , int>::type = 0>
    2664  T get_impl(T*) const
    2665  {
    2666  if (is_string())
    2667  {
    2668  assert(m_value.string != nullptr);
    2669  return *m_value.string;
    2670  }
    2671  else
    2672  {
    2673  throw std::domain_error("type must be string, but is " + type_name());
    2674  }
    2675  }
    2676 
    2678  template<typename T, typename
    2679  std::enable_if<
    2680  std::is_arithmetic<T>::value
    2681  , int>::type = 0>
    2682  T get_impl(T*) const
    2683  {
    2684  switch (m_type)
    2685  {
    2686  case value_t::number_integer:
    2687  {
    2688  return static_cast<T>(m_value.number_integer);
    2689  }
    2690 
    2691  case value_t::number_unsigned:
    2692  {
    2693  return static_cast<T>(m_value.number_unsigned);
    2694  }
    2695 
    2696  case value_t::number_float:
    2697  {
    2698  return static_cast<T>(m_value.number_float);
    2699  }
    2700 
    2701  default:
    2702  {
    2703  throw std::domain_error("type must be number, but is " + type_name());
    2704  }
    2705  }
    2706  }
    2707 
    2709  constexpr boolean_t get_impl(boolean_t*) const
    2710  {
    2711  return is_boolean()
    2712  ? m_value.boolean
    2713  : throw std::domain_error("type must be boolean, but is " + type_name());
    2714  }
    2715 
    2717  object_t* get_impl_ptr(object_t*) noexcept
    2718  {
    2719  return is_object() ? m_value.object : nullptr;
    2720  }
    2721 
    2723  constexpr const object_t* get_impl_ptr(const object_t*) const noexcept
    2724  {
    2725  return is_object() ? m_value.object : nullptr;
    2726  }
    2727 
    2729  array_t* get_impl_ptr(array_t*) noexcept
    2730  {
    2731  return is_array() ? m_value.array : nullptr;
    2732  }
    2733 
    2735  constexpr const array_t* get_impl_ptr(const array_t*) const noexcept
    2736  {
    2737  return is_array() ? m_value.array : nullptr;
    2738  }
    2739 
    2741  string_t* get_impl_ptr(string_t*) noexcept
    2742  {
    2743  return is_string() ? m_value.string : nullptr;
    2744  }
    2745 
    2747  constexpr const string_t* get_impl_ptr(const string_t*) const noexcept
    2748  {
    2749  return is_string() ? m_value.string : nullptr;
    2750  }
    2751 
    2753  boolean_t* get_impl_ptr(boolean_t*) noexcept
    2754  {
    2755  return is_boolean() ? &m_value.boolean : nullptr;
    2756  }
    2757 
    2759  constexpr const boolean_t* get_impl_ptr(const boolean_t*) const noexcept
    2760  {
    2761  return is_boolean() ? &m_value.boolean : nullptr;
    2762  }
    2763 
    2765  number_integer_t* get_impl_ptr(number_integer_t*) noexcept
    2766  {
    2767  return is_number_integer() ? &m_value.number_integer : nullptr;
    2768  }
    2769 
    2771  constexpr const number_integer_t* get_impl_ptr(const number_integer_t*) const noexcept
    2772  {
    2773  return is_number_integer() ? &m_value.number_integer : nullptr;
    2774  }
    2775 
    2777  number_unsigned_t* get_impl_ptr(number_unsigned_t*) noexcept
    2778  {
    2779  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2780  }
    2781 
    2783  constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t*) const noexcept
    2784  {
    2785  return is_number_unsigned() ? &m_value.number_unsigned : nullptr;
    2786  }
    2787 
    2789  number_float_t* get_impl_ptr(number_float_t*) noexcept
    2790  {
    2791  return is_number_float() ? &m_value.number_float : nullptr;
    2792  }
    2793 
    2795  constexpr const number_float_t* get_impl_ptr(const number_float_t*) const noexcept
    2796  {
    2797  return is_number_float() ? &m_value.number_float : nullptr;
    2798  }
    2799 
    2811  template<typename ReferenceType, typename ThisType>
    2812  static ReferenceType get_ref_impl(ThisType& obj)
    2813  {
    2814  // delegate the call to get_ptr<>()
    2815  using PointerType = typename std::add_pointer<ReferenceType>::type;
    2816  auto ptr = obj.template get_ptr<PointerType>();
    2817 
    2818  if (ptr != nullptr)
    2819  {
    2820  return *ptr;
    2821  }
    2822  else
    2823  {
    2824  throw std::domain_error("incompatible ReferenceType for get_ref, actual type is " +
    2825  obj.type_name());
    2826  }
    2827  }
    2828 
    2829  public:
    2830 
    2833 
    2867  template<typename ValueType, typename
    2868  std::enable_if<
    2869  not std::is_pointer<ValueType>::value
    2870  , int>::type = 0>
    2871  ValueType get() const
    2872  {
    2873  return get_impl(static_cast<ValueType*>(nullptr));
    2874  }
    2875 
    2902  template<typename PointerType, typename
    2903  std::enable_if<
    2904  std::is_pointer<PointerType>::value
    2905  , int>::type = 0>
    2906  PointerType get() noexcept
    2907  {
    2908  // delegate the call to get_ptr
    2909  return get_ptr<PointerType>();
    2910  }
    2911 
    2916  template<typename PointerType, typename
    2917  std::enable_if<
    2918  std::is_pointer<PointerType>::value
    2919  , int>::type = 0>
    2920  constexpr const PointerType get() const noexcept
    2921  {
    2922  // delegate the call to get_ptr
    2923  return get_ptr<PointerType>();
    2924  }
    2925 
    2951  template<typename PointerType, typename
    2952  std::enable_if<
    2953  std::is_pointer<PointerType>::value
    2954  , int>::type = 0>
    2955  PointerType get_ptr() noexcept
    2956  {
    2957  // delegate the call to get_impl_ptr<>()
    2958  return get_impl_ptr(static_cast<PointerType>(nullptr));
    2959  }
    2960 
    2965  template<typename PointerType, typename
    2966  std::enable_if<
    2967  std::is_pointer<PointerType>::value
    2968  and std::is_const<typename std::remove_pointer<PointerType>::type>::value
    2969  , int>::type = 0>
    2970  constexpr const PointerType get_ptr() const noexcept
    2971  {
    2972  // delegate the call to get_impl_ptr<>() const
    2973  return get_impl_ptr(static_cast<const PointerType>(nullptr));
    2974  }
    2975 
    3002  template<typename ReferenceType, typename
    3003  std::enable_if<
    3004  std::is_reference<ReferenceType>::value
    3005  , int>::type = 0>
    3006  ReferenceType get_ref()
    3007  {
    3008  // delegate call to get_ref_impl
    3009  return get_ref_impl<ReferenceType>(*this);
    3010  }
    3011 
    3016  template<typename ReferenceType, typename
    3017  std::enable_if<
    3018  std::is_reference<ReferenceType>::value
    3019  and std::is_const<typename std::remove_reference<ReferenceType>::type>::value
    3020  , int>::type = 0>
    3021  ReferenceType get_ref() const
    3022  {
    3023  // delegate call to get_ref_impl
    3024  return get_ref_impl<ReferenceType>(*this);
    3025  }
    3026 
    3055  template < typename ValueType, typename
    3056  std::enable_if <
    3057  not std::is_pointer<ValueType>::value
    3058  and not std::is_same<ValueType, typename string_t::value_type>::value
    3059 #ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
    3060  and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
    3061 #endif
    3062  , int >::type = 0 >
    3063  operator ValueType() const
    3064  {
    3065  // delegate the call to get<>() const
    3066  return get<ValueType>();
    3067  }
    3068 
    3070 
    3071 
    3073  // element access //
    3075 
    3078 
    3102  {
    3103  // at only works for arrays
    3104  if (is_array())
    3105  {
    3106  try
    3107  {
    3108  assert(m_value.array != nullptr);
    3109  return m_value.array->at(idx);
    3110  }
    3111  catch (std::out_of_range&)
    3112  {
    3113  // create better exception explanation
    3114  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3115  }
    3116  }
    3117  else
    3118  {
    3119  throw std::domain_error("cannot use at() with " + type_name());
    3120  }
    3121  }
    3122 
    3146  {
    3147  // at only works for arrays
    3148  if (is_array())
    3149  {
    3150  try
    3151  {
    3152  assert(m_value.array != nullptr);
    3153  return m_value.array->at(idx);
    3154  }
    3155  catch (std::out_of_range&)
    3156  {
    3157  // create better exception explanation
    3158  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    3159  }
    3160  }
    3161  else
    3162  {
    3163  throw std::domain_error("cannot use at() with " + type_name());
    3164  }
    3165  }
    3166 
    3193  reference at(const typename object_t::key_type& key)
    3194  {
    3195  // at only works for objects
    3196  if (is_object())
    3197  {
    3198  try
    3199  {
    3200  assert(m_value.object != nullptr);
    3201  return m_value.object->at(key);
    3202  }
    3203  catch (std::out_of_range&)
    3204  {
    3205  // create better exception explanation
    3206  throw std::out_of_range("key '" + key + "' not found");
    3207  }
    3208  }
    3209  else
    3210  {
    3211  throw std::domain_error("cannot use at() with " + type_name());
    3212  }
    3213  }
    3214 
    3241  const_reference at(const typename object_t::key_type& key) const
    3242  {
    3243  // at only works for objects
    3244  if (is_object())
    3245  {
    3246  try
    3247  {
    3248  assert(m_value.object != nullptr);
    3249  return m_value.object->at(key);
    3250  }
    3251  catch (std::out_of_range&)
    3252  {
    3253  // create better exception explanation
    3254  throw std::out_of_range("key '" + key + "' not found");
    3255  }
    3256  }
    3257  else
    3258  {
    3259  throw std::domain_error("cannot use at() with " + type_name());
    3260  }
    3261  }
    3262 
    3289  {
    3290  // implicitly convert null value to an empty array
    3291  if (is_null())
    3292  {
    3293  m_type = value_t::array;
    3294  m_value.array = create<array_t>();
    3295  }
    3296 
    3297  // operator[] only works for arrays
    3298  if (is_array())
    3299  {
    3300  // fill up array with null values until given idx is reached
    3301  assert(m_value.array != nullptr);
    3302  for (size_t i = m_value.array->size(); i <= idx; ++i)
    3303  {
    3304  m_value.array->push_back(basic_json());
    3305  }
    3306 
    3307  return m_value.array->operator[](idx);
    3308  }
    3309  else
    3310  {
    3311  throw std::domain_error("cannot use operator[] with " + type_name());
    3312  }
    3313  }
    3314 
    3335  {
    3336  // const operator[] only works for arrays
    3337  if (is_array())
    3338  {
    3339  assert(m_value.array != nullptr);
    3340  return m_value.array->operator[](idx);
    3341  }
    3342  else
    3343  {
    3344  throw std::domain_error("cannot use operator[] with " + type_name());
    3345  }
    3346  }
    3347 
    3375  reference operator[](const typename object_t::key_type& key)
    3376  {
    3377  // implicitly convert null value to an empty object
    3378  if (is_null())
    3379  {
    3380  m_type = value_t::object;
    3381  m_value.object = create<object_t>();
    3382  }
    3383 
    3384  // operator[] only works for objects
    3385  if (is_object())
    3386  {
    3387  assert(m_value.object != nullptr);
    3388  return m_value.object->operator[](key);
    3389  }
    3390  else
    3391  {
    3392  throw std::domain_error("cannot use operator[] with " + type_name());
    3393  }
    3394  }
    3395 
    3423  const_reference operator[](const typename object_t::key_type& key) const
    3424  {
    3425  // const operator[] only works for objects
    3426  if (is_object())
    3427  {
    3428  assert(m_value.object != nullptr);
    3429  assert(m_value.object->find(key) != m_value.object->end());
    3430  return m_value.object->find(key)->second;
    3431  }
    3432  else
    3433  {
    3434  throw std::domain_error("cannot use operator[] with " + type_name());
    3435  }
    3436  }
    3437 
    3465  template<typename T, std::size_t n>
    3466  reference operator[](T * (&key)[n])
    3467  {
    3468  return operator[](static_cast<const T>(key));
    3469  }
    3470 
    3500  template<typename T, std::size_t n>
    3501  const_reference operator[](T * (&key)[n]) const
    3502  {
    3503  return operator[](static_cast<const T>(key));
    3504  }
    3505 
    3533  template<typename T>
    3535  {
    3536  // implicitly convert null to object
    3537  if (is_null())
    3538  {
    3539  m_type = value_t::object;
    3540  m_value = value_t::object;
    3541  }
    3542 
    3543  // at only works for objects
    3544  if (is_object())
    3545  {
    3546  assert(m_value.object != nullptr);
    3547  return m_value.object->operator[](key);
    3548  }
    3549  else
    3550  {
    3551  throw std::domain_error("cannot use operator[] with " + type_name());
    3552  }
    3553  }
    3554 
    3582  template<typename T>
    3584  {
    3585  // at only works for objects
    3586  if (is_object())
    3587  {
    3588  assert(m_value.object != nullptr);
    3589  assert(m_value.object->find(key) != m_value.object->end());
    3590  return m_value.object->find(key)->second;
    3591  }
    3592  else
    3593  {
    3594  throw std::domain_error("cannot use operator[] with " + type_name());
    3595  }
    3596  }
    3597 
    3646  template <class ValueType, typename
    3647  std::enable_if<
    3648  std::is_convertible<basic_json_t, ValueType>::value
    3649  , int>::type = 0>
    3650  ValueType value(const typename object_t::key_type& key, ValueType default_value) const
    3651  {
    3652  // at only works for objects
    3653  if (is_object())
    3654  {
    3655  // if key is found, return value and given default value otherwise
    3656  const auto it = find(key);
    3657  if (it != end())
    3658  {
    3659  return *it;
    3660  }
    3661  else
    3662  {
    3663  return default_value;
    3664  }
    3665  }
    3666  else
    3667  {
    3668  throw std::domain_error("cannot use value() with " + type_name());
    3669  }
    3670  }
    3671 
    3676  string_t value(const typename object_t::key_type& key, const char* default_value) const
    3677  {
    3678  return value(key, string_t(default_value));
    3679  }
    3680 
    3706  {
    3707  return *begin();
    3708  }
    3709 
    3714  {
    3715  return *cbegin();
    3716  }
    3717 
    3748  {
    3749  auto tmp = end();
    3750  --tmp;
    3751  return *tmp;
    3752  }
    3753 
    3758  {
    3759  auto tmp = cend();
    3760  --tmp;
    3761  return *tmp;
    3762  }
    3763 
    3809  template <class InteratorType, typename
    3810  std::enable_if<
    3811  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3812  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3813  , int>::type
    3814  = 0>
    3815  InteratorType erase(InteratorType pos)
    3816  {
    3817  // make sure iterator fits the current value
    3818  if (this != pos.m_object)
    3819  {
    3820  throw std::domain_error("iterator does not fit current value");
    3821  }
    3822 
    3823  InteratorType result = end();
    3824 
    3825  switch (m_type)
    3826  {
    3827  case value_t::boolean:
    3828  case value_t::number_float:
    3829  case value_t::number_integer:
    3830  case value_t::number_unsigned:
    3831  case value_t::string:
    3832  {
    3833  if (not pos.m_it.primitive_iterator.is_begin())
    3834  {
    3835  throw std::out_of_range("iterator out of range");
    3836  }
    3837 
    3838  if (is_string())
    3839  {
    3840  delete m_value.string;
    3841  m_value.string = nullptr;
    3842  }
    3843 
    3844  m_type = value_t::null;
    3845  break;
    3846  }
    3847 
    3848  case value_t::object:
    3849  {
    3850  assert(m_value.object != nullptr);
    3851  result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator);
    3852  break;
    3853  }
    3854 
    3855  case value_t::array:
    3856  {
    3857  assert(m_value.array != nullptr);
    3858  result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator);
    3859  break;
    3860  }
    3861 
    3862  default:
    3863  {
    3864  throw std::domain_error("cannot use erase() with " + type_name());
    3865  }
    3866  }
    3867 
    3868  return result;
    3869  }
    3870 
    3917  template <class InteratorType, typename
    3918  std::enable_if<
    3919  std::is_same<InteratorType, typename basic_json_t::iterator>::value or
    3920  std::is_same<InteratorType, typename basic_json_t::const_iterator>::value
    3921  , int>::type
    3922  = 0>
    3923  InteratorType erase(InteratorType first, InteratorType last)
    3924  {
    3925  // make sure iterator fits the current value
    3926  if (this != first.m_object or this != last.m_object)
    3927  {
    3928  throw std::domain_error("iterators do not fit current value");
    3929  }
    3930 
    3931  InteratorType result = end();
    3932 
    3933  switch (m_type)
    3934  {
    3935  case value_t::boolean:
    3936  case value_t::number_float:
    3937  case value_t::number_integer:
    3938  case value_t::number_unsigned:
    3939  case value_t::string:
    3940  {
    3941  if (not first.m_it.primitive_iterator.is_begin() or not last.m_it.primitive_iterator.is_end())
    3942  {
    3943  throw std::out_of_range("iterators out of range");
    3944  }
    3945 
    3946  if (is_string())
    3947  {
    3948  delete m_value.string;
    3949  m_value.string = nullptr;
    3950  }
    3951 
    3952  m_type = value_t::null;
    3953  break;
    3954  }
    3955 
    3956  case value_t::object:
    3957  {
    3958  assert(m_value.object != nullptr);
    3959  result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator,
    3960  last.m_it.object_iterator);
    3961  break;
    3962  }
    3963 
    3964  case value_t::array:
    3965  {
    3966  assert(m_value.array != nullptr);
    3967  result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator,
    3968  last.m_it.array_iterator);
    3969  break;
    3970  }
    3971 
    3972  default:
    3973  {
    3974  throw std::domain_error("cannot use erase() with " + type_name());
    3975  }
    3976  }
    3977 
    3978  return result;
    3979  }
    3980 
    4010  size_type erase(const typename object_t::key_type& key)
    4011  {
    4012  // this erase only works for objects
    4013  if (is_object())
    4014  {
    4015  assert(m_value.object != nullptr);
    4016  return m_value.object->erase(key);
    4017  }
    4018  else
    4019  {
    4020  throw std::domain_error("cannot use erase() with " + type_name());
    4021  }
    4022  }
    4023 
    4048  void erase(const size_type idx)
    4049  {
    4050  // this erase only works for arrays
    4051  if (is_array())
    4052  {
    4053  if (idx >= size())
    4054  {
    4055  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    4056  }
    4057 
    4058  assert(m_value.array != nullptr);
    4059  m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
    4060  }
    4061  else
    4062  {
    4063  throw std::domain_error("cannot use erase() with " + type_name());
    4064  }
    4065  }
    4066 
    4068 
    4069 
    4071  // lookup //
    4073 
    4076 
    4094  iterator find(typename object_t::key_type key)
    4095  {
    4096  auto result = end();
    4097 
    4098  if (is_object())
    4099  {
    4100  assert(m_value.object != nullptr);
    4101  result.m_it.object_iterator = m_value.object->find(key);
    4102  }
    4103 
    4104  return result;
    4105  }
    4106 
    4111  const_iterator find(typename object_t::key_type key) const
    4112  {
    4113  auto result = cend();
    4114 
    4115  if (is_object())
    4116  {
    4117  assert(m_value.object != nullptr);
    4118  result.m_it.object_iterator = m_value.object->find(key);
    4119  }
    4120 
    4121  return result;
    4122  }
    4123 
    4142  size_type count(typename object_t::key_type key) const
    4143  {
    4144  // return 0 for all nonobject types
    4145  assert(not is_object() or m_value.object != nullptr);
    4146  return is_object() ? m_value.object->count(key) : 0;
    4147  }
    4148 
    4150 
    4151 
    4153  // iterators //
    4155 
    4158 
    4183  iterator begin() noexcept
    4184  {
    4185  iterator result(this);
    4186  result.set_begin();
    4187  return result;
    4188  }
    4189 
    4193  const_iterator begin() const noexcept
    4194  {
    4195  return cbegin();
    4196  }
    4197 
    4223  const_iterator cbegin() const noexcept
    4224  {
    4225  const_iterator result(this);
    4226  result.set_begin();
    4227  return result;
    4228  }
    4229 
    4254  iterator end() noexcept
    4255  {
    4256  iterator result(this);
    4257  result.set_end();
    4258  return result;
    4259  }
    4260 
    4264  const_iterator end() const noexcept
    4265  {
    4266  return cend();
    4267  }
    4268 
    4294  const_iterator cend() const noexcept
    4295  {
    4296  const_iterator result(this);
    4297  result.set_end();
    4298  return result;
    4299  }
    4300 
    4325  {
    4326  return reverse_iterator(end());
    4327  }
    4328 
    4333  {
    4334  return crbegin();
    4335  }
    4336 
    4362  {
    4363  return reverse_iterator(begin());
    4364  }
    4365 
    4369  const_reverse_iterator rend() const noexcept
    4370  {
    4371  return crend();
    4372  }
    4373 
    4399  {
    4400  return const_reverse_iterator(cend());
    4401  }
    4402 
    4428  {
    4429  return const_reverse_iterator(cbegin());
    4430  }
    4431 
    4432  private:
    4433  // forward declaration
    4434  template<typename IteratorType> class iteration_proxy;
    4435 
    4436  public:
    4448  static iteration_proxy<iterator> iterator_wrapper(reference cont)
    4449  {
    4450  return iteration_proxy<iterator>(cont);
    4451  }
    4452 
    4456  static iteration_proxy<const_iterator> iterator_wrapper(const_reference cont)
    4457  {
    4458  return iteration_proxy<const_iterator>(cont);
    4459  }
    4460 
    4462 
    4463 
    4465  // capacity //
    4467 
    4470 
    4504  bool empty() const noexcept
    4505  {
    4506  switch (m_type)
    4507  {
    4508  case value_t::null:
    4509  {
    4510  // null values are empty
    4511  return true;
    4512  }
    4513 
    4514  case value_t::array:
    4515  {
    4516  assert(m_value.array != nullptr);
    4517  return m_value.array->empty();
    4518  }
    4519 
    4520  case value_t::object:
    4521  {
    4522  assert(m_value.object != nullptr);
    4523  return m_value.object->empty();
    4524  }
    4525 
    4526  default:
    4527  {
    4528  // all other types are nonempty
    4529  return false;
    4530  }
    4531  }
    4532  }
    4533 
    4567  size_type size() const noexcept
    4568  {
    4569  switch (m_type)
    4570  {
    4571  case value_t::null:
    4572  {
    4573  // null values are empty
    4574  return 0;
    4575  }
    4576 
    4577  case value_t::array:
    4578  {
    4579  assert(m_value.array != nullptr);
    4580  return m_value.array->size();
    4581  }
    4582 
    4583  case value_t::object:
    4584  {
    4585  assert(m_value.object != nullptr);
    4586  return m_value.object->size();
    4587  }
    4588 
    4589  default:
    4590  {
    4591  // all other types have size 1
    4592  return 1;
    4593  }
    4594  }
    4595  }
    4596 
    4633  size_type max_size() const noexcept
    4634  {
    4635  switch (m_type)
    4636  {
    4637  case value_t::array:
    4638  {
    4639  assert(m_value.array != nullptr);
    4640  return m_value.array->max_size();
    4641  }
    4642 
    4643  case value_t::object:
    4644  {
    4645  assert(m_value.object != nullptr);
    4646  return m_value.object->max_size();
    4647  }
    4648 
    4649  default:
    4650  {
    4651  // all other types have max_size() == size()
    4652  return size();
    4653  }
    4654  }
    4655  }
    4656 
    4658 
    4659 
    4661  // modifiers //
    4663 
    4666 
    4692  void clear() noexcept
    4693  {
    4694  switch (m_type)
    4695  {
    4696  case value_t::number_integer:
    4697  {
    4698  m_value.number_integer = 0;
    4699  break;
    4700  }
    4701 
    4702  case value_t::number_unsigned:
    4703  {
    4704  m_value.number_unsigned = 0;
    4705  break;
    4706  }
    4707 
    4708  case value_t::number_float:
    4709  {
    4710  m_value.number_float = 0.0;
    4711  break;
    4712  }
    4713 
    4714  case value_t::boolean:
    4715  {
    4716  m_value.boolean = false;
    4717  break;
    4718  }
    4719 
    4720  case value_t::string:
    4721  {
    4722  assert(m_value.string != nullptr);
    4723  m_value.string->clear();
    4724  break;
    4725  }
    4726 
    4727  case value_t::array:
    4728  {
    4729  assert(m_value.array != nullptr);
    4730  m_value.array->clear();
    4731  break;
    4732  }
    4733 
    4734  case value_t::object:
    4735  {
    4736  assert(m_value.object != nullptr);
    4737  m_value.object->clear();
    4738  break;
    4739  }
    4740 
    4741  default:
    4742  {
    4743  break;
    4744  }
    4745  }
    4746  }
    4747 
    4768  void push_back(basic_json&& val)
    4769  {
    4770  // push_back only works for null objects or arrays
    4771  if (not(is_null() or is_array()))
    4772  {
    4773  throw std::domain_error("cannot use push_back() with " + type_name());
    4774  }
    4775 
    4776  // transform null object into an array
    4777  if (is_null())
    4778  {
    4779  m_type = value_t::array;
    4780  m_value = value_t::array;
    4781  }
    4782 
    4783  // add element to array (move semantics)
    4784  assert(m_value.array != nullptr);
    4785  m_value.array->push_back(std::move(val));
    4786  // invalidate object
    4787  val.m_type = value_t::null;
    4788  }
    4789 
    4794  reference operator+=(basic_json&& val)
    4795  {
    4796  push_back(std::move(val));
    4797  return *this;
    4798  }
    4799 
    4804  void push_back(const basic_json& val)
    4805  {
    4806  // push_back only works for null objects or arrays
    4807  if (not(is_null() or is_array()))
    4808  {
    4809  throw std::domain_error("cannot use push_back() with " + type_name());
    4810  }
    4811 
    4812  // transform null object into an array
    4813  if (is_null())
    4814  {
    4815  m_type = value_t::array;
    4816  m_value = value_t::array;
    4817  }
    4818 
    4819  // add element to array
    4820  assert(m_value.array != nullptr);
    4821  m_value.array->push_back(val);
    4822  }
    4823 
    4828  reference operator+=(const basic_json& val)
    4829  {
    4830  push_back(val);
    4831  return *this;
    4832  }
    4833 
    4854  void push_back(const typename object_t::value_type& val)
    4855  {
    4856  // push_back only works for null objects or objects
    4857  if (not(is_null() or is_object()))
    4858  {
    4859  throw std::domain_error("cannot use push_back() with " + type_name());
    4860  }
    4861 
    4862  // transform null object into an object
    4863  if (is_null())
    4864  {
    4865  m_type = value_t::object;
    4866  m_value = value_t::object;
    4867  }
    4868 
    4869  // add element to array
    4870  assert(m_value.object != nullptr);
    4871  m_value.object->insert(val);
    4872  }
    4873 
    4878  reference operator+=(const typename object_t::value_type& val)
    4879  {
    4880  push_back(val);
    4881  return *this;
    4882  }
    4883 
    4909  void push_back(std::initializer_list<basic_json> init)
    4910  {
    4911  if (is_object() and init.size() == 2 and init.begin()->is_string())
    4912  {
    4913  const string_t key = *init.begin();
    4914  push_back(typename object_t::value_type(key, *(init.begin() + 1)));
    4915  }
    4916  else
    4917  {
    4918  push_back(basic_json(init));
    4919  }
    4920  }
    4921 
    4926  reference operator+=(std::initializer_list<basic_json> init)
    4927  {
    4928  push_back(init);
    4929  return *this;
    4930  }
    4931 
    4954  iterator insert(const_iterator pos, const basic_json& val)
    4955  {
    4956  // insert only works for arrays
    4957  if (is_array())
    4958  {
    4959  // check if iterator pos fits to this JSON value
    4960  if (pos.m_object != this)
    4961  {
    4962  throw std::domain_error("iterator does not fit current value");
    4963  }
    4964 
    4965  // insert to array and return iterator
    4966  iterator result(this);
    4967  assert(m_value.array != nullptr);
    4968  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, val);
    4969  return result;
    4970  }
    4971  else
    4972  {
    4973  throw std::domain_error("cannot use insert() with " + type_name());
    4974  }
    4975  }
    4976 
    4981  iterator insert(const_iterator pos, basic_json&& val)
    4982  {
    4983  return insert(pos, val);
    4984  }
    4985 
    5010  iterator insert(const_iterator pos, size_type cnt, const basic_json& val)
    5011  {
    5012  // insert only works for arrays
    5013  if (is_array())
    5014  {
    5015  // check if iterator pos fits to this JSON value
    5016  if (pos.m_object != this)
    5017  {
    5018  throw std::domain_error("iterator does not fit current value");
    5019  }
    5020 
    5021  // insert to array and return iterator
    5022  iterator result(this);
    5023  assert(m_value.array != nullptr);
    5024  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val);
    5025  return result;
    5026  }
    5027  else
    5028  {
    5029  throw std::domain_error("cannot use insert() with " + type_name());
    5030  }
    5031  }
    5032 
    5064  {
    5065  // insert only works for arrays
    5066  if (not is_array())
    5067  {
    5068  throw std::domain_error("cannot use insert() with " + type_name());
    5069  }
    5070 
    5071  // check if iterator pos fits to this JSON value
    5072  if (pos.m_object != this)
    5073  {
    5074  throw std::domain_error("iterator does not fit current value");
    5075  }
    5076 
    5077  if (first.m_object != last.m_object)
    5078  {
    5079  throw std::domain_error("iterators do not fit");
    5080  }
    5081 
    5082  if (first.m_object == this or last.m_object == this)
    5083  {
    5084  throw std::domain_error("passed iterators may not belong to container");
    5085  }
    5086 
    5087  // insert to array and return iterator
    5088  iterator result(this);
    5089  assert(m_value.array != nullptr);
    5090  result.m_it.array_iterator = m_value.array->insert(
    5091  pos.m_it.array_iterator,
    5092  first.m_it.array_iterator,
    5093  last.m_it.array_iterator);
    5094  return result;
    5095  }
    5096 
    5121  iterator insert(const_iterator pos, std::initializer_list<basic_json> ilist)
    5122  {
    5123  // insert only works for arrays
    5124  if (not is_array())
    5125  {
    5126  throw std::domain_error("cannot use insert() with " + type_name());
    5127  }
    5128 
    5129  // check if iterator pos fits to this JSON value
    5130  if (pos.m_object != this)
    5131  {
    5132  throw std::domain_error("iterator does not fit current value");
    5133  }
    5134 
    5135  // insert to array and return iterator
    5136  iterator result(this);
    5137  assert(m_value.array != nullptr);
    5138  result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, ilist);
    5139  return result;
    5140  }
    5141 
    5159  void swap(reference other) noexcept (
    5160  std::is_nothrow_move_constructible<value_t>::value and
    5161  std::is_nothrow_move_assignable<value_t>::value and
    5162  std::is_nothrow_move_constructible<json_value>::value and
    5163  std::is_nothrow_move_assignable<json_value>::value
    5164  )
    5165  {
    5166  std::swap(m_type, other.m_type);
    5167  std::swap(m_value, other.m_value);
    5168  }
    5169 
    5190  void swap(array_t& other)
    5191  {
    5192  // swap only works for arrays
    5193  if (is_array())
    5194  {
    5195  assert(m_value.array != nullptr);
    5196  std::swap(*(m_value.array), other);
    5197  }
    5198  else
    5199  {
    5200  throw std::domain_error("cannot use swap() with " + type_name());
    5201  }
    5202  }
    5203 
    5224  void swap(object_t& other)
    5225  {
    5226  // swap only works for objects
    5227  if (is_object())
    5228  {
    5229  assert(m_value.object != nullptr);
    5230  std::swap(*(m_value.object), other);
    5231  }
    5232  else
    5233  {
    5234  throw std::domain_error("cannot use swap() with " + type_name());
    5235  }
    5236  }
    5237 
    5258  void swap(string_t& other)
    5259  {
    5260  // swap only works for strings
    5261  if (is_string())
    5262  {
    5263  assert(m_value.string != nullptr);
    5264  std::swap(*(m_value.string), other);
    5265  }
    5266  else
    5267  {
    5268  throw std::domain_error("cannot use swap() with " + type_name());
    5269  }
    5270  }
    5271 
    5273 
    5274 
    5276  // lexicographical comparison operators //
    5278 
    5281 
    5282  private:
    5292  friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    5293  {
    5294  static constexpr std::array<uint8_t, 8> order = {{
    5295  0, // null
    5296  3, // object
    5297  4, // array
    5298  5, // string
    5299  1, // boolean
    5300  2, // integer
    5301  2, // unsigned
    5302  2, // float
    5303  }
    5304  };
    5305 
    5306  // discarded values are not comparable
    5307  if (lhs == value_t::discarded or rhs == value_t::discarded)
    5308  {
    5309  return false;
    5310  }
    5311 
    5312  return order[static_cast<std::size_t>(lhs)] < order[static_cast<std::size_t>(rhs)];
    5313  }
    5314 
    5315  public:
    5339  friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    5340  {
    5341  const auto lhs_type = lhs.type();
    5342  const auto rhs_type = rhs.type();
    5343 
    5344  if (lhs_type == rhs_type)
    5345  {
    5346  switch (lhs_type)
    5347  {
    5348  case value_t::array:
    5349  {
    5350  assert(lhs.m_value.array != nullptr);
    5351  assert(rhs.m_value.array != nullptr);
    5352  return *lhs.m_value.array == *rhs.m_value.array;
    5353  }
    5354  case value_t::object:
    5355  {
    5356  assert(lhs.m_value.object != nullptr);
    5357  assert(rhs.m_value.object != nullptr);
    5358  return *lhs.m_value.object == *rhs.m_value.object;
    5359  }
    5360  case value_t::null:
    5361  {
    5362  return true;
    5363  }
    5364  case value_t::string:
    5365  {
    5366  assert(lhs.m_value.string != nullptr);
    5367  assert(rhs.m_value.string != nullptr);
    5368  return *lhs.m_value.string == *rhs.m_value.string;
    5369  }
    5370  case value_t::boolean:
    5371  {
    5372  return lhs.m_value.boolean == rhs.m_value.boolean;
    5373  }
    5374  case value_t::number_integer:
    5375  {
    5376  return lhs.m_value.number_integer == rhs.m_value.number_integer;
    5377  }
    5378  case value_t::number_unsigned:
    5379  {
    5380  return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
    5381  }
    5382  case value_t::number_float:
    5383  {
    5384  return lhs.m_value.number_float == rhs.m_value.number_float;
    5385  }
    5386  default:
    5387  {
    5388  return false;
    5389  }
    5390  }
    5391  }
    5392  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5393  {
    5394  return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
    5395  }
    5396  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5397  {
    5398  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
    5399  }
    5400  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5401  {
    5402  return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
    5403  }
    5404  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5405  {
    5406  return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5407  }
    5408  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5409  {
    5410  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
    5411  }
    5412  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5413  {
    5414  return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5415  }
    5416 
    5417  return false;
    5418  }
    5419 
    5438  friend bool operator==(const_reference v, std::nullptr_t) noexcept
    5439  {
    5440  return v.is_null();
    5441  }
    5442 
    5447  friend bool operator==(std::nullptr_t, const_reference v) noexcept
    5448  {
    5449  return v.is_null();
    5450  }
    5451 
    5468  friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    5469  {
    5470  return not (lhs == rhs);
    5471  }
    5472 
    5491  friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    5492  {
    5493  return not v.is_null();
    5494  }
    5495 
    5500  friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    5501  {
    5502  return not v.is_null();
    5503  }
    5504 
    5529  friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    5530  {
    5531  const auto lhs_type = lhs.type();
    5532  const auto rhs_type = rhs.type();
    5533 
    5534  if (lhs_type == rhs_type)
    5535  {
    5536  switch (lhs_type)
    5537  {
    5538  case value_t::array:
    5539  {
    5540  assert(lhs.m_value.array != nullptr);
    5541  assert(rhs.m_value.array != nullptr);
    5542  return *lhs.m_value.array < *rhs.m_value.array;
    5543  }
    5544  case value_t::object:
    5545  {
    5546  assert(lhs.m_value.object != nullptr);
    5547  assert(rhs.m_value.object != nullptr);
    5548  return *lhs.m_value.object < *rhs.m_value.object;
    5549  }
    5550  case value_t::null:
    5551  {
    5552  return false;
    5553  }
    5554  case value_t::string:
    5555  {
    5556  assert(lhs.m_value.string != nullptr);
    5557  assert(rhs.m_value.string != nullptr);
    5558  return *lhs.m_value.string < *rhs.m_value.string;
    5559  }
    5560  case value_t::boolean:
    5561  {
    5562  return lhs.m_value.boolean < rhs.m_value.boolean;
    5563  }
    5564  case value_t::number_integer:
    5565  {
    5566  return lhs.m_value.number_integer < rhs.m_value.number_integer;
    5567  }
    5568  case value_t::number_unsigned:
    5569  {
    5570  return lhs.m_value.number_unsigned < rhs.m_value.number_unsigned;
    5571  }
    5572  case value_t::number_float:
    5573  {
    5574  return lhs.m_value.number_float < rhs.m_value.number_float;
    5575  }
    5576  default:
    5577  {
    5578  return false;
    5579  }
    5580  }
    5581  }
    5582  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
    5583  {
    5584  return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
    5585  }
    5586  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
    5587  {
    5588  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
    5589  }
    5590  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_float)
    5591  {
    5592  return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
    5593  }
    5594  else if (lhs_type == value_t::number_float and rhs_type == value_t::number_unsigned)
    5595  {
    5596  return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
    5597  }
    5598  else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_unsigned)
    5599  {
    5600  return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
    5601  }
    5602  else if (lhs_type == value_t::number_unsigned and rhs_type == value_t::number_integer)
    5603  {
    5604  return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
    5605  }
    5606 
    5607  // We only reach this line if we cannot compare values. In that case,
    5608  // we compare types. Note we have to call the operator explicitly,
    5609  // because MSVC has problems otherwise.
    5610  return operator<(lhs_type, rhs_type);
    5611  }
    5612 
    5630  friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    5631  {
    5632  return not (rhs < lhs);
    5633  }
    5634 
    5652  friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    5653  {
    5654  return not (lhs <= rhs);
    5655  }
    5656 
    5674  friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    5675  {
    5676  return not (lhs < rhs);
    5677  }
    5678 
    5680 
    5681 
    5683  // serialization //
    5685 
    5688 
    5711  friend std::ostream& operator<<(std::ostream& o, const basic_json& j)
    5712  {
    5713  // read width member and use it as indentation parameter if nonzero
    5714  const bool pretty_print = (o.width() > 0);
    5715  const auto indentation = (pretty_print ? o.width() : 0);
    5716 
    5717  // reset width to 0 for subsequent calls to this stream
    5718  o.width(0);
    5719 
    5720  // do the actual serialization
    5721  j.dump(o, pretty_print, static_cast<unsigned int>(indentation));
    5722  return o;
    5723  }
    5724 
    5729  friend std::ostream& operator>>(const basic_json& j, std::ostream& o)
    5730  {
    5731  return o << j;
    5732  }
    5733 
    5735 
    5736 
    5738  // deserialization //
    5740 
    5743 
    5768  static basic_json parse(const string_t& s, parser_callback_t cb = nullptr)
    5769  {
    5770  return parser(s, cb).parse();
    5771  }
    5772 
    5797  static basic_json parse(std::istream& i, parser_callback_t cb = nullptr)
    5798  {
    5799  return parser(i, cb).parse();
    5800  }
    5801 
    5805  static basic_json parse(std::istream&& i, parser_callback_t cb = nullptr)
    5806  {
    5807  return parser(i, cb).parse();
    5808  }
    5809 
    5833  friend std::istream& operator<<(basic_json& j, std::istream& i)
    5834  {
    5835  j = parser(i).parse();
    5836  return i;
    5837  }
    5838 
    5843  friend std::istream& operator>>(std::istream& i, basic_json& j)
    5844  {
    5845  j = parser(i).parse();
    5846  return i;
    5847  }
    5848 
    5850 
    5851 
    5852  private:
    5854  // convenience functions //
    5856 
    5858  string_t type_name() const noexcept
    5859  {
    5860  switch (m_type)
    5861  {
    5862  case value_t::null:
    5863  return "null";
    5864  case value_t::object:
    5865  return "object";
    5866  case value_t::array:
    5867  return "array";
    5868  case value_t::string:
    5869  return "string";
    5870  case value_t::boolean:
    5871  return "boolean";
    5872  case value_t::discarded:
    5873  return "discarded";
    5874  default:
    5875  return "number";
    5876  }
    5877  }
    5878 
    5887  static std::size_t extra_space(const string_t& s) noexcept
    5888  {
    5889  std::size_t result = 0;
    5890 
    5891  for (const auto& c : s)
    5892  {
    5893  switch (c)
    5894  {
    5895  case '"':
    5896  case '\\':
    5897  case '\b':
    5898  case '\f':
    5899  case '\n':
    5900  case '\r':
    5901  case '\t':
    5902  {
    5903  // from c (1 byte) to \x (2 bytes)
    5904  result += 1;
    5905  break;
    5906  }
    5907 
    5908  default:
    5909  {
    5910  if (c >= 0x00 and c <= 0x1f)
    5911  {
    5912  // from c (1 byte) to \uxxxx (6 bytes)
    5913  result += 5;
    5914  }
    5915  break;
    5916  }
    5917  }
    5918  }
    5919 
    5920  return result;
    5921  }
    5922 
    5936  static string_t escape_string(const string_t& s)
    5937  {
    5938  const auto space = extra_space(s);
    5939  if (space == 0)
    5940  {
    5941  return s;
    5942  }
    5943 
    5944  // create a result string of necessary size
    5945  string_t result(s.size() + space, '\\');
    5946  std::size_t pos = 0;
    5947 
    5948  for (const auto& c : s)
    5949  {
    5950  switch (c)
    5951  {
    5952  // quotation mark (0x22)
    5953  case '"':
    5954  {
    5955  result[pos + 1] = '"';
    5956  pos += 2;
    5957  break;
    5958  }
    5959 
    5960  // reverse solidus (0x5c)
    5961  case '\\':
    5962  {
    5963  // nothing to change
    5964  pos += 2;
    5965  break;
    5966  }
    5967 
    5968  // backspace (0x08)
    5969  case '\b':
    5970  {
    5971  result[pos + 1] = 'b';
    5972  pos += 2;
    5973  break;
    5974  }
    5975 
    5976  // formfeed (0x0c)
    5977  case '\f':
    5978  {
    5979  result[pos + 1] = 'f';
    5980  pos += 2;
    5981  break;
    5982  }
    5983 
    5984  // newline (0x0a)
    5985  case '\n':
    5986  {
    5987  result[pos + 1] = 'n';
    5988  pos += 2;
    5989  break;
    5990  }
    5991 
    5992  // carriage return (0x0d)
    5993  case '\r':
    5994  {
    5995  result[pos + 1] = 'r';
    5996  pos += 2;
    5997  break;
    5998  }
    5999 
    6000  // horizontal tab (0x09)
    6001  case '\t':
    6002  {
    6003  result[pos + 1] = 't';
    6004  pos += 2;
    6005  break;
    6006  }
    6007 
    6008  default:
    6009  {
    6010  if (c >= 0x00 and c <= 0x1f)
    6011  {
    6012  // convert a number 0..15 to its hex representation
    6013  // (0..f)
    6014  auto hexify = [](const char v) -> char
    6015  {
    6016  return (v < 10) ? ('0' + v) : ('a' + v - 10);
    6017  };
    6018 
    6019  // print character c as \uxxxx
    6020  for (const char m :
    6021  { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f)
    6022  })
    6023  {
    6024  result[++pos] = m;
    6025  }
    6026 
    6027  ++pos;
    6028  }
    6029  else
    6030  {
    6031  // all other characters are added as-is
    6032  result[pos++] = c;
    6033  }
    6034  break;
    6035  }
    6036  }
    6037  }
    6038 
    6039  return result;
    6040  }
    6041 
    6059  void dump(std::ostream& o,
    6060  const bool pretty_print,
    6061  const unsigned int indent_step,
    6062  const unsigned int current_indent = 0) const
    6063  {
    6064  // variable to hold indentation for recursive calls
    6065  unsigned int new_indent = current_indent;
    6066 
    6067  switch (m_type)
    6068  {
    6069  case value_t::object:
    6070  {
    6071  assert(m_value.object != nullptr);
    6072 
    6073  if (m_value.object->empty())
    6074  {
    6075  o << "{}";
    6076  return;
    6077  }
    6078 
    6079  o << "{";
    6080 
    6081  // increase indentation
    6082  if (pretty_print)
    6083  {
    6084  new_indent += indent_step;
    6085  o << "\n";
    6086  }
    6087 
    6088  for (auto i = m_value.object->cbegin(); i != m_value.object->cend(); ++i)
    6089  {
    6090  if (i != m_value.object->cbegin())
    6091  {
    6092  o << (pretty_print ? ",\n" : ",");
    6093  }
    6094  o << string_t(new_indent, ' ') << "\""
    6095  << escape_string(i->first) << "\":"
    6096  << (pretty_print ? " " : "");
    6097  i->second.dump(o, pretty_print, indent_step, new_indent);
    6098  }
    6099 
    6100  // decrease indentation
    6101  if (pretty_print)
    6102  {
    6103  new_indent -= indent_step;
    6104  o << "\n";
    6105  }
    6106 
    6107  o << string_t(new_indent, ' ') + "}";
    6108  return;
    6109  }
    6110 
    6111  case value_t::array:
    6112  {
    6113  assert(m_value.array != nullptr);
    6114 
    6115  if (m_value.array->empty())
    6116  {
    6117  o << "[]";
    6118  return;
    6119  }
    6120 
    6121  o << "[";
    6122 
    6123  // increase indentation
    6124  if (pretty_print)
    6125  {
    6126  new_indent += indent_step;
    6127  o << "\n";
    6128  }
    6129 
    6130  for (auto i = m_value.array->cbegin(); i != m_value.array->cend(); ++i)
    6131  {
    6132  if (i != m_value.array->cbegin())
    6133  {
    6134  o << (pretty_print ? ",\n" : ",");
    6135  }
    6136  o << string_t(new_indent, ' ');
    6137  i->dump(o, pretty_print, indent_step, new_indent);
    6138  }
    6139 
    6140  // decrease indentation
    6141  if (pretty_print)
    6142  {
    6143  new_indent -= indent_step;
    6144  o << "\n";
    6145  }
    6146 
    6147  o << string_t(new_indent, ' ') << "]";
    6148  return;
    6149  }
    6150 
    6151  case value_t::string:
    6152  {
    6153  assert(m_value.string != nullptr);
    6154  o << string_t("\"") << escape_string(*m_value.string) << "\"";
    6155  return;
    6156  }
    6157 
    6158  case value_t::boolean:
    6159  {
    6160  o << (m_value.boolean ? "true" : "false");
    6161  return;
    6162  }
    6163 
    6164  case value_t::number_integer:
    6165  {
    6166  o << m_value.number_integer;
    6167  return;
    6168  }
    6169 
    6170  case value_t::number_unsigned:
    6171  {
    6172  o << m_value.number_unsigned;
    6173  return;
    6174  }
    6175 
    6176  case value_t::number_float:
    6177  {
    6178  // check if number was parsed from a string
    6179  if (m_type.bits.parsed)
    6180  {
    6181  // check if parsed number had an exponent given
    6182  if (m_type.bits.has_exp)
    6183  {
    6184  // buffer size: precision (2^8-1 = 255) + other ('-.e-xxx' = 7) + null (1)
    6185  char buf[263];
    6186  int len;
    6187 
    6188  // handle capitalization of the exponent
    6189  if (m_type.bits.exp_cap)
    6190  {
    6191  len = snprintf(buf, sizeof(buf), "%.*E",
    6192  m_type.bits.precision, m_value.number_float) + 1;
    6193  }
    6194  else
    6195  {
    6196  len = snprintf(buf, sizeof(buf), "%.*e",
    6197  m_type.bits.precision, m_value.number_float) + 1;
    6198  }
    6199 
    6200  // remove '+' sign from the exponent if necessary
    6201  if (not m_type.bits.exp_plus)
    6202  {
    6203  if (len > static_cast<int>(sizeof(buf)))
    6204  {
    6205  len = sizeof(buf);
    6206  }
    6207  for (int i = 0; i < len; i++)
    6208  {
    6209  if (buf[i] == '+')
    6210  {
    6211  for (; i + 1 < len; i++)
    6212  {
    6213  buf[i] = buf[i + 1];
    6214  }
    6215  }
    6216  }
    6217  }
    6218 
    6219  o << buf;
    6220  }
    6221  else
    6222  {
    6223  // no exponent - output as a decimal
    6224  std::stringstream ss;
    6225  ss.imbue(std::locale(std::locale(), new DecimalSeparator)); // fix locale problems
    6226  ss << std::setprecision(m_type.bits.precision)
    6227  << std::fixed << m_value.number_float;
    6228  o << ss.str();
    6229  }
    6230  }
    6231  else
    6232  {
    6233  if (m_value.number_float == 0)
    6234  {
    6235  // special case for zero to get "0.0"/"-0.0"
    6236  o << (std::signbit(m_value.number_float) ? "-0.0" : "0.0");
    6237  }
    6238  else
    6239  {
    6240  // Otherwise 6, 15 or 16 digits of precision allows
    6241  // round-trip IEEE 754 string->float->string,
    6242  // string->double->string or string->long double->string;
    6243  // to be safe, we read this value from
    6244  // std::numeric_limits<number_float_t>::digits10
    6245  std::stringstream ss;
    6246  ss.imbue(std::locale(std::locale(), new DecimalSeparator)); // fix locale problems
    6247  ss << std::setprecision(std::numeric_limits<double>::digits10)
    6248  << m_value.number_float;
    6249  o << ss.str();
    6250  }
    6251  }
    6252  return;
    6253  }
    6254 
    6255  case value_t::discarded:
    6256  {
    6257  o << "<discarded>";
    6258  return;
    6259  }
    6260 
    6261  case value_t::null:
    6262  {
    6263  o << "null";
    6264  return;
    6265  }
    6266  }
    6267  }
    6268 
    6269  private:
    6271  // member variables //
    6273 
    6275  type_data_t m_type = value_t::null;
    6276 
    6278  json_value m_value = {};
    6279 
    6280 
    6281  private:
    6283  // iterators //
    6285 
    6295  class primitive_iterator_t
    6296  {
    6297  public:
    6299  void set_begin() noexcept
    6300  {
    6301  m_it = begin_value;
    6302  }
    6303 
    6305  void set_end() noexcept
    6306  {
    6307  m_it = end_value;
    6308  }
    6309 
    6311  constexpr bool is_begin() const noexcept
    6312  {
    6313  return (m_it == begin_value);
    6314  }
    6315 
    6317  constexpr bool is_end() const noexcept
    6318  {
    6319  return (m_it == end_value);
    6320  }
    6321 
    6323  operator difference_type& () noexcept
    6324  {
    6325  return m_it;
    6326  }
    6327 
    6329  constexpr operator difference_type () const noexcept
    6330  {
    6331  return m_it;
    6332  }
    6333 
    6334  private:
    6335  static constexpr difference_type begin_value = 0;
    6336  static constexpr difference_type end_value = begin_value + 1;
    6337 
    6339  difference_type m_it = std::numeric_limits<std::ptrdiff_t>::denorm_min();
    6340  };
    6341 
    6349  struct internal_iterator
    6350  {
    6352  typename object_t::iterator object_iterator;
    6354  typename array_t::iterator array_iterator;
    6356  primitive_iterator_t primitive_iterator;
    6357 
    6359  internal_iterator() noexcept
    6360  : object_iterator(), array_iterator(), primitive_iterator()
    6361  {}
    6362  };
    6363 
    6365  template<typename IteratorType>
    6366  class iteration_proxy
    6367  {
    6368  private:
    6370  class iteration_proxy_internal
    6371  {
    6372  private:
    6374  IteratorType anchor;
    6376  size_t array_index = 0;
    6377 
    6378  public:
    6379  explicit iteration_proxy_internal(IteratorType it) noexcept
    6380  : anchor(it)
    6381  {}
    6382 
    6384  iteration_proxy_internal& operator*()
    6385  {
    6386  return *this;
    6387  }
    6388 
    6390  iteration_proxy_internal& operator++()
    6391  {
    6392  ++anchor;
    6393  ++array_index;
    6394 
    6395  return *this;
    6396  }
    6397 
    6399  bool operator!= (const iteration_proxy_internal& o) const
    6400  {
    6401  return anchor != o.anchor;
    6402  }
    6403 
    6405  typename basic_json::string_t key() const
    6406  {
    6407  assert(anchor.m_object != nullptr);
    6408 
    6409  switch (anchor.m_object->type())
    6410  {
    6411  // use integer array index as key
    6412  case value_t::array:
    6413  {
    6414  return std::to_string(array_index);
    6415  }
    6416 
    6417  // use key from the object
    6418  case value_t::object:
    6419  {
    6420  return anchor.key();
    6421  }
    6422 
    6423  // use an empty key for all primitive types
    6424  default:
    6425  {
    6426  return "";
    6427  }
    6428  }
    6429  }
    6430 
    6432  typename IteratorType::reference value() const
    6433  {
    6434  return anchor.value();
    6435  }
    6436  };
    6437 
    6439  typename IteratorType::reference container;
    6440 
    6441  public:
    6443  explicit iteration_proxy(typename IteratorType::reference cont)
    6444  : container(cont)
    6445  {}
    6446 
    6448  iteration_proxy_internal begin() noexcept
    6449  {
    6450  return iteration_proxy_internal(container.begin());
    6451  }
    6452 
    6454  iteration_proxy_internal end() noexcept
    6455  {
    6456  return iteration_proxy_internal(container.end());
    6457  }
    6458  };
    6459 
    6460  public:
    6474  class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
    6475  {
    6477  friend class basic_json;
    6478 
    6479  public:
    6489  using iterator_category = std::bidirectional_iterator_tag;
    6490 
    6492  const_iterator() = default;
    6493 
    6495  explicit const_iterator(pointer object) noexcept
    6496  : m_object(object)
    6497  {
    6498  assert(m_object != nullptr);
    6499 
    6500  switch (m_object->m_type)
    6501  {
    6503  {
    6504  m_it.object_iterator = typename object_t::iterator();
    6505  break;
    6506  }
    6507 
    6509  {
    6510  m_it.array_iterator = typename array_t::iterator();
    6511  break;
    6512  }
    6513 
    6514  default:
    6515  {
    6516  m_it.primitive_iterator = primitive_iterator_t();
    6517  break;
    6518  }
    6519  }
    6520  }
    6521 
    6523  explicit const_iterator(const iterator& other) noexcept
    6524  : m_object(other.m_object)
    6525  {
    6526  assert(m_object != nullptr);
    6527 
    6528  switch (m_object->m_type)
    6529  {
    6531  {
    6532  m_it.object_iterator = other.m_it.object_iterator;
    6533  break;
    6534  }
    6535 
    6537  {
    6538  m_it.array_iterator = other.m_it.array_iterator;
    6539  break;
    6540  }
    6541 
    6542  default:
    6543  {
    6544  m_it.primitive_iterator = other.m_it.primitive_iterator;
    6545  break;
    6546  }
    6547  }
    6548  }
    6549 
    6551  const_iterator(const const_iterator& other) noexcept
    6552  : m_object(other.m_object), m_it(other.m_it)
    6553  {}
    6554 
    6557  std::is_nothrow_move_constructible<pointer>::value and
    6558  std::is_nothrow_move_assignable<pointer>::value and
    6559  std::is_nothrow_move_constructible<internal_iterator>::value and
    6560  std::is_nothrow_move_assignable<internal_iterator>::value
    6561  )
    6562  {
    6563  std::swap(m_object, other.m_object);
    6564  std::swap(m_it, other.m_it);
    6565  return *this;
    6566  }
    6567 
    6568  private:
    6570  void set_begin() noexcept
    6571  {
    6572  assert(m_object != nullptr);
    6573 
    6574  switch (m_object->m_type)
    6575  {
    6577  {
    6578  assert(m_object->m_value.object != nullptr);
    6579  m_it.object_iterator = m_object->m_value.object->begin();
    6580  break;
    6581  }
    6582 
    6584  {
    6585  assert(m_object->m_value.array != nullptr);
    6586  m_it.array_iterator = m_object->m_value.array->begin();
    6587  break;
    6588  }
    6589 
    6591  {
    6592  // set to end so begin()==end() is true: null is empty
    6593  m_it.primitive_iterator.set_end();
    6594  break;
    6595  }
    6596 
    6597  default:
    6598  {
    6599  m_it.primitive_iterator.set_begin();
    6600  break;
    6601  }
    6602  }
    6603  }
    6604 
    6606  void set_end() noexcept
    6607  {
    6608  assert(m_object != nullptr);
    6609 
    6610  switch (m_object->m_type)
    6611  {
    6613  {
    6614  assert(m_object->m_value.object != nullptr);
    6615  m_it.object_iterator = m_object->m_value.object->end();
    6616  break;
    6617  }
    6618 
    6620  {
    6621  assert(m_object->m_value.array != nullptr);
    6622  m_it.array_iterator = m_object->m_value.array->end();
    6623  break;
    6624  }
    6625 
    6626  default:
    6627  {
    6628  m_it.primitive_iterator.set_end();
    6629  break;
    6630  }
    6631  }
    6632  }
    6633 
    6634  public:
    6637  {
    6638  assert(m_object != nullptr);
    6639 
    6640  switch (m_object->m_type)
    6641  {
    6643  {
    6644  assert(m_object->m_value.object);
    6645  assert(m_it.object_iterator != m_object->m_value.object->end());
    6646  return m_it.object_iterator->second;
    6647  }
    6648 
    6650  {
    6651  assert(m_object->m_value.array);
    6652  assert(m_it.array_iterator != m_object->m_value.array->end());
    6653  return *m_it.array_iterator;
    6654  }
    6655 
    6657  {
    6658  throw std::out_of_range("cannot get value");
    6659  }
    6660 
    6661  default:
    6662  {
    6663  if (m_it.primitive_iterator.is_begin())
    6664  {
    6665  return *m_object;
    6666  }
    6667  else
    6668  {
    6669  throw std::out_of_range("cannot get value");
    6670  }
    6671  }
    6672  }
    6673  }
    6674 
    6677  {
    6678  assert(m_object != nullptr);
    6679 
    6680  switch (m_object->m_type)
    6681  {
    6683  {
    6684  assert(m_object->m_value.object);
    6685  assert(m_it.object_iterator != m_object->m_value.object->end());
    6686  return &(m_it.object_iterator->second);
    6687  }
    6688 
    6690  {
    6691  assert(m_object->m_value.array);
    6692  assert(m_it.array_iterator != m_object->m_value.array->end());
    6693  return &*m_it.array_iterator;
    6694  }
    6695 
    6696  default:
    6697  {
    6698  if (m_it.primitive_iterator.is_begin())
    6699  {
    6700  return m_object;
    6701  }
    6702  else
    6703  {
    6704  throw std::out_of_range("cannot get value");
    6705  }
    6706  }
    6707  }
    6708  }
    6709 
    6712  {
    6713  auto result = *this;
    6714  ++(*this);
    6715  return result;
    6716  }
    6717 
    6720  {
    6721  assert(m_object != nullptr);
    6722 
    6723  switch (m_object->m_type)
    6724  {
    6726  {
    6727  ++m_it.object_iterator;
    6728  break;
    6729  }
    6730 
    6732  {
    6733  ++m_it.array_iterator;
    6734  break;
    6735  }
    6736 
    6737  default:
    6738  {
    6739  ++m_it.primitive_iterator;
    6740  break;
    6741  }
    6742  }
    6743 
    6744  return *this;
    6745  }
    6746 
    6749  {
    6750  auto result = *this;
    6751  --(*this);
    6752  return result;
    6753  }
    6754 
    6757  {
    6758  assert(m_object != nullptr);
    6759 
    6760  switch (m_object->m_type)
    6761  {
    6763  {
    6764  --m_it.object_iterator;
    6765  break;
    6766  }
    6767 
    6769  {
    6770  --m_it.array_iterator;
    6771  break;
    6772  }
    6773 
    6774  default:
    6775  {
    6776  --m_it.primitive_iterator;
    6777  break;
    6778  }
    6779  }
    6780 
    6781  return *this;
    6782  }
    6783 
    6785  bool operator==(const const_iterator& other) const
    6786  {
    6787  // if objects are not the same, the comparison is undefined
    6788  if (m_object != other.m_object)
    6789  {
    6790  throw std::domain_error("cannot compare iterators of different containers");
    6791  }
    6792 
    6793  assert(m_object != nullptr);
    6794 
    6795  switch (m_object->m_type)
    6796  {
    6798  {
    6799  return (m_it.object_iterator == other.m_it.object_iterator);
    6800  }
    6801 
    6803  {
    6804  return (m_it.array_iterator == other.m_it.array_iterator);
    6805  }
    6806 
    6807  default:
    6808  {
    6809  return (m_it.primitive_iterator == other.m_it.primitive_iterator);
    6810  }
    6811  }
    6812  }
    6813 
    6815  bool operator!=(const const_iterator& other) const
    6816  {
    6817  return not operator==(other);
    6818  }
    6819 
    6821  bool operator<(const const_iterator& other) const
    6822  {
    6823  // if objects are not the same, the comparison is undefined
    6824  if (m_object != other.m_object)
    6825  {
    6826  throw std::domain_error("cannot compare iterators of different containers");
    6827  }
    6828 
    6829  assert(m_object != nullptr);
    6830 
    6831  switch (m_object->m_type)
    6832  {
    6834  {
    6835  throw std::domain_error("cannot compare order of object iterators");
    6836  }
    6837 
    6839  {
    6840  return (m_it.array_iterator < other.m_it.array_iterator);
    6841  }
    6842 
    6843  default:
    6844  {
    6845  return (m_it.primitive_iterator < other.m_it.primitive_iterator);
    6846  }
    6847  }
    6848  }
    6849 
    6851  bool operator<=(const const_iterator& other) const
    6852  {
    6853  return not other.operator < (*this);
    6854  }
    6855 
    6857  bool operator>(const const_iterator& other) const
    6858  {
    6859  return not operator<=(other);
    6860  }
    6861 
    6863  bool operator>=(const const_iterator& other) const
    6864  {
    6865  return not operator<(other);
    6866  }
    6867 
    6870  {
    6871  assert(m_object != nullptr);
    6872 
    6873  switch (m_object->m_type)
    6874  {
    6876  {
    6877  throw std::domain_error("cannot use offsets with object iterators");
    6878  }
    6879 
    6881  {
    6882  m_it.array_iterator += i;
    6883  break;
    6884  }
    6885 
    6886  default:
    6887  {
    6888  m_it.primitive_iterator += i;
    6889  break;
    6890  }
    6891  }
    6892 
    6893  return *this;
    6894  }
    6895 
    6898  {
    6899  return operator+=(-i);
    6900  }
    6901 
    6904  {
    6905  auto result = *this;
    6906  result += i;
    6907  return result;
    6908  }
    6909 
    6912  {
    6913  auto result = *this;
    6914  result -= i;
    6915  return result;
    6916  }
    6917 
    6920  {
    6921  assert(m_object != nullptr);
    6922 
    6923  switch (m_object->m_type)
    6924  {
    6926  {
    6927  throw std::domain_error("cannot use offsets with object iterators");
    6928  }
    6929 
    6931  {
    6932  return m_it.array_iterator - other.m_it.array_iterator;
    6933  }
    6934 
    6935  default:
    6936  {
    6937  return m_it.primitive_iterator - other.m_it.primitive_iterator;
    6938  }
    6939  }
    6940  }
    6941 
    6944  {
    6945  assert(m_object != nullptr);
    6946 
    6947  switch (m_object->m_type)
    6948  {
    6950  {
    6951  throw std::domain_error("cannot use operator[] for object iterators");
    6952  }
    6953 
    6955  {
    6956  return *(m_it.array_iterator + n);
    6957  }
    6958 
    6960  {
    6961  throw std::out_of_range("cannot get value");
    6962  }
    6963 
    6964  default:
    6965  {
    6966  if (m_it.primitive_iterator == -n)
    6967  {
    6968  return *m_object;
    6969  }
    6970  else
    6971  {
    6972  throw std::out_of_range("cannot get value");
    6973  }
    6974  }
    6975  }
    6976  }
    6977 
    6979  typename object_t::key_type key() const
    6980  {
    6981  assert(m_object != nullptr);
    6982 
    6983  if (m_object->is_object())
    6984  {
    6985  return m_it.object_iterator->first;
    6986  }
    6987  else
    6988  {
    6989  throw std::domain_error("cannot use key() for non-object iterators");
    6990  }
    6991  }
    6992 
    6995  {
    6996  return operator*();
    6997  }
    6998 
    6999  private:
    7001  pointer m_object = nullptr;
    7003  internal_iterator m_it = internal_iterator();
    7004  };
    7005 
    7018  class iterator : public const_iterator
    7019  {
    7020  public:
    7022  using pointer = typename basic_json::pointer;
    7024 
    7026  iterator() = default;
    7027 
    7029  explicit iterator(pointer object) noexcept
    7030  : base_iterator(object)
    7031  {}
    7032 
    7034  iterator(const iterator& other) noexcept
    7035  : base_iterator(other)
    7036  {}
    7037 
    7039  iterator& operator=(iterator other) noexcept(
    7040  std::is_nothrow_move_constructible<pointer>::value and
    7041  std::is_nothrow_move_assignable<pointer>::value and
    7042  std::is_nothrow_move_constructible<internal_iterator>::value and
    7043  std::is_nothrow_move_assignable<internal_iterator>::value
    7044  )
    7045  {
    7046  base_iterator::operator=(other);
    7047  return *this;
    7048  }
    7049 
    7052  {
    7053  return const_cast<reference>(base_iterator::operator*());
    7054  }
    7055 
    7058  {
    7059  return const_cast<pointer>(base_iterator::operator->());
    7060  }
    7061 
    7064  {
    7065  iterator result = *this;
    7066  base_iterator::operator++();
    7067  return result;
    7068  }
    7069 
    7072  {
    7073  base_iterator::operator++();
    7074  return *this;
    7075  }
    7076 
    7079  {
    7080  iterator result = *this;
    7081  base_iterator::operator--();
    7082  return result;
    7083  }
    7084 
    7087  {
    7088  base_iterator::operator--();
    7089  return *this;
    7090  }
    7091 
    7094  {
    7095  base_iterator::operator+=(i);
    7096  return *this;
    7097  }
    7098 
    7101  {
    7102  base_iterator::operator-=(i);
    7103  return *this;
    7104  }
    7105 
    7108  {
    7109  auto result = *this;
    7110  result += i;
    7111  return result;
    7112  }
    7113 
    7116  {
    7117  auto result = *this;
    7118  result -= i;
    7119  return result;
    7120  }
    7121 
    7123  difference_type operator-(const iterator& other) const
    7124  {
    7125  return base_iterator::operator-(other);
    7126  }
    7127 
    7130  {
    7131  return const_cast<reference>(base_iterator::operator[](n));
    7132  }
    7133 
    7136  {
    7137  return const_cast<reference>(base_iterator::value());
    7138  }
    7139  };
    7140 
    7158  template<typename Base>
    7159  class json_reverse_iterator : public std::reverse_iterator<Base>
    7160  {
    7161  public:
    7163  using base_iterator = std::reverse_iterator<Base>;
    7165  using reference = typename Base::reference;
    7166 
    7168  json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
    7169  : base_iterator(it)
    7170  {}
    7171 
    7174  : base_iterator(it)
    7175  {}
    7176 
    7179  {
    7180  return base_iterator::operator++(1);
    7181  }
    7182 
    7185  {
    7186  base_iterator::operator++();
    7187  return *this;
    7188  }
    7189 
    7192  {
    7193  return base_iterator::operator--(1);
    7194  }
    7195 
    7198  {
    7199  base_iterator::operator--();
    7200  return *this;
    7201  }
    7202 
    7205  {
    7206  base_iterator::operator+=(i);
    7207  return *this;
    7208  }
    7209 
    7212  {
    7213  auto result = *this;
    7214  result += i;
    7215  return result;
    7216  }
    7217 
    7220  {
    7221  auto result = *this;
    7222  result -= i;
    7223  return result;
    7224  }
    7225 
    7228  {
    7229  return this->base() - other.base();
    7230  }
    7231 
    7234  {
    7235  return *(this->operator+(n));
    7236  }
    7237 
    7239  typename object_t::key_type key() const
    7240  {
    7241  auto it = --this->base();
    7242  return it.key();
    7243  }
    7244 
    7247  {
    7248  auto it = --this->base();
    7249  return it.operator * ();
    7250  }
    7251  };
    7252 
    7253 
    7254  private:
    7256  // lexer and parser //
    7258 
    7266  class lexer
    7267  {
    7268  public:
    7270  enum class token_type
    7271  {
    7272  uninitialized,
    7273  literal_true,
    7274  literal_false,
    7275  literal_null,
    7276  value_string,
    7277  value_number,
    7278  begin_array,
    7279  begin_object,
    7280  end_array,
    7281  end_object,
    7282  name_separator,
    7283  value_separator,
    7284  parse_error,
    7285  end_of_input
    7286  };
    7287 
    7289  using lexer_char_t = unsigned char;
    7290 
    7292  explicit lexer(const string_t& s) noexcept
    7293  : m_stream(nullptr), m_buffer(s)
    7294  {
    7295  m_content = reinterpret_cast<const lexer_char_t*>(s.c_str());
    7296  assert(m_content != nullptr);
    7297  m_start = m_cursor = m_content;
    7298  m_limit = m_content + s.size();
    7299  }
    7300 
    7302  explicit lexer(std::istream* s) noexcept
    7303  : m_stream(s), m_buffer()
    7304  {
    7305  assert(m_stream != nullptr);
    7306  getline(*m_stream, m_buffer);
    7307  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    7308  assert(m_content != nullptr);
    7309  m_start = m_cursor = m_content;
    7310  m_limit = m_content + m_buffer.size();
    7311  }
    7312 
    7314  lexer() = default;
    7315 
    7316  // switch off unwanted functions
    7317  lexer(const lexer&) = delete;
    7318  lexer operator=(const lexer&) = delete;
    7319 
    7335  static string_t to_unicode(const std::size_t codepoint1,
    7336  const std::size_t codepoint2 = 0)
    7337  {
    7338  // calculate the codepoint from the given code points
    7339  std::size_t codepoint = codepoint1;
    7340 
    7341  // check if codepoint1 is a high surrogate
    7342  if (codepoint1 >= 0xD800 and codepoint1 <= 0xDBFF)
    7343  {
    7344  // check if codepoint2 is a low surrogate
    7345  if (codepoint2 >= 0xDC00 and codepoint2 <= 0xDFFF)
    7346  {
    7347  codepoint =
    7348  // high surrogate occupies the most significant 22 bits
    7349  (codepoint1 << 10)
    7350  // low surrogate occupies the least significant 15 bits
    7351  + codepoint2
    7352  // there is still the 0xD800, 0xDC00 and 0x10000 noise
    7353  // in the result so we have to subtract with:
    7354  // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00
    7355  - 0x35FDC00;
    7356  }
    7357  else
    7358  {
    7359  throw std::invalid_argument("missing or wrong low surrogate");
    7360  }
    7361  }
    7362 
    7363  string_t result;
    7364 
    7365  if (codepoint < 0x80)
    7366  {
    7367  // 1-byte characters: 0xxxxxxx (ASCII)
    7368  result.append(1, static_cast<typename string_t::value_type>(codepoint));
    7369  }
    7370  else if (codepoint <= 0x7ff)
    7371  {
    7372  // 2-byte characters: 110xxxxx 10xxxxxx
    7373  result.append(1, static_cast<typename string_t::value_type>(0xC0 | ((codepoint >> 6) & 0x1F)));
    7374  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7375  }
    7376  else if (codepoint <= 0xffff)
    7377  {
    7378  // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx
    7379  result.append(1, static_cast<typename string_t::value_type>(0xE0 | ((codepoint >> 12) & 0x0F)));
    7380  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7381  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7382  }
    7383  else if (codepoint <= 0x10ffff)
    7384  {
    7385  // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    7386  result.append(1, static_cast<typename string_t::value_type>(0xF0 | ((codepoint >> 18) & 0x07)));
    7387  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 12) & 0x3F)));
    7388  result.append(1, static_cast<typename string_t::value_type>(0x80 | ((codepoint >> 6) & 0x3F)));
    7389  result.append(1, static_cast<typename string_t::value_type>(0x80 | (codepoint & 0x3F)));
    7390  }
    7391  else
    7392  {
    7393  throw std::out_of_range("code points above 0x10FFFF are invalid");
    7394  }
    7395 
    7396  return result;
    7397  }
    7398 
    7400  static std::string token_type_name(token_type t)
    7401  {
    7402  switch (t)
    7403  {
    7404  case token_type::uninitialized:
    7405  return "<uninitialized>";
    7406  case token_type::literal_true:
    7407  return "true literal";
    7408  case token_type::literal_false:
    7409  return "false literal";
    7410  case token_type::literal_null:
    7411  return "null literal";
    7412  case token_type::value_string:
    7413  return "string literal";
    7414  case token_type::value_number:
    7415  return "number literal";
    7416  case token_type::begin_array:
    7417  return "'['";
    7418  case token_type::begin_object:
    7419  return "'{'";
    7420  case token_type::end_array:
    7421  return "']'";
    7422  case token_type::end_object:
    7423  return "'}'";
    7424  case token_type::name_separator:
    7425  return "':'";
    7426  case token_type::value_separator:
    7427  return "','";
    7428  case token_type::parse_error:
    7429  return "<parse error>";
    7430  case token_type::end_of_input:
    7431  return "end of input";
    7432  default:
    7433  {
    7434  // catch non-enum values
    7435  return "unknown token"; // LCOV_EXCL_LINE
    7436  }
    7437  }
    7438  }
    7439 
    7450  token_type scan() noexcept
    7451  {
    7452  // pointer for backtracking information
    7453  m_marker = nullptr;
    7454 
    7455  // remember the begin of the token
    7456  m_start = m_cursor;
    7457  assert(m_start != nullptr);
    7458 
    7459 
    7460  {
    7461  lexer_char_t yych;
    7462  unsigned int yyaccept = 0;
    7463  static const unsigned char yybm[] =
    7464  {
    7465  0, 0, 0, 0, 0, 0, 0, 0,
    7466  0, 32, 32, 0, 0, 32, 0, 0,
    7467  128, 128, 128, 128, 128, 128, 128, 128,
    7468  128, 128, 128, 128, 128, 128, 128, 128,
    7469  160, 128, 0, 128, 128, 128, 128, 128,
    7470  128, 128, 128, 128, 128, 128, 128, 128,
    7471  192, 192, 192, 192, 192, 192, 192, 192,
    7472  192, 192, 128, 128, 128, 128, 128, 128,
    7473  128, 128, 128, 128, 128, 128, 128, 128,
    7474  128, 128, 128, 128, 128, 128, 128, 128,
    7475  128, 128, 128, 128, 128, 128, 128, 128,
    7476  128, 128, 128, 128, 0, 128, 128, 128,
    7477  128, 128, 128, 128, 128, 128, 128, 128,
    7478  128, 128, 128, 128, 128, 128, 128, 128,
    7479  128, 128, 128, 128, 128, 128, 128, 128,
    7480  128, 128, 128, 128, 128, 128, 128, 128,
    7481  128, 128, 128, 128, 128, 128, 128, 128,
    7482  128, 128, 128, 128, 128, 128, 128, 128,
    7483  128, 128, 128, 128, 128, 128, 128, 128,
    7484  128, 128, 128, 128, 128, 128, 128, 128,
    7485  128, 128, 128, 128, 128, 128, 128, 128,
    7486  128, 128, 128, 128, 128, 128, 128, 128,
    7487  128, 128, 128, 128, 128, 128, 128, 128,
    7488  128, 128, 128, 128, 128, 128, 128, 128,
    7489  128, 128, 128, 128, 128, 128, 128, 128,
    7490  128, 128, 128, 128, 128, 128, 128, 128,
    7491  128, 128, 128, 128, 128, 128, 128, 128,
    7492  128, 128, 128, 128, 128, 128, 128, 128,
    7493  128, 128, 128, 128, 128, 128, 128, 128,
    7494  128, 128, 128, 128, 128, 128, 128, 128,
    7495  128, 128, 128, 128, 128, 128, 128, 128,
    7496  128, 128, 128, 128, 128, 128, 128, 128,
    7497  };
    7498  if ((m_limit - m_cursor) < 5)
    7499  {
    7500  yyfill(); // LCOV_EXCL_LINE;
    7501  }
    7502  yych = *m_cursor;
    7503  if (yybm[0 + yych] & 32)
    7504  {
    7505  goto basic_json_parser_6;
    7506  }
    7507  if (yych <= '\\')
    7508  {
    7509  if (yych <= '-')
    7510  {
    7511  if (yych <= '"')
    7512  {
    7513  if (yych <= 0x00)
    7514  {
    7515  goto basic_json_parser_2;
    7516  }
    7517  if (yych <= '!')
    7518  {
    7519  goto basic_json_parser_4;
    7520  }
    7521  goto basic_json_parser_9;
    7522  }
    7523  else
    7524  {
    7525  if (yych <= '+')
    7526  {
    7527  goto basic_json_parser_4;
    7528  }
    7529  if (yych <= ',')
    7530  {
    7531  goto basic_json_parser_10;
    7532  }
    7533  goto basic_json_parser_12;
    7534  }
    7535  }
    7536  else
    7537  {
    7538  if (yych <= '9')
    7539  {
    7540  if (yych <= '/')
    7541  {
    7542  goto basic_json_parser_4;
    7543  }
    7544  if (yych <= '0')
    7545  {
    7546  goto basic_json_parser_13;
    7547  }
    7548  goto basic_json_parser_15;
    7549  }
    7550  else
    7551  {
    7552  if (yych <= ':')
    7553  {
    7554  goto basic_json_parser_17;
    7555  }
    7556  if (yych == '[')
    7557  {
    7558  goto basic_json_parser_19;
    7559  }
    7560  goto basic_json_parser_4;
    7561  }
    7562  }
    7563  }
    7564  else
    7565  {
    7566  if (yych <= 't')
    7567  {
    7568  if (yych <= 'f')
    7569  {
    7570  if (yych <= ']')
    7571  {
    7572  goto basic_json_parser_21;
    7573  }
    7574  if (yych <= 'e')
    7575  {
    7576  goto basic_json_parser_4;
    7577  }
    7578  goto basic_json_parser_23;
    7579  }
    7580  else
    7581  {
    7582  if (yych == 'n')
    7583  {
    7584  goto basic_json_parser_24;
    7585  }
    7586  if (yych <= 's')
    7587  {
    7588  goto basic_json_parser_4;
    7589  }
    7590  goto basic_json_parser_25;
    7591  }
    7592  }
    7593  else
    7594  {
    7595  if (yych <= '|')
    7596  {
    7597  if (yych == '{')
    7598  {
    7599  goto basic_json_parser_26;
    7600  }
    7601  goto basic_json_parser_4;
    7602  }
    7603  else
    7604  {
    7605  if (yych <= '}')
    7606  {
    7607  goto basic_json_parser_28;
    7608  }
    7609  if (yych == 0xEF)
    7610  {
    7611  goto basic_json_parser_30;
    7612  }
    7613  goto basic_json_parser_4;
    7614  }
    7615  }
    7616  }
    7617 basic_json_parser_2:
    7618  ++m_cursor;
    7619  {
    7620  return token_type::end_of_input;
    7621  }
    7622 basic_json_parser_4:
    7623  ++m_cursor;
    7624 basic_json_parser_5:
    7625  {
    7626  return token_type::parse_error;
    7627  }
    7628 basic_json_parser_6:
    7629  ++m_cursor;
    7630  if (m_limit <= m_cursor)
    7631  {
    7632  yyfill(); // LCOV_EXCL_LINE;
    7633  }
    7634  yych = *m_cursor;
    7635  if (yybm[0 + yych] & 32)
    7636  {
    7637  goto basic_json_parser_6;
    7638  }
    7639  {
    7640  return scan();
    7641  }
    7642 basic_json_parser_9:
    7643  yyaccept = 0;
    7644  yych = *(m_marker = ++m_cursor);
    7645  if (yych <= 0x0F)
    7646  {
    7647  goto basic_json_parser_5;
    7648  }
    7649  goto basic_json_parser_32;
    7650 basic_json_parser_10:
    7651  ++m_cursor;
    7652  {
    7653  return token_type::value_separator;
    7654  }
    7655 basic_json_parser_12:
    7656  yych = *++m_cursor;
    7657  if (yych <= '/')
    7658  {
    7659  goto basic_json_parser_5;
    7660  }
    7661  if (yych <= '0')
    7662  {
    7663  goto basic_json_parser_13;
    7664  }
    7665  if (yych <= '9')
    7666  {
    7667  goto basic_json_parser_15;
    7668  }
    7669  goto basic_json_parser_5;
    7670 basic_json_parser_13:
    7671  yyaccept = 1;
    7672  yych = *(m_marker = ++m_cursor);
    7673  if (yych <= 'D')
    7674  {
    7675  if (yych == '.')
    7676  {
    7677  goto basic_json_parser_37;
    7678  }
    7679  }
    7680  else
    7681  {
    7682  if (yych <= 'E')
    7683  {
    7684  goto basic_json_parser_38;
    7685  }
    7686  if (yych == 'e')
    7687  {
    7688  goto basic_json_parser_38;
    7689  }
    7690  }
    7691 basic_json_parser_14:
    7692  {
    7693  return token_type::value_number;
    7694  }
    7695 basic_json_parser_15:
    7696  yyaccept = 1;
    7697  m_marker = ++m_cursor;
    7698  if ((m_limit - m_cursor) < 3)
    7699  {
    7700  yyfill(); // LCOV_EXCL_LINE;
    7701  }
    7702  yych = *m_cursor;
    7703  if (yybm[0 + yych] & 64)
    7704  {
    7705  goto basic_json_parser_15;
    7706  }
    7707  if (yych <= 'D')
    7708  {
    7709  if (yych == '.')
    7710  {
    7711  goto basic_json_parser_37;
    7712  }
    7713  goto basic_json_parser_14;
    7714  }
    7715  else
    7716  {
    7717  if (yych <= 'E')
    7718  {
    7719  goto basic_json_parser_38;
    7720  }
    7721  if (yych == 'e')
    7722  {
    7723  goto basic_json_parser_38;
    7724  }
    7725  goto basic_json_parser_14;
    7726  }
    7727 basic_json_parser_17:
    7728  ++m_cursor;
    7729  {
    7730  return token_type::name_separator;
    7731  }
    7732 basic_json_parser_19:
    7733  ++m_cursor;
    7734  {
    7735  return token_type::begin_array;
    7736  }
    7737 basic_json_parser_21:
    7738  ++m_cursor;
    7739  {
    7740  return token_type::end_array;
    7741  }
    7742 basic_json_parser_23:
    7743  yyaccept = 0;
    7744  yych = *(m_marker = ++m_cursor);
    7745  if (yych == 'a')
    7746  {
    7747  goto basic_json_parser_39;
    7748  }
    7749  goto basic_json_parser_5;
    7750 basic_json_parser_24:
    7751  yyaccept = 0;
    7752  yych = *(m_marker = ++m_cursor);
    7753  if (yych == 'u')
    7754  {
    7755  goto basic_json_parser_40;
    7756  }
    7757  goto basic_json_parser_5;
    7758 basic_json_parser_25:
    7759  yyaccept = 0;
    7760  yych = *(m_marker = ++m_cursor);
    7761  if (yych == 'r')
    7762  {
    7763  goto basic_json_parser_41;
    7764  }
    7765  goto basic_json_parser_5;
    7766 basic_json_parser_26:
    7767  ++m_cursor;
    7768  {
    7769  return token_type::begin_object;
    7770  }
    7771 basic_json_parser_28:
    7772  ++m_cursor;
    7773  {
    7774  return token_type::end_object;
    7775  }
    7776 basic_json_parser_30:
    7777  yyaccept = 0;
    7778  yych = *(m_marker = ++m_cursor);
    7779  if (yych == 0xBB)
    7780  {
    7781  goto basic_json_parser_42;
    7782  }
    7783  goto basic_json_parser_5;
    7784 basic_json_parser_31:
    7785  ++m_cursor;
    7786  if (m_limit <= m_cursor)
    7787  {
    7788  yyfill(); // LCOV_EXCL_LINE;
    7789  }
    7790  yych = *m_cursor;
    7791 basic_json_parser_32:
    7792  if (yybm[0 + yych] & 128)
    7793  {
    7794  goto basic_json_parser_31;
    7795  }
    7796  if (yych <= 0x0F)
    7797  {
    7798  goto basic_json_parser_33;
    7799  }
    7800  if (yych <= '"')
    7801  {
    7802  goto basic_json_parser_34;
    7803  }
    7804  goto basic_json_parser_36;
    7805 basic_json_parser_33:
    7806  m_cursor = m_marker;
    7807  if (yyaccept == 0)
    7808  {
    7809  goto basic_json_parser_5;
    7810  }
    7811  else
    7812  {
    7813  goto basic_json_parser_14;
    7814  }
    7815 basic_json_parser_34:
    7816  ++m_cursor;
    7817  {
    7818  return token_type::value_string;
    7819  }
    7820 basic_json_parser_36:
    7821  ++m_cursor;
    7822  if (m_limit <= m_cursor)
    7823  {
    7824  yyfill(); // LCOV_EXCL_LINE;
    7825  }
    7826  yych = *m_cursor;
    7827  if (yych <= 'e')
    7828  {
    7829  if (yych <= '/')
    7830  {
    7831  if (yych == '"')
    7832  {
    7833  goto basic_json_parser_31;
    7834  }
    7835  if (yych <= '.')
    7836  {
    7837  goto basic_json_parser_33;
    7838  }
    7839  goto basic_json_parser_31;
    7840  }
    7841  else
    7842  {
    7843  if (yych <= '\\')
    7844  {
    7845  if (yych <= '[')
    7846  {
    7847  goto basic_json_parser_33;
    7848  }
    7849  goto basic_json_parser_31;
    7850  }
    7851  else
    7852  {
    7853  if (yych == 'b')
    7854  {
    7855  goto basic_json_parser_31;
    7856  }
    7857  goto basic_json_parser_33;
    7858  }
    7859  }
    7860  }
    7861  else
    7862  {
    7863  if (yych <= 'q')
    7864  {
    7865  if (yych <= 'f')
    7866  {
    7867  goto basic_json_parser_31;
    7868  }
    7869  if (yych == 'n')
    7870  {
    7871  goto basic_json_parser_31;
    7872  }
    7873  goto basic_json_parser_33;
    7874  }
    7875  else
    7876  {
    7877  if (yych <= 's')
    7878  {
    7879  if (yych <= 'r')
    7880  {
    7881  goto basic_json_parser_31;
    7882  }
    7883  goto basic_json_parser_33;
    7884  }
    7885  else
    7886  {
    7887  if (yych <= 't')
    7888  {
    7889  goto basic_json_parser_31;
    7890  }
    7891  if (yych <= 'u')
    7892  {
    7893  goto basic_json_parser_43;
    7894  }
    7895  goto basic_json_parser_33;
    7896  }
    7897  }
    7898  }
    7899 basic_json_parser_37:
    7900  yych = *++m_cursor;
    7901  if (yych <= '/')
    7902  {
    7903  goto basic_json_parser_33;
    7904  }
    7905  if (yych <= '9')
    7906  {
    7907  goto basic_json_parser_44;
    7908  }
    7909  goto basic_json_parser_33;
    7910 basic_json_parser_38:
    7911  yych = *++m_cursor;
    7912  if (yych <= ',')
    7913  {
    7914  if (yych == '+')
    7915  {
    7916  goto basic_json_parser_46;
    7917  }
    7918  goto basic_json_parser_33;
    7919  }
    7920  else
    7921  {
    7922  if (yych <= '-')
    7923  {
    7924  goto basic_json_parser_46;
    7925  }
    7926  if (yych <= '/')
    7927  {
    7928  goto basic_json_parser_33;
    7929  }
    7930  if (yych <= '9')
    7931  {
    7932  goto basic_json_parser_47;
    7933  }
    7934  goto basic_json_parser_33;
    7935  }
    7936 basic_json_parser_39:
    7937  yych = *++m_cursor;
    7938  if (yych == 'l')
    7939  {
    7940  goto basic_json_parser_49;
    7941  }
    7942  goto basic_json_parser_33;
    7943 basic_json_parser_40:
    7944  yych = *++m_cursor;
    7945  if (yych == 'l')
    7946  {
    7947  goto basic_json_parser_50;
    7948  }
    7949  goto basic_json_parser_33;
    7950 basic_json_parser_41:
    7951  yych = *++m_cursor;
    7952  if (yych == 'u')
    7953  {
    7954  goto basic_json_parser_51;
    7955  }
    7956  goto basic_json_parser_33;
    7957 basic_json_parser_42:
    7958  yych = *++m_cursor;
    7959  if (yych == 0xBF)
    7960  {
    7961  goto basic_json_parser_52;
    7962  }
    7963  goto basic_json_parser_33;
    7964 basic_json_parser_43:
    7965  ++m_cursor;
    7966  if (m_limit <= m_cursor)
    7967  {
    7968  yyfill(); // LCOV_EXCL_LINE;
    7969  }
    7970  yych = *m_cursor;
    7971  if (yych <= '@')
    7972  {
    7973  if (yych <= '/')
    7974  {
    7975  goto basic_json_parser_33;
    7976  }
    7977  if (yych <= '9')
    7978  {
    7979  goto basic_json_parser_54;
    7980  }
    7981  goto basic_json_parser_33;
    7982  }
    7983  else
    7984  {
    7985  if (yych <= 'F')
    7986  {
    7987  goto basic_json_parser_54;
    7988  }
    7989  if (yych <= '`')
    7990  {
    7991  goto basic_json_parser_33;
    7992  }
    7993  if (yych <= 'f')
    7994  {
    7995  goto basic_json_parser_54;
    7996  }
    7997  goto basic_json_parser_33;
    7998  }
    7999 basic_json_parser_44:
    8000  yyaccept = 1;
    8001  m_marker = ++m_cursor;
    8002  if ((m_limit - m_cursor) < 3)
    8003  {
    8004  yyfill(); // LCOV_EXCL_LINE;
    8005  }
    8006  yych = *m_cursor;
    8007  if (yych <= 'D')
    8008  {
    8009  if (yych <= '/')
    8010  {
    8011  goto basic_json_parser_14;
    8012  }
    8013  if (yych <= '9')
    8014  {
    8015  goto basic_json_parser_44;
    8016  }
    8017  goto basic_json_parser_14;
    8018  }
    8019  else
    8020  {
    8021  if (yych <= 'E')
    8022  {
    8023  goto basic_json_parser_38;
    8024  }
    8025  if (yych == 'e')
    8026  {
    8027  goto basic_json_parser_38;
    8028  }
    8029  goto basic_json_parser_14;
    8030  }
    8031 basic_json_parser_46:
    8032  yych = *++m_cursor;
    8033  if (yych <= '/')
    8034  {
    8035  goto basic_json_parser_33;
    8036  }
    8037  if (yych >= ':')
    8038  {
    8039  goto basic_json_parser_33;
    8040  }
    8041 basic_json_parser_47:
    8042  ++m_cursor;
    8043  if (m_limit <= m_cursor)
    8044  {
    8045  yyfill(); // LCOV_EXCL_LINE;
    8046  }
    8047  yych = *m_cursor;
    8048  if (yych <= '/')
    8049  {
    8050  goto basic_json_parser_14;
    8051  }
    8052  if (yych <= '9')
    8053  {
    8054  goto basic_json_parser_47;
    8055  }
    8056  goto basic_json_parser_14;
    8057 basic_json_parser_49:
    8058  yych = *++m_cursor;
    8059  if (yych == 's')
    8060  {
    8061  goto basic_json_parser_55;
    8062  }
    8063  goto basic_json_parser_33;
    8064 basic_json_parser_50:
    8065  yych = *++m_cursor;
    8066  if (yych == 'l')
    8067  {
    8068  goto basic_json_parser_56;
    8069  }
    8070  goto basic_json_parser_33;
    8071 basic_json_parser_51:
    8072  yych = *++m_cursor;
    8073  if (yych == 'e')
    8074  {
    8075  goto basic_json_parser_58;
    8076  }
    8077  goto basic_json_parser_33;
    8078 basic_json_parser_52:
    8079  ++m_cursor;
    8080  {
    8081  return scan();
    8082  }
    8083 basic_json_parser_54:
    8084  ++m_cursor;
    8085  if (m_limit <= m_cursor)
    8086  {
    8087  yyfill(); // LCOV_EXCL_LINE;
    8088  }
    8089  yych = *m_cursor;
    8090  if (yych <= '@')
    8091  {
    8092  if (yych <= '/')
    8093  {
    8094  goto basic_json_parser_33;
    8095  }
    8096  if (yych <= '9')
    8097  {
    8098  goto basic_json_parser_60;
    8099  }
    8100  goto basic_json_parser_33;
    8101  }
    8102  else
    8103  {
    8104  if (yych <= 'F')
    8105  {
    8106  goto basic_json_parser_60;
    8107  }
    8108  if (yych <= '`')
    8109  {
    8110  goto basic_json_parser_33;
    8111  }
    8112  if (yych <= 'f')
    8113  {
    8114  goto basic_json_parser_60;
    8115  }
    8116  goto basic_json_parser_33;
    8117  }
    8118 basic_json_parser_55:
    8119  yych = *++m_cursor;
    8120  if (yych == 'e')
    8121  {
    8122  goto basic_json_parser_61;
    8123  }
    8124  goto basic_json_parser_33;
    8125 basic_json_parser_56:
    8126  ++m_cursor;
    8127  {
    8128  return token_type::literal_null;
    8129  }
    8130 basic_json_parser_58:
    8131  ++m_cursor;
    8132  {
    8133  return token_type::literal_true;
    8134  }
    8135 basic_json_parser_60:
    8136  ++m_cursor;
    8137  if (m_limit <= m_cursor)
    8138  {
    8139  yyfill(); // LCOV_EXCL_LINE;
    8140  }
    8141  yych = *m_cursor;
    8142  if (yych <= '@')
    8143  {
    8144  if (yych <= '/')
    8145  {
    8146  goto basic_json_parser_33;
    8147  }
    8148  if (yych <= '9')
    8149  {
    8150  goto basic_json_parser_63;
    8151  }
    8152  goto basic_json_parser_33;
    8153  }
    8154  else
    8155  {
    8156  if (yych <= 'F')
    8157  {
    8158  goto basic_json_parser_63;
    8159  }
    8160  if (yych <= '`')
    8161  {
    8162  goto basic_json_parser_33;
    8163  }
    8164  if (yych <= 'f')
    8165  {
    8166  goto basic_json_parser_63;
    8167  }
    8168  goto basic_json_parser_33;
    8169  }
    8170 basic_json_parser_61:
    8171  ++m_cursor;
    8172  {
    8173  return token_type::literal_false;
    8174  }
    8175 basic_json_parser_63:
    8176  ++m_cursor;
    8177  if (m_limit <= m_cursor)
    8178  {
    8179  yyfill(); // LCOV_EXCL_LINE;
    8180  }
    8181  yych = *m_cursor;
    8182  if (yych <= '@')
    8183  {
    8184  if (yych <= '/')
    8185  {
    8186  goto basic_json_parser_33;
    8187  }
    8188  if (yych <= '9')
    8189  {
    8190  goto basic_json_parser_31;
    8191  }
    8192  goto basic_json_parser_33;
    8193  }
    8194  else
    8195  {
    8196  if (yych <= 'F')
    8197  {
    8198  goto basic_json_parser_31;
    8199  }
    8200  if (yych <= '`')
    8201  {
    8202  goto basic_json_parser_33;
    8203  }
    8204  if (yych <= 'f')
    8205  {
    8206  goto basic_json_parser_31;
    8207  }
    8208  goto basic_json_parser_33;
    8209  }
    8210  }
    8211 
    8212  }
    8213 
    8215  void yyfill() noexcept
    8216  {
    8217  if (m_stream == nullptr or not * m_stream)
    8218  {
    8219  return;
    8220  }
    8221 
    8222  const auto offset_start = m_start - m_content;
    8223  const auto offset_marker = m_marker - m_start;
    8224  const auto offset_cursor = m_cursor - m_start;
    8225 
    8226  m_buffer.erase(0, static_cast<size_t>(offset_start));
    8227  std::string line;
    8228  assert(m_stream != nullptr);
    8229  std::getline(*m_stream, line);
    8230  m_buffer += "\n" + line; // add line with newline symbol
    8231 
    8232  m_content = reinterpret_cast<const lexer_char_t*>(m_buffer.c_str());
    8233  assert(m_content != nullptr);
    8234  m_start = m_content;
    8235  m_marker = m_start + offset_marker;
    8236  m_cursor = m_start + offset_cursor;
    8237  m_limit = m_start + m_buffer.size() - 1;
    8238  }
    8239 
    8241  string_t get_token() const
    8242  {
    8243  assert(m_start != nullptr);
    8244  return string_t(reinterpret_cast<typename string_t::const_pointer>(m_start),
    8245  static_cast<size_t>(m_cursor - m_start));
    8246  }
    8247 
    8269  string_t get_string() const
    8270  {
    8271  string_t result;
    8272  result.reserve(static_cast<size_t>(m_cursor - m_start - 2));
    8273 
    8274  // iterate the result between the quotes
    8275  for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
    8276  {
    8277  // process escaped characters
    8278  if (*i == '\\')
    8279  {
    8280  // read next character
    8281  ++i;
    8282 
    8283  switch (*i)
    8284  {
    8285  // the default escapes
    8286  case 't':
    8287  {
    8288  result += "\t";
    8289  break;
    8290  }
    8291  case 'b':
    8292  {
    8293  result += "\b";
    8294  break;
    8295  }
    8296  case 'f':
    8297  {
    8298  result += "\f";
    8299  break;
    8300  }
    8301  case 'n':
    8302  {
    8303  result += "\n";
    8304  break;
    8305  }
    8306  case 'r':
    8307  {
    8308  result += "\r";
    8309  break;
    8310  }
    8311  case '\\':
    8312  {
    8313  result += "\\";
    8314  break;
    8315  }
    8316  case '/':
    8317  {
    8318  result += "/";
    8319  break;
    8320  }
    8321  case '"':
    8322  {
    8323  result += "\"";
    8324  break;
    8325  }
    8326 
    8327  // unicode
    8328  case 'u':
    8329  {
    8330  // get code xxxx from uxxxx
    8331  auto codepoint = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>(i + 1),
    8332  4).c_str(), nullptr, 16);
    8333 
    8334  // check if codepoint is a high surrogate
    8335  if (codepoint >= 0xD800 and codepoint <= 0xDBFF)
    8336  {
    8337  // make sure there is a subsequent unicode
    8338  if ((i + 6 >= m_limit) or * (i + 5) != '\\' or * (i + 6) != 'u')
    8339  {
    8340  throw std::invalid_argument("missing low surrogate");
    8341  }
    8342 
    8343  // get code yyyy from uxxxx\uyyyy
    8344  auto codepoint2 = std::strtoul(std::string(reinterpret_cast<typename string_t::const_pointer>
    8345  (i + 7), 4).c_str(), nullptr, 16);
    8346  result += to_unicode(codepoint, codepoint2);
    8347  // skip the next 10 characters (xxxx\uyyyy)
    8348  i += 10;
    8349  }
    8350  else
    8351  {
    8352  // add unicode character(s)
    8353  result += to_unicode(codepoint);
    8354  // skip the next four characters (xxxx)
    8355  i += 4;
    8356  }
    8357  break;
    8358  }
    8359  }
    8360  }
    8361  else
    8362  {
    8363  // all other characters are just copied to the end of the
    8364  // string
    8365  result.append(1, static_cast<typename string_t::value_type>(*i));
    8366  }
    8367  }
    8368 
    8369  return result;
    8370  }
    8371 
    8392  long double str_to_float_t(long double* /* type */, char** endptr) const
    8393  {
    8394  return std::strtold(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8395  }
    8396 
    8412  double str_to_float_t(double* /* type */, char** endptr) const
    8413  {
    8414  return std::strtod(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8415  }
    8416 
    8432  float str_to_float_t(float* /* type */, char** endptr) const
    8433  {
    8434  return std::strtof(reinterpret_cast<typename string_t::const_pointer>(m_start), endptr);
    8435  }
    8436 
    8464  void get_number(basic_json& result) const
    8465  {
    8466  assert(m_start != nullptr);
    8467 
    8468  const lexer::lexer_char_t* curptr = m_start;
    8469 
    8470  // remember this number was parsed (for later serialization)
    8471  result.m_type.bits.parsed = true;
    8472 
    8473  // 'found_radix_point' will be set to 0xFF upon finding a radix
    8474  // point and later used to mask in/out the precision depending
    8475  // whether a radix is found i.e. 'precision &= found_radix_point'
    8476  uint8_t found_radix_point = 0;
    8477  uint8_t precision = 0;
    8478 
    8479  // accumulate the integer conversion result (unsigned for now)
    8480  number_unsigned_t value = 0;
    8481 
    8482  // maximum absolute value of the relevant integer type
    8483  number_unsigned_t max;
    8484 
    8485  // temporarily store the type to avoid unecessary bitfield access
    8486  value_t type;
    8487 
    8488  // look for sign
    8489  if (*curptr == '-')
    8490  {
    8491  type = value_t::number_integer;
    8492  max = static_cast<uint64_t>(std::numeric_limits<number_integer_t>::max()) + 1;
    8493  curptr++;
    8494  }
    8495  else
    8496  {
    8497  type = value_t::number_unsigned;
    8498  max = static_cast<uint64_t>(std::numeric_limits<number_unsigned_t>::max());
    8499  }
    8500 
    8501  // count the significant figures
    8502  for (; curptr < m_cursor; curptr++)
    8503  {
    8504  // quickly skip tests if a digit
    8505  if (*curptr < '0' || *curptr > '9')
    8506  {
    8507  if (*curptr == '.')
    8508  {
    8509  // don't count '.' but change to float
    8510  type = value_t::number_float;
    8511 
    8512  // reset precision count
    8513  precision = 0;
    8514  found_radix_point = 0xFF;
    8515  continue;
    8516  }
    8517  // assume exponent (if not then will fail parse): change to
    8518  // float, stop counting and record exponent details
    8519  type = value_t::number_float;
    8520  result.m_type.bits.has_exp = true;
    8521 
    8522  // exponent capitalization
    8523  result.m_type.bits.exp_cap = (*curptr == 'E');
    8524 
    8525  // exponent '+' sign
    8526  result.m_type.bits.exp_plus = (*(++curptr) == '+');
    8527  break;
    8528  }
    8529 
    8530  // skip if definitely not an integer
    8531  if (type != value_t::number_float)
    8532  {
    8533  // multiply last value by ten and add the new digit
    8534  auto temp = value * 10 + *curptr - 0x30;
    8535 
    8536  // test for overflow
    8537  if (temp < value || temp > max)
    8538  {
    8539  // overflow
    8540  type = value_t::number_float;
    8541  }
    8542  else
    8543  {
    8544  // no overflow - save it
    8545  value = temp;
    8546  }
    8547  }
    8548  ++precision;
    8549  }
    8550 
    8551  // If no radix point was found then precision would now be set to
    8552  // the number of digits, which is wrong - clear it.
    8553  result.m_type.bits.precision = precision & found_radix_point;
    8554 
    8555  // save the value (if not a float)
    8556  if (type == value_t::number_unsigned)
    8557  {
    8558  result.m_value.number_unsigned = value;
    8559  }
    8560  else if (type == value_t::number_integer)
    8561  {
    8562  result.m_value.number_integer = -static_cast<number_integer_t>(value);
    8563  }
    8564  else
    8565  {
    8566  // parse with strtod
    8567  result.m_value.number_float = str_to_float_t(static_cast<number_float_t*>(nullptr), NULL);
    8568  }
    8569 
    8570  // save the type
    8571  result.m_type = type;
    8572  }
    8573 
    8574  private:
    8576  std::istream* m_stream = nullptr;
    8578  string_t m_buffer;
    8580  const lexer_char_t* m_content = nullptr;
    8582  const lexer_char_t* m_start = nullptr;
    8584  const lexer_char_t* m_marker = nullptr;
    8586  const lexer_char_t* m_cursor = nullptr;
    8588  const lexer_char_t* m_limit = nullptr;
    8589  };
    8590 
    8596  class parser
    8597  {
    8598  public:
    8600  parser(const string_t& s, parser_callback_t cb = nullptr) noexcept
    8601  : callback(cb), m_lexer(s)
    8602  {
    8603  // read first token
    8604  get_token();
    8605  }
    8606 
    8608  parser(std::istream& _is, parser_callback_t cb = nullptr) noexcept
    8609  : callback(cb), m_lexer(&_is)
    8610  {
    8611  // read first token
    8612  get_token();
    8613  }
    8614 
    8616  basic_json parse()
    8617  {
    8618  basic_json result = parse_internal(true);
    8619 
    8620  expect(lexer::token_type::end_of_input);
    8621 
    8622  // return parser result and replace it with null in case the
    8623  // top-level value was discarded by the callback function
    8624  return result.is_discarded() ? basic_json() : result;
    8625  }
    8626 
    8627  private:
    8629  basic_json parse_internal(bool keep)
    8630  {
    8631  auto result = basic_json(value_t::discarded);
    8632 
    8633  switch (last_token)
    8634  {
    8635  case lexer::token_type::begin_object:
    8636  {
    8637  if (keep and (not callback or (keep = callback(depth++, parse_event_t::object_start, result))))
    8638  {
    8639  // explicitly set result to object to cope with {}
    8640  result.m_type = value_t::object;
    8641  result.m_value = json_value(value_t::object);
    8642  }
    8643 
    8644  // read next token
    8645  get_token();
    8646 
    8647  // closing } -> we are done
    8648  if (last_token == lexer::token_type::end_object)
    8649  {
    8650  get_token();
    8651  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8652  {
    8653  result = basic_json(value_t::discarded);
    8654  }
    8655  return result;
    8656  }
    8657 
    8658  // no comma is expected here
    8659  unexpect(lexer::token_type::value_separator);
    8660 
    8661  // otherwise: parse key-value pairs
    8662  do
    8663  {
    8664  // ugly, but could be fixed with loop reorganization
    8665  if (last_token == lexer::token_type::value_separator)
    8666  {
    8667  get_token();
    8668  }
    8669 
    8670  // store key
    8671  expect(lexer::token_type::value_string);
    8672  const auto key = m_lexer.get_string();
    8673 
    8674  bool keep_tag = false;
    8675  if (keep)
    8676  {
    8677  if (callback)
    8678  {
    8679  basic_json k(key);
    8680  keep_tag = callback(depth, parse_event_t::key, k);
    8681  }
    8682  else
    8683  {
    8684  keep_tag = true;
    8685  }
    8686  }
    8687 
    8688  // parse separator (:)
    8689  get_token();
    8690  expect(lexer::token_type::name_separator);
    8691 
    8692  // parse and add value
    8693  get_token();
    8694  auto value = parse_internal(keep);
    8695  if (keep and keep_tag and not value.is_discarded())
    8696  {
    8697  result[key] = std::move(value);
    8698  }
    8699  }
    8700  while (last_token == lexer::token_type::value_separator);
    8701 
    8702  // closing }
    8703  expect(lexer::token_type::end_object);
    8704  get_token();
    8705  if (keep and callback and not callback(--depth, parse_event_t::object_end, result))
    8706  {
    8707  result = basic_json(value_t::discarded);
    8708  }
    8709 
    8710  return result;
    8711  }
    8712 
    8713  case lexer::token_type::begin_array:
    8714  {
    8715  if (keep and (not callback or (keep = callback(depth++, parse_event_t::array_start, result))))
    8716  {
    8717  // explicitly set result to object to cope with []
    8718  result.m_type = value_t::array;
    8719  result.m_value = json_value(value_t::array);
    8720  }
    8721 
    8722  // read next token
    8723  get_token();
    8724 
    8725  // closing ] -> we are done
    8726  if (last_token == lexer::token_type::end_array)
    8727  {
    8728  get_token();
    8729  if (callback and not callback(--depth, parse_event_t::array_end, result))
    8730  {
    8731  result = basic_json(value_t::discarded);
    8732  }
    8733  return result;
    8734  }
    8735 
    8736  // no comma is expected here
    8737  unexpect(lexer::token_type::value_separator);
    8738 
    8739  // otherwise: parse values
    8740  do
    8741  {
    8742  // ugly, but could be fixed with loop reorganization
    8743  if (last_token == lexer::token_type::value_separator)
    8744  {
    8745  get_token();
    8746  }
    8747 
    8748  // parse value
    8749  auto value = parse_internal(keep);
    8750  if (keep and not value.is_discarded())
    8751  {
    8752  result.push_back(std::move(value));
    8753  }
    8754  }
    8755  while (last_token == lexer::token_type::value_separator);
    8756 
    8757  // closing ]
    8758  expect(lexer::token_type::end_array);
    8759  get_token();
    8760  if (keep and callback and not callback(--depth, parse_event_t::array_end, result))
    8761  {
    8762  result = basic_json(value_t::discarded);
    8763  }
    8764 
    8765  return result;
    8766  }
    8767 
    8768  case lexer::token_type::literal_null:
    8769  {
    8770  get_token();
    8771  result.m_type = value_t::null;
    8772  break;
    8773  }
    8774 
    8775  case lexer::token_type::value_string:
    8776  {
    8777  const auto s = m_lexer.get_string();
    8778  get_token();
    8779  result = basic_json(s);
    8780  break;
    8781  }
    8782 
    8783  case lexer::token_type::literal_true:
    8784  {
    8785  get_token();
    8786  result.m_type = value_t::boolean;
    8787  result.m_value = true;
    8788  break;
    8789  }
    8790 
    8791  case lexer::token_type::literal_false:
    8792  {
    8793  get_token();
    8794  result.m_type = value_t::boolean;
    8795  result.m_value = false;
    8796  break;
    8797  }
    8798 
    8799  case lexer::token_type::value_number:
    8800  {
    8801  m_lexer.get_number(result);
    8802  get_token();
    8803  break;
    8804  }
    8805 
    8806  default:
    8807  {
    8808  // the last token was unexpected
    8809  unexpect(last_token);
    8810  }
    8811  }
    8812 
    8813  if (keep and callback and not callback(depth, parse_event_t::value, result))
    8814  {
    8815  result = basic_json(value_t::discarded);
    8816  }
    8817  return result;
    8818  }
    8819 
    8821  typename lexer::token_type get_token() noexcept
    8822  {
    8823  last_token = m_lexer.scan();
    8824  return last_token;
    8825  }
    8826 
    8827  void expect(typename lexer::token_type t) const
    8828  {
    8829  if (t != last_token)
    8830  {
    8831  std::string error_msg = "parse error - unexpected ";
    8832  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8833  lexer::token_type_name(last_token));
    8834  error_msg += "; expected " + lexer::token_type_name(t);
    8835  throw std::invalid_argument(error_msg);
    8836  }
    8837  }
    8838 
    8839  void unexpect(typename lexer::token_type t) const
    8840  {
    8841  if (t == last_token)
    8842  {
    8843  std::string error_msg = "parse error - unexpected ";
    8844  error_msg += (last_token == lexer::token_type::parse_error ? ("'" + m_lexer.get_token() + "'") :
    8845  lexer::token_type_name(last_token));
    8846  throw std::invalid_argument(error_msg);
    8847  }
    8848  }
    8849 
    8850  private:
    8852  int depth = 0;
    8854  parser_callback_t callback;
    8856  typename lexer::token_type last_token = lexer::token_type::uninitialized;
    8858  lexer m_lexer;
    8859  };
    8860 
    8861  public:
    8874  {
    8876  friend class basic_json;
    8877 
    8878  public:
    8901  explicit json_pointer(const std::string& s = "")
    8902  : reference_tokens(split(s))
    8903  {}
    8904 
    8920  std::string to_string() const noexcept
    8921  {
    8922  std::string result;
    8923 
    8924  for (const auto& reference_token : reference_tokens)
    8925  {
    8926  result += "/" + escape(reference_token);
    8927  }
    8928 
    8929  return result;
    8930  }
    8931 
    8933  operator std::string() const
    8934  {
    8935  return to_string();
    8936  }
    8938  private:
    8940  std::string pop_back()
    8941  {
    8942  if (is_root())
    8943  {
    8944  throw std::domain_error("JSON pointer has no parent");
    8945  }
    8946 
    8947  auto last = reference_tokens.back();
    8948  reference_tokens.pop_back();
    8949  return last;
    8950  }
    8951 
    8953  bool is_root() const
    8954  {
    8955  return reference_tokens.empty();
    8956  }
    8957 
    8958  json_pointer top() const
    8959  {
    8960  if (is_root())
    8961  {
    8962  throw std::domain_error("JSON pointer has no parent");
    8963  }
    8964 
    8965  json_pointer result = *this;
    8966  result.reference_tokens = {reference_tokens[0]};
    8967  return result;
    8968  }
    8969 
    8973  reference get_and_create(reference j) const
    8974  {
    8975  pointer result = &j;
    8976 
    8977  // in case no reference tokens exist, return a reference to the
    8978  // JSON value j which will be overwritten by a primitive value
    8979  for (const auto& reference_token : reference_tokens)
    8980  {
    8981  switch (result->m_type)
    8982  {
    8983  case value_t::null:
    8984  {
    8985  if (reference_token == "0")
    8986  {
    8987  // start a new array if reference token is 0
    8988  result = &result->operator[](0);
    8989  }
    8990  else
    8991  {
    8992  // start a new object otherwise
    8993  result = &result->operator[](reference_token);
    8994  }
    8995  break;
    8996  }
    8997 
    8998  case value_t::object:
    8999  {
    9000  // create an entry in the object
    9001  result = &result->operator[](reference_token);
    9002  break;
    9003  }
    9004 
    9005  case value_t::array:
    9006  {
    9007  // create an entry in the array
    9008  result = &result->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9009  break;
    9010  }
    9011 
    9012  /*
    9013  The following code is only reached if there exists a
    9014  reference token _and_ the current value is primitive. In
    9015  this case, we have an error situation, because primitive
    9016  values may only occur as single value; that is, with an
    9017  empty list of reference tokens.
    9018  */
    9019  default:
    9020  {
    9021  throw std::domain_error("invalid value to unflatten");
    9022  }
    9023  }
    9024  }
    9025 
    9026  return *result;
    9027  }
    9028 
    9042  reference get_unchecked(pointer ptr) const
    9043  {
    9044  for (const auto& reference_token : reference_tokens)
    9045  {
    9046  switch (ptr->m_type)
    9047  {
    9048  case value_t::object:
    9049  {
    9050  // use unchecked object access
    9051  ptr = &ptr->operator[](reference_token);
    9052  break;
    9053  }
    9054 
    9055  case value_t::array:
    9056  {
    9057  // error condition (cf. RFC 6901, Sect. 4)
    9058  if (reference_token.size() > 1 and reference_token[0] == '0')
    9059  {
    9060  throw std::domain_error("array index must not begin with '0'");
    9061  }
    9062 
    9063  if (reference_token == "-")
    9064  {
    9065  // explicityly treat "-" as index beyond the end
    9066  ptr = &ptr->operator[](ptr->m_value.array->size());
    9067  }
    9068  else
    9069  {
    9070  // convert array index to number; unchecked access
    9071  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9072  }
    9073  break;
    9074  }
    9075 
    9076  default:
    9077  {
    9078  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9079  }
    9080  }
    9081  }
    9082 
    9083  return *ptr;
    9084  }
    9085 
    9086  reference get_checked(pointer ptr) const
    9087  {
    9088  for (const auto& reference_token : reference_tokens)
    9089  {
    9090  switch (ptr->m_type)
    9091  {
    9092  case value_t::object:
    9093  {
    9094  // note: at performs range check
    9095  ptr = &ptr->at(reference_token);
    9096  break;
    9097  }
    9098 
    9099  case value_t::array:
    9100  {
    9101  if (reference_token == "-")
    9102  {
    9103  // "-" always fails the range check
    9104  throw std::out_of_range("array index '-' (" +
    9105  std::to_string(ptr->m_value.array->size()) +
    9106  ") is out of range");
    9107  }
    9108 
    9109  // error condition (cf. RFC 6901, Sect. 4)
    9110  if (reference_token.size() > 1 and reference_token[0] == '0')
    9111  {
    9112  throw std::domain_error("array index must not begin with '0'");
    9113  }
    9114 
    9115  // note: at performs range check
    9116  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9117  break;
    9118  }
    9119 
    9120  default:
    9121  {
    9122  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9123  }
    9124  }
    9125  }
    9126 
    9127  return *ptr;
    9128  }
    9129 
    9138  const_reference get_unchecked(const_pointer ptr) const
    9139  {
    9140  for (const auto& reference_token : reference_tokens)
    9141  {
    9142  switch (ptr->m_type)
    9143  {
    9144  case value_t::object:
    9145  {
    9146  // use unchecked object access
    9147  ptr = &ptr->operator[](reference_token);
    9148  break;
    9149  }
    9150 
    9151  case value_t::array:
    9152  {
    9153  if (reference_token == "-")
    9154  {
    9155  // "-" cannot be used for const access
    9156  throw std::out_of_range("array index '-' (" +
    9157  std::to_string(ptr->m_value.array->size()) +
    9158  ") is out of range");
    9159  }
    9160 
    9161  // error condition (cf. RFC 6901, Sect. 4)
    9162  if (reference_token.size() > 1 and reference_token[0] == '0')
    9163  {
    9164  throw std::domain_error("array index must not begin with '0'");
    9165  }
    9166 
    9167  // use unchecked array access
    9168  ptr = &ptr->operator[](static_cast<size_type>(std::stoi(reference_token)));
    9169  break;
    9170  }
    9171 
    9172  default:
    9173  {
    9174  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9175  }
    9176  }
    9177  }
    9178 
    9179  return *ptr;
    9180  }
    9181 
    9182  const_reference get_checked(const_pointer ptr) const
    9183  {
    9184  for (const auto& reference_token : reference_tokens)
    9185  {
    9186  switch (ptr->m_type)
    9187  {
    9188  case value_t::object:
    9189  {
    9190  // note: at performs range check
    9191  ptr = &ptr->at(reference_token);
    9192  break;
    9193  }
    9194 
    9195  case value_t::array:
    9196  {
    9197  if (reference_token == "-")
    9198  {
    9199  // "-" always fails the range check
    9200  throw std::out_of_range("array index '-' (" +
    9201  std::to_string(ptr->m_value.array->size()) +
    9202  ") is out of range");
    9203  }
    9204 
    9205  // error condition (cf. RFC 6901, Sect. 4)
    9206  if (reference_token.size() > 1 and reference_token[0] == '0')
    9207  {
    9208  throw std::domain_error("array index must not begin with '0'");
    9209  }
    9210 
    9211  // note: at performs range check
    9212  ptr = &ptr->at(static_cast<size_type>(std::stoi(reference_token)));
    9213  break;
    9214  }
    9215 
    9216  default:
    9217  {
    9218  throw std::out_of_range("unresolved reference token '" + reference_token + "'");
    9219  }
    9220  }
    9221  }
    9222 
    9223  return *ptr;
    9224  }
    9225 
    9227  static std::vector<std::string> split(std::string reference_string)
    9228  {
    9229  std::vector<std::string> result;
    9230 
    9231  // special case: empty reference string -> no reference tokens
    9232  if (reference_string.empty())
    9233  {
    9234  return result;
    9235  }
    9236 
    9237  // check if nonempty reference string begins with slash
    9238  if (reference_string[0] != '/')
    9239  {
    9240  throw std::domain_error("JSON pointer must be empty or begin with '/'");
    9241  }
    9242 
    9243  // extract the reference tokens:
    9244  // - slash: position of the last read slash (or end of string)
    9245  // - start: position after the previous slash
    9246  for (
    9247  // search for the first slash after the first character
    9248  size_t slash = reference_string.find_first_of("/", 1),
    9249  // set the beginning of the first reference token
    9250  start = 1;
    9251  // we can stop if start == string::npos+1 = 0
    9252  start != 0;
    9253  // set the beginning of the next reference token
    9254  // (will eventually be 0 if slash == std::string::npos)
    9255  start = slash + 1,
    9256  // find next slash
    9257  slash = reference_string.find_first_of("/", start))
    9258  {
    9259  // use the text between the beginning of the reference token
    9260  // (start) and the last slash (slash).
    9261  auto reference_token = reference_string.substr(start, slash - start);
    9262 
    9263  // check reference tokens are properly escaped
    9264  for (size_t pos = reference_token.find_first_of("~");
    9265  pos != std::string::npos;
    9266  pos = reference_token.find_first_of("~", pos + 1))
    9267  {
    9268  assert(reference_token[pos] == '~');
    9269 
    9270  // ~ must be followed by 0 or 1
    9271  if (pos == reference_token.size() - 1 or
    9272  (reference_token[pos + 1] != '0' and
    9273  reference_token[pos + 1] != '1'))
    9274  {
    9275  throw std::domain_error("escape error: '~' must be followed with '0' or '1'");
    9276  }
    9277  }
    9278 
    9279  // finally, store the reference token
    9280  unescape(reference_token);
    9281  result.push_back(reference_token);
    9282  }
    9283 
    9284  return result;
    9285  }
    9286 
    9287  private:
    9302  static void replace_substring(std::string& s,
    9303  const std::string& f,
    9304  const std::string& t)
    9305  {
    9306  assert(not f.empty());
    9307 
    9308  for (
    9309  size_t pos = s.find(f); // find first occurrence of f
    9310  pos != std::string::npos; // make sure f was found
    9311  s.replace(pos, f.size(), t), // replace with t
    9312  pos = s.find(f, pos + t.size()) // find next occurrence of f
    9313  );
    9314  }
    9315 
    9317  static std::string escape(std::string s)
    9318  {
    9319  // escape "~"" to "~0" and "/" to "~1"
    9320  replace_substring(s, "~", "~0");
    9321  replace_substring(s, "/", "~1");
    9322  return s;
    9323  }
    9324 
    9326  static void unescape(std::string& s)
    9327  {
    9328  // first transform any occurrence of the sequence '~1' to '/'
    9329  replace_substring(s, "~1", "/");
    9330  // then transform any occurrence of the sequence '~0' to '~'
    9331  replace_substring(s, "~0", "~");
    9332  }
    9333 
    9341  static void flatten(const std::string& reference_string,
    9342  const basic_json& value,
    9343  basic_json& result)
    9344  {
    9345  switch (value.m_type)
    9346  {
    9347  case value_t::array:
    9348  {
    9349  if (value.m_value.array->empty())
    9350  {
    9351  // flatten empty array as null
    9352  result[reference_string] = nullptr;
    9353  }
    9354  else
    9355  {
    9356  // iterate array and use index as reference string
    9357  for (size_t i = 0; i < value.m_value.array->size(); ++i)
    9358  {
    9359  flatten(reference_string + "/" + std::to_string(i),
    9360  value.m_value.array->operator[](i), result);
    9361  }
    9362  }
    9363  break;
    9364  }
    9365 
    9366  case value_t::object:
    9367  {
    9368  if (value.m_value.object->empty())
    9369  {
    9370  // flatten empty object as null
    9371  result[reference_string] = nullptr;
    9372  }
    9373  else
    9374  {
    9375  // iterate object and use keys as reference string
    9376  for (const auto& element : *value.m_value.object)
    9377  {
    9378  flatten(reference_string + "/" + escape(element.first),
    9379  element.second, result);
    9380  }
    9381  }
    9382  break;
    9383  }
    9384 
    9385  default:
    9386  {
    9387  // add primitive value with its reference string
    9388  result[reference_string] = value;
    9389  break;
    9390  }
    9391  }
    9392  }
    9393 
    9399  static basic_json unflatten(const basic_json& value)
    9400  {
    9401  if (not value.is_object())
    9402  {
    9403  throw std::domain_error("only objects can be unflattened");
    9404  }
    9405 
    9406  basic_json result;
    9407 
    9408  // iterate the JSON object values
    9409  for (const auto& element : *value.m_value.object)
    9410  {
    9411  if (not element.second.is_primitive())
    9412  {
    9413  throw std::domain_error("values in object must be primitive");
    9414  }
    9415 
    9416  // assign value to reference pointed to by JSON pointer;
    9417  // Note that if the JSON pointer is "" (i.e., points to the
    9418  // whole value), function get_and_create returns a reference
    9419  // to result itself. An assignment will then create a
    9420  // primitive value.
    9421  json_pointer(element.first).get_and_create(result) = element.second;
    9422  }
    9423 
    9424  return result;
    9425  }
    9426 
    9427  private:
    9429  std::vector<std::string> reference_tokens {};
    9430  };
    9431 
    9433  // JSON Pointer support //
    9435 
    9438 
    9472  reference operator[](const json_pointer& ptr)
    9473  {
    9474  return ptr.get_unchecked(this);
    9475  }
    9499  const_reference operator[](const json_pointer& ptr) const
    9500  {
    9501  return ptr.get_unchecked(this);
    9502  }
    9524  reference at(const json_pointer& ptr)
    9525  {
    9526  return ptr.get_checked(this);
    9527  }
    9549  const_reference at(const json_pointer& ptr) const
    9550  {
    9551  return ptr.get_checked(this);
    9552  }
    9576  basic_json flatten() const
    9577  {
    9578  basic_json result(value_t::object);
    9579  json_pointer::flatten("", *this, result);
    9580  return result;
    9581  }
    9582 
    9610  basic_json unflatten() const
    9611  {
    9612  return json_pointer::unflatten(*this);
    9613  }
    9616 
    9618  // JSON Patch functions //
    9620 
    9623 
    9660  basic_json patch(const basic_json& patch) const
    9661  {
    9662  // make a working copy to apply the patch to
    9663  basic_json result = *this;
    9665  // the valid JSON Patch operations
    9666  enum class patch_operations {add, remove, replace, move, copy, test, invalid};
    9667 
    9668  const auto get_op = [](const std::string op)
    9669  {
    9670  if (op == "add")
    9671  {
    9672  return patch_operations::add;
    9673  }
    9674  if (op == "remove")
    9675  {
    9676  return patch_operations::remove;
    9677  }
    9678  if (op == "replace")
    9679  {
    9680  return patch_operations::replace;
    9681  }
    9682  if (op == "move")
    9683  {
    9684  return patch_operations::move;
    9685  }
    9686  if (op == "copy")
    9687  {
    9688  return patch_operations::copy;
    9689  }
    9690  if (op == "test")
    9691  {
    9692  return patch_operations::test;
    9693  }
    9694 
    9695  return patch_operations::invalid;
    9696  };
    9697 
    9698  // wrapper for "add" operation; add value at ptr
    9699  const auto operation_add = [&result](json_pointer & ptr, basic_json val)
    9700  {
    9701  // adding to the root of the target document means replacing it
    9702  if (ptr.is_root())
    9703  {
    9704  result = val;
    9705  }
    9706  else
    9707  {
    9708  // make sure the top element of the pointer exists
    9709  json_pointer top_pointer = ptr.top();
    9710  if (top_pointer != ptr)
    9711  {
    9712  basic_json& x = result.at(top_pointer);
    9713  }
    9714 
    9715  // get reference to parent of JSON pointer ptr
    9716  const auto last_path = ptr.pop_back();
    9717  basic_json& parent = result[ptr];
    9718 
    9719  switch (parent.m_type)
    9720  {
    9721  case value_t::null:
    9722  case value_t::object:
    9723  {
    9724  // use operator[] to add value
    9725  parent[last_path] = val;
    9726  break;
    9727  }
    9728 
    9729  case value_t::array:
    9730  {
    9731  if (last_path == "-")
    9732  {
    9733  // special case: append to back
    9734  parent.push_back(val);
    9735  }
    9736  else
    9737  {
    9738  const auto idx = std::stoi(last_path);
    9739  if (static_cast<size_type>(idx) > parent.size())
    9740  {
    9741  // avoid undefined behavior
    9742  throw std::out_of_range("array index " + std::to_string(idx) + " is out of range");
    9743  }
    9744  else
    9745  {
    9746  // default case: insert add offset
    9747  parent.insert(parent.begin() + static_cast<difference_type>(idx), val);
    9748  }
    9749  }
    9750  break;
    9751  }
    9752 
    9753  default:
    9754  {
    9755  // if there exists a parent it cannot be primitive
    9756  assert(false); // LCOV_EXCL_LINE
    9757  }
    9758  }
    9759  }
    9760  };
    9761 
    9762  // wrapper for "remove" operation; remove value at ptr
    9763  const auto operation_remove = [&result](json_pointer & ptr)
    9764  {
    9765  // get reference to parent of JSON pointer ptr
    9766  const auto last_path = ptr.pop_back();
    9767  basic_json& parent = result.at(ptr);
    9768 
    9769  // remove child
    9770  if (parent.is_object())
    9771  {
    9772  // perform range check
    9773  auto it = parent.find(last_path);
    9774  if (it != parent.end())
    9775  {
    9776  parent.erase(it);
    9777  }
    9778  else
    9779  {
    9780  throw std::out_of_range("key '" + last_path + "' not found");
    9781  }
    9782  }
    9783  else if (parent.is_array())
    9784  {
    9785  // note erase performs range check
    9786  parent.erase(static_cast<size_type>(std::stoi(last_path)));
    9787  }
    9788  };
    9789 
    9790  // type check
    9791  if (not patch.is_array())
    9792  {
    9793  // a JSON patch must be an array of objects
    9794  throw std::invalid_argument("JSON patch must be an array of objects");
    9795  }
    9796 
    9797  // iterate and apply th eoperations
    9798  for (const auto& val : patch)
    9799  {
    9800  // wrapper to get a value for an operation
    9801  const auto get_value = [&val](const std::string & op,
    9802  const std::string & member,
    9803  bool string_type) -> basic_json&
    9804  {
    9805  // find value
    9806  auto it = val.m_value.object->find(member);
    9807 
    9808  // context-sensitive error message
    9809  const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'";
    9810 
    9811  // check if desired value is present
    9812  if (it == val.m_value.object->end())
    9813  {
    9814  throw std::invalid_argument(error_msg + " must have member '" + member + "'");
    9815  }
    9816 
    9817  // check if result is of type string
    9818  if (string_type and not it->second.is_string())
    9819  {
    9820  throw std::invalid_argument(error_msg + " must have string member '" + member + "'");
    9821  }
    9822 
    9823  // no error: return value
    9824  return it->second;
    9825  };
    9826 
    9827  // type check
    9828  if (not val.is_object())
    9829  {
    9830  throw std::invalid_argument("JSON patch must be an array of objects");
    9831  }
    9832 
    9833  // collect mandatory members
    9834  const std::string op = get_value("op", "op", true);
    9835  const std::string path = get_value(op, "path", true);
    9836  json_pointer ptr(path);
    9837 
    9838  switch (get_op(op))
    9839  {
    9840  case patch_operations::add:
    9841  {
    9842  operation_add(ptr, get_value("add", "value", false));
    9843  break;
    9844  }
    9845 
    9846  case patch_operations::remove:
    9847  {
    9848  operation_remove(ptr);
    9849  break;
    9850  }
    9851 
    9852  case patch_operations::replace:
    9853  {
    9854  // the "path" location must exist - use at()
    9855  result.at(ptr) = get_value("replace", "value", false);
    9856  break;
    9857  }
    9858 
    9859  case patch_operations::move:
    9860  {
    9861  const std::string from_path = get_value("move", "from", true);
    9862  json_pointer from_ptr(from_path);
    9863 
    9864  // the "from" location must exist - use at()
    9865  basic_json v = result.at(from_ptr);
    9866 
    9867  // The move operation is functionally identical to a
    9868  // "remove" operation on the "from" location, followed
    9869  // immediately by an "add" operation at the target
    9870  // location with the value that was just removed.
    9871  operation_remove(from_ptr);
    9872  operation_add(ptr, v);
    9873  break;
    9874  }
    9875 
    9876  case patch_operations::copy:
    9877  {
    9878  const std::string from_path = get_value("copy", "from", true);;
    9879  const json_pointer from_ptr(from_path);
    9880 
    9881  // the "from" location must exist - use at()
    9882  result[ptr] = result.at(from_ptr);
    9883  break;
    9884  }
    9885 
    9886  case patch_operations::test:
    9887  {
    9888  bool success = false;
    9889  try
    9890  {
    9891  // check if "value" matches the one at "path"
    9892  // the "path" location must exist - use at()
    9893  success = (result.at(ptr) == get_value("test", "value", false));
    9894  }
    9895  catch (std::out_of_range&)
    9896  {
    9897  // ignore out of range errors: success remains false
    9898  }
    9899 
    9900  // throw an exception if test fails
    9901  if (not success)
    9902  {
    9903  throw std::domain_error("unsuccessful: " + val.dump());
    9904  }
    9905 
    9906  break;
    9907  }
    9908 
    9909  case patch_operations::invalid:
    9910  {
    9911  // op must be "add", "remove", "replace", "move", "copy", or
    9912  // "test"
    9913  throw std::invalid_argument("operation value '" + op + "' is invalid");
    9914  }
    9915  }
    9916  }
    9917 
    9918  return result;
    9919  }
    9920 
    9953  static basic_json diff(const basic_json& source,
    9954  const basic_json& target,
    9955  std::string path = "") noexcept
    9956  {
    9957  // the patch
    9958  basic_json result(value_t::array);
    9959 
    9960  // if the values are the same, return empty patch
    9961  if (source == target)
    9962  {
    9963  return result;
    9964  }
    9965 
    9966  if (source.type() != target.type())
    9967  {
    9968  // different types: replace value
    9969  result.push_back(
    9970  {
    9971  {"op", "replace"},
    9972  {"path", path},
    9973  {"value", target}
    9974  });
    9975  }
    9976  else
    9977  {
    9978  switch (source.type())
    9979  {
    9980  case value_t::array:
    9981  {
    9982  // first pass: traverse common elements
    9983  size_t i = 0;
    9984  while (i < source.size() and i < target.size())
    9985  {
    9986  // recursive call to compare array values at index i
    9987  auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i));
    9988  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    9989  ++i;
    9990  }
    9991 
    9992  // i now reached the end of at least one array
    9993  // in a second pass, traverse the remaining elements
    9994 
    9995  // remove my remaining elements
    9996  while (i < source.size())
    9997  {
    9998  result.push_back(object(
    9999  {
    10000  {"op", "remove"},
    10001  {"path", path + "/" + std::to_string(i)}
    10002  }));
    10003  ++i;
    10004  }
    10005 
    10006  // add other remaining elements
    10007  while (i < target.size())
    10008  {
    10009  result.push_back(
    10010  {
    10011  {"op", "add"},
    10012  {"path", path + "/" + std::to_string(i)},
    10013  {"value", target[i]}
    10014  });
    10015  ++i;
    10016  }
    10017 
    10018  break;
    10019  }
    10020 
    10021  case value_t::object:
    10022  {
    10023  // first pass: traverse this object's elements
    10024  for (auto it = source.begin(); it != source.end(); ++it)
    10025  {
    10026  // escape the key name to be used in a JSON patch
    10027  const auto key = json_pointer::escape(it.key());
    10028 
    10029  if (target.find(it.key()) != target.end())
    10030  {
    10031  // recursive call to compare object values at key it
    10032  auto temp_diff = diff(it.value(), target[it.key()], path + "/" + key);
    10033  result.insert(result.end(), temp_diff.begin(), temp_diff.end());
    10034  }
    10035  else
    10036  {
    10037  // found a key that is not in o -> remove it
    10038  result.push_back(object(
    10039  {
    10040  {"op", "remove"},
    10041  {"path", path + "/" + key}
    10042  }));
    10043  }
    10044  }
    10045 
    10046  // second pass: traverse other object's elements
    10047  for (auto it = target.begin(); it != target.end(); ++it)
    10048  {
    10049  if (source.find(it.key()) == source.end())
    10050  {
    10051  // found a key that is not in this -> add it
    10052  const auto key = json_pointer::escape(it.key());
    10053  result.push_back(
    10054  {
    10055  {"op", "add"},
    10056  {"path", path + "/" + key},
    10057  {"value", it.value()}
    10058  });
    10059  }
    10060  }
    10061 
    10062  break;
    10063  }
    10064 
    10065  default:
    10066  {
    10067  // both primitive type: replace value
    10068  result.push_back(
    10069  {
    10070  {"op", "replace"},
    10071  {"path", path},
    10072  {"value", target}
    10073  });
    10074  break;
    10075  }
    10076  }
    10077  }
    10078 
    10079  return result;
    10080  }
    10081 
    10083 };
    10084 
    10085 
    10087 // presets //
    10089 
    10098 using json = basic_json<>;
    10099 }
    10100 
    10101 
    10103 // nonmember support //
    10105 
    10106 // specialization of std::swap, and std::hash
    10107 namespace std
    10108 {
    10114 template <>
    10115 inline void swap(nlohmann::json& j1,
    10116  nlohmann::json& j2) noexcept(
    10117  is_nothrow_move_constructible<nlohmann::json>::value and
    10118  is_nothrow_move_assignable<nlohmann::json>::value
    10119  )
    10120 {
    10121  j1.swap(j2);
    10122 }
    10123 
    10125 template <>
    10126 struct hash<nlohmann::json>
    10127 {
    10133  std::size_t operator()(const nlohmann::json& j) const
    10134  {
    10135  // a naive hashing via the string representation
    10136  const auto& h = hash<nlohmann::json::string_t>();
    10137  return h(j.dump());
    10138  }
    10139 };
    10140 }
    10141 
    10154 inline nlohmann::json operator "" _json(const char* s, std::size_t)
    10155 {
    10156  return nlohmann::json::parse(reinterpret_cast<const nlohmann::json::string_t::value_type*>(s));
    10157 }
    10158 
    10164 inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t)
    10165 {
    10166  return nlohmann::json::json_pointer(s);
    10167 }
    10168 
    10169 // restore GCC/clang diagnostic settings
    10170 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
    10171  #pragma GCC diagnostic pop
    10172 #endif
    10173 
    10174 #endif
    const_iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6495
    +
    friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
    comparison: less than or equal
    Definition: json.hpp:5630
    basic_json(const value_t value_type)
    create an empty value with a given type
    Definition: json.hpp:1032
    basic_json(const array_t &val)
    create an array (explicit)
    Definition: json.hpp:1169
    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:4142
    const_reference operator[](size_type idx) const
    access specified array element
    Definition: json.hpp:3334
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:7087
    -
    json_reverse_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:7149
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:7135
    +
    json_reverse_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:7197
    void clear() noexcept
    clears the contents
    Definition: json.hpp:4692
    -
    bool operator==(const const_iterator &other) const
    comparison: equal
    Definition: json.hpp:6737
    -
    json_reverse_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:7143
    +
    bool operator==(const const_iterator &other) const
    comparison: equal
    Definition: json.hpp:6785
    +
    json_reverse_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:7191
    reference operator[](T *(&key)[n])
    access specified object element
    Definition: json.hpp:3466
    -
    friend std::istream & operator>>(std::istream &i, basic_json &j)
    deserialize from stream
    Definition: json.hpp:5795
    +
    friend std::istream & operator>>(std::istream &i, basic_json &j)
    deserialize from stream
    Definition: json.hpp:5843
    constexpr bool is_number_float() const noexcept
    return whether value is a floating-point number
    Definition: json.hpp:2411
    const_reverse_iterator rend() const noexcept
    returns a const reverse iterator to one before the first
    Definition: json.hpp:4369
    -
    iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:7045
    +
    iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:7093
    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:1749
    -
    const_iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6863
    +
    const_iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:6911
    BooleanType boolean_t
    a type for a boolean
    Definition: json.hpp:466
    const_iterator cbegin() const noexcept
    returns a const iterator to the first element
    Definition: json.hpp:4223
    reference operator+=(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4878
    -
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:7003
    +
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:7051
    basic_json(const typename string_t::value_type *val)
    create a string (explicit)
    Definition: json.hpp:1262
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:7185
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:7233
    iterator find(typename object_t::key_type key)
    find an element in a JSON object
    Definition: json.hpp:4094
    -
    friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    comparison: not equal
    Definition: json.hpp:5420
    +
    friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
    comparison: not equal
    Definition: json.hpp:5468
    basic_json(const string_t &val)
    create a string (explicit)
    Definition: json.hpp:1238
    void push_back(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4804
    void erase(const size_type idx)
    remove element from a JSON array given an index
    Definition: json.hpp:4048
    ArrayType< basic_json, AllocatorType< basic_json >> array_t
    a type for an array
    Definition: json.hpp:393
    reference front()
    access the first element
    Definition: json.hpp:3705
    -
    void swap(object_t &other)
    exchanges the values
    Definition: json.hpp:5176
    -
    json_reverse_iterator operator-(difference_type i) const
    subtract from iterator
    Definition: json.hpp:7171
    -
    const_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6821
    +
    void swap(object_t &other)
    exchanges the values
    Definition: json.hpp:5224
    +
    json_reverse_iterator operator-(difference_type i) const
    subtract from iterator
    Definition: json.hpp:7219
    +
    const_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:6869
    a class to store JSON values
    Definition: json.hpp:187
    basic_json(const int val) noexcept
    create an integer number from an enum type (explicit)
    Definition: json.hpp:1373
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:7198
    -
    friend bool operator==(std::nullptr_t, const_reference v) noexcept
    comparison: equal
    Definition: json.hpp:5399
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:7246
    +
    friend bool operator==(std::nullptr_t, const_reference v) noexcept
    comparison: equal
    Definition: json.hpp:5447
    NumberIntegerType number_integer_t
    a type for a number (integer)
    Definition: json.hpp:537
    -
    iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
    inserts elements
    Definition: json.hpp:4962
    +
    iterator insert(const_iterator pos, size_type cnt, const basic_json &val)
    inserts elements
    Definition: json.hpp:5010
    const_reference at(const typename object_t::key_type &key) const
    access specified object element with bounds checking
    Definition: json.hpp:3241
    -
    const_iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6855
    +
    const_iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:6903
    constexpr bool is_object() const noexcept
    return whether value is an object
    Definition: json.hpp:2433
    constexpr bool is_number_integer() const noexcept
    return whether value is an integer number
    Definition: json.hpp:2355
    -
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:6970
    -
    static basic_json parse(std::istream &&i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5757
    -
    const_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6663
    +
    a mutable random access iterator for the basic_json class
    Definition: json.hpp:7018
    +
    static basic_json parse(std::istream &&i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5805
    +
    const_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:6711
    const_iterator cend() const noexcept
    returns a const iterator to one past the last element
    Definition: json.hpp:4294
    ObjectType< StringType, basic_json, std::less< StringType >, AllocatorType< std::pair< const StringType, basic_json >>> object_t
    a type for an object
    Definition: json.hpp:347
    STL namespace.
    @@ -140,157 +140,159 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    static iteration_proxy< const_iterator > iterator_wrapper(const_reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:4456
    reference & operator=(basic_json other) noexcept( std::is_nothrow_move_constructible< value_t >::value and std::is_nothrow_move_assignable< value_t >::value and std::is_nothrow_move_constructible< json_value >::value and std::is_nothrow_move_assignable< json_value >::value )
    copy assignment
    Definition: json.hpp:2064
    constexpr value_t type() const noexcept
    return the type of the JSON value (explicit)
    Definition: json.hpp:2195
    -
    typename basic_json::value_type value_type
    the type of the values when the iterator is dereferenced
    Definition: json.hpp:6433
    -
    json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
    create reverse iterator from iterator
    Definition: json.hpp:7120
    +
    typename basic_json::value_type value_type
    the type of the values when the iterator is dereferenced
    Definition: json.hpp:6481
    +
    json_reverse_iterator(const typename base_iterator::iterator_type &it) noexcept
    create reverse iterator from iterator
    Definition: json.hpp:7168
    PointerType get_ptr() noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2955
    constexpr bool is_string() const noexcept
    return whether value is a string
    Definition: json.hpp:2477
    reference back()
    access the last element
    Definition: json.hpp:3747
    const value_type & const_reference
    the type of an element const reference
    Definition: json.hpp:218
    -
    typename basic_json::const_pointer pointer
    defines a pointer to the type iterated over (value_type)
    Definition: json.hpp:6437
    +
    typename basic_json::const_pointer pointer
    defines a pointer to the type iterated over (value_type)
    Definition: json.hpp:6485
    void push_back(const typename object_t::value_type &val)
    add an object to an object
    Definition: json.hpp:4854
    -
    json_pointer(const std::string &s="")
    create JSON pointer
    Definition: json.hpp:8857
    -
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5720
    +
    void push_back(std::initializer_list< basic_json > init)
    add an object to an object
    Definition: json.hpp:4909
    +
    json_pointer(const std::string &s="")
    create JSON pointer
    Definition: json.hpp:8901
    +
    static basic_json parse(const string_t &s, parser_callback_t cb=nullptr)
    deserialize from string
    Definition: json.hpp:5768
    const_reference operator[](T *(&key)[n]) const
    read-only access specified object element
    Definition: json.hpp:3501
    -
    iterator insert(const_iterator pos, const_iterator first, const_iterator last)
    inserts elements
    Definition: json.hpp:5015
    +
    iterator insert(const_iterator pos, const_iterator first, const_iterator last)
    inserts elements
    Definition: json.hpp:5063
    basic_json(std::nullptr_t) noexcept
    create a null object (explicitly)
    Definition: json.hpp:1084
    basic_json(InputIT first, InputIT last)
    construct a JSON container given an iterator range
    Definition: json.hpp:1819
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:7081
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:7129
    static allocator_type get_allocator()
    returns the allocator associated with the container
    Definition: json.hpp:248
    const_reference operator[](const typename object_t::key_type &key) const
    read-only access specified object element
    Definition: json.hpp:3423
    const_reference operator[](T *key) const
    read-only access specified object element
    Definition: json.hpp:3583
    -
    json_reverse_iterator operator+(difference_type i) const
    add to iterator
    Definition: json.hpp:7163
    +
    json_reverse_iterator operator+(difference_type i) const
    add to iterator
    Definition: json.hpp:7211
    bool empty() const noexcept
    checks whether the container is empty
    Definition: json.hpp:4504
    std::size_t size_type
    a type to represent container sizes
    Definition: json.hpp:223
    -
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:7191
    -
    const_iterator(const iterator &other) noexcept
    copy constructor given a nonconst iterator
    Definition: json.hpp:6475
    +
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:7239
    +
    const_iterator(const iterator &other) noexcept
    copy constructor given a nonconst iterator
    Definition: json.hpp:6523
    basic_json(const CompatibleArrayType &val)
    create an array (implicit)
    Definition: json.hpp:1209
    constexpr bool is_boolean() const noexcept
    return whether value is a boolean
    Definition: json.hpp:2296
    const_reference at(size_type idx) const
    access specified array element with bounds checking
    Definition: json.hpp:3145
    basic_json(size_type cnt, const basic_json &val)
    construct an array with count copies of given value
    Definition: json.hpp:1773
    -
    std::reverse_iterator< Base > base_iterator
    shortcut to the reverse iterator adaptor
    Definition: json.hpp:7115
    +
    std::reverse_iterator< Base > base_iterator
    shortcut to the reverse iterator adaptor
    Definition: json.hpp:7163
    const_reverse_iterator crbegin() const noexcept
    returns a const reverse iterator to the last element
    Definition: json.hpp:4398
    -
    iterator insert(const_iterator pos, std::initializer_list< basic_json > ilist)
    inserts elements
    Definition: json.hpp:5073
    +
    iterator insert(const_iterator pos, std::initializer_list< basic_json > ilist)
    inserts elements
    Definition: json.hpp:5121
    typename std::allocator_traits< allocator_type >::pointer pointer
    the type of an element pointer
    Definition: json.hpp:229
    -
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4906
    -
    friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than or equal
    Definition: json.hpp:5626
    -
    friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    comparison: less than
    Definition: json.hpp:5481
    -
    iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:7023
    -
    bool operator<(const const_iterator &other) const
    comparison: smaller
    Definition: json.hpp:6773
    -
    iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:7015
    +
    iterator insert(const_iterator pos, const basic_json &val)
    inserts element
    Definition: json.hpp:4954
    +
    friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than or equal
    Definition: json.hpp:5674
    +
    friend bool operator<(const_reference lhs, const_reference rhs) noexcept
    comparison: less than
    Definition: json.hpp:5529
    +
    iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:7071
    +
    bool operator<(const const_iterator &other) const
    comparison: smaller
    Definition: json.hpp:6821
    +
    iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:7063
    basic_json(basic_json &&other) noexcept
    move constructor
    Definition: json.hpp:2032
    -
    const_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6700
    +
    const_iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:6748
    reference at(const typename object_t::key_type &key)
    access specified object element with bounds checking
    Definition: json.hpp:3193
    -
    iterator & operator=(iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:6991
    +
    iterator & operator=(iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:7039
    object (unordered set of name/value pairs)
    size_type max_size() const noexcept
    returns the maximum possible number of elements
    Definition: json.hpp:4633
    ~basic_json()
    destructor
    Definition: json.hpp:2092
    -
    iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:7030
    -
    iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:7067
    -
    const_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6708
    +
    iterator operator--(int)
    post-decrement (it–)
    Definition: json.hpp:7078
    +
    iterator operator-(difference_type i)
    subtract from iterator
    Definition: json.hpp:7115
    +
    const_iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:6756
    string_t dump(const int indent=-1) const
    serialization
    Definition: json.hpp:2161
    basic_json value_type
    the type of elements in a basic_json container
    Definition: json.hpp:213
    std::function< bool(int depth, parse_event_t event, basic_json &parsed)> parser_callback_t
    per-element parser callback type
    Definition: json.hpp:983
    AllocatorType< basic_json > allocator_type
    the allocator type
    Definition: json.hpp:226
    StringType string_t
    a type for a string
    Definition: json.hpp:440
    reference operator+=(const basic_json &val)
    add an object to an array
    Definition: json.hpp:4828
    -
    difference_type operator-(const const_iterator &other) const
    return difference
    Definition: json.hpp:6871
    +
    reference operator+=(std::initializer_list< basic_json > init)
    add an object to an object
    Definition: json.hpp:4926
    +
    difference_type operator-(const const_iterator &other) const
    return difference
    Definition: json.hpp:6919
    value_type & reference
    the type of an element reference
    Definition: json.hpp:216
    const_reverse_iterator rbegin() const noexcept
    returns a const reverse iterator to the last element
    Definition: json.hpp:4332
    -
    friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
    serialize to stream
    Definition: json.hpp:5681
    +
    friend std::ostream & operator>>(const basic_json &j, std::ostream &o)
    serialize to stream
    Definition: json.hpp:5729
    constexpr bool is_discarded() const noexcept
    return whether value is discarded
    Definition: json.hpp:2504
    const_iterator begin() const noexcept
    returns a const iterator to the first element
    Definition: json.hpp:4193
    -
    difference_type operator-(const iterator &other) const
    return difference
    Definition: json.hpp:7075
    +
    difference_type operator-(const iterator &other) const
    return difference
    Definition: json.hpp:7123
    constexpr bool is_array() const noexcept
    return whether value is an array
    Definition: json.hpp:2455
    -
    iterator(const iterator &other) noexcept
    copy constructor
    Definition: json.hpp:6986
    +
    iterator(const iterator &other) noexcept
    copy constructor
    Definition: json.hpp:7034
    namespace for Niels Lohmann
    Definition: json.hpp:67
    -
    typename basic_json::difference_type difference_type
    a type to represent differences between iterators
    Definition: json.hpp:6435
    -
    void swap(string_t &other)
    exchanges the values
    Definition: json.hpp:5210
    +
    typename basic_json::difference_type difference_type
    a type to represent differences between iterators
    Definition: json.hpp:6483
    +
    void swap(string_t &other)
    exchanges the values
    Definition: json.hpp:5258
    basic_json(const CompatibleNumberIntegerType val) noexcept
    create an integer number (implicit)
    Definition: json.hpp:1410
    const_reference front() const
    access the first element
    Definition: json.hpp:3713
    -
    bool operator>(const const_iterator &other) const
    comparison: greater than
    Definition: json.hpp:6809
    +
    bool operator>(const const_iterator &other) const
    comparison: greater than
    Definition: json.hpp:6857
    constexpr const PointerType get_ptr() const noexcept
    get a pointer value (implicit)
    Definition: json.hpp:2970
    -
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:6628
    - +
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:6676
    +
    NumberFloatType number_float_t
    a type for a number (floating-point)
    Definition: json.hpp:677
    const_reverse_iterator crend() const noexcept
    returns a const reverse iterator to one before the first
    Definition: json.hpp:4427
    -
    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:5111
    +
    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:5159
    value_t
    the JSON type enumeration
    Definition: json.hpp:696
    reverse_iterator rbegin() noexcept
    returns an iterator to the reverse-beginning
    Definition: json.hpp:4324
    constexpr bool is_null() const noexcept
    return whether value is null
    Definition: json.hpp:2274
    std::ptrdiff_t difference_type
    a type to represent differences between iterators
    Definition: json.hpp:221
    ValueType get() const
    get a value (explicit)
    Definition: json.hpp:2871
    -
    void swap(array_t &other)
    exchanges the values
    Definition: json.hpp:5142
    +
    void swap(array_t &other)
    exchanges the values
    Definition: json.hpp:5190
    InteratorType erase(InteratorType first, InteratorType last)
    remove elements given an iterator range
    Definition: json.hpp:3923
    ValueType value(const typename object_t::key_type &key, ValueType default_value) const
    access specified object element with default value
    Definition: json.hpp:3650
    -
    typename Base::reference reference
    the reference type for the pointed-to element
    Definition: json.hpp:7117
    +
    typename Base::reference reference
    the reference type for the pointed-to element
    Definition: json.hpp:7165
    const_reference back() const
    access the last element
    Definition: json.hpp:3757
    void push_back(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4768
    array (ordered collection of values)
    constexpr bool is_number_unsigned() const noexcept
    return whether value is an unsigned integer number
    Definition: json.hpp:2383
    -
    json_reverse_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:7136
    -
    static basic_json parse(std::istream &i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5749
    -
    friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    comparison: equal
    Definition: json.hpp:5291
    +
    json_reverse_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:7184
    +
    static basic_json parse(std::istream &i, parser_callback_t cb=nullptr)
    deserialize from stream
    Definition: json.hpp:5797
    +
    friend bool operator==(const_reference lhs, const_reference rhs) noexcept
    comparison: equal
    Definition: json.hpp:5339
    string_t value(const typename object_t::key_type &key, const char *default_value) const
    overload for a default value of type const char*
    Definition: json.hpp:3676
    ReferenceType get_ref() const
    get a reference value (implicit)
    Definition: json.hpp:3021
    basic_json(const CompatibleNumberUnsignedType val) noexcept
    create an unsigned number (implicit)
    Definition: json.hpp:1469
    -
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:6588
    +
    reference operator*() const
    return a reference to the value pointed to by the iterator
    Definition: json.hpp:6636
    -
    friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    comparison operator for JSON types
    Definition: json.hpp:5244
    +
    friend bool operator<(const value_t lhs, const value_t rhs) noexcept
    comparison operator for JSON types
    Definition: json.hpp:5292
    basic_json(const number_float_t val) noexcept
    create a floating-point number (explicit)
    Definition: json.hpp:1498
    -
    friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    comparison: not equal
    Definition: json.hpp:5443
    -
    iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:7059
    +
    friend bool operator!=(const_reference v, std::nullptr_t) noexcept
    comparison: not equal
    Definition: json.hpp:5491
    +
    iterator operator+(difference_type i)
    add to iterator
    Definition: json.hpp:7107
    basic_json(const CompatibleNumberFloatType val) noexcept
    create an floating-point number (implicit)
    Definition: json.hpp:1544
    -
    bool operator<=(const const_iterator &other) const
    comparison: less than or equal
    Definition: json.hpp:6803
    +
    bool operator<=(const const_iterator &other) const
    comparison: less than or equal
    Definition: json.hpp:6851
    InteratorType erase(InteratorType pos)
    remove element given an iterator
    Definition: json.hpp:3815
    basic_json(std::initializer_list< basic_json > init, bool type_deduction=true, value_t manual_type=value_t::array)
    create a container (array or object) from an initializer list
    Definition: json.hpp:1617
    -
    iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:6981
    -
    friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    comparison: not equal
    Definition: json.hpp:5452
    +
    iterator(pointer object) noexcept
    constructor for a given JSON instance
    Definition: json.hpp:7029
    +
    friend bool operator!=(std::nullptr_t, const_reference v) noexcept
    comparison: not equal
    Definition: json.hpp:5500
    constexpr bool is_primitive() const noexcept
    return whether type is primitive
    Definition: json.hpp:2225
    -
    const_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6671
    -
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:7009
    -
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6946
    +
    const_iterator & operator++()
    pre-increment (++it)
    Definition: json.hpp:6719
    +
    pointer operator->() const
    dereference the iterator
    Definition: json.hpp:7057
    +
    reference value() const
    return the value of an iterator
    Definition: json.hpp:6994
    constexpr bool is_structured() const noexcept
    return whether type is structured
    Definition: json.hpp:2252
    -
    std::bidirectional_iterator_tag iterator_category
    the category of the iterator
    Definition: json.hpp:6441
    +
    std::bidirectional_iterator_tag iterator_category
    the category of the iterator
    Definition: json.hpp:6489
    basic_json(boolean_t val) noexcept
    create a boolean (explicit)
    Definition: json.hpp:1311
    iterator end() noexcept
    returns an iterator to one past the last element
    Definition: json.hpp:4254
    reverse_iterator rend() noexcept
    returns an iterator to the reverse-end
    Definition: json.hpp:4361
    -
    difference_type operator-(const json_reverse_iterator &other) const
    return difference
    Definition: json.hpp:7179
    +
    difference_type operator-(const json_reverse_iterator &other) const
    return difference
    Definition: json.hpp:7227
    const_iterator find(typename object_t::key_type key) const
    find an element in a JSON object
    Definition: json.hpp:4111
    iterator begin() noexcept
    returns an iterator to the first element
    Definition: json.hpp:4183
    basic_json(const CompatibleObjectType &val)
    create an object (implicit)
    Definition: json.hpp:1142
    const_iterator end() const noexcept
    returns a const iterator to one past the last element
    Definition: json.hpp:4264
    -
    friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than
    Definition: json.hpp:5604
    -
    bool operator>=(const const_iterator &other) const
    comparison: greater than or equal
    Definition: json.hpp:6815
    -
    const_iterator & operator=(const_iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:6508
    +
    friend bool operator>(const_reference lhs, const_reference rhs) noexcept
    comparison: greater than
    Definition: json.hpp:5652
    +
    bool operator>=(const const_iterator &other) const
    comparison: greater than or equal
    Definition: json.hpp:6863
    +
    const_iterator & operator=(const_iterator other) noexcept( std::is_nothrow_move_constructible< pointer >::value and std::is_nothrow_move_assignable< pointer >::value and std::is_nothrow_move_constructible< internal_iterator >::value and std::is_nothrow_move_assignable< internal_iterator >::value )
    copy assignment
    Definition: json.hpp:6556
    size_type erase(const typename object_t::key_type &key)
    remove element from a JSON object given a key
    Definition: json.hpp:4010
    reference operator[](const typename object_t::key_type &key)
    access specified object element
    Definition: json.hpp:3375
    -
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6931
    +
    object_t::key_type key() const
    return the key of an object iterator
    Definition: json.hpp:6979
    reference operator+=(basic_json &&val)
    add an object to an array
    Definition: json.hpp:4794
    -
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6895
    -
    a const random access iterator for the basic_json class
    Definition: json.hpp:6426
    +
    reference operator[](difference_type n) const
    access to successor
    Definition: json.hpp:6943
    +
    a const random access iterator for the basic_json class
    Definition: json.hpp:6474
    constexpr bool is_number() const noexcept
    return whether value is a number
    Definition: json.hpp:2326
    a template for a reverse iterator class
    Definition: json.hpp:202
    basic_json(std::istream &i, parser_callback_t cb=nullptr)
    construct a JSON value given an input stream
    Definition: json.hpp:1926
    -
    typename basic_json::const_reference reference
    defines a reference to the type iterated over (value_type)
    Definition: json.hpp:6439
    -
    json_reverse_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:7130
    -
    friend bool operator==(const_reference v, std::nullptr_t) noexcept
    comparison: equal
    Definition: json.hpp:5390
    +
    typename basic_json::const_reference reference
    defines a reference to the type iterated over (value_type)
    Definition: json.hpp:6487
    +
    json_reverse_iterator operator++(int)
    post-increment (it++)
    Definition: json.hpp:7178
    +
    friend bool operator==(const_reference v, std::nullptr_t) noexcept
    comparison: equal
    Definition: json.hpp:5438
    reference operator[](size_type idx)
    access specified array element
    Definition: json.hpp:3288
    -
    bool operator!=(const const_iterator &other) const
    comparison: not equal
    Definition: json.hpp:6767
    -
    json_reverse_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:7156
    +
    bool operator!=(const const_iterator &other) const
    comparison: not equal
    Definition: json.hpp:6815
    +
    json_reverse_iterator & operator+=(difference_type i)
    add to iterator
    Definition: json.hpp:7204
    reference at(size_type idx)
    access specified array element with bounds checking
    Definition: json.hpp:3101
    size_type size() const noexcept
    returns the number of elements
    Definition: json.hpp:4567
    static iteration_proxy< iterator > iterator_wrapper(reference cont)
    wrapper to access iterator member functions in range-based for
    Definition: json.hpp:4448
    -
    iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:7052
    +
    iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:7100
    basic_json(const object_t &val)
    create an object (explicit)
    Definition: json.hpp:1107
    basic_json(const number_unsigned_t val) noexcept
    create an unsigned integer number (explicit)
    Definition: json.hpp:1438
    -
    friend std::istream & operator<<(basic_json &j, std::istream &i)
    deserialize from stream
    Definition: json.hpp:5785
    -
    json_reverse_iterator(const base_iterator &it) noexcept
    create reverse iterator from base class
    Definition: json.hpp:7125
    -
    friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
    serialize to stream
    Definition: json.hpp:5663
    -
    const_iterator(const const_iterator &other) noexcept
    copy constructor
    Definition: json.hpp:6503
    -
    iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:7038
    -
    iterator insert(const_iterator pos, basic_json &&val)
    inserts element
    Definition: json.hpp:4933
    +
    friend std::istream & operator<<(basic_json &j, std::istream &i)
    deserialize from stream
    Definition: json.hpp:5833
    +
    json_reverse_iterator(const base_iterator &it) noexcept
    create reverse iterator from base class
    Definition: json.hpp:7173
    +
    friend std::ostream & operator<<(std::ostream &o, const basic_json &j)
    serialize to stream
    Definition: json.hpp:5711
    +
    const_iterator(const const_iterator &other) noexcept
    copy constructor
    Definition: json.hpp:6551
    +
    iterator & operator--()
    pre-decrement (–it)
    Definition: json.hpp:7086
    +
    iterator insert(const_iterator pos, basic_json &&val)
    inserts element
    Definition: json.hpp:4981
    ReferenceType get_ref()
    get a reference value (implicit)
    Definition: json.hpp:3006
    -
    const_iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6849
    +
    const_iterator & operator-=(difference_type i)
    subtract from iterator
    Definition: json.hpp:6897
    basic_json(const CompatibleStringType &val)
    create a string (implicit)
    Definition: json.hpp:1293
    basic_json(const basic_json &other)
    copy constructor
    Definition: json.hpp:1957
    reference operator[](T *key)
    access specified object element
    Definition: json.hpp:3534
    @@ -298,7 +300,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
    diff --git a/namespacemembers.html b/namespacemembers.html index 3292ae50b..47c745897 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 6bdd8e8ce..2d9b0b6f6 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 347f9f835..24deecde2 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 14fe3a773..6d2c3d22d 100644 --- a/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html +++ b/namespacenlohmann_1_1anonymous__namespace_02json_8hpp_03.html @@ -108,7 +108,7 @@ Classes diff --git a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html index dd245e3fd..bbdbb7718 100644 --- a/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html +++ b/namespacenlohmann_a2bfd99e845a2e5cd90aeaf1b1431f474.html @@ -101,7 +101,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');

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

    Since
    version 1.0.0
    -

    Definition at line 10058 of file json.hpp.

    +

    Definition at line 10102 of file json.hpp.

    @@ -111,7 +111,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); diff --git a/search/all_d.js b/search/all_d.js index 531337de2..aa4d77302 100644 --- a/search/all_d.js +++ b/search/all_d.js @@ -11,7 +11,7 @@ var searchData= ['operator_2a',['operator*',['../classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html#ab3029a1a83cf46dc28ad443bbad0c74d',1,'nlohmann::basic_json::const_iterator::operator*()'],['../classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html#acbd82115f9232c3d3b5dacc78315b9da',1,'nlohmann::basic_json::iterator::operator*()']]], ['operator_2b',['operator+',['../classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html#a7a80257f2303210b0a5d056fc0b30b40',1,'nlohmann::basic_json::const_iterator::operator+()'],['../classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html#a56952f8d5702541f0d88e6a764d2ae36',1,'nlohmann::basic_json::iterator::operator+()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html#a99ee137dab7e5c948457f6a5321b54b1',1,'nlohmann::basic_json::json_reverse_iterator::operator+()']]], ['operator_2b_2b',['operator++',['../classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html#a8dbaec5bf8ccba3225520356629061cb',1,'nlohmann::basic_json::const_iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html#a8fbb15efd97599209a7def77af8e748e',1,'nlohmann::basic_json::const_iterator::operator++()'],['../classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html#a2943e49b3d88e6ee5793c5923ab2ede9',1,'nlohmann::basic_json::iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html#a050b7fa21051ea57e5b0cc03668b5d4a',1,'nlohmann::basic_json::iterator::operator++()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html#a545a8204cfd6836eb85abc3113a0bb28',1,'nlohmann::basic_json::json_reverse_iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html#a4aede52d6ee253a510897518b59e09c0',1,'nlohmann::basic_json::json_reverse_iterator::operator++()']]], - ['operator_2b_3d',['operator+=',['../classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html#a1c1aa2d148a3e4ce0d4e50cf5b894f41',1,'nlohmann::basic_json::operator+=(basic_json &&val)'],['../classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html#a80c21170db6b5ffd9274b3f351cebadc',1,'nlohmann::basic_json::operator+=(const basic_json &val)'],['../classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html#a9486a272e034c0548305d7a12f3045e6',1,'nlohmann::basic_json::operator+=(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html#a0d5820d1dda9dea3bbeb029cacf68522',1,'nlohmann::basic_json::const_iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html#ae0c848dbc0af1cde15771d45d775b27c',1,'nlohmann::basic_json::iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html#a9accc9dd9f9033f50c0ab6bcf337ffe0',1,'nlohmann::basic_json::json_reverse_iterator::operator+=()']]], + ['operator_2b_3d',['operator+=',['../classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html#a1c1aa2d148a3e4ce0d4e50cf5b894f41',1,'nlohmann::basic_json::operator+=(basic_json &&val)'],['../classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html#a80c21170db6b5ffd9274b3f351cebadc',1,'nlohmann::basic_json::operator+=(const basic_json &val)'],['../classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html#a9486a272e034c0548305d7a12f3045e6',1,'nlohmann::basic_json::operator+=(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html#aa0033766b4d3134b9bb57d81762d75a2',1,'nlohmann::basic_json::operator+=(std::initializer_list< basic_json > init)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html#a0d5820d1dda9dea3bbeb029cacf68522',1,'nlohmann::basic_json::const_iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html#ae0c848dbc0af1cde15771d45d775b27c',1,'nlohmann::basic_json::iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html#a9accc9dd9f9033f50c0ab6bcf337ffe0',1,'nlohmann::basic_json::json_reverse_iterator::operator+=()']]], ['operator_2d',['operator-',['../classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html#abc4552ba2fe39e7901a83dd6d4dec151',1,'nlohmann::basic_json::const_iterator::operator-(difference_type i)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html#a5e4d98a8f95e2eccde8cd48c19efa196',1,'nlohmann::basic_json::const_iterator::operator-(const const_iterator &other) const '],['../classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html#a790f550ff168095c83c2e459c575916c',1,'nlohmann::basic_json::iterator::operator-(difference_type i)'],['../classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html#a9f3940ac5fb2c6ff8045ed59b8a0866f',1,'nlohmann::basic_json::iterator::operator-(const iterator &other) const '],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html#ac2634bee082633671125e909dffad40a',1,'nlohmann::basic_json::json_reverse_iterator::operator-(difference_type i) const '],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html#a115fae3dd8ae02669fedae0545ce1cbc',1,'nlohmann::basic_json::json_reverse_iterator::operator-(const json_reverse_iterator &other) const ']]], ['operator_2d_2d',['operator--',['../classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html#a6cab1c2ed7e2a014980e2a5717f43a64',1,'nlohmann::basic_json::const_iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html#adeb2ff3fdf3cc301b72db109934c9199',1,'nlohmann::basic_json::const_iterator::operator--()'],['../classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html#ab4f238aa5fcf452b1884b748b0395b1f',1,'nlohmann::basic_json::iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html#ab3679dc63b3a59edb98b1c2b96d8683c',1,'nlohmann::basic_json::iterator::operator--()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html#a693439bffe56a9a8cf53bc4a06b911ff',1,'nlohmann::basic_json::json_reverse_iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html#a563a7bd281e9919798d18396107fb05c',1,'nlohmann::basic_json::json_reverse_iterator::operator--()']]], ['operator_2d_3d',['operator-=',['../classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html#aefac8f3e390ac917f021761f4a8f8e71',1,'nlohmann::basic_json::const_iterator::operator-=()'],['../classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html#afe86d48d3e4e5ebdaaec162b3cf0e95c',1,'nlohmann::basic_json::iterator::operator-=()']]], diff --git a/search/all_e.js b/search/all_e.js index 8c032561e..b96c8db3b 100644 --- a/search/all_e.js +++ b/search/all_e.js @@ -5,5 +5,5 @@ var searchData= ['parser_5fcallback_5ft',['parser_callback_t',['../classnlohmann_1_1basic__json_a9e35475e2027520a78e09f460dbe048a.html#a9e35475e2027520a78e09f460dbe048a',1,'nlohmann::basic_json']]], ['patch',['patch',['../classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html#a28dd7f9a1c3f47f9f016e142cd355131',1,'nlohmann::basic_json']]], ['pointer',['pointer',['../classnlohmann_1_1basic__json_a9d1b58099dc64695fcf2847ab0b2a7c7.html#a9d1b58099dc64695fcf2847ab0b2a7c7',1,'nlohmann::basic_json::pointer()'],['../classnlohmann_1_1basic__json_1_1const__iterator_a1da96fc3054d547e7706d3a2f073f389.html#a1da96fc3054d547e7706d3a2f073f389',1,'nlohmann::basic_json::const_iterator::pointer()'],['../classnlohmann_1_1basic__json_1_1iterator_a3aae1df93a78b201d98e178c1c7d02a7.html#a3aae1df93a78b201d98e178c1c7d02a7',1,'nlohmann::basic_json::iterator::pointer()']]], - ['push_5fback',['push_back',['../classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html#a486b96adbf4886c38e38c952394a220f',1,'nlohmann::basic_json::push_back(basic_json &&val)'],['../classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html#a6f3dfd3e83a1e907d7946b47fcd7ceba',1,'nlohmann::basic_json::push_back(const basic_json &val)'],['../classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html#a5212588544f6d2266384c3be9bfda0c5',1,'nlohmann::basic_json::push_back(const typename object_t::value_type &val)']]] + ['push_5fback',['push_back',['../classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html#a486b96adbf4886c38e38c952394a220f',1,'nlohmann::basic_json::push_back(basic_json &&val)'],['../classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html#a6f3dfd3e83a1e907d7946b47fcd7ceba',1,'nlohmann::basic_json::push_back(const basic_json &val)'],['../classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html#a5212588544f6d2266384c3be9bfda0c5',1,'nlohmann::basic_json::push_back(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html#a9c9b4932b26a9630e1a3f25ea42a2c43',1,'nlohmann::basic_json::push_back(std::initializer_list< basic_json > init)']]] ]; diff --git a/search/functions_b.js b/search/functions_b.js index 407ba08bc..382f48dc7 100644 --- a/search/functions_b.js +++ b/search/functions_b.js @@ -8,7 +8,7 @@ var searchData= ['operator_2a',['operator*',['../classnlohmann_1_1basic__json_1_1const__iterator_ab3029a1a83cf46dc28ad443bbad0c74d.html#ab3029a1a83cf46dc28ad443bbad0c74d',1,'nlohmann::basic_json::const_iterator::operator*()'],['../classnlohmann_1_1basic__json_1_1iterator_acbd82115f9232c3d3b5dacc78315b9da.html#acbd82115f9232c3d3b5dacc78315b9da',1,'nlohmann::basic_json::iterator::operator*()']]], ['operator_2b',['operator+',['../classnlohmann_1_1basic__json_1_1const__iterator_a7a80257f2303210b0a5d056fc0b30b40.html#a7a80257f2303210b0a5d056fc0b30b40',1,'nlohmann::basic_json::const_iterator::operator+()'],['../classnlohmann_1_1basic__json_1_1iterator_a56952f8d5702541f0d88e6a764d2ae36.html#a56952f8d5702541f0d88e6a764d2ae36',1,'nlohmann::basic_json::iterator::operator+()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a99ee137dab7e5c948457f6a5321b54b1.html#a99ee137dab7e5c948457f6a5321b54b1',1,'nlohmann::basic_json::json_reverse_iterator::operator+()']]], ['operator_2b_2b',['operator++',['../classnlohmann_1_1basic__json_1_1const__iterator_a8dbaec5bf8ccba3225520356629061cb.html#a8dbaec5bf8ccba3225520356629061cb',1,'nlohmann::basic_json::const_iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a8fbb15efd97599209a7def77af8e748e.html#a8fbb15efd97599209a7def77af8e748e',1,'nlohmann::basic_json::const_iterator::operator++()'],['../classnlohmann_1_1basic__json_1_1iterator_a2943e49b3d88e6ee5793c5923ab2ede9.html#a2943e49b3d88e6ee5793c5923ab2ede9',1,'nlohmann::basic_json::iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1iterator_a050b7fa21051ea57e5b0cc03668b5d4a.html#a050b7fa21051ea57e5b0cc03668b5d4a',1,'nlohmann::basic_json::iterator::operator++()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a545a8204cfd6836eb85abc3113a0bb28.html#a545a8204cfd6836eb85abc3113a0bb28',1,'nlohmann::basic_json::json_reverse_iterator::operator++(int)'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a4aede52d6ee253a510897518b59e09c0.html#a4aede52d6ee253a510897518b59e09c0',1,'nlohmann::basic_json::json_reverse_iterator::operator++()']]], - ['operator_2b_3d',['operator+=',['../classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html#a1c1aa2d148a3e4ce0d4e50cf5b894f41',1,'nlohmann::basic_json::operator+=(basic_json &&val)'],['../classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html#a80c21170db6b5ffd9274b3f351cebadc',1,'nlohmann::basic_json::operator+=(const basic_json &val)'],['../classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html#a9486a272e034c0548305d7a12f3045e6',1,'nlohmann::basic_json::operator+=(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html#a0d5820d1dda9dea3bbeb029cacf68522',1,'nlohmann::basic_json::const_iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html#ae0c848dbc0af1cde15771d45d775b27c',1,'nlohmann::basic_json::iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html#a9accc9dd9f9033f50c0ab6bcf337ffe0',1,'nlohmann::basic_json::json_reverse_iterator::operator+=()']]], + ['operator_2b_3d',['operator+=',['../classnlohmann_1_1basic__json_a1c1aa2d148a3e4ce0d4e50cf5b894f41.html#a1c1aa2d148a3e4ce0d4e50cf5b894f41',1,'nlohmann::basic_json::operator+=(basic_json &&val)'],['../classnlohmann_1_1basic__json_a80c21170db6b5ffd9274b3f351cebadc.html#a80c21170db6b5ffd9274b3f351cebadc',1,'nlohmann::basic_json::operator+=(const basic_json &val)'],['../classnlohmann_1_1basic__json_a9486a272e034c0548305d7a12f3045e6.html#a9486a272e034c0548305d7a12f3045e6',1,'nlohmann::basic_json::operator+=(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_aa0033766b4d3134b9bb57d81762d75a2.html#aa0033766b4d3134b9bb57d81762d75a2',1,'nlohmann::basic_json::operator+=(std::initializer_list< basic_json > init)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a0d5820d1dda9dea3bbeb029cacf68522.html#a0d5820d1dda9dea3bbeb029cacf68522',1,'nlohmann::basic_json::const_iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1iterator_ae0c848dbc0af1cde15771d45d775b27c.html#ae0c848dbc0af1cde15771d45d775b27c',1,'nlohmann::basic_json::iterator::operator+=()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a9accc9dd9f9033f50c0ab6bcf337ffe0.html#a9accc9dd9f9033f50c0ab6bcf337ffe0',1,'nlohmann::basic_json::json_reverse_iterator::operator+=()']]], ['operator_2d',['operator-',['../classnlohmann_1_1basic__json_1_1const__iterator_abc4552ba2fe39e7901a83dd6d4dec151.html#abc4552ba2fe39e7901a83dd6d4dec151',1,'nlohmann::basic_json::const_iterator::operator-(difference_type i)'],['../classnlohmann_1_1basic__json_1_1const__iterator_a5e4d98a8f95e2eccde8cd48c19efa196.html#a5e4d98a8f95e2eccde8cd48c19efa196',1,'nlohmann::basic_json::const_iterator::operator-(const const_iterator &other) const '],['../classnlohmann_1_1basic__json_1_1iterator_a790f550ff168095c83c2e459c575916c.html#a790f550ff168095c83c2e459c575916c',1,'nlohmann::basic_json::iterator::operator-(difference_type i)'],['../classnlohmann_1_1basic__json_1_1iterator_a9f3940ac5fb2c6ff8045ed59b8a0866f.html#a9f3940ac5fb2c6ff8045ed59b8a0866f',1,'nlohmann::basic_json::iterator::operator-(const iterator &other) const '],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_ac2634bee082633671125e909dffad40a.html#ac2634bee082633671125e909dffad40a',1,'nlohmann::basic_json::json_reverse_iterator::operator-(difference_type i) const '],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a115fae3dd8ae02669fedae0545ce1cbc.html#a115fae3dd8ae02669fedae0545ce1cbc',1,'nlohmann::basic_json::json_reverse_iterator::operator-(const json_reverse_iterator &other) const ']]], ['operator_2d_2d',['operator--',['../classnlohmann_1_1basic__json_1_1const__iterator_a6cab1c2ed7e2a014980e2a5717f43a64.html#a6cab1c2ed7e2a014980e2a5717f43a64',1,'nlohmann::basic_json::const_iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1const__iterator_adeb2ff3fdf3cc301b72db109934c9199.html#adeb2ff3fdf3cc301b72db109934c9199',1,'nlohmann::basic_json::const_iterator::operator--()'],['../classnlohmann_1_1basic__json_1_1iterator_ab4f238aa5fcf452b1884b748b0395b1f.html#ab4f238aa5fcf452b1884b748b0395b1f',1,'nlohmann::basic_json::iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1iterator_ab3679dc63b3a59edb98b1c2b96d8683c.html#ab3679dc63b3a59edb98b1c2b96d8683c',1,'nlohmann::basic_json::iterator::operator--()'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a693439bffe56a9a8cf53bc4a06b911ff.html#a693439bffe56a9a8cf53bc4a06b911ff',1,'nlohmann::basic_json::json_reverse_iterator::operator--(int)'],['../classnlohmann_1_1basic__json_1_1json__reverse__iterator_a563a7bd281e9919798d18396107fb05c.html#a563a7bd281e9919798d18396107fb05c',1,'nlohmann::basic_json::json_reverse_iterator::operator--()']]], ['operator_2d_3d',['operator-=',['../classnlohmann_1_1basic__json_1_1const__iterator_aefac8f3e390ac917f021761f4a8f8e71.html#aefac8f3e390ac917f021761f4a8f8e71',1,'nlohmann::basic_json::const_iterator::operator-=()'],['../classnlohmann_1_1basic__json_1_1iterator_afe86d48d3e4e5ebdaaec162b3cf0e95c.html#afe86d48d3e4e5ebdaaec162b3cf0e95c',1,'nlohmann::basic_json::iterator::operator-=()']]], diff --git a/search/functions_c.js b/search/functions_c.js index d7d174c94..8782bced6 100644 --- a/search/functions_c.js +++ b/search/functions_c.js @@ -2,5 +2,5 @@ var searchData= [ ['parse',['parse',['../classnlohmann_1_1basic__json_a35303ad045a06c2a79dc28ac29652e86.html#a35303ad045a06c2a79dc28ac29652e86',1,'nlohmann::basic_json::parse(const string_t &s, parser_callback_t cb=nullptr)'],['../classnlohmann_1_1basic__json_a13c4d2ab4e7ee2f92be785a7b12948ff.html#a13c4d2ab4e7ee2f92be785a7b12948ff',1,'nlohmann::basic_json::parse(std::istream &i, parser_callback_t cb=nullptr)'],['../classnlohmann_1_1basic__json_ab81f2801779e6cb9d98770860af2e39a.html#ab81f2801779e6cb9d98770860af2e39a',1,'nlohmann::basic_json::parse(std::istream &&i, parser_callback_t cb=nullptr)']]], ['patch',['patch',['../classnlohmann_1_1basic__json_a28dd7f9a1c3f47f9f016e142cd355131.html#a28dd7f9a1c3f47f9f016e142cd355131',1,'nlohmann::basic_json']]], - ['push_5fback',['push_back',['../classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html#a486b96adbf4886c38e38c952394a220f',1,'nlohmann::basic_json::push_back(basic_json &&val)'],['../classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html#a6f3dfd3e83a1e907d7946b47fcd7ceba',1,'nlohmann::basic_json::push_back(const basic_json &val)'],['../classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html#a5212588544f6d2266384c3be9bfda0c5',1,'nlohmann::basic_json::push_back(const typename object_t::value_type &val)']]] + ['push_5fback',['push_back',['../classnlohmann_1_1basic__json_a486b96adbf4886c38e38c952394a220f.html#a486b96adbf4886c38e38c952394a220f',1,'nlohmann::basic_json::push_back(basic_json &&val)'],['../classnlohmann_1_1basic__json_a6f3dfd3e83a1e907d7946b47fcd7ceba.html#a6f3dfd3e83a1e907d7946b47fcd7ceba',1,'nlohmann::basic_json::push_back(const basic_json &val)'],['../classnlohmann_1_1basic__json_a5212588544f6d2266384c3be9bfda0c5.html#a5212588544f6d2266384c3be9bfda0c5',1,'nlohmann::basic_json::push_back(const typename object_t::value_type &val)'],['../classnlohmann_1_1basic__json_a9c9b4932b26a9630e1a3f25ea42a2c43.html#a9c9b4932b26a9630e1a3f25ea42a2c43',1,'nlohmann::basic_json::push_back(std::initializer_list< basic_json > init)']]] ]; 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 f9faa9771..094ec289a 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 74bf93ecf..b7844ac64 100644 --- a/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html +++ b/structstd_1_1hash_3_01nlohmann_1_1json_01_4.html @@ -111,11 +111,11 @@ Public Member Functions struct std::hash< nlohmann::json > -

    Definition at line 10086 of file json.hpp.

    +

    Definition at line 10130 of file json.hpp.

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

    Definition at line 10093 of file json.hpp.

    +

    Definition at line 10137 of file json.hpp.

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