Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Down with metric!

By: a guest on Sep 10th, 2013  |  syntax: C++  |  size: 2.50 KB  |  views: 135  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <chrono>
  2. #include <iostream>
  3.  
  4. typedef std::chrono::duration<long long, std::ratio<1,          60>> thirds;
  5. typedef std::chrono::duration<long long, std::ratio<1,        3600>> fourths;
  6. typedef std::chrono::duration<long long, std::ratio<1,      216000>> fifths;
  7. typedef std::chrono::duration<long long, std::ratio<1,    12960000>> sixths;
  8. typedef std::chrono::duration<long long, std::ratio<1,   777600000>> sevenths;
  9. typedef std::chrono::duration<long long, std::ratio<1, 46656000000>> eighths;
  10.  
  11. constexpr std::chrono::hours operator"" _hours(unsigned long long h)
  12. {
  13.         return std::chrono::hours(static_cast<std::chrono::hours::rep>(h));
  14. }
  15.  
  16. constexpr std::chrono::minutes operator"" _minutes(unsigned long long m)
  17. {
  18.         return std::chrono::minutes(static_cast<std::chrono::minutes::rep>(m));
  19. }
  20.  
  21. constexpr std::chrono::seconds operator"" _seconds(unsigned long long s)
  22. {
  23.         return std::chrono::seconds(static_cast<std::chrono::seconds::rep>(s));
  24. }
  25.  
  26. constexpr thirds operator"" _thirds(unsigned long long t)
  27. {
  28.         return thirds(static_cast<thirds::rep>(t));
  29. }
  30.  
  31. constexpr fourths operator"" _fourths(unsigned long long f)
  32. {
  33.         return fourths(static_cast<fourths::rep>(f));
  34. }
  35.  
  36. constexpr fifths operator"" _fifths(unsigned long long f)
  37. {
  38.         return fifths(static_cast<fifths::rep>(f));
  39. }
  40.  
  41. constexpr sixths operator"" _sixths(unsigned long long s)
  42. {
  43.         return sixths(static_cast<sixths::rep>(s));
  44. }
  45.  
  46. constexpr sevenths operator"" _sevenths(unsigned long long s)
  47. {
  48.         return sevenths(static_cast<sevenths::rep>(s));
  49. }
  50.  
  51. constexpr eighths operator"" _eighths(unsigned long long e)
  52. {
  53.         return eighths(static_cast<eighths::rep>(e));
  54. }
  55.  
  56. int main()
  57. {
  58.         std::cout << "1 second is " << std::chrono::duration_cast<thirds>(1_seconds).count() << " thirds.\n";
  59.         std::cout << "1 third is " << std::chrono::duration_cast<fourths>(1_thirds).count() << " fourths.\n";
  60.         std::cout << "1 fourth is " << std::chrono::duration_cast<fifths>(1_fourths).count() << " fifths.\n";
  61.         std::cout << "1 fifth is " << std::chrono::duration_cast<sixths>(1_fifths).count() << " sixths.\n";
  62.         std::cout << "1 sixth is " << std::chrono::duration_cast<sevenths>(1_sixths).count() << " sevenths.\n";
  63.         std::cout << "1 seventh is " << std::chrono::duration_cast<eighths>(1_sevenths).count() << " eighths.\n";
  64.         std::cout << "1 second is " << std::chrono::duration_cast<fifths>(1_seconds).count() << " fifths.\n";
  65.  
  66.         std::cout << "3 fifths is " << std::chrono::duration_cast<std::chrono::nanoseconds>(3_fifths).count() << " nanoseconds.\n";
  67.  
  68.         return 0;
  69. }