0

I am trying to import a code which uses tbb to my project but I don't understand the notation in parallel for loop.This is the first time I am seeing this notation and haven't seen anywhere else.

    tbb::parallel_for( 0, static_cast<int>(centers.size()), 1, [&](int k) {
        ColorRep center = centers[k];

What does "[&](int k)" mean here ? Is it kind of casting ?

Muhammet Ali Asan
  • 1,486
  • 22
  • 39

1 Answers1

2

It denotes a C++ lambda- specifically, one which implicitly captures local variables by reference and takes as argument int i.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • So can this be used in traditional for loop or it is specific to parallel for ? – Muhammet Ali Asan Feb 21 '15 at 10:43
  • @MuhammetAliAsan It's a generic c++ construct. Commonly seen used by std:for_each and its ilk. – Captain Giraffe Feb 21 '15 at 10:47
  • It's just a plain language feature that creates expressions out of functions that can reference local variables. It can be used in any context where a callable object is accepted. – Puppy Feb 21 '15 at 11:14