-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/46686/#review136157
-----------------------------------------------------------
Another approach would be to:
```
template <typename F, typename R = typename result_of<F()>::type>
auto dispatch(const UPID& pid, F&& f)
-> decltype(internal::Dispatch<R>()(pid, std::forward<F>(f)))
{
return internal::Dispatch<R>()(pid, std::forward<F>(f));
}
```
and to provide specializations for all 3 cases:
```
namespace internal {
template <typename R> struct Dispatch;
template <> struct Dispatch<void> { ... };
template <typename R> struct Dispatch<Future<R>> { ... };
template <typename R> struct Dispatch { ... };
} // namespace internal {
```
This way we don't have the `std::function<void()>` case, and it's a more
consistent with the overloads defined above.
3rdparty/libprocess/include/process/dispatch.hpp (line 390)
<https://reviews.apache.org/r/46686/#comment201181>
Please use `result_of` defined in
`3rdparty/stout/include/stout/result_of.hpp`. We had to introduce it for MSVC
limitations.
3rdparty/libprocess/include/process/dispatch.hpp (lines 392 - 395)
<https://reviews.apache.org/r/46686/#comment201182>
We could simply do:
```c++
Future<typename internal::unwrap<R>::type> dispatch(
const UPID& pid, const F& f)
{
auto promise =
std::make_shared<Promise<typename internal::unwrap<R>::type>>();
std::shared_ptr<std::function<void(ProcessBase*)>> f_(
new std::function<void(ProcessBase*)>(
[=](ProcessBase*) {
promise->set(f());
}));
internal::dispatch(pid, f_);
return promise->future();
}
```
- Michael Park
On April 26, 2016, 9:21 a.m., haosdent huang wrote:
>
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/46686/
> -----------------------------------------------------------
>
> (Updated April 26, 2016, 9:21 a.m.)
>
>
> Review request for mesos, Kevin Klues and Michael Park.
>
>
> Bugs: MESOS-4611
> https://issues.apache.org/jira/browse/MESOS-4611
>
>
> Repository: mesos
>
>
> Description
> -------
>
> Allowed to pass lambda in `dispatch`.
>
>
> Diffs
> -----
>
> 3rdparty/libprocess/include/process/dispatch.hpp
> a4c35b2a5668df79415dc5156358df3cd0621d11
>
> Diff: https://reviews.apache.org/r/46686/diff/
>
>
> Testing
> -------
>
>
> Thanks,
>
> haosdent huang
>
>