Jean-Marc Lasgouttes wrote: > Angus> Why not define olatexstream, so, and collate all your magic > Angus> formating inside print()? > > Does this mean that I will have to redefine all the operator<< > I can think of in my header? Isn't there some kind of template that > can do it for me?
I've been thinking a little more about your problem. What happens if you define some magic for the stream that alters the way the next set of data is output? #include <iostream> #include <iomanip> int main() { //std::cout(std::ios::left, std::ios::adjustfield); std::cout << "\foo" << std::setw(10) << 10 << 'B' << std::endl; return 0; } In its current state, this should output \foo 10B whereas if the alignment line is uncommented, it outputs \foo10B Clearly your olatexstream is going to behave differently in the two cases, no? When the next character is given, the flag requires to take the following action: * c == ' ': output "{}" before c * c alphabetical: output ' ' before c Ok, so this particular case won't happen because '10' isn't alphabetical, but the general concept holds I think. I'm not saying that this is likely to happen, just flagging it up. Anyway, perhaps the following accommodates both this weirdness and your desire to only define a single operator<< for olatexstream? template <typename DataT> olatexstream & operator<<(olatexstream & ols, DataT const & data) { std::ostringstream ss; ss.copyfmt(ols); ss << data; ols.print(ss.str()); return ols; } -- Angus