Topic: UDLs for fixed-width integer types
Author: Tristan Brindle <tcbrindle@gmail.com>
Date: Wed, 1 Feb 2017 12:24:55 -0800 (PST)
Raw View
------=_Part_362_60733521.1485980695121
Content-Type: multipart/alternative;
boundary="----=_Part_363_1241895113.1485980695122"
------=_Part_363_1241895113.1485980695122
Content-Type: text/plain; charset=UTF-8
I think a small-but-worthwhile addition to the standard library would be to
add user-defined literals for the various fixed-width integer types defined
in <cstdint>, for example
using namespace std::literals;
auto a = 0u64; // a is std::uint64_t
auto b = 0i16; // b is std::int16_t
to complement the core language-provided literals such as
auto c = 0ul; // c is unsigned long
As far a I can see there have been no papers proposing this to date,
although P0330r0
<http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0330r0.pdf> (proposing
the zu literal for size_t) mentions it as a possible direction for further
work.
Before I go hacking up a paper of my own however, I guess I should canvas a
general opinion: basically, is this something that is worthwhile to pursue,
or is it likely to get quickly shot down in committee?
Thanks,
Tristan
--
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/3b2e3df8-20d7-475d-8461-babed4f6354f%40isocpp.org.
------=_Part_363_1241895113.1485980695122
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><div>I think a small-but-worthwhile addition to the st=
andard library would be to add user-defined literals for the various fixed-=
width integer types defined in <cstdint>, for example</div><div><br><=
/div><div><font face=3D"courier new, monospace">=C2=A0 using namespace std:=
:literals;</font></div><div><font face=3D"courier new, monospace"><br></fon=
t></div><div><font face=3D"courier new, monospace">=C2=A0 auto a =3D 0u64; =
=C2=A0 // a is std::uint64_t</font></div><div><font face=3D"courier new, mo=
nospace">=C2=A0 auto b =3D 0i16; =C2=A0 // b is std::int16_t</font></div><d=
iv><br></div><div>to complement the core language-provided literals such as=
</div><div><br></div><div>=C2=A0 =C2=A0<font face=3D"courier new, monospace=
">auto c =3D 0ul; =C2=A0// c is unsigned long</font></div><div><br></div><d=
iv>As far a I can see there have been no papers proposing this to date, alt=
hough=C2=A0<a href=3D"http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p=
0330r0.pdf">P0330r0</a>=C2=A0(proposing the=C2=A0<font face=3D"courier new,=
monospace">zu</font>=C2=A0literal for size_t) =C2=A0mentions it as a possi=
ble direction for further work.</div><div><br></div><div>Before I go hackin=
g up a paper of my own however, I guess I should canvas a general opinion: =
basically, is this something that is worthwhile to pursue, or is it likely =
to get quickly shot down in committee?</div><div><br></div><div><br></div><=
div>Thanks,</div><div><br></div><div>Tristan</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/3b2e3df8-20d7-475d-8461-babed4f6354f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/3b2e3df8-20d7-475d-8461-babed4f6354f=
%40isocpp.org</a>.<br />
------=_Part_363_1241895113.1485980695122--
------=_Part_362_60733521.1485980695121--
.
Author: David Krauss <potswa@gmail.com>
Date: Thu, 2 Feb 2017 20:33:02 +0800
Raw View
--Apple-Mail=_01978130-4DE9-4E3B-8E1B-79D8F4137883
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
This is often suggested, but will it really make code better?
Which is most readable?
1. std::int16_t b =3D 0;
2. auto b =3D std::int16_t{ 0 };
2a. auto b =3D std::int16_t( 0 );
3. auto b =3D 0i16;
(Also, remember that complex numbers already have the suffixes i, il, if.)
Which best handles expressions? Given short x=E2=80=A6
1. std::int16_t b =3D x + 100; // trips -Wconversion on GCC
2. auto b =3D std::int16_t( x + 100 ); // OK
3. auto b =3D x + 100i16; // deduces int, not int16_t, due to integral prom=
otion
> On 2017=E2=80=9302=E2=80=9302, at 4:24 AM, Tristan Brindle <tcbrindle@gma=
il.com> wrote:
>=20
>=20
> I think a small-but-worthwhile addition to the standard library would be =
to add user-defined literals for the various fixed-width integer types defi=
ned in <cstdint>, for example
>=20
> using namespace std::literals;
>=20
> auto a =3D 0u64; // a is std::uint64_t
> auto b =3D 0i16; // b is std::int16_t
>=20
> to complement the core language-provided literals such as
>=20
> auto c =3D 0ul; // c is unsigned long
>=20
> As far a I can see there have been no papers proposing this to date, alth=
ough P0330r0 <http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0330r0.p=
df> (proposing the zu literal for size_t) mentions it as a possible direct=
ion for further work.
>=20
> Before I go hacking up a paper of my own however, I guess I should canvas=
a general opinion: basically, is this something that is worthwhile to purs=
ue, or is it likely to get quickly shot down in committee?
>=20
>=20
> Thanks,
>=20
> Tristan
>=20
>=20
> --=20
> You received this message because you are subscribed to the Google Groups=
"ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
email to std-proposals+unsubscribe@isocpp.org <mailto:std-proposals+unsubs=
cribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org <mailto:std=
-proposals@isocpp.org>.
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/3b2e3df8-20d7-475d-8461-babed4f6354f%40isocpp.=
org <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3b2e3df8-=
20d7-475d-8461-babed4f6354f%40isocpp.org?utm_medium=3Demail&utm_source=3Dfo=
oter>.
--=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/4CDC2FB5-4A1A-4FC5-9BB4-9AE47346C08E%40gmail.com=
..
--Apple-Mail=_01978130-4DE9-4E3B-8E1B-79D8F4137883
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">This is often sugg=
ested, but will it really make code better?<div class=3D""><br class=3D""><=
/div><div class=3D"">Which is most readable?</div><div class=3D""><br class=
=3D""></div><font face=3D"Courier" class=3D"">1.<span class=3D"Apple-tab-sp=
an" style=3D"white-space: pre;"> </span>std::int16_t b =3D 0;<br class=3D""=
></font><div class=3D""></div><div class=3D""><font face=3D"Courier" class=
=3D""><br class=3D""></font></div><div class=3D""><font face=3D"Courier" cl=
ass=3D"">2.<span class=3D"Apple-tab-span" style=3D"white-space: pre;"> </sp=
an></font><span style=3D"font-family: Courier;" class=3D"">auto b =3D std::=
int16_t{ 0 };</span></div><div class=3D""><div class=3D""><font face=3D"Cou=
rier" class=3D"">2a.<span class=3D"Apple-tab-span" style=3D"white-space: pr=
e;"> </span>auto b =3D std::int16_t( 0 );</font></div></div><div class=3D""=
><font face=3D"Courier" class=3D""><br class=3D""></font></div><div class=
=3D""><font face=3D"Courier" class=3D"">3.<span class=3D"Apple-tab-span" st=
yle=3D"white-space:pre"> </span>auto b =3D 0i16;</font></div><div class=3D"=
"><br class=3D""></div><div class=3D"">(Also, remember that complex numbers=
already have the suffixes <font face=3D"Courier" class=3D"">i</font>,=
<font face=3D"Courier" class=3D"">il</font>, <font face=3D"Courier" class=
=3D"">if</font>.)</div><div class=3D""><br class=3D""></div><div class=3D""=
>Which best handles expressions? Given <font face=3D"Courier" class=3D"">sh=
ort x</font>=E2=80=A6</div><div class=3D""><div class=3D""><br class=3D""><=
/div><div class=3D""><font face=3D"Courier" class=3D"">1.<span class=3D"App=
le-tab-span" style=3D"white-space: pre;"> </span>std::int16_t b =3D x + 100=
; // trips -Wconversion on GCC<br class=3D""></font><div class=3D""></div><=
div class=3D""><font face=3D"Courier" class=3D""><br class=3D""></font></di=
v><div class=3D""><font face=3D"Courier" class=3D"">2.<span class=3D"Apple-=
tab-span" style=3D"white-space: pre;"> </span>auto b =3D std::int16_t( x + =
100 ); // OK</font></div><div class=3D""><font face=3D"Courier" class=3D"">=
<br class=3D""></font></div><div class=3D""><font face=3D"Courier" class=3D=
"">3.<span class=3D"Apple-tab-span" style=3D"white-space: pre;"> </span>aut=
o b =3D x + 100i16; // deduces int, not int16_t, due to integral promotion<=
/font></div></div><div class=3D""><br class=3D""></div><div class=3D""><br =
class=3D""></div><div class=3D""><br class=3D""><div><blockquote type=3D"ci=
te" class=3D""><div class=3D"">On 2017=E2=80=9302=E2=80=9302, at 4:24 AM, T=
ristan Brindle <<a href=3D"mailto:tcbrindle@gmail.com" class=3D"">tcbrin=
dle@gmail.com</a>> wrote:</div><br class=3D"Apple-interchange-newline"><=
div class=3D""><div dir=3D"ltr" class=3D""><br class=3D""><div class=3D"">I=
think a small-but-worthwhile addition to the standard library would be to =
add user-defined literals for the various fixed-width integer types defined=
in <cstdint>, for example</div><div class=3D""><br class=3D""></div>=
<div class=3D""><font face=3D"courier new, monospace" class=3D""> usi=
ng namespace std::literals;</font></div><div class=3D""><font face=3D"couri=
er new, monospace" class=3D""><br class=3D""></font></div><div class=3D""><=
font face=3D"courier new, monospace" class=3D""> auto a =3D 0u64; &nb=
sp; // a is std::uint64_t</font></div><div class=3D""><font face=3D"courier=
new, monospace" class=3D""> auto b =3D 0i16; // b is std::int=
16_t</font></div><div class=3D""><br class=3D""></div><div class=3D"">to co=
mplement the core language-provided literals such as</div><div class=3D""><=
br class=3D""></div><div class=3D""> <font face=3D"courier new,=
monospace" class=3D"">auto c =3D 0ul; // c is unsigned long</font></=
div><div class=3D""><br class=3D""></div><div class=3D"">As far a I can see=
there have been no papers proposing this to date, although <a href=3D=
"http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0330r0.pdf" class=3D"=
">P0330r0</a> (proposing the <font face=3D"courier new, monospace=
" class=3D"">zu</font> literal for size_t) mentions it as a poss=
ible direction for further work.</div><div class=3D""><br class=3D""></div>=
<div class=3D"">Before I go hacking up a paper of my own however, I guess I=
should canvas a general opinion: basically, is this something that is wort=
hwhile to pursue, or is it likely to get quickly shot down in committee?</d=
iv><div class=3D""><br class=3D""></div><div class=3D""><br class=3D""></di=
v><div class=3D"">Thanks,</div><div class=3D""><br class=3D""></div><div cl=
ass=3D"">Tristan</div><div class=3D""><br class=3D""></div></div><div class=
=3D""><br class=3D"webkit-block-placeholder"></div>
-- <br class=3D"">
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br class=3D"">
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" class=3D"">=
std-proposals+unsubscribe@isocpp.org</a>.<br class=3D"">
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" class=3D"">std-proposals@isocpp.org</a>.<br class=3D"">
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/3b2e3df8-20d7-475d-8461-babed4f6354f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" class=3D"">https:/=
/groups.google.com/a/isocpp.org/d/msgid/std-proposals/3b2e3df8-20d7-475d-84=
61-babed4f6354f%40isocpp.org</a>.<br class=3D"">
</div></blockquote></div><br class=3D""></div></div></body></html>
<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/4CDC2FB5-4A1A-4FC5-9BB4-9AE47346C08E%=
40gmail.com?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/4CDC2FB5-4A1A-4FC5-9BB4-9AE47346C08E%=
40gmail.com</a>.<br />
--Apple-Mail=_01978130-4DE9-4E3B-8E1B-79D8F4137883--
.