mercredi 22 avril 2020

How does the compiler generate a closure from a deleted-default-ctor lambda?

I want to know how a lambda with a deleted-default constructor can be used this way:

[](){}; // how is this translated by the compiler?

But this doesn't work:

auto l = [](){std::cout << "lambda expr\n";}; // which ctor is invoked?

decltype (l) g; // doesn't work
  • Because prior to C++ 20 it doesn't work but C++ 20 makes lambda default-constructible.

  • If there is no constructor to call, how is it that object comes into existance?

Aucun commentaire:

Enregistrer un commentaire