反向迭代器 模拟
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;
};
}