From -1714896835518659441
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,7eaa8faac8da5016
X-Google-Attributes: gidf78e5,public
From: sbnaran@uiuc.edu (Siemel B. Naran)
Subject: Re: Defect Report: member == in container iterators considered harmful
Date: 1999/08/19
Message-ID: <slrn7rmuab.cp5.sbnaran@localhost.localdomain>#1/1
X-Deja-AN: 514751389
X-NNTP-Posting-Host: rochester-30.slip.uiuc.edu
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <7p4nj8$n3u@enews4.newsguy.com> <7pcj1q$105@library1.airnews.net>
X-UID: 0000000001
X-Status: $$$T
Organization: University of Illinois at Urbana-Champaign
User-Agent: slrn/0.9.5.7 (UNIX)
Reply-To: sbnaran@uiuc.edu
Newsgroups: comp.std.c++
Originator: clamage@taumet


On 18 Aug 1999 05:18:50 GMT, Bill Wade <bill.wade@stoner.com> wrote:
>Darin Adler wrote in message <7p4nj8$n3u@enews4.newsguy.com>...

>>If they are, any ==, !=, >, <, >=, or <= operator functions defined
>>for these classes to satisfy iterator requirements must be defined in the
>>std namespace, not as member functions.

>I'm not on the committee, but I believe the above is overly restrictive.
>Here are two ways that member functions can support the desired test ( i ==
>ci;    // iterator i;  const_iterator ci).
>
>1) bool iterator::operator==(const_iterator) const;
>2) class iterator: public const_iterator { ... };    // inherit operator==()

I must have missed something.  If the conversion from 'iterator' to
'const_iterator' is implicit, then we could also use a non-member
operator==(const_iterator,const_iterator), optionally a friend.  So
there is a choice 3) too, right?

I wrote my own iterator class iter<T>, and iterator is iter<T> and
const_iterator is iter<const T>.  To write seperate classes class
iter<T> and const_iter<T> is tedious.  So I don't like 1) or 2).
If I had an implicit conversion
   iter<T>::iter(const iter<U>&);
then choice 3) is feasible (eg, T==int and U==const int).  However,
for most type safety and best error messages, I don't want this
templated implicit constructor, so choice 3) I also don't like.

-- 
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


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




