[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/concept/RandomAccessIterator [Back]  [Original]

C++: RandomAccessIterator cppreference.com
cppreference.com

C++: RandomAccessIterator

cppreference.com

<metanoindex/>

RandomAccessIterator BidirectionalIterator , .
:
A RandomAccessIterator is a BidirectionalIterator that can be moved to point to any element in constant time.
Google.
. .
, .
:
A standard pointer is an example of a type that satisfies this concept.
Google.
. .

, It RandomAccessIterator, a, b, i, r It :
:
In addition to the above requirement, for a type It to be an RandomAccessIterator, instances a, b, i, and r of It must:
Google.
. .
Expression Return Equivalent expression Notes
r += n It& if(n>=0) while(n--) ++r; else while(n++) --r; return r;
  • n ,
    :
    n can be both positive or negative
    Google.
    . .
  • ( , )
    :
    Constant complexity (that is, the equivalent expression cannot be used as implementation)
    Google.
    . .
i + n It It temp = i; return temp += n;
n + i It i + n
r -= n It& return r += -n;
i - n It It temp = i; return temp -= n;
n - i It i - n
b - a difference n returns n such that a+n==b
i[n] convertible to reference *(i + n)
a < b contextually convertible to bool b - a > 0 Strict total ordering relation:
  • !(a < a)
  • a < b !(b < a)
    :
    if a < b then !(b < a)
    Google.
    . .
  • a < b b < c a < c
    :
    if a < b and b < c then a < c
    Google.
    . .
  • a < b b < a a == b
    ( )
    :
    a < b or b < a or a == b
    (exactly one of the expressions is true)
    Google.
    . .
a > b contextually convertible to bool b < a Total ordering relation opposite to a < b
a >= b contextually convertible to bool !(a < b)
a <= b contextually convertible to bool !(a > b)

Notes

  • It
    :
    It is the type implementing this concept
    Google.
    . .
  • T std::iterator_traits<It>::value_type
    :
    T is the type std::iterator_traits<It>::value_type
    Google.
    . .
  • reference std::iterator_traits<It>::reference
    :
    reference is the type std::iterator_traits<It>::reference
    Google.
    . .
  • difference std::iterator_traits<It>::difference_type
    :
    difference is the type std::iterator_traits<It>::difference_type
    Google.
    . .
  • i, a, b It const It
    :
    i, a, b are objects of type It or const It
    Google.
    . .
  • r It&
    :
    r is a value of type It&
    Google.
    . .
  • n difference
    :
    n is an integer of type difference
    Google.
    . .
, RandomAccessIterator LessThanComparable.
:
The above rules imply that RandomAccessIterator also implements LessThanComparable.
Google.
. .
mutable RandomAccessiterator BidirectionalIterator, OutputIterator.
:
A mutable RandomAccessiterator is a BidirectionalIterator that additionally satisfies the OutputIterator requirements.
Google.
. .

Web Proxy Viewer  |  New URL  |  Original Page