Commit 3a129426 authored by Lewis Baker's avatar Lewis Baker Committed by Facebook Github Bot

Move decay_rvalue_reference_t metafunction to folly/experimental/coro/detail/Traits.h

Summary:
Make this metafunction available for use outside of the
folly::coro::blockingWait() implementation.

I plan to reuse this metafunction for other operators such as `when_all()`.

Reviewed By: yfeldblum

Differential Revision: D13778687

fbshipit-source-id: f766f93da21bf19e89262cd60048b0b7b1b76940
parent a79183e4
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <folly/experimental/coro/Task.h> #include <folly/experimental/coro/Task.h>
#include <folly/experimental/coro/Traits.h> #include <folly/experimental/coro/Traits.h>
#include <folly/experimental/coro/ViaIfAsync.h> #include <folly/experimental/coro/ViaIfAsync.h>
#include <folly/experimental/coro/detail/Traits.h>
#include <folly/fibers/Baton.h> #include <folly/fibers/Baton.h>
#include <folly/synchronization/Baton.h> #include <folly/synchronization/Baton.h>
...@@ -251,23 +252,12 @@ BlockingWaitPromise<void>::get_return_object() noexcept { ...@@ -251,23 +252,12 @@ BlockingWaitPromise<void>::get_return_object() noexcept {
BlockingWaitPromise<void>>::from_promise(*this)}; BlockingWaitPromise<void>>::from_promise(*this)};
} }
template <typename T>
struct decay_rvalue_reference {
using type = T;
};
template <typename T>
struct decay_rvalue_reference<T&&> : std::decay<T> {};
template <typename T>
using decay_rvalue_reference_t = typename decay_rvalue_reference<T>::type;
template < template <
typename Awaitable, typename Awaitable,
typename Result = await_result_t<Awaitable>, typename Result = await_result_t<Awaitable>,
std::enable_if_t<!std::is_lvalue_reference<Result>::value, int> = 0> std::enable_if_t<!std::is_lvalue_reference<Result>::value, int> = 0>
auto makeBlockingWaitTask(Awaitable&& awaitable) auto makeBlockingWaitTask(Awaitable&& awaitable)
-> BlockingWaitTask<decay_rvalue_reference_t<Result>> { -> BlockingWaitTask<detail::decay_rvalue_reference_t<Result>> {
co_return co_await static_cast<Awaitable&&>(awaitable); co_return co_await static_cast<Awaitable&&>(awaitable);
} }
...@@ -276,7 +266,7 @@ template < ...@@ -276,7 +266,7 @@ template <
typename Result = await_result_t<Awaitable>, typename Result = await_result_t<Awaitable>,
std::enable_if_t<std::is_lvalue_reference<Result>::value, int> = 0> std::enable_if_t<std::is_lvalue_reference<Result>::value, int> = 0>
auto makeBlockingWaitTask(Awaitable&& awaitable) auto makeBlockingWaitTask(Awaitable&& awaitable)
-> BlockingWaitTask<decay_rvalue_reference_t<Result>> { -> BlockingWaitTask<detail::decay_rvalue_reference_t<Result>> {
co_yield co_await static_cast<Awaitable&&>(awaitable); co_yield co_await static_cast<Awaitable&&>(awaitable);
} }
......
/*
* Copyright 2019-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/Traits.h>
namespace folly {
namespace coro {
namespace detail {
/**
* A type trait to decay rvalue-reference types to a prvalue.
*/
template <typename T>
struct decay_rvalue_reference {
using type = T;
};
template <typename T>
struct decay_rvalue_reference<T&&> : remove_cvref<T> {};
template <typename T>
using decay_rvalue_reference_t = typename decay_rvalue_reference<T>::type;
} // namespace detail
} // namespace coro
} // namespace folly
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