Created
April 27, 2024 17:55
-
-
Save tejainece/1195888aa57837bcc8b73f991960623d to your computer and use it in GitHub Desktop.
Print demangled type of a variable in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by tejag on 2024-04-26. | |
// | |
#include <iostream> | |
#include <type_traits> | |
#include <typeinfo> | |
#include <cstdint> | |
#include <cxxabi.h> | |
template<typename T> | |
void printType() { | |
std::cout << abi::__cxa_demangle(typeid(T).name(), NULL, NULL, NULL); | |
} | |
int main() { | |
using Type = std::common_type<uint32_t, int64_t>::type; | |
Type a = static_cast<decltype(a)>(0); | |
int b = 0; | |
printType<decltype(a)>(); | |
std::cout << " "; | |
// printType<decltype(b)>(); | |
std::cout << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment