反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
Lenyiin1 小时前
《 C++ 点滴漫谈: 四十 》文本的艺术:C++ 正则表达式的高效应用之道
c++·正则表达式·lenyiin
yxc_inspire3 小时前
基于Qt的app开发第十三天
c++·qt·app·tcp·面向对象
虾球xz3 小时前
CppCon 2015 学习:Concurrency TS Editor’s Report
开发语言·c++·学习
潇-xiao3 小时前
Qt 按钮类控件(Push Button 与 Radio Button)(1)
c++·qt
板鸭〈小号〉4 小时前
命名管道实现本地通信
开发语言·c++
YKPG5 小时前
C++学习-入门到精通【14】标准库算法
c++·学习·算法
zm5 小时前
极限复习c++
开发语言·c++
程序猿本员6 小时前
线程池精华
c++·后端
靡樊6 小时前
Socket编程UDP\TCP
网络·c++·学习·tcp/ip·udp
byte轻骑兵7 小时前
【C++高级主题】命令空间(五):类、命名空间和作用域
开发语言·c++