<iterator>

std::forward_iterator_tag

struct forward_iterator_tag {};
Forward iterator category
Empty class to identify the category of an iterator as a forward iterator

Forward iterators


Forward iterators are iterators that can be used to access the sequence of elements in a range in the direction that goes from its beginning towards its end.

Performing operations on a forward iterator that is dereferenceable never makes its iterator value non-dereferenceable. This enables algorithms that use this category of iterators to use multiple copies of an iterator to pass more than once by the same iterator values.

All bidirectional and random-access iterators are also valid forward iterators.

There is not a single type of forward iterator: Each container may define its own specific iterator type able to iterate through it and access its elements. But all forward iterators support -at least- the following operations

属性有效的表达式
可以默认构造拷贝构造拷贝赋值析构X a;
X b(a);
b = a;
可以使用相等/不等运算符进行等价比较
(当两个迭代器值指向相同的底层序列时才有意义)。
a == b
a != b
可以作为右值解引用(如果处于可解引用状态)。*a
a->m
对于可变迭代器非 const 迭代器
可以作为左值解引用(如果处于可解引用状态)。
*a = t
可以递增(如果处于可解引用状态)。
结果是也可解引用越界迭代器。
Two iterators that compare equal, keep comparing equal when both are increased.
++a
a++
*a++
属性有效的表达式
可以默认构造拷贝构造拷贝赋值析构X a;
X b(a);
b = a;
可以使用相等/不等运算符进行等价比较
(当两个迭代器值指向相同的底层序列时才有意义)。
a == b
a != b
可以作为右值解引用(如果处于可解引用状态)。*a
a->m
对于可变迭代器非 const 迭代器
可以作为左值解引用(如果处于可解引用状态)。
*a = t
可以递增(如果处于可解引用状态)。
结果是也可解引用越界迭代器。
Two iterators that compare equal, keep comparing equal when both are increased.
++a
a++
*a++
左值是可交换的swap(a,b)

Where X is a forward iterator type, a and b are objects of this iterator type, and t is an object of the type pointed by the iterator type (or some other type that can be assigned to the lvalue returned by dereferencing an object of type X).

常量迭代器 是不满足输出迭代器要求的迭代器;解引用它们会得到对常量元素的引用(例如 const T&)。

These properties are the same as those of bidirectional iterators, except that forward iterators only support being incremented (but not decreased).

另见