Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Concept InputIterator 輸入迭代器概念

InputIterator 輸入迭代器

Description 說明

An input iterator is an iterator that can read through a sequence of values. It is single-pass (old values of the iterator cannot be re-used), and read-only.
輸入迭代器是一種可以讀入一組值的序列的迭代器。它是單遍的(迭代器的舊值不可重用)和只讀的。

An input 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 (not necessarily what *i returns)
    迭代器的值類型(不一定是 *i 所返回的)

  • difference_type

    std::iterator_traits<Iter>::difference_type

    The difference 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 InputIterator 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::input_iterator_tag, a model of DefaultConstructible, and a model of CopyConstructible.

category 必須派生自 std::input_iterator_tag,且 可缺省構造可複製構造

Value type copy constructibility 值類型的可複製構造性

value_type must be a model of CopyConstructible.

value_type 必須為 可複製構造

Difference type properties 距離類型的屬性

difference_type must be a model of SignedInteger.

difference_type 必須為 有符號整數

Valid expressions 有效表達式

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

Dereference 提領

*i

Convertible to value_type

可轉換為 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++

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

Equivalent to (void)(++i)

等價於 (void)(++i)

i is dereferenceable or off-the-end

i 為可提領的或 off-the-end

Postincrement and dereference 後綴遞增並提領

*i++

Convertible to value_type
可轉換為 value_type

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

Equivalent to {value_type t = *i; ++i; return t;}

等價於 {value_type t = *i; ++i; return t;}

i is dereferenceable or off-the-end
i 為可提領的或 off-the-end

Complexity 複雜度

All iterator operations must take amortized constant time.
迭代器的所有操作必須為分期常量時間複雜度。

Models 模型

  • std::istream_iterator

See also 參見


PrevUpHomeNext