Separating the initial value (and accumulator) from the reducer function
can result in simpler invocations.
Unfortunately, the name conflicts with another variant, so we have to name
the method map_reduce0.
distributed::stop() passes the pointer to the instance being destroyed
by reference, in an attempt to keep things clean (by nulling the pointer
after deleting it). This is illegal, however, since the lambda is moved
in the bowels of submit_to(). In release mode this is optimized away so
the code works, but in debug mode it leads to a crash.
Fix by capturing by value instead (could also have been fixed by switching
the enclosing capture to a reference).
Credit to Gleb for identifying the problem.
Makes invoking non-copyable lambdas possible:
distributed<T> t;
non_copyable_type x;
t.invoke_on(0, [x = std::move(x)] (auto& t) {});
As a side effect this could save some copyable lambdas from being
needlesly copied.
Current variants of distributed<T>::invoke_on() require member function to
invoke, which may be tedious to implement for some cases. Add a variant
that supports invoking a functor, accepting the local instance by reference.