Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Concept ForwardIterator 前向迭代器概念

ForwardIterator 前向迭代器

Description 說明

A forward iterator is an iterator that can read through a sequence of values. It is multi-pass (old values of the iterator can be re-used), 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 ForwardIterator concept.cc 雙
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::forward_iterator_tag.

category 必須派生自 std::forward_iterator_tag。

Valid expressions 有效表達式

Name 名字 Expression 表達式 Type 類型 Precondition 前置條件 Semantics 語義 Postcondition 後置條件

Dereference 提領

*i

const-if-not-mutable value_type &

i is incrementable (not off-the-end)
i 是可遞增的(不是 off-the-end)

   

Member access 成員訪問

i->{member-name} (return type is pointer-to-object type)(返回類型為對像指針類型)

const-if-not-mutable value_type *

i is incrementable (not off-the-end)
i 是可遞增的(不是 off-the-end)

   

Preincrement

前綴遞增

++i

Iter &

i is incrementable (not off-the-end)
i 是可遞增的(不是 off-the-end)

   

Postincrement

後綴遞增

i++

Iter

i is incrementable (not off-the-end)
i 是可遞增的(不是 off-the-end)

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

Models 模型

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

See also 參見


PrevUpHomeNext