Re: [Cppunit-devel] templatized assertions
Brought to you by:
blep
|
From: Baptiste L. <bl...@cl...> - 2001-05-20 09:39:07
|
> The traits class I'm using looks like the following, which can easily
> be specialized.
>
> namespace CppUnit {
>
> template <class T>
> struct assertion_traits
>
> static bool equal( const T& x, const T& y )
> {
> return x == y;
> }
>
> static std::string toString( const T& x )
> {
> ostringstream ost;
shouldn't is be std::ostringstream ost; ?
> ost << x;
> return ost.str();
> }
> };
> }
Could you send the patch with the new assert/trait. I'd like to give it a
try.
> I guess you could use a "traits namespace", instead. I'm not
> well-versed enough to know why classes are used over namespaces for
> traits. Maybe its historical? Or maybe it has something to do with
> being able to partially specialize a class template? I discovered the
I think it has to do with the fact you can specify a traits as a template
parameter type. I don't think you can to that with a namespace. This is a
very powerful idiom. See this month online expert column by Andrei
Alexandrescu on CUJ for pointer.
> hard way that GCC does not allow default template parameters in
> templated functions, while it does allow them for templated classes.
> This leads me to suspect that templated classes are better supported
> than templated functions, and for this reason the former are used
> for traits.
That's likely true. STL uses trait specialization, but I'm not sure it
uses function specialization. Let's stick to traits for now, I don't think
you need to override only one function that often.
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).
|