J
John Harrison
I there a reliable and generic method to convert a const_iterator to an
iterator (i.e. something like const_cast).
I ask because I'm writing some methods which take and return iterators.
A const version of the method takes and returns const iterators and the
non-const version takes and returns non-const iterators. I'd like to
avoid code duplication like this
class X
{
iterator some_method(iterator i)
{
...
}
const_iterator some_method(const_iterator i) const
{
return const_cast<X*>(this)->some_method(i);
}
}
But that only works if I can convert a const_iterator to the equivalent
iterator.
Answers or alternatives welcome.
john
iterator (i.e. something like const_cast).
I ask because I'm writing some methods which take and return iterators.
A const version of the method takes and returns const iterators and the
non-const version takes and returns non-const iterators. I'd like to
avoid code duplication like this
class X
{
iterator some_method(iterator i)
{
...
}
const_iterator some_method(const_iterator i) const
{
return const_cast<X*>(this)->some_method(i);
}
}
But that only works if I can convert a const_iterator to the equivalent
iterator.
Answers or alternatives welcome.
john