From a27651b21d1864d99a29f5d8985d6ae970e55ca1 Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 25 Sep 2024 03:15:01 -0400 Subject: [PATCH] push --- CMakeLists.txt | 2 +- include/blt/std/iterator.h | 75 ++++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index abb619a..9b12114 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.21.0) +set(BLT_VERSION 0.21.1) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/iterator.h b/include/blt/std/iterator.h index 4d70916..933bf38 100644 --- a/include/blt/std/iterator.h +++ b/include/blt/std/iterator.h @@ -28,6 +28,7 @@ namespace blt { + // forward declare useful types template> class enumerator; @@ -39,6 +40,7 @@ namespace blt template> class enumerate_wrapper; + // struct which is returned by the enumerator template struct enumerate_item { @@ -46,6 +48,38 @@ namespace blt T value; }; + template + class pair_iterator_base + { + public: + explicit pair_iterator_base(Iter1 iter1, Iter2 iter2): m_iter1(std::move(iter1)), m_iter2(std::move(iter2)) + {} + + friend bool operator==(const pair_iterator_base& a, const pair_iterator_base& b) + { + return a.m_iter1 == b.m_iter1; + } + + friend bool operator!=(const pair_iterator_base& a, const pair_iterator_base& b) + { + return a.m_iter1 != b.m_iter1; + } + + auto iter1() const + { + return m_iter1; + } + + auto iter2() const + { + return m_iter2; + } + + protected: + Iter1 m_iter1; + Iter2 m_iter2; + }; + template class enumerate_iterator_base { @@ -198,9 +232,24 @@ namespace blt auto rev() const { - return enumerator_rev{this->end_.base(), this->begin_.base(), this->container_size, this->begin_.get_index(), + return enumerator_rev{this->end_.base(), + this->begin_.base(), + this->end_.get_index(), + this->begin_.get_index(), this->container_size}; } + + auto skip(blt::size_t offset) + { + auto begin = this->begin(); + for (blt::size_t i = 0; i < offset; i++) + ++begin; + return enumerator{begin.base(), + this->end_.base(), + begin.get_index(), + this->end_.get_index(), + this->container_size}; + } protected: blt::size_t container_size; @@ -214,8 +263,23 @@ namespace blt auto rev() const { - return enumerator{this->end_.base().base(), this->begin_.base().base(), this->end_.base().get_index(), - this->begin_.base().get_index(), this->container_size}; + return enumerator{this->end_.base().base(), + this->begin_.base().base(), + this->end_.base().get_index(), + this->begin_.base().get_index(), + this->container_size}; + } + + auto skip(blt::size_t offset) + { + auto begin = this->begin(); + for (blt::size_t i = 0; i < offset; i++) + --begin; + return enumerator{begin.base(), + this->end_.base(), + begin.get_index(), + this->end_.get_index(), + this->container_size}; } }; } @@ -234,11 +298,6 @@ namespace blt { public: using iterator::enumerator_reversible>::enumerator_reversible; - - auto skip(blt::size_t offset) - { - - } }; template