Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::all,std::ranges::views::all_t

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      Defined in header<ranges>
      inlineconstexpr/* unspecified */ all=/* unspecified */;
      (1)(since C++20)
      template<ranges::viewable_range R>
      using all_t= decltype(views::all(std::declval<R>()));
      (2)(since C++20)
      1) ARangeAdaptorObject (also aRangeAdaptorClosureObject) that returns aview that includes all elements of itsrange argument.
      Given an expressione of typeR, the expressionviews::all(e) isexpression-equivalent to:
      2) Calculates the suitableview type of aviewable_range type.

      [edit]Example

      Run this code
      #include <iostream>#include <ranges>#include <type_traits>#include <vector> int main(){std::vector<int> v{0,1,2,3,4,5};for(int n: std::views::all(v)| std::views::take(2))std::cout<< n<<' ';std::cout<<'\n';     static_assert(std::is_same<        decltype(std::views::single(42)),        std::ranges::single_view<int>>{});     static_assert(std::is_same<        decltype(std::views::all(v)),        std::ranges::ref_view<std::vector<int,std::allocator<int>>>>{}); int a[]{1,2,3,4};    static_assert(std::is_same<        decltype(std::views::all(a)),        std::ranges::ref_view<int[4]>>{});     static_assert(std::is_same<        decltype(std::ranges::subrange{std::begin(a)+1,std::end(a)-1}),        std::ranges::subrange<int*,int*, std::ranges::subrange_kind(1)>>{});}

      Output:

      0 1

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3724C++20views::all might result in hard error for some move-only viewsit gets well-constrained
      P2415R2C++20views::all returned asubrange for a non-view rvaluerangereturns anowning_view for it

      [edit]See also

      an emptyview with no elements
      (class template)(variable template)[edit]
      aview that contains a single element of a specified value
      (class template)(customization point object)[edit]
      aview with unique ownership of somerange
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/all_view&oldid=183372"

      [8]ページ先頭

      ©2009-2025 Movatter.jp