Can't use float array in map

Andrej Mitrovic andrej.mitrovich at gmail.com
Fri Jun 3 10:15:06 PDT 2011


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