David Brown wrote:
On Sun, Mar 30, 2008 at 11:53:22AM -0700, Christopher Smith wrote:

Closures are somewhat useful, at least if the language has garbage
collection.

I find that an odd statement. You can use functors as closures already in C++ (C++0X just avoids it being so syntactically cumbersome), and I've done this a fair bit for at least 5 years. While aspects of C++ have, as always, proven to be annoying when doing this, memory management never really cropped up as a particular problem with functors. Can you give an example of how explicit memory management limits the usefulness of closures?

When closures become syntactical, the allocation becomes implicit.
Implicit allocation with explicit deallocation is very hard to get right.
Actually, C++ makes implicit deallocation easier than most languages, particularly in the cases where you have implicit allocation (copy by value). RAII really does make this aspect of the problem a non-issue.

I guess the one pain point would be if you grabbed a std::auto_ptr in your closure, but if you are using boost smart pointers instead you'll get bopped on the head immediately if you made such a mistake.

--Chris

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to