[stdlib] Make our BidirectionalIndexTypes Comparable

This will allow more error checking, resilient slicing, and occasionally
other useful capabilities.

Step 1 of <rdar://problem/11940897>

Swift SVN r20036
This commit is contained in:
Dave Abrahams
2014-07-16 20:43:42 +00:00
parent f94bc5d929
commit c4f798e246
5 changed files with 105 additions and 5 deletions

View File

@@ -17,6 +17,13 @@ public func ==(
return lhs._position == rhs._position
}
public func <(
lhs: String.UnicodeScalarView.Index,
rhs: String.UnicodeScalarView.Index
) -> Bool {
return lhs._position < rhs._position
}
extension String {
public struct UnicodeScalarView : Sliceable, SequenceType {
init(_ _core: _StringCore) {
@@ -38,7 +45,7 @@ extension String {
}
}
public struct Index : BidirectionalIndexType {
public struct Index : BidirectionalIndexType, Comparable {
public init(_ _position: Int, _ _core: _StringCore) {
self._position = _position
self._core = _core