RandomAccessIterator
阿RandomAccessIterator是BidirectionalIterator可以移动到指向任何恒定时间内的元素。
指向数组元素的指针满足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,类型对象It或const It
r,类型值It&
n,类型的整数difference_type
下列表达式必须有效并具有指定的效果。
Expression | Return type | Operational semantics | Notes | |
|---|---|---|---|---|
r += n | It& | 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. | It | It temp = a; return temp += n; | n can be both positive or negative 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: there exists a value n of type difference_type such that a+n==b Postcondition: b == a + (b - a). | |
in | convertible to reference | *(i + n) | | |
a < b | contextually convertible to bool | b - a > 0 | Strict 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 > 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) | |
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 RandomAccessIterator是RandomAccessIterator,它还能满足OutputIterator所需经费。
另见
- Iterator库
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

