反向迭代器 模拟

反向迭代器 模拟

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;
	};
}
相关推荐
繁星星繁1 小时前
C++11学习笔记
c++·笔记·学习
Stanford_11066 小时前
如何利用Python进行数据分析与可视化的具体操作指南
开发语言·c++·python·微信小程序·微信公众平台·twitter·微信开放平台
千里马-horse7 小时前
Async++ 源码分析8--partitioner.h
开发语言·c++·async++·partitioner
Lucis__8 小时前
再探类&对象——C++入门进阶
开发语言·c++
北京不会遇到西雅图9 小时前
【SLAM】【后端优化】不同优化方法对比
c++·机器人
jndingxin10 小时前
c++多线程(6)------ 条件变量
开发语言·c++
程序员莫小特10 小时前
老题新解|大整数加法
数据结构·c++·算法
洲覆11 小时前
C++ 模板、泛型与 auto 关键字
开发语言·数据结构·c++
千里马-horse12 小时前
Async++ 源码分析7--parallel_reduce.h
开发语言·c++·async++·parallel_reduce
江公望12 小时前
Qt QThread使用方法入门浅解
c++·qt