使用数组将MapResult转换为数组

Koz*_*oss 2 templates d

我在使用arrayfrom std.array转换MapResult为特定的数组类型时遇到了一些麻烦.我的问题如下:

我有一个a对象数组,每个对象都有一个可公开访问的字段val.我想使用mapfrom std.algorithm来遍历a并返回val成员的所有值的数组.我的代码看起来像这样:

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);
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试这样做时,编译器给我一个错误,说array不能从参数类型中推导出函数!(ulong[])(MapResult!(_funcliteral3,Box[])).这是否意味着MapResults不是范围,有没有办法得到我想要的东西?

rat*_*eak 5

实际上它意味着编译器认为这(ulong[])(MapResult!(_funcliteral3,Box[]))是模板参数而不是ulong[]

正确嵌套括号,它应该是固定的

return array!(ulong[])(map!(function ulong(Box x) {return x.val;})(a));
Run Code Online (Sandbox Code Playgroud)