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 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Is this a quiz or what ?  

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today