From 5746144798939509438
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,66d20309909372f6
X-Google-Attributes: gidf78e5,public
From: Oleg Zabluda <zabluda@math.psu.edu>
Subject: Re: STL and set_union algorithm question? (newbie to STL!)
Date: 1998/04/12
Message-ID: <6gk4ft$tip@marianna.psu.edu>#1/1
X-Deja-AN: 343281375
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
References: <6g2te9$a7n$1@ukwsv3.ggr.co.uk> <35290568.2781@wizard.net> <352A9B77.2781E494@pratique.fr> <6gelt5$mpp@marianna.psu.edu> <fxtsono2jp4.fsf@isolde.mti.sgi.com> <6gh6t6$ptn@marianna.psu.edu> <352C74D1.3B6F@pratique.fr>
X-Original-Date: 9 Apr 1998 23:42:53 -0400
X-Server-Date: 10 Apr 1998 04:35:43 GMT
Organization: Penn State University, Center for Academic Computing
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANTCOPuEDnX0m9pzZAQE1aAF5AQti2tfhXlA4T2MWd13yro9IsS4gsCvk MBPr4zH1ZMJOXNCztIUKIx2ptkFVuV39 =Ux5t
Reply-To: zabluda@math.psu.edu (Oleg Zabluda)
Newsgroups: comp.std.c++


Valentin Bonnard <bonnardv@pratique.fr> wrote:
: Oleg Zabluda wrote:

: > I just want it to be non-convertible to set<>::const_iterator.

: I understand your opinion. You may also want cont<T>::iterator 
: not to be convertible to cont<U>::iterator, for any T != U, 
: which would mean that vector::iterator can't be a pointer.

Right. The often used ``typedef T* vector<T>::iterator''
is a disaster, because it does not preclude
vector<Derived>::iterator ==> vector<Base>::iterator
conversions.  

However, I wouldn't mind a conversion from 
cont<Derived*>::iterator to cont<Base*>::iterator. But
since there is no way to express it in C++, I don't
wish for it.

Note also that the standard does not say that if
cont1 and cont2 are different containers, then
cont1<T>::iterator must be non-convertible to 
cont2<T>::iterator (see later).

: I think it's should be possible to avoid direct use of primitive 
: types entirely, but it's too early to impose that given the fact 
: that using an object (class) instead of a built-in incurs a penalty 
: under a number of compilers.

Well, at least the non-convertability from const_iterator to
iterator can be imposed. It's the single largest defect in
STL, I know of. 

STL is a curious part of C++ in this respect. In the rest of the 
language and stdlib, a lot of work was put into a stronger type 
system and const correctness. Many old C functions were duplicated 
to provide const-correct versions. While in STL elementary 
const-correctness is not mandated. The most notable manifestation 
of this is the Plauger's library, shipped with MSVC++, where 
const_iterator's are freely convertible to iterator's for all 
containers, and it's 100% compliant. To add insult to injury, 
set<T>::iterator is convertible to map<U>::iterator for all 
T and U. No kidding. And, again, it's 100% compliant.

Oleg.
-- 
Life is a sexually transmitted, 100% lethal disease.
---
[ 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              ]



