3 ms·
It is: "zero-overhead" is defined to mean you could not open-code it yourself any better. If you specify a capture-by-copy, you have specified a copy. If that
by ncmncm 5y ago
It is: "zero-overhead" is defined to mean you could not open-code it yourself any better.
If you specify a capture-by-copy, you have specified a copy. If that copy involves an allocation, you have specified an allocation. There is exactly zero extra overhead: in the overwhelmingly most common uses, not even a call through a pointer.
The good news is that the compiler knows all about lambdas, so can optimize the hell out of them.
- Koshkin 5y agoBy "careful" I mean avoiding unnecessary use or the temptation of capturing "everything." All too often I see people get enamored with it or fall into the trap of following patterns popular in other, slower, languages.