
"Andy Little" <andy@servocomm.freeserve.co.uk> wrote in message news:ecda4t$hjc$1@sea.gmane.org...
"Deane Yang" <deane_yang@yahoo.com> wrote in message news:ecd87h$brg$1@sea.gmane.org...
Eric Lemings wrote:
This brings up a good question. Say you have two objects:
meters m = 1; feet f = 2;
What is the type (or unit) of the following expression?
m + f;
I apologize for repeating myself, but I want this to fail to compile. I do not want implicit conversion of units. I believe I am not completely alone in this view.
Personally I love implicit unit conversions. :-) I can add a function to prevent them, but you will have to apply that explicitly:
T b = no_cast(a);
or some such.
How's that?
regards Andy Little
For addition you would need to do this: nocast(a) + nocast(b); for multiplication nocast(a) * nocast(b); You could make this a general purpose utility: template <typename T> struct no_caster{ T t; /*...*/ }; template <typename T1, typename T2> typename boost:enable_if< boost::is_same<T1, T2>,T1
::type
operator Op (nocaster<T1> ,nocaster<T2>); regards Andy Little