Skip to content

Commit

Permalink
Remove const from iterator operator return types
Browse files Browse the repository at this point in the history
Commit f28fc22 introduced const qualifiers on post-(inc-/dec-)rement
operators of iterators. These qualifiers prevent the use of basic_json
in place of std::ranges::range, which requires the post-increment
operator to be equality-preserving.

These changes appear to be the result of compiler suggestions, and no
further explanation is discernible from the PR discussion (nlohmann#858).

This commit partially reverts f28fc22, removing all added const
qualifiers.

Fixes nlohmann#3331.
  • Loading branch information
falbrechtskirchinger committed Feb 15, 2022
1 parent d8a6329 commit 3253893
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/nlohmann/detail/iterators/iter_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
@brief post-increment (it++)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl const operator++(int) // NOLINT(readability-const-return-type)
iter_impl operator++(int)
{
auto result = *this;
++(*this);
Expand Down Expand Up @@ -403,7 +403,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
@brief post-decrement (it--)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl const operator--(int) // NOLINT(readability-const-return-type)
iter_impl operator--(int)
{
auto result = *this;
--(*this);
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/iterators/json_reverse_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}

/// post-increment (it++)
json_reverse_iterator const operator++(int) // NOLINT(readability-const-return-type)
json_reverse_iterator operator++(int)
{
return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
}
Expand All @@ -60,7 +60,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
}

/// post-decrement (it--)
json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type)
json_reverse_iterator operator--(int)
{
return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
}
Expand Down
4 changes: 2 additions & 2 deletions include/nlohmann/detail/iterators/primitive_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class primitive_iterator_t
return *this;
}

primitive_iterator_t const operator++(int) noexcept // NOLINT(readability-const-return-type)
primitive_iterator_t operator++(int) noexcept
{
auto result = *this;
++m_it;
Expand All @@ -100,7 +100,7 @@ class primitive_iterator_t
return *this;
}

primitive_iterator_t const operator--(int) noexcept // NOLINT(readability-const-return-type)
primitive_iterator_t operator--(int) noexcept
{
auto result = *this;
--m_it;
Expand Down
12 changes: 6 additions & 6 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11308,7 +11308,7 @@ class primitive_iterator_t
return *this;
}

primitive_iterator_t const operator++(int) noexcept // NOLINT(readability-const-return-type)
primitive_iterator_t operator++(int) noexcept
{
auto result = *this;
++m_it;
Expand All @@ -11321,7 +11321,7 @@ class primitive_iterator_t
return *this;
}

primitive_iterator_t const operator--(int) noexcept // NOLINT(readability-const-return-type)
primitive_iterator_t operator--(int) noexcept
{
auto result = *this;
--m_it;
Expand Down Expand Up @@ -11728,7 +11728,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
@brief post-increment (it++)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl const operator++(int) // NOLINT(readability-const-return-type)
iter_impl operator++(int)
{
auto result = *this;
++(*this);
Expand Down Expand Up @@ -11779,7 +11779,7 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
@brief post-decrement (it--)
@pre The iterator is initialized; i.e. `m_object != nullptr`.
*/
iter_impl const operator--(int) // NOLINT(readability-const-return-type)
iter_impl operator--(int)
{
auto result = *this;
--(*this);
Expand Down Expand Up @@ -12167,7 +12167,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}

/// post-increment (it++)
json_reverse_iterator const operator++(int) // NOLINT(readability-const-return-type)
json_reverse_iterator operator++(int)
{
return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
}
Expand All @@ -12179,7 +12179,7 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
}

/// post-decrement (it--)
json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type)
json_reverse_iterator operator--(int)
{
return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
}
Expand Down

0 comments on commit 3253893

Please sign in to comment.