Topic: Allow multiple same case values if they are next
Author: Arthur Tchaikovsky <atch.cpp@gmail.com>
Date: Wed, 12 Dec 2012 03:27:41 -0800 (PST)
Raw View
------=_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). =20
<DIV><BR></DIV>
<DIV>
<DIV>I had this code</DIV>
<DIV><BR></DIV>
<DIV> enum Key {</DIV>
<DIV> Key_7 =3D 1</DIV>
<DIV> Key_Current =3D 1,</DIV>
<DIV><BR></DIV>
<DIV> Key_8 =3D 2,</DIV>
<DIV> Key_Voltage =3D 2, </DIV>
<DIV><BR></DIV>
<DIV> // ...</DIV>
<DIV> };</DIV>
<DIV><BR></DIV>
<DIV> Pair<LedNumer, LedNumber> getLeds(Key key) {</DIV>
<DIV> switch(key) {</DIV>
<DIV> case Key_7:</DIV>
<DIV> case Key_Current:</DIV>
<DIV> // ...</DIV>
<DIV> break;</DIV>
<DIV><BR></DIV>
<DIV> case Key_8: </DIV>
<DIV> case Key_Voltage:</DIV>
<DIV> // ...</DIV>
<DIV> break;</DIV>
<DIV> }</DIV>
<DIV> }</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> Pair<LedNumer, LedNumber> getLeds(Key key) {</DIV>
<DIV> switch(key) {</DIV>
<DIV> case SameValues<Key_7, Key_Current>:=
:value:</DIV>
<DIV> // ...</DIV>
<DIV> break;</DIV>
<DIV><BR></DIV>
<DIV> case SameValues<Key_8, Key_Voltage>:=
:value:</DIV>
<DIV> // ...</DIV>
<DIV> break;</DIV>
<DIV> }</DIV>
<DIV> }</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 />
<br />
<br />
<br />
------=_Part_123_24783969.1355311661657--
.