diff --git a/src/core/lib/promise/poll.h b/src/core/lib/promise/poll.h index 43509b49dfb..d55174e7441 100644 --- a/src/core/lib/promise/poll.h +++ b/src/core/lib/promise/poll.h @@ -186,19 +186,6 @@ class Poll; template class Poll>; -template -bool operator==(const Poll& a, const Poll& b) { - if (a.pending() && b.pending()) return true; - if (a.ready() && b.ready()) return a.value() == b.value(); - return false; -} - -template -Poll poll_cast(Poll poll) { - if (poll.pending()) return Pending{}; - return static_cast(std::move(poll.value())); -} - // PollTraits tells us whether a type is Poll<> or some other type, and is // leveraged in the PromiseLike/PromiseFactory machinery to select the // appropriate implementation of those concepts based upon the return type of a @@ -214,6 +201,44 @@ struct PollTraits> { static constexpr bool is_poll() { return true; } }; +template +bool operator==(const Poll& a, const Poll& b) { + if (a.pending() && b.pending()) return true; + if (a.ready() && b.ready()) return a.value() == b.value(); + return false; +} + +template +struct PollCastImpl; + +template +struct PollCastImpl> { + static Poll Cast(Poll&& poll) { + if (poll.pending()) return Pending{}; + return static_cast(std::move(poll.value())); + } +}; + +template +struct PollCastImpl::is_poll()>> { + static Poll Cast(U&& poll) { return Poll(T(std::move(poll))); } +}; + +template +struct PollCastImpl { + static Poll Cast(T&& poll) { return Poll(std::move(poll)); } +}; + +template +struct PollCastImpl> { + static Poll Cast(Poll&& poll) { return std::move(poll); } +}; + +template +Poll poll_cast(U poll) { + return PollCastImpl::Cast(std::move(poll)); +} + // Convert a poll to a string template std::string PollToString(