home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16339 < prev    next >
Encoding:
Text File  |  1992-11-15  |  1.8 KB  |  43 lines

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