Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::iota_view<W, Bound>::iota_view

      From cppreference.com
      <cpp‎ |ranges‎ |iota view
       
       
      Ranges library
      Range adaptors
       
      std::ranges::iota_view
      Member functions
      iota_view::iota_view
      Deduction guides
      Nested classes
      Iterator
      Helper concepts
      Member types
      Member functions
      Non-member functions
      Sentinel
      Member functions
      Non-member functions
       
      iota_view() requiresstd::default_initializable<W>=default;
      (1)(since C++20)
      constexprexplicit iota_view( W value);
      (2)(since C++20)
      constexprexplicit iota_view(std::type_identity_t<W> value,
                                   std::type_identity_t<Bound> bound);
      (3)(since C++20)
      constexprexplicit iota_view(/*iterator*/ first,/* see below */ last);
      (4)(since C++20)

      Constructs aniota_view.

       Overload Data members
      value_bound_
      (1)value-initializedvalue-initialized
      (2)initialized withvalue
      (3) initialized withbound 
      (4) initialized withfirst.value_ see below
      2,3) If any of the following conditions is satisfied, the behavior is undefined:
      4) If any of the following conditions is satisfied, the behavior is undefined:
      The type oflast and the method of initializingbound_ are determined by the typeBound denotes:
      The typeBound denotes The type oflast bound_
      Witerator initialized withlast.value_ 
       std::unreachable_sentinel_t Boundinitialized withlast
      any other typesentinelinitialized withlast.bound_

      [edit]Parameters

      value - the starting value
      bound - the bound
      first - the iterator denoting the starting value
      last - the iterator or sentinel denoting the bound

      [edit]Example

      Run this code
      #include <cassert>#include <iostream>#include <iterator>#include <ranges> int main(){constauto l={1,2,3,4}; auto i1= std::ranges::iota_view<int,int>();// overload (1)assert(i1.empty() and i1.size()==0); auto i2= std::ranges::iota_view(1);// overload (2)assert(not i2.empty() and i2.front()==1);for(std::cout<<"1) ";auto e: i2| std::views::take(3))std::cout<< e<<' ';std::cout<<'\n'; auto i3= std::ranges::iota_view(std::begin(l));// overload (2)assert(not i3.empty() and i3.front()== l.begin());for(std::cout<<"2) ";auto e: i3| std::views::take(4))std::cout<<*e<<' ';std::cout<<'\n'; auto i4= std::ranges::iota_view(1,8);// overload (3)assert(not i4.empty() and i4.front()==1 and i4.back()==7);for(std::cout<<"3) ";auto e: i4)std::cout<< e<<' ';std::cout<<'\n'; auto i5= std::ranges::iota_view(l.begin(), l.end());// overload (4)for(std::cout<<"4) ";auto e: i5)std::cout<<*e<<' ';std::cout<<'\n'; auto i6= std::ranges::iota_view(l.begin(),std::unreachable_sentinel);// (4)for(std::cout<<"5) ";auto e: i6| std::views::take(3))std::cout<<*e<<' ';std::cout<<'\n';}

      Output:

      1) 1 2 32) 1 2 3 43) 1 2 3 4 5 6 74) 1 2 3 45) 1 2 3

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3523C++20overload(4) might use wrong sentinel typecorrected
      P2711R1C++20overloads(3,4) were not explicitmade explicit
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/iota_view/iota_view&oldid=176916"

      [8]ページ先頭

      ©2009-2026 Movatter.jp