|
Boost : |
From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-03-07 22:55:56
on 3/6/00 7:32 PM, Marco Manfredini at marco_at_[hidden] wrote:
> Dear boosters,
>
> I was trying to develop a couple of ideas about easy I/O, and hope some of
> them are making sense somehow. I've attached code which sketches three
> classes, namely bound_formatter, unbound_formatter and formatter.
Thanks for taking a stab at this!
> 1) unbound_formatter does a simple minded string replacement on the
> arguments you pipe into it with the << operator, i.e.
>
> string s=unbound_formatter("%1=%2") << "war" << "peace"
>
> gives 'war=peace'
>
> string s=unbound_formatter("a %1 is a %1") << "rose";
>
> you know what I mean.
so far, so good
<snip>
> Therefore it is relatively easy to stack formatter's without caring for
> details:
> cout << formatter("The Message is %1") << (formatter(msg) << 1 << 2);
>
> However the following doesn't work, it requires some extra substituion:
> cout << formatter("The Truth is %1") << formatter("%1 != %2") << 1 << 2;
See, I would prefer a syntax like the one I proposed (using a family of 9
template constructors):
std::cout << format("The Truth is %1", format("%1 != %2", 1, 2));
I prefer using the parentheses to group the items to be formatted not out of
some misplaced nostalgia for printf, but because it makes more sense when
format strings are being used to group the format string with the arguments
to be formatted. That avoids any possible confusion over what this means:
std::cout << formatter("%1 = %2") << 1 << 2;
(also, it takes fewer keystrokes!)
-Dave
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk