mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
- Container, MutableContainer: Replace iterator protocols with direct methods that return the next span following a particular index. This is a radical simplification, but it reintroduces some index validation during iteration, and may have undesirable overhead for complex container types. - RigidArray, DynamicArray, NewArray: Update to reflect changes - Span: Conform to RandomAccessContainer - Borrow, Inout: Normalize labels of “owner” parameters. Expose pointers within the package. - Shared: Normalize read() into borrow()
54 lines
1.6 KiB
Swift
54 lines
1.6 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@available(SwiftCompatibilitySpan 5.0, *)
|
|
public protocol Container: ~Copyable, ~Escapable {
|
|
associatedtype Element: ~Copyable
|
|
|
|
associatedtype Index: Comparable
|
|
|
|
var isEmpty: Bool { get }
|
|
var count: Int { get }
|
|
|
|
var startIndex: Index { get }
|
|
var endIndex: Index { get }
|
|
|
|
#if compiler(>=9999) // We want this but we can't do it yet
|
|
subscript(index: Index) -> Element { borrow }
|
|
#else
|
|
@lifetime(copy self)
|
|
func borrowElement(at index: Index) -> Borrow<Element>
|
|
#endif
|
|
|
|
@lifetime(copy self)
|
|
func span(following index: inout Index, maximumCount: Int) -> Span<Element>
|
|
|
|
func index(after index: Index) -> Index
|
|
func formIndex(after i: inout Index)
|
|
func distance(from start: Index, to end: Index) -> Int
|
|
func index(_ index: Index, offsetBy n: Int) -> Index
|
|
func formIndex(
|
|
_ i: inout Index, offsetBy distance: inout Int, limitedBy limit: Index
|
|
)
|
|
}
|
|
|
|
@available(SwiftCompatibilitySpan 5.0, *)
|
|
extension Container where Self: ~Copyable & ~Escapable {
|
|
@inlinable
|
|
public subscript(index: Index) -> Element {
|
|
@lifetime(copy self)
|
|
unsafeAddress {
|
|
unsafe borrowElement(at: index)._pointer
|
|
}
|
|
}
|
|
}
|
|
|