This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/29914] std::distance(iterator, const_iterator)
- From: "pinskia at physics dot uc dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 20 Nov 2006 22:52:07 -0000
- Subject: [Bug libstdc++/29914] std::distance(iterator, const_iterator)
- References: <bug-29914-8535@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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