News for hackers. Stuff that matters.
Re:Custom Deleters for C++ Smart Pointers by bennofs on Thursday April 28, 2016 @10:24AM (#11589055)
Couldn't you do something like `auto x = make_on_scope_exit([]() { ... });`?
Re:Custom Deleters for C++ Smart Pointers by toth on Thursday April 28, 2016 @10:40AM (#11589182)
Yes, you are right, I am wrong! That works just fine. For the record:

   template<typename T>
   struct OnScopeExit {
       OnScopeExit(T f) :  f_(f) {};
       ~OnScopeExit() { f_();};
       T f_;
   };

   template<typename T>
   OnScopeExit<T> make_scope_exit(T f) { return OnScopeExit<T>(f); }
And then you use it as

    auto x = make_scope_exit([]() { std::cout << "Exitced Scope!" << std::endl; });
Re:Custom Deleters for C++ Smart Pointers by corysama on Thursday April 28, 2016 @11:54AM (#11589783)
Alexandrescu at CPPCon2015 describes how he does ScopeExit starting at 18 minutes into this video

http://youtu.be/WjTrfoiB0MQ

Re:Custom Deleters for C++ Smart Pointers by kzhahou on Thursday April 28, 2016 @03:38PM (#11591405)
With all due respect to Alexandrescu's incredible C++ skills, I find that his style of programming is very detrimental to the overall quality of the C++ environment.

C++ is a very abusable language. This is reflected both in its capabilities and in the ability to shoot yourself in the foot. These points are obviously well-covered in any C++ discussion.

Now, Alexandrescu brings a style of programming in which you exploit templates, sometimes macros, operator overloading, and everything else, in order to squeeze out more generality/reusability out of a piece of code, or simplify the coder-visible syntax of some construct.

We see that right here: the above comments show a few ways to run arbitrary code on a scope exit. Each of the examples above is perfectly easy to follow along. But then the YouTube video show's Alexandrescu's take, and it's a real brain-warper. He invokes a couple of levels of C++ trickery to get his effect. Now, his end result is wonderful... but it's also not easily understandable. If you write code in his style at your job, good luck to the person that takes over your code after you leave the project. They'll have a hell of a time.

IMHO a developer should always sacrifice syntactic sugar, with no performance penalty if done correctly, in exchange for more understandable code.

Re:Custom Deleters for C++ Smart Pointers by pklausler on Thursday April 28, 2016 @02:10PM (#11590806)
You can omit the "auto x =", too.