Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Lee Clagett (forum_at_[hidden])
Date: 2017-01-18 22:14:22

On Mon, 16 Jan 2017 21:23:58 +0100
Damien Buhl <damien.buhl_at_[hidden]> wrote:

> On 16/01/2017 09:54, Olaf van der Spek wrote:
> >
> >
> > It appears to only do checking at compile-time and then forwards to
> > sprintf..
> Yes the current implementation, but based on the expression template
> resulting from the parsing, one could easily produce at compile-time
> efficient code for formatting.

I have a project (currently just a
redirect to github) which generates a spirit::karma expression from a
C-string literal using metaparse. The functions are closely modeled on
the C format functions, but take an output iterator or a std::ostream
instead. The functions are also constexpr objects, so they should work
with the Fit library. For some reason the does not mention
the `fprintf` function, but it is currently in the repo too (the
thread-safe variant has not been pushed out yet). There are a decent
number of tests that compare the results against the system C
formatting functions.

The compile times are not great; metaparse, proto, and spirit v2 are a
rough combination. And the documentation is not 100% accurate - a
number of format string errors are not trapped at compile-time yet. I'm
hoping to get a nicer error reporting system, currently the wrong type
can yield an impenetrable error from within spirit.

The "backend" is currently configurable, and if you can make sense of
my "IR" from the metaparse frontend an output system that does not use
spirit could be written. It would likely result in faster compile
times, but I didn't want to write a floating point generator since there
was much to experiment with on the interface and format string parsing
side. Perhaps something to do if there is interest ...

> But I wasn't clear enough, I just wanted to tell that with the
> underlying library metaparse, one can do the compile-time dispatching.
> Naturally I think the compile-time cost would surely be higher than
> the cat() solution.


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