I was wondering whether Boost.Format does support using a fixed-width / preallocated buffer as output instead of a dynamic buffer managed by the lib itself?
That is, normally you'd do:
boost::format myfmt("arg1: %1% / arg2: %2%");
// e.g.:
cout << (myfmt % 3.14 % 42);
// or
string s = boost::str( myfmt % "hey!" % "there!");
so the Boost:Format lib will automatically take care of allocating enough space and managing the "output buffer" for you.
I was wondering if there's any way to use a predefine non-dynamic buffer with Boost.Format, that is, something like:
const size_t buf_sz = 512;
char big_enough[buf_sz];
boost::format myfmt("arg1: %1% / arg2: %2%");
myfmt.attach_buffer(big_enough, buf_sz);
myfmt % "hey!" % "there!"
// big_enough buffer now contains the result string
I know I could just sift through the examples, the docs and the source, but apart from lacking time atm. (and the very possibility of missing something) it would be interesting to know: If it is not possible, it would be great if someone could explain why (if there is/are specific whys) -- was it deliberate? doesn't it match the API well? ...?
Disclaimer: This question is not about performance!