From -6597570381051943793
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,6a0e273cd04a6fa1
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-01-10 15:30:05 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!uunet!sea.uu.net!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: Pete Becker <petebecker@acm.org>
Newsgroups: comp.std.c++
Subject: Re: new meaning of explicit keyword
Date: Thu, 10 Jan 2002 17:26:19 CST
Organization: Dinkumware, Ltd
Lines: 56
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3C3E11E4.E454ABB0@acm.org>
References: <a1hsph$p4k$1@news.tpi.pl> <92ce342f.0201100428.49e3dd92@posting.google.com> <3C3DE3E6.F27385B2@acm.org> <bQm%7.65$dd2.1604@nreader3.kpnqwest.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Trace: UmFuZG9tSVao1+idSGm0pVjy/NHBAc30i9bNe30Xf2T9k3A0uwSMisA8dm0tzk4x
X-Complaints-To: abuse@rcn.com
NNTP-Posting-Date: 10 Jan 2002 22:12:09 GMT
X-Accept-Language:  en
Xref: archiver1.google.com comp.std.c++:8951

Andrea Ferro wrote:
> 
> "Pete Becker" <petebecker@acm.org> wrote in message
> news:3C3DE3E6.F27385B2@acm.org...
> > Chris McClelland wrote:
> > >
> > > Interesting.
> > >
> > > I'd like to be able to use explicit on cast operators, to force an
> > > explicit cast. Like this:
> > >
> > > class X {
> > > public:
> > >   X(float val) {...}
> > >   explicit operator float() {...}
> > > };
> > >
> > > int main() {
> > >     float a = 10.3f;
> > >     X b = a;  // Fine. Use X(float)
> > >     float c = b;  // Error!!
> > >     float d = static_cast<float>(b);  // Fine...
> > >     float e = (float)b;  // Also fine...
> > > }
> > >
> >
> > What benefit does a mandatory cast have over a function call?
> >
> > float e = b.to_float();
> 
> I think the biggest one would be the possibility to use it in templates.
> That is to make the source type a template parameter.
> 
> Assuming we want assigmenets marked A to be valid for classes where the
> cast operator is not marked explicit (inluding of course all classes so
> far developed and predefined types) but fail for classes we develop with
> the explicit mark on the cast operator, while cases marked B should be
> always valid, you see the difference in templated code like:
> 

Saying "I could write this code" doesn't support adding the feature
unless you also demonstrate that the resulting code is easier to write,
or cleaner, or better in some other way because of having mandatory
casts. Otherwise it's just doing parlor tricks. So, again, what's the
benefit from having mandatory casts?

-- 
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)

---
[ 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://www.research.att.com/~austern/csc/faq.html                ]



