Topic: if constexpr in class declaration
Author: Cleiton Santoia <cleitonsantoia@gmail.com>
Date: Tue, 9 Aug 2016 10:30:47 -0700 (PDT)
Raw View
------=_Part_365_1335599945.1470763847662
Content-Type: multipart/alternative;
boundary="----=_Part_366_873861596.1470763847663"
------=_Part_366_873861596.1470763847663
Content-Type: text/plain; charset=UTF-8
"If constexpr" is defined only as statement, someone thought about allow it
into class definitions like this :
template <class T>
struct X {
if constexpr (std::is_arithmetic_v<T>) {
double value;
} else constexpr {
std::string value;
}
};
X<int>::value // value is double
X<Myclass>::value // value is string
I know that this particular example will be better with concepts, but the
question remains...
--
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/b802b9e3-9f14-4b93-afb5-47b5dc5034a1%40isocpp.org.
------=_Part_366_873861596.1470763847663
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>"If constexpr" is defined only as statement=
, someone thought about allow it into class definitions like this :</div><d=
iv><br></div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb=
(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250=
);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</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: #008=
;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> T</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: #008;" class=3D"styled-by-pre=
ttify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> X </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =
=C2=A0</span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">(</span><font color=3D"#000088"=
><span style=3D"color: #000;" class=3D"styled-by-prettify">std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">is_arithmetic_v</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #6=
60;" 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"styled-by=
-prettify"><br>=C2=A0 =C2=A0 =C2=A0</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">double</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> value</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span></font><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">=C2=A0 =C2=A0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">else</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</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>=C2=A0 =C2=A0 =C2=A0std</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">string</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> value</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>=C2=A0 =C2=A0</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></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>X</span><span style=3D"color: #080;" class=3D"styled-by-=
prettify"><int></span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">value =C2=A0 =C2=A0 </span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">// value is double</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br>X</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Myclass</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">>::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">value </span><span style=3D"color: #800;" class=3D"styled-by-prettify">/=
/ value is string</span></div></code></div><br>I know that this particular =
example will be better with concepts, but the question remains...=C2=A0</di=
v><div><br></div><div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/b802b9e3-9f14-4b93-afb5-47b5dc5034a1%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b802b9e3-9f14-4b93-afb5-47b5dc5034a1=
%40isocpp.org</a>.<br />
------=_Part_366_873861596.1470763847663--
------=_Part_365_1335599945.1470763847662--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 9 Aug 2016 10:56:16 -0700
Raw View
--001a1141287ed40f860539a73f6b
Content-Type: text/plain; charset=UTF-8
On Tue, Aug 9, 2016 at 10:30 AM, Cleiton Santoia <cleitonsantoia@gmail.com>
wrote:
> "If constexpr" is defined only as statement, someone thought about allow
> it into class definitions like this :
>
> template <class T>
> struct X {
> if constexpr (std::is_arithmetic_v<T>) {
> double value;
> } else constexpr {
> std::string value;
> }
> };
>
> X<int>::value // value is double
> X<Myclass>::value // value is string
>
> I know that this particular example will be better with concepts, but the
> question remains...
>
Yes, it's been thought about, but this is doing something fundamentally
different from what 'if constexpr' does, and it has major practical
problems. You can look through the history of papers on constexpr if and
static if for a taste of the problems.
--
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/CAOfiQq%3D6%2B9_qGF-EEHjJ_bpt993s0amWHwoE%3DWABHXCCu%2Bxc5Q%40mail.gmail.com.
--001a1141287ed40f860539a73f6b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Aug 9, 2016 at 10:30 AM, Cleiton Santoia <span dir=3D"ltr"><<a href=
=3D"mailto:cleitonsantoia@gmail.com" target=3D"_blank">cleitonsantoia@gmail=
..com</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"lt=
r"><div>"If constexpr" is defined only as statement, someone thou=
ght about allow it into class definitions like this :</div><div><br></div><=
div><div style=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;ba=
ckground-color:rgb(250,250,250)"><code><div><span style=3D"color:#008">temp=
late</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&l=
t;</span><span style=3D"color:#008">class</span><span style=3D"color:#000">=
T</span><span style=3D"color:#660">></span><span style=3D"color:#000"><=
br></span><span style=3D"color:#008">struct</span><span style=3D"color:#000=
"> X </span><span style=3D"color:#660">{</span><span style=3D"color:#000"><=
br>=C2=A0 =C2=A0</span><span style=3D"color:#008">if</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">(</span><font color=3D"#=
000088"><span style=3D"color:#000">std</span><span style=3D"color:#660">::<=
/span><span style=3D"color:#000">is_arithmetic_v</span><span style=3D"color=
:#660"><</span><span style=3D"color:#000">T</span><span style=3D"color:#=
660">>)</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0</span><span=
style=3D"color:#008">double</span><span style=3D"color:#000"> value</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br></span></=
font><span style=3D"color:#000">=C2=A0 =C2=A0</span><span style=3D"color:#6=
60">}</span><span style=3D"color:#000"> </span><span style=3D"color:#008">e=
lse</span><span style=3D"color:#000"> </span><span style=3D"color:#008">con=
stexpr</span><span style=3D"color:#000"> </span><span style=3D"color:#660">=
{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0std</span><span =
style=3D"color:#660">::</span><span style=3D"color:#008">string</span><span=
style=3D"color:#000"> value</span><span style=3D"color:#660">;</span><span=
style=3D"color:#000"><br>=C2=A0 =C2=A0</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><br>X</span><span style=3D"color:#080">=
<int></span><span style=3D"color:#660">::</span><span style=3D"color:=
#000">value =C2=A0 =C2=A0 </span><span style=3D"color:#800">// value is dou=
ble</span><span style=3D"color:#000"><br>X</span><span style=3D"color:#660"=
><</span><span style=3D"color:#606">Myclass</span><span style=3D"color:#=
660">>::</span><span style=3D"color:#000">value </span><span style=3D"co=
lor:#800">// value is string</span></div></code></div><br>I know that this =
particular example will be better with concepts, but the question remains..=
..=C2=A0</div></div></blockquote><div><br></div><div>Yes, it's been thou=
ght about, but this is doing something fundamentally different from what &#=
39;if constexpr' does, and it has major practical problems. You can loo=
k through the history of papers on constexpr if and static if for a taste o=
f the problems.</div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAOfiQq%3D6%2B9_qGF-EEHjJ_bpt993s0amW=
HwoE%3DWABHXCCu%2Bxc5Q%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoo=
ter">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQq%3=
D6%2B9_qGF-EEHjJ_bpt993s0amWHwoE%3DWABHXCCu%2Bxc5Q%40mail.gmail.com</a>.<br=
/>
--001a1141287ed40f860539a73f6b--
.
Author: rhalbersma@gmail.com
Date: Tue, 9 Aug 2016 15:01:33 -0700 (PDT)
Raw View
------=_Part_761_1141610826.1470780093348
Content-Type: multipart/alternative;
boundary="----=_Part_762_1490687678.1470780093348"
------=_Part_762_1490687678.1470780093348
Content-Type: text/plain; charset=UTF-8
On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:
>
>
> Yes, it's been thought about, but this is doing something fundamentally
> different from what 'if constexpr' does, and it has major practical
> problems. You can look through the history of papers on constexpr if and
> static if for a taste of the problems.
>
I understand that applying if-constexpr to conditional data member layout
is different because a regular if cannot appear at class scope. But reading
the static if papers and their critiques, the supplied alternative to the
OP's example using partial specializations, tuple and empty base class
trickery do not really provide a superior alternative. Optimal class layout
is currently cumbersome, using if-constexpr would make this a lot easier
for users.
What exactly would be making it hard (compared to if-constexpr at function
scope) for the compiler to do the conditional data layout using
if-constexpr?
--
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/6322c6eb-76f7-47cc-b012-db8c5d8892fc%40isocpp.org.
------=_Part_762_1490687678.1470780093348
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Ri=
chard Smith wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;marg=
in-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"=
ltr"><div class=3D"gmail_quote"><div><br></div><div>Yes, it's been thou=
ght about, but this is doing something fundamentally different from what &#=
39;if constexpr' does, and it has major practical problems. You can loo=
k through the history of papers on constexpr if and static if for a taste o=
f the problems.</div></div></div></blockquote><div><br></div><div>I underst=
and that applying if-constexpr to conditional data member layout is differe=
nt because a regular if cannot appear at class scope. But reading the stati=
c if papers and their critiques, the supplied alternative to the OP's e=
xample using partial specializations, tuple and empty base class trickery d=
o not really provide a superior alternative. Optimal class layout is curren=
tly cumbersome, using if-constexpr would make this a lot easier for users.=
=C2=A0</div><div><br></div><div>What exactly would be making it hard (compa=
red to if-constexpr at function scope) for the compiler to do the condition=
al data layout using if-constexpr?</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/6322c6eb-76f7-47cc-b012-db8c5d8892fc%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6322c6eb-76f7-47cc-b012-db8c5d8892fc=
%40isocpp.org</a>.<br />
------=_Part_762_1490687678.1470780093348--
------=_Part_761_1141610826.1470780093348--
.
Author: Richard Smith <richard@metafoo.co.uk>
Date: Tue, 9 Aug 2016 16:12:14 -0700
Raw View
--001a1148d31ed5a2af0539aba923
Content-Type: text/plain; charset=UTF-8
On Tue, Aug 9, 2016 at 3:01 PM, <rhalbersma@gmail.com> wrote:
>
>
> On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:
>>
>>
>> Yes, it's been thought about, but this is doing something fundamentally
>> different from what 'if constexpr' does, and it has major practical
>> problems. You can look through the history of papers on constexpr if and
>> static if for a taste of the problems.
>>
>
> I understand that applying if-constexpr to conditional data member layout
> is different because a regular if cannot appear at class scope. But reading
> the static if papers and their critiques, the supplied alternative to the
> OP's example using partial specializations, tuple and empty base class
> trickery do not really provide a superior alternative. Optimal class layout
> is currently cumbersome, using if-constexpr would make this a lot easier
> for users.
>
> What exactly would be making it hard (compared to if-constexpr at function
> scope) for the compiler to do the conditional data layout using
> if-constexpr?
>
Just a taste:
int value;
template<typename T> struct X {
some_kind_of_static_if (is_fooable_v<T>) {
T value;
}
int f() { return value; }
};
--
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/CAOfiQqm4afYf5Wkk1EBTRQuNsPAo7FpYMx_k6FyuXfEhSwOVrg%40mail.gmail.com.
--001a1148d31ed5a2af0539aba923
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On T=
ue, Aug 9, 2016 at 3:01 PM, <span dir=3D"ltr"><<a href=3D"mailto:rhalbe=
rsma@gmail.com" target=3D"_blank">rhalbersma@gmail.com</a>></span> wrote=
:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span class=3D""><br><=
br>On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:<blo=
ckquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-le=
ft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_qu=
ote"><div><br></div><div>Yes, it's been thought about, but this is doin=
g something fundamentally different from what 'if constexpr' does, =
and it has major practical problems. You can look through the history of pa=
pers on constexpr if and static if for a taste of the problems.</div></div>=
</div></blockquote><div><br></div></span><div>I understand that applying if=
-constexpr to conditional data member layout is different because a regular=
if cannot appear at class scope. But reading the static if papers and thei=
r critiques, the supplied alternative to the OP's example using partial=
specializations, tuple and empty base class trickery do not really provide=
a superior alternative. Optimal class layout is currently cumbersome, usin=
g if-constexpr would make this a lot easier for users.=C2=A0</div><div><br>=
</div><div>What exactly would be making it hard (compared to if-constexpr a=
t function scope) for the compiler to do the conditional data layout using =
if-constexpr?</div></div></blockquote><div><br></div><div>Just a taste:</di=
v><div><br></div><div>int value;</div><div>template<typename T> struc=
t X {</div><div>=C2=A0 some_kind_of_static_if (is_fooable_v<T>) {</di=
v><div>=C2=A0 =C2=A0 T value;</div><div>=C2=A0 }</div><div>=C2=A0 int f() {=
return value; }</div><div>};</div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAOfiQqm4afYf5Wkk1EBTRQuNsPAo7FpYMx_k=
6FyuXfEhSwOVrg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAOfiQqm4afYf5Wkk=
1EBTRQuNsPAo7FpYMx_k6FyuXfEhSwOVrg%40mail.gmail.com</a>.<br />
--001a1148d31ed5a2af0539aba923--
.
Author: Edward Catmur <ed@catmur.co.uk>
Date: Tue, 9 Aug 2016 16:27:38 -0700 (PDT)
Raw View
------=_Part_350_1100570439.1470785258200
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
On Wednesday, 10 August 2016 00:12:16 UTC+1, Richard Smith wrote:
> On Tue, Aug 9, 2016 at 3:01 PM, <rhalb...@gmail.com> wrote:
>=20
>=20
>=20
> On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:
>=20
>=20
>=20
>=20
> Yes, it's been thought about, but this is doing something fundamentally d=
ifferent from what 'if constexpr' does, and it has major practical problems=
.. You can look through the history of papers on constexpr if and static if =
for a taste of the problems.
>=20
>=20
> I understand that applying if-constexpr to conditional data member layout=
is different because a regular if cannot appear at class scope. But readin=
g the static if papers and their critiques, the supplied alternative to the=
OP's example using partial specializations, tuple and empty base class tri=
ckery do not really provide a superior alternative. Optimal class layout is=
currently cumbersome, using if-constexpr would make this a lot easier for =
users.=C2=A0
>=20
>=20
> What exactly would be making it hard (compared to if-constexpr at functio=
n scope) for the compiler to do the conditional data layout using if-conste=
xpr?
>=20
>=20
> Just a taste:
>=20
>=20
> int value;
> template<typename T> struct X {
> =C2=A0 some_kind_of_static_if (is_fooable_v<T>) {
> =C2=A0 =C2=A0 T value;
> =C2=A0 }
> =C2=A0 int f() { return value; }
> };
Well, quite; does the name lookup of value within X::f depend on the type o=
f T? Or did you mean to write this->value, as you'd have to with a dependen=
t base?=20
Note that this particular case (a single data member with dependent type) i=
s perfectly well served by std::conditional. If there was any prospect of g=
etting mixins I'd argue that that would be a mostly satisfactory solution a=
nd wouldn't require any new lookup rules.
--=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/9e7ae9ee-ea29-4cd0-bd67-2c13cddf82a1%40isocpp.or=
g.
------=_Part_350_1100570439.1470785258200--
.
Author: rhalbersma@gmail.com
Date: Wed, 17 Aug 2016 02:44:05 -0700 (PDT)
Raw View
------=_Part_369_2061463580.1471427045606
Content-Type: multipart/alternative;
boundary="----=_Part_370_2018173270.1471427045607"
------=_Part_370_2018173270.1471427045607
Content-Type: text/plain; charset=UTF-8
On Wednesday, August 10, 2016 at 1:12:16 AM UTC+2, Richard Smith wrote:
>
> On Tue, Aug 9, 2016 at 3:01 PM, <rhalb...@gmail.com <javascript:>> wrote:
>
>>
>>
>> On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:
>>>
>>>
>>> Yes, it's been thought about, but this is doing something fundamentally
>>> different from what 'if constexpr' does, and it has major practical
>>> problems. You can look through the history of papers on constexpr if and
>>> static if for a taste of the problems.
>>>
>>
>> I understand that applying if-constexpr to conditional data member layout
>> is different because a regular if cannot appear at class scope. But reading
>> the static if papers and their critiques, the supplied alternative to the
>> OP's example using partial specializations, tuple and empty base class
>> trickery do not really provide a superior alternative. Optimal class layout
>> is currently cumbersome, using if-constexpr would make this a lot easier
>> for users.
>>
>> What exactly would be making it hard (compared to if-constexpr at
>> function scope) for the compiler to do the conditional data layout using
>> if-constexpr?
>>
>
> Just a taste:
>
> int value;
> template<typename T> struct X {
> some_kind_of_static_if (is_fooable_v<T>) {
> T value;
> }
> int f() { return value; }
> };
>
How is that different from
int value;
template<typename T> int f()
{
some_kind_of_static_if(is_fooable_v<T>) {
return value;
} else {
int value = 42;
return value;
}
}
Won't there be a warning about shadowing a global variable in both cases?
--
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/a4dd84d3-45b6-4c0e-a1cc-6c88c46cbe35%40isocpp.org.
------=_Part_370_2018173270.1471427045607
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Wednesday, August 10, 2016 at 1:12:16 AM UTC+2,=
Richard Smith wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;m=
argin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote">On Tue, Aug 9, 2016 at 3:01 PM, <=
span dir=3D"ltr"><<a href=3D"javascript:" target=3D"_blank" gdf-obfuscat=
ed-mailto=3D"NsENg_U9CQAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'=
;javascript:';return true;" onclick=3D"this.href=3D'javascript:'=
;;return true;">rhalb...@gmail.com</a>></span> wrote:<br><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;pa=
dding-left:1ex"><div dir=3D"ltr"><span><br><br>On Tuesday, August 9, 2016 a=
t 7:56:22 PM UTC+2, Richard Smith wrote:<blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:=
1ex"><div dir=3D"ltr"><div class=3D"gmail_quote"><div><br></div><div>Yes, i=
t's been thought about, but this is doing something fundamentally diffe=
rent from what 'if constexpr' does, and it has major practical prob=
lems. You can look through the history of papers on constexpr if and static=
if for a taste of the problems.</div></div></div></blockquote><div><br></d=
iv></span><div>I understand that applying if-constexpr to conditional data =
member layout is different because a regular if cannot appear at class scop=
e. But reading the static if papers and their critiques, the supplied alter=
native to the OP's example using partial specializations, tuple and emp=
ty base class trickery do not really provide a superior alternative. Optima=
l class layout is currently cumbersome, using if-constexpr would make this =
a lot easier for users.=C2=A0</div><div><br></div><div>What exactly would b=
e making it hard (compared to if-constexpr at function scope) for the compi=
ler to do the conditional data layout using if-constexpr?</div></div></bloc=
kquote><div><br></div><div>Just a taste:</div><div><br></div><div>int value=
;</div><div>template<typename T> struct X {</div><div>=C2=A0 some_kin=
d_of_static_if (is_fooable_v<T>) {</div><div>=C2=A0 =C2=A0 T value;</=
div><div>=C2=A0 }</div><div>=C2=A0 int f() { return value; }</div><div>};</=
div></div></div></div></blockquote><div><br></div><div>How is that differen=
t from</div><div><br></div><div>int value;</div><div><br></div><div>templat=
e<typename T> int f()</div><div>{</div><div>=C2=A0 =C2=A0 some_kind_o=
f_static_if(is_fooable_v<T>) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
return value;</div><div>=C2=A0 =C2=A0 } else {</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 int value =3D 42;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return v=
alue;</div><div>=C2=A0 =C2=A0}</div><div>}=C2=A0</div><div><br></div><div>W=
on't there be a warning about shadowing a global variable in both cases=
?</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/a4dd84d3-45b6-4c0e-a1cc-6c88c46cbe35%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a4dd84d3-45b6-4c0e-a1cc-6c88c46cbe35=
%40isocpp.org</a>.<br />
------=_Part_370_2018173270.1471427045607--
------=_Part_369_2061463580.1471427045606--
.
Author: "D. B." <db0451@gmail.com>
Date: Wed, 17 Aug 2016 11:05:46 +0100
Raw View
--001a1146a0dcf61ccc053a419b5c
Content-Type: text/plain; charset=UTF-8
I think the point was that by making the existence of member T conditional,
you'd then have to do the same for the function f() that uses it, and
everything else.
Your situation seems to do something totally different.
--
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/CACGiwhE1YZmjoWNMOKWNzvPgZ0JunQMnUHTTxKwsyQ23C%2BjWuA%40mail.gmail.com.
--001a1146a0dcf61ccc053a419b5c
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I think the point was that by making the existence of=
member T conditional, you'd then have to do the same for the function =
f() that uses it, and everything else.<br><br></div>Your situation seems to=
do something totally different.<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CACGiwhE1YZmjoWNMOKWNzvPgZ0JunQMnUHTT=
xKwsyQ23C%2BjWuA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CACGiwhE1YZmjoW=
NMOKWNzvPgZ0JunQMnUHTTxKwsyQ23C%2BjWuA%40mail.gmail.com</a>.<br />
--001a1146a0dcf61ccc053a419b5c--
.
Author: "'Edward Catmur' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Date: Wed, 17 Aug 2016 14:21:04 +0100
Raw View
--94eb2c0762105ce7c7053a445613
Content-Type: text/plain; charset=UTF-8
On Wed, Aug 17, 2016 at 10:44 AM, <rhalbersma@gmail.com> wrote:
>
>
> On Wednesday, August 10, 2016 at 1:12:16 AM UTC+2, Richard Smith wrote:
>>
>> On Tue, Aug 9, 2016 at 3:01 PM, <rhalb...@gmail.com> wrote:
>>
>>>
>>>
>>> On Tuesday, August 9, 2016 at 7:56:22 PM UTC+2, Richard Smith wrote:
>>>>
>>>>
>>>> Yes, it's been thought about, but this is doing something fundamentally
>>>> different from what 'if constexpr' does, and it has major practical
>>>> problems. You can look through the history of papers on constexpr if and
>>>> static if for a taste of the problems.
>>>>
>>>
>>> I understand that applying if-constexpr to conditional data member
>>> layout is different because a regular if cannot appear at class scope. But
>>> reading the static if papers and their critiques, the supplied alternative
>>> to the OP's example using partial specializations, tuple and empty base
>>> class trickery do not really provide a superior alternative. Optimal class
>>> layout is currently cumbersome, using if-constexpr would make this a lot
>>> easier for users.
>>>
>>> What exactly would be making it hard (compared to if-constexpr at
>>> function scope) for the compiler to do the conditional data layout using
>>> if-constexpr?
>>>
>>
>> Just a taste:
>>
>> int value;
>> template<typename T> struct X {
>> some_kind_of_static_if (is_fooable_v<T>) {
>> T value;
>> }
>> int f() { return value; }
>> };
>>
>
> How is that different from
>
> int value;
>
> template<typename T> int f()
> {
> some_kind_of_static_if(is_fooable_v<T>) {
> return value;
> } else {
> int value = 42;
> return value;
> }
> }
>
> Won't there be a warning about shadowing a global variable in both cases?
>
> In the latter case, you've textually duplicated the return value;
statement, which makes it OK for the two occurrences to have different
meanings (here, name lookup yielding a member vs. a namespace scope
variable). It is not acceptable for a template in two instantiations to
have such different meanings.
If the above doesn't convince you, how about this old chestnut:
using U = int;
template<typename T> struct X {
int i;
some_kind_of_static_if (is_fooable_v<T>) {
static int const U;
}
auto f() { U * i; return i; }
};
--
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/CAJnLdOYznf%2BR3C32E67wr55pdXTn6rSDb8nTZjXfrP4g5ftVvQ%40mail.gmail.com.
--94eb2c0762105ce7c7053a445613
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On W=
ed, Aug 17, 2016 at 10:44 AM, <span dir=3D"ltr"><<a href=3D"mailto:rhal=
bersma@gmail.com" target=3D"_blank">rhalbersma@gmail.com</a>></span> wro=
te:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;=
border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:=
solid;padding-left:1ex"><div dir=3D"ltr"><br><br>On Wednesday, August 10, 2=
016 at 1:12:16 AM UTC+2, Richard Smith wrote:<blockquote class=3D"gmail_quo=
te" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-col=
or:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"l=
tr"><div><div class=3D"gmail_quote">On Tue, Aug 9, 2016 at 3:01 PM, <span =
dir=3D"ltr"><<a rel=3D"nofollow">rhalb...@gmail.com</a>></span> wrote=
:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:so=
lid;padding-left:1ex"><div dir=3D"ltr"><span><br><br>On Tuesday, August 9, =
2016 at 7:56:22 PM UTC+2, Richard Smith wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-co=
lor:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"=
ltr"><div class=3D"gmail_quote"><div><br></div><div>Yes, it's been thou=
ght about, but this is doing something fundamentally different from what &#=
39;if constexpr' does, and it has major practical problems. You can loo=
k through the history of papers on constexpr if and static if for a taste o=
f the problems.</div></div></div></blockquote><div><br></div></span><div>I =
understand that applying if-constexpr to conditional data member layout is =
different because a regular if cannot appear at class scope. But reading th=
e static if papers and their critiques, the supplied alternative to the OP&=
#39;s example using partial specializations, tuple and empty base class tri=
ckery do not really provide a superior alternative. Optimal class layout is=
currently cumbersome, using if-constexpr would make this a lot easier for =
users.=C2=A0</div><div><br></div><div>What exactly would be making it hard =
(compared to if-constexpr at function scope) for the compiler to do the con=
ditional data layout using if-constexpr?</div></div></blockquote><div><br><=
/div><div>Just a taste:</div><div><br></div><div>int value;</div><div>templ=
ate<typename T> struct X {</div><div>=C2=A0 some_kind_of_static_if (i=
s_fooable_v<T>) {</div><div>=C2=A0 =C2=A0 T value;</div><div>=C2=A0 }=
</div><div>=C2=A0 int f() { return value; }</div><div>};</div></div></div><=
/div></blockquote><div><br></div><div>How is that different from</div><div>=
<br></div><div>int value;</div><div><br></div><div>template<typename T&g=
t; int f()</div><div>{</div><div>=C2=A0 =C2=A0 some_kind_of_static_if(is_<w=
br>fooable_v<T>) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return value=
;</div><div>=C2=A0 =C2=A0 } else {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 in=
t value =3D 42;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return value;</div><d=
iv>=C2=A0 =C2=A0}</div><div>}=C2=A0</div><div><br></div><div>Won't ther=
e be a warning about shadowing a global variable in both cases?</div></div>=
<span class=3D""><font color=3D"#888888">
<p></p></font></span></blockquote></div></div><div class=3D"gmail_extra">In=
the latter case, you've textually duplicated the <font face=3D"monospa=
ce, monospace">return value;</font> statement, which makes it OK for the tw=
o occurrences to have different meanings (here, name lookup yielding a memb=
er vs. a namespace scope variable). It is not acceptable for a template in =
two instantiations to have such different meanings.</div><div class=3D"gmai=
l_extra"><br></div><div class=3D"gmail_extra">If the above doesn't conv=
ince you, how about this old chestnut:</div><div class=3D"gmail_extra"><br>=
</div><div class=3D"gmail_extra"><div><font face=3D"monospace, monospace">u=
sing U =3D int;</font></div><div><font face=3D"monospace, monospace">templa=
te<typename T> struct X {</font></div><div><font face=3D"monospace, m=
onospace">=C2=A0 int i;</font></div><div><font face=3D"monospace, monospace=
">=C2=A0 some_kind_of_static_if (is_fooable_v<T>) {</font></div><div>=
<font face=3D"monospace, monospace">=C2=A0 =C2=A0 static int const U;</font=
></div><div><font face=3D"monospace, monospace">=C2=A0 }</font></div><div><=
font face=3D"monospace, monospace">=C2=A0 auto f() { U * i; return i; }</fo=
nt></div><div><font face=3D"monospace, monospace">};</font></div></div></di=
v>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" 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/CAJnLdOYznf%2BR3C32E67wr55pdXTn6rSDb8=
nTZjXfrP4g5ftVvQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAJnLdOYznf%2BR=
3C32E67wr55pdXTn6rSDb8nTZjXfrP4g5ftVvQ%40mail.gmail.com</a>.<br />
--94eb2c0762105ce7c7053a445613--
.