反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
水云桐程序员5 小时前
C++可以写手机应用吗
开发语言·c++·智能手机
小黄人软件9 小时前
C++读写编辑CSV文件示例源码 用于数据导入导出,比Excel好使
开发语言·c++·excel
郭涤生9 小时前
C++各个版本的性能和安全性总结
开发语言·c++
wljy110 小时前
二、静态库的制作和使用
linux·c语言·开发语言·c++
道剑剑非道11 小时前
FFmpeg 6.0 实战:用 C++ 封装摄像头采集与 RTSP 推流
开发语言·c++·ffmpeg
光电笑映11 小时前
从环境变量到进程虚拟地址空间——Linux 内存管理的底层脉络
linux·服务器·c++·c
sparEE12 小时前
c++字符串和自定义字面量
开发语言·c++
蜡笔小马13 小时前
03.C++设计模式-原型模式
c++·设计模式·原型模式
神仙别闹13 小时前
基于QT(C++)实现线性表的建立、插入、删除、查找等基本操作
java·c++·qt
salipopl13 小时前
C/C++ 中 volatile 关键字详解:原理、作用与实际应用
开发语言·c++