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;
		}
	};
相关推荐
依旧阳光的老码农3 小时前
Windows下使用 VS Code + g++ 开发 Qt GUI 项目的完整指南
开发语言·windows·qt
tanyongxi663 小时前
手撕C++STL list:深入理解双向链表的实现
开发语言·c++·链表
老兵发新帖7 小时前
pnpm install报错:此系统上禁止运行脚本
windows
zhishishe10 小时前
2025 年免费 Word 转 PDF 转换器有哪些?
android·windows·pdf·电脑·word
zhishishe18 小时前
工具指南:免费将 PDF 转换为 Word 的 10 个工具
android·windows·pdf·word
hy.z_77718 小时前
【数据结构】线性表( List)和 顺序表(ArrayList)
数据结构·list
h397418 小时前
MFC文件-写MP4
c++·windows·音视频·mfc
xiaowu08019 小时前
C# 使用Windows API实现键盘钩子的类
windows·c#·计算机外设
love530love19 小时前
PyCharm 链接 Podman Desktop 的 podman-machine-default Linux 虚拟环境
linux·运维·windows·pycharm·podman
人猿泰飞1 天前
【AI训练环境搭建】在Windows11上搭建WSL2+Ubuntu22.04+Tensorflow+GPU机器学习训练环境
windows·ubuntu·机器学习·wsl·gpu训练