Re: [swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Jens Persson via swift-users
That will not work since R can be different types depending on T (R == (T, T) for S2 and R == (T, T, T) for S3). I guess Swift would have to support generic associated type for it to work: protocol P { associatedtype R static func foo(_ v: T) -> R } struct S2 : P { typealias R = (U, U)

Re: [swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Slava Pestov via swift-users
Try using an associated type for the result of foo(): protocol P { associatedtype R static func foo(_ v: T) -> R } Slava > On Jul 7, 2017, at 1:50 AM, Jens Persson via swift-users > wrote: > > protocol P { > // … > // For example the following will not work: > // static func

[swift-users] How to add this generic static func as a protocol requirement?

2017-07-07 Thread Jens Persson via swift-users
protocol P { // … // For example the following will not work: // static func foo(_ v: T) -> R // Is there some other way? // … } struct S2 : P { static func foo(_ v: T) -> (T, T) { return (v, v) } } struct S3 : P { static func foo(_ v: T) -> (T, T, T) {