Skip to content

Instantly share code, notes, and snippets.

@krdln
Created October 16, 2013 17:42
Show Gist options
  • Save krdln/7011833 to your computer and use it in GitHub Desktop.
Save krdln/7011833 to your computer and use it in GitHub Desktop.
Example of custom literal suffixes in c++11
#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