From 86b505e412825b318669443372a5a1495a03c774 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 7 Jun 2017 16:26:06 -0700 Subject: [PATCH] [C++] Remove std::iterator usage (#4340) (#4341) * [C++] Remove std::iterator usage (#4340) Inheriting from std::iterator has never been required, and it's deprecated in C++17. It can be replaced by directly providing typedefs. Include for std::random_access_iterator_tag. Note that structs default to public access control. * [C++] Change whitespace style in typedefs. --- include/flatbuffers/base.h | 1 + include/flatbuffers/flatbuffers.h | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/flatbuffers/base.h b/include/flatbuffers/base.h index 04afd5a42..68d327f86 100644 --- a/include/flatbuffers/base.h +++ b/include/flatbuffers/base.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #ifdef _STLPORT_VERSION diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index 963f29637..b94846686 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -118,12 +118,13 @@ template struct IndirectHelper { // An STL compatible iterator implementation for Vector below, effectively // calling Get() for every element. template -struct VectorIterator - : public std::iterator { +struct VectorIterator { + typedef std::random_access_iterator_tag iterator_category; + typedef IT value_type; + typedef uoffset_t difference_type; + typedef IT *pointer; + typedef IT &reference; - typedef std::iterator super_type; - -public: VectorIterator(const uint8_t *data, uoffset_t i) : data_(data + IndirectHelper::element_stride * i) {} VectorIterator(const VectorIterator &other) : data_(other.data_) {} @@ -154,11 +155,11 @@ public: return (data_ - other.data_) / IndirectHelper::element_stride; } - typename super_type::value_type operator *() const { + IT operator *() const { return IndirectHelper::Read(data_, 0); } - typename super_type::value_type operator->() const { + IT operator->() const { return IndirectHelper::Read(data_, 0); }