#ifndef UTIL_PROXY_ITERATOR_H
#define UTIL_PROXY_ITERATOR_H
#include <cstddef>
#include <iterator>
namespace util {
template <class Proxy> class ProxyIterator {
private:
typedef ProxyIterator<Proxy> S;
typedef typename Proxy::InnerIterator InnerIterator;
public:
typedef std::random_access_iterator_tag iterator_category;
typedef typename Proxy::value_type value_type;
typedef std::ptrdiff_t difference_type;
typedef Proxy reference;
typedef ProxyIterator<Proxy> * pointer;
ProxyIterator() {}
template <class AlternateProxy> ProxyIterator(const ProxyIterator<AlternateProxy> &in) : p_(*in) {}
explicit ProxyIterator(const Proxy &p) : p_(p) {}
S &operator=(const S &other) {
I() = other.I();
return *this;
}
bool operator==(const S &other) const { return I() == other.I(); }
bool operator!=(const S &other) const { return !(*this == other); }
bool operator<(const S &other) const { return I() < other.I(); }
bool operator>(const S &other) const { return other < *this; }
bool operator<=(const S &other) const { return !(*this > other); }
bool operator>=(const S &other) const { return !(*this < other); }
S &operator++() { return *this += 1; }
S operator++(int) { S ret(*this); ++*this; return ret; }
S &operator+=(std::ptrdiff_t amount) { I() += amount; return *this; }
S operator+(std::ptrdiff_t amount) const { S ret(*this); ret += amount; return ret; }
S &operator--() { return *this -= 1; }
S operator--(int) { S ret(*this); --*this; return ret; }
S &operator-=(std::ptrdiff_t amount) { I() += (-amount); return *this; }
S operator-(std::ptrdiff_t amount) const { S ret(*this); ret -= amount; return ret; }
std::ptrdiff_t operator-(const S &other) const { return I() - other.I(); }
Proxy operator*() const { return p_; }
Proxy *operator->() { return &p_; }
const Proxy *operator->() const { return &p_; }
Proxy operator[](std::ptrdiff_t amount) const { return *(*this + amount); }
const InnerIterator &Inner() { return p_.Inner(); }
private:
InnerIterator &I() { return p_.Inner(); }
const InnerIterator &I() const { return p_.Inner(); }
Proxy p_;
};
template <class Proxy> ProxyIterator<Proxy> operator+(std::ptrdiff_t amount, const ProxyIterator<Proxy> &it) {
return it + amount;
}
}
#endif