Created
July 21, 2020 08:18
-
-
Save kjk/e02565f5e2f4fdc21da38bc51d6f53a0 to your computer and use it in GitHub Desktop.
Example for https://essential-cpp.programming-books.io/user-defined-literals-d3696e4f87894401af6c2f073d356228 (made with https://codeeval.dev)
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> | |
long double operator"" _km(long double val) | |
{ | |
return val * 1000.0; | |
} | |
long double operator"" _mi(long double val) | |
{ | |
return val * 1609.344; | |
} | |
int main() | |
{ | |
std::cout << "3 km = " << 3.0_km << " m\n"; | |
std::cout << "3 mi = " << 3.0_mi << " m\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment