Chinaunix首页 | 论坛 | 博客
  • 博客访问: 457145
  • 博文数量: 143
  • 博客积分: 6159
  • 博客等级: 准将
  • 技术积分: 1667
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-25 23:08
文章分类

全部博文(143)

文章存档

2013年(1)

2012年(11)

2011年(55)

2010年(76)

分类:

2010-11-27 10:21:17

第二课: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



阅读(1276) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~