Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2007-02-14 20:34:45


Steven,

> As far as putting the system into dim is concerned, I think this
> is an
> excellent idea. If you store the dimension in the low order bits and
> the system in the high order bits, compilation time should be
> unaffected
> if you are only working in a single system. For more complex cases

It was actually much easier to implement the system inside dim<> than
I thought it would be; other than menial changes, all I had to do to get
things working is redefine the comparator :

template<typename S,typename T,typename V>
struct dim
{
        typedef S system_type;
     typedef T tag_type;
     typedef V value_type;
};

/// less than comparison for unit tag sorting
template<typename T,typename V> struct less;

template<typename S1,typename T1,typename V1,
                 typename S2,typename T2,typename V2>
struct less< dim<S1,T1,V1>,dim<S2,T2,V2> >
{
        typedef typename mpl::less<typename S1::value,
                                                           typename S2::value>::type system_less_type;
        typedef typename mpl::less<typename T1::value,
                                                           typename T2::value>::type tag_less_type;
        
        typedef typename mpl::if_<mpl::equal_to<S1,S2>,
                                                          tag_less_type,
                                                          system_less_type>::type type;
};

Then, if you enumerate the systems:

namespace SI { struct system : public ordinal<1> { }; }
namespace CGS { struct system : public ordinal<2> { }; }

everything works so far. Still need to implement the operators and
unit conversion,
which will involve a bit more work, but this actually looks feasible.
All the example
programs except those doing unit conversion already compile and run.
We'll see if
modifying the operators adds too much overhead at compile-time...

Matthias


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