The difference between closures and extensions

Can someone explain the difference between closures and continuations? Relevant wikipedia articles do not really compare the differences between them.

+6
source share
1 answer

Closing is a function that captures data from the environment in which it was declared.

int myVar = 0; auto foo = [&] () { myVar++; }; <- This lambda forms a closure by capturing myVar foo(); assert(myVar == 1); 

Continuation is a more abstract concept and relates to what code should be executed subsequently. It can be implemented using closure.

 myTask = Task([] () { something(); }); myTask.then([=] () { myFoo.bar(); }); // This closure is the continuation of the task myTask.run(); 
+6
source

Source: https://habr.com/ru/post/921568/


All Articles