mirror of
https://github.com/apple/swift-collections
synced 2026-11-27 04:54:21 +00:00
[ContainersPreview] Conform [Unique,Rigid]Array and [Unique,Rigid]Deque to container protocols
This commit is contained in:
15 files changed
+313
-198
No files matched your search
@@ -127,42 +127,6 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public mutating func consume(_ subrange: Range<Index>) -> SubrangeConsumer {
|
||||
SubrangeConsumer(_base: &self._storage, offsetRange: subrange)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@_lifetime(&self)
|
||||
public mutating func consume<R: RangeExpression<Index>>(
|
||||
_ subrange: R
|
||||
) -> SubrangeConsumer {
|
||||
consume(subrange.relative(to: indices))
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@_lifetime(&self)
|
||||
public mutating func consumeAll() -> SubrangeConsumer {
|
||||
consume(indices)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@_lifetime(&self)
|
||||
public mutating func consumeLast(_ n: Int) -> SubrangeConsumer {
|
||||
precondition(
|
||||
n >= 0 && n <= self.count,
|
||||
"Count of elements to consume is out of bounds")
|
||||
return consume(self.count - n ..< self.count)
|
||||
}
|
||||
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
@_lifetime(&self)
|
||||
public mutating func consumeFirst(_ n: Int) -> SubrangeConsumer {
|
||||
precondition(
|
||||
n >= 0 && n <= self.count,
|
||||
"Count of elements to consume is out of bounds")
|
||||
return consume(0 ..< n)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -36,8 +36,22 @@ extension UniqueArray: BorrowingSequence where Element: ~Copyable {
|
||||
|
||||
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: Container where Element: ~Copyable {
|
||||
}
|
||||
extension UniqueArray: Container where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: BidirectionalContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: RandomAccessContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: MutableContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: RangeReplaceableContainer where Element: ~Copyable {}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
extension UniqueArray: DynamicContainer where Element: ~Copyable {}
|
||||
#endif
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
@@ -340,6 +354,22 @@ extension UniqueArray where Element: ~Copyable {
|
||||
) -> Span<Element> {
|
||||
_storage.nextSpan(after: &index, maximumCount: maximumCount)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(&self)
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int, maximumCount: Int
|
||||
) -> MutableSpan<Element> {
|
||||
_storage.nextMutableSpan(after: &index, maximumCount: maximumCount)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(borrow self)
|
||||
public func previousSpan(
|
||||
before index: inout Int, maximumCount: Int
|
||||
) -> Span<Element> {
|
||||
_storage.previousSpan(before: &index, maximumCount: maximumCount)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -31,6 +31,12 @@ extension UniqueArray where Element: ~Copyable {
|
||||
public init(capacity: Int) {
|
||||
_storage = .init(capacity: capacity)
|
||||
}
|
||||
|
||||
/// Initializes a new unique array with the specified capacity and no elements.
|
||||
@inlinable
|
||||
public init(minimumCapacity: Int) {
|
||||
_storage = .init(capacity: minimumCapacity)
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.0, *)
|
||||
|
||||
Reference in new issue
Block a user