In the jQuery version of Deferred (which C ++ calls "futures"), the method .then()takes as an argument a function whose signature does not contain futures. Whereas .then(), proposed for C ++ 17 ( see N3721 ), performs the function c futurein its signature.
Ie if I want to calculate f(g(x))"in the background", N3721 wants me to write
extern int f(int);
extern int g(int);
auto async_fg(int x) {
return std::async(f, x).then([](std::future<int> mid) {
return g(mid.get());
});
}
I am tempted to write a shell, for example:
template<class F>
auto futurize(F&& f) {
return [](auto mid) {
return std::forward<F>(f)(mid.get());
};
}
auto async_fg(int x) {
return std::async(f, x).then(futurize(g));
}
Both solutions seem uncomfortable; and besides, I don’t know the correct name for the operation, which I call "futurize" here. If this operation has been proposed before, what do people call it?
, , future<T> -
template<class T, class F>
auto future<T>::then_futurize(F&& f)
{
return this->then(futurize(std::forward<F>(f)));
}
auto async_fg(int x) {
return std::async(f, x).then_futurize(g);
}
() ? ( then_futurize, .)
(Javascript, Python, Ruby, ++ Boost, ++ Folly...); ++, , , .
, .then() X(future<Y>), X(Y); , . , .then() " " .then() , .