Le 09/01/13 22:32, geocentrix a écrit :
I am attempting to replace my own Quantity class with boost::units.

One thing that is easy in my existing code is to convert a quantity from any
unit of pressure into a specific unit, e.g. GPa (gigapascals), using a
function ConvertedTo(). For example:

Pressure converted_value = existing_value.ConvertedTo(GPa);

How do you do this with boost:units.?

I have the following things defined:

typedef boost::units::quantity<boost::units::si::pressure> Pressure;
static const Pressure Pa = 1.0 * boost::units::si::pascals;
static const Pressure GPa = 1e9 * Pa;
I guess the implicit conversion should do the trick if you type your variables

static const boost::units::quantity<boost::units::si::pressure> Pa = 1.0 * boost::units::si::pascals;
static const boost::units::quantity<boost::units::si::pressure, boost::units::si::giga> GPa = Pa;
as the following is part of the quantity interface

template<typename YY> 
   quantity(const quantity< unit< dimension_type, system_type >, YY > & source, 
Pressure value(1.0^9 * Pa);

How do I display value in GPa? I am missing something very simple and
wondered if someone could advise, please?


#include  <boost/units/io.hpp>
std::cout << GPa;


HTH,
Vicente