【发布时间】:2009-07-02 18:09:56
【问题描述】:
Specman 有 apply() 方法对列表的所有元素执行相同的操作:
var a: list of int;
a = somefunction.that.returns.list.of.int();
var b:= a.apply(it * 2);
apply() 的作用与以下相同:
for each in a {
b.add(it.*2);
};
现在,如果我想在a 的元素上调用一个方法,我可以使用apply(),只要该方法返回一个值。但是,如果我有:
struct bar {
x: int;
foo() is {
message(LOW, "x is ", x);
};
};
我尝试这样做:
var a: list of bar;
a = somefunction.that.returns.list.of.bar();
a.apply(it.foo());
它无法编译,因为foo() 返回void。相反,我必须使用显式循环:
for each in a {
it.foo();
};
specman 中是否有类似于apply() 的不需要返回值的方法?
【问题讨论】: