Lambdas v Closures

Scott Meyers posted this explanation of the difference between a lambda and a closure.

The distinction between a lambda and the corresponding closure is precisely equivalent to the distinction between a class and an instance of the class. A class exists only in source code; it doesn’t exist at runtime. What exists at runtime are objects of the class type. Closures are to lambdas as objects are to classes. This should not be a surprise, because each lambda expression causes a unique class to be generated (during compilation) and also causes an object of that class type–a closure–to be created (at runtime).

He also managed to squeeze in mention of Universal References (in the context of the managing the lifetime of a closure).

1 Comment

Filed under C++, Programming

One response to “Lambdas v Closures

Leave a reply to justanotherhumanoid Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.