You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mesos.apache.org by "Kevin Klues (JIRA)" <ji...@apache.org> on 2016/02/05 21:59:39 UTC
[jira] [Updated] (MESOS-4611) Passing a lambda to dispatch() always
matches the template returning void
[ https://issues.apache.org/jira/browse/MESOS-4611?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kevin Klues updated MESOS-4611:
-------------------------------
Description:
The following idiom does not currently compile:
{code}
Future<Nothing> initialized = dispatch(pid, [] () -> Nothing {
return Nothing();
});
{code}
This seems non-intuitive because the following template exists for dispatch:
{code}
template <typename R>
Future<R> dispatch(const UPID& pid, const std::function<R()>& f)
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());
std::shared_ptr<std::function<void(ProcessBase*)>> f_(
new std::function<void(ProcessBase*)>(
[=](ProcessBase*) {
promise->set(f());
}));
internal::dispatch(pid, f_);
return promise->future();
}
{code}
However, lambdas cannot be implicitly cast to a corresponding std::function<R()> type.
To make this work, you have to explicitly type the lambda before passing it to dispatch.
{code}
std::function<Nothing()> f = []() { return Nothing(); };
Future<Nothing> initialized = dispatch(pid, f);
{code}
We should add template support to allow lambdas to be passed to dispatch() without explicit typing.
was:
The following idiom does not currently compile:
{code}
Future<Nothing> initialized = dispatch(pid, [] () -> Nothing {
return Nothing();
})
{code}
This seems non-intuitive because the following template exists for dispatch:
{code}
template <typename R>
Future<R> dispatch(const UPID& pid, const std::function<R()>& f)
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());
std::shared_ptr<std::function<void(ProcessBase*)>> f_(
new std::function<void(ProcessBase*)>(
[=](ProcessBase*) {
promise->set(f());
}));
internal::dispatch(pid, f_);
return promise->future();
}
{code}
To make this work, you have to explicitly type the lambda before passing it to dispatch.
{code}
std::function<Nothing()> f = []() { return Nothing(); };
Future<Nothing> initialized = dispatch(pid, f);
{code}
We should add template support to allow lambdas to be passed to dispatch() without explicit typing.
> Passing a lambda to dispatch() always matches the template returning void
> -------------------------------------------------------------------------
>
> Key: MESOS-4611
> URL: https://issues.apache.org/jira/browse/MESOS-4611
> Project: Mesos
> Issue Type: Bug
> Components: libprocess
> Reporter: Kevin Klues
> Labels: dispatch, libprocess, mesosphere
>
> The following idiom does not currently compile:
> {code}
> Future<Nothing> initialized = dispatch(pid, [] () -> Nothing {
> return Nothing();
> });
> {code}
> This seems non-intuitive because the following template exists for dispatch:
> {code}
> template <typename R>
> Future<R> dispatch(const UPID& pid, const std::function<R()>& f)
> {
> std::shared_ptr<Promise<R>> promise(new Promise<R>());
>
> std::shared_ptr<std::function<void(ProcessBase*)>> f_(
> new std::function<void(ProcessBase*)>(
> [=](ProcessBase*) {
> promise->set(f());
> }));
> internal::dispatch(pid, f_);
>
> return promise->future();
> }
> {code}
> However, lambdas cannot be implicitly cast to a corresponding std::function<R()> type.
> To make this work, you have to explicitly type the lambda before passing it to dispatch.
> {code}
> std::function<Nothing()> f = []() { return Nothing(); };
> Future<Nothing> initialized = dispatch(pid, f);
> {code}
> We should add template support to allow lambdas to be passed to dispatch() without explicit typing.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)