Boost Users :
Subject: Re: [Boost-users] [units] runtime conversion approach
From: Matthias Schabel (boost_at_[hidden])
Date: 2011-07-29 12:37:09
> I need some help understanding unit conversions using boost::units. I see there are conversions.hpp header files. Does this mean that there are built-in unit conversions for fundamental units, or even mainstream derived ones by simply including the conversions and performing the appropriate operation?
> Can I do something like this, for instance?
> quantity<si::length> test_m = 1.0 * meter;
> quantity<us::inch> test_in = test_m * inch / meter;
You need to do conversions explicitly, so
using namespace boost::units;
typedef us::inch_base_unit::unit_type inch_unit;
std::cout << test_m << "\t" << test_in << std::endl;
1 m 39.3701 in
> What is the best way to go about setting up conversions, or for that matter, defining a unit system; for instance, the us (english) unit system does not appear to be available?
As long as conversions between the base units you are using are defined, the conversions should just work. Study libs/units/examples/radar_beam_height.cpp - that should make it clearer...
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