Swift integer protocols should include typealias for signedness counterpart

Originator:brent
Number:rdar://18173851 Date Originated:29-Aug-2014 03:34 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta6 (6A280e)
Classification:Enhancement Reproducible:Always
 
Summary:
Swift.SignedIntegerType should include an Unsigned typealias, and Swift.UnsignedInteger should include a Signed typealias. This typealias would lead to that type’s same-sized counterpart.

Steps to Reproduce:
1. Write a generic function that takes, say, SignedIntegerType:

   func doSomeBitTwiddling <SignedInteger: SignedIntegerType> (x: SignedInteger)

2. Try to make it return a matching unsigned integer:

    -> SignedInteger.Unsigned

Expected Results:
You can.

Actual Results:
You can’t. The typealias doesn’t exist.

Notes:
In my case, I’m trying to avoid sign extension during resizing by converting to unsigned before doing certain bit-twiddling operations. This is impossible to do generically.

To that end, SignedIntegerType and UnsignedIntegerType should also include init(bitPattern: Self.Unsigned) or init(bitPattern: Self.Signed).

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!