G
Grahamo
Hi,
I'm implementing a custom iterator (random access type ) so I can use
stl algorithms such as sort on my legacy containers. I'm having
problems compiling however. when implementing my customIterator class I
have defined the operators below (as well as others but they're not
important right now, I don't think).
class customIterator
{
customerIterator& operator*() const;
int operator-(const customIterator& x);
int operator-(const contIter& rhs) const
customIterator& operator++();
customIterator operator++(int);
customIterator& operator--();
customIterator operator--(int);
customIterator& operator+=(difference_type n);
customIterator& operator-=(difference_type n);
customIterator operator+(difference_type rhs) const;
customIterator operator-(difference_type rhs) const;
int& operator[](int n);
bool operator==(const customIterator& x) const;
bool operator<(const customIterator& x) const;
}
The problem is when I come to pass one of these iterators into
std::sort, I'm missing all sorts of operators like operator>(int),
operator/(int), operator-(int).
These are being generated because the stl::sort on my platform has code
like this;
while (__last - __first > __stl_threshold) {
or uses expressions like;
if ( (__last - __first)/2 > something... )
Do I need to provide an operator for implicit conversion of my
customIterator to an int so that the comparison ( __last - first >
__stl_threshold) can be evaluated?
Right now I'm just trying to get this to compile with a simple case
vectors of ints.
std::vector<int> vint;
containerWrapper wrapper(vint);
customIterator begin = wrapper.begin();
customIterator end = wrapper.end();
// compilation errors here .......
std::sort(begin, end, aCompareFunction());
compilation errors are like;
1) operator> not implemented in the type customIterator for arguments
of type int
2) operator== not implemented in the type customIterator for arguments
of type int
3) operator/ not implemented in the type customIterator for arguments
of type int
etc. etc.
any ideas?
thanks.
I'm implementing a custom iterator (random access type ) so I can use
stl algorithms such as sort on my legacy containers. I'm having
problems compiling however. when implementing my customIterator class I
have defined the operators below (as well as others but they're not
important right now, I don't think).
class customIterator
{
customerIterator& operator*() const;
int operator-(const customIterator& x);
int operator-(const contIter& rhs) const
customIterator& operator++();
customIterator operator++(int);
customIterator& operator--();
customIterator operator--(int);
customIterator& operator+=(difference_type n);
customIterator& operator-=(difference_type n);
customIterator operator+(difference_type rhs) const;
customIterator operator-(difference_type rhs) const;
int& operator[](int n);
bool operator==(const customIterator& x) const;
bool operator<(const customIterator& x) const;
}
The problem is when I come to pass one of these iterators into
std::sort, I'm missing all sorts of operators like operator>(int),
operator/(int), operator-(int).
These are being generated because the stl::sort on my platform has code
like this;
while (__last - __first > __stl_threshold) {
or uses expressions like;
if ( (__last - __first)/2 > something... )
Do I need to provide an operator for implicit conversion of my
customIterator to an int so that the comparison ( __last - first >
__stl_threshold) can be evaluated?
Right now I'm just trying to get this to compile with a simple case
vectors of ints.
std::vector<int> vint;
containerWrapper wrapper(vint);
customIterator begin = wrapper.begin();
customIterator end = wrapper.end();
// compilation errors here .......
std::sort(begin, end, aCompareFunction());
compilation errors are like;
1) operator> not implemented in the type customIterator for arguments
of type int
2) operator== not implemented in the type customIterator for arguments
of type int
3) operator/ not implemented in the type customIterator for arguments
of type int
etc. etc.
any ideas?
thanks.