第二课:Lambda expression
将前面的functor采用c++0x中的lambda实现如下:
void parallel_apply_foo(int a[], int n)
{
parallel_for(blocked_range<size_t>(0, n),
[=](const blocked_range<size_t>& r) {
for (size_t i = r.begin(); i != r.end(); ++i)
foo(a[i]);
});
}
|
其中Lambda参数意义:
[], no variables defines, using one will result in error
[x, &y], x is captured by value, y is captured by reference
[&], any external variables is implicitly captured by reference if used
[=], any external variables is implicitly captured by value if used
[&, x], x is captured by value, all others by reference
[=, &z], z is captured by reference, all others by value
阅读(1321) | 评论(0) | 转发(0) |