Casting MapResult

jmh530 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 15 08:10:20 PDT 2015


I wrote a simple function to apply map to a float dynamic array

auto exp(float[] x) {
	auto y = x.map!(a => exp(a));
	return y;
}

However, the type of the result is MapResult!(__lambda2, 
float[]). It seems like some of the things that I might do to a 
float[], I can't do to this type, like adding them together. So I 
tried to adjust this by adding in a cast to float[], as in

float[] exp(float[] x) {
	auto y = x.map!(a => exp(a));
	cast(float[]) y;
	return y;
}

But I get an error that I can't convert MapResult!(__lambda2, 
float[]) to float[].

So I suppose I have two questions: 1) am I screwing up the cast, 
or is there no way to convert the MapResult to float[], 2) should 
I just not bother with map (I wrote an alternate, longer, version 
that doesn't use map but returns float[] properly).


More information about the Digitalmars-d-learn mailing list