通常,我不必将数组切片以将其视为范围.但是,当它作为模板别名参数传递时,我似乎这样做:
enum test(alias fun) = "it works";
immutable a = [1,2,3];
pragma(msg, test!(a[].map!(x => x))); // OK
pragma(msg, test!(a.map!(x => x))); // map is not a member of a
// but a.map does work at runtime ...
unittest {
auto r = a.map!(x => x);
}
Run Code Online (Sandbox Code Playgroud)
为什么是这样?