45# ifndef FILTER_ITERATOR_H
46# define FILTER_ITERATOR_H
48# include <type_traits>
68template <
class Container>
70 std::is_pointer_v<Container> or
71 requires {
requires Container::filter_iterator_keeps_a_copy; };
145template <
class Container,
class It,
class Show_Item>
150 static constexpr bool keeps_copy = filter_iterator_keeps_copy<Container>;
153 std::conditional_t<keeps_copy, Container, const Container *>
container_ptr{};
165 if constexpr (
keeps_copy and not std::is_pointer_v<Container>)
219 catch (
const std::overflow_error &)
252 catch (
const std::overflow_error &)
292 catch (
const std::underflow_error &)
307 static constexpr bool goes_back =
requires (
It & i) { i.prev(); };
312 static constexpr bool goes_to_last =
requires (
It & i) { i.reset_last(); i.prev(); };
390 requires std::is_move_assignable_v<Show_Item>
463 Show_Item si = Show_Item())
471 Show_Item si = Show_Item())
584 template <
typename Op>
602 template <
typename Pred>
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Generic filter iterator wrapper.
void reset_last()
Resets the iterator to the last filtered element.
void set_cookie(void *__cookie) noexcept
Sets the cookie pointer.
void next()
Advances the iterator to the next filtered element.
const Container & get_container() const
Returns a const reference to the container being iterated over.
Filter_Iterator(const Container &c, Show_Item si=Show_Item())
Constructs a filter iterator over a container.
static constexpr bool unchecked
It & get_iterator() noexcept
Returns a reference to the underlying base iterator.
static constexpr bool goes_to_last
Whether the base iterator goes to its last item and moves back, as reset_last() needs.
void prev()
Moves the iterator backward to the previous filtered element.
Filter_Iterator(Container &c, Show_Item si=Show_Item())
Filter over the modifiable container c.
Filter_Iterator(const Container &c, void *__cookie, Show_Item si=Show_Item())
Constructs a filter iterator with a cookie.
const It & get_iterator() const noexcept
Returns a const reference to the underlying base iterator.
static constexpr bool goes_back
Whether the base iterator moves back, as prev() and prev_ne() need.
bool container_set() const noexcept
void next_ne() noexcept(shows_ne)
Advances the iterator to the next filtered element, as next() does.
Show_Item Filter_Type
The type of the filter functor.
static constexpr bool shows_ne
void forward_without_curr()
decltype(auto) base_curr()
Filter_Iterator(Container &c, void *__cookie, Show_Item si=Show_Item())
See Filter_Iterator(const Container &, void *, Show_Item); over a modifiable container.
typename It::Item_Type Item_Type
The type of element returned by get_curr()
static auto kept(const Container &c) noexcept
Filter_Iterator(Show_Item si=Show_Item()) noexcept
Default constructor.
static constexpr bool keeps_copy
void * get_cookie() const noexcept
Gets the cookie pointer.
bool empty()
Check if there are no elements that pass the filter.
size_t count()
Count the number of elements that pass the filter.
void backward()
Move backward to the previous element that passes the filter.
void * cookie
User-defined pointer for extensibility (e.g., passing context data to filter)
void reset_first()
Resets the iterator to the first filtered element.
bool has_container() const noexcept
Check if a container has been set.
void set_filter(Show_Item si)
Sets a new filter functor.
void prev_ne() noexcept(shows_ne)
Moves the iterator backward, as prev() does.
void forward()
Move forward to the next element that passes the filter.
void goto_first_valid_item()
Advance to the first element that passes the filter.
const Show_Item & get_filter() const noexcept
Returns a const reference to the filter functor.
void for_each(Op op)
Apply a function to all filtered elements.
std::conditional_t< keeps_copy, Container, const Container * > container_ptr
bool find_if(Pred pred)
Find the first element that satisfies an additional predicate.
Show_Item & get_filter() noexcept
Returns a reference to the filter functor.
void goto_last_valid_item()
Move to the last element that passes the filter.
Slinknc * get_curr_ne() const noexcept
Return the current link guaranteeing no exception. Be careful.
Slinknc * get_curr() const
bool has_curr() const noexcept
An AlephIterator whose get_curr_ne() gives what get_curr() gives, without its check.
PredicateWith<F, Args...>, and neither the call nor the conversion of its result to bool can throw.
Freq_Node * pred
Predecessor node in level-order traversal.
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
auto get_curr() const
Return the current tuple (bounds-checked).
and
Check uniqueness with explicit hash + equality functors.
bool has_curr() const noexcept
Return true if all underlying iterators are positioned on a valid item.
constexpr bool filter_iterator_keeps_copy
Whether a Filter_Iterator keeps a copy of its container, and not its address.
Default filter functor that shows all elements.
bool operator()(const T &) const noexcept
Always returns true (shows all elements).
Filter functor that hides all elements.
bool operator()(const T &) const noexcept
Always returns false (hides all elements).
Filter_Iterator< DynList< int >, DynList< int >::Iterator, Par > It