首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

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

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循环。
代码语言:txt
复制
 `a + n` `n + a`.

ItIt temp = a; return temp += n;

  • n可以是积极的,也可以是消极的
  • a + n == n + a
代码语言:txt
复制
`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)...
代码语言:txt
复制
`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 < bb < c然后a < c
  • a < bb < aa == b

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

代码语言:txt
复制
`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库
代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券