Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-02-19 13:51:21


AMDG

Matthias Schabel <boost <at> schabel-family.org> writes:

> I'm working with Steven Watanabe on a demo implementation of the library
> that allows heterogeneous units from different systems to be mixed,
> so each
> dimension carries its own system information along with it. The main
> problem
> with this is that it these heterogeneous composite units make it
> difficult to
> define functions that are restricted at compile time to a specific
> unit system.
> With concept extensions to C++, it ought to be possible to mitigate
> this issue,
> but at the moment I don't see an easy way to get both features at the
> same
> time...

It can be done using SFINAE. However,
1) All the dimension lists need to be
   processed twice.
2) Partial ordering doesn't work.

2 is solved by concepts. 1 is not.

I've been wondering whether that information
can be encoded in the system. Here are the
basics for when each fundamental dimension has
a unique unit.

template<class DimensionMap>
struct heterogeneous_system {};

template<class DimensionMap>
        
template<class DimensionMap, class Tag>
struct unit_info<heterogeneous_system<DimensionMap>, Tag> :
    unit_info<typename mpl::at<DimensionMap, Tag>::type, Tag> {
};

template<class DimensionMap, class Tag, class System>
struct base_unit_converter<Tag,heterogeneous_system<DimensionMap>,System> :
    base_unit_converter<Tag, typename mpl::at<DimensionMap, Tag>::type,System> {
};

namespace MGS {

typedef heterogeneous_system<
    mpl::map<
        mpl::pair<length_tag, SI::system>,
        mpl::pair<time_tag, SI::system>,
        mpl::pair<mass_tag, CGS::system>
>
> system;

typedef unit<system, energy_type> energy;

energy g_m_squared_per_sec_squared;

}

In Christ,
Steven Watanabe


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