Boost logo

Boost :

From: Janek Kozicki (janek_listy_at_[hidden])
Date: 2006-06-13 17:47:04

In response to Andy's instructions about how to add a liter:

> > 1) In <boost/pqs/meta/components/of_volume.hpp>
> >
> > Add a typedef for the liter in the incoherent_unit struct (starts
> > at line 47).
> > typedef meta::unit<
> > boost::pqs::meta::rational<-3>,
> > meta::rational<1>::type,
> > boost::mpl::int_<1>
> > > liter;

Martin Bonner wisely noted that one should not edit the library itself:

> As far as I am concerned, a third party library file is (almost)
> sacrosanct. I would not want to edit it except to fix the most extreme
> bug - what happens when I upgrade to the next version of PQS.

So with above citation to bring the context, the problem is that it's
not easy to add new unit types. After short private correspondence with
Andy I think there is a solution for that.

Instead of modifying the source code of the library, just add there
following macro (macro name can be different of course):

#define BOOST_UNITS_DIVIDED(numerator,denominator,new_type) \
        typedef /*typename */ pqs::meta::binary_operation< \
                 numerator, \
                 pqs::meta::divides, \
                 denominator \
>::type new_type \

(this macro works in boost 1.33 - without boost::typeof. A similar macro
can be written to utilize boost::typof. Of course a second macro
BOOST_UNITS_MULTIPLIED would be needed as well)

This macro allows to define custom units with small trouble - just write
the unit components. Taking example from my review - I had problems with
a unit N/m (spring stiffness). With above macro I just write one line:


and now I have a new type named N_div_m and I can use it as desired.

With this mechanism maybe the amount of predefined units can be reduced
- maybe even only to one unit per dimension and no mixed units at all?
(not sure about that though). The point is that the user can define
only those units that he is going to use in his program.

IMHO adding this macro will increase pqs' library capabilities a lot.

Janek Kozicki                                                         |

Boost list run by bdawes at, gregod at, cpdaniel at, john at