Boost logo

Boost :

Subject: Re: [boost] Is there interest in typeid(TYPE).name() like function that does not require RTTI
From: Michel Morin (mimomorin_at_[hidden])
Date: 2012-05-30 18:02:19

Antony Polukhin wrote:
>> template <typename T>
>> inline std::string type_name()
>> {
>> #ifndef BOOST_NO_TYPEID
>>    return type_name_detail::demangle_impl<T>::apply();
>> #else
>> #endif
>> }
> When RTTI disabled, you are returning whole function name, not just
> the required type T. In your case you`ll get somethihg like
> ‘std::string boost::type_name() [with T = const int&, std::string =
> std::basic_string<char>]’ instead of 'const int&'.

On VC++ with /GR option, we can still use `typeid` (though we cannot
use it to obtain the dynamic type of polymorphic types).
But, yeah, we get the whole function names if BOOST_CURRENT_FUNCTION is used.

Now I understand what you're trying to do and I'm definitely interested in it!
If there is a reliable way to extract type names from BOOST_CURRENT_FUNCTION,
this is very useful.

Clang-3.1 has gcc-like __PRETTY_FUNCTION__. But, on clang-3.0 and
the prior versions, __PRETTY_FUNCTION__ is less usefull. It does not
contain type names of template arguments for function templates. So
we have to extract type names from function arguments:

    template <typename T>
    const char * f() { return BOOST_CURRENT_FUNCTION; }

    template <typename T>
    const char * g(const T&) { return BOOST_CURRENT_FUNCTION; }

    f<int>() --> const char *f()
    g(0) --> const char *g(const int &)

Thanks for interesting stuff, Antony!


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