diff --git a/CMakeLists.txt b/CMakeLists.txt index e09b98d..662bdf8 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.21) +set(BLT_VERSION 0.20.22) 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 8c6ec6c..9ff8bb6 100644 --- a/include/blt/std/ranges.h +++ b/include/blt/std/ranges.h @@ -32,6 +32,11 @@ namespace blt public: explicit enumerate_base(Iter iter): iter(std::move(iter)) {} + + auto get_iterator() const + { + return iter; + } protected: Iter iter; @@ -104,20 +109,18 @@ namespace blt }; template::iterator_cateogry> - constexpr bool is_forward_only = std::is_same_v; + constexpr bool is_input_or_forward_only = + std::is_same_v || std::is_same_v; template::iterator_category> constexpr bool is_bidirectional_or_better = std::is_same_v || std::is_same_v; template> - class enumerate_wrapper - { - static_assert("Unsupported iterator type!"); - }; + class enumerate_wrapper; template - class enumerate_wrapper, std::void_t>> : public enumerate_base_fwd + class enumerate_wrapper, std::void_t>> : public enumerate_base_fwd { public: using iterator_category = std::forward_iterator_tag; @@ -125,6 +128,7 @@ namespace blt using difference_type = typename std::iterator_traits::difference_type; using pointer = typename std::iterator_traits::pointer; using reference = typename std::iterator_traits::reference; + using iterator_type = Iter; using enumerate_base_fwd::enumerate_base_fwd; }; @@ -139,6 +143,7 @@ namespace blt using difference_type = typename std::iterator_traits::difference_type; using pointer = typename std::iterator_traits::pointer; using reference = typename std::iterator_traits::reference; + using iterator_type = Iter; using enumerate_base_bidirectional::enumerate_base_bidirectional; }; @@ -258,13 +263,10 @@ namespace blt }; template> - class enumerator - { - static_assert("Unsupported iterator type!"); - }; + class enumerator; template - class enumerator, std::void_t>> : public enumerator_base + class enumerator, std::void_t>> : public enumerator_base { public: using enumerator_base::enumerator_base; @@ -275,6 +277,8 @@ namespace blt : public enumerator_base { public: + using iter = Iter; + using type = decltype(std::reverse_iterator{enumerator::end_}); //using enumerator_base::enumerator_base; explicit enumerator(Iter begin, Iter end, blt::size_t container_size): @@ -282,12 +286,16 @@ namespace blt {} explicit enumerator(Iter begin, Iter end, blt::size_t begin_index, blt::size_t end_index): - enumerator_base(std::move(begin), std::move(end), begin_index, end_index), container_size(end_index - begin_index) + enumerator_base(std::move(begin), std::move(end), begin_index, end_index), + container_size(std::abs(static_cast(end_index) - static_cast(begin_index))) {} - enumerator rev() + auto rev() { - return enumerator{std::reverse_iterator{this->end_}, std::reverse_iterator{this->begin_}, container_size - 1, 0ul}; + return enumerator>{ + std::reverse_iterator{this->end_.get_iterator()}, + std::reverse_iterator{this->begin_.get_iterator()}, + this->container_size - 1, 0ul}; } protected: