Boost logo

Boost :

From: Matthias Schabel (boost_at_[hidden])
Date: 2004-01-08 17:54:15


> 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...

------------------------------------------------------------------------
---------------------------
Matthias Schabel, Ph.D.
Utah Center for Advanced Imaging Research
729 Arapeen Drive
Salt Lake City, UT 84108
801-587-9413 (work)
801-585-3592 (fax)
801-706-5760 (cell)
801-484-0811 (home)
mschabel at ucair med utah edu


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