|
Boost : |
From: s_krempp (krempp_at_[hidden])
Date: 2001-12-21 13:32:32
--- Ross Smith wrote:
> In some of my code I've been using repeated function call operators to
> provide arbitrary numbers of arguments. Something like this:
>
> cout << format("%1 %2")(1)(2) << endl;
>
> I like it becaues it bears a reasonable resemblance to a real variadic
> function, and it doesn't overload an arbitrarily-chosen operator that
> might suggest something else to the reader.
I like that too. Indeed N-ary functions can be viewed as a unary function returning an unary function, which returns an unary
function, etc.. So the choice of the operator perfectly fits the concept addressed.
Personnally I'm more used to the behaviour of binary operators like %.
operator()'s rules are rather special, compared to more usual operators, no ?
Anyway, I guess operator() is a better candidate for the long-term job of passing arbitrary numbers of arguments.
Also, I think it solves any possible problem of precedence, since parenthesis are always needed.
And an added bonus, is that we can apply a member function at the end without an extra set of parenthesis
(or am I mistaken ?)
string s = pformat("%d, %d")(x)(y).str() ;
hum, once written it does not look as nice as I thought, maybe this aspect should not be used too much.
Regards,
-- Samuel
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk