Slide 35
Slide 35 text
࣮ࡍͷ4XJGUʹ͓͚ΔEquatableͱComparableͷఆٛ
// ࣮ࡍͷ Equatable ͱ Comparable ͷఆٛ
protocol Equatable {
static func == (lhs: Self, rhs: Self) -> Bool
}
protocol Comparable: Equatable {
static func < (lhs: Self, rhs: Self) -> Bool
}
struct AStruct {
var p: Int
}
extension AStruct: Equatable {
static func == (lhs: AStruct, rhs: AStruct) -> Bool {
return lhs.p == rhs.p
}
}
extension AStruct: Comparable {
static func < (lhs: AStruct, rhs: AStruct) -> Bool {
return lhs.p < rhs.p
}
}