From e2f9d0e2bcacdedc6669b4e5cbeaac7692910091 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 16 Sep 2022 21:45:27 -0400 Subject: Remove unnecessary inheritance --- .clang-tidy | 1 - include/chilbert/SmallBitVec.hpp | 19 ++++++++++--------- include/chilbert/detail/BitVecIterator.hpp | 21 +++++++++++---------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b8924f8..191e6cf 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,7 +11,6 @@ Checks: > -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, - -cppcoreguidelines-slicing, -fuchsia-default-arguments-calls, -fuchsia-default-arguments-declarations, -fuchsia-overloaded-operator, diff --git a/include/chilbert/SmallBitVec.hpp b/include/chilbert/SmallBitVec.hpp index 485ca9e..bd54855 100644 --- a/include/chilbert/SmallBitVec.hpp +++ b/include/chilbert/SmallBitVec.hpp @@ -247,44 +247,45 @@ public: size_t num_racks() const { return 1; } template - class iterator_base : public Mask + class iterator_base { public: iterator_base& operator++() { - Mask::operator++(); + ++m_mask; return *this; } iterator_base& operator--() { - Mask::operator--(); + --m_mask; return *this; } bool operator==(const iterator_base& rhs) const { - return m_vec == rhs.m_vec && Mask::operator==(rhs); + return m_vec == rhs.m_vec && m_mask == rhs.m_mask; } bool operator!=(const iterator_base& rhs) const { return !operator==(rhs); } - bool operator*() const { return m_vec->test(*this); } + bool operator*() const { return m_vec->test(m_mask); } protected: iterator_base(BitVec& vec, const size_t index) - : Mask{index} - , m_vec{&vec} + : m_vec{&vec} + , m_mask{index} {} BitVec* m_vec; + Mask m_mask; }; class iterator : public iterator_base { public: - void set() { m_vec->set(*this); } - void reset() { m_vec->reset(*this); } + void set() { m_vec->set(m_mask); } + void reset() { m_vec->reset(m_mask); } private: friend class SmallBitVec; diff --git a/include/chilbert/detail/BitVecIterator.hpp b/include/chilbert/detail/BitVecIterator.hpp index 43af2ee..bcc5582 100644 --- a/include/chilbert/detail/BitVecIterator.hpp +++ b/include/chilbert/detail/BitVecIterator.hpp @@ -27,26 +27,26 @@ namespace chilbert { namespace detail { template -class BitVecIteratorBase : public BitVecMask +class BitVecIteratorBase { public: using Mask = typename BitVec::Mask; BitVecIteratorBase& operator++() { - Mask::operator++(); + ++m_mask; return *this; } BitVecIteratorBase& operator--() { - Mask::operator--(); + --m_mask; return *this; } bool operator==(const BitVecIteratorBase& rhs) const { - return m_vec == rhs.m_vec && Mask::operator==(rhs); + return m_vec == rhs.m_vec && m_mask == rhs.m_mask; } bool operator!=(const BitVecIteratorBase& rhs) const @@ -54,23 +54,24 @@ public: return !operator==(rhs); } - bool operator*() const { return m_vec->test(*this); } + bool operator*() const { return m_vec->test(m_mask); } protected: BitVecIteratorBase(BitVec& vec, const size_t index) - : Mask{index} - , m_vec{&vec} + : m_vec{&vec} + , m_mask{index} {} - BitVec* m_vec; + BitVec* m_vec; + BitVecMask m_mask; }; template class BitVecIterator : public BitVecIteratorBase { public: - void set() { this->m_vec->set(*this); } - void reset() { this->m_vec->reset(*this); } + void set() { this->m_vec->set(this->m_mask); } + void reset() { this->m_vec->reset(this->m_mask); } private: friend BitVec; -- cgit v1.2.1