Topic: User-defined literal parameters as literal types


Author: joe.sylve@gmail.com
Date: Sun, 9 Jul 2017 15:51:42 -0700 (PDT)
Raw View
------=_Part_6080_1755925653.1499640702081
Content-Type: multipart/alternative;
 boundary="----=_Part_6081_1492606062.1499640702081"

------=_Part_6081_1492606062.1499640702081
Content-Type: text/plain; charset="UTF-8"

Normally function parameters are not treated as literal types (for obvious
reasons); however, user-defined literal function parameters could be made
an exception to that rule.  This would allow compile-time checks such as
the following possible:


// Converts Gibibytes to Bytes
constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
{
    static_assert(gib < (1ULL << 34), "result will overflow"); // Currently
not valid

    return gib << 30;
}


unsigned long long f() {
    return 17179869184_GiB; // This will overflow a uint64_t.
}


Currently, I can find no good way to enforce compile-time validation for
these conversions.  Thoughts?

--
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/ecd87667-05de-4364-879f-0c31de0a808a%40isocpp.org.

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

<div dir=3D"ltr"><div>Normally function parameters are not treated as liter=
al types (for obvious reasons); however, user-defined literal function para=
meters could be made an exception to that rule. =C2=A0This would allow comp=
ile-time checks such as the following possible:=C2=A0</div><div><br></div><=
div><br></div><div><div class=3D"prettyprint" style=3D"background-color: rg=
b(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; bo=
rder-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div c=
lass=3D"subprettyprint"><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">// Converts Gibibytes to Bytes</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br></span><span 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: #008;" class=3D"styled-by=
-prettify">unsigned</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
long</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">long</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">&quot;&quot;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> _GiB </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">unsigned</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">long</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">long</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> gi=
b </span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">static_assert</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">gib </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">(</span><span style=3D"color: #066;" class=3D"sty=
led-by-prettify">1ULL</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #066;" class=3D"styled-by-prettify">34</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #080;" class=3D"styled-by-prettify">&quot;result will overflow&quot;</=
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: #800;" class=3D"styled-by-prettify">// Currently not valid</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =
=C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ret=
urn</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> gib </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #066;" class=3D"styled-by-prettify">30</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br><br><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">unsigned</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">long</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
long</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> f</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span 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">return</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;"=
 class=3D"styled-by-prettify">17179869184</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify">_GiB</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">// This will overflow a uint64_t.</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">}</span></div></code></div><span class=3D"styled-by=
-prettify" style=3D"font-family: monospace; background-color: rgb(250, 250,=
 250); color: rgb(102, 102, 0);"><br></span><br></div><div>Currently, I can=
 find no good way to enforce compile-time validation for these conversions.=
 =C2=A0Thoughts?</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/ecd87667-05de-4364-879f-0c31de0a808a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ecd87667-05de-4364-879f-0c31de0a808a=
%40isocpp.org</a>.<br />

------=_Part_6081_1492606062.1499640702081--

------=_Part_6080_1755925653.1499640702081--

.


Author: Nicol Bolas <jmckesson@gmail.com>
Date: Sun, 9 Jul 2017 16:28:08 -0700 (PDT)
Raw View
------=_Part_3956_1234403004.1499642888787
Content-Type: multipart/alternative;
 boundary="----=_Part_3957_1288889720.1499642888787"

------=_Part_3957_1288889720.1499642888787
Content-Type: text/plain; charset="UTF-8"

First, I think you're using your terms incorrectly. An `unsigned long long`
is a literal type. It is *always* a literal type. That is a static property
of a type, not a dynamic property of anything. What you want is for the
parameters of a UDL function to be treated as a *constant expression*.

Second, that's not really possible. You're allowed to call UDL functions
via explicit `operator` commands, so a UDL cannot assume that a parameter
is a constant expression.

What we *could* do is allow alternate definitions for UDL functions that
make their parameters template parameters rather than function parameters:

template<unsigned long long arg>
constexpr some_type operator""_literal(); {...};

And the compiler would convert `10_literal` into a call to
`operator""_literal<10>()`.

--
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/4dcb4f80-0700-4a8d-8a24-e45c96cf21d9%40isocpp.org.

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

<div dir=3D"ltr">First, I think you&#39;re using your terms incorrectly. An=
 `unsigned long long` is a literal type. It is <i>always</i> a literal type=
.. That is a static property of a type, not a dynamic property of anything. =
What you want is for the parameters of a UDL function to be treated as a <i=
>constant expression</i>.<br><br>Second, that&#39;s not really possible. Yo=
u&#39;re allowed to call UDL functions via explicit `operator` commands, so=
 a UDL cannot assume that a parameter is a constant expression.<br><br>What=
 we <i>could</i> do is allow alternate definitions for UDL functions that m=
ake their parameters template parameters rather than function parameters:<b=
r><br><div style=3D"background-color: rgb(250, 250, 250); border-color: rgb=
(187, 187, 187); border-style: solid; border-width: 1px; overflow-wrap: bre=
ak-word;" class=3D"prettyprint"><code class=3D"prettyprint"><div class=3D"s=
ubprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">unsigned</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">long</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">long</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> arg</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> some_type </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">operator</span><span style=3D"color: #080;" class=3D"styled-=
by-prettify">&quot;&quot;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">_literal</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">();</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{..=
..};</span></div></code></div><br>And the compiler would convert `10_literal=
` into a call to `operator&quot;&quot;_literal&lt;10&gt;()`.<br></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/4dcb4f80-0700-4a8d-8a24-e45c96cf21d9%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/4dcb4f80-0700-4a8d-8a24-e45c96cf21d9=
%40isocpp.org</a>.<br />

------=_Part_3957_1288889720.1499642888787--

------=_Part_3956_1234403004.1499642888787--

.


Author: Manuel Bergler <berglerma@gmail.com>
Date: Mon, 10 Jul 2017 01:30:12 +0200
Raw View
--001a11c171e610085f0553ead9cb
Content-Type: text/plain; charset="UTF-8"

The issue here is that `operator""` - just like the other operators - can
also be called with regular function call syntax and thus with run-time
values.

E.g. the following is also valid:

    constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
{
        return gib << 30;
    }

    int main(int argc, char** argv) {
        return operator""_GiB(argc);
    }

Only allowing UDL operators to be called with constant expression thus
technically is a breaking change.

On Mon, Jul 10, 2017 at 12:51 AM, <joe.sylve@gmail.com> wrote:

> Normally function parameters are not treated as literal types (for obvious
> reasons); however, user-defined literal function parameters could be made
> an exception to that rule.  This would allow compile-time checks such as
> the following possible:
>
>
> // Converts Gibibytes to Bytes
> constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
> {
>     static_assert(gib < (1ULL << 34), "result will overflow"); //
> Currently not valid
>
>     return gib << 30;
> }
>
>
> unsigned long long f() {
>     return 17179869184 <(717)%20986-9184>_GiB; // This will overflow a
> uint64_t.
> }
>
>
> Currently, I can find no good way to enforce compile-time validation for
> these conversions.  Thoughts?
>
> --
> 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/ecd87667-05de-4364-
> 879f-0c31de0a808a%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/ecd87667-05de-4364-879f-0c31de0a808a%40isocpp.org?utm_medium=email&utm_source=footer>
> .
>

--
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/CAM76qmvkBdBQH5MaDbND586QWzCVu%2B-ftMOq4LwgnZb9kuKEAw%40mail.gmail.com.

--001a11c171e610085f0553ead9cb
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">The issue here is that `operator&quot;&quot;` - just like =
the other operators - can also be called with regular function call syntax =
and thus with run-time values.<div><br></div><div>E.g. the following is als=
o valid:</div><div><div>=C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 constex=
pr unsigned long long operator&quot;&quot; _GiB ( unsigned long long gib ) =
{ =C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return gib &lt;&lt; 30;</div=
><div>=C2=A0 =C2=A0 }</div><div><br></div><div>=C2=A0 =C2=A0 int main(int a=
rgc, char** argv) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return operator&q=
uot;&quot;_GiB(argc);</div><div>=C2=A0 =C2=A0 }</div></div><div><br></div><=
div>Only allowing UDL operators to be called with constant expression thus =
technically is a breaking change.</div></div><div class=3D"gmail_extra"><br=
><div class=3D"gmail_quote">On Mon, Jul 10, 2017 at 12:51 AM,  <span dir=3D=
"ltr">&lt;<a href=3D"mailto:joe.sylve@gmail.com" target=3D"_blank">joe.sylv=
e@gmail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div di=
r=3D"ltr"><div>Normally function parameters are not treated as literal type=
s (for obvious reasons); however, user-defined literal function parameters =
could be made an exception to that rule.=C2=A0 This would allow compile-tim=
e checks such as the following possible:=C2=A0</div><div><br></div><div><br=
></div><div><div class=3D"m_6025330924488685454prettyprint" style=3D"backgr=
ound-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:soli=
d;border-width:1px;word-wrap:break-word"><code class=3D"m_60253309244886854=
54prettyprint"><div class=3D"m_6025330924488685454subprettyprint"><span sty=
le=3D"color:#800" class=3D"m_6025330924488685454styled-by-prettify">// Conv=
erts Gibibytes to Bytes</span><span style=3D"color:#000" class=3D"m_6025330=
924488685454styled-by-prettify"><br></span><span style=3D"color:#008" class=
=3D"m_6025330924488685454styled-by-prettify">constexpr</span><span style=3D=
"color:#000" class=3D"m_6025330924488685454styled-by-prettify"> </span><spa=
n style=3D"color:#008" class=3D"m_6025330924488685454styled-by-prettify">un=
signed</span><span style=3D"color:#000" class=3D"m_6025330924488685454style=
d-by-prettify"> </span><span style=3D"color:#008" class=3D"m_60253309244886=
85454styled-by-prettify">long</span><span style=3D"color:#000" class=3D"m_6=
025330924488685454styled-by-prettify"> </span><span style=3D"color:#008" cl=
ass=3D"m_6025330924488685454styled-by-prettify">long</span><span style=3D"c=
olor:#000" class=3D"m_6025330924488685454styled-by-prettify"> </span><span =
style=3D"color:#008" class=3D"m_6025330924488685454styled-by-prettify">oper=
ator</span><span style=3D"color:#080" class=3D"m_6025330924488685454styled-=
by-prettify">&quot;&quot;</span><span style=3D"color:#000" class=3D"m_60253=
30924488685454styled-by-prettify"> _GiB </span><span style=3D"color:#660" c=
lass=3D"m_6025330924488685454styled-by-prettify">(</span><span style=3D"col=
or:#000" class=3D"m_6025330924488685454styled-by-prettify"> </span><span st=
yle=3D"color:#008" class=3D"m_6025330924488685454styled-by-prettify">unsign=
ed</span><span style=3D"color:#000" class=3D"m_6025330924488685454styled-by=
-prettify"> </span><span style=3D"color:#008" class=3D"m_602533092448868545=
4styled-by-prettify">long</span><span style=3D"color:#000" class=3D"m_60253=
30924488685454styled-by-prettify"> </span><span style=3D"color:#008" class=
=3D"m_6025330924488685454styled-by-prettify">long</span><span style=3D"colo=
r:#000" class=3D"m_6025330924488685454styled-by-prettify"> gib </span><span=
 style=3D"color:#660" class=3D"m_6025330924488685454styled-by-prettify">)</=
span><span style=3D"color:#000" class=3D"m_6025330924488685454styled-by-pre=
ttify"><br></span><span style=3D"color:#660" class=3D"m_6025330924488685454=
styled-by-prettify">{</span><span style=3D"color:#000" class=3D"m_602533092=
4488685454styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color=
:#008" class=3D"m_6025330924488685454styled-by-prettify">static_assert</spa=
n><span style=3D"color:#660" class=3D"m_6025330924488685454styled-by-pretti=
fy">(</span><span style=3D"color:#000" class=3D"m_6025330924488685454styled=
-by-prettify">gib </span><span style=3D"color:#660" class=3D"m_602533092448=
8685454styled-by-prettify">&lt;</span><span style=3D"color:#000" class=3D"m=
_6025330924488685454styled-by-prettify"> </span><span style=3D"color:#660" =
class=3D"m_6025330924488685454styled-by-prettify">(</span><span style=3D"co=
lor:#066" class=3D"m_6025330924488685454styled-by-prettify">1ULL</span><spa=
n style=3D"color:#000" class=3D"m_6025330924488685454styled-by-prettify"> <=
/span><span style=3D"color:#660" class=3D"m_6025330924488685454styled-by-pr=
ettify">&lt;&lt;</span><span style=3D"color:#000" class=3D"m_60253309244886=
85454styled-by-prettify"> </span><span style=3D"color:#066" class=3D"m_6025=
330924488685454styled-by-prettify">34</span><span style=3D"color:#660" clas=
s=3D"m_6025330924488685454styled-by-prettify">),</span><span style=3D"color=
:#000" class=3D"m_6025330924488685454styled-by-prettify"> </span><span styl=
e=3D"color:#080" class=3D"m_6025330924488685454styled-by-prettify">&quot;re=
sult will overflow&quot;</span><span style=3D"color:#660" class=3D"m_602533=
0924488685454styled-by-prettify">);</span><span style=3D"color:#000" class=
=3D"m_6025330924488685454styled-by-prettify"> </span><span style=3D"color:#=
800" class=3D"m_6025330924488685454styled-by-prettify">// Currently not val=
id</span><span style=3D"color:#000" class=3D"m_6025330924488685454styled-by=
-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008" class=3D=
"m_6025330924488685454styled-by-prettify">return</span><span style=3D"color=
:#000" class=3D"m_6025330924488685454styled-by-prettify"> gib </span><span =
style=3D"color:#660" class=3D"m_6025330924488685454styled-by-prettify">&lt;=
&lt;</span><span style=3D"color:#000" class=3D"m_6025330924488685454styled-=
by-prettify"> </span><span style=3D"color:#066" class=3D"m_6025330924488685=
454styled-by-prettify">30</span><span style=3D"color:#660" class=3D"m_60253=
30924488685454styled-by-prettify">;</span><span style=3D"color:#000" class=
=3D"m_6025330924488685454styled-by-prettify"><br></span><span style=3D"colo=
r:#660" class=3D"m_6025330924488685454styled-by-prettify">}</span><span sty=
le=3D"color:#000" class=3D"m_6025330924488685454styled-by-prettify"><br><br=
><br></span><span style=3D"color:#008" class=3D"m_6025330924488685454styled=
-by-prettify">unsigned</span><span style=3D"color:#000" class=3D"m_60253309=
24488685454styled-by-prettify"> </span><span style=3D"color:#008" class=3D"=
m_6025330924488685454styled-by-prettify">long</span><span style=3D"color:#0=
00" class=3D"m_6025330924488685454styled-by-prettify"> </span><span style=
=3D"color:#008" class=3D"m_6025330924488685454styled-by-prettify">long</spa=
n><span style=3D"color:#000" class=3D"m_6025330924488685454styled-by-pretti=
fy"> f</span><span style=3D"color:#660" class=3D"m_6025330924488685454style=
d-by-prettify">()</span><span style=3D"color:#000" class=3D"m_6025330924488=
685454styled-by-prettify"> </span><span style=3D"color:#660" class=3D"m_602=
5330924488685454styled-by-prettify">{</span><span style=3D"color:#000" clas=
s=3D"m_6025330924488685454styled-by-prettify"><br>=C2=A0 =C2=A0 </span><spa=
n style=3D"color:#008" class=3D"m_6025330924488685454styled-by-prettify">re=
turn</span><span style=3D"color:#000" class=3D"m_6025330924488685454styled-=
by-prettify"> </span><span style=3D"color:#066" class=3D"m_6025330924488685=
454styled-by-prettify"><a href=3D"tel:(717)%20986-9184" value=3D"+171798691=
84" target=3D"_blank">17179869184</a></span><span style=3D"color:#000" clas=
s=3D"m_6025330924488685454styled-by-prettify">_GiB</span><span style=3D"col=
or:#660" class=3D"m_6025330924488685454styled-by-prettify">;</span><span st=
yle=3D"color:#000" class=3D"m_6025330924488685454styled-by-prettify"> </spa=
n><span style=3D"color:#800" class=3D"m_6025330924488685454styled-by-pretti=
fy">// This will overflow a uint64_t.</span><span style=3D"color:#000" clas=
s=3D"m_6025330924488685454styled-by-prettify"><br></span><span style=3D"col=
or:#660" class=3D"m_6025330924488685454styled-by-prettify">}</span></div></=
code></div><span class=3D"m_6025330924488685454styled-by-prettify" style=3D=
"font-family:monospace;background-color:rgb(250,250,250);color:rgb(102,102,=
0)"><br></span><br></div><div>Currently, I can find no good way to enforce =
compile-time validation for these conversions.=C2=A0 Thoughts?</div></div><=
span class=3D"HOEnZb"><font color=3D"#888888">

<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" target=3D"_=
blank">std-proposals+unsubscribe@<wbr>isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/ecd87667-05de-4364-879f-0c31de0a808a%=
40isocpp.org?utm_medium=3Demail&amp;utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/ecd8=
7667-05de-4364-<wbr>879f-0c31de0a808a%40isocpp.org</a><wbr>.<br>
</font></span></blockquote></div><br></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/CAM76qmvkBdBQH5MaDbND586QWzCVu%2B-ftM=
Oq4LwgnZb9kuKEAw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">h=
ttps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAM76qmvkBdBQH5=
MaDbND586QWzCVu%2B-ftMOq4LwgnZb9kuKEAw%40mail.gmail.com</a>.<br />

--001a11c171e610085f0553ead9cb--

.


Author: gmisocpp@gmail.com
Date: Sun, 9 Jul 2017 17:03:52 -0700 (PDT)
Raw View
------=_Part_6230_1360966311.1499645032436
Content-Type: multipart/alternative;
 boundary="----=_Part_6231_505008025.1499645032436"

------=_Part_6231_505008025.1499645032436
Content-Type: text/plain; charset="UTF-8"


Could we have a feature like this:

if (constexpr(gib)) // If gib is a constant expression
    static_assert(gib > 0);
else
    assert(gib > 0);

Perhaps also say that if an assert statement evaluates to a constant
expression, make assert act as if it was a static_assert.

On Monday, July 10, 2017 at 11:28:08 AM UTC+12, Nicol Bolas wrote:

> First, I think you're using your terms incorrectly. An `unsigned long
> long` is a literal type. It is *always* a literal type. That is a static
> property of a type, not a dynamic property of anything. What you want is
> for the parameters of a UDL function to be treated as a *constant
> expression*.
>
> Second, that's not really possible. You're allowed to call UDL functions
> via explicit `operator` commands, so a UDL cannot assume that a parameter
> is a constant expression.
>
> What we *could* do is allow alternate definitions for UDL functions that
> make their parameters template parameters rather than function parameters:
>
> template<unsigned long long arg>
> constexpr some_type operator""_literal(); {...};
>
> And the compiler would convert `10_literal` into a call to
> `operator""_literal<10>()`.
>

--
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/ee90c92f-39b1-4076-8da0-94e21317be6a%40isocpp.org.

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

<div dir=3D"ltr"><div><br></div><div>Could we have a feature like this:</di=
v><div><br></div><div>if (constexpr(gib)) // If gib is a constant expressio=
n</div><div>=C2=A0=C2=A0=C2=A0 static_assert(gib &gt; 0);</div><div>else</d=
iv><div>=C2=A0=C2=A0=C2=A0 assert(gib &gt; 0);</div><div><br></div><div>Per=
haps also say that if an assert statement evaluates to a constant expressio=
n, make assert act as if it was a static_assert.<br><br>On Monday, July 10,=
 2017 at 11:28:08 AM UTC+12, Nicol Bolas wrote:</div><blockquote class=3D"g=
mail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-l=
eft-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: s=
olid;"><div dir=3D"ltr">First, I think you&#39;re using your terms incorrec=
tly. An `unsigned long long` is a literal type. It is <i>always</i> a liter=
al type. That is a static property of a type, not a dynamic property of any=
thing. What you want is for the parameters of a UDL function to be treated =
as a <i>constant expression</i>.<br><br>Second, that&#39;s not really possi=
ble. You&#39;re allowed to call UDL functions via explicit `operator` comma=
nds, so a UDL cannot assume that a parameter is a constant expression.<br><=
br>What we <i>could</i> do is allow alternate definitions for UDL functions=
 that make their parameters template parameters rather than function parame=
ters:<br><br><div style=3D"border: 1px solid rgb(187, 187, 187); border-ima=
ge: none; background-color: rgb(250, 250, 250);"><code><div><span style=3D"=
color: rgb(0, 0, 136);">template</span><span style=3D"color: rgb(102, 102, =
0);">&lt;</span><span style=3D"color: rgb(0, 0, 136);">unsigned</span><span=
 style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(0, 0, 136=
);">long</span><span style=3D"color: rgb(0, 0, 0);"> </span><span style=3D"=
color: rgb(0, 0, 136);">long</span><span style=3D"color: rgb(0, 0, 0);"> ar=
g</span><span style=3D"color: rgb(102, 102, 0);">&gt;</span><span style=3D"=
color: rgb(0, 0, 0);"><br></span><span style=3D"color: rgb(0, 0, 136);">con=
stexpr</span><span style=3D"color: rgb(0, 0, 0);"> some_type </span><span s=
tyle=3D"color: rgb(0, 0, 136);">operator</span><span style=3D"color: rgb(0,=
 136, 0);">&quot;&quot;</span><span style=3D"color: rgb(0, 0, 0);">_literal=
</span><span style=3D"color: rgb(102, 102, 0);">();</span><span style=3D"co=
lor: rgb(0, 0, 0);"> </span><span style=3D"color: rgb(102, 102, 0);">{...};=
</span></div></code></div><br>And the compiler would convert `10_literal` i=
nto a call to `operator&quot;&quot;_literal&lt;10&gt;()`.<br></div></blockq=
uote></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/ee90c92f-39b1-4076-8da0-94e21317be6a%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/ee90c92f-39b1-4076-8da0-94e21317be6a=
%40isocpp.org</a>.<br />

------=_Part_6231_505008025.1499645032436--

------=_Part_6230_1360966311.1499645032436--

.


Author: joe.sylve@gmail.com
Date: Sun, 9 Jul 2017 18:00:12 -0700 (PDT)
Raw View
------=_Part_6068_1698953819.1499648412191
Content-Type: multipart/alternative;
 boundary="----=_Part_6069_1335075801.1499648412191"

------=_Part_6069_1335075801.1499648412191
Content-Type: text/plain; charset="UTF-8"


>
> First, I think you're using your terms incorrectly. An `unsigned long
> long` is a literal type. It is *always* a literal type. That is a static
> property of a type, not a dynamic property of anything. What you want is
> for the parameters of a UDL function to be treated as a *constant
> expression*.
>

That's almost certainly true.  Thanks for the correction.

The issue here is that `operator""` - just like the other operators - can
> also be called with regular function call syntax and thus with run-time
> values.
>

I did not know this.  It certainly makes this request a bit less
straight-forward.

What if were were to allow a constexpr function qualifier that would
basically define the function as constexpr only?  Then the following would
be valid.


// Converts Gibibytes to Bytes (called only if the function is being used
as constexpr)
constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
constexpr
{
    static_assert(gib < (1ULL << 34), "result will overflow");
    return gib << 30;
}

Could we have a feature like this:
>
> if (constexpr(gib)) // If gib is a constant expression
>     static_assert(gib > 0);
> else
>     assert(gib > 0);
>

I also like this idea, but I think there might be merit to both additions
(or something similar).

--
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/cec32fa3-03ee-45d3-b03d-c89e357eb9f2%40isocpp.org.

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

<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px=
 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">=
First, I think you&#39;re using your terms incorrectly. An `unsigned long l=
ong` is a literal type. It is=C2=A0<i>always</i>=C2=A0a literal type. That =
is a static property of a type, not a dynamic property of anything. What yo=
u want is for the parameters of a UDL function to be treated as a=C2=A0<i>c=
onstant expression</i>.<br></blockquote><div><br>That&#39;s almost certainl=
y true. =C2=A0Thanks for the correction.</div><div><br></div><div><blockquo=
te class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; border-left: 1=
px solid rgb(204, 204, 204); padding-left: 1ex;">The issue here is that `op=
erator&quot;&quot;` - just like the other operators - can also be called wi=
th regular function call syntax and thus with run-time values.<br></blockqu=
ote><div><br>I did not know this. =C2=A0It certainly makes this request a b=
it less straight-forward.=C2=A0</div><br>What if were were to allow a const=
expr function qualifier that would basically define the function as constex=
pr only? =C2=A0Then the following would be valid.</div><div><br></div><div>=
<span style=3D"font-family: monospace; background-color: rgb(250, 250, 250)=
; color: rgb(136, 0, 0);"><br class=3D"Apple-interchange-newline"></span><d=
iv class=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); bor=
der-color: rgb(187, 187, 187); border-style: solid; border-width: 1px; word=
-wrap: break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprin=
t"><span style=3D"color: #800;" class=3D"styled-by-prettify">// Converts Gi=
bibytes to Bytes (called only if the function is being used as constexpr)</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">unsigned</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">long</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">long</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">operator</span><span style=3D"color: #080;" class=3D"styled-by-pre=
ttify">&quot;&quot;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> _GiB </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">unsigned</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">long</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">long</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> gib </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></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 </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>static_assert</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">gib <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"col=
or: #066;" class=3D"styled-by-prettify">1ULL</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">34</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">),</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&quot;resu=
lt will overflow&quot;</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> <br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">return</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> gib </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">30</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><span s=
tyle=3D"font-family: monospace; background-color: rgb(250, 250, 250); color=
: rgb(102, 102, 0);"><br></span><blockquote class=3D"gmail_quote" style=3D"=
margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddi=
ng-left: 1ex;"><div>Could we have a feature like this:</div><div><br></div>=
<div>if (constexpr(gib)) // If gib is a constant expression</div><div>=C2=
=A0=C2=A0=C2=A0 static_assert(gib &gt; 0);</div><div>else</div><div>=C2=A0=
=C2=A0=C2=A0 assert(gib &gt; 0);</div></blockquote><div><br>I also like thi=
s idea, but I think there might be merit to both additions (or something si=
milar).</div></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/cec32fa3-03ee-45d3-b03d-c89e357eb9f2%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/cec32fa3-03ee-45d3-b03d-c89e357eb9f2=
%40isocpp.org</a>.<br />

------=_Part_6069_1335075801.1499648412191--

------=_Part_6068_1698953819.1499648412191--

.


Author: joe.sylve@gmail.com
Date: Sun, 9 Jul 2017 18:06:14 -0700 (PDT)
Raw View
------=_Part_2762_923305509.1499648774394
Content-Type: multipart/alternative;
 boundary="----=_Part_2763_1875797178.1499648774394"

------=_Part_2763_1875797178.1499648774394
Content-Type: text/plain; charset="UTF-8"


>
> First, I think you're using your terms incorrectly. An `unsigned long
> long` is a literal type. It is always a literal type. That is a static
> property of a type, not a dynamic property of anything. What you want is
> for the parameters of a UDL function to be treated as a constant expression.


That's almost certainly true.  Thanks for the correction.

The issue here is that `operator""` - just like the other operators - can
> also be called with regular function call syntax and thus with run-time
> values.


I did not know this.  It certainly makes this request a bit less
straight-forward.

What if were were to allow a constexpr function qualifier that would
basically define the function as constexpr only?  Then the following would
be valid:

// Converts Gibibytes to Bytes (called only if the function is being used
as constexpr)
constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
constexpr
{
    static_assert(gib < (1ULL << 34), "result will overflow");

    return gib << 30;
}

Could we have a feature like this:
> if (constexpr(gib)) // If gib is a constant expression
>     static_assert(gib > 0);
> else
>     assert(gib > 0);


I also like this idea, but I think there might be merit to both additions
(or something similar).

--
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/9dbf1000-a174-423a-99e3-e9433a23f141%40isocpp.org.

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

<div dir=3D"ltr"><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px=
 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">=
First, I think you&#39;re using your terms incorrectly. An `unsigned long l=
ong` is a literal type. It is always a literal type. That is a static prope=
rty of a type, not a dynamic property of anything. What you want is for the=
 parameters of a UDL function to be treated as a constant expression.</bloc=
kquote><div><br></div><div>That&#39;s almost certainly true. =C2=A0Thanks f=
or the correction.</div><div><br></div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0px 0px 0px 0.8ex; border-left: 1px solid rgb(204, 204, 204)=
; padding-left: 1ex;">The issue here is that `operator&quot;&quot;` - just =
like the other operators - can also be called with regular function call sy=
ntax and thus with run-time values.</blockquote><div><br></div><div>I did n=
ot know this. =C2=A0It certainly makes this request a bit less straight-for=
ward.=C2=A0</div><div><br></div><div>What if were were to allow a constexpr=
 function qualifier that would basically define the function as constexpr o=
nly? =C2=A0Then the following would be valid:</div><div><br></div><div clas=
s=3D"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-col=
or: rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: =
break-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n style=3D"color: #800;" class=3D"styled-by-prettify">// Converts Gibibytes=
 to Bytes (called only if the function is being used as constexpr)</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">unsigned</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">long</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">long</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
operator</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&q=
uot;&quot;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 _GiB </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">unsigned</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">long</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">long</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> gib </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">co=
nstexpr</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"><br>=C2=A0 =C2=A0 =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">static_ass=
ert</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">gib </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</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: #066;" =
class=3D"styled-by-prettify">1ULL</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">34</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: #080;" class=3D"styled-by-prettify">&quot;result will ove=
rflow&quot;</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">return</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> gib </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;=
&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #066;" class=3D"styled-by-prettify">30</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">}</span></div></code></div><div><br></=
div><blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; b=
order-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Could we have=
 a feature like this:<br>if (constexpr(gib)) // If gib is a constant expres=
sion<br>=C2=A0 =C2=A0 static_assert(gib &gt; 0);<br>else<br>=C2=A0 =C2=A0 a=
ssert(gib &gt; 0);</blockquote><div><br></div><div>I also like this idea, b=
ut I think there might be merit to both additions (or something similar).</=
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/9dbf1000-a174-423a-99e3-e9433a23f141%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9dbf1000-a174-423a-99e3-e9433a23f141=
%40isocpp.org</a>.<br />

------=_Part_2763_1875797178.1499648774394--

------=_Part_2762_923305509.1499648774394--

.


Author: Daniel Frey <d.frey@gmx.de>
Date: Mon, 10 Jul 2017 07:59:33 +0200
Raw View
> On 10. Jul 2017, at 01:28, Nicol Bolas <jmckesson@gmail.com> wrote:
>=20
> First, I think you're using your terms incorrectly. An `unsigned long lon=
g` is a literal type. It is always a literal type. That is a static propert=
y of a type, not a dynamic property of anything. What you want is for the p=
arameters of a UDL function to be treated as a constant expression.
>=20
> Second, that's not really possible. You're allowed to call UDL functions =
via explicit `operator` commands, so a UDL cannot assume that a parameter i=
s a constant expression.
>=20
> What we could do is allow alternate definitions for UDL functions that ma=
ke their parameters template parameters rather than function parameters:
>=20
> template<unsigned long long arg>
> constexpr some_type operator""_literal(); {...};
>=20
> And the compiler would convert `10_literal` into a call to `operator""_li=
teral<10>()`.

That's already possible. OP "just" needs to calculate the value based on th=
e individual characters. The signature is

template<char... Cs>
constexpr some_type operator"" _literal() { ... }

Now Cs... are always compile-time parameters and you can use them to calcul=
ate the value of unsigned long long with overflow checking, etc. - it's a b=
it tedious but possible.

Be careful that hex- or binary literals are also allowed, so you might be c=
alled with `'0', 'x', '4', 'f'` when the user writes `0x4f_literal`.

--=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/35C8F3DA-77E5-42B3-8A5E-050803657901%40gmx.de.

.


Author: Joe Sylve <joe.sylve@gmail.com>
Date: Mon, 10 Jul 2017 06:29:44 +0000
Raw View
--94eb2c07e74a0cc0420553f0b6e3
Content-Type: text/plain; charset="UTF-8"

While cool, this solution seems suboptimal.

On Mon, Jul 10, 2017, 00:59 Daniel Frey <d.frey@gmx.de> wrote:

> > On 10. Jul 2017, at 01:28, Nicol Bolas <jmckesson@gmail.com> wrote:
> >
> > First, I think you're using your terms incorrectly. An `unsigned long
> long` is a literal type. It is always a literal type. That is a static
> property of a type, not a dynamic property of anything. What you want is
> for the parameters of a UDL function to be treated as a constant expression.
> >
> > Second, that's not really possible. You're allowed to call UDL functions
> via explicit `operator` commands, so a UDL cannot assume that a parameter
> is a constant expression.
> >
> > What we could do is allow alternate definitions for UDL functions that
> make their parameters template parameters rather than function parameters:
> >
> > template<unsigned long long arg>
> > constexpr some_type operator""_literal(); {...};
> >
> > And the compiler would convert `10_literal` into a call to
> `operator""_literal<10>()`.
>
> That's already possible. OP "just" needs to calculate the value based on
> the individual characters. The signature is
>
> template<char... Cs>
> constexpr some_type operator"" _literal() { ... }
>
> Now Cs... are always compile-time parameters and you can use them to
> calculate the value of unsigned long long with overflow checking, etc. -
> it's a bit tedious but possible.
>
> Be careful that hex- or binary literals are also allowed, so you might be
> called with `'0', 'x', '4', 'f'` when the user writes `0x4f_literal`.
>
>

--
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/CAHWCVWLscJunU-g12LHBvL%2Bpeg3fjoVbPXi9Qyz36P1YPccG9g%40mail.gmail.com.

--94eb2c07e74a0cc0420553f0b6e3
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr">While cool, this solution seems suboptimal. </p>
<br><div class=3D"gmail_quote"><div dir=3D"ltr">On Mon, Jul 10, 2017, 00:59=
 Daniel Frey &lt;<a href=3D"mailto:d.frey@gmx.de">d.frey@gmx.de</a>&gt; wro=
te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;b=
order-left:1px #ccc solid;padding-left:1ex">&gt; On 10. Jul 2017, at 01:28,=
 Nicol Bolas &lt;<a href=3D"mailto:jmckesson@gmail.com" target=3D"_blank">j=
mckesson@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; First, I think you&#39;re using your terms incorrectly. An `unsigned l=
ong long` is a literal type. It is always a literal type. That is a static =
property of a type, not a dynamic property of anything. What you want is fo=
r the parameters of a UDL function to be treated as a constant expression.<=
br>
&gt;<br>
&gt; Second, that&#39;s not really possible. You&#39;re allowed to call UDL=
 functions via explicit `operator` commands, so a UDL cannot assume that a =
parameter is a constant expression.<br>
&gt;<br>
&gt; What we could do is allow alternate definitions for UDL functions that=
 make their parameters template parameters rather than function parameters:=
<br>
&gt;<br>
&gt; template&lt;unsigned long long arg&gt;<br>
&gt; constexpr some_type operator&quot;&quot;_literal(); {...};<br>
&gt;<br>
&gt; And the compiler would convert `10_literal` into a call to `operator&q=
uot;&quot;_literal&lt;10&gt;()`.<br>
<br>
That&#39;s already possible. OP &quot;just&quot; needs to calculate the val=
ue based on the individual characters. The signature is<br>
<br>
template&lt;char... Cs&gt;<br>
constexpr some_type operator&quot;&quot; _literal() { ... }<br>
<br>
Now Cs... are always compile-time parameters and you can use them to calcul=
ate the value of unsigned long long with overflow checking, etc. - it&#39;s=
 a bit tedious but possible.<br>
<br>
Be careful that hex- or binary literals are also allowed, so you might be c=
alled with `&#39;0&#39;, &#39;x&#39;, &#39;4&#39;, &#39;f&#39;` when the us=
er writes `0x4f_literal`.<br>
<br>
</blockquote></div>

<p></p>

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

--94eb2c07e74a0cc0420553f0b6e3--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Mon, 10 Jul 2017 17:56:40 -0700
Raw View
On domingo, 9 de julho de 2017 18:06:14 PDT joe.sylve@gmail.com wrote:
> // Converts Gibibytes to Bytes (called only if the function is being used
> as constexpr)
> constexpr unsigned long long operator"" _GiB ( unsigned long long gib )
> constexpr
> {
>     static_assert(gib < (1ULL << 34), "result will overflow");
>
>     return gib << 30;
> }

It's weird to have a second constexpr in that, a keyword that can only appear
if the first one is already there. And if you wanted  a non-constexpr overload,
you'd have zero of them.

constexpr int popcount(uint32_t v) constexpr
{
    return
        (((v      ) & 0xfff)    * UINT64_C(0x1001001001001) &
   UINT64_C(0x84210842108421)) % 0x1f +
        (((v >> 12) & 0xfff)    * UINT64_C(0x1001001001001) &
  UINT64_C(0x84210842108421)) % 0x1f +
        (((v >> 24) & 0xfff)    * UINT64_C(0x1001001001001) &
  UINT64_C(0x84210842108421)) % 0x1f;
}

int popcount(uint32_t v)
{
    int ret;
    asm ("popcount %1, %0" : "=r" (ret) : "r" (v));
    return ret;
}

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

--
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/2398117.ffiao56Z7F%40tjmaciei-mobl1.

.