Boost logo

Boost :

Subject: [boost] [units] problems
From: Robert Ramey (ramey_at_[hidden])
Date: 2013-09-13 16:54:48


I want and need the boost.units functionality. I'm sure that this is what I
want. But I've spend a lot of time going through the documentation and I'm
having real difficulties figure out how to use this. There's a lot there
so I feel that what I want must be in there somewhere. I've started going
through the tutorial example and there are a couple of problems. First of
all, it doesn't compile on my machine. Looking at the tutorial, it actually
contains two programs - one of which is commented out. I tried the
commented out one as well - it didn't compile either. Note that other than
in the header, there are very few if any comments in this code. It doesn't
qualify as a tutorial.

What I expect to see is:

#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/base_units/us/mile.hpp>
void main(){
    using namespace boost::units;
    using namespace boost::units::si;
    using namespace boost::units::us;
    quantity<length, float> l1;
    l1 = 1000.0 * meters;
    quantity<length, float> l2;
    l2 = 1.0 * miles; // compile error
    quantity<length, float> l3 = l1 + l2;
}

and I expect this to pretty much work. The documentation says " Implicit
conversions between unit systems are allowed only when the reduced units are
identical, allowing, for example, trivial conversions between equivalent
units in different systems (such as SI seconds and CGS seconds)" so I
expected that it can convert miles into kilometers. This is a
disappointment - but I'll assume that the authors have a good reason for
this.

So I'm interest in figuring out how to fix this but the manual doesn't seem
to help me. I know a huge amount of effort has been invested in this
package, but I'm afraid this issue of documentation is a big obstacle to
this package being used every where it could be.

Note to authors of boost libraries. When you think you've got the
documentation done, hand it to someone who isn't familiar with it and ask
him to make a small example using the library in 30 minutes. If he can't do
that, it's time to go back to work. Most users will give up if they can't
get some sort of love back from the library in that amount of time.

Robert Ramey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk