Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      C++ named requirements:LegacyRandomAccessIterator

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

      ALegacyRandomAccessIterator is aLegacyBidirectionalIterator that can be moved to point to any element in constant time.

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

      A pointer to an element of an array satisfies all requirements ofLegacyRandomAccessIterator.

      Contents

      [edit]Requirements

      The typeIt satisfiesLegacyRandomAccessIterator if

      And, given

      • value_type, the type denoted bystd::iterator_traits<It>::value_type
      • difference_type, the type denoted bystd::iterator_traits<It>::difference_type
      • reference, the type denoted bystd::iterator_traits<It>::reference
      • i,a,b, objects of typeIt orconst It
      • r, an lvalue of typeIt
      • n, an integer of typedifference_type

      The following expressions must be valid and have their specified effects:

      ExpressionReturn typeOperational semanticsNotes
      r+= nIt&difference_type m= n;

      if(m>=0)while(m--)++r;
      elsewhile(m++)--r;
      return r;

      • n can be both positive or negative
      • The complexity is constant (that is, the implementation cannot actually execute the while loop shown in operational semantics)
      a+ n

      n+ a

      ItIt temp= a;

      return temp+= n;

      • n can be both positive or negative
      • a+ n== n+ a
      r-= nIt&return r+=-n;The absolute value ofn must be within the range of representable values ofdifference_type.
      i- nItIt temp= i;
      return temp-= n;
      b- adifference_typereturn n;
      (see the precondition)

      Precondition:

      • there exists a valuen of typedifference_type such thata+ n== b

      Postcondition:

      • b== a+(b- a).
      i[n]convertible toreference*(i+ n)
      a< b

      meetsBooleanTestable

      (until C++20)

      modelsboolean-testable

      (since C++20)
      Equivalent toreturn b- a>0;Precondition:
      • same as ofb- a

      Strict total ordering relation:

      • !(a< a)
      • ifa< b then!(b< a)
      • ifa< b andb< c thena< c
      • a< b orb< a ora== b
        (exactly one of the expressions is true)
      a> b

      meetsBooleanTestable

      (until C++20)

      modelsboolean-testable

      (since C++20)
      b< aTotal ordering relation opposite toa< b
      a>= b

      meetsBooleanTestable

      (until C++20)

      modelsboolean-testable

      (since C++20)
      !(a< b)
      a<= b

      meetsBooleanTestable

      (until C++20)

      modelsboolean-testable

      (since C++20)
      !(a> b)

      The above rules imply thatLegacyRandomAccessIterator also implementsLessThanComparable.

      AmutableLegacyRandomAccessIterator is aLegacyRandomAccessIterator that additionally satisfies theLegacyOutputIterator requirements.

      Concept

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

      template<class I>

      concept __LegacyRandomAccessIterator=
          __LegacyBidirectionalIterator<I>&&std::totally_ordered<I>&&
              requires(I i,typenamestd::incrementable_traits<I>::difference_type n)
             {
                 { i+= n}->std::same_as<I&>;
                 { i-= n}->std::same_as<I&>;
                 { i+  n}->std::same_as<I>;
                 { n+  i}->std::same_as<I>;
                 { i-  n}->std::same_as<I>;
                 { i-  i}->std::same_as<decltype(n)>;
                 {  i[n]  }->std::convertible_to<std::iter_reference_t<I>>;

             };

      where the exposition-only concept__LegacyBidirectionalIterator is described inLegacyBidirectionalIterator.

      (since C++20)

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 299
      (N3066)
      C++98the return type ofa[n] was required
      to be convertible toconst value_type&
      the return type is required to
      be convertible toreference
      LWG 448C++98the return type ofa[n] was required
      to be convertible tovalue_type
      the return type is required to be
      convertible toconst value_type&[1]
      LWG 1079C++98b- a was defined usinga< b,
      resulted in circular definition
      removeda< b from the definition
      LWG 2114
      (P2167R3)
      C++98convertibility tobool was too weak to reflect the expectation of implementationsrequirements strengthened
      1. LWG issue 299 was reopened after this resolution.

      [edit]See also

      specifies that abidirectional_iterator is a random-access iterator, supporting advancement in constant time and subscripting
      (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/RandomAccessIterator&oldid=175935"

      [8]ページ先頭

      ©2009-2025 Movatter.jp