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;
		}
	};
相关推荐
Surpass-HC11 分钟前
wav-pcm格式
windows·pcm
还是奇怪14 分钟前
Python第四课:循环与数据结构深度解析
数据结构·windows·python·青少年编程·循环
Yu_摆摆15 分钟前
windows安装SonarQube最新版本+SonarScanner搭建运行python项目代码分析
windows
WTCLLB33 分钟前
取消文件隐藏属性,找到winre.wim和boot.sdi
windows·学习
踩坑记录38 分钟前
leetcode hot100 25. K 个一组翻转链表 hard
leetcode·链表
nhfc991 小时前
Gitlab备份且提交Windows服务器数据
服务器·windows·gitlab
康小庄1 小时前
List线程不安全解决办法和适用场景
java·数据结构·spring boot·spring·list·intellij-idea
阿昭L1 小时前
Windows SEH机制(二)
windows
存在即合理L2 小时前
Windows中安装Anaconda后如何在powershell使用conda activate命令
windows·conda
l1t2 小时前
在Windows的WSL中试用GizmoSQL UI连接GizmoSQL数据库服务器
数据库·windows·ui