36 virtual ~AIter()
noexcept =
default;
42 virtual T deref()
const noexcept = 0;
47 virtual void advance()
noexcept = 0;
55 virtual bool equals(
const AIter& other)
const noexcept = 0;
88 template <std::input_or_output_iterator TIt>
89 class Iter final :
public AIter {
116 explicit Iter(TIt& iterator) noexcept : iterator(iterator), userdata(
nullptr) {}
127 T deref()
const noexcept override {
return *iterator; }
128 void advance()
noexcept override { std::ranges::advance(iterator, 1); }
129 bool equals(
const AIter& other)
const noexcept override {
130 return other.type() == type() &&
static_cast<const Iter<TIt>&
>(other).iterator == iterator;
132 const std::type_info& type()
const override {
return typeid(
this); }
144 using value_type = T;
146 using reference = T&;
175 template <std::input_or_output_iterator TIt>
176 explicit GenericIterator(TIt iterator) noexcept : impl(std::make_unique<Iter<TIt>>(iterator)) {}
188 template <std::input_or_output_iterator TIt>
190 : impl(std::make_unique<Iter<TIt>>(iterator, userdata)) {}
249 static_assert(std::input_iterator<GenericIterator<int>>);
Represents a generic iterator that can be initialized to hold any other class instance that satisfies...
bool operator==(const GenericIterator< T > &other) const
Checks if this iterator is equal to the provided one.
GenericIterator()
Default constructor that creates a nullptr-iterator.
GenericIterator< T > & operator=(GenericIterator< T > &&other) noexcept
Move-assignment operator.
GenericIterator(const GenericIterator< T > &other)
Copy-constructs a new generic iterator.
GenericIterator< T > operator++(int) noexcept
Late increments the iterator. That is, advances the iterator by one but returns a copy of the iterato...
GenericIterator< T > & operator++() noexcept
Increments the iterator. That is, advancing it forward by one.
GenericIterator< T > & operator=(const GenericIterator< T > &other) noexcept
Assignment opterator.
GenericIterator(GenericIterator< T > &&other)
Move-constructs a new generic iterator.
T operator*() const
Dereferences the iterator. That is, returns the data it currently points at.
GenericIterator(TIt iterator) noexcept
Constructs a new GenericIterator from the provided arbitrary object that satisfies the std::input_or_...
GenericIterator(TIt iterator, std::shared_ptr< auto > userdata) noexcept
Constructs a new GenericIterator from the provided arbitrary object that satisfies the std::input_or_...