小编Lub*_*und的帖子

dart 中的 for-in 循环顺序

如果我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在任何地方找到具体的解释,谢谢。

for-in-loop dart

5
推荐指数
1
解决办法
5120
查看次数

在 C++ 中将 void 作为 labmda 的通用返回类型干净地处理

我正在尝试编写这样的函数:

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'. 有没有干净的方法?(希望能在大多数标准编译器中编译)?谢谢你。

c++ generics lambda

0
推荐指数
1
解决办法
68
查看次数

标签 统计

c++ ×1

dart ×1

for-in-loop ×1

generics ×1

lambda ×1