Swift: Allow extensions on generics

Originator:mail
Number:rdar://17251830 Date Originated:2014-06-10
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification:Enhancement Reproducible:
 
Summary:
It would be nice if you could do something like this:

extension <T: Comparable> {
  func clamped<T>(#min: T, max: T) {
    return self < min ? min : self > max ? max : self;
  }
  mutating func clamp<T>(#min: T, max: T) -> T {
    self = clamped(min: min, max: max)
    return self
  }
}

It would add the clamped() and clamp() functions to all types that are Comparable.

Steps to Reproduce:
-

Expected Results:
-

Actual Results:
-

Version:
Xcode 6 beta 1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!