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