如何从地图转换MapResult!一组整数?

时间:2016-04-11 19:24:48

标签: algorithm int d

我需要将map!模板中的MapResult从类型auto隐式转换为int []。我该怎么办?

import std.stdio;
import std.conv;
import std.array;
import std.algorithm;

void main()
{
    string s = "1,3,5,6,8";

    int x [];
    // auto xx = s.split(",").map!(a => to!int(a)); // working code
     x = s.split(",").map!(a => to!int(a)); // not working
    writeln(x);
}

1 个答案:

答案 0 :(得分:5)

不可能隐式,但明确地使用array

int[] x = s.split(",").map!(a => a.to!int).array;