反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
十五年专注C++开发13 分钟前
通信中间件 Fast DDS(一) :编译、安装和测试
linux·c++·windows·中间件·cmake·vcpkg
蒋星熠33 分钟前
MySQL 到 ClickHouse 明细分析链路改造:数据校验、补偿与延迟治理
android·大数据·开发语言·c++·python·mysql·系统架构
七七七七071 小时前
【C++ STL】list详解和模拟
开发语言·c++·list
屁股割了还要学5 小时前
【数据结构入门】堆
c语言·开发语言·数据结构·c++·考研·算法·链表
草莓熊Lotso8 小时前
【洛谷题单】--分支结构(三)
c语言·c++·刷题·洛谷
GetcharZp9 小时前
C++日志库新纪元:为什么说spdlog是现代C++开发者必备神器?
c++·后端
Algebraaaaa9 小时前
为什么C++主函数 main 要写成 int 返回值 | main(int argc, char* argv[]) 这种写法是什么意思?
开发语言·c++
fqbqrr13 小时前
2508C++,检测S模式
c++
专注VB编程开发20年15 小时前
IIS Express中可以同时加载并使用.net4.0和.NET 2.0的 DLL
c++·windows·microsoft·c#·vb.net
光头闪亮亮15 小时前
C++凡人修仙法典 - 散修版
c++