0

Can someone explain to me what does this piece of code step by step? I found it in this topic : Segmentation fault on gcc caused by lambda wrapper over variadic template function call and I don't understand nothing :

template <typename TNode, typename... TNodes>
auto execute(TNode& n, TNodes&... ns)
    {      
        [&](){ n.execute(ns...); }();
    }

Especially the part : [&](){ n.execute(ns...); }();

Is there any connection with lambda calculus and programmation language like caml or ocaml?

Thank you in advance

Community
  • 1
  • 1
Fefux
  • 964
  • 5
  • 12

1 Answers1

1

This part [&](){ n.execute(ns...); }(); creates a new lambda and execute it directly. It is equal to:

auto temp= [&](){ n.execute(ns...); };
temp();

This part n.execute(ns...); is calling a member function called TNode::execute which accepts many parameters (variadic template argument) of the types TNodes...

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160