better with obs forms
[ghsmtp.git] / jnk / type_name.hpp
blob973a594c4bd66dbfde4990230da01e18cce35181
1 #include <cstdlib>
2 #include <cxxabi.h>
3 #include <iostream>
4 #include <string>
5 #include <type_traits>
6 #include <typeinfo>
8 template <class T>
9 inline std::string get_type_name()
11 typedef typename std::remove_reference<T>::type TR;
12 std::unique_ptr<char, void (*)(void*)> own(
13 abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr),
14 std::free);
15 std::string r = own != nullptr ? own.get() : typeid(TR).name();
16 if (std::is_const<TR>::value)
17 r += " const";
18 if (std::is_volatile<TR>::value)
19 r += " volatile";
20 if (std::is_lvalue_reference<T>::value)
21 r += "&";
22 else if (std::is_rvalue_reference<T>::value)
23 r += "&&";
24 return r;