C++ 概念: RandomAccessIterator
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
一个
RandomAccessIterator是一个可移动的BidirectionalIterator指向任何元素在固定的时间.原文:
A
RandomAccessIterator is a BidirectionalIterator that can be moved to point to any element in constant time.一个标准的指针是一个类型,满足这个概念的一个例子.
原文:
A standard pointer is an example of a type that satisfies this concept.
[编辑] 要求
除上述要求外,类型
ItRandomAccessIterator,实例a,b,i和rIt必须:原文:
In addition to the above requirement, for a type
It to be an RandomAccessIterator, instances a, b, i, and r of It must:| Expression | Return | Equivalent expression | Notes |
|---|---|---|---|
| r += n | It& | if(n>=0) while(n--) ++r; |
|
| 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 > 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) |
[编辑] 表注意事项
It是实现这一概念的类型原文:Itis the type implementing this conceptreference是类型std::iterator_traits<It>::reference原文:referenceis the type std::iterator_traits<It>::referencedifference是类型std::iterator_traits<It>::difference_type原文:differenceis the type std::iterator_traits<It>::difference_typei,a,b类型的对象It或const It原文:i,a,bare objects of typeItorconst Itn是的整数类型difference
上述规则意味着RandomAccessIterator的实现
LessThanComparable.原文:
The above rules imply that RandomAccessIterator also implements
LessThanComparable.一个
mutable RandomAccessiterator是一个BidirectionalIterator,另外满足OutputIterator要求的.原文:
A
mutable RandomAccessiterator is a BidirectionalIterator that additionally satisfies the OutputIterator requirements.