Skip to content
Snippets Groups Projects
Commit f397cd9d authored by Jö Fahlke's avatar Jö Fahlke
Browse files

Make `className(expr)` return dynamic type

Closes: #158
parent cc6b63a7
No related branches found
No related tags found
1 merge request!659Make `className(expr)` return dynamic type
Pipeline #18018 failed
......@@ -11,6 +11,7 @@
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <type_traits>
#if HAVE_CXA_DEMANGLE
#include <cxxabi.h>
......@@ -18,6 +19,23 @@
namespace Dune {
namespace Impl {
std::string demangle(std::string name)
{
#if HAVE_CXA_DEMANGLE
int status;
char *demangled = abi::__cxa_demangle( name.c_str(), 0, 0, &status );
if( demangled )
{
name = demangled;
std::free( demangled );
}
#endif // #if HAVE_CXA_DEMANGLE
return name;
}
}
/** \brief Provide the demangled class name of a type T as a string */
/*
* \ingroup CxxUtilities
......@@ -26,16 +44,7 @@ namespace Dune {
std::string className ()
{
typedef typename std::remove_reference<T>::type TR;
std::string className = typeid( TR ).name();
#if HAVE_CXA_DEMANGLE
int status;
char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
if( demangled )
{
className = demangled;
std::free( demangled );
}
#endif // #if HAVE_CXA_DEMANGLE
std::string className = Impl::demangle( typeid( TR ).name() );
if (std::is_const<TR>::value)
className += " const";
if (std::is_volatile<TR>::value)
......@@ -52,9 +61,15 @@ namespace Dune {
* \ingroup CxxUtilities
*/
template <class T>
std::string className ( T& )
std::string className ( T&& v)
{
return className<T>();
typedef typename std::remove_reference<T>::type TR;
std::string className = Impl::demangle( typeid(v).name() );
if (std::is_const<TR>::value)
className += " const";
if (std::is_volatile<TR>::value)
className += " volatile";
return className;
}
} // namespace Dune
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment