Iterators and Iterator Types

C++ Primer 4/e 在Iterators這裡有一個術語:『When first encountered, the nomenclature around iterators can be confusing. In part the confusion arises because the same term, iterator, is used to refer to two things. We speak generally of the concept of an iterator, and we speak specifically of a concrete iterator type defined by a container, such as vector<int>.

What’s important to understand is that there is a collection of types that serve as iterators. These types are related conceptually. We refer to a type as an iterator if it supports a certain set of actions. Those actions let us navigate among the elements of a container and let us access the value of those elements.

Each container class defines its own iterator type that can be used to access the elements in the container. That is, each container defines a type named iterator, and that type supports the actions of an (conceptual) iterator.』

中文版的是這樣說:『第一次遭遇術語iterators時可能會感到困惑。部份原因是同一個術語iterator可用來指兩件事。可以指一般的iterator概念,也可以指某容器(例如vector<int>)所定義的具象iterator型別。

一件必須瞭解的重要事情是,有一大群型別可作為iterators使用。這些型別在概念上彼此關聯。當一個型別支援某「特定動作集」時我們稱它為iterator;它讓我們得以尋訪容器元素並存取元素值。

每個做為容器的class都定義有自己的iterator型別,可用來存取容器元素。也就是說每個容器都定意有一個名為iterator的型別,該型別支援(概念上的)iterator所能採取的動作。』

什麼叫具象?我太淺了,看不懂。

感謝你看到這裡,很快就可以離開了,但最好的獎勵行動就是按一下幫我分享或留言,感恩喔~

點我分享到Facebook

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *