[Boost-users] [format] Alternative syntax

6 views
Skip to first unread message

Emre Turkay

unread,
Jul 29, 2009, 10:34:33 AM7/29/09
to boost...@lists.boost.org
Hi folks,

Any interest in the alternative syntax for boost::format?

format2 f("Hello %s, %s");
std::cout << f("Joe", "Jane") << std::endl
<< f("Jose", "Mary") << std::endl;

Which creates the output;

Hello Joe, Jane
Hello Jose, Mary

Code is available at http://bit.ly/2J60Re for any suggessions.

Take care,

emre
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Steven Watanabe

unread,
Jul 29, 2009, 3:33:33 PM7/29/09
to boost...@lists.boost.org
AMDG

Emre Turkay wrote:
> Any interest in the alternative syntax for boost::format?
>
> format2 f("Hello %s, %s");
> std::cout << f("Joe", "Jane") << std::endl
> << f("Jose", "Mary") << std::endl;
>
> Which creates the output;
>
> Hello Joe, Jane
> Hello Jose, Mary
>
> Code is available at http://bit.ly/2J60Re for any suggessions.
>

Why is this syntax better?

In Christ,
Steven Watanabe

OvermindDL1

unread,
Jul 29, 2009, 8:16:19 PM7/29/09
to boost...@lists.boost.org
On Wed, Jul 29, 2009 at 1:33 PM, Steven Watanabe<watan...@gmail.com> wrote:
> AMDG
>
> Emre Turkay wrote:
>>
>> Any interest in the alternative syntax for boost::format?
>>
>> format2 f("Hello %s, %s");
>> std::cout << f("Joe", "Jane") << std::endl
>>          << f("Jose", "Mary") << std::endl;
>>
>> Which creates the output;
>>
>> Hello Joe, Jane
>> Hello Jose, Mary
>>
>> Code is available at http://bit.ly/2J60Re for any suggessions.
>>
>
> Why is this syntax better?

I like that syntax, and I can see how it could be better in that it
would have better caching (does not need to recreate the object, which
is very slow), and it is a more simple syntax then the normal way you
can cache it. Looks nice to me.

Emre Turkay

unread,
Jul 30, 2009, 2:46:32 AM7/30/09
to boost...@lists.boost.org
Hi,

On Wed, Jul 29, 2009 at 12:33:33PM -0700, Steven Watanabe wrote:
> Why is this syntax better?
>
> In Christ,
> Steven Watanabe

format f1("%s, %s");
string s1 = (f1 % arg1 % arg2).str();

format2 f2("%s, %s");
string s2 = f2(arg1, arg2);

I don't claim it's better in general, the first case is better in places
where you need to bind the arguments one by one. And I think the second
case is easier to read and understand and therefore it is better in places
where you can bind all the arguments at once and need the formatted
string immediately.

Take care,

emre

Emre Turkay

unread,
Jul 30, 2009, 3:05:56 AM7/30/09
to boost...@lists.boost.org
Hi,

On Wed, Jul 29, 2009 at 06:16:19PM -0600, OvermindDL1 wrote:
> I like that syntax, and I can see how it could be better in that it
> would have better caching (does not need to recreate the object, which
> is very slow), and it is a more simple syntax then the normal way you
> can cache it. Looks nice to me.

Well, thanks. Apparently, removing the extra copy of the boost::format
object does not change the functionality, so it is removed.

Take care,

emre

Reply all
Reply to author
Forward
0 new messages