help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Decode output from typeid().name()


From: C.W.Holeman II
Subject: Re: Decode output from typeid().name()
Date: Wed, 18 Feb 2009 22:15:28 -0800
User-agent: Thunderbird 2.0.0.19 (X11/20090105)

Pedro Lamarão wrote:
On 17 fev, 12:13, "C.W.Holeman II" <cwhii_google_s...@yahoo.com>
wrote:
Pedro Lamarão wrote:
On 16 fev, 20:27, "C.W.Holeman II" <cwhii_google_s...@yahoo.com>
wrote:
Is there a reference that decodes the output from typeid().name()?
The C++ Standard does not specify the value of that expression.
It could very well be the null string in a conforming specification.
Which is the reason I posted to gnu.g++.help not c++.

Good point.

GCC implements the Itanium C++ ABI, specified here:

http://www.codesourcery.com/public/cxx-abi/abi.html

You will see that, contrary to my expectation, this specification does
in fact guarantee some form to that expression.
Search for the demangler API.

Thanks.

#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
class X {
public:
    template<typename T> void operator[](T const&){
        size_t len;
        int s;
        char* p=abi::__cxa_demangle(typeid(T).name(), 0, &len, &s);
        std::cout << typeid(T).name() << ": " << p << std::endl;
    }
};
int main(){
    X x;
    x["Hello, world!"];
    x[1];
    x[-1.234];
    x[x];
}

--
C.W.Holeman II cwhii5@Julian5Locals.com-5s http://JulianLocals.com/cwhii
 To only a fraction of the  human  race does God  give the  privilege of
 earning one's bread doing what one would have  gladly pursued free, for
 passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks


reply via email to

[Prev in Thread] Current Thread [Next in Thread]