[swift-evolution] [proposal] default func ==(_:_:)

davesweeris at mac.com davesweeris at mac.com
Wed Jan 27 03:14:34 CST 2016


I’d expand that to allow any protocol to be annotated “@memberwise” or something, if their requirements can be satisfied in that manner.

Have we already talked about this? I can’t remember.

- Dave Sweeris

> On Jan 27, 2016, at 00:40, Jan E. Schotsman via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Feature name - provide default func ==(_:_:) for types declared Equatable
> 
> Author: Jan E.Schotsman
> 
> Introduction:
> 
> If all of a type's stored properties are Equatable it makes sense for Swift to provide a default equality implementation.
> 
> Motivation:
> 
> In a project where many large types are defined that need to be Equatable it gets cumbersome to write explicit equality functions for all types.
> 
> Proposed solution
> 
> If a type is declared Equatable, all its stored properties are Equatable and no func ==(_:_:) is defined by the developer the compiler will synthetisize a memberwise equality function.
> (Recursiveness of this procedure is almost automatic)
> 
> Impact on existing code
> 
> There is no impact on existing code. Equality functions equal to the default implementation can simply be removed.
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list