[Bug libstdc++/29914] std::distance(iterator, const_iterator)
pinskia at physics dot uc dot edu
gcc-bugzilla@gcc.gnu.org
Mon Nov 20 22:52:00 GMT 2006
------- Comment #3 from pinskia at physics dot uc dot edu 2006-11-20 22:52 -------
Subject: Re: std::distance(iterator, const_iterator)
>
>
>
> ------- Comment #2 from wouter dot vermaelen at pi dot be 2006-11-20 22:47 -------
> I don't know of any implementation that does accept this. It was just very
> unexpected and inconvenient that it didn't work.
>
> I don't know C++ well enough, so maybe the following is completely flawed. But
> wouldn't it be possible to extend iterator_traits with a const_iterator typedef
> and provide an overload for distance() like this:
>
> template <typename IT1, typename IT2>
> typename std::iterator_traits<IT1>::difference_type distance(IT1 it1, IT2 it2)
> {
> typedef typename std::iterator_traits<IT1>::const_iterator CIT1;
> typedef typename std::iterator_traits<IT2>::const_iterator CIT2;
> CIT1 cit1 = it1;
> CIT2 cit2 = it2;
> return std::distance(cit1, cit2);
> }
That would cause confusion in cases where distance is passed vert different
iterators.
Maybe something more like:
template <typename IT1>
typename std::iterator_traits<IT1>::difference_type distance(IT1 it1,
typename std::iterator_traits<IT1>::const_iterator it2)
{
typename std::iterator_traits<IT1>::const_iterator cit1 = it1;
return std::distance(cit1, it2);
}
And one for the const iterator in the first argument.
-- Pinski
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914
More information about the Gcc-bugs
mailing list