home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16588 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  2.4 KB

  1. Xref: sparky comp.lang.c++:16588 comp.std.c++:1600
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!batcomputer!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: Proposal - enhancement for switch statement.
  6. Message-ID: <1992Nov19.163944.19935@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1992Nov16.004558.9855@muddcs.claremont.edu> <1992Nov16.213015.1@vax1.bham.ac.uk>
  11. Date: Thu, 19 Nov 1992 16:39:44 GMT
  12. Lines: 59
  13.  
  14. In article <1992Nov16.213015.1@vax1.bham.ac.uk> mccauleyba@vax1.bham.ac.uk (Brian McCauley) writes:
  15.  
  16. >
  17. >Now (as promised) why ranges would be unnecessary (following the "if you
  18. >can do it with a class then don't extend the language" rule ;-) )
  19. >
  20. >template <class T> class Range {
  21. >  T top,bottom; 
  22. >public:
  23. >  Range(t,b) : top(t),bottom(b) {} 
  24. >  int operator==(T t) { return bottom <= t && top >= t; }
  25. >}
  26. >template <class T> inline operator == (T& t,Range<T>& r) {return r == t;}
  27. >
  28. >switch (i) {
  29. >  case Range<char>('0','9') : case '-' : {/*...*/} break;
  30. >}
  31.  
  32.     This is illegal. 
  33.     The 'argument' of a case must be a constant expression.
  34.     switch is a primitive operation, the compiler must be able to
  35.     check for duplicate cases.
  36.  
  37. >
  38. >compare:
  39. >
  40. >switchc (i) {
  41. >  case '0'...'9' , '-': /*...*/
  42. >}
  43.  
  44.     Much nicer :-)
  45. >
  46. >OK so it's not as concise as your form but it far more C++. Assuming your
  47. >compiler supports inlining it can be made to optimize as well as the
  48. >explicit range syntax.
  49. >
  50. >BTW heres a new constuct (my mother's favorate in BASIC) that would become
  51. >available:
  52. >
  53. >switch(TRUE) {
  54. >  case expr1: { /* code */} break;
  55. >  case expr2: { /* code */} break;
  56. >  delfault: {/* code */}
  57. >}
  58. >
  59. >-- 
  60. >    \\   ( )    No Bullshit!     |  Email: B.A.McCauley@bham.ac.uk   
  61. > .  _\\__[oo        from         |  Voice: +44 21 471 3789 (home)
  62. >.__/  \\ /\@    /~)  /~[   /\/[  |    Fax: +44 21 625 2175 (work)
  63. >.  l___\\      /~~) /~~[  /   [  |  Snail: 197 Harborne Lane,
  64. > # ll  l\\    ~~~~ ~   ~ ~    ~  |         Birmingham, B29 6SS, UK
  65. >###LL  LL\\   (Brian McCauley)   |   ICBM: 52.5N 1.9W
  66.  
  67.  
  68. -- 
  69. ;----------------------------------------------------------------------
  70.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  71.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  72. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  73.