News for hackers. Stuff that matters.
Re:Orthodox C++ by kllrnohj on Monday December 28, 2020 @10:43AM (#25560026)
But by doing that you'd be breaking the safety (and functionality) of shared_ptr as you'd end up with potentially dangling references (similarly weak pointers are broken). Which then raises the question of why are you using shared_ptr in the first place? You could use a custom allocator just for auditing that all outstanding references were released, I suppose, but actually releasing the memory anyway is just adding bugs. Which can be a fair risk to take, it just seems like shared_ptr is then not the thing you want to indicate appropriate "running with scissors" behavior.
Re:Orthodox C++ by gmueckl on Tuesday December 29, 2020 @08:51AM (#25569695)
As long as you can guarantee that no shared_ptr lives longer than its backing memory pool, it's perfectly fine. The same goes for every other kind of pointer wrapper you could dream up.

At least you can write a replacement for shared_ptr. The same is not true for std::function. This is the only named type a capturing lambda converts to according to the language standard and it's an STL type with complex behind the scenes behavior.

Re:Orthodox C++ by kllrnohj on Wednesday December 30, 2020 @12:42AM (#25578940)
You can write your own std::function, too, nor is it the only STL type that can take a capturing lambda (std::packaged_task for example).

A capturing lambda is just a class with an operator(). It's complicated to do what std::function does, but fully possible.

In fact, custom std::function replacements have better lambda support than std::function itself. Such as unique_function in https://github.com/Naios/function2 which can handle non-copyable lambdas.