A range adaptor that represents
view
of an underlying sequence with only the elements that satisfy the predicate.
filter_view
models the concepts bidirectional_range
, forward_range
, input_range
, and common_range
when the underlying view
V
models respective concepts.
V
base_
the underlying view
copyable-box
<Pred>
(until C++23)movable-box
<Pred>
(since C++23) pred_
wraps the predicate used to filter out elements of base_
begin_
V
satisfies forward_range
) an object that caches an iterator to the first element of base_
that satisfies the pred_
filter_view
V
filter_view
filter_view
filter_view
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] std::ranges::filter_view::filter_view
1) Value-initializes base_
via its default member initializer (= V()) and default-initializes pred_
(which value-initializes the contained Pred
).
2) Initializes base_
with std::move(base) and initializes pred_
with std::move(pred).
constexpr V base() &&;
(2) (since C++20)1) Equivalent to return base_;.
2) Equivalent to return std::move(base_);.
std::ranges::filter_view::predconstexpr const Pred& pred() const;
(since C++20)Returns a reference to the contained Pred
object. The behavior is undefined if pred_
does not contain a value.
constexpr /*iterator*/ begin();
(exposition only*)In order to provide the amortized constant time complexity required by the range
concept, this function caches the result within the filter_view
object for use on subsequent calls. Equivalent to
The behavior is undefined if pred_
does not contain a value.
constexpr auto end();
(since C++20)Returns an iterator to the end. Equivalent to
[edit] Deduction guides template< class R, class Pred >filter_view
filter_view
when the underlying view is not a common_range
#include <iostream> #include <ranges> int main() { auto even = [](int i) { return 0 == i % 2; }; auto square = [](int i) { return i * i; }; for (int i : std::views::iota(0, 6) | std::views::filter(even) | std::views::transform(square)) std::cout << i << ' '; std::cout << '\n'; }
Output:
[edit] Defect reportsThe following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 3714Pred
is not default_initializable
, the default constructor
filter_view
which does not contain a Pred
the filter_view
is also
default_initializable
[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4