Skip to content

Instantly share code, notes, and snippets.

@othrayte
Created April 11, 2018 07:42
Show Gist options
  • Select an option

  • Save othrayte/98798cd48e7f5ba1bfb62257edb447e0 to your computer and use it in GitHub Desktop.

Select an option

Save othrayte/98798cd48e7f5ba1bfb62257edb447e0 to your computer and use it in GitHub Desktop.
Using c++ user defined literals to provide squared literal numbers
constexpr auto operator "" _²(long double x) {
return x*x;
}
constexpr unsigned long long int operator "" _²(unsigned long long int x) {
return x*x;
}
int main() {
return 4_²;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment