home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!spool.mu.edu!sgiblab!sti.com!dgreen
- From: dgreen@sti.com (Dan R. Greening)
- Subject: Re: Proposal - enhancement for switch statement.
- Message-ID: <BxsHtz.8qJ@sti.com>
- Sender: usenet@sti.com
- Nntp-Posting-Host: smurf
- Organization: Software Transformation, Inc.
- References: <1992Nov15.190830.11622@cssc-syd.tansu.com.au> <MCGRANT.92Nov15132747@rascals.stanford.edu>
- Date: Mon, 16 Nov 1992 03:32:23 GMT
- Lines: 30
-
- mcgrant@rascals.stanford.edu (Michael C. Grant) wrote:
- >In article <1992Nov15.190830.11622@cssc-syd.tansu.com.au>
- >pete@cssc-syd.tansu.com.au (Peter Alexander Merel) writes:
- >> [switch on any type using == proposal]
- >> Any chance?
- >
- >I doubt it... Even before C++ came along, switch statements could not
- >handle floats, strings, structures, etc. Sure, a switch statement could
- >be turned into a set of if-then-else statements, but it isn't because
- >it usually is best turned into a jump table.
-
- Smart compilers should put it into a series of jump tables and do binary
- search to identify the correct jump table.
-
- The obvious rhetorical question is "why not require SwitchType to have
- a well-ordering relation using operator< and operator==?". They you could
- at least do the binary search part instead of a sequence of "=="
- operations.
-
- But the rhetoric is just that: I'd prefer to keep it simple, and leave
- switch alone.
-
- The reason is pretty simple: you as the programmer know your data much
- better than the compiler. If you are going to use expensive operations,
- like a series of categorizing "==" operator calls, it seems like you
- should tailor your "switch" to the data. The compiler can't do that.
- --
- ____
- \ /Dan Greening Software Transformation 1601 Saratoga-Sunnyvale Rd, #100
- \/dgreen@sti.com (408) 973-8081 x313 Cupertino, CA 95014
-