From c079eabfdf1c972d8da90c5a59f1646d9cb8806a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Mon, 7 Feb 2022 11:27:34 -0600 Subject: [PATCH] a/util: iterator cleanups to reduce diffs, using a self typedef. --- .../u_template_historybuf_const_iterator.inl | 28 ++++++++-------- .../util/u_template_historybuf_iterator.inl | 32 ++++++++++--------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/xrt/auxiliary/util/u_template_historybuf_const_iterator.inl b/src/xrt/auxiliary/util/u_template_historybuf_const_iterator.inl index cef7d992d..67b770e14 100644 --- a/src/xrt/auxiliary/util/u_template_historybuf_const_iterator.inl +++ b/src/xrt/auxiliary/util/u_template_historybuf_const_iterator.inl @@ -29,6 +29,7 @@ namespace detail { friend class HistoryBufIterator; public: + using Self = HistoryBufConstIterator; using container_type = const HistoryBuffer; using typename base::difference_type; using typename base::iterator_category; @@ -79,50 +80,50 @@ namespace detail { operator->() const noexcept; //! Pre-increment: Advance, then return self. - HistoryBufConstIterator & + Self & operator++(); //! Post-increment: return a copy of initial state after incrementing self - HistoryBufConstIterator + Self operator++(int); //! Pre-decrement: Subtract, then return self. - HistoryBufConstIterator & + Self & operator--(); //! Post-decrement: return a copy of initial state after decrementing self - HistoryBufConstIterator + Self operator--(int); // Use the base class implementation of subtracting one iterator from another using base::operator-; //! Increment by an arbitrary amount. - HistoryBufConstIterator & + Self & operator+=(std::ptrdiff_t n) noexcept; //! Decrement by an arbitrary amount. - HistoryBufConstIterator & + Self & operator-=(std::ptrdiff_t n) noexcept; //! Increment a copy of the iterator by an arbitrary amount. - HistoryBufConstIterator + Self operator+(std::ptrdiff_t n) const noexcept; //! Decrement a copy of the iterator by an arbitrary amount. - HistoryBufConstIterator + Self operator-(std::ptrdiff_t n) const noexcept; private: //! Factory for a "begin" iterator from a container and its helper: mostly for internal use. - static HistoryBufConstIterator + static Self begin(container_type &container, const RingBufferHelper &helper) { return {&container, std::move(base::begin(helper))}; } //! Construct the "past the end" iterator that can be decremented safely - static HistoryBufConstIterator + static Self end(container_type &container, const RingBufferHelper &helper) { return {&container, std::move(base::end(helper))}; @@ -182,7 +183,7 @@ namespace detail { inline HistoryBufConstIterator HistoryBufConstIterator::operator--(int) { - HistoryBufConstIterator tmp = *this; + Self tmp = *this; this->decrement_n(1); return tmp; } @@ -207,7 +208,7 @@ namespace detail { inline HistoryBufConstIterator HistoryBufConstIterator::operator+(std::ptrdiff_t n) const noexcept { - HistoryBufConstIterator ret(*this); + Self ret(*this); ret += n; return ret; } @@ -216,12 +217,13 @@ namespace detail { inline HistoryBufConstIterator HistoryBufConstIterator::operator-(std::ptrdiff_t n) const noexcept { - HistoryBufConstIterator ret(*this); + Self ret(*this); ret -= n; return ret; } } // namespace detail +// HistoryBuffer method implementations that depend on const_iterator availability template inline typename HistoryBuffer::const_iterator diff --git a/src/xrt/auxiliary/util/u_template_historybuf_iterator.inl b/src/xrt/auxiliary/util/u_template_historybuf_iterator.inl index a4737463a..73f3ca2a5 100644 --- a/src/xrt/auxiliary/util/u_template_historybuf_iterator.inl +++ b/src/xrt/auxiliary/util/u_template_historybuf_iterator.inl @@ -28,6 +28,7 @@ namespace detail { friend class HistoryBuffer; public: + using Self = HistoryBufIterator; using container_type = HistoryBuffer; using typename base::difference_type; using typename base::iterator_category; @@ -75,53 +76,53 @@ namespace detail { operator->() const noexcept; //! Pre-increment: Advance, then return self. - HistoryBufIterator & + Self & operator++(); //! Post-increment: return a copy of initial state after incrementing self - HistoryBufIterator + Self operator++(int); //! Pre-decrement: Subtract, then return self. - HistoryBufIterator & + Self & operator--(); //! Post-decrement: return a copy of initial state after decrementing self - HistoryBufIterator + Self operator--(int); // Use the base class implementation of subtracting one iterator from another using base::operator-; //! Increment by an arbitrary amount. - HistoryBufIterator & + Self & operator+=(std::ptrdiff_t n) noexcept; //! Decrement by an arbitrary amount. - HistoryBufIterator & + Self & operator-=(std::ptrdiff_t n) noexcept; //! Increment a copy of the iterator by an arbitrary amount. - HistoryBufIterator + Self operator+(std::ptrdiff_t n) const noexcept; //! Decrement a copy of the iterator by an arbitrary amount. - HistoryBufIterator + Self operator-(std::ptrdiff_t n) const noexcept; private: //! Factory for a "begin" iterator from a container and its helper: mostly for internal use. - static HistoryBufIterator + static Self begin(container_type &container, const RingBufferHelper &helper) { - return HistoryBufIterator{&container, std::move(base::begin(helper))}; + return {&container, std::move(base::begin(helper))}; } //! Construct the "past the end" iterator that can be decremented safely - static HistoryBufIterator + static Self end(container_type &container, const RingBufferHelper &helper) { - return HistoryBufIterator{&container, std::move(base::end(helper))}; + return {&container, std::move(base::end(helper))}; } // for use internally @@ -178,7 +179,7 @@ namespace detail { inline HistoryBufIterator HistoryBufIterator::operator--(int) { - HistoryBufIterator tmp = *this; + Self tmp = *this; this->decrement_n(1); return tmp; } @@ -203,7 +204,7 @@ namespace detail { inline HistoryBufIterator HistoryBufIterator::operator+(std::ptrdiff_t n) const noexcept { - HistoryBufIterator ret(*this); + Self ret(*this); ret += n; return ret; } @@ -212,7 +213,7 @@ namespace detail { inline HistoryBufIterator HistoryBufIterator::operator-(std::ptrdiff_t n) const noexcept { - HistoryBufIterator ret(*this); + Self ret(*this); ret -= n; return ret; } @@ -224,6 +225,7 @@ namespace detail { {} } // namespace detail +// HistoryBuffer method implementations that depend on iterator availability template inline typename HistoryBuffer::iterator