CASM  1.1.0
A Clusters Approach to Statistical Mechanics
TypeInfo.hh
Go to the documentation of this file.
1 #ifndef CASM_TypeInfo
2 #define CASM_TypeInfo
3 
4 #include <cxxabi.h>
5 
6 #include <cstdlib>
7 #include <memory>
8 #include <string>
9 #include <type_traits>
10 #include <typeinfo>
11 #include <utility>
12 
13 namespace CASM {
14 
18 template <typename T>
19 std::string type_name() {
20  typedef typename std::remove_reference<T>::type TR;
21  std::unique_ptr<char, void (*)(void *)> name(
22  abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr),
23  std::free);
24  std::string res = name.get();
25  if (std::is_const<TR>::value) {
26  res += " const";
27  }
28  if (std::is_volatile<TR>::value) {
29  res += " volatile";
30  }
31  if (std::is_lvalue_reference<T>::value) {
32  res += "&";
33  } else if (std::is_rvalue_reference<T>::value) {
34  res += "&&";
35  }
36  return res;
37 }
38 } // namespace CASM
39 
40 #endif
Main CASM namespace.
Definition: APICommand.hh:8
std::string type_name()
Definition: TypeInfo.hh:19
GenericDatumFormatter< std::string, DataObject > name()