From 3d3f169a63a6545be1774ae71fcf2f8ebf290481 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 14 Aug 2018 22:26:39 -0700 Subject: [PATCH] MSVC's STL doesn't let iterators go before begin() (#98) * MSVC's STL doesn't let iterators go before begin() This is the case even of the iterator is not dereferenced. Fix #94. * cleanup --- libs/utils/include/utils/RangeSet.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libs/utils/include/utils/RangeSet.h b/libs/utils/include/utils/RangeSet.h index a21e6b290f..5d0ff093e1 100644 --- a/libs/utils/include/utils/RangeSet.h +++ b/libs/utils/include/utils/RangeSet.h @@ -47,16 +47,16 @@ public: Slice getRanges() const { return { mStorage.cbegin(), mStorage.cend() }; } - BufferRange const* begin() const noexcept { return &*mStorage.begin(); } - BufferRange const* end() const noexcept { return &*mStorage.end(); } - BufferRange const* cbegin() const noexcept { return &*mStorage.cbegin(); } - BufferRange const* cend() const noexcept { return &*mStorage.cend(); } + BufferRange const* begin() const noexcept { return mStorage.data(); } + BufferRange const* end() const noexcept { return mStorage.data() + mStorage.size(); } + BufferRange const* cbegin() const noexcept { return mStorage.data(); } + BufferRange const* cend() const noexcept { return mStorage.data() + mStorage.size(); } BufferRange const& operator[](size_t i) const noexcept { return mStorage[i]; } private: // Fixed capacity vector - template ::value >::type> + template::value>::type> class vector { std::array mElements; uint32_t mSize = 0; @@ -68,6 +68,8 @@ private: bool empty() const noexcept { return size() == 0; } size_t size() const noexcept { return mSize; } size_t capacity() const noexcept { return CAPACITY; } + value_type *data() { return mElements.data(); } + value_type const *data() const { return mElements.data(); } iterator begin() { return mElements.begin(); } iterator end() { return begin() + mSize; } const_iterator begin() const { return mElements.begin(); } @@ -86,7 +88,8 @@ private: assert(mSize < CAPACITY); // equivalent to std::move_backward(pos, end(), end() + 1) but we don't want a call to memmove iterator e = end(); - while (pos != e--) { + while (pos != e) { + --e; e[1] = e[0]; } *pos = value;