相关疑难解决方法(0)

在嵌套的Lambda中捕获Lambda的静态

这个答案中,我使用此代码:

std::vector<std::vector<int>> imat(3, std::vector<int>(10));

std::for_each(imat.begin(), imat.end(), [&](auto& i) {
    static auto row = 0;
    auto column = 0;
    std::transform(i.begin(), i.end(), i.begin(), 
        [&](const auto& /*j*/) {
            return row * column++; 
    }); 

    ++row; 
});
Run Code Online (Sandbox Code Playgroud)

但我注意到static auto row根据编译器捕获的一些不当行为.

Clang 3.7.0收益率:

0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9
0 2 4 6 8 10 12 14 16 18

gcc 5.1.0产量:

0 0 0 0 0 …

c++ lambda capture language-lawyer c++14

13
推荐指数
1
解决办法
589
查看次数

标签 统计

c++ ×1

c++14 ×1

capture ×1

lambda ×1

language-lawyer ×1