home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:16588 comp.std.c++:1600
- Newsgroups: comp.lang.c++,comp.std.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Proposal - enhancement for switch statement.
- Message-ID: <1992Nov19.163944.19935@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Nov16.004558.9855@muddcs.claremont.edu> <1992Nov16.213015.1@vax1.bham.ac.uk>
- Date: Thu, 19 Nov 1992 16:39:44 GMT
- Lines: 59
-
- In article <1992Nov16.213015.1@vax1.bham.ac.uk> mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
-
- >
- >Now (as promised) why ranges would be unnecessary (following the "if you
- >can do it with a class then don't extend the language" rule ;-) )
- >
- >template <class T> class Range {
- > T top,bottom;
- >public:
- > Range(t,b) : top(t),bottom(b) {}
- > int operator==(T t) { return bottom <= t && top >= t; }
- >}
- >template <class T> inline operator == (T& t,Range<T>& r) {return r == t;}
- >
- >switch (i) {
- > case Range<char>('0','9') : case '-' : {/*...*/} break;
- >}
-
- This is illegal.
- The 'argument' of a case must be a constant expression.
- switch is a primitive operation, the compiler must be able to
- check for duplicate cases.
-
- >
- >compare:
- >
- >switchc (i) {
- > case '0'...'9' , '-': /*...*/
- >}
-
- Much nicer :-)
- >
- >OK so it's not as concise as your form but it far more C++. Assuming your
- >compiler supports inlining it can be made to optimize as well as the
- >explicit range syntax.
- >
- >BTW heres a new constuct (my mother's favorate in BASIC) that would become
- >available:
- >
- >switch(TRUE) {
- > case expr1: { /* code */} break;
- > case expr2: { /* code */} break;
- > delfault: {/* code */}
- >}
- >
- >--
- > \\ ( ) No Bullshit! | Email: B.A.McCauley@bham.ac.uk
- > . _\\__[oo from | Voice: +44 21 471 3789 (home)
- >.__/ \\ /\@ /~) /~[ /\/[ | Fax: +44 21 625 2175 (work)
- >. l___\\ /~~) /~~[ / [ | Snail: 197 Harborne Lane,
- > # ll l\\ ~~~~ ~ ~ ~ ~ | Birmingham, B29 6SS, UK
- >###LL LL\\ (Brian McCauley) | ICBM: 52.5N 1.9W
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-