220 27617 <7f85133e-f985-4f96-b550-42909016ce2b@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: tomalak@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Sort of "static assert" for coverage of enumerations
 within a switch
Date: Thu, 4 Aug 2016 16:10:39 -0700 (PDT)
Lines: 192
Approved: news@gmane.org
Message-ID: <7f85133e-f985-4f96-b550-42909016ce2b@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_988_809003679.1470352239480"
X-Trace: blaine.gmane.org 1470352247 31539 195.159.176.226 (4 Aug 2016 23:10:47 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 4 Aug 2016 23:10:47 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD2MBSP3TQARB4EWR66QKGQEEAJ22BY@isocpp.org Fri Aug 05 01:10:42 2016
Return-path: <std-proposals+bncBD2MBSP3TQARB4EWR66QKGQEEAJ22BY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pf0-f199.google.com ([209.85.192.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD2MBSP3TQARB4EWR66QKGQEEAJ22BY@isocpp.org>)
	id 1bVRmj-0007Vh-Ju
	for gclcip-std-proposals@m.gmane.org; Fri, 05 Aug 2016 01:10:41 +0200
Original-Received: by mail-pf0-f199.google.com with SMTP id w128sf484124304pfd.3
        for <gclcip-std-proposals@m.gmane.org>; Thu, 04 Aug 2016 16:10:42 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=0/k6+pAFMgLzQMydZfp4Hwy0PUm38qPjm2ifdAHDPzs=;
        b=lmlPWo+HbsxDiyfB1vJahP8PyHtDKCL8u3eRM873VomQB0mvqDKgL/Bp41jYlvdD53
         RBdXn800hOSOPV/B7KKj2Ftk2/a8NbXbzUs8yWhmLdPQCbPv7mXZgXUncRsqoEX+Z659
         3/oD3I8qsBSYTrAGh4I4unDuziOonadANQ+0xuho3SXs5bEw7XLPT1ClISKs2aCf/LpD
         3htGdjJME6A6J4QJw6w/ake6yc8Galg/L7YbDs0T+EyyDpeTqa5CgV0hOvcRgc440ZQZ
         HaVcwJgYyDDOwac7nyDfbfkAxdPG529jUULfLE3GfFt48FB4Z7Pzplwv+RjjzuOOModN
         +ZAw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-spam-checked-in-group
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=0/k6+pAFMgLzQMydZfp4Hwy0PUm38qPjm2ifdAHDPzs=;
        b=ck0o5NCnxmeSpMJf2L3jlnoJRJ2UD2kDazOZLdx9EsGdmvtetF81dJTXYkd8CFqsyJ
         RpsYY9QvmW0jzgaIuQKmQ8wT+q+erwZRJfJzLW5Ud/kg6xjWrWh7aCzgaxOobRjYUAGm
         yeOQuWZjfqK6d4+giV0sn85s4Y/ybNNqlrO4TMSRB0H3AvLEhCckZzdYVW9H516cr0q1
         anK2t20yGzpcnQV8CdyYXf4ZJShTYY3L3K63f7VSZXg+l/tAFcf+rSSMFd6ty26hLOfr
         TmeRdpDfe8MbWK6Ir99dAHcpCxU34r6Jn3AMR+5LX1Pc1gCi/8zh/w8T9z6qZ6NWcmmm
         2+0A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=0/k6+pAFMgLzQMydZfp4Hwy0PUm38qPjm2ifdAHDPzs=;
        b=epMTwiILtQNy9PkBbmY71/FGiYt0zPtHY01nAqJhoFWpWDJbDALqQaZhrYwmECByXK
         nUMM2hTt9lmh2q98YKYrQhRJ0rFeqc+jyb5+CCBW8vVYEQG0lPwYOOL5GMuqDLLqy7wK
         vTC3A2stAFhT2i3AcCHEV6QDZp8y0uSEX3n/X2OGOgwmkQWWx5pHCgvY3pqoxVgRlO8d
         cNa38AgJI6Q1qxj+DD7hhuoG41y3qKGxOS2HSHAiZE0vfjFxtDY6O34/V7zQ7VK8rNNC
         D85upHqn7s7SnJaGO5ECJnUk31sxyXBvHyPhfLtVCQJ8lph978jF4eLjLZnZcvfkCo8z
         ypag==
X-Gm-Message-State: AEkoouvTHMuXM0AKoHw9uXzsShRioWBw7GbLdWJVKuQXxUjlDIOpImfYCvPPCNBoZfgVAw==
X-Received: by 10.66.183.229 with SMTP id ep5mr65923056pac.3.1470352241330;
        Thu, 04 Aug 2016 16:10:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.20.68 with SMTP id 65ls1843411iou.16.gmail; Thu, 04 Aug
 2016 16:10:40 -0700 (PDT)
X-Received: by 10.36.36.10 with SMTP id f10mr26849ita.7.1470352240360;
        Thu, 04 Aug 2016 16:10:40 -0700 (PDT)
X-Original-Sender: tomalak@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:27617
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/27617>

------=_Part_988_809003679.1470352239480
Content-Type: multipart/alternative; 
	boundary="----=_Part_989_1004757785.1470352239487"

------=_Part_989_1004757785.1470352239487
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Sup,

Sorry that this is so embryonic, but I wanted to open a discussion about it=
=20
before going too far down the rabbit hole. Besides, it may have been=20
considered already.

Good old fashioned enum:

enum E
{
   A,
   B,
   C
};


Make it a scoped enum if you like.

Two ways of "ensuring" that all enumerators are considered in a switch=20
(which isn't always what you want; let's assume that, in this scenario, it=
=20
*is*):

switch (e) {
   case A:
   case B:
   case C:
      foo();
      break;
  =20
   default:
      assert(false);
}


Or my favourite =E2=80=94 omit the `default` case and pay attention to warn=
ings so=20
that you at least get immediate feedback at build time:

switch (e) {
   case A:
   case B:
   case C:
     foo();
     break;
}


Maybe we should have a sort of static_assert equivalent that can break the=
=20
build when not all enumerations are covered by a switch?

Just a thought.

Discuss.....


-Lightness

--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/7f85133e-f985-4f96-b550-42909016ce2b%40isocpp.or=
g.

------=_Part_989_1004757785.1470352239487
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sup,<div><br></div><div>Sorry that this is so embryonic, b=
ut I wanted to open a discussion about it before going too far down the rab=
bit hole. Besides, it may have been considered already.<div><br></div><div>=
Good old fashioned enum:</div><div><br></div><div class=3D"prettyprint" sty=
le=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgrou=
nd-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"su=
bprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">enu=
m</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> E<br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0A</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0B</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0C<br></=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</span></d=
iv></code></div><div><br></div><div><br></div><div>Make it a scoped enum if=
 you like.</div><div><br></div><div>Two ways of &quot;ensuring&quot; that a=
ll enumerators are considered in a switch (which isn&#39;t always what you =
want; let&#39;s assume that, in this scenario, it <i>is</i>):</div><div><br=
></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, =
187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><code c=
lass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">switch</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">e</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">case</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">case</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> B</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">case</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> C</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>=C2=A0 =C2=A0 =C2=A0 foo</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">break</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0<br>=C2=A0 =C2=A0</span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">default</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">assert</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">false</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">}</span></div></code></div><div><br></div><div><br></div><div>Or =
my favourite =E2=80=94 omit the `default` case and pay attention to warning=
s so that you at least get immediate feedback at build time:</div><div><div=
><br></div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 1=
87, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><co=
de class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">switch</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">e</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">case</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">case</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> B</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">case</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> C</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>=C2=A0 =C2=A0 =C2=A0foo</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">break</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">}</span></div></code></div><div><br></div></div><div><br></div>=
<div>Maybe we should have a sort of static_assert=C2=A0equivalent that can =
break the build when not all enumerations are covered by a switch?</div><di=
v><br></div><div>Just a thought.</div><div><br></div><div>Discuss.....</div=
><div><br></div><div><br></div><div>-Lightness</div></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/7f85133e-f985-4f96-b550-42909016ce2b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/7f85133e-f985-4f96-b550-42909016ce2b=
%40isocpp.org</a>.<br />

------=_Part_989_1004757785.1470352239487--

------=_Part_988_809003679.1470352239480--

.
