Summary:
[Folly] 4-way overloads for `SemiFuture::value`.
Overload on the receiver reference category and `const`-qualification, deriving the return type reference category and `const`-qualification. Like `Optional`, `Try`, etc.
Differential Revision:
D6062006
fbshipit-source-id:
d7396cd4d4bb62e99445d5f61cb360898fa1c3f3
}
template <class T>
-typename std::add_lvalue_reference<T>::type SemiFuture<T>::value() {
+T& SemiFuture<T>::value() & {
throwIfInvalid();
return core_->getTry().value();
}
template <class T>
-typename std::add_lvalue_reference<const T>::type SemiFuture<T>::value() const {
+T const& SemiFuture<T>::value() const& {
throwIfInvalid();
return core_->getTry().value();
}
+template <class T>
+T&& SemiFuture<T>::value() && {
+ throwIfInvalid();
+
+ return std::move(core_->getTry().value());
+}
+
+template <class T>
+T const&& SemiFuture<T>::value() const&& {
+ throwIfInvalid();
+
+ return std::move(core_->getTry().value());
+}
+
template <class T>
inline Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && {
throwIfInvalid();
~SemiFuture();
- /** Return the reference to result. Should not be called if !isReady().
- Will rethrow the exception if an exception has been
- captured.
- */
- typename std::add_lvalue_reference<T>::type
- value();
- typename std::add_lvalue_reference<const T>::type
- value() const;
+ /// Returns a reference to the result, with a reference category and const-
+ /// qualification equivalent to the reference category and const-qualification
+ /// of the receiver.
+ ///
+ /// If moved-from, throws NoState.
+ ///
+ /// If !isReady(), throws FutureNotReady.
+ ///
+ /// If an exception has been captured, throws that exception.
+ T& value() &;
+ T const& value() const&;
+ T&& value() &&;
+ T const&& value() const&&;
/// Returns an inactive Future which will call back on the other side of
/// executor (when it is activated).
EXPECT_EQ(42, *up);
EXPECT_THROW(makeSemiFuture<int>(eggs).value(), eggs_t);
+
+ EXPECT_TYPE(std::declval<SemiFuture<int>&>().value(), int&);
+ EXPECT_TYPE(std::declval<SemiFuture<int> const&>().value(), int const&);
+ EXPECT_TYPE(std::declval<SemiFuture<int>&&>().value(), int&&);
+ EXPECT_TYPE(std::declval<SemiFuture<int> const&&>().value(), int const&&);
}
TEST(SemiFuture, hasException) {