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)
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
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) {