Created
October 16, 2013 17:42
-
-
Save krdln/7011833 to your computer and use it in GitHub Desktop.
Example of custom literal suffixes in c++11
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 <cstdio> | |
struct _Ms { int x; }; | |
struct _Us { int x; }; | |
constexpr _Ms operator "" ms(long long unsigned x) { return {(int)x}; } | |
constexpr _Us operator"" us(long long unsigned x) { return {(int)x}; } | |
void fun(_Ms x) { printf("%d milisekund\n", x.x); } | |
void fun(_Us x) { printf("%d mikrosekund\n", x.x); } | |
int main() { | |
fun(5ms); | |
fun(500us); | |
return {}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment