This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug libstdc++/29914] std::distance(iterator, const_iterator)
- From: Andrew Pinski <pinskia at physics dot uc dot edu>
- To: gcc-bugzilla at gcc dot gnu dot org
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 20 Nov 2006 17:53:26 -0500 (EST)
- Subject: Re: [Bug libstdc++/29914] 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