Topic: Proposing addition to proposal


Author: Barry Revzin <barry.revzin@gmail.com>
Date: Thu, 14 Jun 2018 06:01:14 -0700 (PDT)
Raw View
------=_Part_3367_879429609.1528981274122
Content-Type: multipart/alternative;
 boundary="----=_Part_3368_957224584.1528981274123"

------=_Part_3368_957224584.1528981274123
Content-Type: text/plain; charset="UTF-8"



On Wednesday, June 13, 2018 at 8:18:39 PM UTC-5, csha...@gmail.com wrote:
>
> The proposal P0595R1, as it is currently stated, in my opinion, would be a
> wonderful addition to C++. However I believe that there could be another
> potential use case for std::is_constant_evaluated, in which it accepts a
> variable as an argument. The expression would return true if and only if
> the compiler is already aware of the value of the variable itself. The
> motivation behind this is to address proposals for constexpr variable
> function arguments and similar situations, but could sidestep the potential
> pitfalls of function overloading. But it allows the programmer to leverage
> inline optimizations that the compiler is often already doing by making
> him/her aware of when those optimizations are applied.
>
>
This would imply turning a functions into a function template, where each
parameter is a non-type template parameter, without any change in its
declaration, based on what you happen to put in the function body. What
you're looking for P1045 and its constexpr? syntax - which would work by
effectively having N+1 template instantiations (one for each compile-time
value, and one for runtime). But even that wouldn't solve your problem,
since you cannot have non-type template parameters of floating point type -
even with P0732.

Separately, if constexpr(is_constant_evaluated()) is wrong.
is_constant_evaluated() checks if it's in a context that requires constant
evaluation. if constexpr is certainly such a context, so that would be
trivially true. You always just want if (is_constant_evaluated()).

--
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/ccb56dbe-7702-403e-9e06-b8ad164a9162%40isocpp.org.

------=_Part_3368_957224584.1528981274123
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, June 13, 2018 at 8:18:39 PM UTC-5, c=
sha...@gmail.com wrote:<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">The proposal P0595R1, as it is currently stated, in my opinion, w=
ould be a wonderful addition to C++. However I believe that there could be =
another potential use case for std::is_constant_evaluated, in which it acce=
pts a variable as an argument. The expression would return true if and only=
 if the compiler is already aware of the value of the variable itself. The =
motivation behind this is to address proposals for constexpr variable funct=
ion arguments and similar situations, but could sidestep the potential pitf=
alls of function overloading. But it allows the programmer to leverage inli=
ne optimizations that the compiler is often already doing by making him/her=
 aware of when those optimizations are applied.<div><br></div></div></block=
quote><div><br></div><div>This would imply turning a functions into a funct=
ion template, where each parameter is a non-type template parameter, withou=
t any change in its declaration, based on what you happen to put in the fun=
ction body. What you&#39;re looking for P1045 and its constexpr? syntax - w=
hich would work by effectively having N+1 template instantiations (one for =
each compile-time value, and one for runtime). But even that wouldn&#39;t s=
olve your problem, since you cannot have non-type template parameters of fl=
oating point type - even with P0732.=C2=A0</div><div><br></div><div>Separat=
ely, if constexpr(is_constant_evaluated()) is wrong. is_constant_evaluated(=
) checks if it&#39;s in a context that requires constant evaluation. if con=
stexpr is certainly such a context, so that would be trivially true. You al=
ways just want if (is_constant_evaluated()).</div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/ccb56dbe-7702-403e-9e06-b8ad164a9162%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ccb56dbe-7702-403e-9e06-b8ad164a9162=
%40isocpp.org</a>.<br />

------=_Part_3368_957224584.1528981274123--

------=_Part_3367_879429609.1528981274122--

.


Author: bastienpenava@gmail.com
Date: Thu, 14 Jun 2018 11:58:22 -0700 (PDT)
Raw View
------=_Part_4402_613498978.1529002702901
Content-Type: multipart/alternative;
 boundary="----=_Part_4403_1322917060.1529002702902"

------=_Part_4403_1322917060.1529002702902
Content-Type: text/plain; charset="UTF-8"

On Thursday, June 14, 2018 at 3:18:39 AM UTC+2, csha...@gmail.com wrote:
>
> The proposal P0595R1, as it is currently stated, in my opinion, would be a
> wonderful addition to C++. However I believe that there could be another
> potential use case for std::is_constant_evaluated, in which it accepts a
> variable as an argument. The expression would return true if and only if
> the compiler is already aware of the value of the variable itself. The
> motivation behind this is to address proposals for constexpr variable
> function arguments and similar situations, but could sidestep the potential
> pitfalls of function overloading. But it allows the programmer to leverage
> inline optimizations that the compiler is often already doing by making
> him/her aware of when those optimizations are applied.
>
> Declared something like this:
> namespace std
> {
>     // Already in P0595R1. This returns true if the compiler is
> evaluating the function itself in constexpr context.
>     constexpr bool is_constant_evaluated() noexcept;
>
>
>     // Returns true if the literal value of variable t is known to the
> compiler.
>     template <typename T>
>     constexpr bool is_constant_evaluated(T t) noexcept;
> }
>
>
> Example usage:
> inline constexpr float MyPow(float x, float y)
> {
>     if constexpr (std::is_constant_evaluated())
>     {
>         return 0; // TODO: Make a compile-time friendly pow function
>     }
>     else if constexpr (std::is_constant_evaluated(y))
>     {
>         if constexpr (y == 0.f)
>             return 1.f;
>         if constexpr (y == 1.f)
>             return x;
>         if constexpr (y == 2.f)
>             return x * x;
>         if constexpr (y == 3.f)
>             return x * x * x;
>         else
>             return powf(x, y);
>     }
>     else
>         return powf(x, y);
> }
>
>
> float g_x, g_y; // globally mutable, always evaluated at runtime
> int main()
> {
>     constexpr float a = MyPow(3.14f, 2.5f); // MyPow takes the first if
> block and returns a value computed at compile-time
>     float b = MyPow(g_x, 2.0f);             // Compiler inlines: float b
> = g_x * g_x;
>     float c = MyPow(g_x, 1.0f);             // Compiler inlines: float c
> = g_x;
>     float d = MyPow(g_x, g_y);              // Compiler inlines: float d
> = powf(g_x, g_y);
>
>
>     float y = 0.f;
>     float e = MyPow(g_x, y);                // Optimizing compiler SHOULD
> inline: float e = 1.0f; Because y is known at compile time.
>
>
>     return 0;
> }
>
>
> This of course makes the assumption that the compiler is obligated to skip
> compilation of code that fails the constexpr if conditional where it would
> instead compile the code in the else blocks, and vice versa where the if
> constexpr passes. It's also worth mentioning that there should be no
> guarantee that just because a variable is assigned to a literal and then
> immediately queried for std::is_constant_evaluated that it will return
> true. It's up to the compiler to respect this case only when the variable
> is optimized in a way to be treated as such. For example, it may return
> false in a non-optimized build, but true in an optimized build where inline
> expansion is guaranteed.
>
> As far as the preceding example goes, yes, I went straight to the float
> use case, which is normally non-integral, but I wanted to also demonstrate
> that this works around the issue where floats cannot be template arguments
> in a more elegant and uniformly obvious way where a function author can
> optimize for specific cases and combinations of literal values.
>
>
std::is_constant_evaluated is useless in a "static_assert" of "if
constexpr" for the simple reason that it would yield only false.
"if constexpr" and "static_assert" are evaluated at parsing or template
instantiation time.
The same thing would happen with what you propose.
Furthermore in your example a simple 'if constexpr' statement would have
side effects.

--
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/5f49b2c1-0824-4a3f-b8bb-5e73680bbdba%40isocpp.org.

------=_Part_4403_1322917060.1529002702902
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, June 14, 2018 at 3:18:39 AM UTC+2, csha...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>The proposal P0595R1, as it is currently stated, in my opinion, would be a=
 wonderful addition to C++. However I believe that there could be another p=
otential use case for std::is_constant_evaluated, in which it accepts a var=
iable as an argument. The expression would return true if and only if the c=
ompiler is already aware of the value of the variable itself. The motivatio=
n behind this is to address proposals for constexpr variable function argum=
ents and similar situations, but could sidestep the potential pitfalls of f=
unction overloading. But it allows the programmer to leverage inline optimi=
zations that the compiler is often already doing by making him/her aware of=
 when those optimizations are applied.<div><br></div><div><div>Declared som=
ething like this:</div><div><div style=3D"background-color:rgb(250,250,250)=
;border-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wra=
p:break-word"><code><div><span style=3D"color:#008">namespace</span><span s=
tyle=3D"color:#000"> std<br></span><span style=3D"color:#660">{</span><span=
 style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">/=
/ Already in P0595R1. This returns true if the compiler is evaluating the f=
unction itself in constexpr context.</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">bool</span><span style=
=3D"color:#000"> is_constant_evaluated</span><span style=3D"color:#660">()<=
/span><span style=3D"color:#000"> noexcept</span><span style=3D"color:#660"=
>;</span><span style=3D"color:#000"><br><br><br>=C2=A0 =C2=A0 </span><span =
style=3D"color:#800">// Returns true if the literal value of variable t is =
known to the compiler.</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 <=
/span><span style=3D"color:#008">template</span><span style=3D"color:#000">=
 </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">ty=
pename</span><span style=3D"color:#000"> T</span><span style=3D"color:#660"=
>&gt;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#008">bool</span><span style=3D"color:#000"> is_constant_evalu=
ated</span><span style=3D"color:#660">(</span><span style=3D"color:#000">T =
t</span><span style=3D"color:#660">)</span><span style=3D"color:#000"> noex=
cept</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><b=
r></span><span style=3D"color:#660">}</span></div></code></div><div><br></d=
iv></div><div><br></div><div>Example usage:</div></div><div><div style=3D"b=
ackground-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style=
:solid;border-width:1px;word-wrap:break-word"><code><div><span style=3D"col=
or:#008">inline</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#008">constexpr</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">float</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#606">MyPow</span><span style=3D"color:#660">(</span><span style=3D"co=
lor:#008">float</span><span style=3D"color:#000"> x</span><span style=3D"co=
lor:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#=
008">float</span><span style=3D"color:#000"> y</span><span style=3D"color:#=
660">)</span><span style=3D"color:#000"><br></span><span style=3D"color:#66=
0">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=
=3D"color:#008">if</span><span style=3D"color:#000"> </span><span style=3D"=
color:#008">constexpr</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">(</span><span style=3D"color:#000">std</span><span style=3D=
"color:#660">::</span><span style=3D"color:#000">is_constant_evaluated</spa=
n><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>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">retu=
rn</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0</s=
pan><span style=3D"color:#660">;</span><span style=3D"color:#000"> </span><=
span style=3D"color:#800">// TODO: Make a compile-time friendly pow functio=
n</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"=
color:#660">}</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color:#008">else</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#008">if</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">constexpr</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">std</span><span sty=
le=3D"color:#660">::</span><span style=3D"color:#000">is_constant_evaluated=
</span><span style=3D"color:#660">(</span><span style=3D"color:#000">y</spa=
n><span style=3D"color:#660">)<wbr>)</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color:#660">{</span><span style=3D"colo=
r:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">i=
f</span><span style=3D"color:#000"> </span><span style=3D"color:#008">const=
expr</span><span style=3D"color:#000"> </span><span style=3D"color:#660">(<=
/span><span style=3D"color:#000">y </span><span style=3D"color:#660">=3D=3D=
</span><span style=3D"color:#000"> </span><span style=3D"color:#066">0.f</s=
pan><span style=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">re=
turn</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1.=
f</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">if</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">constexpr</span><=
span style=3D"color:#000"> </span><span style=3D"color:#660">(</span><span =
style=3D"color:#000">y </span><span style=3D"color:#660">=3D=3D</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#066">1.f</span><span st=
yle=3D"color:#660">)</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><sp=
an style=3D"color:#000"> x</span><span style=3D"color:#660">;</span><span s=
tyle=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"c=
olor:#008">if</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">constexpr</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#660">(</span><span style=3D"color:#000">y </span><span style=3D"color:=
#660">=3D=3D</span><span style=3D"color:#000"> </span><span style=3D"color:=
#066">2.f</span><span style=3D"color:#660">)</span><span style=3D"color:#00=
0"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"colo=
r:#008">return</span><span style=3D"color:#000"> x </span><span style=3D"co=
lor:#660">*</span><span style=3D"color:#000"> x</span><span style=3D"color:=
#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </=
span><span style=3D"color:#008">if</span><span style=3D"color:#000"> </span=
><span style=3D"color:#008">constexpr</span><span style=3D"color:#000"> </s=
pan><span style=3D"color:#660">(</span><span style=3D"color:#000">y </span>=
<span style=3D"color:#660">=3D=3D</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#066">3.f</span><span style=3D"color:#660">)</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </spa=
n><span style=3D"color:#008">return</span><span style=3D"color:#000"> x </s=
pan><span style=3D"color:#660">*</span><span style=3D"color:#000"> x </span=
><span style=3D"color:#660">*</span><span style=3D"color:#000"> x</span><sp=
an style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =C2=
=A0 =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 =C2=A0 =C2=A0 </span><span =
style=3D"color:#008">return</span><span style=3D"color:#000"> powf</span><s=
pan style=3D"color:#660">(</span><span style=3D"color:#000">x</span><span s=
tyle=3D"color:#660">,</span><span style=3D"color:#000"> y</span><span style=
=3D"color:#660">);</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </spa=
n><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:#0=
00"><br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=3D"color:#008">retur=
n</span><span style=3D"color:#000"> powf</span><span style=3D"color:#660">(=
</span><span style=3D"color:#000">x</span><span style=3D"color:#660">,</spa=
n><span style=3D"color:#000"> y</span><span style=3D"color:#660">);</span><=
span style=3D"color:#000"><br></span><span style=3D"color:#660">}</span><sp=
an style=3D"color:#000"><br><br><br></span><span style=3D"color:#008">float=
</span><span style=3D"color:#000"> g_x</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> g_y</span><span style=3D"color:#660">;</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#800">// globall=
y mutable, always evaluated at runtime</span><span style=3D"color:#000"><br=
></span><span style=3D"color:#008">int</span><span style=3D"color:#000"> ma=
in</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"color:#008">constexpr</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">float</span><span style=
=3D"color:#000"> a </span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#000"> </span><span style=3D"color:#606">MyPow</span><span style=
=3D"color:#660">(</span><span style=3D"color:#066">3.14f</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#066">2.5f</span><span style=3D"color:#660">);</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#800">// MyPow takes the first if bl=
ock and returns a value computed at compile-time</span><span style=3D"color=
:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">float</span><spa=
n style=3D"color:#000"> b </span><span style=3D"color:#660">=3D</span><span=
 style=3D"color:#000"> </span><span style=3D"color:#606">MyPow</span><span =
style=3D"color:#660">(</span><span style=3D"color:#000">g_x</span><span sty=
le=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">2.0f</span><span style=3D"color:#660">);</span><span style=3D"=
color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><span style=
=3D"color:#800">// Compiler inlines: float b =3D g_x * g_x;</span><span sty=
le=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">float=
</span><span style=3D"color:#000"> c </span><span style=3D"color:#660">=3D<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyPow</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">g_x</spa=
n><span style=3D"color:#660">,</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#066">1.0f</span><span style=3D"color:#660">);</span><spa=
n style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 </span><s=
pan style=3D"color:#800">// Compiler inlines: float c =3D g_x;</span><span =
style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">fl=
oat</span><span style=3D"color:#000"> d </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#606">MyP=
ow</span><span style=3D"color:#660">(</span><span style=3D"color:#000">g_x<=
/span><span style=3D"color:#660">,</span><span style=3D"color:#000"> g_y</s=
pan><span style=3D"color:#660">);</span><span style=3D"color:#000"> =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0</span><span style=3D"color:#800">=
// Compiler inlines: float d =3D powf(g_x, g_y);</span><span style=3D"color=
:#000"><br><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">float</s=
pan><span style=3D"color:#000"> y </span><span style=3D"color:#660">=3D</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#066">0.f</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br>=C2=A0 =
=C2=A0 </span><span style=3D"color:#008">float</span><span style=3D"color:#=
000"> e </span><span style=3D"color:#660">=3D</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">MyPow</span><span style=3D"color:#66=
0">(</span><span style=3D"color:#000">g_x</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> y</span><span style=3D"color:#660">);</=
span><span style=3D"color:#000"> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0</span><span style=3D"color:#800">// Optimizing</span><span st=
yle=3D"color:#800"> compiler SHOULD inline: float e =3D 1.0f; Because y is =
known at compile time.</span><span style=3D"color:#000"><br><br><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></span><span style=3D"color:#660">}=
</span></div></code></div><div><br></div></div><div><br><div>This of course=
 makes the assumption that the compiler is obligated to skip compilation of=
 code that fails the constexpr if conditional where it would instead compil=
e the code in the else blocks, and vice versa where the if constexpr passes=
.. It&#39;s also worth mentioning that there should be no guarantee that jus=
t because a variable is assigned to a literal and then immediately queried =
for std::is_constant_evaluated that it will return true. It&#39;s up to the=
 compiler to respect this case only when the variable is optimized in a way=
 to be treated as such. For example, it may return false in a non-optimized=
 build, but true in an optimized build where inline expansion is guaranteed=
..</div><div><br></div><div>As far as the preceding example goes, yes, I wen=
t straight to the float use case, which is normally non-integral, but I wan=
ted to also demonstrate that this works around the issue where floats canno=
t be template arguments in a more elegant and uniformly obvious way where a=
 function author can optimize for specific cases and combinations of litera=
l values.</div></div><div><br></div></div></blockquote><div><br></div><div>=
std::<span style=3D"color: rgb(0, 0, 0); font-family: monospace; background=
-color: rgb(250, 250, 250);">is_constant_evaluated is useless in a &quot;st=
atic_assert&quot; of &quot;if constexpr&quot; for the simple reason that it=
 would yield only false.</span></div><div><font color=3D"#000000" face=3D"m=
onospace">&quot;if constexpr&quot; and &quot;static_assert&quot; are evalua=
ted at parsing or template instantiation time.</font></div><div><font color=
=3D"#000000" face=3D"monospace">The same thing would happen with what you p=
ropose.</font></div><div><font color=3D"#000000" face=3D"monospace">Further=
more in your example a simple &#39;if constexpr&#39; statement would have s=
ide effects.</font></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/5f49b2c1-0824-4a3f-b8bb-5e73680bbdba%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/5f49b2c1-0824-4a3f-b8bb-5e73680bbdba=
%40isocpp.org</a>.<br />

------=_Part_4403_1322917060.1529002702902--

------=_Part_4402_613498978.1529002702901--

.