1

Here's a bit of code from another question which adds 29.0 minutes to 60.0 seconds and displays the result in hours:

cout <<
    static_cast<quantity<hour_base_unit::unit_type>>
    (quantity<time>{29.0 * minute_base_unit::unit_type()} + 60.0 * seconds)
    << endl;

What's the recommended way to define minutes so that the above expression can be written as:

cout <<
    static_cast<quantity<hour_base_unit::unit_type>>
    (29.0 * minutes + 60.0 * seconds)
    << endl;
Community
  • 1
  • 1
dharmatech
  • 8,979
  • 8
  • 42
  • 88

1 Answers1

2

If you can, I would recommend using C++14's <chrono> facilities for this. They are very nice. (I know this is not technically an answer to his question, but it might save him a lot of work).

#include <iostream>
#include <chrono>

int main () {
    using namespace std::chrono;
    std::cout << duration_cast<hours>(29min + 60s).count() << std::endl;
}
Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
  • Hi Marshall! `chrono` is definitely very nice. However, I just used "hours, minutes, seconds" as they're familiar units. I'd like to do things similar to the above for other sorts of units (add feet + meters, see the result in inches, etc). (PS: I enjoyed the 2014 Grill the Committe presentation!) – dharmatech Dec 23 '15 at 04:21