Skip to content

Instantly share code, notes, and snippets.

@tejainece
Created April 27, 2024 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tejainece/1195888aa57837bcc8b73f991960623d to your computer and use it in GitHub Desktop.
Save tejainece/1195888aa57837bcc8b73f991960623d to your computer and use it in GitHub Desktop.
Print demangled type of a variable in C++
//
// 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