3 ms·
I like that in C++11, you specify what should be captured and how it should be captured (by value or by reference).
by dkersten 10y ago
I like that in C++11, you specify what should be captured and how it should be captured (by value or by reference).
- masklinn 10y agoRust is the same, though it's less flexible[0]: it doesn't have capture lists, only [&] and [=], and they're very slightly different: * the default is similar to [&] but will infer the capture mode and use the "simplest" possible one (reference, mutable reference or value) depending on use on a per-value basis. * `move` closures are similar to [=] but will use Rust ownership semantics, so they will copy Copy values and move non-Copy values, it can capture external references (mutable or not) by value so if you needed to explicitly tweak your capture that's the one you'd use. [0] OTOH it's more readable
- steveklabnik 10y agoI'm not sure that "less flexible" is accurate; we can accomplish the same things, but through different means.
- masklinn 10y agoIt might have been unclear, but I meant the closure syntax/capture itself is less flexible. You can get the same result e.g. using a move closure and declaring references outside the closure then capturing that by value, but I'm sure you could also do that in C++.
- steveklabnik 10y agoAh, yes. Cool :)