【发布时间】:2015-11-18 12:16:00
【问题描述】:
http://dpaste.dzfl.pl/76c79f1f12ab
void main(){
import std.container;
import std.stdio;
import std.algorithm.iteration;
import std.range;
Array!int ai = [1,2,3,4];
Array!int ai1 = [1,2,3,4];
Array!int ai2 = [1,2,3,4];
auto arange = lockstep(ai[],ai1[]);
arange.each!((a,b) => writeln(a, b));
auto arange2 = lockstep(ai[],ai1[],ai2[]);
arange2.each!((a,b,c) => writeln(a, b, c));
}
错误:模板 std.algorithm.iteration.each 不能推导出函数 从参数类型 !((a, b, c) => writeln(a, b, c))(Lockstep!(RangeT!(Array!int), RangeT!(Array!int), RangeT!(Array!int))),候选对象是: /opt/compilers/dmd2/include/std/algorithm/iteration.d(820):
std.algorithm.iteration.each(别名 pred = "a")
arange 有效,但 arange2 无效,因为编译器无法推断该函数。即使我显式添加参数类型也会出现错误。
【问题讨论】:
-
看起来
each被硬连线以接受一元或二元函数,可能是因为它仍然尝试使用unaryFun和@987654330 来支持字符串样式的lambdas (.each!"a++") @.
标签: d