Topic: Constructing a Bad Stream
Author: Adi Shavit <adishavit@gmail.com>
Date: Thu, 26 Jan 2017 12:09:43 -0800 (PST)
Raw View
------=_Part_491_1540744972.1485461383439
Content-Type: multipart/alternative;
boundary="----=_Part_492_448142833.1485461383440"
------=_Part_492_448142833.1485461383440
Content-Type: text/plain; charset=UTF-8
Hi,
In a recent blog post
<https://adishavit.github.io/2017/Istream-Idiosyncrasies/> I noted that
there is no way to construct a bad (or !good()) std::istringstream.
This is too bad because, as I show in the blog post, it creates a missed
copy elision or RVO opportunity.
Briefly, we cannot do this:
std::istringstream bad_stream(){
return std::istringstream(std::ios_base::failbit); // ERROR: No such ctor
}
but must do this:
std::istringstream bad_stream(){
std::istringstream bad; // create a named local variable
bad.setstate(std::ios_base::failbit); // change state
return bad; }
In the current standard, we must hope that the (optional) NRVO kicks in,
instead of the mandatory RVO and/or copy-elision in the proposed first
example.
Also, it is good practice to always be striving for the least amount of
mutable state (variables) in our code.
Using a single line at the point of return (or maybe even: return {std::
ios_base::failbit}; ) is much cleaner than remembering to set the state of
a local or calling a helper function like bad_stream() above.
As an interesting side note, the use case I present there treats
std::istringstream as a Maybe or an optional that can be tested for
validity at the point of use (just like optional).
Unlike Maybe or std::optional, there is no way to construct an
invalid/bad/!good stream.
At its simplest, I would imagine a std::istringstream ctor accepting a
std::ios_base::iostate just like std::basic_ios::setstate().
Some outstanding questions:
1. Since setstate() is a method of std::basic_ios, should this ctor be
given to other derived classes like basic_ostream, basic_istream and
their descendants?
2. If so which ones? All?
3. What about std::basic_ios itself? Should it have such a (protected)
ctor too? Seems to me it should.
Patrice Roy suggested that I make a small proposal to add such a ctor and
I'd like to gauge your thoughts about the subject.
I am no big iostream expert, so be gentle. :-)
Warm regards,
Adi
--
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/f59c568b-544c-473a-a9c6-8001c0658f5f%40isocpp.org.
------=_Part_492_448142833.1485461383440
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hi,<div><br></div><div>=C2=A0 In <a href=3D"https://adisha=
vit.github.io/2017/Istream-Idiosyncrasies/">a recent blog post</a> I noted =
that there is no way to construct a bad (or !good())=C2=A0<font face=3D"cou=
rier new, monospace">std::istringstream</font>.</div><div>This is too bad b=
ecause, as I show in the blog post, it creates a missed copy elision or RVO=
opportunity.</div><div><br></div><div>Bri<font size=3D"2">efly, we cannot =
do this:</font></div><div><font size=3D"2"><br></font></div><div><pre class=
=3D"highlight" style=3D"padding: 10px; font-variant-numeric: inherit; font-=
stretch: inherit; line-height: 1.3em; font-family: Consolas, Menlo, Monaco,=
"Lucida Console", "Liberation Mono", "DejaVu Sans=
Mono", "Bitstream Vera Sans Mono", "Courier New",=
monospace, serif; vertical-align: baseline; border-radius: 3px; background=
: rgb(63, 63, 63); color: rgb(235, 219, 178); width: 729.618px;"><code styl=
e=3D"border-width: initial; border-style: none; font-style: inherit; font-v=
ariant: inherit; font-weight: inherit; font-stretch: inherit; line-height: =
inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", =
"Liberation Mono", "DejaVu Sans Mono", "Bitstream =
Vera Sans Mono", "Courier New", monospace, serif; vertical-a=
lign: baseline; background: none; border-radius: 3px; white-space: pre-wrap=
;"><font size=3D"2"><span class=3D"n" style=3D"font-style: inherit; font-va=
riant: inherit; font-weight: inherit; font-stretch: inherit; line-height: i=
nherit; font-family: inherit; vertical-align: baseline; color: rgb(220, 220=
, 204);">std</span><span class=3D"o" style=3D"font-style: inherit; font-var=
iant: inherit; font-weight: inherit; font-stretch: inherit; line-height: in=
herit; font-family: inherit; vertical-align: baseline; color: rgb(240, 239,=
208);">::</span><span class=3D"n" style=3D"font-style: inherit; font-varia=
nt: inherit; font-weight: inherit; font-stretch: inherit; line-height: inhe=
rit; font-family: inherit; vertical-align: baseline; color: rgb(220, 220, 2=
04);">istringstream</span> <span class=3D"n" style=3D"font-style: inherit; =
font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-he=
ight: inherit; font-family: inherit; vertical-align: baseline; color: rgb(2=
20, 220, 204);">bad_stream</span><span class=3D"p" style=3D"font-style: inh=
erit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; l=
ine-height: inherit; font-family: inherit; vertical-align: baseline; color:=
rgb(220, 220, 204);">()</span>
<span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">{</span>
<span class=3D"k" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(240, 223, 175);">return</=
span> std<span class=3D"o" style=3D"background-color: initial; font-family:=
inherit; font-style: inherit; font-variant: inherit; font-weight: inherit;=
font-stretch: inherit; line-height: inherit; vertical-align: baseline; col=
or: rgb(240, 239, 208);">::</span><span class=3D"n" style=3D"background-col=
or: initial; font-family: inherit; font-style: inherit; font-variant: inher=
it; font-weight: inherit; font-stretch: inherit; line-height: inherit; vert=
ical-align: baseline; color: rgb(220, 220, 204);">istringstream</span><span=
style=3D"background-color: initial; font-style: inherit; font-variant-liga=
tures: inherit; font-variant-caps: inherit; font-weight: inherit;">(</span>=
<span class=3D"n" style=3D"background-color: initial; font-family: inherit;=
font-style: inherit; font-variant: inherit; font-weight: inherit; font-str=
etch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(2=
20, 220, 204);">std</span><span class=3D"o" style=3D"background-color: init=
ial; font-family: inherit; font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; vertical-ali=
gn: baseline; color: rgb(240, 239, 208);">::</span><span class=3D"n" style=
=3D"background-color: initial; font-family: inherit; font-style: inherit; f=
ont-variant: inherit; font-weight: inherit; font-stretch: inherit; line-hei=
ght: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">ios_bas=
e</span><span class=3D"o" style=3D"background-color: initial; font-family: =
inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; =
font-stretch: inherit; line-height: inherit; vertical-align: baseline; colo=
r: rgb(240, 239, 208);">::</span><span class=3D"n" style=3D"background-colo=
r: initial; font-family: inherit; font-style: inherit; font-variant: inheri=
t; font-weight: inherit; font-stretch: inherit; line-height: inherit; verti=
cal-align: baseline; color: rgb(220, 220, 204);">failbit</span><span class=
=3D"p" style=3D"background-color: initial; font-family: inherit; font-style=
: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inher=
it; line-height: inherit; vertical-align: baseline; color: rgb(220, 220, 20=
4);">)</span>;<span style=3D"background-color: initial; font-style: inherit=
; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight:=
inherit;"> // ERROR: No such ctor</span><br><span class=3D"p" style=3D"fo=
nt-style: inherit; font-variant: inherit; font-weight: inherit; font-stretc=
h: inherit; line-height: inherit; font-family: inherit; vertical-align: bas=
eline; color: rgb(220, 220, 204);">}</span></font></code></pre></div><div><=
font size=3D"2"><br></font></div><div><font size=3D"2">but must do this:</f=
ont></div><div><font size=3D"2"><br></font></div><div><pre class=3D"highlig=
ht" style=3D"padding: 10px; font-variant-numeric: inherit; font-stretch: in=
herit; line-height: 1.3em; font-family: Consolas, Menlo, Monaco, "Luci=
da Console", "Liberation Mono", "DejaVu Sans Mono"=
, "Bitstream Vera Sans Mono", "Courier New", monospace,=
serif; vertical-align: baseline; border-radius: 3px; background: rgb(63, 6=
3, 63); color: rgb(235, 219, 178); width: 729.618px;"><code style=3D"border=
-width: initial; border-style: none; font-style: inherit; font-variant: inh=
erit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fo=
nt-family: Consolas, Menlo, Monaco, "Lucida Console", "Liber=
ation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans M=
ono", "Courier New", monospace, serif; vertical-align: basel=
ine; background: none; border-radius: 3px; white-space: pre-wrap;"><font si=
ze=3D"2"><span class=3D"n" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">st=
d</span><span class=3D"o" style=3D"font-style: inherit; font-variant: inher=
it; font-weight: inherit; font-stretch: inherit; line-height: inherit; font=
-family: inherit; vertical-align: baseline; color: rgb(240, 239, 208);">::<=
/span><span class=3D"n" style=3D"font-style: inherit; font-variant: inherit=
; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-f=
amily: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">istri=
ngstream</span> <span class=3D"n" style=3D"font-style: inherit; font-varian=
t: inherit; font-weight: inherit; font-stretch: inherit; line-height: inher=
it; font-family: inherit; vertical-align: baseline; color: rgb(220, 220, 20=
4);">bad_stream</span><span class=3D"p" style=3D"font-style: inherit; font-=
variant: inherit; font-weight: inherit; font-stretch: inherit; line-height:=
inherit; font-family: inherit; vertical-align: baseline; color: rgb(220, 2=
20, 204);">()</span>
<span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">{</span>
<span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">std</spa=
n><span class=3D"o" style=3D"font-style: inherit; font-variant: inherit; fo=
nt-weight: inherit; font-stretch: inherit; line-height: inherit; font-famil=
y: inherit; vertical-align: baseline; color: rgb(240, 239, 208);">::</span>=
<span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">istringstre=
am</span> <span class=3D"n" style=3D"font-style: inherit; font-variant: inh=
erit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fo=
nt-family: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">b=
ad</span><span class=3D"p" style=3D"font-style: inherit; font-variant: inhe=
rit; font-weight: inherit; font-stretch: inherit; line-height: inherit; fon=
t-family: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">;<=
/span> // create a named local variable
<span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">bad</spa=
n><span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; fo=
nt-weight: inherit; font-stretch: inherit; line-height: inherit; font-famil=
y: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">.</span><=
span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; font-=
weight: inherit; font-stretch: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">setstate</sp=
an><span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">(</span>=
<span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">std</span><=
span class=3D"o" style=3D"font-style: inherit; font-variant: inherit; font-=
weight: inherit; font-stretch: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; color: rgb(240, 239, 208);">::</span><sp=
an class=3D"n" style=3D"font-style: inherit; font-variant: inherit; font-we=
ight: inherit; font-stretch: inherit; line-height: inherit; font-family: in=
herit; vertical-align: baseline; color: rgb(220, 220, 204);">ios_base</span=
><span class=3D"o" style=3D"font-style: inherit; font-variant: inherit; fon=
t-weight: inherit; font-stretch: inherit; line-height: inherit; font-family=
: inherit; vertical-align: baseline; color: rgb(240, 239, 208);">::</span><=
span class=3D"n" style=3D"font-style: inherit; font-variant: inherit; font-=
weight: inherit; font-stretch: inherit; line-height: inherit; font-family: =
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">failbit</spa=
n><span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; fo=
nt-weight: inherit; font-stretch: inherit; line-height: inherit; font-famil=
y: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">); // ch=
ange state</span>
<span class=3D"k" style=3D"font-style: inherit; font-variant: inherit; f=
ont-weight: inherit; font-stretch: inherit; line-height: inherit; font-fami=
ly: inherit; vertical-align: baseline; color: rgb(240, 223, 175);">return</=
span> <span class=3D"n" style=3D"font-style: inherit; font-variant: inherit=
; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-f=
amily: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">bad</=
span><span class=3D"p" style=3D"font-style: inherit; font-variant: inherit;=
font-weight: inherit; font-stretch: inherit; line-height: inherit; font-fa=
mily: inherit; vertical-align: baseline; color: rgb(220, 220, 204);">;</spa=
n> =20
<span class=3D"p" style=3D"font-style: inherit; font-variant: inherit; font=
-weight: inherit; font-stretch: inherit; line-height: inherit; font-family:=
inherit; vertical-align: baseline; color: rgb(220, 220, 204);">}</span></f=
ont></code></pre></div><div><font size=3D"2"><br></font></div><div><font si=
ze=3D"2">In </font>the current standard, we must hope that the (optional) N=
RVO kicks in, instead of the mandatory RVO and/or copy-elision in the propo=
sed first example.<br></div><div><br></div><div>Also, it is good practice t=
o always be striving for the least amount of mutable state (variables) in o=
ur code.=C2=A0</div><div>Using a single line at the point of return (or may=
be even:=C2=A0<font face=3D"courier new, monospace" color=3D"#000000">retur=
n {<span class=3D"n" style=3D"font-size: small; background-color: initial; =
font-style: inherit; font-variant: inherit; font-weight: inherit; white-spa=
ce: pre-wrap; font-stretch: inherit; line-height: inherit; vertical-align: =
baseline;">std</span><span class=3D"o" style=3D"font-size: small; backgroun=
d-color: initial; font-style: inherit; font-variant: inherit; font-weight: =
inherit; white-space: pre-wrap; font-stretch: inherit; line-height: inherit=
; vertical-align: baseline;">::</span><span class=3D"n" style=3D"font-size:=
small; background-color: initial; font-style: inherit; font-variant: inher=
it; font-weight: inherit; white-space: pre-wrap; font-stretch: inherit; lin=
e-height: inherit; vertical-align: baseline;">ios_base</span><span class=3D=
"o" style=3D"font-size: small; background-color: initial; font-style: inher=
it; font-variant: inherit; font-weight: inherit; white-space: pre-wrap; fon=
t-stretch: inherit; line-height: inherit; vertical-align: baseline;">::</sp=
an><span class=3D"n" style=3D"font-size: small; background-color: initial; =
font-style: inherit; font-variant: inherit; font-weight: inherit; white-spa=
ce: pre-wrap; font-stretch: inherit; line-height: inherit; vertical-align: =
baseline;">failbit}; </span></font>) is much cleaner than remembering to se=
t the state of a local or calling a helper function like <font face=3D"cour=
ier new, monospace">bad_stream()</font> above.</div><div><br></div><div>As =
an interesting side note, the use case I present there treats=C2=A0<font fa=
ce=3D"courier new, monospace">std::istringstream</font>=C2=A0as a Maybe or =
an optional that can be tested for validity at the point of use (just like =
optional).</div><div>Unlike Maybe or <font face=3D"courier new, monospace">=
std::optional</font>, there is no way to construct an invalid/bad/!good str=
eam.</div><div><br></div><div>At its simplest, I would imagine a=C2=A0<font=
face=3D"courier new, monospace">std::istringstream</font>=C2=A0ctor accept=
ing a <font face=3D"courier new, monospace">std::ios_base::iostate</font> j=
ust like <font face=3D"courier new, monospace">std::basic_ios::setstate()</=
font>.<br></div><div><br></div><div>Some outstanding questions:</div><div><=
ol><li>Since <font face=3D"courier new, monospace">setstate()</font> is a m=
ethod of <font face=3D"courier new, monospace">std::basic_ios</font>, shoul=
d this ctor be given to other derived classes like <font face=3D"courier ne=
w, monospace">basic_ostream</font>, <font face=3D"courier new, monospace">b=
asic_istream </font>and their descendants?=C2=A0<br></li><li>If so which on=
es? All?</li><li>What about=C2=A0<font face=3D"courier new, monospace">std:=
:basic_ios</font>=C2=A0itself?=C2=A0Should it have such a (protected) ctor =
too? Seems to me it should.</li></ol><div><div>Patrice Roy suggested that I=
make a small proposal to add such a ctor and I'd like to gauge your th=
oughts about the subject.</div></div></div><div>I am no big iostream expert=
, so be gentle. :-)</div><div><br></div><div>Warm regards,<br>Adi</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/f59c568b-544c-473a-a9c6-8001c0658f5f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/f59c568b-544c-473a-a9c6-8001c0658f5f=
%40isocpp.org</a>.<br />
------=_Part_492_448142833.1485461383440--
------=_Part_491_1540744972.1485461383439--
.
Author: Patrice Roy <patricer@gmail.com>
Date: Thu, 26 Jan 2017 15:55:13 -0500
Raw View
--f40304361d8ad7ff4f05470590f5
Content-Type: text/plain; charset=UTF-8
I confirm that I suggested Adi write a proposal for this. It seems like a
useful feature to have, and I must admit I was surprised to realize we
don't have it yet, but there might be other ways to acheive this I haven't
thought of (feel free to tell me if such is the case).
Cheers!
2017-01-26 15:09 GMT-05:00 Adi Shavit <adishavit@gmail.com>:
> Hi,
>
> In a recent blog post
> <https://adishavit.github.io/2017/Istream-Idiosyncrasies/> I noted that
> there is no way to construct a bad (or !good()) std::istringstream.
> This is too bad because, as I show in the blog post, it creates a missed
> copy elision or RVO opportunity.
>
> Briefly, we cannot do this:
>
> std::istringstream bad_stream(){
> return std::istringstream(std::ios_base::failbit); // ERROR: No such ctor
> }
>
>
> but must do this:
>
> std::istringstream bad_stream(){
> std::istringstream bad; // create a named local variable
> bad.setstate(std::ios_base::failbit); // change state
> return bad; }
>
>
> In the current standard, we must hope that the (optional) NRVO kicks in,
> instead of the mandatory RVO and/or copy-elision in the proposed first
> example.
>
> Also, it is good practice to always be striving for the least amount of
> mutable state (variables) in our code.
> Using a single line at the point of return (or maybe even: return {std::
> ios_base::failbit}; ) is much cleaner than remembering to set the state
> of a local or calling a helper function like bad_stream() above.
>
> As an interesting side note, the use case I present there treats
> std::istringstream as a Maybe or an optional that can be tested for
> validity at the point of use (just like optional).
> Unlike Maybe or std::optional, there is no way to construct an
> invalid/bad/!good stream.
>
> At its simplest, I would imagine a std::istringstream ctor accepting a
> std::ios_base::iostate just like std::basic_ios::setstate().
>
> Some outstanding questions:
>
> 1. Since setstate() is a method of std::basic_ios, should this ctor be
> given to other derived classes like basic_ostream, basic_istream and
> their descendants?
> 2. If so which ones? All?
> 3. What about std::basic_ios itself? Should it have such a (protected)
> ctor too? Seems to me it should.
>
> Patrice Roy suggested that I make a small proposal to add such a ctor and
> I'd like to gauge your thoughts about the subject.
> I am no big iostream expert, so be gentle. :-)
>
> Warm regards,
> Adi
>
> --
> 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/f59c568b-544c-473a-
> a9c6-8001c0658f5f%40isocpp.org
> <https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f59c568b-544c-473a-a9c6-8001c0658f5f%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/CAKiZDp1kfhzTJ_6FRTqa360Cq5bpBmZ-eNU9ok4nDsseCB2FZA%40mail.gmail.com.
--f40304361d8ad7ff4f05470590f5
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I confirm that I suggested Adi write a proposal for t=
his. It seems like a useful feature to have, and I must admit I was surpris=
ed to realize we don't have it yet, but there might be other ways to ac=
heive this I haven't thought of (feel free to tell me if such is the ca=
se).<br><br></div>Cheers!<br></div><div class=3D"gmail_extra"><br><div clas=
s=3D"gmail_quote">2017-01-26 15:09 GMT-05:00 Adi Shavit <span dir=3D"ltr">&=
lt;<a href=3D"mailto:adishavit@gmail.com" target=3D"_blank">adishavit@gmail=
..com</a>></span>:<br><blockquote class=3D"gmail_quote" style=3D"margin:0=
0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">Hi,=
<div><br></div><div>=C2=A0 In <a href=3D"https://adishavit.github.io/2017/I=
stream-Idiosyncrasies/" target=3D"_blank">a recent blog post</a> I noted th=
at there is no way to construct a bad (or !good())=C2=A0<font face=3D"couri=
er new, monospace">std::istringstream</font>.</div><div>This is too bad bec=
ause, as I show in the blog post, it creates a missed copy elision or RVO o=
pportunity.</div><div><br></div><div>Bri<font size=3D"2">efly, we cannot do=
this:</font></div><div><font size=3D"2"><br></font></div><div><pre class=
=3D"m_2567301285593658705highlight" style=3D"padding:10px;font-variant-nume=
ric:inherit;font-stretch:inherit;line-height:1.3em;font-family:Consolas,Men=
lo,Monaco,"Lucida Console","Liberation Mono","Deja=
Vu Sans Mono","Bitstream Vera Sans Mono","Courier New&q=
uot;,monospace,serif;vertical-align:baseline;border-radius:3px;background:r=
gb(63,63,63);color:rgb(235,219,178);width:729.618px"><code style=3D"border-=
width:initial;border-style:none;font-style:inherit;font-variant:inherit;fon=
t-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:Conso=
las,Menlo,Monaco,"Lucida Console","Liberation Mono",&qu=
ot;DejaVu Sans Mono","Bitstream Vera Sans Mono","Courie=
r New",monospace,serif;vertical-align:baseline;background:none;border-=
radius:3px;white-space:pre-wrap"><font size=3D"2"><span class=3D"m_25673012=
85593658705n" style=3D"font-style:inherit;font-variant:inherit;font-weight:=
inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vertic=
al-align:baseline;color:rgb(220,220,204)">std</span><span class=3D"m_256730=
1285593658705o" style=3D"font-style:inherit;font-variant:inherit;font-weigh=
t:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vert=
ical-align:baseline;color:rgb(240,239,208)">::</span><span class=3D"m_25673=
01285593658705n" style=3D"font-style:inherit;font-variant:inherit;font-weig=
ht:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;ver=
tical-align:baseline;color:rgb(220,220,204)">istringstream</span> <span cla=
ss=3D"m_2567301285593658705n" style=3D"font-style:inherit;font-variant:inhe=
rit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-famil=
y:inherit;vertical-align:baseline;color:rgb(220,220,204)">bad_stream</span>=
<span class=3D"m_2567301285593658705p" style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;f=
ont-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">()</span=
>
<span class=3D"m_2567301285593658705p" style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;f=
ont-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">{</span>
<span class=3D"m_2567301285593658705k" style=3D"font-style:inherit;font-=
variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inheri=
t;font-family:inherit;vertical-align:baseline;color:rgb(240,223,175)">retur=
n</span> std<span class=3D"m_2567301285593658705o" style=3D"background-colo=
r:initial;font-family:inherit;font-style:inherit;font-variant:inherit;font-=
weight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:base=
line;color:rgb(240,239,208)">::</span><span class=3D"m_2567301285593658705n=
" style=3D"background-color:initial;font-family:inherit;font-style:inherit;=
font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:i=
nherit;vertical-align:baseline;color:rgb(220,220,204)">istringstream</span>=
<span style=3D"background-color:initial;font-style:inherit;font-variant-lig=
atures:inherit;font-variant-caps:inherit;font-weight:inherit">(</span><span=
class=3D"m_2567301285593658705n" style=3D"background-color:initial;font-fa=
mily:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;vertical-align:baseline;color:rgb(22=
0,220,204)">std</span><span class=3D"m_2567301285593658705o" style=3D"backg=
round-color:initial;font-family:inherit;font-style:inherit;font-variant:inh=
erit;font-weight:inherit;font-stretch:inherit;line-height:inherit;vertical-=
align:baseline;color:rgb(240,239,208)">::</span><span class=3D"m_2567301285=
593658705n" style=3D"background-color:initial;font-family:inherit;font-styl=
e:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;lin=
e-height:inherit;vertical-align:baseline;color:rgb(220,220,204)">ios_<wbr>b=
ase</span><span class=3D"m_2567301285593658705o" style=3D"background-color:=
initial;font-family:inherit;font-style:inherit;font-variant:inherit;font-we=
ight:inherit;font-stretch:inherit;line-height:inherit;vertical-align:baseli=
ne;color:rgb(240,239,208)">::</span><span class=3D"m_2567301285593658705n" =
style=3D"background-color:initial;font-family:inherit;font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;vertical-align:baseline;color:rgb(220,220,204)">failbit</span><span cl=
ass=3D"m_2567301285593658705p" style=3D"background-color:initial;font-famil=
y:inherit;font-style:inherit;font-variant:inherit;font-weight:inherit;font-=
stretch:inherit;line-height:inherit;vertical-align:baseline;color:rgb(220,2=
20,204)">)</span>;<span style=3D"background-color:initial;font-style:inheri=
t;font-variant-ligatures:inherit;font-variant-caps:inherit;font-weight:inhe=
rit"> // ERROR: No such ctor</span><br><span class=3D"m_256730128559365870=
5p" style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fo=
nt-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:b=
aseline;color:rgb(220,220,204)">}</span></font></code></pre></div><div><fon=
t size=3D"2"><br></font></div><div><font size=3D"2">but must do this:</font=
></div><div><font size=3D"2"><br></font></div><div><pre class=3D"m_25673012=
85593658705highlight" style=3D"padding:10px;font-variant-numeric:inherit;fo=
nt-stretch:inherit;line-height:1.3em;font-family:Consolas,Menlo,Monaco,&quo=
t;Lucida Console","Liberation Mono","DejaVu Sans Mono&q=
uot;,"Bitstream Vera Sans Mono","Courier New",monospace=
,serif;vertical-align:baseline;border-radius:3px;background:rgb(63,63,63);c=
olor:rgb(235,219,178);width:729.618px"><code style=3D"border-width:initial;=
border-style:none;font-style:inherit;font-variant:inherit;font-weight:inher=
it;font-stretch:inherit;line-height:inherit;font-family:Consolas,Menlo,Mona=
co,"Lucida Console","Liberation Mono","DejaVu Sans=
Mono","Bitstream Vera Sans Mono","Courier New",mo=
nospace,serif;vertical-align:baseline;background:none;border-radius:3px;whi=
te-space:pre-wrap"><font size=3D"2"><span class=3D"m_2567301285593658705n" =
style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-s=
tretch:inherit;line-height:inherit;font-family:inherit;vertical-align:basel=
ine;color:rgb(220,220,204)">std</span><span class=3D"m_2567301285593658705o=
" style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font=
-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:bas=
eline;color:rgb(240,239,208)">::</span><span class=3D"m_2567301285593658705=
n" style=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;fon=
t-stretch:inherit;line-height:inherit;font-family:inherit;vertical-align:ba=
seline;color:rgb(220,220,204)">istringstream</span> <span class=3D"m_256730=
1285593658705n" style=3D"font-style:inherit;font-variant:inherit;font-weigh=
t:inherit;font-stretch:inherit;line-height:inherit;font-family:inherit;vert=
ical-align:baseline;color:rgb(220,220,204)">bad_stream</span><span class=3D=
"m_2567301285593658705p" style=3D"font-style:inherit;font-variant:inherit;f=
ont-weight:inherit;font-stretch:inherit;line-height:inherit;font-family:inh=
erit;vertical-align:baseline;color:rgb(220,220,204)">()</span>
<span class=3D"m_2567301285593658705p" style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;f=
ont-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">{</span>
<span class=3D"m_2567301285593658705n" style=3D"font-style:inherit;font-=
variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inheri=
t;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">std</=
span><span class=3D"m_2567301285593658705o" style=3D"font-style:inherit;fon=
t-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inhe=
rit;font-family:inherit;vertical-align:baseline;color:rgb(240,239,208)">::<=
/span><span class=3D"m_2567301285593658705n" style=3D"font-style:inherit;fo=
nt-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inh=
erit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">is=
tringstream</span> <span class=3D"m_2567301285593658705n" style=3D"font-sty=
le:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;li=
ne-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(220=
,220,204)">bad</span><span class=3D"m_2567301285593658705p" style=3D"font-s=
tyle:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;=
line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(2=
20,220,204)">;</span> // create a named local variable
<span class=3D"m_2567301285593658705n" style=3D"font-style:inherit;font-=
variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inheri=
t;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">bad</=
span><span class=3D"m_2567301285593658705p" style=3D"font-style:inherit;fon=
t-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inhe=
rit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">.</=
span><span class=3D"m_2567301285593658705n" style=3D"font-style:inherit;fon=
t-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inhe=
rit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">set=
state</span><span class=3D"m_2567301285593658705p" style=3D"font-style:inhe=
rit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heig=
ht:inherit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,20=
4)">(</span><span class=3D"m_2567301285593658705n" style=3D"font-style:inhe=
rit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heig=
ht:inherit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,20=
4)">std</span><span class=3D"m_2567301285593658705o" style=3D"font-style:in=
herit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-he=
ight:inherit;font-family:inherit;vertical-align:baseline;color:rgb(240,239,=
208)">::</span><span class=3D"m_2567301285593658705n" style=3D"font-style:i=
nherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-h=
eight:inherit;font-family:inherit;vertical-align:baseline;color:rgb(220,220=
,204)">ios_base</span><span class=3D"m_2567301285593658705o" style=3D"font-=
style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit=
;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb(=
240,239,208)">::</span><span class=3D"m_2567301285593658705n" style=3D"font=
-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inheri=
t;line-height:inherit;font-family:inherit;vertical-align:baseline;color:rgb=
(220,220,204)">fa<wbr>ilbit</span><span class=3D"m_2567301285593658705p" st=
yle=3D"font-style:inherit;font-variant:inherit;font-weight:inherit;font-str=
etch:inherit;line-height:inherit;font-family:inherit;vertical-align:baselin=
e;color:rgb(220,220,204)">); // change state</span>
<span class=3D"m_2567301285593658705k" style=3D"font-style:inherit;font-=
variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inheri=
t;font-family:inherit;vertical-align:baseline;color:rgb(240,223,175)">retur=
n</span> <span class=3D"m_2567301285593658705n" style=3D"font-style:inherit=
;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:=
inherit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204)"=
>bad</span><span class=3D"m_2567301285593658705p" style=3D"font-style:inher=
it;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-heigh=
t:inherit;font-family:inherit;vertical-align:baseline;color:rgb(220,220,204=
)">;</span> =20
<span class=3D"m_2567301285593658705p" style=3D"font-style:inherit;font-var=
iant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;f=
ont-family:inherit;vertical-align:baseline;color:rgb(220,220,204)">}</span>=
</font></code></pre></div><div><font size=3D"2"><br></font></div><div><font=
size=3D"2">In </font>the current standard, we must hope that the (optional=
) NRVO kicks in, instead of the mandatory RVO and/or copy-elision in the pr=
oposed first example.<br></div><div><br></div><div>Also, it is good practic=
e to always be striving for the least amount of mutable state (variables) i=
n our code.=C2=A0</div><div>Using a single line at the point of return (or =
maybe even:=C2=A0<font color=3D"#000000" face=3D"courier new, monospace">re=
turn {<span class=3D"m_2567301285593658705n" style=3D"font-size:small;backg=
round-color:initial;font-style:inherit;font-variant:inherit;font-weight:inh=
erit;white-space:pre-wrap;font-stretch:inherit;line-height:inherit;vertical=
-align:baseline">std</span><span class=3D"m_2567301285593658705o" style=3D"=
font-size:small;background-color:initial;font-style:inherit;font-variant:in=
herit;font-weight:inherit;white-space:pre-wrap;font-stretch:inherit;line-he=
ight:inherit;vertical-align:baseline">::</span><span class=3D"m_25673012855=
93658705n" style=3D"font-size:small;background-color:initial;font-style:inh=
erit;font-variant:inherit;font-weight:inherit;white-space:pre-wrap;font-str=
etch:inherit;line-height:inherit;vertical-align:baseline">ios_base</span><s=
pan class=3D"m_2567301285593658705o" style=3D"font-size:small;background-co=
lor:initial;font-style:inherit;font-variant:inherit;font-weight:inherit;whi=
te-space:pre-wrap;font-stretch:inherit;line-height:inherit;vertical-align:b=
aseline">::</span><span class=3D"m_2567301285593658705n" style=3D"font-size=
:small;background-color:initial;font-style:inherit;font-variant:inherit;fon=
t-weight:inherit;white-space:pre-wrap;font-stretch:inherit;line-height:inhe=
rit;vertical-align:baseline">failbit}; </span></font>) is much cleaner than=
remembering to set the state of a local or calling a helper function like =
<font face=3D"courier new, monospace">bad_stream()</font> above.</div><div>=
<br></div><div>As an interesting side note, the use case I present there tr=
eats=C2=A0<font face=3D"courier new, monospace">std::istringstream</font>=
=C2=A0as a Maybe or an optional that can be tested for validity at the poin=
t of use (just like optional).</div><div>Unlike Maybe or <font face=3D"cour=
ier new, monospace">std::optional</font>, there is no way to construct an i=
nvalid/bad/!good stream.</div><div><br></div><div>At its simplest, I would =
imagine a=C2=A0<font face=3D"courier new, monospace">std::istringstream</fo=
nt>=C2=A0ctor accepting a <font face=3D"courier new, monospace">std::ios_ba=
se::iostate</font> just like <font face=3D"courier new, monospace">std::bas=
ic_ios::setstate()</font>.<br></div><div><br></div><div>Some outstanding qu=
estions:</div><div><ol><li>Since <font face=3D"courier new, monospace">sets=
tate()</font> is a method of <font face=3D"courier new, monospace">std::bas=
ic_ios</font>, should this ctor be given to other derived classes like <fon=
t face=3D"courier new, monospace">basic_ostream</font>, <font face=3D"couri=
er new, monospace">basic_istream </font>and their descendants?=C2=A0<br></l=
i><li>If so which ones? All?</li><li>What about=C2=A0<font face=3D"courier =
new, monospace">std::basic_ios</font>=C2=A0itself?=C2=A0<wbr>Should it have=
such a (protected) ctor too? Seems to me it should.</li></ol><div><div>Pat=
rice Roy suggested that I make a small proposal to add such a ctor and I=
9;d like to gauge your thoughts about the subject.</div></div></div><div>I =
am no big iostream expert, so be gentle. :-)</div><div><br></div><div>Warm =
regards,<br>Adi</div><span class=3D"HOEnZb"><font color=3D"#888888"><div><b=
r></div></font></span></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" 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/f59c568b-544c-473a-a9c6-8001c0658f5f%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter" target=3D"_blank">=
https://groups.google.com/a/<wbr>isocpp.org/d/msgid/std-<wbr>proposals/f59c=
568b-544c-473a-<wbr>a9c6-8001c0658f5f%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" 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/CAKiZDp1kfhzTJ_6FRTqa360Cq5bpBmZ-eNU9=
ok4nDsseCB2FZA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAKiZDp1kfhzTJ_6F=
RTqa360Cq5bpBmZ-eNU9ok4nDsseCB2FZA%40mail.gmail.com</a>.<br />
--f40304361d8ad7ff4f05470590f5--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Thu, 26 Jan 2017 12:57:44 -0800 (PST)
Raw View
------=_Part_531_906522159.1485464264169
Content-Type: multipart/alternative;
boundary="----=_Part_532_2015463668.1485464264169"
------=_Part_532_2015463668.1485464264169
Content-Type: text/plain; charset=UTF-8
On Thursday, January 26, 2017 at 3:09:43 PM UTC-5, Adi Shavit wrote:
>
> Hi,
>
> In a recent blog post
> <https://adishavit.github.io/2017/Istream-Idiosyncrasies/> I noted that
> there is no way to construct a bad (or !good()) std::istringstream.
>
A better question is this: why would you want to?
Logically, `istringstream`s should always be either good or eof, never bad
or fail. The only reason you can make it bad is because it has the
`setstate` member was publicly inherited. A better interface for string
streams would not have such a function.
Setting this state is not a thing we should encourage people to do, and
giving the object a constructor encourages exactly that.
As an interesting side note, the use case I present there treats
> std::istringstream as a Maybe or an optional that can be tested for
> validity at the point of use (just like optional).
>
Which would be more reasonably handled through a `std::optional` type,
rather than making it based on stringstream state that's not reasonable for
that type.
--
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/aabcfa51-687f-4dad-a53f-e0dec8d077ee%40isocpp.org.
------=_Part_532_2015463668.1485464264169
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">On Thursday, January 26, 2017 at 3:09:43 PM UTC-5, Adi Sha=
vit wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left:=
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Hi,=
<div><br></div><div>=C2=A0 In <a href=3D"https://adishavit.github.io/2017/I=
stream-Idiosyncrasies/" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"t=
his.href=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fadishavit.git=
hub.io%2F2017%2FIstream-Idiosyncrasies%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3=
dAFQjCNH0MvUvXmnRkP7LwAW2KGxH4O__-w';return true;" onclick=3D"this.href=
=3D'https://www.google.com/url?q\x3dhttps%3A%2F%2Fadishavit.github.io%2=
F2017%2FIstream-Idiosyncrasies%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH=
0MvUvXmnRkP7LwAW2KGxH4O__-w';return true;">a recent blog post</a> I not=
ed that there is no way to construct a bad (or !good())=C2=A0<font face=3D"=
courier new, monospace">std::istringstream</font>.</div><div></div></div></=
blockquote><div><br>A better question is this: why would you want to?<br><b=
r>Logically, `istringstream`s should always be either good or eof, never ba=
d or fail. The only reason you can make it bad is because it has the `setst=
ate` member was publicly inherited. A better interface for string streams w=
ould not have such a function.<br><br>Setting this state is not a thing we =
should encourage people to do, and giving the object a constructor encourag=
es exactly that.<br><br></div><blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"ltr"><div></div><div>As an interesting side note, the use case =
I present there treats=C2=A0<font face=3D"courier new, monospace">std::istr=
ingstream</font>=C2=A0as a Maybe or an optional that can be tested for vali=
dity at the point of use (just like optional).</div></div></blockquote><div=
><br>Which would be more reasonably handled through a `std::optional` type,=
rather than making it based on stringstream state that's not reasonabl=
e for that type.</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/aabcfa51-687f-4dad-a53f-e0dec8d077ee%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/aabcfa51-687f-4dad-a53f-e0dec8d077ee=
%40isocpp.org</a>.<br />
------=_Part_532_2015463668.1485464264169--
------=_Part_531_906522159.1485464264169--
.
Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 26 Jan 2017 23:02:10 +0200
Raw View
On 26 January 2017 at 22:57, Nicol Bolas <jmckesson@gmail.com> wrote:
> On Thursday, January 26, 2017 at 3:09:43 PM UTC-5, Adi Shavit wrote:
>>
>> Hi,
>>
>> In a recent blog post I noted that there is no way to construct a bad
>> (or !good()) std::istringstream.
>
>
> A better question is this: why would you want to?
>
> Logically, `istringstream`s should always be either good or eof, never bad
> or fail. The only reason you can make it bad is because it has the
What?
istringstream ss("1 two 3");
int a, b;
ss >> a >> b;
cout << ss.eof();
cout << ss.good();
cout << ss.fail();}
This prints 001. Want to try that characterization again?
--
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/CAFk2RUZ%2BDk9AMunKSPyjrcaJTV_jCsTHzVkp-Qt%3DG7HLGyogwg%40mail.gmail.com.
.
Author: Adi Shavit <adishavit@gmail.com>
Date: Fri, 27 Jan 2017 02:59:22 -0800 (PST)
Raw View
------=_Part_716_1708545371.1485514762986
Content-Type: multipart/alternative;
boundary="----=_Part_717_1536068682.1485514762986"
------=_Part_717_1536068682.1485514762986
Content-Type: text/plain; charset=UTF-8
An istream conceptually models a list<optional<any>> (or a generator or
range (among other things)).
As with any, you need to know the type of what you're extracting (with <<).
If it's not there or your type is wrong the optional will be invalid.
Just like you can construct an empty list and query a list's emptiness, it
seems logical to be able to create a "bad" stream - or put another way,
inconsistent to NOT be able to create a bad stream.
--
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/882d2b03-4a9e-4963-a095-48b8faaea0ee%40isocpp.org.
------=_Part_717_1536068682.1485514762986
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">An istream conceptually models a <font face=3D"courier new=
, monospace">list<optional<any>></font>=C2=A0(or a generator or=
range (among other things)).<div>As with <font face=3D"courier new, monosp=
ace">any</font>, you need to know the type of what you're extracting (w=
ith <<).=C2=A0</div><div>If it's not there or your type is wrong =
the optional will be invalid.</div><div>Just like you can construct an empt=
y list and query a list's emptiness, it seems logical to be able to cre=
ate a "bad" stream - or put another way, inconsistent to NOT be a=
ble to create a bad stream.</div><div><br></div><div><br></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/882d2b03-4a9e-4963-a095-48b8faaea0ee%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/882d2b03-4a9e-4963-a095-48b8faaea0ee=
%40isocpp.org</a>.<br />
------=_Part_717_1536068682.1485514762986--
------=_Part_716_1708545371.1485514762986--
.
Author: Adi Shavit <adishavit@gmail.com>
Date: Fri, 27 Jan 2017 03:06:20 -0800 (PST)
Raw View
------=_Part_507_2083149192.1485515180455
Content-Type: multipart/alternative;
boundary="----=_Part_508_1487067520.1485515180455"
------=_Part_508_1487067520.1485515180455
Content-Type: text/plain; charset=UTF-8
Oops
As with any, you need to know the type of what you're extracting (with <<).
>
I meant: >>
--
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/fc1a72cf-cd4f-494f-a0e0-0167c68c1395%40isocpp.org.
------=_Part_508_1487067520.1485515180455
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Oops<br><br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><=
div>As with <font face=3D"courier new, monospace">any</font>, you need to k=
now the type of what you're extracting (with <<).=C2=A0</div></di=
v></blockquote><div><br></div><div>I meant: >>=C2=A0</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/fc1a72cf-cd4f-494f-a0e0-0167c68c1395%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/fc1a72cf-cd4f-494f-a0e0-0167c68c1395=
%40isocpp.org</a>.<br />
------=_Part_508_1487067520.1485515180455--
------=_Part_507_2083149192.1485515180455--
.