Boost logo

Boost :

From: Robert Allan Schwartz (notbob_at_[hidden])
Date: 2003-02-28 18:23:04

> > Perhaps my spelling class template could be folded into type_traits?
> [code snipped]
> Looks interesting, but I'm not sure if it's such a huge advantage over:
> template <typename T>
> void foo(T)
> {
> cout << "T is " << typeid(T).name() << endl;
> }
> The resulting string of your method is more portable of course, but is
> that the only reason?

No. There are other reasons why typeid() is not as "good" as my proposal:

1) You must #include <typeinfo> in order to use typeid(). This seems to me
to be unnecessary overhead.

2) The following program:

class base { };

class derived : public base { };

int main(void)
 base * b = new derived;

 base const * const b2 = new derived;


 return 0;


T is P4base
T is 4base
T is PC4base
T is 4base

when compiled by g++ and executed in cygwin.

As you point out, the string returned by typeid().name() is not specified by
the Standard, so it is not portable, but in this case, it is extremely
difficult to decipher.

I believe a "standardized" (within Boost), portable, and *readable* text
representation of T makes my proposal better than typeid().

Thanks for your feedback!


Boost list run by bdawes at, gregod at, cpdaniel at, john at