home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:16605 comp.std.c++:1602
- Newsgroups: comp.lang.c++,comp.std.c++
- Path: sparky!uunet!munnari.oz.au!sol.deakin.OZ.AU!news.cs.uow.edu.au!cssc-syd.tansu.com.au!pete
- From: pete@cssc-syd.tansu.com.au (Peter Alexander Merel)
- Subject: Re: Proposal - enhancement for switch statement.
- Message-ID: <1992Nov19.213223.20140@cssc-syd.tansu.com.au>
- Organization: AOTC - CSSC
- References: <1992Nov16.004558.9855@muddcs.claremont.edu> <1992Nov16.213015.1@vax1.bham.ac.uk>
- Date: Thu, 19 Nov 1992 21:32:23 GMT
- Lines: 48
-
- mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
- >No. Please not another token in the parser.
-
- Agreed. The C++ philosophy appears to be, only add a token if there's just
- no other way at all.
-
- >The only problem is that if a class has both an `operator==(int)' and an
- >`operator int ()' defined inconsistantly the some existing switch
- >statements would change their meaning.
-
- I thought about this a little, and thanks to Mike Tiller for raising it
- privately. Mike raised an associated problem, that operator== doesn't
- have to return an int, but can return any damned thing it pleases ...
- so a really perverse operator== might return something that can't cast
- into an int.
-
- But how about this:
-
- switch looks, in the first instance, for a way to cast the switch
- expression and case constants into int. That should keep existing code
- from breaking.
-
- Failing to find a way to do this, switch looks for an operator== on the
- type returned from the switch expression with a distinctive signature, say
-
- int const operator==(foo const & bar) const
-
- There's a precedent for this sort of usage in the copy constructor, and
- of course this way the case constants can have different types to match
- different overloaded operator==.
-
- >switch(TRUE) {
- > case expr1: { /* code */} break;
- > case expr2: { /* code */} break;
- > delfault: {/* code */}
- >}
-
- >This is exactly equivalent to an if ladder but some people think it looks
- >nicer :-)
-
- Looks way cool, but I think there's a little inconsistency with the previous
- switch - you've got the constant at the top, and we'd have to commute the
- operator== to get it to fly. Sounds messy to me.
-
- --
- Internet: pete@cssc-syd.tansu.com.au UUCP: {uunet,mcvax}!munnari!cssc-syd!pete
- Snail: 1/18-20 Orion Road, Lane Cove NSW 2066 Australia Phone: +61 2 911 3130
- I am a big pond in a small fish.
-