public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/29914]  New: std::distance(iterator, const_iterator)
@ 2006-11-20 14:39 wouter dot vermaelen at pi dot be
  2006-11-20 20:21 ` [Bug libstdc++/29914] " pcarlini at suse dot de
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: wouter dot vermaelen at pi dot be @ 2006-11-20 14:39 UTC (permalink / raw)
  To: gcc-bugs

#include <vector>
#include <iterator>

int main()
{
        typedef std::vector<int> V;
        V v;
        for (V::iterator       it = v.begin(); it != v.end(); ++it) {
                distance(v.begin(), it); // this works
        }
        for (V::const_iterator it = v.begin(); it != v.end(); ++it) {
                distance(v.begin(), it); // this doesn't
        }
}

--------------

The second loop unexpectedly (for me at least) fails to compile. I can
understand that the c++ standard only requires std::distance() to work with
iterators of the exact same type. But as a QOI issue I believe it should also
accept mixed const and non-const iterators.


-- 
           Summary: std::distance(iterator, const_iterator)
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wouter dot vermaelen at pi dot be


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
@ 2006-11-20 20:21 ` pcarlini at suse dot de
  2006-11-20 22:47 ` wouter dot vermaelen at pi dot be
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2006-11-20 20:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pcarlini at suse dot de  2006-11-20 20:21 -------
I don't think this is simply matter of QoI: the standard is very clear about
the number (1) of template parameters. As a matter of fact, at least another
couple of implementations also reject this kind of snippet. Are you aware of
any actual implementation accepting it? In that case, we could possibly
escalate the issue to a Standard DR, we would look more in detail into it.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
  2006-11-20 20:21 ` [Bug libstdc++/29914] " pcarlini at suse dot de
@ 2006-11-20 22:47 ` wouter dot vermaelen at pi dot be
  2006-11-20 22:52   ` Andrew Pinski
  2006-11-20 22:52 ` pinskia at physics dot uc dot edu
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: wouter dot vermaelen at pi dot be @ 2006-11-20 22:47 UTC (permalink / raw)
  To: gcc-bugs



------- 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);
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
  2006-11-20 20:21 ` [Bug libstdc++/29914] " pcarlini at suse dot de
  2006-11-20 22:47 ` wouter dot vermaelen at pi dot be
@ 2006-11-20 22:52 ` pinskia at physics dot uc dot edu
  2006-11-20 23:15 ` pcarlini at suse dot de
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: pinskia at physics dot uc dot edu @ 2006-11-20 22:52 UTC (permalink / raw)
  To: gcc-bugs



------- 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 22:47 ` wouter dot vermaelen at pi dot be
@ 2006-11-20 22:52   ` Andrew Pinski
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Pinski @ 2006-11-20 22:52 UTC (permalink / raw)
  To: gcc-bugzilla; +Cc: gcc-bugs

> 
> 
> 
> ------- 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
                   ` (2 preceding siblings ...)
  2006-11-20 22:52 ` pinskia at physics dot uc dot edu
@ 2006-11-20 23:15 ` pcarlini at suse dot de
  2006-11-21  2:34 ` bangerth at dealii dot org
  2006-11-21  2:49 ` pcarlini at suse dot de
  5 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2006-11-20 23:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pcarlini at suse dot de  2006-11-20 23:15 -------
Guys, I'm keeping this PR open, but personally, certainly I'm not going to add
to the library this code, without support from the Committee. Maybe others want
to comment...


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-11-20 23:15:00
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
                   ` (3 preceding siblings ...)
  2006-11-20 23:15 ` pcarlini at suse dot de
@ 2006-11-21  2:34 ` bangerth at dealii dot org
  2006-11-21  2:49 ` pcarlini at suse dot de
  5 siblings, 0 replies; 8+ messages in thread
From: bangerth at dealii dot org @ 2006-11-21  2:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from bangerth at dealii dot org  2006-11-21 02:34 -------
I think it would be completely unacceptable if we added new signatures
to std::distance. If someone is inconvenienced, the solution is to
simply do a cast by hand:

  std::distance (it1, V::const_iterator(it2));

or something like this. I can not imagine that anything good whatsoever
could come out of us trying to invent new signatures or other non-standard
things in namespace std. If it were up to me, this PR should be closed.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug libstdc++/29914] std::distance(iterator, const_iterator)
  2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
                   ` (4 preceding siblings ...)
  2006-11-21  2:34 ` bangerth at dealii dot org
@ 2006-11-21  2:49 ` pcarlini at suse dot de
  5 siblings, 0 replies; 8+ messages in thread
From: pcarlini at suse dot de @ 2006-11-21  2:49 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pcarlini at suse dot de  2006-11-21 02:49 -------
Agreed. In due course, I will try to discuss the issue with the Library Working
Group people, just in case something could be improved for the next standard.


-- 

pcarlini at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29914


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-11-21  2:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-20 14:39 [Bug libstdc++/29914] New: std::distance(iterator, const_iterator) wouter dot vermaelen at pi dot be
2006-11-20 20:21 ` [Bug libstdc++/29914] " pcarlini at suse dot de
2006-11-20 22:47 ` wouter dot vermaelen at pi dot be
2006-11-20 22:52   ` Andrew Pinski
2006-11-20 22:52 ` pinskia at physics dot uc dot edu
2006-11-20 23:15 ` pcarlini at suse dot de
2006-11-21  2:34 ` bangerth at dealii dot org
2006-11-21  2:49 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).