Reputation: 9527
Let's suppose I'd like to add 29 minutes and 60 seconds and display the result in hours.
Here's something that appears to work:
cout <<
static_cast<quantity<hour_base_unit::unit_type>>
(quantity<time>{29.0 * minute_base_unit::unit_type()} + 60.0 * seconds)
<< endl;
The following is displayed on the console:
0.5 h
Is this the recommended approach? Is there a better or more idiomatic way?
The entire program illustrating the above example is below.
#include <iostream>
#include <boost/units/systems/si/io.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/base_units/metric/hour.hpp>
#include <boost/units/base_units/metric/minute.hpp>
using namespace std;
using namespace boost::units;
using namespace boost::units::si;
using namespace boost::units::metric;
int main()
{
cout <<
static_cast<quantity<hour_base_unit::unit_type>>
(quantity<time>{29.0 * minute_base_unit::unit_type()} + 60.0 * seconds)
<< endl;
return 0;
}
Upvotes: 2
Views: 683