| 131 | // An STL compatible iterator implementation for Vector below, effectively |
| 132 | // calling Get() for every element. |
| 133 | template<typename T, typename IT> struct VectorIterator { |
| 134 | typedef std::random_access_iterator_tag iterator_category; |
| 135 | typedef IT value_type; |
| 136 | typedef ptrdiff_t difference_type; |
| 137 | typedef IT *pointer; |
| 138 | typedef IT &reference; |
| 139 | |
| 140 | VectorIterator(const uint8_t *data, uoffset_t i) |
| 141 | : data_(data + IndirectHelper<T>::element_stride * i) {} |
| 142 | VectorIterator(const VectorIterator &other) : data_(other.data_) {} |
| 143 | VectorIterator() : data_(nullptr) {} |
| 144 | |
| 145 | VectorIterator &operator=(const VectorIterator &other) { |
| 146 | data_ = other.data_; |
| 147 | return *this; |
| 148 | } |
| 149 | |
| 150 | // clang-format off |
| 151 | #if !defined(FLATBUFFERS_CPP98_STL) |
| 152 | VectorIterator &operator=(VectorIterator &&other) { |
| 153 | data_ = other.data_; |
| 154 | return *this; |
| 155 | } |
| 156 | #endif // !defined(FLATBUFFERS_CPP98_STL) |
| 157 | // clang-format on |
| 158 | |
| 159 | bool operator==(const VectorIterator &other) const { |
| 160 | return data_ == other.data_; |
| 161 | } |
| 162 | |
| 163 | bool operator<(const VectorIterator &other) const { |
| 164 | return data_ < other.data_; |
| 165 | } |
| 166 | |
| 167 | bool operator!=(const VectorIterator &other) const { |
| 168 | return data_ != other.data_; |
| 169 | } |
| 170 | |
| 171 | difference_type operator-(const VectorIterator &other) const { |
| 172 | return (data_ - other.data_) / IndirectHelper<T>::element_stride; |
| 173 | } |
| 174 | |
| 175 | // Note: return type is incompatible with the standard |
| 176 | // `reference operator*()`. |
| 177 | IT operator*() const { return IndirectHelper<T>::Read(data_, 0); } |
| 178 | |
| 179 | // Note: return type is incompatible with the standard |
| 180 | // `pointer operator->()`. |
| 181 | IT operator->() const { return IndirectHelper<T>::Read(data_, 0); } |
| 182 | |
| 183 | VectorIterator &operator++() { |
| 184 | data_ += IndirectHelper<T>::element_stride; |
| 185 | return *this; |
| 186 | } |
| 187 | |
| 188 | VectorIterator operator++(int) { |
| 189 | VectorIterator temp(data_, 0); |
| 190 | data_ += IndirectHelper<T>::element_stride; |