Boost logo

Boost :

Subject: [boost]  Is there interest in typeid(TYPE).name() like function that does not require RTTI
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2012-05-29 15:29:02


Would be there some interest in function for getting class name without RTTI?

Such function can be implemented like that:

template <class TemplateNameT>
std::string template_type(const TemplateNameT& v) {
#ifdef _MSC_VER
   const char* const template_name_begin =
strstr(BOOST_CURRENT_FUNCTION, "(const ") + sizeof("(const ") - 1;

   const char* const template_name_end = template_name_begin +
strlen(template_name_begin) - sizeof("&)");
   // Code for other platforms

   return std::string(template_name_begin, template_name_end);

If there is some interest, I'll update code to work on other
platforms, and change method signature from template_type(instance) to

Usage example:

// Function can be compiled with RTTI disabled.
template <class T>
void foo(const T& val) {
   std::cerr << template_type<T>::name(); // instead of typeid(T).name();

Best regards,
Antony Polukhin

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