An interesting idea! Once it's working, I'll be interested to see
what kind of performance behaviors you have. Even without using
boost, it would be possible to add this to ctemplate, using a vector
of TemplateString's (which are much like the boost class you're
using), and a helper routine that we'd add to Template that emits such
a vector to an fd using writev (which is, I assume, what the boost
routine is doing as well).
As for variable lifetime, the Emitter class was written with no
assumptions for the input lifetimes, but we could do an audit to
figure out more exactly what we can depend on.
In general, literal text is owned by the Template instance and should
live as long as you could ever need. Variables are owned by the
associated TemplateDictionary, which should also be long enough for a
given Expand() call. Modified variables, as you point out, do not
live for very long. Neither does various debug info that might be
emitted into the expanded template, none of which should apply to your
test cases.
I think to further debug this, we'd have to see a sample program
you've written that uses this new functionality, and the output it
gives in practice.
craig