220 38053 <9fa8e6c3-f3c7-468e-bb0f-b9197a88eb80@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: david.bolvansky@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: [[likely]] attribute for switch case
Date: Tue, 8 May 2018 09:29:26 -0700 (PDT)
Lines: 158
Approved: news@gmane.org
Message-ID: <9fa8e6c3-f3c7-468e-bb0f-b9197a88eb80@isocpp.org>
References: <9adde2c8-8306-4708-96f2-edb621d906c7@isocpp.org>
 <0918afa6-6f04-fdc1-fd80-f2843a5e63f1@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_3928_1786510966.1525796966258"
X-Trace: blaine.gmane.org 1525796841 7436 195.159.176.226 (8 May 2018 16:27:21 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 8 May 2018 16:27:21 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDSMRTMFUIFRBZ5AY7LQKGQECJRQ6RA@isocpp.org Tue May 08 18:27:17 2018
Return-path: <std-proposals+bncBDSMRTMFUIFRBZ5AY7LQKGQECJRQ6RA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f70.google.com ([209.85.213.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDSMRTMFUIFRBZ5AY7LQKGQECJRQ6RA@isocpp.org>)
	id 1fG5SO-0001qK-Rr
	for gclcip-std-proposals@m.gmane.org; Tue, 08 May 2018 18:27:17 +0200
Original-Received: by mail-vk0-f70.google.com with SMTP id h62-v6sf12352789vke.1
        for <gclcip-std-proposals@m.gmane.org>; Tue, 08 May 2018 09:29:28 -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=sRkubCCK1MpViGEKJe+CnlWWu2HW3NJDTGnyn8hImj4=;
        b=K3f1sDFLru2fBxcCdNfL6Me4ypsX49j3USosapmQiwhsNRknfeMcfNEX6cn7mPMrz3
         UeFkseXEUzgx9U2tfPoIkB3zFb7J8tfCwa7EuXFUDcK4i5j2zdEpxMJKrmV92IuiQkbm
         jQKJjeDWKsKuwOQuP0L0J81N05mcyVgKoqFEj7d2StE+slOzdNYg59hWckuBqBKcccZJ
         9HvtDp2Xe324JTWmkNqZc2jum/7VKFGfpIEfUJk+7DSrdvgmTRlFZhaviH/nmCBojfKJ
         qwV1K/mpAYIj74iEYYJm3et3c1nySlhoebKuHEMbQmyguKQq4so249wPrwWlmo9Fq2O3
         emaw==
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=sRkubCCK1MpViGEKJe+CnlWWu2HW3NJDTGnyn8hImj4=;
        b=GNRWexvI3FRDAK033oM4RlrwJGVcjn0XVyhjVOZzI/cUO7f8yj/k51SYUr+Yq5oqwD
         1azA9nEnvdeFodvJ+bQpoK418mEDxPu8oJm7Yqg68accKhuTFk9dAnlSx6u5Q9m4fCIb
         dJPIb8+EvD1KwP+RYRIUDDnUTJCxPto4VFYV7Ybdlto0RbKSP3l4yTHKphaNwttDk1ay
         NWFUB9Z595/wvYRlEfWfsZGt3cs9596e3FbYhL0qnN8PPXJbpzF1j+BTVTv7rBADyNiJ
         fNvyn1cVkfgu3Ohnp5OAALS48Qf9ZBkBI16cIdvMEgUtve/Rmc+459NJIctfTVQoKtXg
         8Mkw==
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=sRkubCCK1MpViGEKJe+CnlWWu2HW3NJDTGnyn8hImj4=;
        b=BjvE1TEmPILziLsdrpb33iGqipT6VpgScSZvgzRZ/AmVYGb6mWfCoZyFRTKFtlmx1L
         fINNwPQtzwxaYE4ybVb14Sm6Rty5LWA+SVyIhyXCcTGNH6AWNnCGH4rDaiPDdtrWsQQy
         U4d+zA5klX3KvCXKfxDY9wVHrd0Z4XB6mDDfBLYifUl4+kMixRE4DCuChyf+w0BeZzfH
         tV2JjjSZJc3lMlaQCH5hQxmJgpNYuVQSk1WNJWjd6wCASkJK+VBOAqvujEuAJZRWuBJ1
         h/u3GzBLHcUY2X8sGoVv8lSUbowNIy2r6sYraYWFeJUdBqn2rvDIhEom1FYpUVv8VbPq
         lOgw==
X-Gm-Message-State: ALQs6tDmoGO+x7CD2lZcDdoQx6lkgfYHsdg1oGcb66L8xPBavFZBZPu2
	STwnH0vJ6dV0ofWzNGJeNameyQ==
X-Google-Smtp-Source: AB8JxZpo6HBPWXCwheEQz5jHBedGYfrAo2jnGs40EsPxG+i5mRBTCPS4PRHU7o1EooCeEek4lAs1jQ==
X-Received: by 2002:a1f:848d:: with SMTP id g135-v6mr21534973vkd.11.1525796967749;
        Tue, 08 May 2018 09:29:27 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a1f:db45:: with SMTP id s66-v6ls965511vkg.12.gmail; Tue, 08
 May 2018 09:29:26 -0700 (PDT)
X-Received: by 2002:a1f:3095:: with SMTP id w143-v6mr6596136vkw.9.1525796966756;
        Tue, 08 May 2018 09:29:26 -0700 (PDT)
In-Reply-To: <0918afa6-6f04-fdc1-fd80-f2843a5e63f1@gmail.com>
X-Original-Sender: david.bolvansky@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:38053
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/38053>

------=_Part_3928_1786510966.1525796966258
Content-Type: multipart/alternative; 
	boundary="----=_Part_3929_329272358.1525796966258"

------=_Part_3929_329272358.1525796966258
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Thanks, N4741 really has it already.

D=C5=88a utorok, 8. m=C3=A1ja 2018 18:08:48 UTC+2 Andrey Semashev nap=C3=AD=
sal(-a):
>
> On 05/08/18 18:48, david.b...@gmail.com <javascript:> wrote:=20
> > Hello,=20
> >=20
> > Since in C++20 we can write:=20
> >=20
> > char * b(int e) {=20
> > if  ([[likely]] e =3D=3D 0)=20
> > return "0";=20
> > else if (e =3D=3D 1)=20
> > return "1";=20
> >     else return "undef";=20
> > }=20
> >=20
> > Can likely attribute be added even for switch case? Like for example:=
=20
> >=20
> > switch(e) {=20
> >      case 0 [[likely]]:=20
> >            return "0";=20
> >      case 1:=20
> >           return "1";=20
> >      default:=20
> >           return "undef";=20
> >=20
> > }=20
> >=20
> >=20
> > I read the "likely" attribute=20
> > proposal=20
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0479r0.html=20
> > and they do not mention this use case for switches.=20
>
> N4741 includes and example with `switch`/`case` in=20
> [dcl.attr.likelihood]/3.=20
>
> I suspect your example with an `if` statement is not doing what you=20
> think it does. The [[likely]] applies to the condition expression, which=
=20
> basically says "this condition is likely to be executed" and not "this=20
> condition is likely to be true". The correct example is also given in=20
> the aforementioned section.=20
>
> This is the most unfortunate aspect of this proposal as it makes it=20
> incompatible with __builtin_expect and tons of code that wraps it in=20
> macros.=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/9fa8e6c3-f3c7-468e-bb0f-b9197a88eb80%40isocpp.or=
g.

------=_Part_3929_329272358.1525796966258
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Thanks, N4741 really has it already.<br><br>D=C5=88a utoro=
k, 8. m=C3=A1ja 2018 18:08:48 UTC+2 Andrey Semashev nap=C3=ADsal(-a):<block=
quote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-le=
ft: 1px #ccc solid;padding-left: 1ex;">On 05/08/18 18:48, <a href=3D"javasc=
ript:" target=3D"_blank" gdf-obfuscated-mailto=3D"KTwhuBEiBgAJ" rel=3D"nofo=
llow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;return true;" onclic=
k=3D"this.href=3D&#39;javascript:&#39;;return true;">david.b...@gmail.com</=
a> wrote:
<br>&gt; Hello,
<br>&gt;=20
<br>&gt; Since in C++20 we can write:
<br>&gt;=20
<br>&gt; char * b(int e) {
<br>&gt; if=C2=A0 ([[likely]] e =3D=3D 0)
<br>&gt; return &quot;0&quot;;
<br>&gt; else if (e =3D=3D 1)
<br>&gt; return &quot;1&quot;;
<br>&gt; =C2=A0=C2=A0 =C2=A0else return &quot;undef&quot;;
<br>&gt; }
<br>&gt;=20
<br>&gt; Can likely attribute be added even for switch case? Like for examp=
le:
<br>&gt;=20
<br>&gt; switch(e) {
<br>&gt; =C2=A0=C2=A0 =C2=A0 case 0 [[likely]]:
<br>&gt; =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return &quot;0&quot;;
<br>&gt; =C2=A0=C2=A0 =C2=A0 case 1:
<br>&gt; =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return &quot;1&quot;;
<br>&gt; =C2=A0=C2=A0 =C2=A0 default:
<br>&gt; =C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return &quot;undef&quot;;
<br>&gt;=20
<br>&gt; }
<br>&gt;=20
<br>&gt;=20
<br>&gt; I read the &quot;likely&quot; attribute=20
<br>&gt; proposal=C2=A0<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/do=
cs/papers/2016/p0479r0.html" target=3D"_blank" rel=3D"nofollow" onmousedown=
=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.open-s=
td.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0479r0.html\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNFxGsWJ-xIPfVshaBevbFktekHjfQ&#39;;return tru=
e;" onclick=3D"this.href=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2=
Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2016%2Fp0479r0.htm=
l\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxGsWJ-xIPfVshaBevbFktekHjfQ&#39;=
;return true;">http://www.open-std.<wbr>org/jtc1/sc22/wg21/docs/<wbr>papers=
/2016/p0479r0.html</a>=20
<br>&gt; and they do not mention this use case for switches.
<br>
<br>N4741 includes and example with `switch`/`case` in [dcl.attr.likelihood=
]/3.
<br>
<br>I suspect your example with an `if` statement is not doing what you=20
<br>think it does. The [[likely]] applies to the condition expression, whic=
h=20
<br>basically says &quot;this condition is likely to be executed&quot; and =
not &quot;this=20
<br>condition is likely to be true&quot;. The correct example is also given=
 in=20
<br>the aforementioned section.
<br>
<br>This is the most unfortunate aspect of this proposal as it makes it=20
<br>incompatible with __builtin_expect and tons of code that wraps it in ma=
cros.
<br></blockquote></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/9fa8e6c3-f3c7-468e-bb0f-b9197a88eb80%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9fa8e6c3-f3c7-468e-bb0f-b9197a88eb80=
%40isocpp.org</a>.<br />

------=_Part_3929_329272358.1525796966258--

------=_Part_3928_1786510966.1525796966258--

.
