[swift-users] can we express "does not conform to a particular protocol"?
Zhao Xin
owenzx at gmail.com
Mon Jul 3 22:50:24 CDT 2017
In my own test, it seams that there is no way to test a type conforms to
Equatable or not.
`Protocol 'Equatable' can only be used as a generic constraint because it
has Self or associated type requirements`
Zhao Xin
On Tue, Jul 4, 2017 at 9:27 AM, David Baraff <davidbaraff at gmail.com> wrote:
> No, i want the equality function run if the two types are equatable, and
> false otherwise (even if you might deem them to be the same, e.g. two
> identical sets, because sets do not conform to equatable, or two identical
> classes, becauses classes are not (in general) equatable).
>
> So
> maybeEqual(3, 3) // true
> maybeEqual(3, 4) // false
> maybeEqual([1,2,3], [1,2,3]) // false (because arrays are not actual
> equatable)
>
> let d = [String:Any]()
> maybeEqual(d, d) // false because type(d) is not equatable even
> though obviously d is equal to itself
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170704/97b7cf31/attachment.html>
More information about the swift-users
mailing list