From b621bfcef0b64511d01282fbf8dcc33134d9b48d Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 28 May 2023 17:04:44 +0200 Subject: [PATCH] Define SharedIterator as proper random access iterator Drop Container template argument as it's always std::vector. --- apps/openmw/mwworld/store.hpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwworld/store.hpp b/apps/openmw/mwworld/store.hpp index 238c5cbd5f..25cac68c55 100644 --- a/apps/openmw/mwworld/store.hpp +++ b/apps/openmw/mwworld/store.hpp @@ -115,20 +115,20 @@ namespace MWWorld const T* find(int index) const; }; - template > + template class SharedIterator { - typedef typename Container::const_iterator Iter; - - Iter mIter; - public: - SharedIterator() {} + using Iter = typename std::vector::const_iterator; + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = std::ptrdiff_t; + using pointer = T*; + using reference = T&; - SharedIterator(const SharedIterator& orig) - : mIter(orig.mIter) - { - } + SharedIterator() = default; + + SharedIterator(const SharedIterator& other) = default; SharedIterator(const Iter& iter) : mIter(iter) @@ -151,7 +151,7 @@ namespace MWWorld return iter; } - SharedIterator& operator+=(int advance) + SharedIterator& operator+=(difference_type advance) { mIter += advance; return *this; @@ -178,6 +178,14 @@ namespace MWWorld const T& operator*() const { return **mIter; } const T* operator->() const { return &(**mIter); } + + private: + Iter mIter; + + friend inline difference_type operator-(const SharedIterator& lhs, const SharedIterator& rhs) + { + return lhs.mIter - rhs.mIter; + } }; class ESMStore;