From 544c17889148b36b2f22eec4cc40656a1d4a4046 Mon Sep 17 00:00:00 2001 From: Lukasz Wojciechowski Date: Wed, 11 Mar 2015 10:44:44 +0100 Subject: [PATCH] Use functor object as main argument of callAndWait Previous solution was based on std::function, that causes problems because std::function template arguments needed to be explicitely defined. Functor simplifies usage of callAndWait. Change-Id: If4f8a640848e41042e6841e49354510c08db5357 --- src/common/timeout.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/common/timeout.h b/src/common/timeout.h index 7e985ab..98662e1 100644 --- a/src/common/timeout.h +++ b/src/common/timeout.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -34,9 +35,6 @@ namespace Timeout { template using Timeout = std::chrono::duration; -template -using Function = std::function; - typedef std::function CancelFunction; enum ExpectMode { @@ -62,16 +60,15 @@ std::ostream& operator<<(std::ostream& os, const std::future_status &status) return os; } -template -Ret callAndWait(const Timeout &timeout, +template + typename std::result_of::type + callAndWait(const Timeout &timeout, ExpectMode expect, CancelFunction cancelFunction, - Function function, - Args... args) { - RUNNER_ASSERT_MSG(function, - "not empty function must be passed to callAndWait"); + F&& function, + Args&&... args) { - std::future fut = std::async(std::launch::async, function, std::forward(args)...); + auto fut = std::async(std::launch::async, function, std::forward(args)...); std::future_status status = fut.wait_for(timeout); if (status == std::future_status::timeout && cancelFunction) -- 2.7.4