mirror of
https://github.com/nlohmann/json.git
synced 2024-08-21 20:42:29 +02:00
* ⚗️ move CI targets to CMake * ♻️ add target for cpplint * ♻️ add target for self-contained binaries * ♻️ add targets for iwyu and infer * 🔊 add version output * ♻️ add target for oclint * 🚨 fix warnings * ♻️ rename targets * ♻️ use iwyu properly * 🚨 fix warnings * ♻️ use iwyu properly * ♻️ add target for benchmarks * ♻️ add target for CMake flags * 👷 use GitHub Actions * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ try to install Clang 11 * ⚗️ try to install GCC 11 * ⚗️ add clang analyze target * 🔥 remove Google Benchmark * ⬆️ Google Benchmark 1.5.2 * 🔥 use fetchcontent * 🐧 add target to download a Linux version of CMake * 🔨 fix dependency * 🚨 fix includes * 🚨 fix comment * 🔧 adjust flags for GCC 11.0.0 20210110 (experimental) * 🐳 user Docker image to run CI * 🔧 add target for Valgrind * 👷 add target for Valgrind tests * ⚗️ add Dart * ⏪ remove Dart * ⚗️ do not call ctest in test subdirectory * ⚗️ download test data explicitly * ⚗️ only execute Valgrind tests * ⚗️ fix labels * 🔥 remove unneeded jobs * 🔨 cleanup * 🐛 fix OCLint call * ✅ add targets for offline and git-independent tests * ✅ add targets for C++ language versions and reproducible tests * 🔨 clean up * 👷 add CI steps for cppcheck and cpplint * 🚨 fix warnings from Clang-Tidy * 👷 add CI steps for Clang-Tidy * 🚨 fix warnings * 🔧 select proper binary * 🚨 fix warnings * 🚨 suppress some unhelpful warnings * 🚨 fix warnings * 🎨 fix format * 🚨 fix warnings * 👷 add CI steps for Sanitizers * 🚨 fix warnings * ⚡ add optimization to sanitizer build * 🚨 fix warnings * 🚨 add missing header * 🚨 fix warnings * 👷 add CI step for coverage * 👷 add CI steps for disabled exceptions and implicit conversions * 🚨 fix warnings * 👷 add CI steps for checking indentation * 🐛 fix variable use * 💚 fix build * ➖ remove CircleCI * 👷 add CI step for diagnostics * 🚨 fix warning * 🔥 clean Travis
120 lines
3.5 KiB
C++
120 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <cstddef> // ptrdiff_t
|
|
#include <iterator> // reverse_iterator
|
|
#include <utility> // declval
|
|
|
|
namespace nlohmann
|
|
{
|
|
namespace detail
|
|
{
|
|
//////////////////////
|
|
// reverse_iterator //
|
|
//////////////////////
|
|
|
|
/*!
|
|
@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:
|
|
-
|
|
[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator):
|
|
The iterator that can be moved can be moved in both directions (i.e.
|
|
incremented and decremented).
|
|
- [OutputIterator](https://en.cppreference.com/w/cpp/named_req/OutputIterator):
|
|
It is possible to write to the pointed-to element (only if @a Base is
|
|
@ref iterator).
|
|
|
|
@since version 1.0.0
|
|
*/
|
|
template<typename Base>
|
|
class json_reverse_iterator : public std::reverse_iterator<Base>
|
|
{
|
|
public:
|
|
using difference_type = std::ptrdiff_t;
|
|
/// shortcut to the reverse iterator adapter
|
|
using base_iterator = std::reverse_iterator<Base>;
|
|
/// the reference type for the pointed-to element
|
|
using reference = typename Base::reference;
|
|
|
|
/// create reverse iterator from iterator
|
|
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
|
|
: base_iterator(it) {}
|
|
|
|
/// create reverse iterator from base class
|
|
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)
|
|
{
|
|
return static_cast<json_reverse_iterator>(base_iterator::operator++(1));
|
|
}
|
|
|
|
/// pre-increment (++it)
|
|
json_reverse_iterator& operator++()
|
|
{
|
|
return static_cast<json_reverse_iterator&>(base_iterator::operator++());
|
|
}
|
|
|
|
/// post-decrement (it--)
|
|
json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type)
|
|
{
|
|
return static_cast<json_reverse_iterator>(base_iterator::operator--(1));
|
|
}
|
|
|
|
/// pre-decrement (--it)
|
|
json_reverse_iterator& operator--()
|
|
{
|
|
return static_cast<json_reverse_iterator&>(base_iterator::operator--());
|
|
}
|
|
|
|
/// add to iterator
|
|
json_reverse_iterator& operator+=(difference_type i)
|
|
{
|
|
return static_cast<json_reverse_iterator&>(base_iterator::operator+=(i));
|
|
}
|
|
|
|
/// add to iterator
|
|
json_reverse_iterator operator+(difference_type i) const
|
|
{
|
|
return static_cast<json_reverse_iterator>(base_iterator::operator+(i));
|
|
}
|
|
|
|
/// subtract from iterator
|
|
json_reverse_iterator operator-(difference_type i) const
|
|
{
|
|
return static_cast<json_reverse_iterator>(base_iterator::operator-(i));
|
|
}
|
|
|
|
/// return difference
|
|
difference_type operator-(const json_reverse_iterator& other) const
|
|
{
|
|
return base_iterator(*this) - base_iterator(other);
|
|
}
|
|
|
|
/// access to successor
|
|
reference operator[](difference_type n) const
|
|
{
|
|
return *(this->operator+(n));
|
|
}
|
|
|
|
/// return the key of an object iterator
|
|
auto key() const -> decltype(std::declval<Base>().key())
|
|
{
|
|
auto it = --this->base();
|
|
return it.key();
|
|
}
|
|
|
|
/// return the value of an iterator
|
|
reference value() const
|
|
{
|
|
auto it = --this->base();
|
|
return it.operator * ();
|
|
}
|
|
};
|
|
} // namespace detail
|
|
} // namespace nlohmann
|