diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2018-07-29 21:45:13 -0700 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2018-07-29 21:45:13 -0700 |
commit | 06c99e6c91d87a91f3e54191670d23e3f4d132b9 (patch) | |
tree | a2c82149d6fe802c68365f73e11f3c241c95ef3d /zen/ring_buffer.h | |
parent | 10.1 (diff) | |
download | FreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.tar.gz FreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.tar.bz2 FreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.zip |
10.2
Diffstat (limited to 'zen/ring_buffer.h')
-rwxr-xr-x | zen/ring_buffer.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/zen/ring_buffer.h b/zen/ring_buffer.h index 1a67c452..6debd84e 100755 --- a/zen/ring_buffer.h +++ b/zen/ring_buffer.h @@ -163,16 +163,26 @@ public: class Iterator { public: + using iterator_category = std::random_access_iterator_tag; + using value_type = Value; + using difference_type = ptrdiff_t; + using pointer = Value*; + using reference = Value&; + Iterator(Container& container, size_t offset) : container_(&container), offset_(offset) {} Iterator& operator++() { ++offset_; return *this; } + Iterator& operator+=(ptrdiff_t offset) { offset_ += offset; } inline friend bool operator==(const Iterator& lhs, const Iterator& rhs) { assert(lhs.container_ == rhs.container_); return lhs.offset_ == rhs.offset_; } inline friend bool operator!=(const Iterator& lhs, const Iterator& rhs) { return !(lhs == rhs); } + inline friend ptrdiff_t operator-(const Iterator& lhs, const Iterator& rhs) { return lhs.offset_ - rhs.offset_; } + inline friend Iterator operator+(const Iterator& lhs, ptrdiff_t offset) { Iterator tmp(lhs); return tmp += offset; } Value& operator* () const { return (*container_)[offset_]; } Value* operator->() const { return &(*container_)[offset_]; } private: Container* container_ = nullptr; - size_t offset_ = 0; + ptrdiff_t offset_ = 0; }; + using iterator = Iterator< RingBuffer, T>; using const_iterator = Iterator<const RingBuffer, const T>; |