list双向链表迭代器的实现

cpp 复制代码
// typedef __list_iterator<T, T&, T*> iterator;
	// typedef __list_iterator<T, const T&, const T*> const_iterator;
	template<class T, class Ref, class Ptr>
	struct __list_iterator
	{
		typedef list_node<T> Node;
		typedef __list_iterator<T, Ref, Ptr> self;
		Node* _node;

		__list_iterator(Node* node)
			:_node(node)
		{}

		Ref operator*()
		{
			return _node->_val;
		}

		Ptr operator->()
		{
			return &_node->_val;
		}

		self& operator++()
		{
			_node = _node->_next;
			return *this;
		}

		self operator++(int)
		{
			self tmp(*this);

			_node = _node->_next;

			return tmp;
		}

		self& operator--()
		{
			_node = _node->_prev;
			return *this;
		}

		self operator--(int)
		{
			self tmp(*this);

			_node = _node->_prev;

			return tmp;
		}

		bool operator!=(const self& it) const
		{
			return _node != it._node;
		}

		bool operator==(const self& it) const
		{
			return _node == it._node;
		}
	};
相关推荐
前路不黑暗@2 小时前
Java:继承与多态
java·开发语言·windows·经验分享·笔记·学习·学习方法
吴名氏.3 小时前
细数Java中List的10个坑
java·开发语言·数据结构·list
酷柚易汛智推官4 小时前
Windows 10 停服下的国产化迁移:统信 UOS 工具核心技术深度解析
windows·操作系统·酷柚易汛
光芒再现dev5 小时前
Win10/Win11文件夹图片不能预览怎么解决?
windows
lingggggaaaa5 小时前
小迪安全v2023学习笔记(一百四十三讲)—— Win系统权限提升篇&AD内网域控&NetLogon&ADCS&PAC&KDC&CVE漏洞
windows·笔记·学习·安全·内网安全·权限提升
低头不见7 小时前
策略模式上下文管理
windows·python·策略模式
电脑小管家7 小时前
笔记本蓝牙怎么开启 完整教程
windows·驱动开发·计算机外设·电脑·音频
懒羊羊不懒@8 小时前
JavaSe—List集合系列
java·开发语言·数据结构·人工智能·windows
碎像19 小时前
Windows系统暂停强制更新的操作(超详细说明)
windows
chian-ocean1 天前
双向链表的“链”与“殇”——Rust LinkedList 的深度剖析、实战与再思考
数据结构·链表·rust