Boost logo

Boost :

Subject: Re: [boost] typesafe printf with variadic template
From: Abel Sinkovics (abel_at_[hidden])
Date: 2013-11-14 13:52:30

Hi Michael,

On 2013-11-14 19:20, Michael Marcin wrote:
> It seems a common example for C++11 and variadic templates is a
> typesafe printf which is supposed to obsolete things like
> Boost.Format. However there doesn't seem to be one usable out of the box.
> If this is really a large improvement shouldn't this facility be in
> boost?

I have a typesafe printf implementation based on Metaparse. It takes a
different approach as the common example for variadic templates. It adds
type checking to the non-safe printf and has no runtime overhead. The
current implementation generates code using macros instead of variadic
templates, but I'm planning to extend it in the near future.

You can use it like this:

printf<MPLLIBS_STRING("John %d, %s %d\n")>(11, "Joe", 13);

The library contains wrappers for fprintf and sprintf as well. It also
contains a valid_arguments metafunction that takes a format string and a
list of argument types and checks if the argument types are valid for
the format string.

The documentation is here:
Here are examples using it:


Boost list run by bdawes at, gregod at, cpdaniel at, john at