dune-common 2.8.0
Loading...
Searching...
No Matches
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>
46 {
47 typedef typename std::remove_reference<T>::type TR;
48 std::string className = Impl::demangle( typeid( TR ).name() );
50 className += " const";
52 className += " volatile";
54 className += "&";
56 className += "&&";
57 return className;
58 }
59
61 /*
62 * \ingroup CxxUtilities
63 */
64 template <class T>
66 {
67 typedef typename std::remove_reference<T>::type TR;
68 std::string className = Impl::demangle( typeid(v).name() );
70 className += " const";
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
T c_str(T... args)
T free(T... args)