December 04, 2002
This seemed so minor, but you never know:

if you do this

string A = typeid(*this).name();

inside a template, you will get an extra space after the typename..

#include <iostream>
#include <typeinfo.h>

struct Root { };
template<typename T> struct Test {
Test() { cout << typeid(*this).name() << endl; }
};

void main() {
Test<Root> t;
}

// output is: Test<Root >

I verified that it is a space.

Richard


December 04, 2002
In article <asln3j$5tb$1@digitaldaemon.com>, Richard (fractal@clark.net) says...
> This seemed so minor, but you never know:
> 
> if you do this
> 
> string A = typeid(*this).name();
> 
> inside a template, you will get an extra space after the typename..
> 
> #include <iostream>
> #include <typeinfo.h>
> 
> struct Root { };
> template<typename T> struct Test {
> Test() { cout << typeid(*this).name() << endl; }
> };
> 
> void main() {
> Test<Root> t;
> }
> 
> // output is: Test<Root >
> 
> I verified that it is a space.

I don't think it's a bug.  The actual text that
shows up from a type_info.name() is not specified
by the C++ standard.  I suspect that the trailing
space on templated names is useful for the case
where templates are nested, making the result
more like what you have to type in those cases.
For example, you might have
  std::vector<std::list<MyType> >
whereas it would be syntactically wrong to have
  std::vector<std::list<MyType>>
Of course, the ultimate trailing space is not
necessary, but if it helps in the composition of
templated names, it is harmless and legal.

-- 
-Larry Brasfield
(address munged, s/sn/h/ to reply)