std::ranges...e_while_view(3)
πΈ NAME πΈ
okay bestie, welcome to the std::ranges...e_while_view(3) page from the C++ Standard Libary manual π
this one is all about std::ranges::views::take_while and std::ranges::take_while_view, and yes, we're covering every last cute little detail.
std::ranges::views::take_while,std::ranges::take_while_view β that's the pair, no cap. π«Ά
β¨ Synopsis β¨
Defined in header <ranges>
template< ranges::view V, class Pred >
requires ranges::input_range<V> &&
std::is_object_v<Pred> &&
std::indirect_unary_predicate<const Pred, ranges::iterator_t<V>>
class take_while_view
: public ranges::view_interface<take_while_view<V, Pred>>
(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 */
constexpr ranges::view auto take_while( R&& r, Pred&& pred );
(since C++20)
template< class Pred >
constexpr /*range adaptor closure*/ take_while( Pred&& pred );
(since C++20)
- A range adaptor that represents view of the elements from an underlying sequence, starting at the beginning and ending at the first element for which the predicate returns false. π
RangeAdaptorObject. The expressionviews::take_while(e, f)is expression-equivalent totake_while_view(e, f)for any suitable subexpressionseandf. π
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. periodt. π
π Member functions π
constructorβ constructs atake_while_view;(C++20)(public member function)baseβ returns a copy of the underlying (adapted) view;(C++20)(public member function)predβ returns a reference to the stored predicate;(C++20)(public member function)beginβ returns an iterator to the beginning;(C++20)(public member function)endβ returns a sentinel representing the end;(C++20)(public member function)
𧬠Inherited from std::ranges::view_interface π§¬
emptyβ returns whether the derived view is empty. Provided if it satisfiessized_rangeorforward_range.(C++20)(public member function of std::ranges::view_interface<D>)cbeginβ returns a constant iterator to the beginning of the range.(C++23)(public member function of std::ranges::view_interface<D>)cendβ returns a sentinel for the constant iterator of the range.(C++23)(public member function of std::ranges::view_interface<D>)operator boolβ returns whether the derived view is not empty. Provided ifranges::emptyis applicable to it.(C++20)(public member function of std::ranges::view_interface<D>)dataβ gets the address of derived view's data. Provided if its iterator type satisfiescontiguous_iterator.(C++20)(public member function of std::ranges::view_interface<D>)frontβ returns the first element in the derived view. Provided if it satisfiesforward_range.(C++20)(public member function of std::ranges::view_interface<D>)operator[]β returns then^thelement in the derived view. Provided if it satisfiesrandom_access_range.(C++20)(public member function of std::ranges::view_interface<D>)
π§ Deduction guides π§
the page gives this its own little heading; no extra details are listed under it, bestie. β¨
πͺ Nested classes πͺ
sentinelβ the sentinel type(exposition-only member class template*)
π Example π
// Run this code
#include <iostream>
#include <ranges>
int main()
{
for (int year : std::views::iota(2020)
| std::views::take_while([](int y) { return y <=
2023; }))
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 β
2020 2021 2022 2023
Today is yesterday's tomorrow!
π See also π
ranges::take_viewβ a view consisting of the first N elements of another view(class template)views::takeβ(range adaptor object)(C++20)ranges::drop_while_viewβ 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)views::drop_whileβ(range adaptor object)(C++20)
π that's the whole manual page, bestie! source: http://cppreference.com Β· version/date: 2024.06.10 Β· title: std::ranges...e_while_view(3) β now go take while the predicate is true and slay the ranges game π¦π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms