# Boost :

From: Jan Langer (jan_at_[hidden])
Date: 2004-01-08 17:27:19

Dan W. wrote:
>> and have all the internal stuff done in SI. I have thought about the
>> possibility of doing away with unit models entirely - the only
>> problem is then you need to define some absolute reference for
>> conversions
>
> I'm not sure I understand the need for an absolute reference. Couldn't
> each unit BE its own absolute reference? Inside meters, 1 m == 1; inside
> mm, 1 mm == 1. Conversion functions could be non-class functions:
>
> template< U, V >
> void convert( U&, V ){ assert(0); }
> template <>
> void convert<m,mm>( x,y ){ x = 0.001 * y; }
> template <>
> void convert<mm,m>( x,y ){ x = 1000.0 * y; }
>
> then
> template< typename Z >
> m::operator=( Z z ){ convert( *this, z ); }

there was already discussion about this topic and i think andy wanted to
do something in this direction.

the problem is not the assignment, but the other operators. for example
addition, what is correct the first or the last form?

template <typename Unit1, typename Unit2>
Unit1 operator + (Unit1 u1, Unit2 u2)
{
Unit1 t;
convert (t, u2);
return u1 + t;
}

template <typename Unit1, typename Unit2>
Unit2 operator + (Unit1 u1, Unit2 u2)
{
Unit2 t;
convert (t, u1);
return t + u2;
}

jan

```--
jan langer ... jan_at_[hidden]
"pi ist genau drei"
```