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;
		}
	};
相关推荐
kakakahahahaha12 小时前
Windows笔记本重装系统的4种路径和风险边界
windows·电脑·笔记本电脑·内容运营·软件需求·重装系统
多弗朗皮卡丘15 小时前
数据结构4:链表(下)
c语言·数据结构·链表
自动化监测Learner15 小时前
Windows 自带搜索太慢?Everything 安装与使用指南,全盘文件秒搜
windows·everything
天机玄正19 小时前
云运维高阶二:CLI 调用 API (白名单追随)
windows·云原生
您^_^19 小时前
DeepSeek-Harness v0.1.5-alpha.1更新后旧会话打不开?5 步抢救 8MB 会话照抄
人工智能·windows·个人开发·deepseek v4 pro·deepseekharness
正仪19 小时前
systemd 是什么?
linux·运维·windows
小溪学编程20 小时前
Java ListIterator 接口详解:双向遍历与列表修改的利器
java·开发语言·windows
203号居民20 小时前
LeetCode hot 100 — 138. 随机链表的复制
算法·leetcode·链表
2601_9623649721 小时前
没有 TPM2.0,还能用 Windows Hello 摄像头吗?
windows·安全·电脑
江湖人称菠萝包1 天前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter9-对话框
windows·笔记