Swift.IntegerType should include min and max properties
| Originator: | brent | ||
| Number: | rdar://18173845 | Date Originated: | 29-Aug-2014 03:32 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta6 (6A280e) |
| Classification: | Enhancement | Reproducible: | Sometimes |
Summary:
IntegerType should require that conforming types implement min and max type properties. This would allow generic code to use these properties.
Steps to Reproduce:
1. Write a generic function that takes IntegerTypes (or (Signed|Unsigned)IntegerType).
func headroom<Integer: IntegerType> (x: Integer) -> Integer {
2. Try to use the generic type’s .max and .min properties:
return Integer.max - x
Expected Results:
You can do so.
Actual Results:
This is an error because these protocols don’t require min and max properties. Nor do any other protocols.
Notes:
I’m trying to write a generic “perform a truncating conversion” function, and I believe that doing this will require me to access at least IntegerType.max.
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!