Created
April 18, 2019 06:03
-
-
Save kim366/c5ccc5bc380d6fa02d34d09e66d9145d to your computer and use it in GitHub Desktop.
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 <cassert> | |
| template<typename T> | |
| struct types_match | |
| { | |
| static bool match() { return false; } | |
| }; | |
| #define SYNC(cpp_type, type_name) \ | |
| template<> \ | |
| struct types_match<cpp_type> \ | |
| { \ | |
| static auto type() \ | |
| { \ | |
| static auto type = type_name; \ | |
| return type; \ | |
| } \ | |
| \ | |
| static bool match(const char* other) { return other == type(); } \ | |
| }; | |
| SYNC(int, "int"); | |
| SYNC(double, "double"); | |
| int main() | |
| { | |
| assert(types_match<int>::match("int")); | |
| assert(types_match<double>::match("double")); | |
| assert(!types_match<int>::match("double")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment