Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |ranges‎ |iota view
       
       
      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
       
      struct/*iterator*/;
      (1)(exposition only*)
      Helper alias templates
      template<class I>
      using/*iota-diff-t*/=/* see below */;
      (2)(exposition only*)
      Helper concepts
      template<class I>

      concept/*decrementable*/=
         std::incrementable<I>&& requires(I i){
             {--i}->std::same_as<I&>;
             { i--}->std::same_as<I>;

         };
      (3)(exposition only*)
      template<class I>

      concept/*advanceable*/=
         /*decrementable*/<I>&&std::totally_ordered<I>&&
          requires(I i,const I j,const/*iota-diff-t*/<I> n){
             { i+= n}->std::same_as<I&>;
             { i-= n}->std::same_as<I&>;
              I(j+ n);
              I(n+ j);
              I(j- n);
             { j- j}->std::convertible_to</*iota-diff-t*/<I>>;

         };
      (4)(exposition only*)
      1)ranges::iota_view<W, Bound>::iterator is the type of the iterators returned bybegin() andend() ofranges::iota_view<W, Bound>.
      2) Calculates the difference type for both iterator types andinteger-like types.
      • IfI is not an integral type, or if it is an integral type andsizeof(std::iter_difference_t<I>) is greater thansizeof(I), then/*iota-diff-t*/<I> isstd::iter_difference_t<I>.
      • Otherwise,/*iota-diff-t*/<I> is a signed integer type of width greater than the width ofI if such a type exists.
      • Otherwise,I is one of the widest integral types, and/*iota-diff-t*/<I> is an unspecifiedsigned-integer-like type of width not less than the width ofI. It is unspecified whether/*iota-diff-t*/<I> modelsweakly_incrementable in this case.
      3) Specifies that a type isincrementable, and pre- and post-operator-- for the type have common meaning.
      4) Specifies that a type is bothdecrementable andtotally_ordered, andoperator+=,operator-=,operator+, andoperator- among the type and its different type have common meaning.

      /*iterator*/ models

      However, it only satisfiesLegacyInputIterator ifW modelsincrementable, and does not satisfyLegacyInputIterator otherwise.

      Contents

      [edit]Semantic requirements

      3) TypeI modelsdecrementable only ifI satisfiesdecrementable and all concepts it subsumes are modeled, and given equal objectsa andb of typeI:
      • Ifa andb are in the domain of both pre- and post-operator-- (i.e. they are decrementable), then the following are alltrue:
      • Ifa andb are in the domain of both pre- and post-operator++ (i.e. they are incrementable), thenbool(--(++a)== b) istrue.
      4) LetD denote/*iota-diff-t*/<I>. TypeI modelsadvanceable only ifI satisfiesadvanceable and all concepts it subsumes are modeled, and given
      • objectsa andb of typeI and
      • valuen of typeD,

      such thatb is reachable froma aftern applications of++a, all following conditions are satisfied:

      • (a+= n) is equal tob.
      • std::addressof(a+= n) is equal tostd::addressof(a).
      • I(a+ n) is equal to(a+= n).
      • For any two positive valuesx andy of typeD, ifI(a+ D(x+ y)) is well-defined, thenI(a+ D(x+ y)) is equal toI(I(a+ x)+ y).
      • I(a+ D(0)) is equal toa.
      • IfI(a+ D(n-1)) is well-defined, thenI(a+ n) is equal to[](I c){return++c;}(I(a+ D(n-1))).
      • (b+=-n) is equal toa.
      • (b-= n) is equal toa.
      • std::addressof(b-= n) is equal tostd::addressof(b).
      • I(b- n) is equal to(b-= n).
      • D(b- a) is equal ton.
      • D(a- b) is equal toD(-n).
      • bool(a<= b) istrue.

      [edit]Nested types

      Type Definition
      iterator_concept aniterator tag, see below
      iterator_category
      (only present ifW modelsincrementable and
      /*iota-diff-t*/<W> is an integral type)
      std::input_iterator_tag
      value_typeW
      difference_type/*iota-diff-t*/<W>

      [edit]Determining the iterator concept

      iterator_concept is defined as follows:

      [edit]Data members

      Member Definition
      Wvalue_ the current value
      (exposition-only member object*)

      [edit]Member functions

      std::ranges::iota_view::iterator::iterator

      /*iterator*/() requiresstd::default_initializable<W>=default;
      (1)(since C++20)
      constexprexplicit/*iterator*/( W value);
      (2)(since C++20)
      1) Value initializesvalue_.
      2) Initializesvalue_ withvalue.

      std::ranges::iota_view::iterator::operator*

      constexpr W operator*()const
         noexcept(std::is_nothrow_copy_constructible_v<W>);
      (since C++20)

      Returnsvalue_.

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(6,9).begin()};constint& r=*it;// binds with temporaryassert(*it==6 and r==6);++it;assert(*it==7 and r==6);}

      std::ranges::iota_view::iterator::operator++

      constexpr/*iterator*/& operator++();
      (1)(since C++20)
      constexprvoid operator++(int);
      (2)(since C++20)
      constexpr/*iterator*/ operator++(int) requiresstd::incrementable<W>;
      (3)(since C++20)
      1) Equivalent to++value_ ;return*this;.
      2) Equivalent to++value_ ;.
      3) Equivalent toauto tmp=*this;++value_ ;return tmp;.

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(8).begin()};assert(*it==8);assert(*++it==9);assert(*it++==9);assert(*it==10);}

      std::ranges::iota_view::iterator::operator--

      constexpr/*iterator*/& operator--() requires/*decrementable*/<W>;
      (1)(since C++20)
      constexpr/*iterator*/operator--(int) requires/*decrementable*/<W>;
      (2)(since C++20)
      1) Equivalent to--value_ ;return*this;.
      2) Equivalent toauto tmp=*this;--value_ ;return tmp;.

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(8).begin()};assert(*it==8);assert(*--it==7);assert(*it--==7);assert(*it==6);}

      std::ranges::iota_view::iterator::operator+=

      constexpr/*iterator*/& operator+=( difference_type n)
          requires/*advanceable*/<W>;
      (since C++20)

      Updatesvalue_ and returns*this:

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(5).begin()};assert(*it==5);assert(*(it+=3)==8);}

      std::ranges::iota_view::iterator::operator-=

      constexpr/*iterator*/& operator-=( difference_type n)
          requires/*advanceable*/<W>;
      (since C++20)

      Updatesvalue_ and returns*this:

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(6).begin()};assert(*it==6);assert(*(it-=-3)==9);}

      std::ranges::iota_view::iterator::operator[]

      constexpr W operator[]( difference_type n)const
          requires/*advanceable*/<W>;
      (since C++20)

      ReturnsW(value_ + n).

      Example

      Run this code
      #include <cassert>#include <ranges> int main(){auto it{std::views::iota(6).begin()};assert(*it==6);assert(*(it+3)==9);}

      [edit]Non-member functions

      operator==, <, >, <=, >=, <=>(std::ranges::iota_view::iterator)

      friendconstexprbool operator==

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::equality_comparable<W>;
      (1)(since C++20)
      friendconstexprbool operator<

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::totally_ordered<W>;
      (2)(since C++20)
      friendconstexprbool operator>

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::totally_ordered<W>;
      (3)(since C++20)
      friendconstexprbool operator<=

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::totally_ordered<W>;
      (4)(since C++20)
      friendconstexprbool operator>=

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::totally_ordered<W>;
      (5)(since C++20)
      friendconstexprbool operator<=>

         (const/*iterator*/& x,const/*iterator*/& y)

          requiresstd::totally_ordered<W>&&std::three_way_comparable<W>;
      (6)(since C++20)
      1) Returnsx.value_ == y.value_.
      2) Returnsx.value_ < y.value_.
      3) Returnsy< x.
      4) Returns!(y< x).
      5) Returns!(x< y).
      6) Returnsx.value_ <=> y.value_.

      The!= operator issynthesized fromoperator==.

      These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.

      operator+(std::ranges::iota_view::iterator)

      friendconstexpr/*iterator*/ operator+

         (/*iterator*/ i, difference_type n)

          requires/*advanceable*/<W>;
      (1)(since C++20)
      friendconstexpr/*iterator*/ operator+

         ( difference_type n,/*iterator*/ i)

          requires/*advanceable*/<W>;
      (2)(since C++20)

      Equivalent toi+= n;return i;.

      These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.

      operator-(std::ranges::iota_view::iterator)

      friendconstexpr/*iterator*/ operator-

         (/*iterator*/ i, difference_type n)

          requires/*advanceable*/<W>;
      (1)(since C++20)
      friendconstexpr difference_type operator-

         (const/*iterator*/& x,const/*iterator*/& y)

          requires/*advanceable*/<W>;
      (2)(since C++20)
      1) Equivalent toi-= n;return i;.
      2) LetD bedifference_type:

      These functions are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup wheniterator is an associated class of the arguments.

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      P2259R1C++20memberiterator_category is always defineddefined only ifW satisfiesincrementable
      LWG 3580C++20bodies ofoperator+ andoperator- rule outimplicit movemade suitable for implicit move
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/iota_view/iterator&oldid=176931"

      [8]ページ先頭

      ©2009-2025 Movatter.jp