std::ranges::views::take_while, std::ranges::take_while_view
Defined in header <ranges>
|
||
template< ranges::view V, class Pred > requires ranges::input_range<V> && |
(1) | (since C++20) |
namespace views { inline constexpr /*unspecified*/ take_while = /*unspecified*/; |
(2) | (since C++20) |
Call signature |
||
template< ranges::viewable_range R, class Pred > requires /* see below */ |
(since C++20) | |
template< class Pred > constexpr /*range adaptor closure*/ take_while( Pred&& pred ); |
(since C++20) | |
view
of the elements from an underlying sequence, starting at the beginning and ending at the first element for which the predicate returns false.take_while_view models the concepts contiguous_range
, random_access_range
, bidirectional_range
, forward_range
, and input_range
when the underlying view V models respective concepts.
Contents |
[edit] Expression-equivalent
Expression e is expression-equivalent to expression f, if e and f have the same effects, either are both potentially-throwing or are both not potentially-throwing (i.e. noexcept(e) == noexcept(f)), and either are both constant subexpressions or are both not constant subexpressions.
[edit] Member functions
(C++20) |
constructs a take_while_view (public member function) |
(C++20) |
returns a copy of the underlying (adapted) view (public member function) |
(C++20) |
returns a reference to the stored predicate (public member function) |
(C++20) |
returns an iterator to the beginning (public member function) |
(C++20) |
returns a sentinel representing the end (public member function) |
Inherited from std::ranges::view_interface | |
(C++20) |
Returns whether the derived view is empty. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> )
|
(C++20) |
Returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D> )
|
(C++20) |
Gets the address of derived view's data. Provided if its iterator type satisfies contiguous_iterator . (public member function of std::ranges::view_interface<D> )
|
(C++20) |
Returns the first element in the derived view. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> )
|
(C++20) |
Returns the nth element in the derived view. Provided if it satisfies random_access_range . (public member function of std::ranges::view_interface<D> )
|
[edit] Deduction guides
[edit] Nested classes
the sentinel type (exposition-only member class template) |
[edit] Example
#include <ranges> #include <iostream> int main() { for (int year : std::views::iota(2017) | std::views::take_while([](int y) { return y <= 2020; })) { std::cout << year << ' '; } std::cout << '\n'; const char idea[] {"Today is yesterday's tomorrow!.."}; for (char x : std::ranges::take_while_view(idea, [](char c) { return c != '.'; })) { std::cout << x; } std::cout << '\n'; }
Output:
2017 2018 2019 2020 Today is yesterday's tomorrow!
[edit] See also
(C++20) |
a view consisting of the first N elements of another view (class template) (range adaptor object) |
a view consisting of the elements of another view , skipping the initial subsequence of elements until the first element where the predicate returns false (class template) (range adaptor object) |