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 00:41:00

2012/5/30 Michel Morin <mimomorin_at_[hidden]>:
> Antony Polukhin wrote:
>> Would be there some interest in function for getting class name without RTTI?
> Boost.Exception has such a function boost::type_name in
> <boost/exception/detail/type_info.hpp>.
> template <typename T>
> struct demangle_impl
> {
>    static std::string apply()
>    {
>        return boost::units::detail::demangle(typeid(T).name());
>    }
> };
> template <typename T>
> inline std::string type_name()
> {
>    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&'.

There is also a detail/sp_typeinfo.hpp header, which provides almost
what I propose. But it is undocumented, creates additional static
variables for each template instance, produces long names(like from
example above), noncopyable.

May be we shall document sp_typeinfo.hpp, move it to utility, and
implement it via temple_info<T> class, which would be copyable?

Best regards,
Antony Polukhin

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