
Quoting Jeremy Maitin-Shepard <jbms@cmu.edu>:
Rene Rivera <grafikrobot@gmail.com> writes:
You just described the Boost.Format library.
The boost format library may be pretty good. It could presumably be adapted to work on top of a different set of backend facilities for formatting various types to character strings/streams, as opposed to being based on the iostreams system,
boost.format seems to be unknow or not liked, anyways, it didn't seems like a reference. However, it should solve a majority of the need. Just it's not efficient (somethings like 3 or 4 times slower that printf from the doc if I recall correctly). For most application, this wouldn't be a problem. But sometimes it can. we could imagine something like: cout << format("var ",_s," =3D ",_h<8>,";")%v.n%v.v << endl; or cout << format("var ",_s," =3D ",_h<8>,";")(v.n,v.v) << endl; or cout << format("var "%_s%" =3D "%_h<8>%";",v.n,v.v) << endl; where _s and _h are respectively string and hex integer, the positionnal and format option could be passed as template or runtime parameter. for user defined type outputing, either use << like boost.format or define another free funtion which could take additional parameter like formating option template<class T,class OPT> void toString(stream& os, T t, OPT opt) { ... } this shouldn't be too slow at compile time, but I fear a little code bloating. There is then a tradeoff speed/size by selecting runtime or compile time parameter. -- Cédric Venet Jeremy, Sorry for the double post (I dislike this webmail wich ignore the reply-to)