Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::take_while,std::ranges::take_while_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
       
      Defined in header<ranges>
      template<ranges::view V,class Pred>

          requiresranges::input_range<V>&&
                   std::is_object_v<Pred>&&
                   std::indirect_unary_predicate<const Pred,ranges::iterator_t<V>>
      class take_while_view

         :publicranges::view_interface<take_while_view<V, Pred>>
      (1)(since C++20)
      namespace views{

         inlineconstexpr/*unspecified*/ take_while=/*unspecified*/;

      }
      (2)(since C++20)
      Call signature
      template<ranges::viewable_range R,class Pred>

          requires/* see below */

      constexprranges::viewauto take_while( R&& r, Pred&& pred);
      (since C++20)
      template<class Pred>
      constexpr/*range adaptor closure*/ take_while( Pred&& pred);
      (since C++20)
      1) A range adaptor that representsview of the elements from an underlying sequence, starting at the beginning and ending at the first element for which the predicate returnsfalse.
      2)RangeAdaptorObject. The expressionviews::take_while(e, f) isexpression-equivalent totake_while_view(e, f) for any suitable subexpressionse andf.

      take_while_view models the conceptscontiguous_range,random_access_range,bidirectional_range,forward_range, andinput_range when the underlying viewV models respective concepts.

      Contents

      [edit]Data members

      Member Description
      Vbase_(private) the underlying view
      (exposition-only member object*)
      copyable-box<Pred>(until C++23)movable-box<Pred>(since C++23)pred_(private) the underlying function object
      (exposition-only member object*)

      [edit]Member functions

      constructs atake_while_view
      (public member function)[edit]
      returns a copy of the underlying (adapted) view
      (public member function)[edit]
      returns a reference to the stored predicate
      (public member function)[edit]
      returns an iterator to the beginning
      (public member function)[edit]
      returns a sentinel representing the end
      (public member function)[edit]
      Inherited fromstd::ranges::view_interface
      returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a constant iterator to the beginning of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a sentinel for the constant iterator of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns whether the derived view is not empty, provided only ifranges::empty is applicable to it
      (public member function ofstd::ranges::view_interface<D>)[edit]
      gets the address of derived view's data, provided only if its iterator type satisfiescontiguous_iterator
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the first element in the derived view, provided if it satisfiesforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns thenth element in the derived view, provided only if it satisfiesrandom_access_range
      (public member function ofstd::ranges::view_interface<D>)[edit]

      [edit]Deduction guides

      [edit]Nested classes

      the sentinel type
      (exposition-only member class template*)

      [edit]Notes

      Forforward_iterators,views::take_while(v, pred) is similar toranges::subrange{ranges::begin(v),ranges::find_if_not(v, pred)}, but the latter invokespred only during construction (while the former invokespred each time a validtake_while iterator is compared to a sentinel).

      [edit]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<2026;}))std::cout<< year<<' ';std::cout<<'\n'; constchar note[]{"Today is yesterday's tomorrow!..."};auto not_dot=[](char c){return c!='.';};for(char x: std::ranges::take_while_view(note, not_dot))std::cout<< x;std::cout<<'\n';}

      Output:

      2020 2021 2022 2023 2024 2025Today is yesterday's tomorrow!

      [edit]See also

      aview consisting of the first N elements of anotherview
      (class template)(range adaptor object)[edit]
      aview consisting of the elements of anotherview, skipping the initial subsequence of elements until the first element where the predicate returnsfalse
      (class template)(range adaptor object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/take_while_view&oldid=182364"

      [8]ページ先頭

      ©2009-2025 Movatter.jp