Merge pull request #39492 from AnthonyLatsis/se-309-2

SE-309: Covariant erasure for dependent member types
This commit is contained in:
Anthony Latsis
2022-02-02 07:07:17 +03:00
committed by GitHub
37 changed files with 2538 additions and 956 deletions

View File

@@ -42,7 +42,7 @@ namespace swift {
template<typename U>
/*implicit*/ OptionalEnum(
U &&value,
typename std::enable_if<!std::is_integral<U>::value>::type * = {})
typename std::enable_if<std::is_convertible<U, T>::value>::type * = {})
: Storage(static_cast<storage_type>(T{std::forward<U>(value)}) + 1) {
assert(hasValue() && "cannot store this value");
}
@@ -82,6 +82,32 @@ namespace swift {
assert(Storage == (storage_type)(intptr_t)Storage);
return (intptr_t)Storage;
}
// Provide comparison operators for the optional value.
friend bool operator==(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return (!lhs && !rhs) || (lhs && rhs && lhs.getValue() == rhs.getValue());
}
friend bool operator!=(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return !(lhs == rhs);
}
friend bool operator<(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return rhs && (!lhs || lhs.getValue() < rhs.getValue());
}
friend bool operator>(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return rhs < lhs;
}
friend bool operator<=(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return !(rhs < lhs);
}
friend bool operator>=(const OptionalEnum &lhs, const OptionalEnum &rhs) {
return !(lhs < rhs);
}
};
} // end namespace swift