You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2016/01/30 03:03:30 UTC
[2/2] mesos git commit: Added variadic template for process::await.
Added variadic template for process::await.
Previously, templates only existed to allow await to take either a
std::list of Futures, *exactly* 2 Futures as arguments, or *exactly* 3
Futures as arguments.
This commit removes the 2 and 3 argument templates and replaces them
with a variadic template that accepts an arbitrary number of Futures as
arguments.
Review: https://reviews.apache.org/r/42956/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fcc6f954
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fcc6f954
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fcc6f954
Branch: refs/heads/master
Commit: fcc6f95499559e55ebe6b0a5c5ca0665ad5c7742
Parents: 10f153e
Author: Kevin Klues <kl...@gmail.com>
Authored: Fri Jan 29 17:56:00 2016 -0800
Committer: Benjamin Mahler <be...@gmail.com>
Committed: Fri Jan 29 17:56:36 2016 -0800
----------------------------------------------------------------------
3rdparty/libprocess/include/process/collect.hpp | 62 +++++---------------
1 file changed, 16 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/fcc6f954/3rdparty/libprocess/include/process/collect.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/collect.hpp b/3rdparty/libprocess/include/process/collect.hpp
index 5c857ee..5a92b72 100644
--- a/3rdparty/libprocess/include/process/collect.hpp
+++ b/3rdparty/libprocess/include/process/collect.hpp
@@ -52,18 +52,8 @@ Future<std::list<Future<T>>> await(const std::list<Future<T>>& futures);
// Waits on each future specified and returns the wrapping future
// typed of a tuple of futures.
-// TODO(jieyu): Investigate the use of variadic templates here.
-template <typename T1, typename T2>
-Future<std::tuple<Future<T1>, Future<T2>>> await(
- const Future<T1>& future1,
- const Future<T2>& future2);
-
-
-template <typename T1, typename T2, typename T3>
-Future<std::tuple<Future<T1>, Future<T2>, Future<T3>>> await(
- const Future<T1>& future1,
- const Future<T2>& future2,
- const Future<T3>& future3);
+template <typename... Ts>
+Future<std::tuple<Future<Ts>...>> await(const Future<Ts>&... futures);
namespace internal {
@@ -243,43 +233,23 @@ inline Future<std::list<Future<T>>> await(
}
-template <typename T1, typename T2>
-Future<std::tuple<Future<T1>, Future<T2>>> await(
- const Future<T1>& future1,
- const Future<T2>& future2)
-{
- Future<Nothing> wrapper1 = future1
- .then([]() { return Nothing(); });
-
- Future<Nothing> wrapper2 = future2
- .then([]() { return Nothing(); });
-
- std::list<Future<Nothing>> futures = { wrapper1, wrapper2 };
-
- return await(futures)
- .then([=]() { return std::make_tuple(future1, future2); });
-}
-
-
-template <typename T1, typename T2, typename T3>
-Future<std::tuple<Future<T1>, Future<T2>, Future<T3>>> await(
- const Future<T1>& future1,
- const Future<T2>& future2,
- const Future<T3>& future3)
+template <typename... Ts>
+Future<std::tuple<Future<Ts>...>> await(const Future<Ts>&... futures)
{
- Future<Nothing> wrapper1 = future1
- .then([]() { return Nothing(); });
-
- Future<Nothing> wrapper2 = future2
- .then([]() { return Nothing(); });
-
- Future<Nothing> wrapper3 = future3
- .then([]() { return Nothing(); });
+ std::list<Future<Nothing>> wrappers = {
+ futures.then([]() { return Nothing(); })...
+ };
- std::list<Future<Nothing>> futures = { wrapper1, wrapper2, wrapper3 };
+ // TODO(klueska): Unfortunately, we have to use a lambda followed
+ // by a bind here because of a bug in gcc 4.8 to handle variadic
+ // parameters in lambdas:
+ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47226
+ auto f = [](const Future<Ts>&... futures) {
+ return std::make_tuple(futures...);
+ };
- return await(futures)
- .then([=]() { return std::make_tuple(future1, future2, future3); });
+ return await(wrappers)
+ .then(std::bind(f, futures...));
}
} // namespace process {