c++ : human readable type names on both platforms

So little C++ so much good!

Update 2021 Apr

Modern times. Godbolt and the proper immediately obvious test online.

Here is the full code in case you can not be bothered to follow that Godbolt link. Please read the rest of the prose below.

Isn’t it funny how quickly we forgot both Wanbox and Colliru?

2018 May 24

In case you like to experiment and learn modern C++, you will be needing some R&D little nuggets of your own.

For example. C++ is notorious for its powerful meta-programming capabilities.  Thus it is very likely, in your C++ quest, you need to see the name of some type that is giving you a headache, while you are trying to understand SFINAE, no less.

And very likely you are using Stack Overflow to find answers. And over there you realize not all people use your beloved Visual Studio and MSVC. A lot of good C++ programmers/architects do use GCC and clang.  After all, clang is in widespread usage in some core C++ teams inside Microsoft too.

So. The little problem in that clang/GCC code is that type names do stay mangled by default.

As an example do the “Run code” here. That is the page on the  typeid() operator, on cppreference.com.

Meaning your MSVC code where you need to see the type name will produce mangled names on those numerous clang/GCC samples.

You will need to write a little code (like the one above ) to check this or that, using one of the good online compilers like the Wandbox I am using.

Not to worry. I have written a little function for you, to use when you need to see human-readable names in either MSVC on Windows or clang and GCC on Linux as is the Wandbox or Coliru, runtime, and platform.

Here it is:

The usage is explained in the code. And here:

I do prefer Wandbox also because one can add headers, so I just add the code as a header. For Coliru you have only one file (AFAIK?) so you will have to do copy-paste.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.