反向迭代器 模拟

反向迭代器 模拟

cpp 复制代码
namespace sjy
{
	template <typename Iterator, typename Ref, typename Ptr>
	struct Reverse_iterator  
	{
		typedef Reverse_iterator<Iterator, Ref, Ptr> self;
		Reverse_iterator(Iterator it)
			:_it(it)
		{}
		
		bool operator!=(const self& other) const
		{
			return _it != other._it;
		}
		
		bool operator==(const self& other) const
		{
			return _it == other._it;
		}
		
		self& operator++()
		{
			--_it;
			return *this;
		}
		
		self& operator--()
		{
			++_it;
			return *this;
		}
		
		Ref operator*()
		{
			Iterator tmp(_it);
			return *(--tmp);
		}
		
		Ptr operator->()
		{
			return &(operator*());
		}
		
		/*成员变量*/
		Iterator _it;
	};
}
相关推荐
Demon--hx1 小时前
设计不能被继承的类
开发语言·c++
兔兔兔兔11 小时前
记录C++ 13
开发语言·c++·算法
开心大爆炸2 小时前
ubuntu20.4 安装ros1 noetic版本流程
c++
欧特克_Glodon5 小时前
OpenCV计算机视觉开发入门与实践<二十四>:几何变换之平移、缩放、旋转
c++·人工智能·opencv·计算机视觉
鱼很腾apoc5 小时前
【Linux】第13期 详解应用层协议HTTP+Cookie/Session+HTTPS
linux·服务器·c++·学习·http·https
charlie1145141915 小时前
deque、list 与 forward_list:vector 之外的三个选择
开发语言·数据结构·c++·list·开源项目
Escalating_xu6 小时前
【C++ string 上篇】从字符串基础到容量管理、迭代器与经典算法题
java·c++·算法
啦啦啦啦啦zzzz6 小时前
ET和LT详解
linux·运维·服务器·网络·c++·网络编程
skr爱码士6 小时前
10_Qt Designer 与 UI 文件(.ui 原理、uic 编译、动态加载)
c++·qt·ui·客户端
程与留7 小时前
11_常用控件速查(上):QPushButton、QLabel、QLineEdit、QComboBox
c++·qt