Dune Core Modules (2.5.2)

classname.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_CLASSNAME_HH
4#define DUNE_CLASSNAME_HH
5
11#include <cstdlib>
12#include <string>
13#include <typeinfo>
14
15#if HAVE_CXA_DEMANGLE
16#include <cxxabi.h>
17#endif // #if HAVE_CXA_DEMANGLE
18
19namespace Dune {
20
22 template <class T>
23 std::string className ()
24 {
25 typedef typename std::remove_reference<T>::type TR;
26 std::string className = typeid( TR ).name();
27#if HAVE_CXA_DEMANGLE
28 int status;
29 char *demangled = abi::__cxa_demangle( className.c_str(), 0, 0, &status );
30 if( demangled )
31 {
32 className = demangled;
33 std::free( demangled );
34 }
35#endif // #if HAVE_CXA_DEMANGLE
36 if (std::is_const<TR>::value)
37 className += " const";
38 if (std::is_volatile<TR>::value)
39 className += " volatile";
40 if (std::is_lvalue_reference<T>::value)
41 className += "&";
42 else if (std::is_rvalue_reference<T>::value)
43 className += "&&";
44 return className;
45 }
46
48 template <class T>
49 std::string className ( T& )
50 {
51 return className<T>();
52 }
53} // namespace Dune
54
55#endif // DUNE_CLASSNAME_HH
Dune namespace.
Definition: alignment.hh:11
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:23
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)