Dune Core Modules (2.8.0)

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 <memory>
13#include <string>
14#include <typeinfo>
15#include <type_traits>
16
17#if __has_include(<cxxabi.h>) && !DISABLE_CXA_DEMANGLE
18#define HAVE_CXA_DEMANGLE 1
19#include <cxxabi.h>
20#endif // #if HAVE_CXA_DEMANGLE
21
22namespace Dune {
23
24 namespace Impl {
25
26 inline std::string demangle(std::string name)
27 {
28#if HAVE_CXA_DEMANGLE
29 int status;
30 std::unique_ptr<char, void(*)(void*)>
31 demangled(abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status),
32 std::free);
33 if( demangled )
34 name = demangled.get();
35#endif // #if HAVE_CXA_DEMANGLE
36 return name;
37 }
38 }
39
41 /*
42 * \ingroup CxxUtilities
43 */
44 template <class T>
45 std::string className ()
46 {
47 typedef typename std::remove_reference<T>::type TR;
48 std::string className = Impl::demangle( typeid( TR ).name() );
49 if (std::is_const<TR>::value)
50 className += " const";
51 if (std::is_volatile<TR>::value)
52 className += " volatile";
53 if (std::is_lvalue_reference<T>::value)
54 className += "&";
55 else if (std::is_rvalue_reference<T>::value)
56 className += "&&";
57 return className;
58 }
59
61 /*
62 * \ingroup CxxUtilities
63 */
64 template <class T>
65 std::string className ( T&& v)
66 {
67 typedef typename std::remove_reference<T>::type TR;
68 std::string className = Impl::demangle( typeid(v).name() );
69 if (std::is_const<TR>::value)
70 className += " const";
71 if (std::is_volatile<TR>::value)
72 className += " volatile";
73 return className;
74 }
75} // namespace Dune
76
77#endif // DUNE_CLASSNAME_HH
Dune namespace.
Definition: alignedallocator.hh:11
std::string className()
Provide the demangled class name of a type T as a string.
Definition: classname.hh:45
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)