Skip to content

Commit d75bb90

Browse files
committed
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.
1 parent 7caa4b2 commit d75bb90

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

include/rapidjson/document.h

+14-8
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_N
4545
#endif // __GNUC__
4646

4747
#ifndef RAPIDJSON_NOMEMBERITERATORCLASS
48-
#include <iterator> // std::iterator, std::random_access_iterator_tag
48+
#include <iterator> // std::random_access_iterator_tag
4949
#endif
5050

5151
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
@@ -98,16 +98,13 @@ struct GenericMember {
9898
\see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator
9999
*/
100100
template <bool Const, typename Encoding, typename Allocator>
101-
class GenericMemberIterator
102-
: public std::iterator<std::random_access_iterator_tag
103-
, typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
101+
class GenericMemberIterator {
104102

105103
friend class GenericValue<Encoding,Allocator>;
106104
template <bool, typename, typename> friend class GenericMemberIterator;
107105

108106
typedef GenericMember<Encoding,Allocator> PlainType;
109107
typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
110-
typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
111108

112109
public:
113110
//! Iterator type itself
@@ -117,12 +114,21 @@ class GenericMemberIterator
117114
//! Non-constant iterator type
118115
typedef GenericMemberIterator<false,Encoding,Allocator> NonConstIterator;
119116

117+
/** \name std::iterator_traits support */
118+
//@{
119+
typedef ValueType value_type;
120+
typedef ValueType * pointer;
121+
typedef ValueType & reference;
122+
typedef std::ptrdiff_t difference_type;
123+
typedef std::random_access_iterator_tag iterator_category;
124+
//@}
125+
120126
//! Pointer to (const) GenericMember
121-
typedef typename BaseType::pointer Pointer;
127+
typedef pointer Pointer;
122128
//! Reference to (const) GenericMember
123-
typedef typename BaseType::reference Reference;
129+
typedef reference Reference;
124130
//! Signed integer type (e.g. \c ptrdiff_t)
125-
typedef typename BaseType::difference_type DifferenceType;
131+
typedef difference_type DifferenceType;
126132

127133
//! Default constructor (singular value)
128134
/*! Creates an iterator pointing to no element.

0 commit comments

Comments
 (0)