In the following code, assigning to an std function results in more copy constructor calls than assigning to an auto variable. ( actually initializing, not assigning ;) )
I get that a value captured local must be copied.
I get that each time i assign it to a new std::function an extra copy will be needed.
But why is there a difference between initializing an auto var and and a function var?
#include <iostream>
#include <functional>
using namespace std;
struct A { A()=default; A(const A&) {cout << "CC\n";} };
int main()
{
A a1;
//auto f = [a1] (){}; // just 1 CC
//[a1] (){}; // just 1 CC
function<void()> f=[a1] (){}; // 2 CC
return 0;
}