Hi Root Team, When doing generic programming with templates -- which I know the ROOT team isn't going to do, but it should support its users doing -- it is very inconvenient to have different Streamer invocations between TObject's and Plain Old Data types. I.e., one would like to simply be able to write template <class T> class X: public TObject { T fDataMember; // Some data member ... } and then template<class T> X::Streamer(TBuffer &buf) { if (buf.IsReading()) { buf >> fDataMember; ... } else { buf << fDataMember; } } expecting the Streamer to work for both X<TH1F> and X<Int_t>. Unfortunately this does not work right now, because Int_t's require an operator>>, and TObjects require a call to Streamer(buf). The fix would be quite simple: In TObject.h, include the following two little inline functions: TBuffer & operator<<(TBuffer &buf, const TObject &obj) { return const_cast<TObject &>(obj).Streamer(buf); /* The const declaration and const_cast are needed to allow true generic programming with const object types but avoid the problem that the Streamer, since it does both input and output, is not declared const. */ } TBuffer & operator>>(TBuffer &buf, TObject &obj) { return obj.Streamer(buf); } George Heintzelman gah@bnl.gov
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:24 MET