mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-29 02:00:01 +00:00
random access iterator for vector added (#4119)
* random access iterator for vector added * Style changes
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
d1e8899310
commit
ab76c57ec8
@@ -252,9 +252,9 @@ template<typename T> struct IndirectHelper<const T *> {
|
|||||||
// calling Get() for every element.
|
// calling Get() for every element.
|
||||||
template<typename T, typename IT>
|
template<typename T, typename IT>
|
||||||
struct VectorIterator
|
struct VectorIterator
|
||||||
: public std::iterator<std::input_iterator_tag, IT, uoffset_t> {
|
: public std::iterator<std::random_access_iterator_tag, IT, uoffset_t> {
|
||||||
|
|
||||||
typedef std::iterator<std::input_iterator_tag, IT, uoffset_t> super_type;
|
typedef std::iterator<std::random_access_iterator_tag, IT, uoffset_t> super_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VectorIterator(const uint8_t *data, uoffset_t i) :
|
VectorIterator(const uint8_t *data, uoffset_t i) :
|
||||||
@@ -274,15 +274,15 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const VectorIterator& other) const {
|
bool operator==(const VectorIterator &other) const {
|
||||||
return data_ == other.data_;
|
return data_ == other.data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const VectorIterator& other) const {
|
bool operator!=(const VectorIterator &other) const {
|
||||||
return data_ != other.data_;
|
return data_ != other.data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
ptrdiff_t operator-(const VectorIterator& other) const {
|
ptrdiff_t operator-(const VectorIterator &other) const {
|
||||||
return (data_ - other.data_) / IndirectHelper<T>::element_stride;
|
return (data_ - other.data_) / IndirectHelper<T>::element_stride;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,11 +300,40 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
VectorIterator operator++(int) {
|
VectorIterator operator++(int) {
|
||||||
VectorIterator temp(data_,0);
|
VectorIterator temp(data_, 0);
|
||||||
data_ += IndirectHelper<T>::element_stride;
|
data_ += IndirectHelper<T>::element_stride;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VectorIterator operator+(const uoffset_t &offset) {
|
||||||
|
return VectorIterator(data_ + offset * IndirectHelper<T>::element_stride, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorIterator& operator+=(const uoffset_t &offset) {
|
||||||
|
data_ += offset * IndirectHelper<T>::element_stride;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorIterator &operator--() {
|
||||||
|
data_ -= IndirectHelper<T>::element_stride;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorIterator operator--(int) {
|
||||||
|
VectorIterator temp(data_, 0);
|
||||||
|
data_ -= IndirectHelper<T>::element_stride;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorIterator operator-(const uoffset_t &offset) {
|
||||||
|
return VectorIterator(data_ - offset * IndirectHelper<T>::element_stride, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
VectorIterator& operator-=(const uoffset_t &offset) {
|
||||||
|
data_ -= offset * IndirectHelper<T>::element_stride;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t *data_;
|
const uint8_t *data_;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user