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() {
}
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();
......
......@@ -82,14 +82,19 @@ class SemiFuture {
~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).
......
......@@ -77,6 +77,11 @@ TEST(SemiFuture, value) {
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) {
......
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