Add a _Hashable protocol

Originator:natecook
Number:rdar://18479532 Date Originated:9/27/2014
Status:Open Resolved:
Product:Xcode Product Version:6.1 beta 2
Classification:Enhancement Reproducible:Always
 
Summary:
Currently the `Hashable` protocol inherits from `Equatable` and adds the `hashValue: Int` property. Because of inheriting from Equatable, the Hashable protocol can only be used as a generic constraint, which means it isn't possible to write a generic function when you only need the hashValue from a group of objects, rather than an equality check.

The protocols would need to be:

protocol _Hashable {
    var hashValue: Int { get }
}

protocol Hashable: _Hashable, Equatable { }

Steps to Reproduce:
1. Open Xcode
2. Create a new playground
3. Enter the following code:

func combinedHashValue(args: _Hashable...) -> Int {
    return args.reduce(0) { $0 + $1.hashValue }
}


Expected Results:
The code would compile and return the sum of the hashValues.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!