Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:LegacyForwardIterator

      From cppreference.com
      <cpp‎ |named req
       
       
      C++ named requirements
       

      ALegacyForwardIterator is aLegacyIterator that can read data from the pointed-to element.

      UnlikeLegacyInputIterator andLegacyOutputIterator, it can be used in multipass algorithms.

      If aLegacyForwardIteratorit originates from aContainer, thenit's value type is the same as the container's, so dereferencing (*it) obtains the container's value type.

      Contents

      [edit]Requirements

      Type Definition
      X A forward iterator type
      T Thevalue type ofX (i.e.std::iterator_traits<X>::value_type)
      Refstd::iterator_traits<X>::reference
      Value Definition
      i,j Values of typeX orconst X
      r A value of typeX&

      X satisfiesLegacyForwardIterator if all following conditions are satisfied:

      • X satisfiesLegacyInputIterator.
      • X satisfiesDefaultConstructible.
      • IfX is amutable iterator,Ref is a reference toT.
      • IfX is a constant iterator,Ref is a reference toconst T.
      • Objects of the typeX providemulti-pass guarantee.
      • Ifi andj are equal, then eitheri andj are bothdereferenceable or else neither is dereferenceable.
      • Ifi andj are both dereferenceable, theni== j if and only if*i and*j are bound to the same object.
      • The following expressions must be valid and have their specified effects:
       Expression TypeEffects
      r++convertible toconst X& Equivalent toX x= r;
      ++r;
      return x;
      .
      *i++Ref

      [edit]Equality domain

      Thedomain of== for forward iterators is that of iterators over the sameunderlying sequence.

      However,value-initialized forward iterators can be compared, and must compare equal to other value-initialized iterators of the same type.

      In other words, value-initialized forward iterators behave as if they refer past the end of the same empty sequence.

      (since C++14)

      [edit]Multi-pass guarantee

      Two dereferenceable iteratorsa andb of typeX offer themulti-pass guarantee if all following conditions are satisfied:

      • a== b implies++a==++b.
      • Any of the following conditions is satisfied:
      • X is a pointer type.
      • The expression(void)++X(a),*a is equivalent to the expression*a.

      Concept

      For the definition ofstd::iterator_traits, the following exposition-only concept is defined.

      template<class It>

      concept __LegacyForwardIterator=
          __LegacyInputIterator<It>&&std::constructible_from<It>&&
         std::is_reference_v<std::iter_reference_t<It>>&&
         std::same_as<
             std::remove_cvref_t<std::iter_reference_t<It>>,
             typenamestd::indirectly_readable_traits<It>::value_type>&&
          requires(It it){
             {  it++}->std::convertible_to<const It&>;
             {*it++}->std::same_as<std::iter_reference_t<It>>;

         };

      where the exposition-only concept__LegacyInputIterator<T> is described inLegacyInputIterator.

      (since C++20)

      [edit]Notes

      Unlike thestd::forward_iterator concept, theLegacyForwardIterator requirements requires dereference to return a reference.

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 1212
      (N3066)
      C++98the type of*i++ did not match the type of
      *i-- required byLegacyBidirectionalIterator
      changed the
      type toRef
      LWG 1311
      (N3066)
      C++98a== b implies++a==++b” alone
      did not offer multipass guarantee[1]
      also requires “a== b
      implies++a!= b[2]
      LWG 3798C++20__LegacyForwardIterator required
      std::iter_reference_t<It> to be an lvalue reference type
      also allows rvalue
      reference types
      1. In the scenario wherea andb use the same underlying iterator, evaluating the expression++a==++b actually increments the underlying container twice, but the result is stilltrue.
      2. Formally also requires implying++b!= a.

      [edit]See also

      specifies that aninput_iterator is a forward iterator, supporting equality comparison and multi-pass
      (concept)[edit]
      Iterator library provides definitions for iterators, iterator traits, adaptors, and utility functions
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/named_req/ForwardIterator&oldid=172455"

      [8]ページ先頭

      ©2009-2025 Movatter.jp