i am implementing a custom RandomAccessCollection with an Index type of UInt32.
struct SubSequence:RandomAccessCollection
{
typealias Index = Element.Offset
typealias SubSequence = Self
let indices:Range<Element.Offset>
private
let storage:[Element]
var startIndex:Element.Offset
{
self.indices.lowerBound
}
var endIndex:Element.Offset
{
self.indices.upperBound
}
subscript(offset:Element.Offset) -> Element
{
_read
{
yield self.storage[.init(offset - self.startIndex)]
}
}
subscript(range:Range<Element.Offset>) -> Self
{
.init(storage: self.storage, indices: range)
}
func index(before base:Element.Offset) -> Element.Offset
{
base - 1
}
func index(after base:Element.Offset) -> Element.Offset
{
base + 1
}
// func index(_ base:Element.Offset, offsetBy distance:Int) -> Element.Offset
// {
// Element.Offset.init(Int.init(base) + distance)
// }
somehow i am allowed to inherit the index(_:offsetBy:) implementation, but not the index(before:) or index(after:) requirements.
error: type 'Branch.Buffer<Element>.SubSequence' does not conform to protocol 'Collection'
struct SubSequence:RandomAccessCollection
^
Swift.RandomAccessCollection:3:28: note: candidate would match if 'DefaultIndices<Branch.Buffer<Element>.SubSequence>' was the same type as 'Range<Branch.Buffer<Element>.SubSequence.Index>' (aka 'Range<Element.Offset>')
@inlinable public func index(after i: Self.Index) -> Self.Index
^
Swift.RandomAccessCollection:11:19: note: protocol requires function 'index(before:)' with type '(Branch.Buffer<Element>.SubSequence.Index) -> Branch.Buffer<Element>.SubSequence.Index' (aka '(Element.Offset) -> Element.Offset')
override func index(before i: Self.Index) -> Self.Index
^
Swift.RandomAccessCollection:13:19: note: protocol requires function 'index(after:)' with type '(Branch.Buffer<Element>.SubSequence.Index) -> Branch.Buffer<Element>.SubSequence.Index' (aka '(Element.Offset) -> Element.Offset')
override func index(after i: Self.Index) -> Self.Index
^
Swift.Collection:27:10: note: protocol requires function 'index(after:)' with type '(Branch.Buffer<Element>.SubSequence.Index) -> Branch.Buffer<Element>.SubSequence.Index' (aka '(Element.Offset) -> Element.Offset')
func index(after i: Self.Index) -> Self.Index
why? i would have assumed index(_:offsetBy:) is more important than index(before:) or index(after:).