Commit 943408f5 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

4-way overloads for SemiFuture::value

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
parent 4e2b0bb9
...@@ -247,19 +247,33 @@ SemiFuture<T>::~SemiFuture() { ...@@ -247,19 +247,33 @@ SemiFuture<T>::~SemiFuture() {
} }
template <class T> template <class T>
typename std::add_lvalue_reference<T>::type SemiFuture<T>::value() { T& SemiFuture<T>::value() & {
throwIfInvalid(); throwIfInvalid();
return core_->getTry().value(); return core_->getTry().value();
} }
template <class T> template <class T>
typename std::add_lvalue_reference<const T>::type SemiFuture<T>::value() const { T const& SemiFuture<T>::value() const& {
throwIfInvalid(); throwIfInvalid();
return core_->getTry().value(); 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> template <class T>
inline Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && { inline Future<T> SemiFuture<T>::via(Executor* executor, int8_t priority) && {
throwIfInvalid(); throwIfInvalid();
......
...@@ -82,14 +82,19 @@ class SemiFuture { ...@@ -82,14 +82,19 @@ class SemiFuture {
~SemiFuture(); ~SemiFuture();
/** Return the reference to result. Should not be called if !isReady(). /// Returns a reference to the result, with a reference category and const-
Will rethrow the exception if an exception has been /// qualification equivalent to the reference category and const-qualification
captured. /// of the receiver.
*/ ///
typename std::add_lvalue_reference<T>::type /// If moved-from, throws NoState.
value(); ///
typename std::add_lvalue_reference<const T>::type /// If !isReady(), throws FutureNotReady.
value() const; ///
/// 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 /// Returns an inactive Future which will call back on the other side of
/// executor (when it is activated). /// executor (when it is activated).
......
...@@ -77,6 +77,11 @@ TEST(SemiFuture, value) { ...@@ -77,6 +77,11 @@ TEST(SemiFuture, value) {
EXPECT_EQ(42, *up); EXPECT_EQ(42, *up);
EXPECT_THROW(makeSemiFuture<int>(eggs).value(), eggs_t); 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) { TEST(SemiFuture, hasException) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment