Topic: Library support for binary literals.
Author: 3dw4rd@verizon.net
Date: Fri, 26 Apr 2013 10:49:41 -0700 (PDT)
Raw View
------=_Part_2307_26599404.1366998581419
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Since binary numeric literals have been blessed into C++14 it seems to me=
=20
that a small amount of library support in analogy to hex would be useful=20
and not too difficult or intrusive. This ould allow people to provide a=20
std::bin manipulator to input and output streams and write integers=20
formatted as, for example, 0b01001.
Table 85 Integer conversions: add basefield =3D=3D bin
Question: What to do about lack of standard stdio equivalent?
Table 87 Integer conversions: add basefield =3D=3D bin
We want to support both '0b' for !uppercase and '0B' for uppercase.
Question: What to do about lack of standard stdio equivalent?
In 27.5.1 Header <ios> synopsis [iostreams.base.overview]
Add bin to basefield:
// 27.5.6.3 base=EF=AC=81eld:
ios_base& dec (ios_base& str);
ios_base& hex (ios_base& str);
ios_base& oct (ios_base& str);
ios_base& bin (ios_base& str); // <- NEW!!!
27.5.3 Class ios_base [ios.base]
// 27.5.3.1.2 fmtflags
class ios_base {
....
static constexpr fmtflags bin =3D *unspecified*;
....
Table 122 =E2=80=94 fmtflags e=EF=AC=80ects
bin converts integer input or generates integer output in binary=20
base.
Table 123 =E2=80=94 fmtflags constants
basefield dec | oct | hex | bin
27.5.6.3 basefield manipulators [base=EF=AC=81eld.manip]
Add:
ios_base& bin(ios_base& str);
7 E=EF=AC=80ects: Calls str.setf(ios_base::bin, ios_base::basefield).
8 Returns: str.
Question: We could do binfloat. It might be amusing. We could use the bin=
=20
flag for it instead of copying hexfloat.
Or we could punt/defer this.
ios_base& binfloat(ios_base& str);
10 E=EF=AC=80ects: Calls str.setf(ios_base::fixed | ios_base::scienti=
fic,=20
ios_base::floatfield)
.setf(ios_base::bin, ios_base::basefield).
11 Returns: str.
12 [ Note: The more obvious use of ios_base::bin to specify binary=20
=EF=AC=82oating-point format is chosen for consistency with hexfloat. =E2=
=80=94 end note ]
OR
Just use bin manipulator.
OR
Just not bother with binary floats.
Which??? I'm thinking the last for now.
In the language for:
27.7.3.6.2 Arithmetic inserters [ostream.inserters.arithmetic]
do we need to change fragments
...
baseflags =3D=3D ios_base::oct || baseflags =3D=3D ios_base::hex
...
to
...
baseflags =3D=3D ios_base::oct || baseflags =3D=3D ios_base::hex || basef=
lags =3D=3D=20
ios_base::bin
...
?
27.7.4 Standard manipulators [std.manip]
Add:
setbase(int base);
unspecified
4 Returns: An object of unspeci=EF=AC=81ed type such that if out is an=
object=20
of type basic_ostream<charT,
traits> then the expression out << setbase(base) behaves as if it=20
called f(out, base), or if in is
an object of type basic_istream<charT, traits> then the expression=
=20
in >> setbase(base) behaves
as if it called f(in, base), where the function f is de=EF=AC=81ned =
as:
void f(ios_base& str, int base) {
// set basefield
str.setf(base =3D=3D 2 ? ios_base::bin :
base =3D=3D 8 ? ios_base::oct :
base =3D=3D 10 ? ios_base::dec :
base =3D=3D 16 ? ios_base::hex :
ios_base::fmtflags(0), ios_base::basefield);
}
The expression out << setbase(base) shall have type=20
basic_ostream<charT, traits>& and value
out. The expression in >> setbase(base) shall have type=20
basic_istream<charT, traits>& and
value in.
Is this an interesting and worthy proposal? I would be willing to write it=
=20
up. (I've never none a proposal before.)
--=20
---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/?hl=3Den.
------=_Part_2307_26599404.1366998581419
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Since binary numeric literals have been blessed into C++14 it seems to me t=
hat a small amount of library support in analogy to hex would be useful and=
not too difficult or intrusive. This ould allow people to provide a =
std::bin manipulator to input and output streams and write integers formatt=
ed as, for example, 0b01001.<br><br>Table 85 Integer conversions: add basef=
ield =3D=3D bin<br>Question: What to do about lack of standard stdio equiva=
lent?<br><br>Table 87 Integer conversions: add basefield =3D=3D bin<br>We w=
ant to support both '0b' for !uppercase and '0B' for uppercase.<br>Question=
: What to do about lack of standard stdio equivalent?<br><br>In 27.5.1 Head=
er <ios> synopsis [iostreams.base.overview]<br>Add bin to basefield:<=
br><br>// 27.5.6.3 base=EF=AC=81eld:<br><div class=3D"prettyprint" style=3D=
"background-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); bo=
rder-style: solid; border-width: 1px; word-wrap: break-word;"><code class=
=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;"=
class=3D"styled-by-prettify">ios_base</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> dec </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">ios_base</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> str</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>ios_base</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> hex </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">ios_base</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> str</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>ios_base</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> oct </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">ios_base</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> str</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
>ios_base</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
amp;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> bin &=
nbsp; </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify">ios_base</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> str</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: #800;" class=3D"styled-by-prettify">// <- NEW!!!</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span></=
div></code></div><br><br>27.5.3 Class ios_base [ios.base]<br>// 27.5.3.1.2 =
fmtflags<br><br>class ios_base {<br>...<br><span style=3D"color: rgb(0, 255=
, 0);"> static constexpr fmtflags bin =3D *unspecified*;</span><br>..=
..<br><br><br>Table 122 =E2=80=94 fmtflags e=EF=AC=80ects<br>bin =
converts integer input or generates integer =
output in binary base.<br><br><br>Table 123 =E2=80=94 fmtflags constants<br=
>basefield dec | oct | hex<span style=3D"color: rgb=
(0, 255, 0);"> | bin</span><br><br><br>27.5.6.3 basefield manipulators [bas=
e=EF=AC=81eld.manip]<br>Add:<br> ios_base& bin(ios_base& str)=
;<br>7 E=EF=AC=80ects: Calls str.setf(ios_bas=
e::bin, ios_base::basefield).<br>8 Returns: s=
tr.<br><br><br>Question: We could do binfloat. It might be amusing.&n=
bsp; We could use the bin flag for it instead of copying hexfloat.<br> =
; Or we could punt/de=
fer this.<br><br> ios_base& binfloat(ios_base& str);<br>10 &n=
bsp; E=EF=AC=80ects: Calls str.setf(ios_base::fixed=
| ios_base::scientific, ios_base::floatfield)<br> &=
nbsp; &nbs=
p; .setf(=
ios_base::bin, ios_base::basefield).<br>11 R=
eturns: str.<br>12 [ Note: The more obvious use of ios_base::bin to specify=
binary =EF=AC=82oating-point format is chosen for consistency with hexfloa=
t. =E2=80=94 end note ]<br><br>OR<br><br>Just use bin manipulator.<br=
><br>OR<br><br>Just not bother with binary floats.<br><br>Which??? I'=
m thinking the last for now.<br><br>In the language for:<br><br>27.7.3.6.2 =
Arithmetic inserters [ostream.inserters.arithmetic]<br><br>do we need to ch=
ange fragments<br> ...<br> baseflags =3D=3D ios_base::oct || ba=
seflags =3D=3D ios_base::hex<br> ...<br>
to<br> ...<br>
baseflags =3D=3D ios_base::oct || baseflags =3D=3D ios_base::hex<spa=
n style=3D"color: rgb(0, 255, 0);"> || baseflags =3D=3D ios_base::bin</span=
><br> ...<br>
?<br><br><br>27.7.4 Standard manipulators [std.manip]<br><br>Add:<br> =
&nb=
sp; setbase(int base);<br> unspecified<br>4 &n=
bsp; Returns: An object of unspeci=EF=AC=81ed type such that if=
out is an object of type basic_ostream<charT,<br> &nbs=
p; traits> then the expression out << setbase(base) be=
haves as if it called f(out, base), or if in is<br> =
an object of type basic_istream<charT, traits> then the =
expression in >> setbase(base) behaves<br> &nb=
sp; as if it called f(in, base), where the function f is de=EF=AC=81n=
ed as:<br> void f(ios_base&=
amp; str, int base) {<br> &n=
bsp; // set basefield<br> &n=
bsp; str.setf(<span style=3D"color: rgb(0, 255, 0);=
">base =3D=3D 2 ? ios_base::bin :</span><br> &=
nbsp; base =3D=
=3D 8 ? ios_base::oct :<br> =
base =3D=3D 10 ? ios_base:=
:dec :<br>  =
; base =3D=3D 16 ? ios_base::hex :<br> &=
nbsp; &nbs=
p; ios_base::fmtflags(0), ios_base::basefield);<br> =
}<br> &nb=
sp; The expression out << setbase(base) shall have type basic_ostream=
<charT, traits>& and value<br>  =
; out. The expression in >> setbase(base) shall have type basic_istre=
am<charT, traits>& and<br> va=
lue in.<br><br><br>Is this an interesting and worthy proposal? I woul=
d be willing to write it up. (I've never none a proposal before.)<br>=
<br><br>
<p></p>
-- <br />
<br />
--- <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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
<br />
<br />
------=_Part_2307_26599404.1366998581419--
.
Author: Beman Dawes <bdawes@acm.org>
Date: Fri, 26 Apr 2013 21:26:20 -0400
Raw View
On Fri, Apr 26, 2013 at 1:49 PM, <3dw4rd@verizon.net> wrote:
> Since binary numeric literals have been blessed into C++14 it seems to me
> that a small amount of library support in analogy to hex would be useful and
> not too difficult or intrusive. This ould allow people to provide a
> std::bin manipulator to input and output streams and write integers
> formatted as, for example, 0b01001.
The committee would likely want stronger motivation that just saying
that the proposal would allow doing something.
You might want to look at Lawrence Crowl's paper on digit separators.
He provided compelling examples of code that became much easier to
read with digit separators.
>
> Table 85 Integer conversions: add basefield == bin
> Question: What to do about lack of standard stdio equivalent?
>
> Table 87 Integer conversions: add basefield == bin
> We want to support both '0b' for !uppercase and '0B' for uppercase.
> Question: What to do about lack of standard stdio equivalent?
Those are questions that would be worked out in conjunction with the C
committee. You don't have to worry about that - there are liaison
people who will take whatever is proposed for C++ and coordinate with
the C committee.
>
> dec | oct | hex | bin details
>
Details elided. There are only a few people who understand the
implications of changes to iostreams and I'm not one of them. They are
mostly implementers who understand the internals.
> Is this an interesting and worthy proposal?
Seems worthwhile to me:-)
> I would be willing to write it
> up. (I've never none a proposal before.)
This is probably a nice one to start with - worth doing, but not overly complex.
--Beman
--
---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en.
.