Dune Core Modules (2.7.1)

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