auto a = [](){}; auto b = [](){}; vector<decltype(a)> v; v.push_back(a); //ok v.push_back(b); //compiler error
a and b are of a different type.
I am wondering if each lambda function is really a kind of anonymous class, whenever we create a lambda function, we create a new class with a random name that is visible only to the compiler?
Yes, each lambda introduces its own unique type.
Now the same lambda can have several closures (lambda instances) associated with it in several ways. C ++ 14 type output returns the simplest:
auto nothing() { return []{}; }
, . , - .