Difference between normal for and range based for loop?

Difference between normal for and range based for loop?

What is the difference between these two loop? 

tbb::concurrent_vector<T> list;
tbb::parallel_for(tbb::blocked_range<size_t>(0, list.size()),
    [&](const tbb::blocked_range<size_t>& r)
    {
        for(size_t i = std::begin(r); i != std::end(r); ++i)
        {
            //Do something with list[i]
        }
    }
);

tbb::parallel_for(tbb::blocked_range<size_t>(0, list.size()),
    [&](const tbb::blocked_range<size_t>& r)
    {
        for(auto& l : list)
        {
            //Do something with l
        }
    }
);

2 帖子 / 0 全新
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项
Michel Lemay的头像

Is this a quiz or what ?  

Pretty obvious second loop won't give expected parallelism and is incorrect.

登陆并发表评论。