1#ifndef HALCHECK_LIB_ITERATOR_FILTER_HPP
2#define HALCHECK_LIB_ITERATOR_FILTER_HPP
6#include <halcheck/lib/functional.hpp>
7#include <halcheck/lib/iterator/base.hpp>
8#include <halcheck/lib/iterator/interface.hpp>
9#include <halcheck/lib/iterator/range.hpp>
10#include <halcheck/lib/iterator/type_traits.hpp>
11#include <halcheck/lib/optional.hpp>
12#include <halcheck/lib/pp.hpp>
13#include <halcheck/lib/type_traits.hpp>
18namespace halcheck {
namespace lib {
26template<
typename I,
typename F>
34 "F must be invocable and return a boolean-testable value");
36 template<
typename,
typename>
80 while (_base != _end && !
lib::invoke(*_func, *_base))
98 : _base(
std::move(other._base)), _end(
std::move(other._end)), _func(
std::move(*other._func)) {}
116 : _base(
std::move(other._base)), _end(
std::move(other._end)), _func(*
std::move(other._func)) {}
122 constexpr const I &
base() const & noexcept {
return _base; }
128 I
base() && {
return std::move(_base); }
143 }
while (_base != _end && !
lib::invoke(*_func, *_base));
151 template<bool _ = true, HALCHECK_REQUIRE(lib::is_bidirectional_iterator<I>() && _)>
166 return lhs._base == rhs._base;
189 template<
typename I,
typename F>
205 explicit ref(
const F *base =
nullptr) : base(base) {}
206 template<
typename... Args>
214 filter_view() =
default;
216 filter_view(V base, F func) : _base(
std::move(base)), _func(
std::move(func)) {}
218 template<bool _ = true, HALCHECK_REQUIRE(std::is_copy_constructible<V>() && _)>
219 constexpr V base()
const & {
223 V base() && {
return std::move(_base); }
225 lib::filter_iterator<lib::iterator_t<V>, ref> begin() {
233 lib::filter_iterator<lib::iterator_t<const U>, ref> begin()
const {
237 lib::filter_iterator<lib::iterator_t<V>, ref>
end() {
245 lib::filter_iterator<lib::iterator_t<const U>, ref>
end()
const {
251 lib::optional<F> _func;
254template<
typename V,
typename F>
255lib::filter_view<V, F> filter(V base, F func) {
256 return lib::filter_view<V, F>(std::move(base), std::move(func));
friend constexpr bool operator==(const filter_iterator &lhs, const filter_iterator &rhs)
Compares two filter_iterators for equality.
Definition filter.hpp:165
filter_iterator & operator++()
Advances the base iterator to the next element that satisfies the predicate.
Definition filter.hpp:140
I base() &&
Get the base iterator of this filter_iterator.
Definition filter.hpp:128
constexpr filter_iterator(filter_iterator< I2, F2 > other)
Performs a conversion on a filter_iterator with compatible type parameters.
Definition filter.hpp:97
lib::conditional_t< lib::is_random_access_iterator< I >{}, std::bidirectional_iterator_tag, lib::iter_category_t< I > > iterator_category
Indicates the level of supported iterator operations this type provides.
Definition filter.hpp:65
filter_iterator(I base, I end, F fun)
Constructs a filter_iterator from a (begin, end] pair of iterators and a predicate.
Definition filter.hpp:79
constexpr reference operator*() const noexcept(noexcept(*std::declval< const I & >()))
Dereferences the base iterator.
Definition filter.hpp:134
constexpr const I & base() const &noexcept
Get a reference to the base iterator of this filter_iterator.
Definition filter.hpp:122
An iterator adaptor that skips elements that do not satisfy user-defined predicate.
Definition filter.hpp:27
lib::iter_difference_t< I > difference_type
The return type of operator-.
Definition filter.hpp:60
void pointer
This iterator type does not support operator->.
Definition filter.hpp:55
lib::iter_value_t< I > value_type
The type of value pointed to by this type of iterator.
Definition filter.hpp:45
constexpr filter_iterator()=default
Constructs a default filter_iterator.
lib::iter_reference_t< I > reference
The return type of operator*.
Definition filter.hpp:50
A utility class for easily defining new iterators.
Definition interface.hpp:40
An implementation of std::optional.
Definition optional.hpp:338
An implementation of std::ranges::view_interface.
Definition interface.hpp:238
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@20 invoke
An implementation of std::invoke.
decltype(lib::invoke(std::declval< F >(), std::declval< Args >()...)) invoke_result_t
An implementation of std::invoke_result_t.
Definition invoke.hpp:42
typename std::iterator_traits< I >::value_type iter_value_t
The type of value pointed to by an iterator.
Definition base.hpp:16
typename std::iterator_traits< I >::difference_type iter_difference_t
The return type of operator- for an iterator.
Definition base.hpp:32
typename std::iterator_traits< I >::reference iter_reference_t
The return type of operator* for an iterator.
Definition base.hpp:24
typename std::iterator_traits< I >::iterator_category iter_category_t
A tag type indicating the level of supported iterator options a type provides.
Definition base.hpp:40
lib::iter_reference_t< lib::iterator_t< R > > range_reference_t
The type returned by operator* for a range type's iterators.
Definition range.hpp:340
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::end_cpo::@28 end
Gets an iterator to past the end of a range.
HALCHECK_INLINE_CONSTEXPR struct halcheck::lib::@21 make_filter_iterator
Constructs a filter_iterator.
#define HALCHECK_INLINE_CONSTEXPR
A backwards-compatible substitute for inline constexpr.
Definition pp.hpp:70
typename std::conditional< Cond, T, F >::type conditional_t
An implementation of std::conditional_t.
Definition type_traits.hpp:51
#define HALCHECK_REQUIRE(...)
Expands to a template argument that is only valid if the given argument evaluates to true.
Definition type_traits.hpp:24
Determines if a type is satisfies the boolean-testable concept.
Definition type_traits.hpp:370