d不要求opApply()为域
规范显示按域声明闭包,但编译器不强制.
struct S {
int opApply (/*scope*/ int delegate (int* ptr) @safe dg) @safe {
return 0;
}//无域.
}
void test(S s) @safe {
foreach (int* x; s)
{
}
}
编译无误.
规范说:最佳实践是尽量用域注解闭包参数.
浙公网安备 33010602011771号