News for hackers. Stuff that matters.
Re:Lambda expression comparison between C++11, C++14 and C++17 by hendzen on Saturday May 14, 2016 @06:39PM (#11698383)
What if you want to move some things, but copy others?

e.g.

  auto shared = std::make_shared<MySharedType>(...);
  auto unique = std::make_unique<MyOwnedType>(...);

  function_that_accepts_lambda([shared, u = std::move(unique)] {
      shared->foo(...); u->bar(...);
  });

  // Outer scope can still use shared.
  shared->foo(....);
Re:Lambda expression comparison between C++11, C++14 and C++17 by steveklabnik on Saturday May 14, 2016 @07:03PM (#11698461)
I am 99% sure this is identical:

    let on_heap = Box::new(...);
    let shared = Arc::new(...);

    let s = shared.clone();
    function_that_accepts_lambda(move || {
        on_heap.bar();
        s.foo();
    });
We have to make the extra s binding.

Also, my sibling is correct that Copy types will just be copied, not moved.

Re:Lambda expression comparison between C++11, C++14 and C++17 by vvanders on Saturday May 14, 2016 @06:46PM (#11698403)
If the type implements Copy they'll be implicitly copied when moved into the Rust closure(I think). Or you can declare a scope var and clone() manually.