Topic: basic_ostream and basic_istream operator()


Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 9 Feb 2014 05:12:06 -0800 (PST)
Raw View
------=_Part_2372_31039015.1391951526805
Content-Type: text/plain; charset=UTF-8

Sorry if this idea has been floated before, but what do you think about
adding an operator() overload to ostream and istream along the lines of:

    struct basic_ostream
    {
        ...

        template<typename... Args>
        void operator()(Args&&...);

        ...
    }

The implementation perfect forwards each argument to an operator<< chain
for ostream or an operator>> chain for istream.

For example:

    #include <iostream>
    using std::cout;

    int x = 42;

    int main()
    {
        cout("Hello World!\n");

        cout("The answer is ", x);
    }

For ostream, we could also add a proxy member functor called `ln` that
appends std::endl:

    int main()
    {
        cout.ln("Hello World!");
    }

We could also add a corresponding format and formatln proxy member functor
that provides "placeholder style" output:

    int main()
    {

        cout.format("The answer is ___\n", x);

        cout.formatln("The answer is ___", x);
    }

The implementation splits the string on triple underscores and then
intersperses the arguments passing it up to operator().  Other placeholders
are conceivable, for example see boost.format, C# WriteLine, Java
out.format, C printf, etc etc.

--

---
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/.

------=_Part_2372_31039015.1391951526805
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Sorry if this idea has been floated before, but what do yo=
u think about adding an operator() overload to ostream and istream along th=
e lines of:<div><br></div><div><font face=3D"courier new, monospace">&nbsp;=
 &nbsp; struct basic_ostream</font></div><div><font face=3D"courier new, mo=
nospace">&nbsp; &nbsp; {</font></div><div><font face=3D"courier new, monosp=
ace">&nbsp; &nbsp; &nbsp; &nbsp; ...</font></div><div><font face=3D"courier=
 new, monospace"><br></font></div><div><font face=3D"courier new, monospace=
">&nbsp; &nbsp; &nbsp; &nbsp; template&lt;typename... Args&gt;</font></div>=
<div><font face=3D"courier new, monospace">&nbsp; &nbsp; &nbsp; &nbsp; void=
 operator()(Args&amp;&amp;...);</font></div><div><font face=3D"courier new,=
 monospace"><br></font></div><div><font face=3D"courier new, monospace">&nb=
sp; &nbsp; &nbsp; &nbsp; ...</font></div><div><font face=3D"courier new, mo=
nospace">&nbsp; &nbsp; }</font></div><div><br></div><div>The implementation=
 perfect forwards each argument to an operator&lt;&lt; chain for ostream or=
 an operator&gt;&gt; chain for istream.</div><div><br></div><div>For exampl=
e:</div><div><br></div><div><font face=3D"courier new, monospace">&nbsp; &n=
bsp; #include &lt;iostream&gt;</font></div><div><span style=3D"font-family:=
 'courier new', monospace;">&nbsp; &nbsp; using std::cout;</span></div><div=
><span style=3D"font-family: 'courier new', monospace;"><br></span></div><d=
iv><div><font face=3D"courier new, monospace">&nbsp; &nbsp; int x =3D 42;</=
font></div></div><div><font face=3D"courier new, monospace"><br></font></di=
v><div><span style=3D"font-family: 'courier new', monospace;">&nbsp; &nbsp;=
 int main()</span><br><font face=3D"courier new, monospace">&nbsp; &nbsp; {=
</font></div><div><font face=3D"courier new, monospace">&nbsp; &nbsp; &nbsp=
; &nbsp; cout("Hello World!\n");</font></div><div><font face=3D"courier new=
, monospace"><br></font></div><div><font face=3D"courier new, monospace">&n=
bsp; &nbsp; &nbsp; &nbsp;&nbsp;</font><span style=3D"font-family: 'courier =
new', monospace;">cout("The answer is ", x);</span><br></div><div><span sty=
le=3D"font-family: 'courier new', monospace;">&nbsp; &nbsp; }</span><br></d=
iv><div><br></div><div>For ostream, we could also add a proxy member functo=
r called `ln` that appends std::endl:</div><div><br></div><div><font face=
=3D"courier new, monospace">&nbsp; &nbsp; int main()</font></div><div><font=
 face=3D"courier new, monospace">&nbsp; &nbsp; {</font></div><div><font fac=
e=3D"courier new, monospace">&nbsp; &nbsp; &nbsp; &nbsp; cout.ln("Hello Wor=
ld!");</font></div><div><font face=3D"courier new, monospace">&nbsp; &nbsp;=
 }</font></div><div><br></div><div>We could also add a corresponding format=
 and formatln proxy member functor that provides "placeholder style" output=
:</div><div><br></div><div><font face=3D"courier new, monospace">&nbsp; &nb=
sp; int main()</font></div><div><font face=3D"courier new, monospace">&nbsp=
; &nbsp; {</font></div><div><br></div><div><font face=3D"courier new, monos=
pace">&nbsp; &nbsp; &nbsp; &nbsp; cout.format("The answer is ___\n", x);</f=
ont></div><div><font face=3D"courier new, monospace"><br></font></div><div>=
<font face=3D"courier new, monospace">&nbsp; &nbsp; &nbsp; &nbsp; cout.form=
atln("The answer is ___", x);</font></div><div><font face=3D"courier new, m=
onospace">&nbsp; &nbsp; }</font></div><div><br></div><div><font face=3D"ari=
al, sans-serif">The implementation splits the string on triple underscores =
and then intersperses the arguments passing it up to operator(). &nbsp;Othe=
r placeholders are conceivable, for example see boost.format, C# WriteLine,=
 Java out.format, C printf, etc etc.</font></div><div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <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 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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2372_31039015.1391951526805--

.


Author: David Krauss <potswa@gmail.com>
Date: Sun, 9 Feb 2014 21:50:22 +0800
Raw View
--Apple-Mail=_2EB81D6E-E76C-49F7-BA09-604C2F04122B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=ISO-8859-1


On Feb 9, 2014, at 9:12 PM, Andrew Tomazos <andrewtomazos@gmail.com> wrote:

> Sorry if this idea has been floated before, but what do you think about a=
dding an operator() overload to ostream and istream along the lines of:
>=20
>         void operator()(Args&&...);
>=20
> The implementation perfect forwards each argument to an operator<< chain =
for ostream or an operator>> chain for stream.

As alternative syntax, I don't see the motivation to standardize it.

But I wonder if the syntax could help get around locale facet dynamic dispa=
tching, which does bog down iostreams. The implementation could check wheth=
er the relevant facets of the current locale are all system-provided (perha=
ps just depending on locale object identity), and for the most common case =
forward the entire argument list to a streamlined, statically dispatched im=
plementation.

>         cout.ln("Hello World!");

This is definitely not more readable than "Hello World!\n". Having endl to =
confuse people as opposed to just \n and flush is bad enough already.

> We could also add a corresponding format and formatln proxy member functo=
r that provides "placeholder style" output:

Why? Placeholders aren't inherently faster. printf worked that way because =
of the quirky half-support of C for variadic argument lists. iostreams fail=
s to be as fast as stdio, but for other reasons. Adding placeholders atop i=
ostreams just makes it slower and illegible.

>         cout.format("The answer is ___\n", x);

How is this better than cout( "The answer is ", x, "\n" )? Format strings w=
ith indexed placeholders can be dynamically computed to rearrange the items=
, but that is seldom done in practice and is about as gratuitously brittle =
as a loop made from goto.

--=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/.

--Apple-Mail=_2EB81D6E-E76C-49F7-BA09-604C2F04122B
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=ISO-8859-1

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-=
mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Feb 9=
, 2014, at 9:12 PM, Andrew Tomazos &lt;<a href=3D"mailto:andrewtomazos@gmai=
l.com">andrewtomazos@gmail.com</a>&gt; wrote:</div><br class=3D"Apple-inter=
change-newline"><blockquote type=3D"cite"><div dir=3D"ltr">Sorry if this id=
ea has been floated before, but what do you think about adding an operator(=
) overload to ostream and istream along the lines of:<div><br></div><div><s=
pan style=3D"font-family: 'courier new', monospace;">&nbsp; &nbsp; &nbsp; &=
nbsp; void operator()(Args&amp;&amp;...);</span></div><div><br></div><div>T=
he implementation perfect forwards each argument to an operator&lt;&lt; cha=
in for ostream or an operator&gt;&gt; chain for stream.</div></div></blockq=
uote><div><br></div><div>As alternative syntax, I don&rsquo;t see the motiv=
ation to standardize it.</div><div><br></div><div>But I wonder if the synta=
x could help get around locale facet dynamic dispatching, which does bog do=
wn iostreams. The implementation could check whether the relevant facets of=
 the current locale are all system-provided (perhaps just depending on loca=
le object identity), and for the most common case forward the entire argume=
nt list to a streamlined, statically dispatched implementation.</div><br><b=
lockquote type=3D"cite"><div dir=3D"ltr"><div><font face=3D"courier new, mo=
nospace">&nbsp; &nbsp; &nbsp; &nbsp; cout.ln("Hello World!&rdquo;);</font><=
/div></div></blockquote><div><br></div><div>This is definitely not more rea=
dable than &ldquo;Hello World!\n&rdquo;. Having <font face=3D"Courier">endl=
</font>&nbsp;to confuse people as opposed to just <font face=3D"Courier">\n=
</font> and <font face=3D"Courier">flush</font> is bad enough already.</div=
><div><br></div><blockquote type=3D"cite"><div dir=3D"ltr"><div>We could al=
so add a corresponding format and formatln proxy member functor that provid=
es "placeholder style" output:</div></div></blockquote><div><br></div><div>=
Why? Placeholders aren&rsquo;t inherently faster. <font face=3D"Courier">pr=
intf</font> worked that way because of the quirky half-support of C for var=
iadic argument lists. iostreams fails to be as fast as stdio, but for other=
 reasons. Adding placeholders atop iostreams just makes it slower <i>and</i=
>&nbsp;illegible.</div><br><blockquote type=3D"cite"><div dir=3D"ltr"><div>=
<span style=3D"font-family: 'courier new', monospace;">&nbsp; &nbsp; &nbsp;=
 &nbsp; cout.format("The answer is ___\n", x);</span></div></div></blockquo=
te><div><br></div><div>How is this better than <font face=3D"Courier">cout(=
 "The answer is ", x, "\n" )</font>? Format strings with <i>indexed</i> pla=
ceholders can be dynamically computed to rearrange the items, but that is s=
eldom done in practice and is about as gratuitously brittle as a loop made =
from <font face=3D"Courier">goto</font>.</div><div><br></div></div></body><=
/html>

<p></p>

-- <br />
&nbsp;<br />
--- <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 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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_2EB81D6E-E76C-49F7-BA09-604C2F04122B--

.


Author: Andrew Tomazos <andrewtomazos@gmail.com>
Date: Sun, 9 Feb 2014 07:18:04 -0800 (PST)
Raw View
------=_Part_5_33398302.1391959084904
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Sunday, February 9, 2014 2:50:22 PM UTC+1, David Krauss wrote:
>
> This is definitely not more readable than =E2=80=9CHello World!\n=E2=80=
=9D. Having endl to=20
> confuse people as opposed to just \n and flush is bad enough already.
>

Whether it adds "\n" (no flush) or std::endl (flush) is negotiable.

What about:

    cout.ln("The answer is ", x);

....is it more readable than:

    cout("The answer is", x, "\n");

Most languages seem to have distinct print and println functions.  I think=
=20
having the line termination "mode" expressed vertically justified the same=
=20
distance from the indent makes it easier to read for some reason, possibly=
=20
because it makes it easier to ignore when there are multiple such=20
statements in sequence.  The first example was bad because it happens to=20
end in a string literal, so the line terminator is only the additional 2=20
characters `\n` and not the additional 6 `, "\n"`.

We could also add a corresponding format and formatln proxy member functor=
=20
> that provides "placeholder style" output:
>
> Why? Placeholders aren=E2=80=99t inherently faster. printf worked that wa=
y=20
> because of the quirky half-support of C for variadic argument lists.=20
> iostreams fails to be as fast as stdio, but for other reasons. Adding=20
> placeholders atop iostreams just makes it slower *and* illegible.
>
>         cout.format("The answer is ___\n", x);
>
>
> How is this better than cout( "The answer is ", x, "\n" )? Format strings=
=20
> with *indexed* placeholders can be dynamically computed to rearrange the=
=20
> items, but that is seldom done in practice and is about as gratuitously=
=20
> brittle as a loop made from goto.
>

The specific placeholder substring syntax is too negotiable (as is whether=
=20
they are indexed or possibly even named somehow) - however I think the=20
populatity of "format-style" interfaces - that is, having a format string=
=20
as the first argument containing some form of placeholder substrings,=20
followed by the arguments for those placeholders - even in languages=20
without the old C variable arguments limitations - demonstrates there is=20
more going on here.

Again my example wasn't very good, I think to see the benefit we have to=20
imagine a short format string with lengthy expression arguments:

Compare:

    cout.format("from {0} to {1}, {2} remain",
        get_start_interval(),
        get_start_interval() + delta,
        y.remaining_count);

....to:

    cout("from ", get_start_interval(), " to ", get_start_interval() +=20
delta,
           ", ", y.remaining_count, " remain");

and we can easily see why the format-style is superior here.  It is a=20
"separation of data from presentation" effect I think.

--=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/.

------=_Part_5_33398302.1391959084904
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Sunday, February 9, 2014 2:50:22 PM UTC+1, David Krauss=
 wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap=
:break-word"><div><div>This is definitely not more readable than =E2=80=9CH=
ello World!\n=E2=80=9D. Having <font face=3D"Courier">endl</font>&nbsp;to c=
onfuse people as opposed to just <font face=3D"Courier">\n</font> and <font=
 face=3D"Courier">flush</font> is bad enough already.<br></div></div></div>=
</blockquote><div><br></div><div>Whether it adds "\n" (no flush) or std::en=
dl (flush) is negotiable.</div><div><br></div><div>What about:</div><div><b=
r></div><div>&nbsp; &nbsp; cout.ln("The answer is ", x);</div><div><br></di=
v><div>...is it more readable than:</div><div><br></div><div>&nbsp; &nbsp; =
cout("The answer is", x, "\n");</div><div><br></div><div>Most languages see=
m to have distinct print and println functions. &nbsp;I think having the li=
ne termination "mode" expressed vertically justified the same distance from=
 the indent makes it easier to read for some reason, possibly because it ma=
kes it easier to ignore when there are multiple such statements in sequence=
.. &nbsp;The first example was bad because it happens to end in a string lit=
eral, so the line terminator is only the additional 2 characters `\n` and n=
ot the additional 6 `, "\n"`.</div><div><br></div><blockquote class=3D"gmai=
l_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;=
padding-left: 1ex;"><div style=3D"word-wrap:break-word"><div><div></div><bl=
ockquote type=3D"cite"><div dir=3D"ltr"><div>We could also add a correspond=
ing format and formatln proxy member functor that provides "placeholder sty=
le" output:</div></div></blockquote><div>Why? Placeholders aren=E2=80=99t i=
nherently faster. <font face=3D"Courier">printf</font> worked that way beca=
use of the quirky half-support of C for variadic argument lists. iostreams =
fails to be as fast as stdio, but for other reasons. Adding placeholders at=
op iostreams just makes it slower <i>and</i>&nbsp;illegible.</div><br><bloc=
kquote type=3D"cite"><div dir=3D"ltr"><div><span style=3D"font-family:'cour=
ier new',monospace">&nbsp; &nbsp; &nbsp; &nbsp; cout.format("The answer is =
___\n", x);</span></div></div></blockquote><div><br></div><div>How is this =
better than <font face=3D"Courier">cout( "The answer is ", x, "\n" )</font>=
? Format strings with <i>indexed</i> placeholders can be dynamically comput=
ed to rearrange the items, but that is seldom done in practice and is about=
 as gratuitously brittle as a loop made from <font face=3D"Courier">goto</f=
ont>.</div></div></div></blockquote><div><br></div><div>The specific placeh=
older substring syntax is too negotiable (as is whether they are indexed or=
 possibly even named somehow) - however I think the populatity of "format-s=
tyle" interfaces - that is, having a format string as the first argument co=
ntaining some form of placeholder substrings, followed by the arguments for=
 those placeholders - even in languages without the old C variable argument=
s limitations - demonstrates there is more going on here.</div><div><br></d=
iv><div>Again my example wasn't very good, I think to see the benefit we ha=
ve to imagine a short format string with lengthy expression arguments:</div=
><div><br></div><div>Compare:</div><div><br></div><div>&nbsp; &nbsp; cout.f=
ormat("from {0} to {1}, {2} remain",</div><div>&nbsp; &nbsp; &nbsp; &nbsp; =
get_start_interval(),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; get_start_inter=
val() + delta,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; y.remaining_count);</d=
iv><div><br></div><div>...to:</div><div><br></div><div>&nbsp; &nbsp; cout("=
from ", get_start_interval(), " to ", get_start_interval() + delta,</div><d=
iv>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", ", y.remaining_count, " rema=
in");</div><div><br></div><div>and we can easily see why the format-style i=
s superior here. &nbsp;It is a "separation of data from presentation" effec=
t I think.</div><div><br></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <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 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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_5_33398302.1391959084904--

.


Author: Thiago Macieira <thiago@macieira.org>
Date: Sun, 09 Feb 2014 11:18:36 -0800
Raw View
Em dom 09 fev 2014, =E0s 07:18:04, Andrew Tomazos escreveu:
> Again my example wasn't very good, I think to see the benefit we have to=
=20
> imagine a short format string with lengthy expression arguments:
>=20
> Compare:
>=20
>     cout.format("from {0} to {1}, {2} remain",
>         get_start_interval(),
>         get_start_interval() + delta,
>         y.remaining_count);
>=20
> ...to:
>=20
>     cout("from ", get_start_interval(), " to ", get_start_interval() +=20
> delta,
>            ", ", y.remaining_count, " remain");
>=20
> and we can easily see why the format-style is superior here.  It is a=20
> "separation of data from presentation" effect I think.

Don't forget localisation needs. Very often, localisation requires rearrang=
ing=20
the arguments:

C: "from {0} to {1}, {2} remain"
pt_BR: "{2} sobram de {0} a {1}"

A placeholder string can be easily extracted by localisation tools. Doing t=
hat=20
to the broken-up formatting with commas would be very hard: it would requir=
e a=20
more complex C++ parser than most tools have. And it goes against L10n 101:=
=20
"never concatenate translatable strings".

Not to mention that the formatter tool would need to buffer everything,=20
reconstruct the placeholders, get the translation, and then re-print.

--=20
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

--=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/.

.


Author: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Date: Sun, 9 Feb 2014 15:03:50 -0800 (PST)
Raw View
------=_Part_2666_28311617.1391987030963
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

This thread contains a long discussion on formatting using a formatting=20
string and typesafe argument list:=20
https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/89RQz9BP=
7mY

It also lifts the discussion by not limiting the output medium to a ostream=
=20
and by allowing formatting of any type that has a "tostring" or similar=20
predefined overloaded function. It allows the format string to be preparsed=
=20
and used many times for better performance and finally formatting=20
parameters (precision, radix, padding, width etc.) can be customized for=20
all data types.

I definitely think that despite what other programming languages have done=
=20
the format string + arguments idiom is far more useful, especially for=20
localisation.


Den s=C3=B6ndagen den 9:e februari 2014 kl. 20:18:36 UTC+1 skrev Thiago Mac=
ieira:
>
> Em dom 09 fev 2014, =C3=A0s 07:18:04, Andrew Tomazos escreveu:=20
> > Again my example wasn't very good, I think to see the benefit we have t=
o=20
> > imagine a short format string with lengthy expression arguments:=20
> >=20
> > Compare:=20
> >=20
> >     cout.format("from {0} to {1}, {2} remain",=20
> >         get_start_interval(),=20
> >         get_start_interval() + delta,=20
> >         y.remaining_count);=20
> >=20
> > ...to:=20
> >=20
> >     cout("from ", get_start_interval(), " to ", get_start_interval() +=
=20
> > delta,=20
> >            ", ", y.remaining_count, " remain");=20
> >=20
> > and we can easily see why the format-style is superior here.  It is a=
=20
> > "separation of data from presentation" effect I think.=20
>
> Don't forget localisation needs. Very often, localisation requires=20
> rearranging=20
> the arguments:=20
>
> C: "from {0} to {1}, {2} remain"=20
> pt_BR: "{2} sobram de {0} a {1}"=20
>
> A placeholder string can be easily extracted by localisation tools. Doing=
=20
> that=20
> to the broken-up formatting with commas would be very hard: it would=20
> require a=20
> more complex C++ parser than most tools have. And it goes against L10n=20
> 101:=20
> "never concatenate translatable strings".=20
>
> Not to mention that the formatter tool would need to buffer everything,=
=20
> reconstruct the placeholders, get the translation, and then re-print.=20
>
> --=20
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org=20
>    Software Architect - Intel Open Source Technology Center=20
>       PGP/GPG: 0x6EF45358; fingerprint:=20
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358=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 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/.

------=_Part_2666_28311617.1391987030963
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This thread contains a long discussion on formatting using=
 a formatting string and typesafe argument lis<span style=3D"font-size: 13p=
x;">t:&nbsp;</span><a href=3D"https://groups.google.com/a/isocpp.org/forum/=
#!topic/std-proposals/89RQz9BP7mY" style=3D"font-size: 13px;">https://group=
s.google.com/a/isocpp.org/forum/#!topic/std-proposals/89RQz9BP7mY</a><div><=
div><br></div><div>It also lifts the discussion by not limiting the output =
medium to a ostream and by allowing formatting of any type that has a "tost=
ring" or similar predefined overloaded function. It allows the format strin=
g to be preparsed and used many times for better performance and finally fo=
rmatting parameters (precision, radix, padding, width etc.) can be customiz=
ed for all data types.</div><div><br></div><div>I definitely think that des=
pite what other programming languages have done the format string + argumen=
ts idiom is far more useful, especially for localisation.</div><div><br><br=
>Den s=C3=B6ndagen den 9:e februari 2014 kl. 20:18:36 UTC+1 skrev Thiago Ma=
cieira:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Em dom 09 fev 2014, =C3=
=A0s 07:18:04, Andrew Tomazos escreveu:
<br>&gt; Again my example wasn't very good, I think to see the benefit we h=
ave to=20
<br>&gt; imagine a short format string with lengthy expression arguments:
<br>&gt;=20
<br>&gt; Compare:
<br>&gt;=20
<br>&gt; &nbsp; &nbsp; cout.format("from {0} to {1}, {2} remain",
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; get_start_interval(),
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; get_start_interval() + delta,
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; y.remaining_count);
<br>&gt;=20
<br>&gt; ...to:
<br>&gt;=20
<br>&gt; &nbsp; &nbsp; cout("from ", get_start_interval(), " to ", get_star=
t_interval() +=20
<br>&gt; delta,
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;", ", y.remaining_count, =
" remain");
<br>&gt;=20
<br>&gt; and we can easily see why the format-style is superior here. &nbsp=
;It is a=20
<br>&gt; "separation of data from presentation" effect I think.
<br>
<br>Don't forget localisation needs. Very often, localisation requires rear=
ranging=20
<br>the arguments:
<br>
<br>C: "from {0} to {1}, {2} remain"
<br>pt_BR: "{2} sobram de {0} a {1}"
<br>
<br>A placeholder string can be easily extracted by localisation tools. Doi=
ng that=20
<br>to the broken-up formatting with commas would be very hard: it would re=
quire a=20
<br>more complex C++ parser than most tools have. And it goes against L10n =
101:=20
<br>"never concatenate translatable strings".
<br>
<br>Not to mention that the formatter tool would need to buffer everything,=
=20
<br>reconstruct the placeholders, get the translation, and then re-print.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%=
3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNCNanbu7euhq=
Ln_62FW8ag';return true;" onclick=3D"this.href=3D'http://www.google.com/url=
?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\75AFQjCNEswDUBNC=
Nanbu7euhqLn_62FW8ag';return true;">macieira.info</a> - thiago (AT) <a href=
=3D"http://kde.org" target=3D"_blank" onmousedown=3D"this.href=3D'http://ww=
w.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75AFQj=
CNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;" onclick=3D"this.href=3D'http:=
//www.google.com/url?q\75http%3A%2F%2Fkde.org\46sa\75D\46sntz\0751\46usg\75=
AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;">kde.org</a>
<br>&nbsp; &nbsp;Software Architect - Intel Open Source Technology Center
<br>&nbsp; &nbsp; &nbsp; PGP/GPG: 0x6EF45358; fingerprint:
<br>&nbsp; &nbsp; &nbsp; E067 918B B660 DBD1 105C &nbsp;966C 33F5 F005 6EF4=
 5358
<br>
<br></blockquote></div></div></div>

<p></p>

-- <br />
&nbsp;<br />
--- <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 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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2666_28311617.1391987030963--

.