Re: Why not add a feature to let lambda reference itself?
On 3/11/12 8:02 AM, Roman W wrote:
On Saturday, March 10, 2012 7:22:22 PM UTC, Christopher Creutzig wrote:
No, see ?5.1.2.7:
| [?] for purposes of [?] determining the type and value of this
| (9.3.2) [?], the compound-statement is considered in the context of
| the lambda-expression.
Do you mean that "this" would always refer to the (possible) object
creating the lambda function?
Right. And, to be honest, I find that much more intuitive. It allows
writing something like this sketch:
class ButtonController {
// ...
public:
void attach(Button *b) {
// ...
b->setCallback([&b]() -> void { onClicked(b) });
}
protected:
virtual void onClicked(Button *b) = 0;
}
--
Der Erleuchtete rangiert in seiner von Selbstzweifeln freien
Erkenntnissicherheit nun einmal ?ber dem banal nur logisch Denkenden.
(Klaus-R. L?ffler)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]