/*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace folly {
-template <class> struct Promise;
+template <class> class Promise;
template <typename T>
struct isFuture : std::false_type {
- typedef T Inner;
+ using Inner = typename Unit::Lift<T>::type;
};
template <typename T>
namespace detail {
-template <class> struct Core;
-template <class...> struct VariadicContext;
+template <class> class Core;
+template <class...> struct CollectAllVariadicContext;
+template <class...> struct CollectVariadicContext;
template <class> struct CollectContext;
template<typename F, typename... Args>
template <bool isTry, typename F, typename... Args>
struct argResult {
- typedef resultOf<F, Args...> Result;
+ using Result = resultOf<F, Args...>;
};
template<typename F, typename... Args>
template<typename T,
typename = detail::resultOf<T, Args...>>
static constexpr std::true_type
- check(std::nullptr_t) { return std::true_type{}; };
+ check(std::nullptr_t) { return std::true_type{}; }
template<typename>
static constexpr std::false_type
- check(...) { return std::false_type{}; };
+ check(...) { return std::false_type{}; }
typedef decltype(check<F>(nullptr)) type;
static constexpr bool value = type::value;
typedef Future<typename ReturnsFuture::Inner> Return;
};
-template<typename F>
-struct callableResult<void, F> {
- typedef typename std::conditional<
- callableWith<F>::value,
- detail::argResult<false, F>,
- typename std::conditional<
- callableWith<F, Try<void>&&>::value,
- detail::argResult<true, F, Try<void>&&>,
- detail::argResult<true, F, Try<void>&>>::type>::type Arg;
- typedef isFuture<typename Arg::Result> ReturnsFuture;
- typedef Future<typename ReturnsFuture::Inner> Return;
-};
-
template <typename L>
struct Extract : Extract<decltype(&L::operator())> { };
typedef typename ArgType<Args...>::FirstArg FirstArg;
};
-} // detail
+// 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.
+// When compiling with gcc versions 4.9 and up, as well as clang, we do not
+// need to apply FunctionReferenceToPointer (i.e. T can be used instead of
+// FunctionReferenceToPointer<T>).
+// Applying FunctionReferenceToPointer first, the code works on all tested
+// compiler versions: gcc 4.8 and above, cland 3.5 and above.
+
+template <typename T>
+struct FunctionReferenceToPointer {
+ using type = T;
+};
+
+template <typename R, typename... Args>
+struct FunctionReferenceToPointer<R (&)(Args...)> {
+ using type = R (*)(Args...);
+};
+} // detail
-struct Timekeeper;
+class Timekeeper;
} // namespace