Is there any problem with such closure implementation (stolen from python hack)?
void function(int value) {
struct closure {
closure(int v = value) : value_(value) {}
private: int value_;
};
closure c;
}
Upon further investigation, it appears in member functions, local variables can not be used as default values, but object variables can.
That looks like a good basis to make a closure. More of an idiom than a hack, since you’re legitimately using language features for their intended purpose.
Of course, your example doesn’t do anything. And it can only be used within
function.Gratuitous C++0x plug: