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;
		}
	};
相关推荐
CCPC不拿奖不改名3 小时前
大模型推理架构与开源生态知识整理
数据库·windows·python·架构·langchain·开源·github
王维同学5 小时前
[自学][Windows C++]RunOnceEx 注册表分组键的安全遍历
c++·windows·安全·开源
imatt9 小时前
Qt Creator 在Windows下编译信息乱码
windows·qt
就不掉头发10 小时前
计算机的虚拟内存
linux·服务器·windows
华玥作者10 小时前
uniapp 万条数据不卡顿:我写了个虚拟列表组件 hy-list,原生支持瀑布流
数据结构·uni-app·list·vue3
壹号用户12 小时前
c++入门之list了解及使用
数据结构·list
来一碗刘肉面12 小时前
什么是双端队列
数据结构·链表
春风霓裳12 小时前
window设置永不更新
windows
tkevinjd14 小时前
力扣148-排序链表
算法·leetcode·链表
luyun02020214 小时前
专防未成年,吾爱出品
网络·windows·figma