3 ms·
For all such examples of using closures there are alternative implementations that use more efficient mechanisms. For examples like this, if it is not desired
by adrian_b 3y ago
For all such examples of using closures there are alternative implementations that use more efficient mechanisms.
For examples like this, if it is not desired to use a single function with one extra parameter, then multiple functions that differ in using some different constants or different private static variables can be generated by some template mechanism, without using closures.
The problem with closures is that they introduce an overhead in any function that is passed as a parameter or used for some other reason through a pointer, by adding an extra indirection, even if in most cases this is not needed, instead of adding overhead only in the few cases when capturing local variables is really useful (unless something like whole program optimization is used).