From 6470475866890859330
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7eaa8faac8da5016
X-Google-Attributes: gidf78e5,public
From: "Darin Adler" <darin@bentspoon.com>
Subject: Re: Defect Report: member == in container iterators considered harmful
Date: 1999/08/18
Message-ID: <7pcoa8$2kf0@enews2.newsguy.com>#1/1
X-Deja-AN: 514097021
X-NNTP-Posting-Host: news.newsdawg.com
Content-Transfer-Encoding: 7bit
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7p4nj8$n3u@enews4.newsguy.com> <37B95B96.7F37@wanadoo.fr>
X-UID: 0000000001
X-Status: $$$T
Content-Type: text/plain; charset="US-ASCII"
Organization: http://extra.newsguy.com
Mime-Version: 1.0
Newsgroups: comp.std.c++
Originator: clamage@taumet


Valentin Bonnard <Bonnard.V@wanadoo.fr> wrote:

> [Note: fowarded to the issue list maintainer]
>
> Darin Adler wrote:
>
>> Some standard containers define iterator classes to fulfill the requirements
>> described in 23.1 [lib.container.requirements]. This states that iterator
>> must be convertible to const_iterator. However, the following code is not
>> guaranteed to work:
>>
>>     bool check_equal(std::deque<int>::iterator i,
>>         std::deque<int>::const_iterator ci)
>>     {
>>         return i == ci;
>>     }
>>
>> The reason for this is that there's no requirement that the == operator be
>> defined as a non-member function.
>
> It's the contrary: as a non member function, deduction
> won't ever work. With member functions, it will work
> sometimes (i == ci is an error, ci == i is ok).
>
> So mandating non member functions certainly:
> - isn't a solution

I tried this solution on my compiler before posting the defect report. I
changed the following function definition within the deque template in the
definition of deque::const_iterator:

        bool operator ==(const const_iterator& rhs) const
        {return cur_ == rhs.cur_;}

to this:

        friend bool operator ==(const const_iterator& lhs,
            const const_iterator& rhs)
        {return lhs.cur_ == rhs.cur_;}

After this change, everything worked as before, but the check_equal function
compiled and executed correctly.

In light of this, I don't understand what you mean when you say, "deduction
won't ever work."

Is there something non-standard about the compiler I'm using that is causing
it to work? Is there some other test case that will show me that deduction
isn't working?

> - goes agains the spirit of generic programming

I'd like to argue about this one, but since you offer no evidence of how it
goes against the spirit of generic programming, I don't know what to argue
with. It seems rather subjective.

I just want the library to work. I don't want to constrain implementers of
non-library classes, but I'd like the library classes to work consistently,
even with different implementations of the library.

    -- Darin


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




