Avatar
こういうことだと思うんです
2:53 PM
やっぱり呼び出し元でEquatableが見えてないとAnyEquatableを作った瞬間にfalse側に倒れちゃいますね。上位から伝播させなければいけない
2:54 PM
@swift-5.1.5 protocol AnyEquatableBase { associatedtype Value var value: Value { get } func isEqual(to other: Self) -> Bool } extension AnyEquatableBase { func isEqual(to other: Self) -> Bool { false } } extension AnyEquatableBase where Value: Equatable { func isEqual(to other: Self) -> Bool { value == other.value } } struct AnyEquatable<T>: AnyEquatableBase { var value: T } func check<T>(lhs: T, rhs: T) -> Bool { AnyEquatable(value: lhs).isEqual(to: AnyEquatable(value: rhs)) } print(check(lhs: "test", rhs: "test"))