Possible Duplicate:
Obtaining const_iterator from iterator
I want to write a metafunction which returns the corresponding const_iterator from an iterator
template <class Iterator>
struct get_const_iterator
{
typedef ??? type;
};
get_const_iterator<int*>::typemust beconst int*get_const_iterator<const int*>::typemust beconst int*get_const_iterator<int* const>::typemust beconst int*orconst int* const, I don’t careget_const_iterator<std::list<char>::iterator>::typemust bestd::list<char>::const_iterator
etc.
Can this be done with iterator_traits or without them?
Edit: Let’s assume that if 2 container have the same iterator type then they also have the same const_iterator type. I think this is a reasonable assumption, although theoretically not entirely correct one.
You can do it in C++0x
Although I’m starting to agree with Steve — this is not a general solution since different containers may have the same iterator types.