From 623c03bc4998c97e5f3f01c62d840b25c8f6e7d3 Mon Sep 17 00:00:00 2001 From: Niels Date: Sun, 19 Jul 2015 12:41:46 +0200 Subject: [PATCH] some cleanup --- README.md | 1 + doc/Doxyfile | 8 +- src/json.hpp | 1277 ++++++++++++++++----------------------------- src/json.hpp.re2c | 168 +++--- 4 files changed, 549 insertions(+), 905 deletions(-) diff --git a/README.md b/README.md index fa37a910..759c6cbc 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Though it's 2015 already, the support for C++11 is still a bit sparse. Currently - GCC 4.9 - GCC 5.0 - GCC 5.1 +- GCC 5.2 - Clang 3.4 - Clang 3.5 - Clang 3.6 diff --git a/doc/Doxyfile b/doc/Doxyfile index 033f8484..46b15aae 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -37,7 +37,7 @@ OPTIMIZE_FOR_FORTRAN = NO OPTIMIZE_OUTPUT_VHDL = NO EXTENSION_MAPPING = MARKDOWN_SUPPORT = YES -AUTOLINK_SUPPORT = YES +AUTOLINK_SUPPORT = NO BUILTIN_STL_SUPPORT = YES CPP_CLI_SUPPORT = NO SIP_SUPPORT = NO @@ -95,7 +95,7 @@ QUIET = YES WARNINGS = YES WARN_IF_UNDOCUMENTED = YES WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO +WARN_NO_PARAMDOC = YES WARN_FORMAT = "$file:$line: $text" WARN_LOGFILE = #--------------------------------------------------------------------------- @@ -108,7 +108,7 @@ RECURSIVE = NO EXCLUDE = EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = -EXCLUDE_SYMBOLS = nlohmann::internals +EXCLUDE_SYMBOLS = nlohmann::anonymous_namespace EXAMPLE_PATH = examples EXAMPLE_PATTERNS = EXAMPLE_RECURSIVE = NO @@ -151,7 +151,7 @@ HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 HTML_TIMESTAMP = YES -HTML_DYNAMIC_SECTIONS = NO +HTML_DYNAMIC_SECTIONS = YES HTML_INDEX_NUM_ENTRIES = 100 GENERATE_DOCSET = YES DOCSET_FEEDNAME = "Doxygen generated docs" diff --git a/src/json.hpp b/src/json.hpp index a0c06191..dfb2bc48 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -103,24 +103,47 @@ default) @requirement The class satisfies the following concept requirements: - Basic - - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible) - - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible) - - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) - - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable) - - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable) - - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible) + - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible): + JSON values can be default constructed. The result will be a JSON null value. + - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible): + A JSON value can be constructed from an rvalue argument. + - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible): + A JSON value can be copy-constrcuted from an lvalue expression. + - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable): + A JSON value van be assigned from an rvalue argument. + - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable): + A JSON value can be copy-assigned from an lvalue expression. + - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible): + JSON values can be destructed. - Layout - - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType) + - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType): + JSON values have + [standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout): + All non-static data members are private and standard layout types, the class + has no virtual functions or (virtual) base classes. - Library-wide - - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable) - - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable) - - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable) - - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer) + - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable): + JSON values can be compared with `==`, see @ref + operator==(const_reference,const_reference). + - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable): + JSON values can be compared with `<`, see @ref + operator<(const_reference,const_reference). + - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable): + Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of + other compatible types, using unqualified function call @ref swap(). + - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer): + JSON values can be compared against `std::nullptr_t` objects which are used + to model the `null` value. - Container - - [Container](http://en.cppreference.com/w/cpp/concept/Container) - - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + - [Container](http://en.cppreference.com/w/cpp/concept/Container): + JSON values can be used like STL containers and provide iterator access. + - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer); + JSON values can be used like STL containers and provide reverse iterator + access. +@internal @note ObjectType trick from http://stackoverflow.com/a/9860911 +@endinternal @see RFC 7159 */ @@ -137,8 +160,13 @@ class basic_json { private: /// workaround type for MSVC - using basic_json_t = - basic_json; + using basic_json_t = basic_json; public: @@ -269,8 +297,11 @@ class basic_json @sa array_t */ - using object_t = - ObjectType, AllocatorType>>; + using object_t = ObjectType, + AllocatorType>>; /*! @brief a type for an array @@ -526,7 +557,7 @@ class basic_json boolean, ///< boolean value number_integer, ///< number value (integer) number_float, ///< number value (floating-point) - discarded ///< (internal) indicates the parser callback chose not to keep the value + discarded ///< discarded by the the parser callback function }; @@ -767,7 +798,6 @@ class basic_json value.,basic_json} @sa basic_json(std::nullptr_t) - @ingroup container */ basic_json() noexcept = default; @@ -1503,9 +1533,7 @@ class basic_json @throw std::bad_alloc if allocation for object, array, or string fails. @liveexample{The following code shows an example for the copy - constructor.,basic_jsonbasic_json_t} - - @ingroup container + constructor.,basic_json__basic_json} */ basic_json(const basic_json& other) : m_type(other.m_type) @@ -1599,8 +1627,6 @@ class basic_json 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.,basic_json__copyassignment} - - @ingroup container */ reference& operator=(basic_json other) noexcept ( std::is_nothrow_move_constructible::value and @@ -1625,8 +1651,6 @@ class basic_json @requirement This function satisfies the Container requirements: - The complexity is linear. - All stored elements are destroyed and all memory is freed. - - @ingroup container */ ~basic_json() { @@ -3138,8 +3162,6 @@ class basic_json - The complexity is constant. @liveexample{The following code shows an example for @ref begin.,begin} - - @ingroup container */ iterator begin() { @@ -3150,7 +3172,6 @@ class basic_json /*! @copydoc basic_json::cbegin() - @ingroup container */ const_iterator begin() const { @@ -3173,8 +3194,6 @@ class basic_json - Has the semantics of `const_cast(*this).begin()`. @liveexample{The following code shows an example for @ref cbegin.,cbegin} - - @ingroup container */ const_iterator cbegin() const { @@ -3198,8 +3217,6 @@ class basic_json - The complexity is constant. @liveexample{The following code shows an example for @ref end.,end} - - @ingroup container */ iterator end() { @@ -3210,7 +3227,6 @@ class basic_json /*! @copydoc basic_json::cend() - @ingroup container */ const_iterator end() const { @@ -3233,8 +3249,6 @@ class basic_json - Has the semantics of `const_cast(*this).end()`. @liveexample{The following code shows an example for @ref cend.,cend} - - @ingroup container */ const_iterator cend() const { @@ -3257,8 +3271,6 @@ class basic_json - Has the semantics of `reverse_iterator(end())`. @liveexample{The following code shows an example for @ref rbegin.,rbegin} - - @ingroup reversiblecontainer */ reverse_iterator rbegin() { @@ -3267,7 +3279,6 @@ class basic_json /*! @copydoc basic_json::crbegin() - @ingroup reversiblecontainer */ const_reverse_iterator rbegin() const { @@ -3289,8 +3300,6 @@ class basic_json - Has the semantics of `reverse_iterator(begin())`. @liveexample{The following code shows an example for @ref rend.,rend} - - @ingroup reversiblecontainer */ reverse_iterator rend() { @@ -3299,7 +3308,6 @@ class basic_json /*! @copydoc basic_json::crend() - @ingroup reversiblecontainer */ const_reverse_iterator rend() const { @@ -3321,8 +3329,6 @@ class basic_json - Has the semantics of `const_cast(*this).rbegin()`. @liveexample{The following code shows an example for @ref crbegin.,crbegin} - - @ingroup reversiblecontainer */ const_reverse_iterator crbegin() const { @@ -3344,8 +3350,6 @@ class basic_json - Has the semantics of `const_cast(*this).rend()`. @liveexample{The following code shows an example for @ref crend.,crend} - - @ingroup reversiblecontainer */ const_reverse_iterator crend() const { @@ -3388,8 +3392,6 @@ class basic_json @liveexample{The following code uses @ref empty to check if a @ref json object contains any elements.,empty} - - @ingroup container */ bool empty() const noexcept { @@ -3444,8 +3446,6 @@ class basic_json @liveexample{The following code calls @ref size on the different value types.,size} - - @ingroup container */ size_type size() const noexcept { @@ -3503,8 +3503,6 @@ class basic_json @liveexample{The following code calls @ref max_size on the different value types. Note the output is implementation specific.,max_size} - - @ingroup container */ size_type max_size() const noexcept { @@ -3932,8 +3930,6 @@ class basic_json @liveexample{The example below shows how JSON arrays can be swapped.,swap__reference} - - @ingroup container */ void swap(reference other) noexcept ( std::is_nothrow_move_constructible::value and @@ -3962,8 +3958,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__array_t} - - @ingroup container */ void swap(array_t& other) { @@ -3993,8 +3987,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__object_t} - - @ingroup container */ void swap(object_t& other) { @@ -4024,8 +4016,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__string_t} - - @ingroup container */ void swap(string_t& other) { @@ -4100,8 +4090,6 @@ class basic_json @liveexample{The example demonstrates comparing several JSON types.,operator__equal} - - @ingroup container */ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { @@ -4186,8 +4174,6 @@ class basic_json @liveexample{The example demonstrates comparing several JSON types.,operator__notequal} - - @ingroup container */ friend bool operator!=(const_reference lhs, const_reference rhs) noexcept { @@ -4839,7 +4825,7 @@ class basic_json } /// return value to compare - operator const difference_type () const + operator difference_type () const { return m_it; } @@ -4862,21 +4848,28 @@ class basic_json struct internal_iterator { /// iterator for JSON objects - typename object_t::iterator object_iterator; + typename object_t::iterator object_iterator = typename object_t::iterator(); /// iterator for JSON arrays - typename array_t::iterator array_iterator; + typename array_t::iterator array_iterator = typename array_t::iterator(); /// generic iterator for all other types - primitive_iterator_t primitive_iterator; - - // leave the union un-initialized - internal_iterator() {} + primitive_iterator_t primitive_iterator = primitive_iterator_t(); }; public: - /// a const random access iterator for the basic_json class + /*! + @brief a const random access iterator for the @ref basic_json class + + This class implements a const iterator for the @ref basic_json class. From + this class, the @ref iterator class is derived. + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + */ class const_iterator : public std::iterator { - // allow basic_json class to access m_it + /// allow basic_json to access private members friend class basic_json; public: @@ -5368,7 +5361,16 @@ class basic_json internal_iterator m_it = internal_iterator(); }; - /// a random access iterator for the basic_json class + /*! + @brief a mutable random access iterator for the @ref basic_json class + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + - [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): + It is possible to write to the pointed-to element. + */ class iterator : public const_iterator { public: @@ -5490,13 +5492,28 @@ class basic_json } }; - /// a template for a reverse iterator class + /*! + @brief a template for a reverse iterator class + + @tparam Base the base iterator type to reverse. Valid types are @ref + iterator (to create @ref reverse_iterator) and @ref const_iterator (to + create @ref const_reverse_iterator). + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + - [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): + It is possible to write to the pointed-to element (only if @a Base is + @ref iterator). + */ template class json_reverse_iterator : public std::reverse_iterator { public: /// shortcut to the reverse iterator adaptor using base_iterator = std::reverse_iterator; + /// the reference type for the pointed-to element using reference = typename Base::reference; /// create reverse iterator from iterator @@ -5772,758 +5789,369 @@ class basic_json // remember the begin of the token m_start = m_cursor; + + { + lexer_char_t yych; + unsigned int yyaccept = 0; + static const unsigned char yybm[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 32, 32, 0, 0, 32, 0, 0, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 96, 64, 0, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 192, 192, 192, 192, 192, 192, 192, 192, + 192, 192, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 0, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, + }; - { - lexer_char_t yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = - { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 32, 0, 0, 32, 0, 0, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 96, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 0, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - }; - - if ((m_limit - m_cursor) < 5) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '9') - { - if (yych <= ' ') - { - if (yych <= '\n') - { - if (yych <= 0x00) - { - goto basic_json_parser_27; - } - if (yych <= 0x08) - { - goto basic_json_parser_29; - } - if (yych >= '\n') - { - goto basic_json_parser_4; - } - } - else - { - if (yych == '\r') - { - goto basic_json_parser_2; - } - if (yych <= 0x1F) - { - goto basic_json_parser_29; - } - } - } - else - { - if (yych <= ',') - { - if (yych == '"') - { - goto basic_json_parser_26; - } - if (yych <= '+') - { - goto basic_json_parser_29; - } - goto basic_json_parser_14; - } - else - { - if (yych <= '-') - { - goto basic_json_parser_22; - } - if (yych <= '/') - { - goto basic_json_parser_29; - } - if (yych <= '0') - { - goto basic_json_parser_23; - } - goto basic_json_parser_25; - } - } - } - else - { - if (yych <= 'm') - { - if (yych <= '\\') - { - if (yych <= ':') - { - goto basic_json_parser_16; - } - if (yych == '[') - { - goto basic_json_parser_6; - } - goto basic_json_parser_29; - } - else - { - if (yych <= ']') - { - goto basic_json_parser_8; - } - if (yych == 'f') - { - goto basic_json_parser_21; - } - goto basic_json_parser_29; - } - } - else - { - if (yych <= 'z') - { - if (yych <= 'n') - { - goto basic_json_parser_18; - } - if (yych == 't') - { - goto basic_json_parser_20; - } - goto basic_json_parser_29; - } - else - { - if (yych <= '{') - { - goto basic_json_parser_10; - } - if (yych == '}') - { - goto basic_json_parser_12; - } - goto basic_json_parser_29; - } - } - } -basic_json_parser_2: - ++m_cursor; - yych = *m_cursor; - goto basic_json_parser_5; -basic_json_parser_3: - { - return scan(); - } -basic_json_parser_4: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; -basic_json_parser_5: - if (yybm[0 + yych] & 32) - { - goto basic_json_parser_4; - } - goto basic_json_parser_3; -basic_json_parser_6: - ++m_cursor; - { - return token_type::begin_array; - } -basic_json_parser_8: - ++m_cursor; - { - return token_type::end_array; - } -basic_json_parser_10: - ++m_cursor; - { - return token_type::begin_object; - } -basic_json_parser_12: - ++m_cursor; - { - return token_type::end_object; - } -basic_json_parser_14: - ++m_cursor; - { - return token_type::value_separator; - } -basic_json_parser_16: - ++m_cursor; - { - return token_type::name_separator; - } -basic_json_parser_18: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'u') - { - goto basic_json_parser_59; - } -basic_json_parser_19: - { - return token_type::parse_error; - } -basic_json_parser_20: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'r') - { - goto basic_json_parser_55; - } - goto basic_json_parser_19; -basic_json_parser_21: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych == 'a') - { - goto basic_json_parser_50; - } - goto basic_json_parser_19; -basic_json_parser_22: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_19; - } - if (yych <= '0') - { - goto basic_json_parser_49; - } - if (yych <= '9') - { - goto basic_json_parser_40; - } - goto basic_json_parser_19; -basic_json_parser_23: - yyaccept = 1; - yych = *(m_marker = ++m_cursor); - if (yych <= 'D') - { - if (yych == '.') - { - goto basic_json_parser_42; - } - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_43; - } - if (yych == 'e') - { - goto basic_json_parser_43; - } - } -basic_json_parser_24: - { - return token_type::value_number; - } -basic_json_parser_25: - yyaccept = 1; - yych = *(m_marker = ++m_cursor); - goto basic_json_parser_41; -basic_json_parser_26: - yyaccept = 0; - yych = *(m_marker = ++m_cursor); - if (yych <= 0x0F) - { - goto basic_json_parser_19; - } - goto basic_json_parser_31; -basic_json_parser_27: - ++m_cursor; - { - return token_type::end_of_input; - } -basic_json_parser_29: - yych = *++m_cursor; - goto basic_json_parser_19; -basic_json_parser_30: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; -basic_json_parser_31: - if (yybm[0 + yych] & 64) - { - goto basic_json_parser_30; - } - if (yych <= 0x0F) - { - goto basic_json_parser_32; - } - if (yych <= '"') - { - goto basic_json_parser_34; - } - goto basic_json_parser_33; -basic_json_parser_32: - m_cursor = m_marker; - if (yyaccept == 0) - { - goto basic_json_parser_19; - } - else - { - goto basic_json_parser_24; - } -basic_json_parser_33: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= 'e') - { - if (yych <= '/') - { - if (yych == '"') - { - goto basic_json_parser_30; - } - if (yych <= '.') - { - goto basic_json_parser_32; - } - goto basic_json_parser_30; - } - else - { - if (yych <= '\\') - { - if (yych <= '[') - { - goto basic_json_parser_32; - } - goto basic_json_parser_30; - } - else - { - if (yych == 'b') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - } - } - else - { - if (yych <= 'q') - { - if (yych <= 'f') - { - goto basic_json_parser_30; - } - if (yych == 'n') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 's') - { - if (yych <= 'r') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 't') - { - goto basic_json_parser_30; - } - if (yych <= 'u') - { - goto basic_json_parser_36; - } - goto basic_json_parser_32; - } - } - } -basic_json_parser_34: - ++m_cursor; - { - return token_type::value_string; - } -basic_json_parser_36: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych >= ':') - { - goto basic_json_parser_32; - } - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_37; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych >= 'g') - { - goto basic_json_parser_32; - } - } -basic_json_parser_37: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych >= ':') - { - goto basic_json_parser_32; - } - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_38; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych >= 'g') - { - goto basic_json_parser_32; - } - } -basic_json_parser_38: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych >= ':') - { - goto basic_json_parser_32; - } - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_39; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych >= 'g') - { - goto basic_json_parser_32; - } - } -basic_json_parser_39: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '@') - { - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } - else - { - if (yych <= 'F') - { - goto basic_json_parser_30; - } - if (yych <= '`') - { - goto basic_json_parser_32; - } - if (yych <= 'f') - { - goto basic_json_parser_30; - } - goto basic_json_parser_32; - } -basic_json_parser_40: - yyaccept = 1; - m_marker = ++m_cursor; - if ((m_limit - m_cursor) < 3) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; -basic_json_parser_41: - if (yybm[0 + yych] & 128) - { - goto basic_json_parser_40; - } - if (yych <= 'D') - { - if (yych != '.') - { - goto basic_json_parser_24; - } - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_43; - } - if (yych == 'e') - { - goto basic_json_parser_43; - } - goto basic_json_parser_24; - } -basic_json_parser_42: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_47; - } - goto basic_json_parser_32; -basic_json_parser_43: - yych = *++m_cursor; - if (yych <= ',') - { - if (yych != '+') - { - goto basic_json_parser_32; - } - } - else - { - if (yych <= '-') - { - goto basic_json_parser_44; - } - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych <= '9') - { - goto basic_json_parser_45; - } - goto basic_json_parser_32; - } -basic_json_parser_44: - yych = *++m_cursor; - if (yych <= '/') - { - goto basic_json_parser_32; - } - if (yych >= ':') - { - goto basic_json_parser_32; - } -basic_json_parser_45: - ++m_cursor; - if (m_limit <= m_cursor) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= '/') - { - goto basic_json_parser_24; - } - if (yych <= '9') - { - goto basic_json_parser_45; - } - goto basic_json_parser_24; -basic_json_parser_47: - yyaccept = 1; - m_marker = ++m_cursor; - if ((m_limit - m_cursor) < 3) - { - yyfill(); // LCOV_EXCL_LINE; - } - yych = *m_cursor; - if (yych <= 'D') - { - if (yych <= '/') - { - goto basic_json_parser_24; - } - if (yych <= '9') - { - goto basic_json_parser_47; - } - goto basic_json_parser_24; - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_43; - } - if (yych == 'e') - { - goto basic_json_parser_43; - } - goto basic_json_parser_24; - } -basic_json_parser_49: - yyaccept = 1; - yych = *(m_marker = ++m_cursor); - if (yych <= 'D') - { - if (yych == '.') - { - goto basic_json_parser_42; - } - goto basic_json_parser_24; - } - else - { - if (yych <= 'E') - { - goto basic_json_parser_43; - } - if (yych == 'e') - { - goto basic_json_parser_43; - } - goto basic_json_parser_24; - } -basic_json_parser_50: - yych = *++m_cursor; - if (yych != 'l') - { - goto basic_json_parser_32; - } - yych = *++m_cursor; - if (yych != 's') - { - goto basic_json_parser_32; - } - yych = *++m_cursor; - if (yych != 'e') - { - goto basic_json_parser_32; - } - ++m_cursor; - { - return token_type::literal_false; - } -basic_json_parser_55: - yych = *++m_cursor; - if (yych != 'u') - { - goto basic_json_parser_32; - } - yych = *++m_cursor; - if (yych != 'e') - { - goto basic_json_parser_32; - } - ++m_cursor; - { - return token_type::literal_true; - } -basic_json_parser_59: - yych = *++m_cursor; - if (yych != 'l') - { - goto basic_json_parser_32; - } - yych = *++m_cursor; - if (yych != 'l') - { - goto basic_json_parser_32; - } - ++m_cursor; - { - return token_type::literal_null; + if ((m_limit - m_cursor) < 5) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '9') { + if (yych <= ' ') { + if (yych <= '\n') { + if (yych <= 0x00) goto basic_json_parser_27; + if (yych <= 0x08) goto basic_json_parser_29; + if (yych >= '\n') goto basic_json_parser_4; + } else { + if (yych == '\r') goto basic_json_parser_2; + if (yych <= 0x1F) goto basic_json_parser_29; + } + } else { + if (yych <= ',') { + if (yych == '"') goto basic_json_parser_26; + if (yych <= '+') goto basic_json_parser_29; + goto basic_json_parser_14; + } else { + if (yych <= '-') goto basic_json_parser_22; + if (yych <= '/') goto basic_json_parser_29; + if (yych <= '0') goto basic_json_parser_23; + goto basic_json_parser_25; } } + } else { + if (yych <= 'm') { + if (yych <= '\\') { + if (yych <= ':') goto basic_json_parser_16; + if (yych == '[') goto basic_json_parser_6; + goto basic_json_parser_29; + } else { + if (yych <= ']') goto basic_json_parser_8; + if (yych == 'f') goto basic_json_parser_21; + goto basic_json_parser_29; + } + } else { + if (yych <= 'z') { + if (yych <= 'n') goto basic_json_parser_18; + if (yych == 't') goto basic_json_parser_20; + goto basic_json_parser_29; + } else { + if (yych <= '{') goto basic_json_parser_10; + if (yych == '}') goto basic_json_parser_12; + goto basic_json_parser_29; + } + } + } +basic_json_parser_2: + ++m_cursor; + yych = *m_cursor; + goto basic_json_parser_5; +basic_json_parser_3: + { return scan(); } +basic_json_parser_4: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; +basic_json_parser_5: + if (yybm[0+yych] & 32) { + goto basic_json_parser_4; + } + goto basic_json_parser_3; +basic_json_parser_6: + ++m_cursor; + { return token_type::begin_array; } +basic_json_parser_8: + ++m_cursor; + { return token_type::end_array; } +basic_json_parser_10: + ++m_cursor; + { return token_type::begin_object; } +basic_json_parser_12: + ++m_cursor; + { return token_type::end_object; } +basic_json_parser_14: + ++m_cursor; + { return token_type::value_separator; } +basic_json_parser_16: + ++m_cursor; + { return token_type::name_separator; } +basic_json_parser_18: + yyaccept = 0; + yych = *(m_marker = ++m_cursor); + if (yych == 'u') goto basic_json_parser_59; +basic_json_parser_19: + { return token_type::parse_error; } +basic_json_parser_20: + yyaccept = 0; + yych = *(m_marker = ++m_cursor); + if (yych == 'r') goto basic_json_parser_55; + goto basic_json_parser_19; +basic_json_parser_21: + yyaccept = 0; + yych = *(m_marker = ++m_cursor); + if (yych == 'a') goto basic_json_parser_50; + goto basic_json_parser_19; +basic_json_parser_22: + yych = *++m_cursor; + if (yych <= '/') goto basic_json_parser_19; + if (yych <= '0') goto basic_json_parser_49; + if (yych <= '9') goto basic_json_parser_40; + goto basic_json_parser_19; +basic_json_parser_23: + yyaccept = 1; + yych = *(m_marker = ++m_cursor); + if (yych <= 'D') { + if (yych == '.') goto basic_json_parser_42; + } else { + if (yych <= 'E') goto basic_json_parser_43; + if (yych == 'e') goto basic_json_parser_43; + } +basic_json_parser_24: + { return token_type::value_number; } +basic_json_parser_25: + yyaccept = 1; + yych = *(m_marker = ++m_cursor); + goto basic_json_parser_41; +basic_json_parser_26: + yyaccept = 0; + yych = *(m_marker = ++m_cursor); + if (yych <= 0x0F) goto basic_json_parser_19; + goto basic_json_parser_31; +basic_json_parser_27: + ++m_cursor; + { return token_type::end_of_input; } +basic_json_parser_29: + yych = *++m_cursor; + goto basic_json_parser_19; +basic_json_parser_30: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; +basic_json_parser_31: + if (yybm[0+yych] & 64) { + goto basic_json_parser_30; + } + if (yych <= 0x0F) goto basic_json_parser_32; + if (yych <= '"') goto basic_json_parser_34; + goto basic_json_parser_33; +basic_json_parser_32: + m_cursor = m_marker; + if (yyaccept == 0) { + goto basic_json_parser_19; + } else { + goto basic_json_parser_24; + } +basic_json_parser_33: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= 'e') { + if (yych <= '/') { + if (yych == '"') goto basic_json_parser_30; + if (yych <= '.') goto basic_json_parser_32; + goto basic_json_parser_30; + } else { + if (yych <= '\\') { + if (yych <= '[') goto basic_json_parser_32; + goto basic_json_parser_30; + } else { + if (yych == 'b') goto basic_json_parser_30; + goto basic_json_parser_32; + } + } + } else { + if (yych <= 'q') { + if (yych <= 'f') goto basic_json_parser_30; + if (yych == 'n') goto basic_json_parser_30; + goto basic_json_parser_32; + } else { + if (yych <= 's') { + if (yych <= 'r') goto basic_json_parser_30; + goto basic_json_parser_32; + } else { + if (yych <= 't') goto basic_json_parser_30; + if (yych <= 'u') goto basic_json_parser_36; + goto basic_json_parser_32; + } + } + } +basic_json_parser_34: + ++m_cursor; + { return token_type::value_string; } +basic_json_parser_36: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '@') { + if (yych <= '/') goto basic_json_parser_32; + if (yych >= ':') goto basic_json_parser_32; + } else { + if (yych <= 'F') goto basic_json_parser_37; + if (yych <= '`') goto basic_json_parser_32; + if (yych >= 'g') goto basic_json_parser_32; + } +basic_json_parser_37: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '@') { + if (yych <= '/') goto basic_json_parser_32; + if (yych >= ':') goto basic_json_parser_32; + } else { + if (yych <= 'F') goto basic_json_parser_38; + if (yych <= '`') goto basic_json_parser_32; + if (yych >= 'g') goto basic_json_parser_32; + } +basic_json_parser_38: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '@') { + if (yych <= '/') goto basic_json_parser_32; + if (yych >= ':') goto basic_json_parser_32; + } else { + if (yych <= 'F') goto basic_json_parser_39; + if (yych <= '`') goto basic_json_parser_32; + if (yych >= 'g') goto basic_json_parser_32; + } +basic_json_parser_39: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '@') { + if (yych <= '/') goto basic_json_parser_32; + if (yych <= '9') goto basic_json_parser_30; + goto basic_json_parser_32; + } else { + if (yych <= 'F') goto basic_json_parser_30; + if (yych <= '`') goto basic_json_parser_32; + if (yych <= 'f') goto basic_json_parser_30; + goto basic_json_parser_32; + } +basic_json_parser_40: + yyaccept = 1; + m_marker = ++m_cursor; + if ((m_limit - m_cursor) < 3) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; +basic_json_parser_41: + if (yybm[0+yych] & 128) { + goto basic_json_parser_40; + } + if (yych <= 'D') { + if (yych != '.') goto basic_json_parser_24; + } else { + if (yych <= 'E') goto basic_json_parser_43; + if (yych == 'e') goto basic_json_parser_43; + goto basic_json_parser_24; + } +basic_json_parser_42: + yych = *++m_cursor; + if (yych <= '/') goto basic_json_parser_32; + if (yych <= '9') goto basic_json_parser_47; + goto basic_json_parser_32; +basic_json_parser_43: + yych = *++m_cursor; + if (yych <= ',') { + if (yych != '+') goto basic_json_parser_32; + } else { + if (yych <= '-') goto basic_json_parser_44; + if (yych <= '/') goto basic_json_parser_32; + if (yych <= '9') goto basic_json_parser_45; + goto basic_json_parser_32; + } +basic_json_parser_44: + yych = *++m_cursor; + if (yych <= '/') goto basic_json_parser_32; + if (yych >= ':') goto basic_json_parser_32; +basic_json_parser_45: + ++m_cursor; + if (m_limit <= m_cursor) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= '/') goto basic_json_parser_24; + if (yych <= '9') goto basic_json_parser_45; + goto basic_json_parser_24; +basic_json_parser_47: + yyaccept = 1; + m_marker = ++m_cursor; + if ((m_limit - m_cursor) < 3) yyfill(); // LCOV_EXCL_LINE; + yych = *m_cursor; + if (yych <= 'D') { + if (yych <= '/') goto basic_json_parser_24; + if (yych <= '9') goto basic_json_parser_47; + goto basic_json_parser_24; + } else { + if (yych <= 'E') goto basic_json_parser_43; + if (yych == 'e') goto basic_json_parser_43; + goto basic_json_parser_24; + } +basic_json_parser_49: + yyaccept = 1; + yych = *(m_marker = ++m_cursor); + if (yych <= 'D') { + if (yych == '.') goto basic_json_parser_42; + goto basic_json_parser_24; + } else { + if (yych <= 'E') goto basic_json_parser_43; + if (yych == 'e') goto basic_json_parser_43; + goto basic_json_parser_24; + } +basic_json_parser_50: + yych = *++m_cursor; + if (yych != 'l') goto basic_json_parser_32; + yych = *++m_cursor; + if (yych != 's') goto basic_json_parser_32; + yych = *++m_cursor; + if (yych != 'e') goto basic_json_parser_32; + ++m_cursor; + { return token_type::literal_false; } +basic_json_parser_55: + yych = *++m_cursor; + if (yych != 'u') goto basic_json_parser_32; + yych = *++m_cursor; + if (yych != 'e') goto basic_json_parser_32; + ++m_cursor; + { return token_type::literal_true; } +basic_json_parser_59: + yych = *++m_cursor; + if (yych != 'l') goto basic_json_parser_32; + yych = *++m_cursor; + if (yych != 'l') goto basic_json_parser_32; + ++m_cursor; + { return token_type::literal_null; } + } } @@ -7047,7 +6675,6 @@ namespace std { /*! @brief exchanges the values of two JSON objects -@ingroup container */ template <> inline void swap(nlohmann::json& j1, diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index a52383d5..e2561f36 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -103,24 +103,47 @@ default) @requirement The class satisfies the following concept requirements: - Basic - - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible) - - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible) - - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) - - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable) - - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable) - - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible) + - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible): + JSON values can be default constructed. The result will be a JSON null value. + - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible): + A JSON value can be constructed from an rvalue argument. + - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible): + A JSON value can be copy-constrcuted from an lvalue expression. + - [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable): + A JSON value van be assigned from an rvalue argument. + - [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable): + A JSON value can be copy-assigned from an lvalue expression. + - [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible): + JSON values can be destructed. - Layout - - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType) + - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType): + JSON values have + [standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout): + All non-static data members are private and standard layout types, the class + has no virtual functions or (virtual) base classes. - Library-wide - - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable) - - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable) - - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable) - - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer) + - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable): + JSON values can be compared with `==`, see @ref + operator==(const_reference,const_reference). + - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable): + JSON values can be compared with `<`, see @ref + operator<(const_reference,const_reference). + - [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable): + Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of + other compatible types, using unqualified function call @ref swap(). + - [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer): + JSON values can be compared against `std::nullptr_t` objects which are used + to model the `null` value. - Container - - [Container](http://en.cppreference.com/w/cpp/concept/Container) - - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) + - [Container](http://en.cppreference.com/w/cpp/concept/Container): + JSON values can be used like STL containers and provide iterator access. + - [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer); + JSON values can be used like STL containers and provide reverse iterator + access. +@internal @note ObjectType trick from http://stackoverflow.com/a/9860911 +@endinternal @see RFC 7159 */ @@ -137,8 +160,13 @@ class basic_json { private: /// workaround type for MSVC - using basic_json_t = - basic_json; + using basic_json_t = basic_json; public: @@ -269,8 +297,11 @@ class basic_json @sa array_t */ - using object_t = - ObjectType, AllocatorType>>; + using object_t = ObjectType, + AllocatorType>>; /*! @brief a type for an array @@ -526,7 +557,7 @@ class basic_json boolean, ///< boolean value number_integer, ///< number value (integer) number_float, ///< number value (floating-point) - discarded ///< (internal) indicates the parser callback chose not to keep the value + discarded ///< discarded by the the parser callback function }; @@ -767,7 +798,6 @@ class basic_json value.,basic_json} @sa basic_json(std::nullptr_t) - @ingroup container */ basic_json() noexcept = default; @@ -1503,9 +1533,7 @@ class basic_json @throw std::bad_alloc if allocation for object, array, or string fails. @liveexample{The following code shows an example for the copy - constructor.,basic_jsonbasic_json_t} - - @ingroup container + constructor.,basic_json__basic_json} */ basic_json(const basic_json& other) : m_type(other.m_type) @@ -1599,8 +1627,6 @@ class basic_json 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.,basic_json__copyassignment} - - @ingroup container */ reference& operator=(basic_json other) noexcept ( std::is_nothrow_move_constructible::value and @@ -1625,8 +1651,6 @@ class basic_json @requirement This function satisfies the Container requirements: - The complexity is linear. - All stored elements are destroyed and all memory is freed. - - @ingroup container */ ~basic_json() { @@ -3138,8 +3162,6 @@ class basic_json - The complexity is constant. @liveexample{The following code shows an example for @ref begin.,begin} - - @ingroup container */ iterator begin() { @@ -3150,7 +3172,6 @@ class basic_json /*! @copydoc basic_json::cbegin() - @ingroup container */ const_iterator begin() const { @@ -3173,8 +3194,6 @@ class basic_json - Has the semantics of `const_cast(*this).begin()`. @liveexample{The following code shows an example for @ref cbegin.,cbegin} - - @ingroup container */ const_iterator cbegin() const { @@ -3198,8 +3217,6 @@ class basic_json - The complexity is constant. @liveexample{The following code shows an example for @ref end.,end} - - @ingroup container */ iterator end() { @@ -3210,7 +3227,6 @@ class basic_json /*! @copydoc basic_json::cend() - @ingroup container */ const_iterator end() const { @@ -3233,8 +3249,6 @@ class basic_json - Has the semantics of `const_cast(*this).end()`. @liveexample{The following code shows an example for @ref cend.,cend} - - @ingroup container */ const_iterator cend() const { @@ -3257,8 +3271,6 @@ class basic_json - Has the semantics of `reverse_iterator(end())`. @liveexample{The following code shows an example for @ref rbegin.,rbegin} - - @ingroup reversiblecontainer */ reverse_iterator rbegin() { @@ -3267,7 +3279,6 @@ class basic_json /*! @copydoc basic_json::crbegin() - @ingroup reversiblecontainer */ const_reverse_iterator rbegin() const { @@ -3289,8 +3300,6 @@ class basic_json - Has the semantics of `reverse_iterator(begin())`. @liveexample{The following code shows an example for @ref rend.,rend} - - @ingroup reversiblecontainer */ reverse_iterator rend() { @@ -3299,7 +3308,6 @@ class basic_json /*! @copydoc basic_json::crend() - @ingroup reversiblecontainer */ const_reverse_iterator rend() const { @@ -3321,8 +3329,6 @@ class basic_json - Has the semantics of `const_cast(*this).rbegin()`. @liveexample{The following code shows an example for @ref crbegin.,crbegin} - - @ingroup reversiblecontainer */ const_reverse_iterator crbegin() const { @@ -3344,8 +3350,6 @@ class basic_json - Has the semantics of `const_cast(*this).rend()`. @liveexample{The following code shows an example for @ref crend.,crend} - - @ingroup reversiblecontainer */ const_reverse_iterator crend() const { @@ -3388,8 +3392,6 @@ class basic_json @liveexample{The following code uses @ref empty to check if a @ref json object contains any elements.,empty} - - @ingroup container */ bool empty() const noexcept { @@ -3444,8 +3446,6 @@ class basic_json @liveexample{The following code calls @ref size on the different value types.,size} - - @ingroup container */ size_type size() const noexcept { @@ -3503,8 +3503,6 @@ class basic_json @liveexample{The following code calls @ref max_size on the different value types. Note the output is implementation specific.,max_size} - - @ingroup container */ size_type max_size() const noexcept { @@ -3932,8 +3930,6 @@ class basic_json @liveexample{The example below shows how JSON arrays can be swapped.,swap__reference} - - @ingroup container */ void swap(reference other) noexcept ( std::is_nothrow_move_constructible::value and @@ -3962,8 +3958,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__array_t} - - @ingroup container */ void swap(array_t& other) { @@ -3993,8 +3987,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__object_t} - - @ingroup container */ void swap(object_t& other) { @@ -4024,8 +4016,6 @@ class basic_json @liveexample{The example below shows how JSON values can be swapped.,swap__string_t} - - @ingroup container */ void swap(string_t& other) { @@ -4100,8 +4090,6 @@ class basic_json @liveexample{The example demonstrates comparing several JSON types.,operator__equal} - - @ingroup container */ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { @@ -4186,8 +4174,6 @@ class basic_json @liveexample{The example demonstrates comparing several JSON types.,operator__notequal} - - @ingroup container */ friend bool operator!=(const_reference lhs, const_reference rhs) noexcept { @@ -4839,7 +4825,7 @@ class basic_json } /// return value to compare - operator const difference_type () const + operator difference_type () const { return m_it; } @@ -4862,21 +4848,28 @@ class basic_json struct internal_iterator { /// iterator for JSON objects - typename object_t::iterator object_iterator; + typename object_t::iterator object_iterator = typename object_t::iterator(); /// iterator for JSON arrays - typename array_t::iterator array_iterator; + typename array_t::iterator array_iterator = typename array_t::iterator(); /// generic iterator for all other types - primitive_iterator_t primitive_iterator; - - // leave the union un-initialized - internal_iterator() {} + primitive_iterator_t primitive_iterator = primitive_iterator_t(); }; public: - /// a const random access iterator for the basic_json class + /*! + @brief a const random access iterator for the @ref basic_json class + + This class implements a const iterator for the @ref basic_json class. From + this class, the @ref iterator class is derived. + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + */ class const_iterator : public std::iterator { - // allow basic_json class to access m_it + /// allow basic_json to access private members friend class basic_json; public: @@ -5368,7 +5361,16 @@ class basic_json internal_iterator m_it = internal_iterator(); }; - /// a random access iterator for the basic_json class + /*! + @brief a mutable random access iterator for the @ref basic_json class + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + - [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): + It is possible to write to the pointed-to element. + */ class iterator : public const_iterator { public: @@ -5490,13 +5492,28 @@ class basic_json } }; - /// a template for a reverse iterator class + /*! + @brief a template for a reverse iterator class + + @tparam Base the base iterator type to reverse. Valid types are @ref + iterator (to create @ref reverse_iterator) and @ref const_iterator (to + create @ref const_reverse_iterator). + + @requirement The class satisfies the following concept requirements: + - [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator): + The iterator that can be moved to point (forward and backward) to any + element in constant time. + - [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator): + It is possible to write to the pointed-to element (only if @a Base is + @ref iterator). + */ template class json_reverse_iterator : public std::reverse_iterator { public: /// shortcut to the reverse iterator adaptor using base_iterator = std::reverse_iterator; + /// the reference type for the pointed-to element using reference = typename Base::reference; /// create reverse iterator from iterator @@ -6353,7 +6370,6 @@ namespace std { /*! @brief exchanges the values of two JSON objects -@ingroup container */ template <> inline void swap(nlohmann::json& j1,