Boost logo

Boost :

From: Cédric Venet (cedric.venet_at_[hidden])
Date: 2007-06-18 16:50:05


>
> -> Hard formatting: printf/scanf are much easier to use and they don't
> >> need several hundred of function calls to do their job. The
> operator<<
>
> > I'd rather disagree with you here. Operator<< gives a great advantage
> of
> > extensibility which printf cannot offer. I can define my own classes
> That is not a real issue. You can easily provide a mechanism for
> supporting user-defined types on top of a printf/scanf-like interface,
> e.g. by specializing a template, or overloading some other function
> that
> is called by the implementation of the formatting system. So ease of
> supporting user-defined types is not an argument in favor of
> operator<<.

Supposing I want some function which take a formatting chain and an arbitrary number of parameter to pass it to the new printf and then do something (usually, add a prefix, a new line or throw an exception). How can I do the forwarding in C++2003 (without defining x overload). Perhaps fusion provide some support for this?

Motivation:

Template<class T... >
Void PrintAndThrow(const char* c, T... args) {
        Cout.printf(c,args);
        Throw somethings;
}

Another things is what would be the type of the format string: a const char* or std::string? Which would need parsing each time (an no compile time checking) or a complex type build by expression template (I am thinking about some proto DSL here). It would be more complex and slower to compile, but it as some advantage. This problem don't existe with << since we treat one object at a time which is the reason reordering is impossible and internationalization difficult.

-- 
Cédric Venet

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk