[SR-3762] Default implementation of index(after:) for Integer indices #46347
Labels
affects ABI
Flag: Affects ABI
good first issue
Good for newcomers
improvement
standard library
Area: Standard library umbrella
swift evolution proposal needed
Flag → feature: A feature that warrants a Swift evolution proposal
Additional Detail from JIRA
md5: 0a15e4ebe05ad3320d3ce0d815461616
Issue Description:
There should be a default implementation for Collections whose Index type is Int. This make it more convenient to write integer indexed collections. In the previous collections model it was just understood that an Int index’s successor was the integer + 1 and there was no boilerplate a developer had to write.
extension Collection where Index: Integer {
public func index(after i: Index) -> Index {
return i + 1
}
}
Note, this would mean that collections that did not want this behavior (say, they used a non-unit stride) would need to remember to override this. However, since users can just do integer calculations themselves without using the collection, it would probably be wise for these types to create an opaque index type to wrap the integer in anyway.
This would need an evolution proposal. Part of the initial pitch should include whether this should be done to just
Collection
or be specific toRandomAccessCollection
.The text was updated successfully, but these errors were encountered: