[swift-users] Workaround for generics not currently supporting conditional conformance to a protocol
Howard Lovatt
howard.lovatt at gmail.com
Tue Nov 15 21:39:51 CST 2016
Hi All,
Does anyone have a good workaround for generics not currently supporting
conditional conformance to a protocol. As stated in the Generics Manifesto
something like this would be nice:
extension Array: Equatable where Element: Equatable {
static func ==(lhs: Array, rhs: Array) -> Bool { ... }
}
But I would currently write a wrapper, something like:
struct ArrayE<T: Equatable> {
var elements: [T]
}
extension ArrayE: Equatable {
static func ==(lhs: ArrayE, rhs: ArrayE) -> Bool { ... }
}
This can get unwieldy when there are a lot of conditional protocol
extensions required, i.e. wrappers round wrappers.
Is there a better way?
Thanks for any tips,
-- Howard.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161116/2a4a8132/attachment.html>
More information about the swift-users
mailing list