Boost logo

Boost Users :

Subject: Re: [Boost-users] [units]
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-09 19:15:13


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 <cid:part1.09060809.06050200_at_[hidden]>< unit <cid:part2.07050401.07090106_at_[hidden]>< 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





Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net