summaryrefslogtreecommitdiff
path: root/zen/ring_buffer.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2018-07-29 21:45:13 -0700
committerDaniel Wilhelm <shieldwed@outlook.com>2018-07-29 21:45:13 -0700
commit06c99e6c91d87a91f3e54191670d23e3f4d132b9 (patch)
treea2c82149d6fe802c68365f73e11f3c241c95ef3d /zen/ring_buffer.h
parent10.1 (diff)
downloadFreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.tar.gz
FreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.tar.bz2
FreeFileSync-06c99e6c91d87a91f3e54191670d23e3f4d132b9.zip
10.2
Diffstat (limited to 'zen/ring_buffer.h')
-rwxr-xr-xzen/ring_buffer.h12
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>;
bgstack15