0001-Avoid-inheritance-from-std-iterator.patch 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. From d75bb90a5dd8c5946ce7496748d1cea842aabc0f Mon Sep 17 00:00:00 2001
  2. From: "Philipp A. Hartmann" <pah@qo.cx>
  3. Date: Tue, 12 Dec 2017 21:16:07 +0100
  4. Subject: [PATCH] Avoid inheritance from std::iterator
  5. Instead of inheriting from the deprecated std::iterator
  6. template, define the member typedefs needed for
  7. std::iterator_traits directly.
  8. Closes #1131.
  9. ---
  10. include/rapidjson/document.h | 22 ++++++++++++++--------
  11. 1 file changed, 14 insertions(+), 8 deletions(-)
  12. diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h
  13. index 094a07e8..eb6d7dcb 100644
  14. --- a/include/rapidjson/document.h
  15. +++ b/include/rapidjson/document.h
  16. @@ -45,7 +45,7 @@ RAPIDJSON_DIAG_OFF(terminate) // ignore throwing RAPIDJSON_ASSERT in RAPIDJSON_N
  17. #endif // __GNUC__
  18. #ifndef RAPIDJSON_NOMEMBERITERATORCLASS
  19. -#include <iterator> // std::iterator, std::random_access_iterator_tag
  20. +#include <iterator> // std::random_access_iterator_tag
  21. #endif
  22. #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
  23. @@ -98,16 +98,13 @@ struct GenericMember {
  24. \see GenericMember, GenericValue::MemberIterator, GenericValue::ConstMemberIterator
  25. */
  26. template <bool Const, typename Encoding, typename Allocator>
  27. -class GenericMemberIterator
  28. - : public std::iterator<std::random_access_iterator_tag
  29. - , typename internal::MaybeAddConst<Const,GenericMember<Encoding,Allocator> >::Type> {
  30. +class GenericMemberIterator {
  31. friend class GenericValue<Encoding,Allocator>;
  32. template <bool, typename, typename> friend class GenericMemberIterator;
  33. typedef GenericMember<Encoding,Allocator> PlainType;
  34. typedef typename internal::MaybeAddConst<Const,PlainType>::Type ValueType;
  35. - typedef std::iterator<std::random_access_iterator_tag,ValueType> BaseType;
  36. public:
  37. //! Iterator type itself
  38. @@ -117,12 +114,21 @@ public:
  39. //! Non-constant iterator type
  40. typedef GenericMemberIterator<false,Encoding,Allocator> NonConstIterator;
  41. + /** \name std::iterator_traits support */
  42. + //@{
  43. + typedef ValueType value_type;
  44. + typedef ValueType * pointer;
  45. + typedef ValueType & reference;
  46. + typedef std::ptrdiff_t difference_type;
  47. + typedef std::random_access_iterator_tag iterator_category;
  48. + //@}
  49. +
  50. //! Pointer to (const) GenericMember
  51. - typedef typename BaseType::pointer Pointer;
  52. + typedef pointer Pointer;
  53. //! Reference to (const) GenericMember
  54. - typedef typename BaseType::reference Reference;
  55. + typedef reference Reference;
  56. //! Signed integer type (e.g. \c ptrdiff_t)
  57. - typedef typename BaseType::difference_type DifferenceType;
  58. + typedef difference_type DifferenceType;
  59. //! Default constructor (singular value)
  60. /*! Creates an iterator pointing to no element.
  61. --
  62. 2.42.0