Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Units - Can't figure out how to use it
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-12-23 11:44:23


AMDG

Brandon Olivares wrote:
> I've been reading the documentation for Boost.Units. I understand most of
> what it is saying, but am still confused on how to do many things with this
> library.
>
> Most of the examples are using that test_system.hpp. Does this mean that you
> actually have to explicitly define the units you want to use?
>
> I am confused because I see the header files for the units I want to use,
> e.g., light_year or astronomical_unit, but I can't figure out how to
> actually use them. If I use boost::units::astronomical::light_second, it
> cannot find it. I am able to use the SI units just fine, such as:
>
> Quantity<si::length> l = 4.0 * si::meters;
>
> But beyond that, I'm lost.
>
> I also don't know which headers I should include. I don't know if there's
> one or two headers that include all the basics I would need, or if I have to
> include each of them individually.
>

There is no catch-all header.

> Here's a simple program I was trying to write just to test light_second, but
> do not know how to make it work or which headers to include:
>
> int main()
> {
> using namespace boost::units;
> using namespace boost::units::astronomical;
> using namespace std;
>
> quantity<light_second> l1 = 4.0 * light_second;
>
> cout << "l1 = " << l1 << endl;
>
> return 0;
> }
>

#include <boost/units/base_units/astronomical/light_second.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/io.hpp>
#include <iostream>

typedef boost::units::astronomical::light_second_base_unit::unit_type
light_second;

int main()
{
using namespace boost::units;
using namespace boost::units::astronomical;
using namespace std;

quantity<light_second> l1 = 4.0 * light_second();

cout << "l1 = " << l1 << endl;

return 0;
}

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