Commit d75bb90a authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

Avoid inheritance from std::iterator

Instead of inheriting from the deprecated std::iterator
template, define the member typedefs needed for
std::iterator_traits directly.

Closes #1131.
parent 7caa4b21
...@@ -45,7 +45,7 @@ RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_N ...@@ -45,7 +45,7 @@ RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_N
#endif // __GNUC__ #endif // __GNUC__
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
#include <iterator> // std::iterator, std::random_access_iterator_tag #include <iterator> // std::random_access_iterator_tag
#endif #endif
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
...@@ -98,16 +98,13 @@ struct GenericMember { ...@@ -98,16 +98,13 @@ struct GenericMember {
\see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator \see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator
*/ */
template <bool Const, typename Encoding, typename Allocator> template <bool Const, typename Encoding, typename Allocator>
class GenericMemberIterator class GenericMemberIterator {
: public std::iterator<std::random_access_iterator_tag
, typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
friend class GenericValue<Encoding,Allocator>; friend class GenericValue<Encoding,Allocator>;
template <bool, typename, typename> friend class GenericMemberIterator; template <bool, typename, typename> friend class GenericMemberIterator;
typedef GenericMember<Encoding,Allocator> PlainType; typedef GenericMember<Encoding,Allocator> PlainType;
typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType; typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
public: public:
//! Iterator type itself //! Iterator type itself
...@@ -117,12 +114,21 @@ public: ...@@ -117,12 +114,21 @@ public:
//! Non-constant iterator type //! Non-constant iterator type
typedef GenericMemberIterator<false,Encoding,Allocator> NonConstIterator; typedef GenericMemberIterator<false,Encoding,Allocator> NonConstIterator;
/** \name std::iterator_traits support */
//@{
typedef ValueType value_type;
typedef ValueType * pointer;
typedef ValueType & reference;
typedef std::ptrdiff_t difference_type;
typedef std::random_access_iterator_tag iterator_category;
//@}
//! Pointer to (const) GenericMember //! Pointer to (const) GenericMember
typedef typename BaseType::pointer Pointer; typedef pointer Pointer;
//! Reference to (const) GenericMember //! Reference to (const) GenericMember
typedef typename BaseType::reference Reference; typedef reference Reference;
//! Signed integer type (e.g. \c ptrdiff_t) //! Signed integer type (e.g. \c ptrdiff_t)
typedef typename BaseType::difference_type DifferenceType; typedef difference_type DifferenceType;
//! Default constructor (singular value) //! Default constructor (singular value)
/*! Creates an iterator pointing to no element. /*! Creates an iterator pointing to no element.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment