Re: [Cppunit-devel] templatized assertions
Brought to you by:
blep
From: Baptiste L. <bl...@cl...> - 2001-05-19 14:05:34
|
> On Wed, May 16, 2001 at 09:28:06PM +0200, Baptiste Lepilleur wrote: > > I would use a trait to add the object to the stream. The trait generic > > implementation would use '<<', but could be specialized when needed. > > That sounds like a reasonable idea. I'm not terribly experienced in > traits; what would be a good name for the function? Some of CppUnit > already uses "toString", which seems reasonable enough, yes? How about using specialized template function: template<class Type> std::string toString( Type &object ) { std::ostringstream stream; stream << object; return stream.str(); } template<class Type> bool equalsTo( Type &object1, Type &object2 ) { return object1 == object2; } // Example of specializations: struct MyObject { std::string print() { return "<MyObject>"; } }; template<> std::string toString<MyObject>( MyObject &object ) { return object.print(); } template<> bool equalsTo<MyObject>( MyObject &object1, MyObject &object2 ) { return &object1 == &object2; } I like that one because it solves the naming problem and you can change only the behavior you really need to change. Baptiste. --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Author of The Text Reformatter, a tool for fanfiction readers and writers. Language: English, French (Well, I'm French). |