I'm having a bit of trouble using array
from std.array
to convert a MapResult
to a specific array type. My problem is as follows:
I have an array a
of objects, each of which has a publically-accessible field val
. I would like to use map
from std.algorithm
to go over a
and return an array of all the values of the val
members. My code looks something like this:
import std.algorithm:map;
import std.array:array;
//import for my object type, which I call Box here
ulong[] fun (Box[] a) {
return array!(ulong[])(map!(function ulong(Box x) {return x.val;})(a);
}
However, when I try to do this, the compiler gives me an error saying that array
cannot deduce the function from the argument types !(ulong[])(MapResult!(_funcliteral3,Box[]))
. Does that mean that MapResult
s aren't ranges, and is there a way to get what I want?
actually it means that the compiler believed that (ulong[])(MapResult!(_funcliteral3,Box[]))
was the template parameter instead of ulong[]
nest your parenthesis properly and it should be fixed
return array!(ulong[])(map!(function ulong(Box x) {return x.val;})(a));