Can't use float array in map

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Jun 3 10:23:36 PDT 2011


Ugh don't I love making silly posts like these. ref won't work for any
types, not just floats, since it uses the .init property.

My real problem was that I was using assignment in my first example
instead of returning a value. Using map with ref doesn't make much
sense. So my complaints are void.

On 6/3/11, Andrej Mitrovic <andrej.mitrovich at gmail.com> wrote:
> Offending line in map:
> alias typeof(_fun(.ElementType!R.init)) ElementType;
>
> So it tires to pass .init which will be nan for floats.
>
> A quick workaround would be:
>     static if (isFloatingPoint!(ElementType!R))
>     {
>         .ElementType!R x;
>         alias typeof(_fun(x)) ElementType;
>     }
>     else
>     {
>         alias typeof(_fun(.ElementType!R.init)) ElementType;
>     }
>
> Also, my example was just a little flawed (semantically speaking),
> since I was missing a return statement:
>
>     double[10] arr;
>     arr[] = 1.0;
>     auto result = map!((ref double sample){ return 1.0; })(arr[]);
>
> This will then work with that change.
>


More information about the Digitalmars-d-learn mailing list