vendredi 25 août 2017

How std::function is implemented?

We had a discussion with colleagues on how std::function is implemented, and in particular, how a single std::function stores different lambdas. For example, in the code below lambda1 and lambda2 are variables of different types, and there can not be a data member in std::function class that stores lambdas by value, and obviously std::function does something more complicated than assigning a member to some value in its constructor and assignment operator:

auto lambda1 = []{};
auto lambda2 = []{};
std::function<void ()> f = lambda1;
f = lambda2;

So the question is what exactly it does?

Aucun commentaire:

Enregistrer un commentaire