2005/10/31

Boost Concept BidirectionalIterator

Concept BidirectionalIterator

BidirectionalIterator

Description(描述)

一个 bidirectional iterator 是一个能够读取一个值序列的 iterator 。它可以在 sequence 中沿两个方向运动,既可以是 mutable (它所指向的内容可以被改变)也可以是 not mutable 。

一 个 iterator 表示一个 sequence 中的一个 position 。也就是说, iterator 可以指向 sequence 的内部(当 dereference 及被 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

Notation(符号)

Iter
A type playing the role of iterator-type in the BidirectionalIterator concept.
i, j
Objects of type Iter
x
Object of type value_type

Type expressions

Category tag

category must be derived from std::bidirectional_iterator_tag.

Valid expressions(有效表达式)

Name Expression Type Precondition Semantics Postcondition

Predecrement

--i

Iter &

i is incrementable (not off-the-end) and some dereferenceable iterator j exists such that i == ++j

Postdecrement

i--

Iter

Same as for predecrement

Equivalent to {Iter j = i; --i; return j;}

i is dereferenceable or off-the-end

Complexity(复杂度)

All iterator operations must take amortized constant time.

Invariants

Predecrement must return object

&i = &(--i)

Unique path through sequence

i == j implies --i == --j

Increment and decrement are inverses

++i; --i; and --i; ++i; 如果 i 的两个 operations 都合法,就必须保证 i 的值没有改变。

Models

  • T *
  • std::list::iterator

没有评论: