GCC의 경우 트릭을 사용해야합니다. cxxabi.h 을 사용하여이 목적을 위해 약간의 래퍼를 작성했습니다.
#include <string>
#include <iostream>
#include <iomanip>
#include <typeinfo>
#include <cxxabi.h>
#define DEBUG_TYPE(x) do { typedef void(*T)x; debug_type<T>(T(), #x); } while(0)
template<typename T>
struct debug_type
{
template<typename U>
debug_type(void(*)(U), const std::string& p_str)
{
std::string str(p_str.begin() + 1, p_str.end() - 1);
std::cout << str << " => ";
char * name = 0;
int status;
name = abi::__cxa_demangle(typeid(U).name(), 0, 0, &status);
if (name != 0) { std::cout << name << std::endl; }
else { std::cout << typeid(U).name() << std::endl; }
free(name);
}
};
두 번 괄호가 필요합니다. 모든 유형의 작품.
지금 당신은 부스트 : : MPL을 위해 그것을 사용할 수 있습니다
DEBUG_TYPE((if_c<true, true_, false_>::type));
것입니다 인쇄 :
if_c<true, true_, false_>::type => bool_<true>
틀림 매크로에 대한 경우이다'#DEFINE ENABLE_TYPENAME의 (A) 템플릿 <> 구조체 유형 이름 {const 정적 CHAR *() {#A를 리턴하기; }};'. 그런 다음 클래스'Foo'를 쓸 때'ENABLE_TYPENAME (Foo)'를 할 수 있습니다. 필요하면 올바른 네임 스페이스에 넣을 수 있습니다. –
"각 유형에 대해 별개"아니요,이 보증조차 가지고 있지 않습니다. – icecrime
GCC는 Itanium ABI 기능으로 디맹 글트 될 수있는 아이 늄 ABI 맹 글링 된 이름을 제공합니다. – Puppy