Boost logo

Boost :

From: Andy Little (andy_at_[hidden])
Date: 2006-08-21 20:20:50

"Dave Steffen" <dgsteffen_at_[hidden]> wrote in message

> I don't know how to do that, but I'm absolutely sure it's what your
> users want.

Sorted as a quick test in my local copy of Quan FWIW.

I added a metafunction to query the unit :

allow_implicit_unit_conversions<StaticUnit>::type // bool_ true or false

 (of fixed_quantity<StaticUnit,NumericType>)

Modified the fixed_quantity ctor to query the unit.

added a conditional explicit ctor allowing conversions and voila:

#include <quan/length.hpp>

int main()
    quan::length::m L1(1);
    quan::length::mm L2 = L1; // line 6
    L1 + quan::length::m(L2); // ok

e:\Projects\Test\test.cpp(6) : error C2440: 'initializing' : cannot convert from
'quan::length_<Value_type>::m' to 'quan::fixed_quantity<StaticUnit,NumericType>'
        Constructor for class 'quan::fixed_quantity<StaticUnit,NumericType>' is
declared 'explicit'

Also works for addition etc.

In this quick mod a Macro decides whether the particular implementation of a
StaticUnit returns true or false.
but you could create a Static where that is a policy parameter I guess.. I'm not
sure if this is important enough to do that, but if it is, it is no great
problem to add it.

Andy Little

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