反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
纪念 2299 分钟前
C++算法(六)
开发语言·c++·算法
ShineWinsu38 分钟前
对于Qt:QCheckBox常见属性的详细解析
c++·qt·面试·笔试·gui·qcheckbox·多选框
AI的探索之旅1 小时前
97 个 OpenCV 实例(三十七):二维码识别,一张图四个码的陷阱
c++·opencv·计算机视觉
UIU1142 小时前
P16237 [蓝桥杯 2026 省 B] 应急布线
数据结构·c++·算法·蓝桥杯
raindayinrain2 小时前
c++设计模式
开发语言·c++·设计模式
旖旎夜光2 小时前
LeetCode 315: 算右侧小于当前元素的个数(归并排序) —— 题解
c++·学习·算法·leetcode·排序算法
D e re k ZH2 小时前
保序回归:从 PAVA 到可并堆的单调约束优化
c++·算法·数据挖掘·回归·kotlin
青少儿编程课堂2 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:字典树前缀树与单词检索统计
c++·python·算法·bfs·信息学竞赛
octopus_c3 小时前
C++ 运算符重载详解 && 日期类的实现
开发语言·c++
青少儿编程课堂3 小时前
2026蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:堆排序与优先队列解析
c++·python·算法·bfs·信息学竞赛