I am working with the memory of some lambdas in C++, but I am a bit puzzled by their size.
Here is my test code:
#include <iostream>
#include <string>
int main()
{
auto f = [](){ return 17; };
std::cout << f() << std::endl;
std::cout << &f << std::endl;
std::cout << sizeof(f) << std::endl;
}
You can run it here: http://cpp.sh/72zk
The ouptut is:
17
0x7d90ba8f626f
1
This suggests that the size of my lambda is 1.
-
How is this possible?
-
Shouldn't the lambda be, at minimum, a pointer to its implementation?
Aucun commentaire:
Enregistrer un commentaire