1#ifndef CPARK_FILTER_RDD_H
2#define CPARK_FILTER_RDD_H
25template <std::ranges::view V,
typename Func>
26requires std::invocable<Func, std::ranges::range_value_t<V>>&& std::is_convertible_v<
27 std::invoke_result_t<Func, std::ranges::range_value_t<V>>,
bool>
class FilterView
28 :
public std::ranges::view_interface<FilterView<V, Func>> {
30 using OriginalIterator = std::ranges::iterator_t<V>;
31 using OriginalSentinel = std::ranges::sentinel_t<V>;
41 using difference_type = std::ptrdiff_t;
42 using value_type = std::ranges::range_value_t<V>;
44 using OriginalIterator = std::ranges::iterator_t<V>;
45 using OriginalSentinel = std::ranges::sentinel_t<V>;
53 iterator_ = std::ranges::find_if(iterator_, sentinel_, *func_);
65 iterator_ = std::ranges::find_if(iterator_, sentinel_, *func_);
83 OriginalIterator iterator_;
84 OriginalSentinel sentinel_;
91 : original_view_{std::
move(
view)}, func_{std::
move(func)} {}
95 return Iterator{std::ranges::begin(original_view_), std::ranges::end(original_view_),
96 const_cast<Func*
>(&func_)};
100 constexpr auto end()
const {
101 return Iterator{std::ranges::end(original_view_), std::ranges::end(original_view_),
102 const_cast<Func*
>(&func_)};
117template <concepts::Rdd R,
typename Func>
118requires std::invocable<Func, utils::RddElementType<R>>&& std::is_convertible_v<
119 std::invoke_result_t<Func, utils::RddElementType<R>>,
bool>
class FilterRdd
120 :
public BaseRdd<FilterRdd<R, Func>> {
133 "Instance of FilterRdd does not satisfy Rdd concept.");
149 constexpr auto beginImpl()
const {
return std::ranges::begin(splits_); }
151 constexpr auto endImpl()
const {
return std::ranges::end(splits_); }
154 std::vector<ViewSplit<FilterView<std::ranges::range_value_t<R>, Func>>> splits_{};
160template <
typename Func>
163 explicit Filter(
Func func) : func_{std::move(func)} {}
165 template <concepts::Rdd R,
typename T = utils::RddElementType<R>>
166 requires std::invocable<Func, T>&& std::is_same_v<std::invoke_result_t<Func, T>,
bool>
auto
167 operator()(
const R&
r)
const {
178template <
typename Func, concepts::Rdd R>
Definition base_rdd.h:522
Definition filter_rdd.h:161
Definition filter_rdd.h:120
constexpr FilterRdd(const R &prev, Func func)
Definition filter_rdd.h:131
Definition filter_rdd.h:39
Iterator & operator++()
Definition filter_rdd.h:62
bool operator==(const Iterator &other) const
Definition filter_rdd.h:77
bool operator!=(const Iterator &other) const
Definition filter_rdd.h:80
value_type operator*() const
Definition filter_rdd.h:59
Iterator(OriginalIterator iterator, OriginalSentinel sentinel, Func *func)
Definition filter_rdd.h:50
Iterator operator++(int)
Definition filter_rdd.h:70
Definition filter_rdd.h:28
constexpr FilterView(V view, Func func)
Definition filter_rdd.h:90
constexpr auto begin() const
Definition filter_rdd.h:94
constexpr auto end() const
Definition filter_rdd.h:100
auto operator|(const R &r, const Collect &collect)
Definition collect.h:48