我的一些矢量迭代器的实现:
class iterator : public std::iterator<std::input_iterator_tag, int> {
Vector<T> *vector;
size_t position;
public:
iterator(Vector<T> *vector_, size_t idx) {...};
iterator(const iterator &it) {...};
friend bool operator == (const iterator &a, const iterator &b) {...};
friend bool operator > (const iterator &a, const iterator &b) {...};
friend bool operator < (const iterator &a, const iterator &b) {...};
friend bool operator >= (const iterator &a, const iterator &b) {...};
friend bool operator <= (const iterator &a, const iterator &b) {...};
friend bool operator != (const iterator &a, const iterator &b) {...};
iterator &operator = (const iterator &b) {...};
T operator * () {...};
iterator &operator ++ () {...}
iterator &operator -- () {...}
std::ptrdiff_t operator - (const iterator &b) const {...}
};
但是出于原因,调用std::sort(vector.begin(), vector.end())
会输出no operator +=
之类的错误,这表明事件std::sort
将我的迭代器视为随机访问。为什么?