Xref: utzoo comp.std.c++:267 comp.std.c:3525 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!fs1!ee.ubc.ca!mikeb From: mikeb@ee.ubc.ca (Mike Bolotski) Newsgroups: comp.std.c++,comp.std.c Subject: Re: Proposed Enhancement to select/case (yes, I know...) Message-ID: <1990Aug31.134248@ee.ubc.ca> Date: 31 Aug 90 20:42:48 GMT References: <1990Aug30.164610.3519@zoo.toronto.edu> Sender: root@fs1.ee.ubc.ca Reply-To: mikeb@salmon.ee.ubc.ca Organization: Dept of EE, University of British Columbia Lines: 35 In article <1990Aug30.164610.3519@zoo.toronto.edu>, henry@zoo.toronto.edu (Henry Spencer) writes: > In article burley@world.std.com (James C Burley) writes: > >... how about this: allow ranges (and, perhaps, lists) on case statements. > > Such a feature appeared in one draft of ANSI C, and disappeared in the > next. I believe the reason was the usual: there was no implementation > experience with it, and it was a minor convenience rather than a solution > to a serious problem. From the G++ info file: Switch Ranges ============= A GNU C++ extension to the switch statement permits range specification for case values. For example, below is a concise way to print out a function parameter's "character class:" print_char_class (char c) { switch (c) { case 'a'..'z': printf ("lower case\n"); break; case 'A'..'Z': printf ("upper case\n"); break; case '0'..'9': printf ("digit\n"); break; default: printf ("other\n"); } } Duplicate, overlapping case values and empty ranges are detected and rejected by the compiler. -- Mike Bolotski VLSI Laboratory, Department of Electrical Engineering mikeb@salmon.ee.ubc.ca University of British Columbia, Vancouver, Canada