|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2006-08-21 20:20:50
"Dave Steffen" <dgsteffen_at_[hidden]> wrote in message
news:17642.19283.854773.973499_at_yttrium.numerica.us...
> 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>'
with
[
Value_type=quan::quantity_traits::default_value_type
]
and
[
StaticUnit=quan::meta::unit<quan::meta::components::of_length::abstract_quantity,quan::meta::si_unit::milli>,
NumericType=quan::quantity_traits::default_value_type
]
Constructor for class 'quan::fixed_quantity<StaticUnit,NumericType>' is
declared 'explicit'
with
[
StaticUnit=quan::meta::unit<quan::meta::components::of_length::abstract_quantity,quan::meta::si_unit::milli>,
NumericType=quan::quantity_traits::default_value_type
]
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.
regards
Andy Little
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk