r****t 发帖数: 10904 | 1 在本版前面看到师傅们说过,不过当时就有疑问:
为啥 pointers are iterators?
只是因为 iterator objects support pointers arithmetic 就这么说么?(比如
sequential containers 可以用一对 pointer 来初始化,这个是不是用的 overload
ctor 来实现的?)总觉得这样逻辑有点不通,倒像是 duck typing 的逻辑了。
还是有啥别的意思在里面? | t****t 发帖数: 6806 | 2 short answer: iterators are generalized pointers. so pointers, by definition
, are iterators.
long answer: there is no iterator "type" or pointer "type". iterator and
pointer are CONCEPTs, which are classes of types (that satisfy some
condition). pointer satisfy all the requirement of iterator so pointer is
iterator.
for implementation, anything suuport "iterator" (or some subclasses of
iterators) must be implemented with template (template is a set of
overloaded functions, so you are right, it is by "overload ctor"), since
iterator is not a single type.
【在 r****t 的大作中提到】 : 在本版前面看到师傅们说过,不过当时就有疑问: : 为啥 pointers are iterators? : 只是因为 iterator objects support pointers arithmetic 就这么说么?(比如 : sequential containers 可以用一对 pointer 来初始化,这个是不是用的 overload : ctor 来实现的?)总觉得这样逻辑有点不通,倒像是 duck typing 的逻辑了。 : 还是有啥别的意思在里面?
|
|