Skip to content

Commit

Permalink
🎨 cleanup after PR #395
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Dec 14, 2016
1 parent fe00b36 commit f24e4f6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ I deeply appreciate the help of the following people.
- [cgzones](https://github.com/cgzones) had an idea how to fix the Coverity scan.
- [Jared Grubb](https://github.com/jaredgrubb) silenced a nasty documentation warning.
- [Yixin Zhang](https://github.com/qwename) fixed an integer overflow check.
- [Bosswestfalen](https://github.com/Bosswestfalen) merged two iterator classes into a smaller one.

Thanks a lot for helping out!

Expand Down
35 changes: 17 additions & 18 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class basic_json

public:
// forward declarations
template<typename U> class iter_impl;
template<typename Base> class json_reverse_iterator;
class json_pointer;

Expand Down Expand Up @@ -261,8 +262,6 @@ class basic_json
/// the type of an element const pointer
using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;

// forward declaration for iterators
template <typename U> class iter_impl;
/// an iterator for a basic_json container
using iterator = iter_impl<basic_json>;
/// a const iterator for a basic_json container
Expand Down Expand Up @@ -8208,8 +8207,8 @@ class basic_json
/*!
@brief a template for a random access iterator for the @ref basic_json class
This class implements a both iterators (iterator and const_iterator)
for the @ref basic_json class.
This class implements a both iterators (iterator and const_iterator) for the
@ref basic_json class.
@note An iterator is called *initialized* when a pointer to a JSON value
has been set (e.g., by a constructor or a copy assignment). If the
Expand All @@ -8222,9 +8221,9 @@ class basic_json
The iterator that can be moved to point (forward and backward) to any
element in constant time.
@since version 1.0.0
@since version 1.0.0, simplified in version 2.0.9
*/
template <typename U>
template<typename U>
class iter_impl : public std::iterator<std::random_access_iterator_tag, U>
{
/// allow basic_json to access private members
Expand All @@ -8242,12 +8241,12 @@ class basic_json
using difference_type = typename basic_json::difference_type;
/// defines a pointer to the type iterated over (value_type)
using pointer = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_pointer,
typename basic_json::pointer>::type;
typename basic_json::const_pointer,
typename basic_json::pointer>::type;
/// defines a reference to the type iterated over (value_type)
using reference = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_reference,
typename basic_json::reference>::type;
typename basic_json::const_reference,
typename basic_json::reference>::type;
/// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag;

Expand Down Expand Up @@ -8288,19 +8287,19 @@ class basic_json
}

/*
Use operator const_iterator instead of
const_iterator(const iterator& other) noexcept
to avoid two class definitions for iterator and const_iterator.
Use operator `const_iterator` instead of `const_iterator(const iterator&
other) noexcept` to avoid two class definitions for @ref iterator and
@ref const_iterator.
This function is only called if this class is an iterator.
If this class is a const_iterator this function is not called.
This function is only called if this class is an @ref iterator. If this
class is a @ref const_iterator this function is not called.
*/
operator const_iterator() const
{
const_iterator ret;
{
const_iterator ret;

if (m_object)
{
{
ret.m_object = m_object;
ret.m_it = m_it;
}
Expand Down
37 changes: 19 additions & 18 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class basic_json

public:
// forward declarations
template<typename U> class iter_impl;
template<typename Base> class json_reverse_iterator;
class json_pointer;

Expand Down Expand Up @@ -262,9 +263,9 @@ class basic_json
using const_pointer = typename std::allocator_traits<allocator_type>::const_pointer;

/// an iterator for a basic_json container
class iterator;
using iterator = iter_impl<basic_json>;
/// a const iterator for a basic_json container
class const_iterator;
using const_iterator = iter_impl<const basic_json>;
/// a reverse iterator for a basic_json container
using reverse_iterator = json_reverse_iterator<typename basic_json::iterator>;
/// a const reverse iterator for a basic_json container
Expand Down Expand Up @@ -8206,8 +8207,8 @@ class basic_json
/*!
@brief a template for a random access iterator for the @ref basic_json class

This class implements a both iterators (iterator and const_iterator)
for the @ref basic_json class.
This class implements a both iterators (iterator and const_iterator) for the
@ref basic_json class.

@note An iterator is called *initialized* when a pointer to a JSON value
has been set (e.g., by a constructor or a copy assignment). If the
Expand All @@ -8220,9 +8221,9 @@ class basic_json
The iterator that can be moved to point (forward and backward) to any
element in constant time.

@since version 1.0.0
@since version 1.0.0, simplified in version 2.0.9
*/
template <typename U>
template<typename U>
class iter_impl : public std::iterator<std::random_access_iterator_tag, U>
{
/// allow basic_json to access private members
Expand All @@ -8240,12 +8241,12 @@ class basic_json
using difference_type = typename basic_json::difference_type;
/// defines a pointer to the type iterated over (value_type)
using pointer = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_pointer,
typename basic_json::pointer>::type;
typename basic_json::const_pointer,
typename basic_json::pointer>::type;
/// defines a reference to the type iterated over (value_type)
using reference = typename std::conditional<std::is_const<U>::value,
typename basic_json::const_reference,
typename basic_json::reference>::type;
typename basic_json::const_reference,
typename basic_json::reference>::type;
/// the category of the iterator
using iterator_category = std::bidirectional_iterator_tag;

Expand Down Expand Up @@ -8286,19 +8287,19 @@ class basic_json
}

/*
Use operator const_iterator instead of
const_iterator(const iterator& other) noexcept
to avoid two class definitions for iterator and const_iterator.
Use operator `const_iterator` instead of `const_iterator(const iterator&
other) noexcept` to avoid two class definitions for @ref iterator and
@ref const_iterator.

This function is only called if this class is an iterator.
If this class is a const_iterator this function is not called.
This function is only called if this class is an @ref iterator. If this
class is a @ref const_iterator this function is not called.
*/
operator const_iterator() const
{
const_iterator ret;
{
const_iterator ret;

if (m_object)
{
{
ret.m_object = m_object;
ret.m_it = m_it;
}
Expand Down

0 comments on commit f24e4f6

Please sign in to comment.