反向迭代器 模拟

反向迭代器 模拟

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+,+,c++)