Topic: A proposal to add a printf-like interface to
Author: Martinho Fernandes <martinho.fernandes@gmail.com>
Date: Wed, 26 Dec 2012 00:26:30 +0000
Raw View
On 26 December 2012 00:04:53, Olaf van der Spek wrote:
> Op zondag 23 december 2012 07:53:58 UTC+1 schreef Zhihao Yuan het
> volgende:
>
> Nice proposal!
>
>
> > If an /internally formattable/ argument is an object of an
> instantiation of |basic_string|, it is printed as if a return value of
> its |data()|member function is printed.
>
> I assume size() is used too?
> Otherwise you're running into issues with string termination.
Why would that be? The return value of data is null-terminated. Using=20
size() may be good for optimization, but it is not required for=20
correctness.
--
Mit freundlichen Gr=FC=DFen,
Martinho Fernandes
--=20
.
Author: Herb Sutter <hsutter@microsoft.com>
Date: Wed, 26 Dec 2012 01:01:06 +0000
Raw View
> > > If an /internally formattable/ argument is an object of an
> > > instantiation of |basic_string|, it is printed as if a return value of
> > > its |data()|member function is printed.
Olaf van der Spek:
> > I assume size() is used too?
> > Otherwise you're running into issues with string termination.
Martinho Fernandes:
> Why would that be? The return value of data is null-terminated. Using
> size() may be good for optimization, but it is not required for correctness.
It is, because otherwise you won't get the right answer for strings that contain embedded nulls.
I agree with Olaf that something like "the size() characters starting at its data() pointer" should be mentioned here.
Herb
--
.
Author: Zhihao Yuan <lichray@gmail.com>
Date: Tue, 25 Dec 2012 20:28:58 -0600
Raw View
Thanks for your suggestions, Sutter and all guys who give me those suggestions.
I'm going to add an "Acknowledgements" section.
Some examples and a benchmark (using Boost.Format's test code) are added.
https://github.com/lichray/formatxx/blob/proposal/proposal/printf.md
On Tue, Dec 25, 2012 at 7:01 PM, Herb Sutter <hsutter@microsoft.com> wrote:
> It is, because otherwise you won't get the right answer for strings that contain embedded nulls.
>
> I agree with Olaf that something like "the size() characters starting at its data() pointer" should be mentioned here.
Ah, sad. My purpose is leave the formatting problem to printf so that
I don't need to
explain how a basic_string is being truncated by a precision. But
since printf does not
support a string with embedded NULs, I have to rethink this part.
Considering string
truncation on multibyte strings (like UTF-8) is a pitfall, the
"feature" of truncation on
basic_string might be removed.
--
Zhihao Yuan, ID lichray
The best way to predict the future is to invent it.
___________________________________________________
4BSD -- http://4bsd.biz/
--
.
Author: Jeffrey Yasskin <jyasskin@googlers.com>
Date: Wed, 26 Dec 2012 15:15:33 -0800
Raw View
On Wed, Dec 26, 2012 at 3:08 PM, <stackmachine@hotmail.com> wrote:
> C++ is getting worse and worse. This proposal is part of it.
General positive and negative sentiment belongs somewhere other than
this list. Please constrain your posts to suggesting concrete changes.
Thank you,
Jeffrey
--
.
Author: stackmachine@hotmail.com
Date: Wed, 26 Dec 2012 16:56:59 -0800 (PST)
Raw View
------=_Part_1050_30700719.1356569819411
Content-Type: text/plain; charset=ISO-8859-1
Am Donnerstag, 27. Dezember 2012 00:15:33 UTC+1 schrieb Jeffrey Yasskin:
>
> On Wed, Dec 26, 2012 at 3:08 PM, <stackm...@hotmail.com <javascript:>>
> wrote:
> > C++ is getting worse and worse. This proposal is part of it.
>
> General positive and negative sentiment belongs somewhere other than
> this list. Please constrain your posts to suggesting concrete changes.
>
> Thank you,
> Jeffrey
>
Concrete change: Dump the C printf format specifiers, use a new syntax. I
don't understand how one can possibly be so stupid to copy them over from C.
--
------=_Part_1050_30700719.1356569819411
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>Am Donnerstag, 27. Dezember 2012 00:15:33 UTC+1 schrieb Jeffrey Yas=
skin:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;">On Wed, Dec 26, 2012 at 3=
:08 PM, <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"-6-QGlrDMV4J">stackm...@hotmail.com</a>> wrote:
<br>> C++ is getting worse and worse. This proposal is part of it.
<br>
<br>General positive and negative sentiment belongs somewhere other than
<br>this list. Please constrain your posts to suggesting concrete changes.
<br>
<br>Thank you,
<br>Jeffrey
<br></blockquote><div>Concrete change: Dump the C printf format speci=
fiers, use a new syntax. I don't understand how one can possibly be so stup=
id to copy them over from C.<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_1050_30700719.1356569819411--
.
Author: Jeffrey Yasskin <jyasskin@googlers.com>
Date: Wed, 26 Dec 2012 17:15:40 -0800
Raw View
On Wed, Dec 26, 2012 at 4:56 PM, <stackmachine@hotmail.com> wrote:
>
>
> Am Donnerstag, 27. Dezember 2012 00:15:33 UTC+1 schrieb Jeffrey Yasskin:
>>
>> On Wed, Dec 26, 2012 at 3:08 PM, <stackm...@hotmail.com> wrote:
>> > C++ is getting worse and worse. This proposal is part of it.
>>
>> General positive and negative sentiment belongs somewhere other than
>> this list. Please constrain your posts to suggesting concrete changes.
>>
>> Thank you,
>> Jeffrey
>
> Concrete change: Dump the C printf format specifiers, use a new syntax. I
> don't understand how one can possibly be so stupid to copy them over from C.
Ah, reading the thread might help you then. Zhihao already answered,
"For me, I prefer a format specification with type hint. A pure
positional syntax like %1%, %2% or even a pure sequential syntax like
{}, {} do not make much sense to me. But %d obviously offers more
information."
I happen to disagree and prefer a syntax that doesn't encode a small
set of types like this, but a desire for some redundant type
information isn't stupid, especially since several compilers already
check that this information is compatible with the real argument
types.
Jeffrey
--
.
Author: stackmachine@hotmail.com
Date: Wed, 26 Dec 2012 17:23:18 -0800 (PST)
Raw View
------=_Part_996_12102635.1356571398229
Content-Type: text/plain; charset=ISO-8859-1
Am Donnerstag, 27. Dezember 2012 02:15:40 UTC+1 schrieb Jeffrey Yasskin:
>
> On Wed, Dec 26, 2012 at 4:56 PM, <stackm...@hotmail.com <javascript:>>
> wrote:
> >
> >
> > Am Donnerstag, 27. Dezember 2012 00:15:33 UTC+1 schrieb Jeffrey Yasskin:
> >>
> >> On Wed, Dec 26, 2012 at 3:08 PM, <stackm...@hotmail.com> wrote:
> >> > C++ is getting worse and worse. This proposal is part of it.
> >>
> >> General positive and negative sentiment belongs somewhere other than
> >> this list. Please constrain your posts to suggesting concrete changes.
> >>
> >> Thank you,
> >> Jeffrey
> >
> > Concrete change: Dump the C printf format specifiers, use a new syntax.
> I
> > don't understand how one can possibly be so stupid to copy them over
> from C.
>
> Ah, reading the thread might help you then. Zhihao already answered,
> "For me, I prefer a format specification with type hint. A pure
> positional syntax like %1%, %2% or even a pure sequential syntax like
> {}, {} do not make much sense to me. But %d obviously offers more
> information."
>
> I happen to disagree and prefer a syntax that doesn't encode a small
> set of types like this, but a desire for some redundant type
> information isn't stupid, especially since several compilers already
> check that this information is compatible with the real argument
> types.
>
> Jeffrey
>
The checks aren't necessary and i hate remembering format specifiers.
What's the sepcifier for size_t again? Also you lose the possibility to
print custom types.
--
------=_Part_996_12102635.1356571398229
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><br>Am Donnerstag, 27. Dezember 2012 02:15:40 UTC+1 schrieb Jeffrey Yas=
skin:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;">On Wed, Dec 26, 2012 at 4=
:56 PM, <<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-=
mailto=3D"3g2QjlojCKUJ">stackm...@hotmail.com</a>> wrote:
<br>>
<br>>
<br>> Am Donnerstag, 27. Dezember 2012 00:15:33 UTC+1 schrieb Jeffrey Ya=
sskin:
<br>>>
<br>>> On Wed, Dec 26, 2012 at 3:08 PM, <<a>stackm...@hotmai=
l.com</a>> wrote:
<br>>> > C++ is getting worse and worse. This proposal is part of =
it.
<br>>>
<br>>> General positive and negative sentiment belongs somewhere othe=
r than
<br>>> this list. Please constrain your posts to suggesting concrete =
changes.
<br>>>
<br>>> Thank you,
<br>>> Jeffrey
<br>>
<br>> Concrete change: Dump the C printf format specifiers, use a =
new syntax. I
<br>> don't understand how one can possibly be so stupid to copy them ov=
er from C.
<br>
<br>Ah, reading the thread might help you then. Zhihao already answered,
<br>"For me, I prefer a format specification with type hint. A pure
<br>positional syntax like %1%, %2% or even a pure sequential syntax like
<br>{}, {} do not make much sense to me. But %d obviously offers more
<br>information."
<br>
<br>I happen to disagree and prefer a syntax that doesn't encode a small
<br>set of types like this, but a desire for some redundant type
<br>information isn't stupid, especially since several compilers already
<br>check that this information is compatible with the real argument
<br>types.
<br>
<br>Jeffrey
<br></blockquote><div>The checks aren't necessary and i hate remembering fo=
rmat specifiers. What's the sepcifier for size_t again? Also you lose the p=
ossibility to print custom types.<br></div>
<p></p>
-- <br />
<br />
<br />
<br />
------=_Part_996_12102635.1356571398229--
.
Author: Patrick Michael Niedzielski <patrickniedzielski@gmail.com>
Date: Thu, 27 Dec 2012 01:38:38 +0000
Raw View
On mer, 2012-12-26 at 17:23 -0800, stackmachine@hotmail.com wrote:
> The checks aren't necessary and i hate remembering format specifiers.
> What's the sepcifier for size_t again?
%z. I've never had trouble remembering that, and either way, neither
the point nor either of our personal abilities to remember it are
relevant. See below.
> Also you lose the possibility to print custom types.
The proposal addresses both points you brought up. Quoting:
To balance the standard compliance and the extensibility, this
proposal distinguishes the arguments to be printed into:
* internally formattable, which have the same formatting as if
they are formatted by snprintf or a wide character equivalence
given the same format specifications with a fitted length
modifier, and
* potentially formattable, which will be outputted by the <<
operator with the translated formatting properties set up on the
output stream.
Also, concerning the format specifiers:
For a basic_ostream<CharT, Traits> and a given format
description, the matched argument is internally formattable if:
* the type hint is d, i, o, u, x, or X, and the argument is an
integer, or
* the type hint is a, A, e, E, f, F, g, or G, and the argument is
a floating-point number, or
* the type hint is p, and the argument is a pointer, or
* the type hint is c, and the argument is char, CharT, or
Traits::int_type, or signed char/unsigned char if CharT is char,
or
* the type hint is s, and the argument is const char*, const
CharT*, or const signed char*/const unsigned char* if CharT is
char.
[snipped note]
Otherwise, the argument is potentially formattable.
For reference, Zhihao's proposal is at
https://github.com/lichray/formatxx/blob/proposal/proposal/printf.md .
Regards,
Patrick Niedzielski
--
.
Author: Thiago Macieira <thiago@macieira.org>
Date: Sat, 31 Aug 2013 10:24:01 -0700
Raw View
On s=E1bado, 31 de agosto de 2013 10:01:11, fmatthew5876@gmail.com wrote:
> Of course the problem here for beginners is when they ask why this progra=
m
> doesn't work:
>=20
> void main() {
> putf("Hello World");
> }
It doesn't work because your main returns void :-)
GCC: <stdin>:1:11: error: =91::main=92 must return =91int=92
Clang: <stdin>:1:1: error: 'main' must return 'int'
ICC: Line 1: warning #1079: return type of function "main" must be "int"
--=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: fmatthew5876@gmail.com
Date: Sat, 31 Aug 2013 10:28:45 -0700 (PDT)
Raw View
------=_Part_1741_26341469.1377970125920
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
On Saturday, August 31, 2013 1:24:01 PM UTC-4, Thiago Macieira wrote:
>
> On s=E1bado, 31 de agosto de 2013 10:01:11, fmatth...@gmail.com<javascrip=
t:>wrote:=20
> > Of course the problem here for beginners is when they ask why this=20
> program=20
> > doesn't work:=20
> >=20
> > void main() {=20
> > putf("Hello World");=20
> > }=20
>
> It doesn't work because your main returns void :-)=20
>
> GCC: <stdin>:1:11: error: =91::main=92 must return =91int=92=20
> Clang: <stdin>:1:1: error: 'main' must return 'int'=20
> ICC: Line 1: warning #1079: return type of function "main" must be "int"=
=20
>
> Well of course, but you get the point I hope. :)=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_1741_26341469.1377970125920
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><br><br>On Saturday, August 31, 2013 1:24:01 PM UTC-4, Thi=
ago Macieira wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On s=E1bado=
, 31 de agosto de 2013 10:01:11, <a href=3D"javascript:" target=3D"_blank" =
gdf-obfuscated-mailto=3D"fUApRP9KkNoJ">fmatth...@gmail.com</a> wrote:
<br>> Of course the problem here for beginners is when they ask why this=
program
<br>> doesn't work:
<br>>=20
<br>> void main() {
<br>> putf("Hello World");
<br>> }
<br>
<br>It doesn't work because your main returns void :-)
<br>
<br>GCC: <stdin>:1:11: error: =91::main=92 must return =91int=92
<br>Clang: <stdin>:1:1: error: 'main' must return 'int'
<br>ICC: Line 1: warning #1079: return type of function "main" must be "int=
"
<br>
<br></blockquote><div>Well of course, but you get the point I hope. :) =
;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;">--=20
<br>Thiago Macieira - thiago (AT) <a href=3D"http://macieira.info" target=
=3D"_blank">macieira.info</a> - thiago (AT) <a href=3D"http://kde.org" targ=
et=3D"_blank">kde.org</a>
<br> Software Architect - Intel Open Source Technology Center
<br> PGP/GPG: 0x6EF45358; fingerprint:
<br> E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4=
5358
<br>
<br></blockquote></div>
<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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />
------=_Part_1741_26341469.1377970125920--
.