diff --git a/include/spdlog/details/circular_q.h b/include/spdlog/details/circular_q.h index 9deade41..35dca80f 100644 --- a/include/spdlog/details/circular_q.h +++ b/include/spdlog/details/circular_q.h @@ -6,8 +6,6 @@ #include #include -#include -#include namespace spdlog { namespace details { @@ -76,7 +74,7 @@ public: } // Return number of elements actually stored - [[nodiscard]] size_t size() const + size_t size() const { if (tail_ >= head_) { @@ -97,13 +95,7 @@ public: return v_[(head_ + idx) % max_items_]; } - // Return reference to item by index. - T &operator[](size_t idx) - { - return const_cast(static_cast(*this)[idx]); - } - - // Pop item from front if exists. + // Pop item from front if not empty. void pop_front() { if(!empty()) @@ -124,7 +116,7 @@ public: { return ((tail_ + 1) % max_items_) == head_; } - return true; + return false; } [[nodiscard]] size_t overrun_counter() const @@ -137,73 +129,6 @@ public: overrun_counter_ = 0; } - // Iterator support - class iterator - { - public: - using iterator_category = std::forward_iterator_tag; - using value_type = T; - using difference_type = std::ptrdiff_t; - using pointer = T *; - using reference = T &; - - explicit iterator(circular_q *circular_q = nullptr, size_t index = 0) - : cq_(circular_q) - , index_(index) - {} - - reference operator*() const - { - return cq_->operator[](index_); - } - - pointer operator->() - { - return &operator*(); - } - - // Prefix increment - iterator &operator++() - { - if(cq_ != nullptr) - { - index_ = (index_ + 1); - } - return *this; - } - - // Postfix increment - iterator operator++(int) - { - iterator retval = *this; - ++(*this); - return retval; - } - - bool operator==(iterator other) const - { - return cq_ == other.cq_ && index_ == other.index_; - } - - bool operator!=(iterator other) const - { - return index_ != other.index_ || cq_ != other.cq_; - } - - private: - circular_q *cq_; - size_t index_; - }; - - iterator begin() - { - return iterator(this, 0); - } - iterator end() - { - return iterator(this, size()); - } - private: // copy from other&& and reset it to disabled state void copy_moveable(circular_q &&other) noexcept diff --git a/tests/test_circular_q.cpp b/tests/test_circular_q.cpp index 5f1a0e57..bef6ceeb 100644 --- a/tests/test_circular_q.cpp +++ b/tests/test_circular_q.cpp @@ -12,7 +12,7 @@ TEST_CASE("test_size", "[circular_q]") REQUIRE(q.full() == false); for (size_t i = 0; i < q_size; i++) { - q.push_back(std::move(i)); + q.push_back(10); } REQUIRE(q.size() == q_size); q.push_back(999); @@ -26,7 +26,7 @@ TEST_CASE("test_rolling", "[circular_q]") for (size_t i = 0; i < q_size + 2; i++) { - q.push_back(std::move(i)); + q.push_back(size_t{i}); // arg to push_back must be r value } REQUIRE(q.size() == q_size);