Created
August 25, 2018 00:39
-
-
Save jdiego/affab070c4862ff880c55b2d73df8d90 to your computer and use it in GitHub Desktop.
Printing C++ Types with __PRETTY__FUNCTION__. You can use this C++ trick to explore what the compiler is doing to your types, either for metaprogramming purposes or just to learn more about auto, auto&&, and decltype(auto)
This file contains hidden or 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
#include <cstdio> | |
template<typename T> | |
void f(void) | |
{ | |
puts(__PRETTY_FUNCTION__); | |
} | |
#define EXPLORE(expr) \ | |
printf("decltype(" #expr ") is ..."); \ | |
f<decltype(expr)>(); | |
int main() | |
{ | |
auto x = 5; | |
auto&& y = 5; | |
decltype(auto) z = 5; | |
EXPLORE(x); EXPLORE((x)); | |
EXPLORE(y); EXPLORE((y)); | |
EXPLORE(z); EXPLORE((z)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment