I’m searching for the simplest way to write a function
        func maybeEqual<T>(_ lhs:T, _rhs:T) -> Bool

where it returns lhs == rhs if T is equatable, and false, otherwise.
I tried

func maybeEqual<T>(_ lhs:T, _rhs:T) -> Bool {
    return false
}

func maybeEqual<T:Equatable>(_ lhs:T, _ rhs:T) -> Bool {
    return lhs == rhs
}

but that doesn’t work.  Is there a way to express a type not matching something?
Alternately, how can I write this?

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to