反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
_F_y4 小时前
MySQL用C/C++连接
c语言·c++·mysql
兩尛4 小时前
c++知识点2
开发语言·c++
xiaoye-duck4 小时前
C++ string 底层原理深度解析 + 模拟实现(下)——面试 / 开发都适用
开发语言·c++·stl
Azure_withyou5 小时前
Visual Studio中try catch()还未执行,throw后便报错
c++·visual studio
琉染云月5 小时前
【C++入门练习软件推荐】Visual Studio下载与安装(以Visual Studio2026为例)
c++·visual studio
L_09077 小时前
【C++】高阶数据结构 -- 红黑树
数据结构·c++
智者知已应修善业10 小时前
【查找字符最大下标以*符号分割以**结束】2024-12-24
c语言·c++·经验分享·笔记·算法
91刘仁德10 小时前
c++类和对象(下)
c语言·jvm·c++·经验分享·笔记·算法
diediedei11 小时前
模板编译期类型检查
开发语言·c++·算法
mmz120711 小时前
分治算法(c++)
c++·算法