Returns the distance between two indices.
Required. Default implementation provided.
SDK
- Xcode 10.0+
Framework
- Swift Standard Library
Declaration
func distance(from start: Self.Index, to end: Self.Index) -> Int
Parameters
startA valid index of the collection.
endAnother valid index of the collection. If
endis equal tostart, the result is zero.
Return Value
The distance between start and end. The result can be negative only if the collection conforms to the Bidirectional protocol.
Discussion
Unless the collection conforms to the Bidirectional protocol, start must be less than or equal to end.
Complexity: O(1) if the collection conforms to Random; otherwise, O(k), where k is the resulting distance.