casting int[] to bool[]

Don nospam at nospam.com
Fri Jan 30 01:04:42 PST 2009


Steven Schveighoffer wrote:
> "Jarrett Billingsley" wrote
>> On Thu, Jan 29, 2009 at 6:15 PM, Saaa <empty at needmail.com> wrote:
>>> That gives the same error.. only casting x to real works :/
>> That's more an issue with D's extremely (overly?) strict overload
>> resolution rules.  Functions like sin() shouldn't be an issue, since
>> there is only one overload with those.

The underlying problem is the implicit conversions. A problem with sin() 
used to exist: There was sin(creal) and sin(ireal). Then if you have 
sin(float) there are so many conversion options:
float->double -> real
   \        \       \
  cfloat->cdouble-> creal
So once you've implemented any two of those functions, you have to 
implement all of the others. It's really quite ridiculous. I got Walter 
to remove the implicit conversions real->complex for that reason.

   But yes, as far as pow() is
>> concerned, I guess you do have to cast to real.  Casting is fine here,
>> don't bother using to!().

> 
> This is such a common "mistake", and really more of an annoyance, I wonder 
> if it might be better if pow were switched to a template that called the 
> actual pow after casting the first argument to real.  Often times, one does 
> not use reals as their variable type, and I seem to recall this kind of 
> error happens even with literals for both arguments...
> 
> Something like:
> 
> real pow(T, U)(T t, U u)
> {
>    return _pow(cast(real)t, u);
> }
> 
> -Steve 
> 
> 

It would be better. Please create a bugzilla report, and I'll fix it.


More information about the Digitalmars-d-learn mailing list