Boost logo

Boost Users :

Subject: Re: [Boost-users] [Units] help with type-safe unit-specific conversions
From: justinleona_at_[hidden]
Date: 2009-07-24 14:35:56


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?

Justin


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