RandomAccessIterator
C++概念: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`.
It
It 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。
http://en.cpPreference.com/w/cpp/Concept/RandomAccessIterator