|
Boost Users : |
Subject: Re: [Boost-users] [Units] help with type-safe unit-specific conversions
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-25 01:31:00
AMDG
justinleona_at_[hidden] wrote:
> I have conversions working fine for built-in types, but for both
> scaled types and user-defined types I don't know how to get indirect
> conversions to compile.
>
> Here is an example:
>
> #include <boost/units/quantity.hpp>
> #include <boost/units/systems/si.hpp>
> #include <boost/units/systems/si/prefixes.hpp>
> #include <boost/units/base_units/metric/bar.hpp>
>
> void f() {
> typedef metric::bar_base_unit::unit_type bars;
>
> typedef boost::units::scale<10,static_rational<3> > kilo_type;
> typedef make_scaled_unit<bars,kilo_type>::type kbars;
> const kbars kilobars;
>
> typedef boost::units::scale<10,static_rational<6> > mega_type;
> typedef make_scaled_unit<si::pressure,mega_type>::type mpa;
> const mpa megapascals;
>
> typedef boost::units::quantity<si::pressure> Pascals;
> typedef boost::units::quantity<mpa> Megapascals;
> typedef boost::units::quantity<kbars> Kilobars;
>
> Megapascals p(.5*kilobars);
> std::cout << Kilobars(p) << std::endl;
> }
>
> If I directly convert it works - e.g., Kilobars(Pascals(p)). Do I
> need to use BOOST_UNITS_DEFAULT_CONVERSION to set a default
> conversion? If so - which part(s) of the chain need it?
>
This ought to just work. Fixed in the trunk.
In Christ,
Steven Watanabe
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