Avatar
norio_nomura 6/9/2017 3:26 AM
Swift 4で + コメントアウトで <Int> になるような
3:29 AM
protocol Addable { associatedtype SomeType func sayHello() static func sayHello2(_ x: Self) -> Self static func + (a: Self, b: Self) -> Self } extension Addable { func sayHello() { print("hello<default>") } static func sayHello2(_ x: Self) -> Self { print("hello<default>"); return x } static func + (a: Self, b: Self) -> Self { print("add<default>"); return a } } extension Addable where SomeType == Int { func sayHello() { print("hello<Int>") } static func sayHello2(_ x: Self) -> Self { print("hello<Int>"); return x } static func + (a: Self, b: Self) -> Self { print("add<Int>"); return a } } struct Concrete<T>: Addable { typealias SomeType = T } let a = Concrete<Int>() a.sayHello() // prints hello<Int> _ = Concrete.sayHello2(a) // prints hello<Int> _ = a + a // prints add<default> ... why? (edited)
3:32 AM
operator func だけ where が効いてない。 (edited)