🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #439

Re: Proposed Enhancement to select/case (yes, I know...)

#439
From: Mike Bolotski
Date: Fri, 31 Aug 1990 20:42
35 lines
1902 bytes
In article <1990Aug30.164610.3519@zoo.toronto.edu>, henry@zoo.toronto.edu (Henry Spencer) writes:
> In article <BURLEY.90Aug30030645@world.std.com> 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 
Technical Details
Message-ID: <1990Aug31.134248@ee.ubc.ca>
Path: arc1-ca.pugleaf.net!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
References: <BURLEY.90Aug30030645@world.std.com> <1990Aug30.164610.3519@zoo.toronto.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <BURLEY.90Aug30030645@world.std.com> <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