diff options
author | Treeston <treeston.mmoc@gmail.com> | 2018-12-25 12:36:20 +0100 |
---|---|---|
committer | Treeston <treeston.mmoc@gmail.com> | 2018-12-25 12:36:20 +0100 |
commit | 4c3af3b636d5e9279fb694c9d9a5a4422ad773d0 (patch) | |
tree | 94f3cd420a8b511554f8aa134d78ec624afcf888 /src/common/Utilities/Containers.h | |
parent | 6d6077e36fe9c5cb8ea8e4f981d637e72ee87037 (diff) |
Core/Utils: some code style adjustments, 6d6077e follow-up
Diffstat (limited to 'src/common/Utilities/Containers.h')
-rw-r--r-- | src/common/Utilities/Containers.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/common/Utilities/Containers.h b/src/common/Utilities/Containers.h index 212dc3994f2..c870713bbc4 100644 --- a/src/common/Utilities/Containers.h +++ b/src/common/Utilities/Containers.h @@ -41,7 +41,7 @@ namespace Trinity } template <class T> - class BufferWriteGuard + class CheckedBufferOutputIterator { public: using iterator_category = std::output_iterator_tag; @@ -50,20 +50,20 @@ namespace Trinity using reference = T&; using difference_type = std::ptrdiff_t; - BufferWriteGuard(T* buf, size_t n) : _buf(buf), _n(n) {} + CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf+n) {} T& operator*() const { check(); return *_buf; } - BufferWriteGuard& operator++() { check(); ++_buf; --_n; return *this; } - T* operator++(int) { check(); T* b = _buf; ++_buf; --_n; return b; } + CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; } + CheckedBufferOutputIterator operator++(int) { CheckedBufferOutputIterator v = *this; operator++(); return v; } - size_t size() const { return _n; } + size_t remaining() const { return (_end - _buf); } private: T* _buf; - size_t _n; - void check() + T* _end; + void check() const { - if (!_n) + if (!(_buf < _end)) throw std::out_of_range("index"); } }; |