forked from qicosmos/cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype_name.hpp
More file actions
36 lines (35 loc) · 748 Bytes
/
type_name.hpp
File metadata and controls
36 lines (35 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <type_traits>
#include <typeinfo>
#ifndef _MSC_VER
#include <cxxabi.h>
#endif
#include <memory>
#include <string>
#include <cstdlib>
//获取类型易读的名称
template <class T>
std::string type_name()
{
typedef typename std::remove_reference<T>::type TR;
std::unique_ptr<char, void(*)(void*)> own
(
#ifndef __GNUC__
nullptr,
#else
abi::__cxa_demangle(typeid(TR).name(), nullptr,
nullptr, nullptr),
#endif
std::free
);
std::string r = own != nullptr ? own.get() : typeid(TR).name();
if (std::is_const<TR>::value)
r += " const";
if (std::is_volatile<TR>::value)
r += " volatile";
if (std::is_lvalue_reference<T>::value)
r += "&";
else if (std::is_rvalue_reference<T>::value)
r += "&&";
return r;
}