semi working

v1
Brett 2024-09-23 23:21:03 -04:00
parent 7935e34ad4
commit ce09a70241
2 changed files with 23 additions and 15 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake) 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_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT) set(BLT_TARGET BLT)

View File

@ -33,6 +33,11 @@ namespace blt
explicit enumerate_base(Iter iter): iter(std::move(iter)) explicit enumerate_base(Iter iter): iter(std::move(iter))
{} {}
auto get_iterator() const
{
return iter;
}
protected: protected:
Iter iter; Iter iter;
}; };
@ -104,20 +109,18 @@ namespace blt
}; };
template<typename Iter, typename Category = typename std::iterator_traits<Iter>::iterator_cateogry> template<typename Iter, typename Category = typename std::iterator_traits<Iter>::iterator_cateogry>
constexpr bool is_forward_only = std::is_same_v<Category, std::forward_iterator_tag>; constexpr bool is_input_or_forward_only =
std::is_same_v<Category, std::forward_iterator_tag> || std::is_same_v<Category, std::input_iterator_tag>;
template<typename Iter, typename Category = typename std::iterator_traits<Iter>::iterator_category> template<typename Iter, typename Category = typename std::iterator_traits<Iter>::iterator_category>
constexpr bool is_bidirectional_or_better = constexpr bool is_bidirectional_or_better =
std::is_same_v<Category, std::bidirectional_iterator_tag> || std::is_same_v<Category, std::random_access_iterator_tag>; std::is_same_v<Category, std::bidirectional_iterator_tag> || std::is_same_v<Category, std::random_access_iterator_tag>;
template<typename Iter, typename = std::void_t<>> template<typename Iter, typename = std::void_t<>>
class enumerate_wrapper class enumerate_wrapper;
{
static_assert("Unsupported iterator type!");
};
template<typename Iter> template<typename Iter>
class enumerate_wrapper<Iter, std::enable_if_t<is_forward_only<Iter>, std::void_t<std::forward_iterator_tag>>> : public enumerate_base_fwd<Iter> class enumerate_wrapper<Iter, std::enable_if_t<is_input_or_forward_only<Iter>, std::void_t<std::forward_iterator_tag>>> : public enumerate_base_fwd<Iter>
{ {
public: public:
using iterator_category = std::forward_iterator_tag; using iterator_category = std::forward_iterator_tag;
@ -125,6 +128,7 @@ namespace blt
using difference_type = typename std::iterator_traits<Iter>::difference_type; using difference_type = typename std::iterator_traits<Iter>::difference_type;
using pointer = typename std::iterator_traits<Iter>::pointer; using pointer = typename std::iterator_traits<Iter>::pointer;
using reference = typename std::iterator_traits<Iter>::reference; using reference = typename std::iterator_traits<Iter>::reference;
using iterator_type = Iter;
using enumerate_base_fwd<Iter>::enumerate_base_fwd; using enumerate_base_fwd<Iter>::enumerate_base_fwd;
}; };
@ -139,6 +143,7 @@ namespace blt
using difference_type = typename std::iterator_traits<Iter>::difference_type; using difference_type = typename std::iterator_traits<Iter>::difference_type;
using pointer = typename std::iterator_traits<Iter>::pointer; using pointer = typename std::iterator_traits<Iter>::pointer;
using reference = typename std::iterator_traits<Iter>::reference; using reference = typename std::iterator_traits<Iter>::reference;
using iterator_type = Iter;
using enumerate_base_bidirectional<Iter>::enumerate_base_bidirectional; using enumerate_base_bidirectional<Iter>::enumerate_base_bidirectional;
}; };
@ -258,13 +263,10 @@ namespace blt
}; };
template<typename Iter, typename = std::void_t<>> template<typename Iter, typename = std::void_t<>>
class enumerator class enumerator;
{
static_assert("Unsupported iterator type!");
};
template<typename Iter> template<typename Iter>
class enumerator<Iter, std::enable_if_t<is_forward_only<Iter>, std::void_t<std::forward_iterator_tag>>> : public enumerator_base<Iter> class enumerator<Iter, std::enable_if_t<is_input_or_forward_only<Iter>, std::void_t<std::forward_iterator_tag>>> : public enumerator_base<Iter>
{ {
public: public:
using enumerator_base<Iter>::enumerator_base; using enumerator_base<Iter>::enumerator_base;
@ -275,6 +277,8 @@ namespace blt
: public enumerator_base<Iter> : public enumerator_base<Iter>
{ {
public: public:
using iter = Iter;
using type = decltype(std::reverse_iterator{enumerator::end_});
//using enumerator_base<Iter>::enumerator_base; //using enumerator_base<Iter>::enumerator_base;
explicit enumerator(Iter begin, Iter end, blt::size_t container_size): 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): explicit enumerator(Iter begin, Iter end, blt::size_t begin_index, blt::size_t end_index):
enumerator_base<Iter>(std::move(begin), std::move(end), begin_index, end_index), container_size(end_index - begin_index) enumerator_base<Iter>(std::move(begin), std::move(end), begin_index, end_index),
container_size(std::abs(static_cast<blt::ptrdiff_t>(end_index) - static_cast<blt::ptrdiff_t>(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<Iter>>{
std::reverse_iterator{this->end_.get_iterator()},
std::reverse_iterator{this->begin_.get_iterator()},
this->container_size - 1, 0ul};
} }
protected: protected: