std::bind can express the same thing, but the construct is an example of job security through code obsecurity. ——“job security through code obsecurity”。某群经常有人提到这个现象,但这个词总结得更好玩。
By default, the operator() member function inside the closure class generated from a lambda is const. ——Unless you explicitly declare the lambda as mutable: []() mutable {} That has the effect of rendering all the data members in the closure const within the body of the lambda.
A bind object contains copies of all the arguments passed to std::bind. For each lvalue argument, the corresponding object in the bind object is copy constructed. For each rvalue, it's move constructed.
Lambdas may be dependent not just on local variabls and parameters (which may be captured), but also on objects with static storage duration. Such objects are defined at global or namespace scope or are declared static inside classes, functions, or files. These objects can be used inside lambdas, but they can't be captured.
A by-reference capture causes a closure to contain a reference to a local variable or to a parameter that's available in the scope where the lambda is defined.
There are two default capture modes in C++11: by-reference and by-value. Default by-reference capture can lead to dangling references. Default by-value capture lures you into thinking you are immune to that problem (you're not), and it lulls you into thinking your closures are self-contained (they may not be).
晨星
2019-09-11 00:33:47
晨星
2019-09-08 18:42:20
晨星
2019-09-08 18:37:54
晨星
2019-09-08 18:32:22
晨星
2019-09-08 18:31:18
晨星
2019-09-08 18:30:23
晨星
2019-09-08 18:20:34
晨星
2019-09-08 18:15:39
晨星
2019-09-07 00:22:59
晨星
2019-09-07 00:20:49