|
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>.
...
> #ifndef BOOST_NO_TYPEID
> 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()
> {
> #ifndef BOOST_NO_TYPEID
> return type_name_detail::demangle_impl<T>::apply();
> #else
> return BOOST_CURRENT_FUNCTION;
> #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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk