Commit 0e34d328 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

no need to overload return_value

Summary: No need to overload coroutine `promise_type::return_value` to handle initializer list expressions - just template and default the parameter.

Reviewed By: Orvid

Differential Revision: D26508901

fbshipit-source-id: 61c4a2225355b0044638cd89b9153d599317a453
parent 261d05eb
......@@ -1357,7 +1357,7 @@ struct Promise {
return {};
}
std::experimental::suspend_never final_suspend() const noexcept { return {}; }
template <typename U>
template <typename U = Value>
void return_value(U&& u) {
value_->emplace(static_cast<U&&>(u));
}
......
......@@ -642,7 +642,7 @@ struct OptionalPromise {
return {};
}
std::experimental::suspend_never final_suspend() const noexcept { return {}; }
template <typename U>
template <typename U = Value>
void return_value(U&& u) {
*value_ = static_cast<U&&>(u);
}
......
......@@ -102,7 +102,7 @@ class BlockingWaitPromise final : public BlockingWaitPromiseBase {
}
template <
typename U,
typename U = T,
std::enable_if_t<std::is_convertible<U, T>::value, int> = 0>
void return_value(U&& value) noexcept(
std::is_nothrow_constructible<T, U&&>::value) {
......
......@@ -159,9 +159,7 @@ class TaskPromise : public TaskPromiseBase {
exception_wrapper::from_exception_ptr(std::current_exception()));
}
void return_value(T&& t) { result_.emplace(static_cast<T&&>(t)); }
template <typename U>
template <typename U = T>
void return_value(U&& value) {
if constexpr (std::is_same_v<remove_cvref_t<U>, Try<StorageType>>) {
DCHECK(value.hasValue() || value.hasException());
......
......@@ -107,20 +107,13 @@ class InlineTaskPromise : public InlineTaskPromiseBase {
InlineTask<T> get_return_object() noexcept;
template <
typename Value,
typename Value = T,
std::enable_if_t<std::is_convertible<Value&&, T>::value, int> = 0>
void return_value(Value&& value) noexcept(
std::is_nothrow_constructible<T, Value&&>::value) {
result_.emplace(static_cast<Value&&>(value));
}
// Also provide non-template overload for T&& so that we can do
// 'co_return {arg1, arg2}' as shorthand for 'co_return T{arg1, arg2}'.
void return_value(T&& value) noexcept(
std::is_nothrow_move_constructible<T>::value) {
result_.emplace(static_cast<T&&>(value));
}
void unhandled_exception() noexcept {
result_.emplaceException(
folly::exception_wrapper::from_exception_ptr(std::current_exception()));
......
......@@ -87,7 +87,7 @@ class InlineTask {
public:
InlineTask get_return_object() { return InlineTask(this); }
template <typename U>
template <typename U = T>
void return_value(U&& value) {
*valuePtr_ = std::forward<U>(value);
}
......@@ -196,7 +196,7 @@ class InlineTaskAllocator {
return InlineTaskAllocator(this);
}
template <typename U>
template <typename U = T>
void return_value(U&& value) {
*valuePtr_ = std::forward<U>(value);
}
......
......@@ -96,7 +96,7 @@ class InlineTask {
public:
InlineTask get_return_object() { return InlineTask(this); }
template <typename U>
template <typename U = T>
void return_value(U&& value) {
*valuePtr_ = std::forward<U>(value);
}
......
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