diff --git a/CMakeLists.txt b/CMakeLists.txt index c18c512..80e38d3 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.20.25) +set(BLT_VERSION 0.20.26) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/ranges.h b/include/blt/std/ranges.h index 112b716..8795579 100644 --- a/include/blt/std/ranges.h +++ b/include/blt/std/ranges.h @@ -19,6 +19,15 @@ namespace blt { + template> + class enumerate_wrapper; + + template> + class enumerator; + + template> + class enumerator_rev; + template struct enumerate_item { @@ -105,9 +114,6 @@ namespace blt } }; - template> - class enumerate_wrapper; - template class enumerate_wrapper, std::void_t>> : public enumerate_forward_iterator @@ -163,34 +169,46 @@ namespace blt IterWrapper end_; }; - template + template class enumerator_reversible : public enumerator_base { public: explicit enumerator_reversible(Iter begin, Iter end, blt::size_t container_size): - enumerator_base(std::move(begin), std::move(end)), container_size(container_size) + enumerator_base{IterWrapper{enumerate_wrapper{std::move(begin), 0}}, + IterWrapper{enumerate_wrapper{std::move(end), container_size}}}, + container_size(container_size) {} - explicit enumerator_reversible(Iter begin, Iter end, blt::size_t begin_index, blt::size_t end_index): - enumerator_base(IterWrapper{enumerate_wrapper(std::move(begin), begin_index)}, - IterWrapper{enumerate_wrapper(std::move(end), end_index)}), - container_size(std::abs(static_cast(end_index) - static_cast(begin_index))) + explicit enumerator_reversible(Iter begin, Iter end, blt::size_t begin_index, blt::size_t end_index, blt::size_t container_size): + enumerator_base(IterWrapper{enumerate_wrapper{std::move(begin), begin_index}}, + IterWrapper{enumerate_wrapper{std::move(end), end_index}}), + container_size(container_size) {} - auto rev() + auto rev() const { - return Reverse{this->end_.base(), this->begin_.base(), this->container_size, 0ul}; + return enumerator_rev{this->end_.base(), this->begin_.base(), this->container_size, this->begin_.get_index(), + this->container_size}; } protected: blt::size_t container_size; }; - template> - class enumerator; - - template> - class enumerator_rev; + template + class enumerator_reversible_rev : public enumerator_reversible + { + public: + using enumerator_reversible::enumerator_reversible; + + auto rev() const + { + BLT_TRACE(this->end_.base().get_index()); + BLT_TRACE(this->begin_.base().get_index()); + return enumerator{this->end_.base().base(), this->begin_.base().base(), this->end_.base().get_index(), + this->begin_.base().get_index(), this->container_size}; + } + }; template class enumerator, std::void_t>> @@ -202,34 +220,46 @@ namespace blt template class enumerator, std::void_t>> - : public enumerator_reversible, enumerator_rev> + : public enumerator_reversible> { public: - using enumerator_reversible, enumerator_rev>::enumerator_reversible; + using enumerator_reversible>::enumerator_reversible; }; template class enumerator, std::void_t>> - : public enumerator_reversible, enumerator_rev> + : public enumerator_reversible> { public: - using enumerator_reversible, enumerator_rev>::enumerator_reversible; + using enumerator_reversible>::enumerator_reversible; + + auto skip(blt::size_t offset) + { + return enumerator{this->begin_.base() + offset, this->end_.base(), this->begin_.get_index() + offset, this->container_size, + this->container_size}; + } }; template class enumerator_rev, std::void_t>> - : public enumerator_reversible>, enumerator> + : public enumerator_reversible_rev>> { public: - using enumerator_reversible>, enumerator>::enumerator_reversible; + using enumerator_reversible_rev>>::enumerator_reversible_rev; }; template class enumerator_rev, std::void_t>> - : public enumerator_reversible>, enumerator> + : public enumerator_reversible_rev>> { public: - using enumerator_reversible>, enumerator>::enumerator_reversible; + using enumerator_reversible_rev>>::enumerator_reversible_rev; + + auto skip(blt::size_t offset) + { + return enumerator_rev{this->begin_.base().base() - offset, this->end_.base().base(), this->begin_.base().get_index() - offset, + this->container_size, this->container_size}; + } }; template