Skip to content

Instantly share code, notes, and snippets.

@larryhou
Created June 12, 2023 08:53
Show Gist options
  • Save larryhou/92f800c226d7e5bb7d6c7e89fc1c11f9 to your computer and use it in GitHub Desktop.
Save larryhou/92f800c226d7e5bb7d6c7e89fc1c11f9 to your computer and use it in GitHub Desktop.

https://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html

#include <exception>
#include <iostream>
#include <cstdlib>
#include <cxxabi.h>

struct empty { };

template <typename T, int N>
  struct bar { };

int main()
{
  int     status;
  char   *realname;

  // typeid
  bar<empty,17>          u;
  const std::type_info  &ti = typeid(u);

  realname = abi::__cxa_demangle(ti.name(), NULL, NULL, &status);
  std::cout << ti.name() << "\t=> " << realname << "\t: " << status << '\n';
  std::free(realname);
}
3barI5emptyLi17EE       => bar<empty, 17>       : 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment