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; 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? Thanks in advance. Andrew -- View this message in context: http://boost.2283326.n4.nabble.com/units-tp4641179.html Sent from the Boost - Users mailing list archive at Nabble.com.
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@wanadoo.fr>< unit <cid:part2.07050401.07090106@wanadoo.fr>< 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
participants (2)
-
geocentrix
-
Vicente J. Botet Escriba