在线文档教程

RandomAccessIterator

C++概念:RandomAccessIterator

RandomAccessIteratorBidirectionalIterator可以移动到指向任何恒定时间内的元素。

指向数组元素的指针满足RandomAccessIterator...

所需

类型It满足RandomAccessIterator如果。

  • 类型It满足BidirectionalIterator还有,给予。

  • value_type,所表示的类型std::iterator_traits<It>::value_type

  • difference_type,所表示的类型std::iterator_traits<It>::difference_type

  • reference,所表示的类型std::iterator_traits<It>::reference

  • i,,,a,,,b,类型对象Itconst It

  • r,类型值It&

  • n,类型的整数difference_type

下列表达式必须有效并具有指定的效果。

ExpressionReturn typeOperational semanticsNotes
r += nIt&difference_type m = n; if (m >= 0) while (m--) ++r; else while (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 of n must be within the range of representable values of difference_type.
i - nItIt temp = i; return temp -= n;
b - adifference_typereturn n;Precondition: there exists a value n of type difference_type such that a+n==b Postcondition: b == a + (b - a).
inconvertible to reference*(i + n)
a < bcontextually convertible to boolb - a > 0Strict total ordering relation: !(a < a) if a < b then !(b < a) if a < b and b < c then a < c a < b or b < a or a == b (exactly one of the expressions is true)
a > bcontextually convertible to boolb < aTotal ordering relation opposite to a < b
a >= bcontextually convertible to bool!(a < b)
a <= bcontextually convertible to bool!(a > b)

  • n可以是积极的,也可以是消极的

  • 复杂性为常数%28,也就是说,实现不能实际执行操作语义%29中显示的while循环。

`a + n` `n + a`.

ItIt temp = a; return temp += n;

  • n可以是积极的,也可以是消极的

  • a + n == n + a

`r -= n` `It&` `return r += -n;` The absolute value of `n` must be within the range of representable values of `difference_type`. `i - n` `It` `It temp = i; return temp -= n;` `b - a` `difference_type` `return n;` Precondition:

  • 有一个值n类型difference_type使...a+n==b邮政条件:

  • b == a + (b - a)...

`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)

  • 如果a < b和b < c然后a < c

  • a < b或b < a或a == b

%28其中一个表达式为真%29

`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)`

上述规则意味着RandomAccessIterator还实现LessThanComparable...

mutable RandomAccessIteratorRandomAccessIterator,它还能满足OutputIterator所需经费。

另见

  • Iterator库

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cpPreference.com/w/cpp/Concept/RandomAccessIterator