0

In Swift, one can extend a sequence that contains elements of a particular type, e.g.:

extension SequenceType where Generator.Element == Rect {
  func intersection() -> Rect? { ... }
}

// when using
let intersection = [rect1, rect2, rect3].intersection()

which is nice. However, how can I do the same thing if Rect itself is a generic type (e.g. Rect<Float>, Rect<Double> etc.)? I tried

extension SequenceType where Generator.Element == Rect<T>

but the compiler complains about 'undeclared type T'. I can't quite figure out where to put it. Right now, I have to specialise for every floating-point type.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
MrMobster
  • 1,851
  • 16
  • 25
  • 1
    This looks quite similar: http://stackoverflow.com/questions/33357346/extending-a-protocol-where-self-generic-type-in-swift-requires-arguments-in. – Martin R Apr 05 '16 at 12:31
  • Thank you for the reference! This must be one of those NYI type system features then. – MrMobster Apr 05 '16 at 13:03

0 Answers0