Boost logo

Boost Users :

Subject: Re: [Boost-users] [units] easier scaled units generation
From: Matthias Schabel (boost_at_[hidden])
Date: 2010-05-04 01:50:42


> 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,

While it is not (yet) standards compliant, most current C++ compilers support this,
which is about as easy as you can get :

#include <boost/units/systems/si.hpp>
#include <boost/units/systems/si/prefixes.hpp>

using namespace boost::units;

typedef typeof(si::giga*si::pascals) gigapascal_type;

int main()
{
    std::cout << 1.5*gigapascal_type() << std::endl;
    
    return 0;
}

Matthias



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