220 986 <f0ee9fbc-15bc-4bfb-82d0-3867de682a71@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Arthur Tchaikovsky <atch.cpp@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allow multiple same case values if they are next
 to each other
Date: Wed, 12 Dec 2012 03:27:41 -0800 (PST)
Lines: 137
Approved: news@gmane.org
Message-ID: <f0ee9fbc-15bc-4bfb-82d0-3867de682a71@isocpp.org>
References: <8d87c9d3-a192-45aa-98a6-d8c727f18a46@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_123_24783969.1355311661657"
X-Trace: ger.gmane.org 1355311665 22794 80.91.229.3 (12 Dec 2012 11:27:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 12 Dec 2012 11:27:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDL6FI4NYYERBL6UUGDAKGQEX5DUQCA@isocpp.org Wed Dec 12 12:27:59 2012
Return-path: <std-proposals+bncBDL6FI4NYYERBL6UUGDAKGQEX5DUQCA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vc0-f200.google.com ([209.85.220.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDL6FI4NYYERBL6UUGDAKGQEX5DUQCA@isocpp.org>)
	id 1TikTl-0007sE-EJ
	for gclcip-std-proposals@m.gmane.org; Wed, 12 Dec 2012 12:27:57 +0100
Original-Received: by mail-vc0-f200.google.com with SMTP id f13sf834393vcb.7
        for <gclcip-std-proposals@m.gmane.org>; Wed, 12 Dec 2012 03:27:43 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-beenthere:date:from:to:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=eKZa3utHcwlWKwCfuK32RaF1vXdF7lSYIqIQtmERaHs=;
        b=DHdAGX/6D7oMv7aPnGr/09JHx5umY5Dipyx2XLMDgUgtW+PGFHUvRD4fBNeGPdylYg
         Zn1GwXWFaGZqKC5aY/7Ncx+QIYKOHvvXBret1QF/tZUZ4PLiCclt0nceTrHlrANZ044M
         m2mCNXvwbhQqmkv1YsRXzwPq2nlvSMPllfc9qg+uVLdhLaHcjfFhfeq+iP52S4Ig9ujN
         UivSwWKo7hYaSAf0ojoU8kdY6clQBTiVipNXBn1Ib3AU8iFE0G/2nHY0PgZVUBixyKwX
         nw5HXYTJ3XxcRnkMDD2FlqLuviRJuIMuq2/PPBe/CcahDx0OXXbWIHngsPLUHGxLUhVk
         9Hww==
Original-Received: by 10.236.117.66 with SMTP id i42mr928269yhh.8.1355311663242;
        Wed, 12 Dec 2012 03:27:43 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.117.167 with SMTP id kf7ls1056437qeb.40.gmail; Wed, 12 Dec
 2012 03:27:42 -0800 (PST)
Original-Received: by 10.49.87.1 with SMTP id t1mr234764qez.41.1355311662302;
        Wed, 12 Dec 2012 03:27:42 -0800 (PST)
In-Reply-To: <8d87c9d3-a192-45aa-98a6-d8c727f18a46@isocpp.org>
X-Original-Sender: atch.cpp@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:986
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/986>

------=_Part_123_24783969.1355311661657
Content-Type: text/plain; charset=ISO-8859-1

I agree with you, and think that this should be amended. After all we have 
'case' not 'value' in switch statement. So different cases should be 
allowed independently of their values.

On Tuesday, 11 December 2012 23:24:38 UTC, Johannes Schaub wrote:

> Here is a simple proposal for allowing multiple consecutive identical case 
> values. My use-case were buttons that have a left and a right label, with 
> each label having their own led (but the button was a single button sending 
> a single key id).  
>
>  I had this code
>
>     enum Key {
>       Key_7 = 1
>       Key_Current = 1,
>
>       Key_8 = 2,
>       Key_Voltage = 2, 
>
>       // ...
>     };
>
>     Pair<LedNumer, LedNumber> getLeds(Key key) {
>       switch(key) {
>         case Key_7:
>         case Key_Current:
>           // ...
>           break;
>
>         case Key_8: 
>         case Key_Voltage:
>           // ...
>           break;
>       }
>     }
>
> C++ does't like this. It would be nice if this was allowed. I wrote an 
> ugly workaround like
>
>      Pair<LedNumer, LedNumber> getLeds(Key key) {
>       switch(key) {
>         case SameValues<Key_7, Key_Current>::value:
>           // ...
>           break;
>
>         case SameValues<Key_8, Key_Voltage>::value:
>           // ...
>           break;
>       }
>     }
>
> Which static_asserts that all constants have the same value. But I would 
> like to have native readable language support. Does anyone feel the same?
>

-- 




------=_Part_123_24783969.1355311661657
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<DIV>I agree with you, and think that this should be amended. After all we =
have 'case' not 'value' in switch statement. So different cases should be a=
llowed independently of their values.</DIV>
<DIV><BR>On Tuesday, 11 December 2012 23:24:38 UTC, Johannes Schaub wrote:<=
/DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>Here is a simple proposal for allo=
wing multiple consecutive identical case values. My use-case were buttons t=
hat have a left and a right label, with each label having their own led (bu=
t the button was a single button sending a single key id).&nbsp;=20
<DIV><BR></DIV>
<DIV>
<DIV>I had this code</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; enum Key {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; Key_7 =3D 1</DIV>
<DIV>&nbsp; &nbsp; &nbsp; Key_Current =3D 1,</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; &nbsp; Key_8 =3D 2,</DIV>
<DIV>&nbsp; &nbsp; &nbsp; Key_Voltage =3D 2,&nbsp;</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; &nbsp; // ...</DIV>
<DIV>&nbsp; &nbsp; };</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; Pair&lt;LedNumer, LedNumber&gt; getLeds(Key key) {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; switch(key) {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case Key_7:</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case Key_Current:</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ...</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case Key_8:&nbsp;</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case Key_Voltage:</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ...</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</DIV>
<DIV>&nbsp; &nbsp; &nbsp; }</DIV>
<DIV>&nbsp; &nbsp; }</DIV>
<DIV><BR></DIV>
<DIV>C++ does't like this. It would be nice if this was allowed. I wrote an=
 ugly workaround like</DIV></DIV>
<DIV><BR></DIV>
<DIV>
<DIV>&nbsp; &nbsp; Pair&lt;LedNumer, LedNumber&gt; getLeds(Key key) {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; switch(key) {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case SameValues&lt;Key_7, Key_Current&gt;:=
:value:</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ...</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; case SameValues&lt;Key_8, Key_Voltage&gt;:=
:value:</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // ...</DIV>
<DIV>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;</DIV>
<DIV>&nbsp; &nbsp; &nbsp; }</DIV>
<DIV>&nbsp; &nbsp; }</DIV></DIV>
<DIV><BR></DIV>
<DIV>Which static_asserts that all constants have the same value. But I wou=
ld like to have native readable language support. Does anyone feel the same=
?</DIV></BLOCKQUOTE>

<p></p>

-- <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_123_24783969.1355311661657--

.
