220 32542 <5d084b24-5fd4-4a81-968f-aa8561b19e09@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 02:15:21 -0700 (PDT)
Lines: 499
Approved: news@gmane.org
Message-ID: <5d084b24-5fd4-4a81-968f-aa8561b19e09@isocpp.org>
References: <1b5ee8eb-53df-4e98-af2f-829c7bc2e5b2@isocpp.org>
 <9064929.QEV8q21eIZ@tjmaciei-mobl1>
 <99350a9e-0c6b-468d-9761-f2b2b052275e@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_1113621356.1495358121806"
X-Trace: blaine.gmane.org 1495358124 16622 195.159.176.226 (21 May 2017 09:15:24 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sun, 21 May 2017 09:15:24 +0000 (UTC)
Cc: ma.kalbfuss@web.de
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC7YTI72XQOBBKVVQXEQKGQERHCYKUA@isocpp.org Sun May 21 11:15:19 2017
Return-path: <std-proposals+bncBC7YTI72XQOBBKVVQXEQKGQERHCYKUA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f70.google.com ([209.85.214.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBC7YTI72XQOBBKVVQXEQKGQERHCYKUA@isocpp.org>)
	id 1dCMxJ-0004Ar-Rk
	for gclcip-std-proposals@m.gmane.org; Sun, 21 May 2017 11:15:18 +0200
Original-Received: by mail-it0-f70.google.com with SMTP id s131sf74067498itd.6
        for <gclcip-std-proposals@m.gmane.org>; Sun, 21 May 2017 02:15:23 -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=k4f8w6hau4zksiqgTa9OTrfslgGCu3B2WU10AIXh+iM=;
        b=QPoMtczqU4ZdvpnKq5awgq6lztG6CBDOSWotfhh1dI7CD2LNAi6NQECrnb1Ko/6oHM
         oVBpOwr7YsEFCiIUQ/BLTGv+7uR9bXZdb5GCwMxlmH0h6wOMhgZj/X9t2UxWWuLIjbeq
         9TnGXFgWMMCN6I6iC/dbT6AaDjaDq0ZY/oicHKtom3GzhdixZ0Eg49/gfCYtBVvlqSpa
         ctkw5WZjMfPG0Jz4t997QsZnR0XO6nI5FGn7qVY7E2SSwvn8WwRW9EtkvnjQ+BxZ0bgz
         YrCLm51cUcrVRoplnjshlSW4YqytGixopgMwHk6dpwRcw5yyVie9O6tKmNGOWqLVWSXI
         Y+MQ==
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=k4f8w6hau4zksiqgTa9OTrfslgGCu3B2WU10AIXh+iM=;
        b=BIJA3e7sKIKs6YjuP1oEgkbYqGS0wBzZMv9U/lS040/Ay+5e3QR27R44k4vsEFnqNk
         CGO8+7gzhkNe3eQm9nmotOayZUmbRC/1l0j461gBmg8SbumMuwe6D8flc5ShiY3YhQdA
         XQd755947uO0xE9GcyC7Uhw72KxIBm5sw0l+1AH5HN1Lrafb6nT0qCazQo3XFU+IkCp+
         h4k/oStWr4N/9N3hTVOamQqKoSuz9xRTamId1E4ikKp4kHx+PCU4GvVJgB2JLxWkPHSJ
         QalJYoyVeO3wDVtfk3fbFjYJSpwe8KrMwbWSMUYvrldke/IpyXo3DBgMLNgj3j2UEcjk
         +SFw==
X-Gm-Message-State: AODbwcDmLJgrcRBFRt1YxroH5ezgebY3lMxh7hOs99OC3yJ9yi5/c8pe
	60aOsXheh1xh0c/3
X-Received: by 10.36.105.21 with SMTP id e21mr6883549itc.19.1495358123196;
        Sun, 21 May 2017 02:15:23 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.157.11.145 with SMTP id 17ls1988681oth.36.gmail; Sun, 21 May
 2017 02:15:22 -0700 (PDT)
X-Received: by 10.157.45.79 with SMTP id v73mr371504ota.20.1495358122341;
        Sun, 21 May 2017 02:15:22 -0700 (PDT)
In-Reply-To: <99350a9e-0c6b-468d-9761-f2b2b052275e@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:32542
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/32542>

------=_Part_2087_1113621356.1495358121806
Content-Type: multipart/alternative; 
	boundary="----=_Part_2088_1911461960.1495358121807"

------=_Part_2088_1911461960.1495358121807
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

The coresponding assembly code without iostream to avoid unecessary=20
complexity:

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-1], 1
        cmp     BYTE PTR [rbp-1], 0
        je      .L9
        nop
        lea     rax, [rbp-2]
        mov     rdi, rax
        call    A::doit()
        mov     eax, 0
        jmp     .L8
..L9:
        nop
        lea     rax, [rbp-3]
        mov     rdi, rax
        call    B::doit()
        mov     eax, 0
..L8:
        leave
        ret





Am Sonntag, 21. Mai 2017 11:03:45 UTC+2 schrieb ma.ka...@web.de:
>
> I revisited your statement, that this isn't possible, because the type=20
> would be determined at runtime. I have to disagree, now.  It is possible =
at=20
> compile time.
>
> Look at the following code:
>
> auto x =3D runtime_condition ? A{} : B{};
> x.doit();
>
> This is not going to work, as you stated. But you could write the=20
> following instead:
>
> auto f =3D [&](auto x) { x.doit(); };
> runtime_condition ? f(A{}) : f(B{});
>
> The code, following the ternary statement is moved into a generic lambda.
> auto x =3D runtime_condition ? A{} : B{};
>
> The generic lambda is instantiated two times, for each branch. Depending=
=20
> on runtime_condition,
> only one instance is executed. The statement
>
> auto x =3D runtime_condition ? A{} : X{};
>
> could introduce the following code inside the current scope twice, like=
=20
> the generic lambda did. Ones for each type.
> Depending on the runtime_condition, the code pointer is moved to the firs=
t=20
> or the second instantiaton with a jump.
>
> The following C++ code snippet describes roughly how the generated code=
=20
> could look like.
>
> #include <iostream>
>
> struct A{ void doit(){ std::cout << "A::doit" << std::endl; } };
> struct B{ void doit(){ std::cout << "B::doit" << std::endl; } };
>
> int main()
> {
>     auto runtime_condition =3D true;
>
>     if(runtime_condition)
>         goto ternary_branch_1;
>     else
>         goto ternary_branch_2;
>
> ternary_branch_1:
>     A __instance1__;
>     __instance1__.doit();
>     return 0;
> ternary_branch_2:
>     B __instance2__;
>     __instance2__.doit();
>     return 0;
> }
>
>
>
>
>
>
>
> Am Samstag, 20. Mai 2017 21:29:56 UTC+2 schrieb Thiago Macieira:
>>
>> On s=C3=A1bado, 20 de maio de 2017 10:41:56 PDT ma.ka...@web.de wrote:=
=20
>> > Hi Guys,=20
>> >=20
>> > I had the following situation:=20
>> >=20
>> > I have a Group of StaticSet classes with a compatible interface but=20
>> > distinct in there concrete type. empty_set is not an intervall!=20
>> > I tried the following:=20
>> >=20
>> >=20
>> > auto dec_digit =3D make_interval('0', '0' + std::min(base, DECIMAL_BAS=
E)=20
>> - 1);=20
>> > auto upper_digit =3D (base > DECIMAL_DIGIT) ? make_interval('A', 'A' +=
=20
>> (base=20
>> > - 1 - DECIMAL_BASE)) : empty_set;=20
>> > auto lower_digit =3D (base > DECIMAL_DIGIT) ? make_interval('a', 'a' +=
=20
>> (base=20
>> > - 1 - DECIMAL_BASE)) : empty_set;=20
>> >=20
>> >=20
>> > Wouldn't it be possible to allow such code, especially in conjunction=
=20
>> with=20
>> > concepts?=20
>>
>> No. lower_digit must have exactly one type, determined at compile-time.=
=20
>> What=20
>> you're asking for would cause the type to be determined at runtime, whic=
h=20
>> is=20
>> not possible in C++.=20
>>
>> Alternatives:=20
>> * convert empty_set to make_interval's type=20
>> * convert either to a common type (which you need to be explicit about,=
=20
>> so it=20
>>    won't work with auto)=20
>> * use std::variant<interval, decltype(empty_set)>=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/5d084b24-5fd4-4a81-968f-aa8561b19e09%40isocpp.or=
g.

------=_Part_2088_1911461960.1495358121807
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The coresponding assembly code without iostream to avoid u=
necessary complexity:<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"prett=
yprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D=
"styled-by-prettify">A</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">doit</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 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"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> rsp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 QWORD PTR </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">[</span><span s=
tyle=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;" cla=
ss=3D"styled-by-prettify">],</span><span style=3D"color: #000;" class=3D"st=
yled-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">::</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=
 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><s=
pan 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: #000;" cl=
ass=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<b=
r>=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 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 push =C2=
=A0 =C2=A0rbp<br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 rbp</span><s=
pan 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 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">su=
b</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-prettify">=
,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #066;" class=3D"styled-by-prettify">16</span><span sty=
le=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"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">1=
</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 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-pretti=
fy">rbp</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</=
span><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><spa=
n 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">L9<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><spa=
n 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"col=
or: #660;" class=3D"styled-by-prettify">-</span><span style=3D"color: #066;=
" class=3D"styled-by-prettify">2</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 mov =C2=A0 =C2=A0 eax</span><span style=3D"co=
lor: #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"style=
d-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 jmp =C2=A0 =C2=A0 </span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">L8<br></span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">L9</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 =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"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">[</span><span style=3D"color: #000;" class=3D"styled-by-prettify">rbp=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">-</span><s=
pan style=3D"color: #066;" class=3D"styled-by-prettify">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 mov =
=C2=A0 =C2=A0 rdi</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> r=
ax<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"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>=C2=A0 =C2=A0 =C2=A0 =C2=A0 mov =C2=A0 =C2=A0 eax<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><sp=
an 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></span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">L8</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">:</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><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>Am Sonntag, 21. Mai 2017 =
11:03:45 UTC+2 schrieb ma.ka...@web.de:<blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div dir=3D"ltr">I revisited your statement, that this isn&#39;t p=
ossible, because the type would be determined at runtime. I have to disagre=
e, now.=C2=A0 It is possible at compile time.<br><br>Look at the following =
code:<br><br><div style=3D"background-color:rgb(250,250,250);border-color:r=
gb(187,187,187);border-style:solid;border-width:1px"><code><div><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> x </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> runtime_condition </s=
pan><span style=3D"color:#660">?</span><span style=3D"color:#000"> A</span>=
<span style=3D"color:#660">{}</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">:</span><span style=3D"color:#000"> B</span><span st=
yle=3D"color:#660">{};</span><span style=3D"color:#000"><br>x</span><span s=
tyle=3D"color:#660">.</span><span style=3D"color:#000">doit</span><span sty=
le=3D"color:#660">();</span><span style=3D"color:#000"><br></span></div></c=
ode></div><br>This is not going to work, as you stated. But you could write=
 the following instead:<br><br><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><cod=
e><div><span style=3D"color:#008">auto</span><span style=3D"color:#000"> f =
</span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">[&amp;](</span><span style=3D"color:#008">au=
to</span><span style=3D"color:#000"> x</span><span style=3D"color:#660">)</=
span><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span>=
<span style=3D"color:#000"> x</span><span style=3D"color:#660">.</span><spa=
n style=3D"color:#000">doit</span><span style=3D"color:#660">();</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">};</span><span st=
yle=3D"color:#000"><br>runtime_condition </span><span style=3D"color:#660">=
?</span><span style=3D"color:#000"> f</span><span style=3D"color:#660">(</s=
pan><span style=3D"color:#000">A</span><span style=3D"color:#660">{})</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><spa=
n style=3D"color:#000"> f</span><span style=3D"color:#660">(</span><span st=
yle=3D"color:#000">B</span><span style=3D"color:#660">{});</span><span styl=
e=3D"color:#000"><br></span></div></code></div><br>The code, following the =
ternary statement is moved into a generic lambda.<br><code><div style=3D"ba=
ckground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:=
solid;border-width:1px"><code><div><span style=3D"color:#008">auto</span><s=
pan style=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><sp=
an style=3D"color:#000"> runtime_condition </span><span style=3D"color:#660=
">?</span><span style=3D"color:#000"> A</span><span style=3D"color:#660">{}=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">:</spa=
n><span style=3D"color:#000"> B</span><span style=3D"color:#660">{};</span>=
<span style=3D"color:#000"><br></span></div></code></div><span style=3D"col=
or:#000"><br>The generic lambda is instantiated two times, for each branch.=
 Depending on runtime_condition,<br>only one instance is executed. The stat=
ement<br></span></code><span style=3D"color:#000"></span><br><span style=3D=
"color:#000"></span><code><span style=3D"color:#000"><div style=3D"backgrou=
nd-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;=
border-width:1px"><code><div><span style=3D"color:#008">auto</span><span st=
yle=3D"color:#000"> x </span><span style=3D"color:#660">=3D</span><span sty=
le=3D"color:#000"> runtime_condition </span><span style=3D"color:#660">?</s=
pan><span style=3D"color:#000"> A</span><span style=3D"color:#660">{}</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><spa=
n style=3D"color:#000"> X</span><span style=3D"color:#660">{};</span><span =
style=3D"color:#000"><br></span></div></code></div><br>could introduce the =
following code inside the current scope twice, like the generic lambda did.=
 Ones for each type.<br>Depending on the runtime_condition, the code pointe=
r is moved to the first or the second instantiaton with a jump.<br><br></sp=
an></code>The following C++ code snippet describes roughly how the generate=
d code could look like.<br><br><div style=3D"background-color:rgb(250,250,2=
50);border-color:rgb(187,187,187);border-style:solid;border-width:1px"><cod=
e><div><span style=3D"color:#800">#include</span><span style=3D"color:#000"=
> </span><span style=3D"color:#080">&lt;iostream&gt;</span><span style=3D"c=
olor:#000"><br><br></span><span style=3D"color:#008">struct</span><span sty=
le=3D"color:#000"> A</span><span style=3D"color:#660">{</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">void</span><span style=
=3D"color:#000"> doit</span><span style=3D"color:#660">(){</span><span styl=
e=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span style=
=3D"color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#080">&quot;A::doit&quot=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;&=
lt;</span><span style=3D"color:#000"> std</span><span style=3D"color:#660">=
::</span><span style=3D"color:#000">endl</span><span style=3D"color:#660">;=
</span><span style=3D"color:#000"> </span><span style=3D"color:#660">}</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span><s=
pan style=3D"color:#000"><br></span><span style=3D"color:#008">struct</span=
><span style=3D"color:#000"> B</span><span style=3D"color:#660">{</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">void</span><span=
 style=3D"color:#000"> doit</span><span style=3D"color:#660">(){</span><spa=
n style=3D"color:#000"> std</span><span style=3D"color:#660">::</span><span=
 style=3D"color:#000">cout </span><span style=3D"color:#660">&lt;&lt;</span=
><span style=3D"color:#000"> </span><span style=3D"color:#080">&quot;B::doi=
t&quot;</span><span style=3D"color:#000"> </span><span style=3D"color:#660"=
>&lt;&lt;</span><span style=3D"color:#000"> std</span><span style=3D"color:=
#660">::</span><span style=3D"color:#000">endl</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"> </span><span style=3D"color:#660">};</s=
pan><span style=3D"color:#000"><br><br></span><span style=3D"color:#008">in=
t</span><span style=3D"color:#000"> main</span><span style=3D"color:#660">(=
)</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">{<=
/span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"co=
lor:#008">auto</span><span style=3D"color:#000"> runtime_condition </span><=
span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">true</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008=
">if</span><span style=3D"color:#660">(</span><span style=3D"color:#000">ru=
ntime_condition</span><span style=3D"color:#660">)</span><span style=3D"col=
or:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">=
goto</span><span style=3D"color:#000"> ternary_branch_1</span><span style=
=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color:#008">else</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">goto</span><span=
 style=3D"color:#000"> ternary_branch_2</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br><br>ternary_branch_1</span><span style=
=3D"color:#660">:</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 A __in=
stance1__</span><span style=3D"color:#660">;</span><span style=3D"color:#00=
0"><br>=C2=A0 =C2=A0 __instance1__</span><span style=3D"color:#660">.</span=
><span style=3D"color:#000">doit</span><span style=3D"color:#660">();</span=
><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#=
008">return</span><span style=3D"color:#000"> </span><span style=3D"color:#=
066">0</span><span style=3D"color:#660">;</span><span style=3D"color:#000">=
<br>ternary_branch_2</span><span style=3D"color:#660">:</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 B __instance2__</span><span style=3D"colo=
r:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 __instance2__<=
/span><span style=3D"color:#660">.</span><span style=3D"color:#000">doit</s=
pan><span style=3D"color:#660">();</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#066">0</span><span style=3D"color:#=
660">;</span><span style=3D"color:#000"><br></span><span style=3D"color:#66=
0">}</span></div></code></div><br><br><br><br><br><br><br>Am Samstag, 20. M=
ai 2017 21:29:56 UTC+2 schrieb Thiago Macieira:<blockquote class=3D"gmail_q=
uote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;paddin=
g-left:1ex">On s=C3=A1bado, 20 de maio de 2017 10:41:56 PDT <a rel=3D"nofol=
low">ma.ka...@web.de</a> wrote:
<br>&gt; Hi Guys,
<br>&gt;=20
<br>&gt; I had the following situation:
<br>&gt;=20
<br>&gt; I have a Group of StaticSet classes with a compatible interface bu=
t
<br>&gt; distinct in there concrete type. empty_set is not an intervall!
<br>&gt; I tried the following:
<br>&gt;=20
<br>&gt;=20
<br>&gt; auto dec_digit =3D make_interval(&#39;0&#39;, &#39;0&#39; + std::m=
in(base, DECIMAL_BASE) - 1);
<br>&gt; auto upper_digit =3D (base &gt; DECIMAL_DIGIT) ? make_interval(&#3=
9;A&#39;, &#39;A&#39; + (base
<br>&gt; - 1 - DECIMAL_BASE)) : empty_set;
<br>&gt; auto lower_digit =3D (base &gt; DECIMAL_DIGIT) ? make_interval(&#3=
9;a&#39;, &#39;a&#39; + (base
<br>&gt; - 1 - DECIMAL_BASE)) : empty_set;
<br>&gt;=20
<br>&gt;=20
<br>&gt; Wouldn&#39;t it be possible to allow such code, especially in conj=
unction with
<br>&gt; concepts?
<br>
<br>No. lower_digit must have exactly one type, determined at compile-time.=
 What=20
<br>you&#39;re asking for would cause the type to be determined at runtime,=
 which is=20
<br>not possible in C++.
<br>
<br>Alternatives:
<br>* convert empty_set to make_interval&#39;s type
<br>* convert either to a common type (which you need to be explicit about,=
 so it=20
<br>=C2=A0 =C2=A0won&#39;t work with auto)
<br>* use std::variant&lt;interval, decltype(empty_set)&gt;
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" rel=3D"n=
ofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.googl=
e.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return true;" onclick=3D"this.href=
=3D&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fmacieira.info\x26sa\x3d=
D\x26sntz\x3d1\x26usg\x3dAFQjCNEswDUBNCNanbu7euhqLn_62FW8ag&#39;;return tru=
e;">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" rel=3D"nofol=
low" target=3D"_blank" onmousedown=3D"this.href=3D&#39;http://www.google.co=
m/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHGR=
Jdo5_JYG1DowztwAHAKs80XSA&#39;;return true;" onclick=3D"this.href=3D&#39;ht=
tp://www.google.com/url?q\x3dhttp%3A%2F%2Fkde.org\x26sa\x3dD\x26sntz\x3d1\x=
26usg\x3dAFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA&#39;;return true;">kde.org</a>
<br>=C2=A0 =C2=A0Software Architect - Intel Open Source Technology Center
<br>
<br></blockquote></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/5d084b24-5fd4-4a81-968f-aa8561b19e09%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5d084b24-5fd4-4a81-968f-aa8561b19e09=
%40isocpp.org</a>.<br />

------=_Part_2088_1911461960.1495358121807--

------=_Part_2087_1113621356.1495358121806--

.
