Last active
April 27, 2024 20:02
-
-
Save maxattack/17bff2f6b20df58b4a2b to your computer and use it in GitHub Desktop.
C++ Getting a Compile-Time Unique Numeric ID for a Type
This file contains 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 <iostream> | |
template<typename T> | |
size_t numeric_handle() { | |
static int x; | |
return (size_t)(&x); | |
} | |
int main(int argc, char* argv[]) { | |
using namespace std; | |
cout << "int " << numeric_handle<int>() << endl; | |
cout << "float " << numeric_handle<float>() << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You just return the address of the pointer.