Skip to content

Commit 37b0f4e

Browse files
committed
Add compatibility shims for non-Int index distances
1 parent 7dd70d2 commit 37b0f4e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

stdlib/public/core/Collection.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,29 @@ extension Collection {
17041704

17051705

17061706
extension Collection {
1707-
@available(swift, deprecated: 4.1, message: "all index disatnces are now of type Int")
1707+
@available(swift, deprecated, message: "all index distances are now of type Int")
17081708
public typealias IndexDistance = Int
1709-
}
17101709

1710+
@available(*, deprecated, message: "all index distances are now of type Int")
1711+
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T) -> Index {
1712+
return index(i, offsetBy: Int(n))
1713+
}
1714+
/* FIXME: crashes the compiler
1715+
@available(*, deprecated, message: "all index distances are now of type Int")
1716+
public func formIndex<T: BinaryInteger>(_ i: Index, offsetBy n: T) {
1717+
return formIndex(i, offsetBy: Int(n))
1718+
}
1719+
@available(*, deprecated, message: "all index distances are now of type Int")
1720+
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T, limitedBy limit: Index) -> Index {
1721+
return index(i, offsetBy: Int(n), limitedBy: limit)
1722+
}
1723+
*/
1724+
@available(*, deprecated, message: "all index distances are now of type Int")
1725+
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T, limitedBy limit: Index) -> Bool {
1726+
return formIndex(&i, offsetBy: Int(n), limitedBy: limit)
1727+
}
1728+
@available(*, deprecated, message: "all index distances are now of type Int")
1729+
public func distance<T: BinaryInteger>(from start: Index, to end: Index) -> T {
1730+
return numericCast(distance(from: start, to: end) as Int)
1731+
}
1732+
}

0 commit comments

Comments
 (0)