Boost logo

Boost Users :

Subject: [Boost-users] [units] easier scaled units generation
From: alfC (alfredo.correa_at_[hidden])
Date: 2010-05-03 23:46:26


scaled units are a great feature of boost.units, however it seems
complicated to (explicitly) create variables in such units. This is
the way I found to create a variable that stores a quantity like
GigaPascals:

 using boost::units;
 typedef make_scaled_unit<si::pressure, scale<10, static_rational< 9>
> >::type gpa_unit;
 gpa_unit GPa;
 quantity<gpa_unit> p(1.*GPa); //or p(1.*si::giga*si::pascal);

the question is, is there a simpler way of doing this? for example,
just

 quantity<giga<si::pressure> > p = ...; //values are converted/stored
in giga pascals.

I could add some "metafunction":

template<class Unit> giga{
 typedef make_scaled_unit<Unit, scale<10, static_rational< 9> >
>::type unit;
};

 and use it like
 quantity<giga<si::pressure>::unit> p;

and even specialize for femto, atto, mega, kile, etc. I this already
implemented in some other way?

In this way if I had implemented an electronvolt unit I could have
megaelectronvolt for free

 quantity<mega<electronvolt_unit>::unit> energy = ...;

Thank you,
Alfredo


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