#include <chrono>
#include <functional>
#include <future>
+#include <type_traits>
#include <utility>
#include <tests_common.h>
template <class Rep, class Period>
using Timeout = std::chrono::duration<Rep, Period>;
-template <class Ret, class... Args>
-using Function = std::function<Ret(Args...)>;
-
typedef std::function<void(void)> CancelFunction;
enum ExpectMode {
return os;
}
-template <class Rep, class Period, class Ret, class... Args>
-Ret callAndWait(const Timeout<Rep, Period> &timeout,
+template <class Rep, class Period, class F, class... Args>
+ typename std::result_of<F(Args...)>::type
+ callAndWait(const Timeout<Rep, Period> &timeout,
ExpectMode expect,
CancelFunction cancelFunction,
- Function<Ret, Args...> function,
- Args... args) {
- RUNNER_ASSERT_MSG(function,
- "not empty function must be passed to callAndWait");
+ F&& function,
+ Args&&... args) {
- std::future<Ret> fut = std::async(std::launch::async, function, std::forward<Args>(args)...);
+ auto fut = std::async(std::launch::async, function, std::forward<Args>(args)...);
std::future_status status = fut.wait_for(timeout);
if (status == std::future_status::timeout && cancelFunction)