2 ms·
I rather like c++ closures in that they are pretty explicit about how capture works. Given the other concepts in the language it is absolutely necessary to cons
by asveikau 7y ago
I rather like c++ closures in that they are pretty explicit about how capture works. Given the other concepts in the language it is absolutely necessary to consider how closure capture works with the copy constructor, for example. I would contrast it with objc blocks, where capture is pretty implicit and sometimes feel ambiguous.
But I think that copy constructor is the root of a lot of evil performance penalty in c++. In the old days it was especially easy to over-allocate with vector or string. Move semantics fixed some of this. But passing around closures without a lot of care is also a consequence. An "easy" solution, to capture a shared_ptr, is not without its costs.
- gumby 7y agoYes, I often delete the copy constructor so that accidental copy cases become compile-time errors, though tttt that doesn’t seem to come up that often. I was bitten by a use-after-move last week but it was my own fault in some startup-time-order-of-initialization undefined behavior that the code was depending on that only worked on one compiler. It’s pretty uncommon.
- gpderetta 7y agoShared_ptr, the solution and cause of most performance problems :)