문제

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 MapResults 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));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top