Boost logo

Boost :

From: J.F.K. (beholder_at_[hidden])
Date: 2004-01-09 02:09:02


automatic conversions are important enough for units library,
so I've start another thread.

the solution proposed by Matthias Schabel and Deane Yang:
1) no automatic conversion (Rationale - it is error prone)
code like this:
L_cm = l1_cm + l2_m*cm_;

another possible solution (preffered to me):
2) automatic conversion of units with the same dimension
   if, ond only if appropriate converter provided (it isolate
us from external contexts)

I call all interested people to vote and express your
opinions.

to avoid issue with "Unit1 operator + (Unit1 u1, Unit2 u2)"
some kind of "expression templates" could be applied.
operators like "+-*/" will return a compile time proxy object
and in assign operator for unit it'll be converted in the type
of this unit.

your opinions?

Regards, Oleg.

----- Original Message -----
From: "Matthias Schabel" <boost_at_[hidden]>
Newsgroups: gmane.comp.lib.boost.devel
Sent: Friday, 09 January, 2004 04:54
Subject: Re: Re: physical-quantities

> > 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;
> > }
>
> These problems go away if you require explicit conversions. I know
> Andy wants automagic conversions, but I still think that the costs far
> outweigh the benefits for reasons like the above. In addition, the
> more explicit the units are the less likely errors are to arise when
> code is later cannibalized, rewritten, cut-n-pasted, etc... into
> contexts for which it was not originally intended...
>


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