220 33523 <68a9dd6e-7e33-4e3a-96da-24fe435eda5a@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: wei zhang <lala.willzhang@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: A more advanced switch
Date: Tue, 1 Aug 2017 23:19:39 -0700 (PDT)
Lines: 198
Approved: news@gmane.org
Message-ID: <68a9dd6e-7e33-4e3a-96da-24fe435eda5a@isocpp.org>
References: <f8c908e2-d06f-4cd1-bda0-fe2b97fd21f1@isocpp.org>
 <34130636.8iyeqGTS6R@tjmaciei-mobl1>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5202_965121556.1501654779451"
X-Trace: blaine.gmane.org 1501654789 32307 195.159.176.226 (2 Aug 2017 06:19:49 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 2 Aug 2017 06:19:49 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDWIFSHO6EDBB7G5QXGAKGQEFOMQZSI@isocpp.org Wed Aug 02 08:19:42 2017
Return-path: <std-proposals+bncBDWIFSHO6EDBB7G5QXGAKGQEFOMQZSI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pg0-f70.google.com ([74.125.83.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDWIFSHO6EDBB7G5QXGAKGQEFOMQZSI@isocpp.org>)
	id 1dcn0J-0007bl-F5
	for gclcip-std-proposals@m.gmane.org; Wed, 02 Aug 2017 08:19:35 +0200
Original-Received: by mail-pg0-f70.google.com with SMTP id u7sf40716714pgo.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 01 Aug 2017 23:19:41 -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:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=fxOOrJ/v05g/Tapq4zhk7wfyMybKvMbO9tv7PhnzHXk=;
        b=OQJfmTF/uAF4BVT7uKHP6I+2RaRqDR/feWmIVphLsIQcEeJef9t1sBXoxCJlN3E11S
         dHVTf65J1tOv+DgDlNANcohxZhv2eejgUpYyGZoLkfqGdjVY2OUrto8ElQHpMfXIpb+t
         m4YzCkTIAbyy/5ZxV7SkYf0Z1H5VMNa+4B4F78MtdYYgcVBVRZ8+doh/njDKnEA4BAHG
         t2EJ+cfkNYxlUObWpW7IkPjWxJxhrzjpQsQoB8VegsRVJobIgWpdjoxUIo7E3z0l6LlZ
         PFxfEmPwUK9jyQOmkQSqWp8vlnD8zCPnxdPF6tjXiLtnsx5X/2mdOljkh5vCwaKgvckV
         1kEA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=fxOOrJ/v05g/Tapq4zhk7wfyMybKvMbO9tv7PhnzHXk=;
        b=rCHwQkLsMt+kjOWPBSvI1gEavarMvhDF0kQDWSgOv0XljXoUvzPa0WwP/CTDwG8kvH
         +EvOkZnM8y++ogQIAj1EHFx8/qilwY4p0kmtqIlOYg3ttU2+DhXwMFzHoTEOjqi0BGQq
         ES713txnyQCU6jAtJ+P+9Vf6d9dJzmDNQOG3NoNuAOgvx9TKUUgm0d4rgoVTAhKD1w6N
         1jQtPzagUaXELN1XZviCa49++e+RdoRHUuoPuF4KfnY8EXVsfl4cT6qYxhjj9u4n340X
         tmwqoSeZspC6GA2t5wnFDS9oOVV0bELUhX0TIdQEr5ApLDrFfX9XtK7W/aHtvTRJPJv7
         A0Zw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :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=fxOOrJ/v05g/Tapq4zhk7wfyMybKvMbO9tv7PhnzHXk=;
        b=LnjhY4eLTeEVaN4mFw1DlFfCo2rnwtdvBWjVASwFFK0BoGYUrjNcLtiR1ktk1mjG/W
         I0NifbDLfzqn0FoQ++/NlwiZFri8a5At6EoLx5XZ1t0Ta/vKyjZvWgkMluWyd4XEU+vU
         ogekg3qI9N4QTNcftyLgtyCuH0RR4dEcPyJgDhxM0vmiv/FoRZCTKCguOO3gmwJfao1d
         XYNEJWqrpRXbex8eMiJoqCjfebeq+zDUpbxE7cqHgvBaV3z+z+xMYDJ5uJnJdeVedX4W
         60lh3Te2i5+2vv+YRMszYc7u3wl3bF0eFBxt3ZZ/1p3YBhUUms5qV3GW+m4IuSuqgFPc
         35xQ==
X-Gm-Message-State: AIVw113wUvmkpBKOKJ+MgDUxoVAfNpUo4k6iOtDDvj5c8Os5KvEVvhkh
	wGwkALFprk727Rsq
X-Received: by 10.98.11.200 with SMTP id 69mr2762276pfl.21.1501654781176;
        Tue, 01 Aug 2017 23:19:41 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.43.81 with SMTP id r78ls11851664ior.51.gmail; Tue, 01 Aug
 2017 23:19:39 -0700 (PDT)
X-Received: by 10.31.153.84 with SMTP id b81mr113475vke.14.1501654779916;
        Tue, 01 Aug 2017 23:19:39 -0700 (PDT)
In-Reply-To: <34130636.8iyeqGTS6R@tjmaciei-mobl1>
X-Original-Sender: lala.willzhang@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:33523
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33523>

------=_Part_5202_965121556.1501654779451
Content-Type: multipart/alternative; 
	boundary="----=_Part_5203_1138877533.1501654779451"

------=_Part_5203_1138877533.1501654779451
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

We can only add silently with case 5, 6:




=E5=9C=A8 2017=E5=B9=B48=E6=9C=882=E6=97=A5=E6=98=9F=E6=9C=9F=E4=B8=89 UTC+=
8=E4=B8=8A=E5=8D=885:34:29=EF=BC=8CThiago Macieira=E5=86=99=E9=81=93=EF=BC=
=9A
>
> On ter=C3=A7a-feira, 1 de agosto de 2017 14:24:04 PDT costeln...@gmail.co=
m=20
> <javascript:>=20
> wrote:=20
> > We have to use "case" for every, well, case when specifying a sequence,=
=20
> > because it uses fallthrough. We have to use "break" to avoid that. I=20
> find=20
> > this bad. Because of the necessity of using "break" we can't just=20
> "break"=20
> > out of a loop if the switch is inside a loop. Also, if there are=20
> > consecutive cases we have to specify each one of them. Additionally, we=
=20
> > could also forget breaking. This "switch" isn't safe and is pretty old.=
=20
> >=20
> > In Pawn we can do it a lot better:=20
> > switch( variable )=20
> > {=20
> >     case 0 .. 4:=20
>
> With GNU extensions to C and C++:=20
>
>         case 0 ... 4:=20
>
> > 1. There's no need for break, there's no fallthrough. Advantage: we can=
=20
> > easily "continue" and "break" loops from inside the "switch".=20
>
> That can't change now. This HAS been discussed in this list and in std-=
=20
> discussions and, just like the non-local breaks, it's very hard to adapt=
=20
> the=20
> language grammar to.=20
>
> We need a different keyword or some modification keyword to the switch,=
=20
> since=20
> there is unmarked code that expects to fall through. We cannot silently=
=20
> break=20
> them.=20
>
> > I know that it's hard to have features accepted in such a popular=20
> standard,=20
> > but upgrading switch is something that should really be considered !=20
> > C++17's [[fallthrough]] attribute is just as complicated as the=20
> "switch".=20
> > It needs to be added everywhere or else we would get warnings (AFAIK).=
=20
>
> We've done that in Qt. Not very difficult once the compiler starts=20
> warning.=20
>
> The difficult part is to guess whether a fallthrough was intended or a=20
> break was=20
> missing.=20
>
> --=20
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org=20
>    Software Architect - Intel Open Source Technology Center=20
>
>

--=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/68a9dd6e-7e33-4e3a-96da-24fe435eda5a%40isocpp.or=
g.

------=_Part_5203_1138877533.1501654779451
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">We can only add silently with case 5, 6:<div><br></div><di=
v><br><div><br><br>=E5=9C=A8 2017=E5=B9=B48=E6=9C=882=E6=97=A5=E6=98=9F=E6=
=9C=9F=E4=B8=89 UTC+8=E4=B8=8A=E5=8D=885:34:29=EF=BC=8CThiago Macieira=E5=
=86=99=E9=81=93=EF=BC=9A<blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On ter=
=C3=A7a-feira, 1 de agosto de 2017 14:24:04 PDT <a href=3D"javascript:" tar=
get=3D"_blank" gdf-obfuscated-mailto=3D"Z8Ui7RrhBAAJ" rel=3D"nofollow" onmo=
usedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclick=3D"this.=
href=3D&#39;javascript:&#39;;return true;">costeln...@gmail.com</a>=20
<br>wrote:
<br>&gt; We have to use &quot;case&quot; for every, well, case when specify=
ing a sequence,
<br>&gt; because it uses fallthrough. We have to use &quot;break&quot; to a=
void that. I find
<br>&gt; this bad. Because of the necessity of using &quot;break&quot; we c=
an&#39;t just &quot;break&quot;
<br>&gt; out of a loop if the switch is inside a loop. Also, if there are
<br>&gt; consecutive cases we have to specify each one of them. Additionall=
y, we
<br>&gt; could also forget breaking. This &quot;switch&quot; isn&#39;t safe=
 and is pretty old.
<br>&gt;=20
<br>&gt; In Pawn we can do it a lot better:
<br>&gt; switch( variable )
<br>&gt; {
<br>&gt; =C2=A0 =C2=A0 case 0 .. 4:
<br>
<br>With GNU extensions to C and C++:
<br>
<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0case 0 ... 4:
<br>
<br>&gt; 1. There&#39;s no need for break, there&#39;s no fallthrough. Adva=
ntage: we can
<br>&gt; easily &quot;continue&quot; and &quot;break&quot; loops from insid=
e the &quot;switch&quot;.
<br>
<br>That can&#39;t change now. This HAS been discussed in this list and in =
std-
<br>discussions and, just like the non-local breaks, it&#39;s very hard to =
adapt the=20
<br>language grammar to.
<br>
<br>We need a different keyword or some modification keyword to the switch,=
 since=20
<br>there is unmarked code that expects to fall through. We cannot silently=
 break=20
<br>them.
<br>
<br>&gt; I know that it&#39;s hard to have features accepted in such a popu=
lar standard,
<br>&gt; but upgrading switch is something that should really be considered=
 !
<br>&gt; C++17&#39;s [[fallthrough]] attribute is just as complicated as th=
e &quot;switch&quot;.
<br>&gt; It needs to be added everywhere or else we would get warnings (AFA=
IK).
<br>
<br>We&#39;ve done that in Qt. Not very difficult once the compiler starts =
warning.
<br>
<br>The difficult part is to guess whether a fallthrough was intended or a =
break was=20
<br>missing.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.goo=
gle.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\=
x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x=
3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return t=
rue;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" target=3D"=
_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.google.=
com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
GRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;=
http://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1=
\x26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a=
>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/68a9dd6e-7e33-4e3a-96da-24fe435eda5a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/68a9dd6e-7e33-4e3a-96da-24fe435eda5a=
%40isocpp.org</a>.<br />

------=_Part_5203_1138877533.1501654779451--

------=_Part_5202_965121556.1501654779451--

.
