220 32549 <2798d4f2-09b1-4030-965d-0bbb36a5549b@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: ma.kalbfuss@web.de
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: relaxing rules for ternary operator. Allow
 incompatible types.
Date: Sun, 21 May 2017 07:11:13 -0700 (PDT)
Lines: 738
Approved: news@gmane.org
Message-ID: <2798d4f2-09b1-4030-965d-0bbb36a5549b@isocpp.org>
References: <1b5ee8eb-53df-4e98-af2f-829c7bc2e5b2@isocpp.org>
 <9064929.QEV8q21eIZ@tjmaciei-mobl1>
 <99350a9e-0c6b-468d-9761-f2b2b052275e@isocpp.org>
 <795341bd-d042-49c9-9eba-6b8ac6ca8a5e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_2087_1742423123.1495375873967"
X-Trace: blaine.gmane.org 1495375875 22774 195.159.176.226 (21 May 2017 14:11:15 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 21 May 2017 14:11:15 +0000 (UTC)
Cc: ma.kalbfuss@web.de
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC7YTI72XQOBBAWAQ3EQKGQEVS2WCPA@isocpp.org Sun May 21 16:11:10 2017
Return-path: <std-proposals+bncBC7YTI72XQOBBAWAQ3EQKGQEVS2WCPA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb0-f198.google.com ([209.85.213.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC7YTI72XQOBBAWAQ3EQKGQEVS2WCPA@isocpp.org>)
	id 1dCRZd-0005nZ-P4
	for gclcip-std-proposals@m.gmane.org; Sun, 21 May 2017 16:11:10 +0200
Original-Received: by mail-yb0-f198.google.com with SMTP id 130sf12653436ybl.7
        for <gclcip-std-proposals@m.gmane.org>; Sun, 21 May 2017 07:11:15 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc: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=MgtklsRYpYizKAQE6Y8MiBlyjDcE5caU9ucdjc7qaKk=;
        b=MmeLdTavW/DneybxTdwvqHLnr2fCvtmNt0Ide7DdQrhbxUL95XADc2APDv2zat/rpm
         lPp4sjyU2pcavxLOxAJzcv11k0Ux+8szoa/g+ZozpU3ereHL7Q/6NJ0gbnx6BW1T75mQ
         H9g703hbYrxrSiOcthovs6FsKPBBvCobYQlpWvA4ercRHeTjqglkEfxyZiEesLPZ/p+D
         2iLyisi4S89aBJ+SEh3VsYX0vqCx29zl5ne9obgFZyWgcEONJ6jszvnY5J4BKifCjWU1
         97G2lc+tf7ZdBA/iU8rK1dNqzO7TcxZ2TxOZuNhINAktxO8ZG0JlLRU0oN96Ka1rSfCb
         WXtg==
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:cc: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=MgtklsRYpYizKAQE6Y8MiBlyjDcE5caU9ucdjc7qaKk=;
        b=omoXJbY8NkWhFNNTOS1bxxe+8KJLVsF65xeJi6rc3htqkAtz5vI352KXfX1ktT/TvG
         2moRqG9uQdHRgkKrMoQFvCzkHNSWZ7m7AlfDIyzO2WHA67BwjX6KAVh4C1meLwNE/7K+
         LoLFNLj/Bwoyz++5J3wrIFZqyS7A0pIyJEAVFGTeL1j0EOfiBYSjFAouWyQWbeNf2qh7
         dv+P6eIjnDmWgklDlAdILJ5fuG58exGfUk41Yf65V59kQzBHJfMnm8ck3NkMpSwxjE4V
         NbcIvW1JhvM66PBB0jLWY5Ux6eRkerXNf1pgOnvu9lz4a0kr1R+n8fAvPPxD4uRMBVEx
         4GJw==
X-Gm-Message-State: AODbwcAPSO/bARrcDbEC1Ir+1T0LiW8ABtnCY66GXDxN5rLPvyjbXfVt
	Ym2x1e0iSDReqTVT
X-Received: by 10.129.160.196 with SMTP id x187mr9203418ywg.90.1495375875221;
        Sun, 21 May 2017 07:11:15 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.45.193 with SMTP id g59ls2104768otb.40.gmail; Sun, 21 May
 2017 07:11:14 -0700 (PDT)
X-Received: by 10.157.17.23 with SMTP id g23mr390652ote.4.1495375874425;
        Sun, 21 May 2017 07:11:14 -0700 (PDT)
In-Reply-To: <795341bd-d042-49c9-9eba-6b8ac6ca8a5e@isocpp.org>
X-Original-Sender: ma.kalbfuss@web.de
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:32549
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32549>

------=_Part_2087_1742423123.1495375873967
Content-Type: multipart/alternative; 
	boundary="----=_Part_2088_776051707.1495375873969"

------=_Part_2088_776051707.1495375873969
Content-Type: text/plain; charset="UTF-8"

The following code should be generated when a loop is involved. the loop 
has its own scope. The code duplication is limited to the scope of the loop.
But let's improve it further. Instead of duplicate the following code in 
the enclosing scope, it is sufficient to duplicate the dependend code.
Code is dependend  if the result of the ternary operation is involved. So 
only these parst are duplicated. As an addition, the code is only 
duplicated,
if the condition is known at runtime. If it is known at compile time, only 
one branch is created. Code outside of the loop or the code necessary to
implement the loop is NOT duplicated and is not part of the branches. For 
now, I will call this construct "generic ternary operator". Like other 
generics
it introduces code duplication. It's not a special problem of this 
construct.
It is important, that existing code does not break. For cases where the 
existing conversion rules apply, there should be no duplication.

Exmaple including a loop:

struct A{ void doit(){ } };
struct B{ void doit(){ } };

int main()
{
    auto runtime_condition = true;

    for(int i = 0; i < 100; i++) {
        auto x = runtime_condition ? A{} : B{};
        x.doit();
        /* do something without x */
        x.doit()
        /* do something without x */
    }

    return 0;
}




struct A{ void doit(){ } };
struct B{ void doit(){ } };

int main()
{
    auto runtime_condition = true;

    for(int i = 0; i < 100; i++) {
        if(runtime_condition)
            goto ternary_branch_1;
        else
            goto ternary_branch_2;

ternary_branch_1:
        A __instance1__;
        __instance1__.doit();
        goto ternary_end_1;
ternary_branch_2:
        B __instance2__;
        __instance2__.doit();
ternary_end_1:         
        /* do something without x */;
ternary_branch_3:
        __instance1__.doit();
        goto ternary_end_2;
ternary_branch_4:
       __instance2__.doit();
ternary_end_2:
        /* do something without x */;
    }

    return 0;
}




A::doit():
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        nop
        pop     rbp
        ret
B::doit():
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        nop
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     BYTE PTR [rbp-5], 1
        mov     DWORD PTR [rbp-4], 0
..L11:
        cmp     DWORD PTR [rbp-4], 99
        jg      .L4
        cmp     BYTE PTR [rbp-5], 0
        je      .L13
        nop
        lea     rax, [rbp-6]
        mov     rdi, rax
        call    A::doit()
        jmp     .L9
..L13:
        nop
        lea     rax, [rbp-7]
        mov     rdi, rax
        call    B::doit()
..L9:
        lea     rax, [rbp-6]
        mov     rdi, rax
        call    A::doit()
        nop
        add     DWORD PTR [rbp-4], 1
        jmp     .L11
..L4:
        mov     eax, 0
        leave
        ret








Am Sonntag, 21. Mai 2017 15:00:03 UTC+2 schrieb Mingxin Wang:
>
> You may as well consider the following situations:
>
> *Loops*
>
> It is difficult for compilers to generate code for loops with the feature 
> you proposed, e.g.:
>
> void foo(int n) {
>   /* A: Do something before the loop */
>   for (int i = 0; i < n; ++i) {
>     /* B: Do something */
>     auto x = runtime_condition() ? A{} : B{};
>     /* C: Do some other things with x */
>   }
>   /* D: Do something after the loop */
> }
> *Code Snippet 1*
>
> As far as I am concerned, here is the equivalent of the code that the 
> compiler would automatically generate for the code above (with your method):
>
> template <class T>
> void bar(int i, int n, T x) {
>   /* C: Do some other things with x */
>   ++i;
>   if (i < n) {
>     /* B: Do something */
>     if (runtime_condition()) {
>       bar(i, n, A{});
>     } else {
>       bar(i, n, B{});
>     }
>   }
> }
>
> void foo(int n) {
>   /* A: Do something before the loop */
>   if (0 < n) {
>     /* B: Do something */
>     if (runtime_condition()) {
>       bar(1, n, A{});
>     } else {
>       bar(1, n, B{});
>     }
>   }
>   /* D: Do something after the loop */
> }
> *Code Snippet 2*
>
> It is too complicated! Moreover, as the recursive call of the "function 
> template bar" is not able to be optimized, it will possibly increase the 
> runtime overhead.
>
> *Size*
>
> Compilers may generate a lot of redundant code when the feature is used 
> extensively, e.g.:
>
> auto x0 = runtime_condition_0() ? A0{} : B0{};
> auto x1 = runtime_condition_1() ? A1{} : B1{};
> // ...
> auto xn = runtime_condition_n() ? An{} : Bn{};
> *Code Snippet 3*
>
> As you introduced, the compiler is supposed to generate code for every 
> path! For the code above, it requires O(2^n) size for code generation, 
> which is NOT acceptable in most cases.
>
> In fact, the challenges above can be solved gracefully with the "proxies" 
> and the "wrappers".
>
> As the condition is determined at runtime, the concrete type cannot be 
> deduced at compile time. The only reason for us to save the returned value 
> is that *they have similar expressions and semantics*. We can simply 
> extract the common expressions of the types which are used in the context 
> to a "proxy", and save the returned value with a "wrapper", e.g. Code 
> Snippet 1 can be reconstructed as is shown below (with better performance 
> and smaller size):
>
> /* Declares the common expressions required in the context */
> proxy P {
>   void f_0();
>   double f_1(int, int);
> };
>
> void foo(int n) {
>   /* A: Do something before the loop */
>   for (int i = 0; i < n; ++i) {
>     /* B: Do something */
>     Wrapper<P> x(runtime_condition() ? Wrapper<P>(A{}) : Wrapper<P>(B{}));
>     P p = x.get_proxy();
>     /* C: Do some other things with p */
>   }
>   /* D: Do something after the loop */
> }
> *Code Snippet 4*
>
> Mingxin Wang
>

-- 
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 email 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/2798d4f2-09b1-4030-965d-0bbb36a5549b%40isocpp.org.

------=_Part_2088_776051707.1495375873969
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The following code should be generated when a loop is invo=
lved. the loop has its own scope. The code duplication is limited to the sc=
ope of the loop.<br>But let&#39;s improve it further. Instead of duplicate =
the following code in the enclosing scope, it is sufficient to duplicate th=
e dependend code.<br>Code is dependend=C2=A0 if the result of the ternary o=
peration is involved. So only these parst are duplicated. As an addition, t=
he code is only duplicated,<br>if the condition is known at runtime. If it =
is known at compile time, only one branch is created. Code outside of the l=
oop or the code necessary to<br>implement the loop is NOT duplicated and is=
 not part of the branches. For now, I will call this construct &quot;generi=
c ternary operator&quot;. Like other generics<br>it introduces code duplica=
tion. It&#39;s not a special problem of this construct.<br>It is important,=
 that existing code does not break. For cases where the existing conversion=
 rules apply, there should be no duplication.<br><br>Exmaple including a lo=
op:<div style=3D"background-color: rgb(250, 250, 250); border-color: rgb(18=
7, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: break-=
word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subp=
rettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><=
/span><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</spa=
n><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"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">void</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> doit</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(){</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">}</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-by-prettify"><br></span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> B</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> doit</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(){</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">int</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> main</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> runtime_condition </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>true</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0=
 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">fo=
r</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cl=
ass=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> i </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #066;" class=3D"styled-by-prettify">100</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> i</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">++)</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"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> x </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> runtime_condition </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">?</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> A</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{}</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-by-prettify"> B</span><span st=
yle=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 =C2=A0 =
x</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">doit</span><span s=
tyle=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 =C2=A0=
 </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/* do som=
ething without x */</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 x</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">doit</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">/* do something without x */</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span></div></code></div><br><br><br><div style=
=3D"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187);=
 border-style: solid; border-width: 1px; overflow-wrap: break-word;" class=
=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"subprettyprint">=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> A</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">void</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> doit</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(){</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">};</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"> B</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">void</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> doit</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
(){</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> main</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">{</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-pretti=
fy">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> r=
untime_condition </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">true</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><br>=C2=A0 =C2=A0 </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">for</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> i </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"sty=
led-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
i </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">100</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> i</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">++)</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify">runtime_condition</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">goto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> ternary_branch_1</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 =C2=A0 =C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">else</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">goto</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> ternary_branch_2</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br><br>ternary_branch_1</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 =C2=A0 =C2=A0 A __instance1__</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 =C2=A0 =
__instance1__</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">doit</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">goto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> t=
ernary_end_1</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>ter=
nary_branch_2</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 B __instance2__</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 =C2=A0 =C2=A0 __instance2__</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">doit</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify"><br>ternary_end_1</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 <br>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by=
-prettify">/* do something without x */</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>ternary_branch_3</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 =C2=A0 __instance1__</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">doit</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">goto</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> ternary_end_2</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>ternary_branch_4</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0__instance2__</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
doit</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>ternary_e=
nd_2</span><span style=3D"color: #660;" class=3D"styled-by-prettify">:</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-by-pr=
ettify">/* do something without x */</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
/div></code></div><br><br><br><br><div style=3D"background-color: rgb(250, =
250, 250); border-color: rgb(187, 187, 187); border-style: solid; border-wi=
dth: 1px; overflow-wrap: break-word;" class=3D"prettyprint"><code class=3D"=
prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">doit</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">():</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 push =C2=A0 =C2=A0rbp<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 mov =C2=A0 =C2=A0 rbp</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> rsp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 QWORD PTR </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">rbp</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">8</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">],</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> rdi<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 nop<br>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 pop =C2=A0 =C2=A0 rbp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret<=
br>B</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">doit</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">():</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 push =C2=A0 =C2=A0rbp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=
=A0 rbp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> rsp<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 QWORD PTR </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">rbp</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">-</span><span style=3D"color: #066;" class=3D"st=
yled-by-prettify">8</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">],</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> rdi<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 nop<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 pop=
 =C2=A0 =C2=A0 rbp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret<br>main</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 p=
ush =C2=A0 =C2=A0rbp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 rbp</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> rsp<br>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">sub</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
=C2=A0 =C2=A0 rsp</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: #066;" class=3D"styled-by-prettify">16</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 mov =C2=A0 =C2=A0 BYTE PTR </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">rbp</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">-</span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">5</span><span style=3D"color: #660;" class=3D"styled-by-prettify">]=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 mov =C2=A0 =C2=A0 DWORD PTR </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">rbp</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">-</span><span style=3D"color: #066;" class=3D"styled-by-prettify">=
4</span><span style=3D"color: #660;" class=3D"styled-by-prettify">],</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #066;" class=3D"styled-by-prettify">0</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">L11</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 cmp =C2=A0 =C2=A0 DWORD PTR </span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">rbp</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #0=
66;" class=3D"styled-by-prettify">4</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">],</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pr=
ettify">99</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 jg =C2=A0 =C2=A0 =C2=A0</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">L4<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 cmp=
 =C2=A0 =C2=A0 BYTE PTR </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">[</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">rbp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-<=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">5</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">],</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">0</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 je =C2=A0 =C2=
=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
..</span><span style=3D"color: #000;" class=3D"styled-by-prettify">L13<br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 nop<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 lea =C2=A0 =
=C2=A0 rax</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">rbp</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">6</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 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 rdi</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> rax<br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 call =C2=A0 =C2=A0A</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">doit</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><b=
r>=C2=A0 =C2=A0 =C2=A0 =C2=A0 jmp =C2=A0 =C2=A0 </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">L9<br></span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">L13</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">:</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 nop<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 lea =C2=
=A0 =C2=A0 rax</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">rbp</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">7</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 =C2=A0 mov =C2=A0 =C2=A0 rdi</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> rax<br>=C2=A0 =C2=A0=
 =C2=A0 =C2=A0 call =C2=A0 =C2=A0B</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">doit</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">L9</span><spa=
n 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 =C2=
=A0 lea =C2=A0 =C2=A0 rax</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">[</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">rbp</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">-</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">6</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 =C2=A0 mov =C2=A0 =C2=
=A0 rdi</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> rax<br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 call =C2=A0 =C2=A0A</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify">doit</span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 nop<br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 add =C2=A0 =C2=A0 DWORD PTR </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">[</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">rbp</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">-</span><span style=3D"color: #066;" class=3D"styled-by-prettify">4=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">],</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 jmp =
=C2=A0 =C2=A0 </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">L11<b=
r></span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">L4</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mo=
v =C2=A0 =C2=A0 eax</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #066;" class=3D"styled-by-prettify">0</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 leave<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 ret</span></div></code><=
/div><br><br><br><br><br><br><br><br>Am Sonntag, 21. Mai 2017 15:00:03 UTC+=
2 schrieb Mingxin Wang:<blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div di=
r=3D"ltr"><div><font face=3D"georgia, serif">You may as well consider the f=
ollowing situations:<br></font></div><div><font face=3D"georgia, serif"><br=
></font></div><div><div style=3D"font-family:georgia,serif"><b><font size=
=3D"4">Loops</font></b></div><div style=3D"font-family:georgia,serif"><br><=
/div><div style=3D"font-family:georgia,serif">It is difficult for compilers=
 to generate code for loops with the feature you proposed, e.g.:</div><div =
style=3D"font-family:georgia,serif"><br></div><div style=3D"font-family:geo=
rgia,serif"><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break=
-word;background-color:rgb(250,250,250)"><code><div><div>void foo(int n) {<=
/div><div>=C2=A0 /* A: Do something before the loop */</div><div>=C2=A0 for=
 (int i =3D 0; i &lt; n; ++i) {</div><div>=C2=A0 =C2=A0 /* B: Do something =
*/</div><div>=C2=A0 =C2=A0 auto x =3D runtime_condition() ? A{} : B{};</div=
><div>=C2=A0 =C2=A0 /* C: Do some other things with x */</div><div>=C2=A0 }=
</div><div>=C2=A0 /* D: Do something after the loop */</div><div>}</div></d=
iv></code></div><div style=3D"text-align:center"><b>Code Snippet 1</b></div=
></div><div style=3D"font-family:georgia,serif"><br></div><div style=3D"fon=
t-family:georgia,serif">As far as I am concerned, here is the equivalent of=
 the code that the compiler would automatically generate for the code above=
 (with your method):<br></div><div style=3D"font-family:georgia,serif"><br>=
</div><div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-=
word;background-color:rgb(250,250,250)"><code><div><font color=3D"#660066">=
<div>template &lt;class T&gt;</div><div>void bar(int i, int n, T x) {</div>=
<div>=C2=A0 /* C: Do some other things with x */</div><div>=C2=A0 ++i;</div=
><div>=C2=A0 if (i &lt; n) {</div><div>=C2=A0 =C2=A0 /* B: Do something */<=
/div><div>=C2=A0 =C2=A0 if (runtime_condition()) {</div><div>=C2=A0 =C2=A0 =
=C2=A0 bar(i, n, A{});</div><div>=C2=A0 =C2=A0 } else {</div><div>=C2=A0 =
=C2=A0 =C2=A0 bar(i, n, B{});</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 }<=
/div><div>}</div><div><br></div><div>void foo(int n) {</div><div>=C2=A0 /* =
A: Do something before the loop */</div><div>=C2=A0 if (0 &lt; n) {</div><d=
iv>=C2=A0 =C2=A0 /* B: Do something */</div><div>=C2=A0 =C2=A0 if (runtime_=
condition()) {</div><div>=C2=A0 =C2=A0 =C2=A0 bar(1, n, A{});</div><div>=C2=
=A0 =C2=A0 } else {</div><div>=C2=A0 =C2=A0 =C2=A0 bar(1, n, B{});</div><di=
v>=C2=A0 =C2=A0 }</div><div>=C2=A0 }</div><div>=C2=A0 /* D: Do something af=
ter the loop */</div><div>}</div></font></div></code></div><div style=3D"te=
xt-align:center"><font face=3D"georgia, serif"><b>Code Snippet 2</b></font>=
</div><div><font face=3D"georgia, serif"><br></font></div><div><font face=
=3D"georgia, serif">It is too complicated! Moreover, as the recursive call =
of the &quot;function template bar&quot; is not able to be optimized, it wi=
ll possibly increase the runtime overhead.</font></div><div><font face=3D"g=
eorgia, serif"><br></font></div><div><font size=3D"4" face=3D"georgia, seri=
f"><b>Size</b></font></div><div><font face=3D"georgia, serif"><br></font></=
div><div><font face=3D"georgia, serif">Compilers may generate a lot of redu=
ndant code when the feature is used extensively, e.g.:</font></div></div><d=
iv><font face=3D"georgia, serif"><br></font></div><div><font face=3D"georgi=
a, serif"><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-w=
ord;background-color:rgb(250,250,250)"><code><div><div>auto x0 =3D runtime_=
condition_0() ? A0{} : B0{};</div><div>auto x1 =3D runtime_condition_1() ? =
A1{} : B1{};</div><div>// ...</div><div>auto xn =3D runtime_condition_n() ?=
 An{} : Bn{};</div></div></code></div><div style=3D"text-align:center"><b>C=
ode Snippet 3</b></div><div><br></div><div>As you introduced, the compiler =
is supposed to generate code for every path! For the code above, it require=
s O(2^n) size for code generation, which is NOT acceptable in most cases.</=
div><div><br></div><div>In fact, the challenges above can be solved gracefu=
lly with the &quot;proxies&quot; and the &quot;wrappers&quot;.</div><div><b=
r></div><div>As the condition is determined at runtime, the concrete type c=
annot be deduced at compile time. The only reason for us to save the return=
ed value is that <b>they have similar expressions and semantics</b>. We can=
 simply extract the common expressions of the types which are used in the c=
ontext to a &quot;proxy&quot;, and save the returned value with a &quot;wra=
pper&quot;, e.g. Code Snippet 1 can be reconstructed as is shown below (wit=
h better performance and smaller size):</div></font></div><div><font face=
=3D"georgia, serif"><br></font></div></div><div><div style=3D"border:1px so=
lid rgb(187,187,187);word-wrap:break-word;background-color:rgb(250,250,250)=
"><code><div><font color=3D"#660066"><div>/* Declares the common expression=
s required in the context */</div><div>proxy P {</div><div>=C2=A0 void f_0(=
);</div><div>=C2=A0 double f_1(int, int);</div><div>};</div><div><br></div>=
<div>void foo(int n) {</div><div>=C2=A0 /* A: Do something before the loop =
*/</div><div>=C2=A0 for (int i =3D 0; i &lt; n; ++i) {</div><div>=C2=A0 =C2=
=A0 /* B: Do something */</div><div>=C2=A0 =C2=A0 Wrapper&lt;P&gt; x(runtim=
e_condition() ? Wrapper&lt;P&gt;(A{}) : Wrapper&lt;P&gt;(B{}));</div><div>=
=C2=A0 =C2=A0 P p =3D x.get_proxy();</div><div>=C2=A0 =C2=A0 /* C: Do some =
other things with p */</div><div>=C2=A0 }</div><div>=C2=A0 /* D: Do somethi=
ng after the loop */</div><div>}</div></font></div></code></div><div style=
=3D"text-align:center"><font face=3D"georgia, serif"><b>Code Snippet 4</b><=
/font></div></div><div style=3D"text-align:left"><font face=3D"georgia, ser=
if"><br></font></div><div style=3D"text-align:left"><font face=3D"georgia, =
serif">Mingxin Wang</font></div></div></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/2798d4f2-09b1-4030-965d-0bbb36a5549b%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/2798d4f2-09b1-4030-965d-0bbb36a5549b=
%40isocpp.org</a>.<br />

------=_Part_2088_776051707.1495375873969--

------=_Part_2087_1742423123.1495375873967--

.
