Swift Indexes shuld be comparable

Originator:brent
Number:rdar://17768142 Date Originated:22-Jul-2014 01:55 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta4 (6A267n)
Classification:Enhancement Reproducible:Always
 
Summary:
It is impossible to tell if one ForwardIndex or BidirectionalIndex comes before or after another. This makes certain algorithms quite difficult to write.

Steps to Reproduce:
1. Try to implement this function in a playground. It should return the distance, whether positive or negative, between two indexes:

    func - <IndexType: BidirectionalIndex>(lhs: IndexType, rhs: IndexType) -> IndexType.DistanceType

Expected Results:
You can test whether lhs < rhs or rhs < lhs and then proceed accordingly.

Actual Results:
You cannot. I have not been able to find a way to implement this function.

Notes:
You also can’t implement this function by iterating in both directions, because you can’t get the predecessor of the startIndex, nor (presumably) the successor of the endIndex. That limitation is a bit more understandable, though.

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!