理解iterator
来源:互联网 发布:上交所待遇知乎 编辑:程序博客网 时间:2024/05/19 00:13
参考:http://www.cplusplus.com/reference/std/iterator/iterator/
// iterator example#include <iostream>#include <iterator>using namespace std;class myiterator : public iterator<input_iterator_tag, int>{int* p;public:myiterator(int* x) :p(x) {}myiterator(const myiterator& mit) : p(mit.p) {}myiterator& operator++() {++p;return *this;}myiterator operator++(int) {myiterator tmp(*this); operator++(); return tmp;}bool operator==(const myiterator& rhs) {return p==rhs.p;}bool operator!=(const myiterator& rhs) {return p!=rhs.p;}int& operator*() {return *p;}};int main () {int numbers[]={10,20,30,40,50};myiterator beginning(numbers);myiterator end(numbers+5);for (myiterator it=beginning; it!=end; it++)cout << *it << " ";cout << endl;return 0;}//Output: 10 20 30 40 50
MSDN中的iterator
iteratortemplate<class C, class T, class Dist = ptrdiff_t>struct iterator { typedef C iterator_category; typedef T value_type; typedef Dist distance_type;};The template class serves as a base type for all iterators. It defines the member types iterator_category (a synonym(synonym同义词) for the template parameter C), value_type (a synonym for the template parameter T), and distance_type (a synonym for the template parameter Dist).
表示iterator是其他所有迭代器的一个基本类型。
来自http://www.cplusplus.com/reference/std/iterator/iterator/中的iteratoriterator 是一个类模板。This is a base class template that can be used to derive iterator classes from it. It is not an iterator class and does not provide any of the functionality an iterator is expected to have.
This base class only provides some member types, which in fact are not required to be present in any iterator type (iterator types have no specific member requirements), but they might be useful, since they define the members needed for the default iterator_traits class template to generate the appropriate iterator_traits class automatically.
iterator的定义如下:
template <class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> struct iterator { typedef T value_type; typedef Distance difference_type; typedef Pointer pointer; typedef Reference reference; typedef Category iterator_category; };参数说明如下:
请参见本文最上面的例子。
- 理解iterator
- Iterator理解
- 深入理解Iterator模式
- Struts2 中的Iterator理解
- iterator个人理解
- 设计模式-Iterator理解
- java迭代器Iterator的理解
- Python中iterator的理解
- java集合遍历 Iterator理解
- 深入理解 C++迭代器 iterator
- 深入理解Java的迭代器Iterator
- 工作积累之Iterator模式理解
- 关于foreach、Iterable、Iterator的一点理解
- Java深入理解 - 迭代器 Iterator 总结
- Java列表迭代器Iterator的理解
- java迭代器(Iterator)的理解
- Iterator
- Iterator
- sqlserver 重新设计数据库表结构
- 在unicode环境下将CString类型转换成char
- web.config 连接sql
- 静态循环链表【数组】
- Eclipse3.7中搭建Android开发环境
- 理解iterator
- sql 转换成xml语言(转)
- DataSet与DataAdapter初步
- 《那些年啊,那些事——一个程序员的奋斗史》——96
- JSP页面查询显示常用模式
- 是什么浪费了我的时间
- for循环中声明变量的一个问题回顾
- SQL Server 返回最后插入记录的自动编号ID (Java语言)
- ie6 滤镜问题