future: add futurize::make_exception_future()

Add a way to create an exceptional future of a type that is not directly
known.
This commit is contained in:
Avi Kivity
2015-07-17 16:08:28 +03:00
parent f2577c8af3
commit c1906a3d2a

View File

@@ -509,6 +509,10 @@ struct futurize {
/// and return the result, as a future (if it wasn't already).
template<typename Func, typename... FuncArgs>
static inline type apply(Func&& func, FuncArgs&&... args);
/// Makes an exceptional future of type \ref type.
template <typename Arg>
static type make_exception_future(Arg&& arg);
};
/// \cond internal
@@ -522,6 +526,9 @@ struct futurize<void> {
template<typename Func, typename... FuncArgs>
static inline type apply(Func&& func, FuncArgs&&... args);
template <typename Arg>
static type make_exception_future(Arg&& arg);
};
template <typename... Args>
@@ -534,6 +541,9 @@ struct futurize<future<Args...>> {
template<typename Func, typename... FuncArgs>
static inline type apply(Func&& func, FuncArgs&&... args);
template <typename Arg>
static type make_exception_future(Arg&& arg);
};
/// \endcond
@@ -967,6 +977,29 @@ typename futurize<future<Args...>>::type futurize<future<Args...>>::apply(Func&&
return func(std::forward<FuncArgs>(args)...);
}
template <typename T>
template <typename Arg>
inline
future<T>
futurize<T>::make_exception_future(Arg&& arg) {
return ::make_exception_future<T>(std::forward<Arg>(arg));
}
template <typename... T>
template <typename Arg>
inline
future<T...>
futurize<future<T...>>::make_exception_future(Arg&& arg) {
return ::make_exception_future<T...>(std::forward<Arg>(arg));
}
template <typename Arg>
inline
future<>
futurize<void>::make_exception_future(Arg&& arg) {
return ::make_exception_future<>(std::forward<Arg>(arg));
}
/// \endcond
#endif /* FUTURE_HH_ */