typedef typename ArgType<Args...>::FirstArg FirstArg;
};
+template <typename R, typename... Args>
+struct Extract<R (*)(Args...)> {
+ typedef isFuture<R> ReturnsFuture;
+ typedef Future<typename ReturnsFuture::Inner> Return;
+ typedef typename ReturnsFuture::Inner RawReturn;
+ typedef typename ArgType<Args...>::FirstArg FirstArg;
+};
+
+template <typename R, typename... Args>
+struct Extract<R (&)(Args...)> {
+ typedef isFuture<R> ReturnsFuture;
+ typedef Future<typename ReturnsFuture::Inner> Return;
+ typedef typename ReturnsFuture::Inner RawReturn;
+ typedef typename ArgType<Args...>::FirstArg FirstArg;
+};
+
// gcc-4.8 refuses to capture a function reference in a lambda. This can be
// mitigated by casting them to function pointer types first. The following
// helper is used in Future.h to achieve that where necessary.
EXPECT_EQ(1, count);
}
+namespace {
+Future<int> onErrorHelperEggs(const eggs_t&) {
+ return makeFuture(10);
+}
+Future<int> onErrorHelperGeneric(const std::exception&) {
+ return makeFuture(20);
+}
+}
+
TEST(Future, onError) {
bool theFlag = false;
auto flag = [&]{ theFlag = true; };
EXPECT_NO_THROW(f.value());
}
+ // Function pointer
+ {
+ auto f = makeFuture()
+ .then([]() -> int { throw eggs; })
+ .onError(onErrorHelperEggs)
+ .onError(onErrorHelperGeneric);
+ EXPECT_EQ(10, f.value());
+ }
+ {
+ auto f = makeFuture()
+ .then([]() -> int { throw std::runtime_error("test"); })
+ .onError(onErrorHelperEggs)
+ .onError(onErrorHelperGeneric);
+ EXPECT_EQ(20, f.value());
+ }
+ {
+ auto f = makeFuture()
+ .then([]() -> int { throw std::runtime_error("test"); })
+ .onError(onErrorHelperEggs);
+ EXPECT_THROW(f.value(), std::runtime_error);
+ }
+
// No throw
{
auto f = makeFuture()