2005/11/01

Boost Concept RandomAccessIterator

Concept RandomAccessIterator

RandomAccessIterator

Description(描述)

一 个 random access iterator 是一个能够读取一个值序列的 iterator 。它可以沿着 sequence 的两个方向运动(一次移动任意距离都可以保证在 constant time 内),而且可以是 mutable (它所指向的数据可以被改变)或者是 not mutable 。

一个 iterator 表示一个 sequence 中的一个 position 。也就是说, iterator 能够指向 sequence 的内部(当 dereferenced 及被 incrementable 时,返回一个 value ),或者 off-the-end (不能 dereferenceable 或 incrementable )。

Refinement of(强化自)

Associated types(相关型别)

  • value_type

    std::iterator_traits::value_type

    The value type of the iterator

  • category

    std::iterator_traits::iterator_category

    The category of the iterator

  • difference_type

    std::iterator_traits::difference_type

    The difference type of the iterator (measure of the number of steps between two iterators)

Notation(符号)

Iter
A type playing the role of iterator-type in the RandomAccessIterator concept.
i, j
Objects of type Iter
x
Object of type value_type
n
Object of type difference_type
int_off
Object of type int

Type expressions

Category tag

category must be derived from std::random_access_iterator_tag.

Valid expressions(有效表达式)

Name Expression Type Semantics

Motion

i += n

Iter &

Equivalent to applying i++n times if n is positive, applying i---n times if n is negative, and to a null operation if n is zero.

Motion (with integer offset)

i += int_off

Iter &

Equivalent to applying i++n times if n is positive, applying i---n times if n is negative, and to a null operation if n is zero.

Subtractive motion

i -= n

Iter &

Equivalent to i+=(-n)

Subtractive motion (with integer offset)

i -= int_off

Iter &

Equivalent to i+=(-n)

Addition

i + n

Iter

Equivalent to {Iter j = i; j += n; return j;}

Addition with integer

i + int_off

Iter

Equivalent to {Iter j = i; j += n; return j;}

Addition (count first)

n + i

Iter

Equivalent to i + n

Addition with integer (count first)

int_off + i

Iter

Equivalent to i + n

Subtraction

i - n

Iter

Equivalent to i + (-n)

Subtraction with integer

i - int_off

Iter

Equivalent to i + (-n)

Distance

i - j

difference_type

The number of times i must be incremented (or decremented if the result is negative) to reach j. Not defined if j is not reachable from i.

Element access

i[n]

const-if-not-mutable value_type &

Equivalent to *(i + n)

Element access with integer index

i[int_off]

const-if-not-mutable value_type &

Equivalent to *(i + n)

Complexity(复杂度)

所有 iterator operations 必须是 amortized constant time 。

Models

  • T *
  • std::vector::iterator
  • std::vector::const_iterator
  • std::deque::iterator
  • std::deque::const_iterator

没有评论: