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;
		}
	};
相关推荐
我爱吃福鼎肉片1 小时前
【C++】——list
c++·vector·list
充值内卷3 小时前
WPF入门教学四 WPF控件概述
windows·ui·wpf
ahauedu8 小时前
案例分析-Stream List 中取出值最大的前 5 个和最小的 5 个值
数据结构·list
Navigator_Z15 小时前
数据结构C //线性表(链表)ADT结构及相关函数
c语言·数据结构·算法·链表
程序猿小D16 小时前
第二百三十五节 JPA教程 - JPA Lob列示例
java·数据库·windows·oracle·jdk·jpa
iummature18 小时前
ZLMediaKit Windows编译以及使用
windows
周伯通*21 小时前
Windows上,使用远程桌面连接Ubuntu
linux·windows·ubuntu
蠢蠢的打码21 小时前
8584 循环队列的基本操作
数据结构·c++·算法·链表·图论
GDAL1 天前
GNU力量注入Windows:打造高效跨平台开发新纪元
服务器·windows·gnu
薯条不要番茄酱1 天前
数据结构-3.链表
数据结构·链表