Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Concept BidirectionalIterator 雙向迭代器概念

BidirectionalIterator 雙向迭代器

Description 說明

A bidirectional iterator is an iterator that can read through a sequence of values. It can move in either direction through the sequence, and can be either mutable (data pointed to by it can be changed) or not mutable.
雙向迭代器是一種可以讀入一組值的序列的迭代器。它可以從兩個方向遍歷序列,可以是可寫的(所指數據可以改變)或不可寫的。

An iterator represents a position in a sequence. Therefore, the iterator can point into the sequence (returning a value when dereferenced and being incrementable), or be off-the-end (and not dereferenceable or incrementable).
迭代器表示了在一個序列中的某個位置。因此,迭代器可以指向序列內部(在提領時返回一個值且可以遞增),或者指向序列末端之後(不可提領且不可遞 增)

Refinement of 精化自

Associated types 關聯類型

  • value_type

    std::iterator_traits<Iter>::value_type

    The value type of the iterator
    迭代器的值類型

  • category

    std::iterator_traits<Iter>::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
類型 Iter 的對象
x
Object of type value_type
類型 value_type 的對象

Type expressions 類型表達式

Category tag 類別標記

category must be derived from std::bidirectional_iterator_tag.

category 必須派生自 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
i 是可遞增的(不是 off-the-end)且存在某個可提領的迭代器 j 滿足 i == ++j

   

Postdecrement

後綴遞減

i--

Iter

Same as for predecrement

與前綴遞減相同

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

等價於 {Iter j = i; --i; return j;}

i is dereferenceable or off-the-end
i 為可提領的或 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; must end up with the value of i unmodified, if i both of the operations in the pair are valid.

++i; --i;--i; ++i; 必須以原來的 i 值結束,如果 i 在兩個操作中均有效。

Models 模型

  • T *
  • std::list<T>::iterator

See also 參見


PrevUpHomeNext