|
Boost Users : |
Subject: Re: [Boost-users] more Boost::Units questions
From: Matthias Schabel (boost_at_[hidden])
Date: 2009-01-09 18:33:08
> My biggest issue is that my recent software development experience
> has involved using Java much more than C++ and I'm trying to learn
> how to use a C++ library that makes pretty heavy use of templates.
> Is there a tutorial somewhere that shows examples of doing basic
> things with this library? The kind of things
The examples directory has simple, functional demonstrations of just
about every type of functionality that anyone has wanted to date.
> - What is the difference between a "measurement" and a "quantity"?
> Is it that the former doesn't specify a unit?
measurement is just a toy class to demonstrate that you can integrate
units with non-trivial UDTs.
> - Does the library provide functions for converting between
> different units? ... for example, converting from miles to
> kilometers. If not, is there a recommended way to do this?
Dimensionally consistent quantities can be converted by explicit
construction or through conversion_factor. See the examples I listed
earlier.
> - Can I only add quantities that have the same unit or can I add
> ones with different units and the library will handle conversions
> for me?
Any dimensionally-consistent quantities may be combined, but you need
to stipulate the conversion path yourself - the library specifically
disables implicit conversions because these are impossible to make
consistent.
> - How can I extract the numeric value from a quantity?
The value() member function.
> - How can I extract the unit type from a quantity?
Did you look at the documentation for class quantity? Use the
unit_type typedef.
I really strongly recommend you go through the example code. Just
about everything is in there and is reasonably well commented.
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