Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::iota,std::ranges::iota_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
      std::ranges::iota_view
      Member functions
      Deduction guides
      Nested classes
      Iterator
      Helper concepts
      Member types
      Member functions
      Non-member functions
      Sentinel
      Member functions
      Non-member functions
       
      Defined in header<ranges>
      template<std::weakly_incrementable W,

               std::semiregular Bound=std::unreachable_sentinel_t>
          requires/*weakly-equality-comparable-with*/<W, Bound>&&std::copyable<W>
      class iota_view

         :publicranges::view_interface<iota_view<W, Bound>>
      (1)(since C++20)
      namespace views{

         inlineconstexpr/* unspecified */ iota=/* unspecified */;

      }
      (2)(since C++20)
      Call signature
      template<class W>

          requires/* see below */

      constexpr/* see below */ iota( W&& value);
      (since C++20)
      template<class W,class Bound>

          requires/* see below */

      constexpr/* see below */ iota( W&& value, Bound&& bound);
      (since C++20)
      1) A range factory that generates a sequence of elements by repeatedly incrementing an initial value. Can be either bounded or unbounded (infinite).
      2)views::iota(e) andviews::iota(e, f) areexpression-equivalent toiota_view<std::decay_t<decltype((e))>>(e) andiota_view(e, f) respectively for any suitable subexpressionse andf.

      Contents

      Customization point objects

      The nameviews::iota denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Data members

      Member Definition
      Wvalue_ the beginning value
      (exposition-only member object*)
      Boundbound_ the sentinel value, may be unreachable
      (exposition-only member object*)

      [edit]Member functions

      creates aniota_view
      (public member function)
      obtains the beginning iterator of aniota_view
      (public member function)
      obtains the sentinel denoting the end of aniota_view
      (public member function)
      tests whether theiota_view is empty (i.e. the iterator and the sentinel compare equal)
      (public member function)
      (optional)
      obtains the size of aniota_view (only provided if it is bounded)
      (public member function)
      Inherited fromstd::ranges::view_interface
      (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]
      returns the first element in the derived view, provided if it satisfiesforward_range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_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 iterator type
      (exposition-only member class*)
      the sentinel type used when theiota_view is bounded andBound andW are not the same type
      (exposition-only member class*)

      [edit]Helper templates

      template<std::weakly_incrementable W,std::semiregular Bound>
      constexprboolranges::enable_borrowed_range<ranges::iota_view<W, Bound>>=true;
      (since C++20)

      This specialization ofranges::enable_borrowed_range makesiota_view satisfyborrowed_range.

      [edit]Example

      Run this code
      #include <algorithm>#include <iostream>#include <ranges> struct Bound{int bound;bool operator==(int x)const{return x== bound;}}; int main(){for(int i: std::ranges::iota_view{1,10})std::cout<< i<<' ';std::cout<<'\n'; for(int i: std::views::iota(1,10))std::cout<< i<<' ';std::cout<<'\n'; for(int i: std::views::iota(1, Bound{10}))std::cout<< i<<' ';std::cout<<'\n'; for(int i: std::views::iota(1)| std::views::take(9))std::cout<< i<<' ';std::cout<<'\n';     std::ranges::for_each(std::views::iota(1,10),[](int i){std::cout<< i<<' ';});std::cout<<'\n';}

      Output:

      1 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 91 2 3 4 5 6 7 8 9

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 4096C++20views::iota could copy aniota_view as-isforbidden
      P2325R3C++20iota_view required thatW issemiregular
      asview requireddefault_initializable
      only requires thatW iscopyable

      [edit]See also

      (C++11)
      fills a range with successive increments of the starting value
      (function template)[edit]
      fills a range with successive increments of the starting value
      (algorithm function object)[edit]
      aview consisting of a generated sequence by repeatedly producing the same value
      (class template)(customization point object)[edit]
      aview that maps each element of adapted sequence to a tuple of both the element's position and its value
      (class template)(range adaptor object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/iota_view&oldid=182091"

      [8]ページ先頭

      ©2009-2025 Movatter.jp