Skip to content

Instantly share code, notes, and snippets.

@zorchp
Last active October 6, 2023 15:28
Show Gist options
  • Save zorchp/7ab82a559529546cc11ac6ad9ac3fcb1 to your computer and use it in GitHub Desktop.
Save zorchp/7ab82a559529546cc11ac6ad9ac3fcb1 to your computer and use it in GitHub Desktop.
print-type-with-clang-and-gcc-use-cxxabi
#include <cxxabi.h>
#include <iostream>
#if __cplusplus < 202002
#define print_type(x) \
std::cout << #x << typeid(x).name() << " => " \
<< abi::__cxa_demangle(typeid(x).name(), NULL, NULL, NULL) \
<< std::endl
#else
#include <format>
#define print_type(x) \
std::cout << std::format( \
"{} : {} => {}\n", #x, typeid(x).name(), \
abi::__cxa_demangle(typeid(x).name(), NULL, NULL, NULL))
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment