Boost logo

Boost :

Subject: Re: [boost] Is there interest in typeid(TYPE).name() like function that does not require RTTI
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2012-05-30 14:53:00


2012/5/30 Nevin Liber <nevin_at_[hidden]>:
> On 29 May 2012 14:29, Antony Polukhin <antoshkka_at_[hidden]> wrote:
>
>> Would be there some interest in function for getting class name without
>> RTTI?
>>
>
> To be clear, this does not do the same thing as RTTI.  For instance:
>
> struct B { virtual ~B() {} };
> struct D : B {};
> // ...
> D d;
> B& b(d);
> std::cout << template_type(b) << std::endl;
>
> will print B, not D.

Yeep, you`ve got it!

> That being said, this is mighty useful, especially when doing non-trivial
> things with templates.
>
> Now, I'd rather the interface return some kind of range, as there are many
> times I don't want to pay the allocation cost for putting it in a string.

I was implementing const char* raw_name() and std::string
name_demangled(). First returns zero terminated character sequence
that contains not very nice names:

class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > >::name_begin(void)
or
std::basic_string<char>]

Second returns more user friendly nice printable name:

class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> >
or
std::basic_string<char>

Any more feature requests?

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk