Swift.IntegerType should include endian handling stuff
| Originator: | brent | ||
| Number: | rdar://18173849 | Date Originated: | 29-Aug-2014 03:34 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta6 (6A280e) |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
Each IntegerType-conforming type implements a set of endian-handling features: big-endian and little-endian initializers and properties, plus a byteSwapped property. These should be declared in a protocol they all conform to.
Steps to Reproduce:
1. Declare a generic function that takes IntegerTypes:
func readIntegerFromPacket<Integer: IntegerType> (packet: [UInt8]) -> Integer {
let integerSizedThing: Integer = readRawIntegerFromPacket(packet)
2. Try to use one of the endianness features:
return integerSizedThing.bigEndian
}
Expected Results:
You can.
Actual Results:
You can’t. This behavior is not part of any protocol, even though all integer types have identically-named and identically-functioning members for this function.
Notes:
This could be part of the IntegerType protocol, but it might actually make sense to put it in a separate protocol that both IntegerType and FloatingPointType conform to, and to add endian-handling functionality to the floating-point types.
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!