如下图,end()和rbegin()两个迭代器内部的指针起始是一样的,区别在于方向不同,导致取的值不同;
因此通过调用reverse_iterator的构造函数,将正向迭代器保存到cunrrent中,当真正调用*,++等等成员函数时,对保存的current加以改造
使用方式:
vector<int> v;
...
v.rbegin();
- inserter iterator:
There are three insert iterators: inserter(c, it); back_inserter©, front_inserter©;
they all use data members to save the underlying container c (inserter also saves an additional insertion position it), and overload operator= , When assigning values to these three iterators, insert, push_back, and push_front are called respectively on the underlying container. For other ++, * and other operations, it just returns back_insert_iterator itself directly, and does nothing else;
下图中在copy算法中对第三参数resuly做的事情:*, =, ++操作
operator*不做任何事情,直接返回本身
operator=会对底层容器调用insert操作
operator++不做任何事情,直接返回本身
- stream_iterator:istream_iterator和ostream_iteraor
ostream_iterator<int> out_it(cout, ",");
如下图,operator*,operator++同样不做任何事情,只有operator=内分别对保存的数据成员调用<<
istream_iterator<double> eos;
istream_iterator<double> iit(cin);