如果我for-in在 dart 中使用循环List,是否可以保证迭代的顺序正确?例如执行以下代码
List bars = getSomeListOfBars();
for(bar in bars){
foo(bar);
}
Run Code Online (Sandbox Code Playgroud)
与以下完全相同的方式?
List bars = getSomeListOfBars();
for(int i=0;i<bars.length;i++){
foo(bar[i]);
}
Run Code Online (Sandbox Code Playgroud)
我没有dart在任何地方找到具体的解释,谢谢。
我正在尝试编写这样的函数:
template <typename T>
void testActionBehavesIdentically(Foo& fooA, Foo& fooB, std::function<T(Foo&)> action)
if (std::is_same<T, void>::value)
{
// perform action even if T is void
action(fooA);
action(fooB);
}
else
{
// if T is not void, test also return values
T resultA = action(fooA);
T resultB = action(fooB);
CHECK_EQUAL(resultA, resultB);
}
// tests that the state of both foos is the same
CHECK_EQUAL(fooA, fooB);
}
Run Code Online (Sandbox Code Playgroud)
T有时在哪里void。编译(在 VS2019 上)失败并显示
error C2182: 'resultA': illegal use of type 'void'. 有没有干净的方法?(希望能在大多数标准编译器中编译)?谢谢你。