On Sat, Jan 29, 2011 at 05:52:08PM +0100, Tommaso Cucinotta wrote: > Il 29/01/2011 17:13, Tommaso Cucinotta ha scritto: > > > >>I can also share my template-based one, that avoids code replication > >>and actually turns this burden over the odocstream class itself. > >>Assuming > >>the latter works fine on all architectures, this one should as well :-). > > > >Forgot to attach. > > just don't even try it: my own brand new automated tests just started > to fail because, with that template-ish thing, at the first attempt of > typing a character in text-mode LyX was asserting :-). > > I'm using the Enrico's patch that works fine (at least on my 64-bit > machine).
Yet, I think your idea is right for avoiding code duplication. Let's see whether requiring explicit instantiations works. If yes, adding a forgotten type would only require adding a single-line instantiation declaration. So, does the attach patch work for you? -- Enrico
Index: src/support/docstream.cpp =================================================================== --- src/support/docstream.cpp (revisione 37365) +++ src/support/docstream.cpp (copia locale) @@ -511,31 +511,19 @@ otexstream & operator<<(otexstream & ots } -otexstream & operator<<(otexstream & ots, double d) +template <typename Type> +otexstream & operator<<(otexstream & ots, Type value) { - ots.os() << d; + ots.os() << value; ots.canBreakLine(true); ots.protectSpace(false); return ots; } - -otexstream & operator<<(otexstream & ots, int i) -{ - ots.os() << i; - ots.canBreakLine(true); - ots.protectSpace(false); - return ots; -} - - -otexstream & operator<<(otexstream & ots, unsigned int i) -{ - ots.os() << i; - ots.canBreakLine(true); - ots.protectSpace(false); - return ots; -} +template otexstream & operator<< <double>(otexstream &, double); +template otexstream & operator<< <int>(otexstream &, int); +template otexstream & operator<< <unsigned int>(otexstream &, unsigned int); +template otexstream & operator<< <unsigned long>(otexstream &, unsigned long); } Index: src/support/docstream.h =================================================================== --- src/support/docstream.h (revisione 37365) +++ src/support/docstream.h (copia locale) @@ -147,11 +147,8 @@ otexstream & operator<<(otexstream &, ch /// otexstream & operator<<(otexstream &, char); /// -otexstream & operator<<(otexstream &, double); -/// -otexstream & operator<<(otexstream &, int); -/// -otexstream & operator<<(otexstream &, unsigned int); +template <typename Type> +otexstream & operator<<(otexstream & ots, Type value); /// Helper struct for changing stream encoding struct SetEnc {