反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
孞㐑¥2 分钟前
Linux之进程概念
linux·c++·经验分享·笔记
wen__xvn42 分钟前
每日一题洛谷T534125 合数c++
开发语言·c++
wen__xvn1 小时前
每日一题洛谷P8615 [蓝桥杯 2014 国 C] 拼接平方数c++
c++·职场和发展·蓝桥杯
刘梓谦1 小时前
Qt获取CPU使用率及内存占用大小
开发语言·c++·qt
珊瑚里的鱼1 小时前
第八讲 | stack和queue的使用及其模拟实现
开发语言·c++·笔记·visualstudio·stl·学习方法·visual studio
yong15858553432 小时前
[SIGPIPE 错误] 一个 Linux socket 程序,没有任何报错打印直接退出程序
linux·服务器·网络·c++
敲上瘾3 小时前
MySQL数据类型
数据库·c++·mysql·数据库开发·数据库架构
小陶来咯4 小时前
【高级IO】多路转接之单线程Reactor
服务器·网络·数据库·c++
C++实习生9 小时前
powerbuilder9.0中文版
c语言·c++
oioihoii10 小时前
C++23 std::generator:用于范围的同步协程生成器 (P2502R2, P2787R0)
开发语言·c++·c++23