mirror of
https://github.com/apple/swift-collections
synced 2026-11-22 04:20:40 +00:00
Merge pull request #464 from lorentey/containers
Add support for older builds of the 6.2 compiler
This commit is contained in:
29 files changed
+487
-141
No files matched your search
+1
-3
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:6.0
|
||||
// swift-tools-version:6.2
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
@@ -56,8 +56,6 @@ let availabilityMacros: KeyValuePairs<String, String> = [
|
||||
"SwiftStdlib 6.0": "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0",
|
||||
"SwiftStdlib 6.1": "macOS 15.4, iOS 18.4, watchOS 11.4, tvOS 18.4, visionOS 2.4",
|
||||
"SwiftStdlib 6.2": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999",
|
||||
"SwiftCompatibilitySpan 5.0": "macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1",
|
||||
"SwiftCompatibilitySpan 6.2": "macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0",
|
||||
]
|
||||
|
||||
let extraSettings: [SwiftSetting] = [
|
||||
|
||||
@@ -20,13 +20,13 @@ extension Deque: RandomAccessContainer {
|
||||
_storage.value.borrowElement(at: index)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@lifetime(borrow self)
|
||||
public func nextSpan(after index: inout Int) -> Span<Element> {
|
||||
_storage.value.nextSpan(after: &index)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@lifetime(borrow self)
|
||||
public func previousSpan(before index: inout Int) -> Span<Element> {
|
||||
_storage.value.previousSpan(before: &index)
|
||||
|
||||
@@ -33,13 +33,13 @@ public struct DynamicDeque<Element: ~Copyable>: ~Copyable {
|
||||
extension DynamicDeque: @unchecked Sendable where Element: Sendable & ~Copyable {}
|
||||
|
||||
extension DynamicDeque: RandomAccessContainer where Element: ~Copyable {
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@lifetime(borrow self)
|
||||
public func nextSpan(after index: inout Int) -> Span<Element> {
|
||||
_storage.nextSpan(after: &index)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@lifetime(borrow self)
|
||||
public func previousSpan(before index: inout Int) -> Span<Element> {
|
||||
_storage.previousSpan(before: &index)
|
||||
|
||||
@@ -61,7 +61,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidDeque where Element: ~Copyable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
@@ -78,7 +78,7 @@ extension RigidDeque where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidDeque: RandomAccessContainer, MutableContainer where Element: ~Copyable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
|
||||
@@ -74,7 +74,7 @@ extension DynamicArray /*where Element: Copyable*/ {
|
||||
self.append(copying: contents)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<C: Container<Element> & ~Copyable & ~Escapable>(
|
||||
@@ -84,7 +84,7 @@ extension DynamicArray /*where Element: Copyable*/ {
|
||||
self.init(consuming: RigidArray(capacity: capacity, copying: contents))
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<C: Container<Element> & Sequence<Element>>(
|
||||
@@ -110,7 +110,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
//MARK: - Span creation
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var span: Span<Element> {
|
||||
@lifetime(borrow self)
|
||||
@inlinable
|
||||
@@ -118,8 +118,9 @@ extension DynamicArray where Element: ~Copyable {
|
||||
_storage.span
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(&self)
|
||||
@inlinable
|
||||
@@ -127,6 +128,16 @@ extension DynamicArray where Element: ~Copyable {
|
||||
_storage.mutableSpan
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(borrow self)
|
||||
@inlinable
|
||||
mutating get {
|
||||
_storage.mutableSpan
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//MARK: RandomAccessContainer conformance
|
||||
@@ -162,7 +173,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension DynamicArray: RandomAccessContainer where Element: ~Copyable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
@@ -181,21 +192,28 @@ extension DynamicArray: RandomAccessContainer where Element: ~Copyable {
|
||||
|
||||
extension DynamicArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func mutateElement(at index: Int) -> Inout<Element> {
|
||||
_storage.mutateElement(at: index)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@lifetime(&self)
|
||||
public mutating func swapAt(_ i: Int, _ j: Int) {
|
||||
_storage.swapAt(i, j)
|
||||
}
|
||||
}
|
||||
|
||||
extension DynamicArray: MutableContainer where Element: ~Copyable {
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func nextMutableSpan(after index: inout Int) -> MutableSpan<Element> {
|
||||
_storage.nextMutableSpan(after: &index)
|
||||
}
|
||||
@@ -348,7 +366,7 @@ extension DynamicArray where Element: ~Copyable {
|
||||
/// whether the element should be removed from the array.
|
||||
///
|
||||
/// - Complexity: O(`count`)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func removeAll<E: Error>(
|
||||
where shouldBeRemoved: (borrowing Element) throws(E) -> Bool
|
||||
@@ -440,7 +458,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(`newElements.count`) when amortized over many
|
||||
/// invocations on the same array.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(copying newElements: Span<Element>) {
|
||||
_ensureFreeCapacity(newElements.count)
|
||||
@@ -475,7 +493,7 @@ extension DynamicArray {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public mutating func _appendContainer<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
>(
|
||||
@@ -499,7 +517,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(`newElements.count`), when amortized over many invocations
|
||||
/// over the same array.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -519,7 +537,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(`newElements.count`), when amortized over many invocations
|
||||
/// over the same array.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append<
|
||||
C: Container<Element> & Sequence<Element>
|
||||
@@ -636,7 +654,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func insert(
|
||||
copying newElements: Span<Element>, at index: Int
|
||||
@@ -677,7 +695,7 @@ extension DynamicArray {
|
||||
at: index, copying: newElements, newCount: newCount)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal mutating func _insertContainer<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -711,7 +729,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
@@ -742,7 +760,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
@@ -850,7 +868,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
@@ -898,7 +916,7 @@ extension DynamicArray {
|
||||
subrange, copyingCollection: newElements, newCount: c)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func _replaceSubrange<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -937,7 +955,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public mutating func replaceSubrange<
|
||||
@@ -973,7 +991,7 @@ extension DynamicArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public mutating func replaceSubrange<
|
||||
|
||||
@@ -59,7 +59,7 @@ extension NewArray: RandomAccessCollection, MutableCollection {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension NewArray: RandomAccessContainer, MutableContainer {
|
||||
@lifetime(borrow self)
|
||||
public func borrowElement(at index: Int) -> Borrow<Element> {
|
||||
@@ -76,13 +76,21 @@ extension NewArray: RandomAccessContainer, MutableContainer {
|
||||
return _storage.value.previousSpan(before: &index)
|
||||
}
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func mutateElement(at index: Int) -> Inout<Element> {
|
||||
_ensureUnique()
|
||||
return _storage.value.mutateElement(at: index)
|
||||
}
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func nextMutableSpan(after index: inout Int) -> MutableSpan<Element> {
|
||||
_ensureUnique()
|
||||
return _storage.value.nextMutableSpan(after: &index)
|
||||
@@ -172,7 +180,7 @@ extension NewArray {
|
||||
self._storage.value.append(newElement)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func insert(_ item: consuming Element, at index: Int) {
|
||||
precondition(index >= 0 && index <= count)
|
||||
@@ -211,7 +219,7 @@ extension NewArray {
|
||||
}
|
||||
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func removeLast() -> Element {
|
||||
precondition(count > 0, "Cannot remove last element from empty array")
|
||||
|
||||
@@ -13,8 +13,42 @@
|
||||
import InternalCollectionsUtilities
|
||||
#endif
|
||||
|
||||
/// A manually resizable, heap allocated, noncopyable array of
|
||||
/// potentially noncopyable elements.
|
||||
/// A fixed capacity, heap allocated, noncopyable array of potentially
|
||||
/// noncopyable elements.
|
||||
///
|
||||
/// `RigidArray` instances are created with a certain maximum capacity. Elements
|
||||
/// can be added to the array up to that capacity, but no more: trying to add an
|
||||
/// item to a full array results in a runtime trap.
|
||||
///
|
||||
/// var items = RigidArray<Int>(capacity: 2)
|
||||
/// items.append(1)
|
||||
/// items.append(2)
|
||||
/// items.append(3) // Runtime error: RigidArray capacity overflow
|
||||
///
|
||||
/// Rigid arrays provide convenience properties to help verify that it has
|
||||
/// enough available capacity: `isFull` and `freeCapacity`.
|
||||
///
|
||||
/// guard items.freeCapacity >= 4 else { throw CapacityOverflow() }
|
||||
/// items.append(copying: newItems)
|
||||
///
|
||||
/// It is possible to extend or shrink the capacity of a rigid array instance,
|
||||
/// but this needs to be done explicitly, with operations dedicated to this
|
||||
/// purpose (such as ``reserveCapacity`` and ``reallocate(capacity:)``).
|
||||
/// The array never resizes itself automatically.
|
||||
///
|
||||
/// It therefore requires careful manual analysis or up front runtime capacity
|
||||
/// checks to prevent the array from overflowing its storage. This makes
|
||||
/// this type more difficult to use than a dynamic array. However, it allows
|
||||
/// this construct to provide predictably stable performance.
|
||||
///
|
||||
/// This trading of usability in favor of stable performance limits `RigidArray`
|
||||
/// to the most resource-constrained of use cases, such as space-constrained
|
||||
/// environments that require carefully accounting of every heap allocation, or
|
||||
/// time-constrained applications that cannot accommodate unexpected latency
|
||||
/// spikes due to a reallocation getting triggered at an inopportune moment.
|
||||
///
|
||||
/// For use cases outside of these narrow domains, we generally recommmend
|
||||
/// the use of ``DynamicArray`` rather than `RigidArray`.
|
||||
@safe
|
||||
@frozen
|
||||
public struct RigidArray<Element: ~Copyable>: ~Copyable {
|
||||
@@ -95,7 +129,7 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
self.append(copying: contents)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<C: Container<Element> & Sequence<Element>>(
|
||||
@@ -116,7 +150,7 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
self.append(copying: contents)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<C: Container<Element> & ~Copyable & ~Escapable>(
|
||||
@@ -127,7 +161,7 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
self.append(copying: contents)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public init<C: Container<Element> & Collection<Element>>(
|
||||
@@ -139,6 +173,8 @@ extension RigidArray /*where Element: Copyable*/ {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: init(moving:), init(consuming:)
|
||||
|
||||
//MARK: - Basics
|
||||
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
@@ -170,7 +206,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
//MARK: - Span creation
|
||||
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var span: Span<Element> {
|
||||
@lifetime(borrow self)
|
||||
@inlinable
|
||||
@@ -180,7 +216,8 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(&self)
|
||||
@inlinable
|
||||
@@ -189,17 +226,32 @@ extension RigidArray where Element: ~Copyable {
|
||||
return unsafe _overrideLifetime(result, mutating: &self)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(borrow self)
|
||||
@inlinable
|
||||
mutating get {
|
||||
let result = unsafe MutableSpan(_unsafeElements: _items)
|
||||
return unsafe _overrideLifetime(result, mutating: &self)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
internal func _span(in range: Range<Int>) -> Span<Element> {
|
||||
span._extracting(range)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
internal mutating func _mutableSpan(
|
||||
in range: Range<Int>
|
||||
) -> MutableSpan<Element> {
|
||||
@@ -260,7 +312,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidArray: RandomAccessContainer where Element: ~Copyable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
@@ -277,7 +329,11 @@ extension RigidArray: RandomAccessContainer where Element: ~Copyable {
|
||||
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
@inlinable
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func mutateElement(at index: Int) -> Inout<Element> {
|
||||
precondition(index >= 0 && index < _count)
|
||||
return unsafe Inout(
|
||||
@@ -295,9 +351,13 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RigidArray: MutableContainer where Element: ~Copyable {
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Int
|
||||
) -> MutableSpan<Element> {
|
||||
@@ -508,7 +568,7 @@ extension RigidArray where Element: ~Copyable {
|
||||
/// whether the element should be removed from the array.
|
||||
///
|
||||
/// - Complexity: O(`count`)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func removeAll<E: Error>(
|
||||
where shouldBeRemoved: (borrowing Element) throws(E) -> Bool
|
||||
@@ -551,6 +611,24 @@ extension RigidArray where Element: ~Copyable {
|
||||
unsafe _storage.initializeElement(at: _count, to: item)
|
||||
_count &+= 1
|
||||
}
|
||||
|
||||
/// Adds an element to the end of the array, if possible.
|
||||
///
|
||||
/// If the array does not have sufficient capacity to hold any more elements,
|
||||
/// then this returns the given item without appending it; otherwise it
|
||||
/// returns nil.
|
||||
///
|
||||
/// - Parameter item: The element to append to the collection.
|
||||
/// - Returns: `item` if the array is full; otherwise nil.
|
||||
///
|
||||
/// - Complexity: O(1)
|
||||
@inlinable
|
||||
public mutating func pushLast(_ item: consuming Element) -> Element? {
|
||||
// FIXME: Remove this in favor of a standard algorithm.
|
||||
if isFull { return item }
|
||||
append(item)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
@@ -576,6 +654,18 @@ extension RigidArray where Element: ~Copyable {
|
||||
_count &+= items.count
|
||||
}
|
||||
|
||||
/// Appends the elements of a given array to the end of this array by moving
|
||||
/// them between the containers. On return, the input array becomes empty, but
|
||||
/// it is not destroyed, and it preserves its original storage capacity.
|
||||
///
|
||||
/// If the target array does not have sufficient capacity to hold all items
|
||||
/// in the source array, then this triggers a runtime error.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - items: A fully initialized buffer whose contents to move into
|
||||
/// the array.
|
||||
///
|
||||
/// - Complexity: O(`items.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(
|
||||
moving items: inout RigidArray<Element>
|
||||
@@ -588,6 +678,17 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends the elements of a given container to the end of this array by
|
||||
/// consuming the source container.
|
||||
///
|
||||
/// If the target array does not have sufficient capacity to hold all items
|
||||
/// in the source array, then this triggers a runtime error.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - items: A fully initialized buffer whose contents to move into
|
||||
/// the array.
|
||||
///
|
||||
/// - Complexity: O(`items.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(
|
||||
consuming items: consuming RigidArray<Element>
|
||||
@@ -647,7 +748,7 @@ extension RigidArray {
|
||||
/// - newElements: A span whose contents to copy into the array.
|
||||
///
|
||||
/// - Complexity: O(`newElements.count`)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func append(copying items: Span<Element>) {
|
||||
unsafe items.withUnsafeBufferPointer { source in
|
||||
@@ -686,7 +787,7 @@ extension RigidArray {
|
||||
precondition(it.next() == nil, "RigidArray capacity overflow")
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal mutating func _appendContainer<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -708,7 +809,7 @@ extension RigidArray {
|
||||
/// - newElements: A container whose contents to copy into the array.
|
||||
///
|
||||
/// - Complexity: O(`newElements.count`)
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<C: Container<Element> & ~Copyable & ~Escapable>(
|
||||
@@ -726,7 +827,7 @@ extension RigidArray {
|
||||
/// - newElements: The new elements to copy into the array.
|
||||
///
|
||||
/// - Complexity: O(*m*), where *m* is the length of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func append<
|
||||
@@ -795,6 +896,18 @@ extension RigidArray where Element: ~Copyable {
|
||||
_count &+= items.count
|
||||
}
|
||||
|
||||
/// Inserts the elements of a given array into the given position in this
|
||||
/// array by moving them between the containers. On return, the input array
|
||||
/// becomes empty, but it is not destroyed, and it preserves its original
|
||||
/// storage capacity.
|
||||
///
|
||||
/// If the target array does not have sufficient capacity to hold all items
|
||||
/// in the source array, then this triggers a runtime error.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - items: An array whose contents to move into `self`.
|
||||
///
|
||||
/// - Complexity: O(`items.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func insert(
|
||||
moving items: inout RigidArray<Element>,
|
||||
@@ -809,6 +922,17 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Inserts the elements of a given array into the given position in this
|
||||
/// array by consuming the source container.
|
||||
///
|
||||
/// If the target array does not have sufficient capacity to hold all items
|
||||
/// in the source array, then this triggers a runtime error.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - items: A fully initialized buffer whose contents to move into
|
||||
/// the array.
|
||||
///
|
||||
/// - Complexity: O(`items.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func insert(
|
||||
consuming items: consuming RigidArray<Element>,
|
||||
@@ -817,7 +941,6 @@ extension RigidArray where Element: ~Copyable {
|
||||
var items = items
|
||||
self.insert(moving: &items, at: index)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension RigidArray {
|
||||
@@ -904,7 +1027,7 @@ extension RigidArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func insert(
|
||||
copying newElements: Span<Element>, at index: Int
|
||||
@@ -943,7 +1066,7 @@ extension RigidArray {
|
||||
_count += newCount
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal mutating func _insertContainer<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -1011,7 +1134,7 @@ extension RigidArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
@@ -1043,7 +1166,7 @@ extension RigidArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@_alwaysEmitIntoClient
|
||||
@inline(__always)
|
||||
public mutating func insert<
|
||||
@@ -1093,34 +1216,116 @@ extension RigidArray where Element: ~Copyable {
|
||||
}
|
||||
|
||||
extension RigidArray where Element: ~Copyable {
|
||||
/// Replaces the specified range of elements by moving the elements of a
|
||||
/// fully initialized buffer into their place. On return, the buffer is left
|
||||
/// in an uninitialized state.
|
||||
///
|
||||
/// This method has the effect of removing the specified range of elements
|
||||
/// from the array and inserting the new elements starting at the same
|
||||
/// location. The number of new elements need not match the number of elements
|
||||
/// being removed.
|
||||
///
|
||||
/// If the capacity of the array isn't sufficient to accommodate the new
|
||||
/// elements, then this method triggers a runtime error.
|
||||
///
|
||||
/// If you pass a zero-length range as the `subrange` parameter, this method
|
||||
/// inserts the elements of `newElements` at `subrange.lowerBound`. Calling
|
||||
/// the `insert(copying:at:)` method instead is preferred in this case.
|
||||
///
|
||||
/// Likewise, if you pass a zero-length buffer as the `newElements`
|
||||
/// parameter, this method removes the elements in the given subrange
|
||||
/// without replacement. Calling the `removeSubrange(_:)` method instead is
|
||||
/// preferred in this case.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - subrange: The subrange of the array to replace. The bounds of
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: A fully initialized buffer whose contents to move into
|
||||
/// the array.
|
||||
///
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
moving items: UnsafeMutableBufferPointer<Element>,
|
||||
moving newElements: UnsafeMutableBufferPointer<Element>,
|
||||
) {
|
||||
let gap = unsafe _gapForReplacement(
|
||||
of: subrange, withNewCount: items.count)
|
||||
let c = unsafe gap._moveInitializePrefix(from: items)
|
||||
assert(c == items.count)
|
||||
of: subrange, withNewCount: newElements.count)
|
||||
let c = unsafe gap._moveInitializePrefix(from: newElements)
|
||||
assert(c == newElements.count)
|
||||
}
|
||||
|
||||
/// Replaces the specified range of elements by moving the elements of a
|
||||
/// another array into their place. On return, the source array
|
||||
/// becomes empty, but it is not destroyed, and it preserves its original
|
||||
/// storage capacity.
|
||||
///
|
||||
/// This method has the effect of removing the specified range of elements
|
||||
/// from the array and inserting the new elements starting at the same
|
||||
/// location. The number of new elements need not match the number of elements
|
||||
/// being removed.
|
||||
///
|
||||
/// If the capacity of the array isn't sufficient to accommodate the new
|
||||
/// elements, then this method triggers a runtime error.
|
||||
///
|
||||
/// If you pass a zero-length range as the `subrange` parameter, this method
|
||||
/// inserts the elements of `newElements` at `subrange.lowerBound`. Calling
|
||||
/// the `insert(copying:at:)` method instead is preferred in this case.
|
||||
///
|
||||
/// Likewise, if you pass a zero-length buffer as the `newElements`
|
||||
/// parameter, this method removes the elements in the given subrange
|
||||
/// without replacement. Calling the `removeSubrange(_:)` method instead is
|
||||
/// preferred in this case.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - subrange: The subrange of the array to replace. The bounds of
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: An array whose contents to move into `self`.
|
||||
///
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
moving items: inout RigidArray<Element>,
|
||||
moving newElements: inout RigidArray<Element>,
|
||||
) {
|
||||
unsafe items.withUnsafeMutableBufferPointer { buffer, count in
|
||||
unsafe newElements.withUnsafeMutableBufferPointer { buffer, count in
|
||||
unsafe self.replaceSubrange(subrange, moving: buffer)
|
||||
count = 0
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces the specified range of elements by moving the elements of a
|
||||
/// given array into their place, consuming it in the process.
|
||||
///
|
||||
/// This method has the effect of removing the specified range of elements
|
||||
/// from the array and inserting the new elements starting at the same
|
||||
/// location. The number of new elements need not match the number of elements
|
||||
/// being removed.
|
||||
///
|
||||
/// If the capacity of the array isn't sufficient to accommodate the new
|
||||
/// elements, then this method triggers a runtime error.
|
||||
///
|
||||
/// If you pass a zero-length range as the `subrange` parameter, this method
|
||||
/// inserts the elements of `newElements` at `subrange.lowerBound`. Calling
|
||||
/// the `insert(copying:at:)` method instead is preferred in this case.
|
||||
///
|
||||
/// Likewise, if you pass a zero-length buffer as the `newElements`
|
||||
/// parameter, this method removes the elements in the given subrange
|
||||
/// without replacement. Calling the `removeSubrange(_:)` method instead is
|
||||
/// preferred in this case.
|
||||
///
|
||||
/// - Parameters
|
||||
/// - subrange: The subrange of the array to replace. The bounds of
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: An array whose contents to move into `self`.
|
||||
///
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@_alwaysEmitIntoClient
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
consuming items: consuming RigidArray<Element>,
|
||||
consuming newElements: consuming RigidArray<Element>,
|
||||
) {
|
||||
replaceSubrange(subrange, moving: &items)
|
||||
replaceSubrange(subrange, moving: &newElements)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1150,8 +1355,7 @@ extension RigidArray {
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: The new elements to copy into the collection.
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@inlinable
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
@@ -1188,8 +1392,7 @@ extension RigidArray {
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: The new elements to copy into the collection.
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@inlinable
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
@@ -1225,9 +1428,8 @@ extension RigidArray {
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: The new elements to copy into the collection.
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func replaceSubrange(
|
||||
_ subrange: Range<Int>,
|
||||
@@ -1285,8 +1487,7 @@ extension RigidArray {
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: The new elements to copy into the collection.
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public mutating func replaceSubrange(
|
||||
@@ -1297,7 +1498,7 @@ extension RigidArray {
|
||||
subrange, copyingCollection: newElements, newCount: newElements.count)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public mutating func _replaceSubrange<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -1338,9 +1539,8 @@ extension RigidArray {
|
||||
/// the range must be valid indices in the array.
|
||||
/// - newElements: The new elements to copy into the collection.
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
/// - Complexity: O(`self.count` + `newElements.count`)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public mutating func replaceSubrange<
|
||||
@@ -1380,7 +1580,7 @@ extension RigidArray {
|
||||
///
|
||||
/// - Complexity: O(*n* + *m*), where *n* is count of this array and
|
||||
/// *m* is the count of `newElements`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public mutating func replaceSubrange<
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public protocol BidirectionalContainer<Element>: Container, ~Copyable, ~Escapable {
|
||||
func index(before i: Index) -> Index
|
||||
func formIndex(before i: inout Index)
|
||||
@@ -18,7 +18,7 @@ public protocol BidirectionalContainer<Element>: Container, ~Copyable, ~Escapabl
|
||||
func previousSpan(before index: inout Index) -> Span<Element>
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension BidirectionalContainer where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public protocol Container<Element>: ~Copyable, ~Escapable {
|
||||
associatedtype Element: ~Copyable/* & ~Escapable*/
|
||||
associatedtype Index: Comparable
|
||||
@@ -30,7 +30,7 @@ public protocol Container<Element>: ~Copyable, ~Escapable {
|
||||
limitedBy limit: Index
|
||||
)
|
||||
|
||||
#if compiler(>=9999) // FIXME: We can't do this yet
|
||||
#if compiler(>=9999) // FIXME: Needs borrow accessors
|
||||
subscript(index: Index) -> Element { borrow }
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
@@ -83,7 +83,7 @@ public protocol Container<Element>: ~Copyable, ~Escapable {
|
||||
func _customLastIndexOfEquatableElement(_ element: borrowing Element) -> Index??
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
public func _defaultIndex(_ i: Index, advancedBy distance: Int) -> Index {
|
||||
@@ -171,7 +171,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
public var isEmpty: Bool {
|
||||
@@ -215,13 +215,13 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
public func _customLastIndexOfEquatableElement(_ element: borrowing Element) -> Index?? { nil }
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Sequence {
|
||||
@inlinable
|
||||
public var underestimatedCount: Int { count }
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Collection {
|
||||
// Resolve ambiguities between default implementations between Collection
|
||||
// and Container.
|
||||
@@ -256,7 +256,7 @@ extension Container where Self: Collection {
|
||||
public func _customLastIndexOfEquatableElement(_ element: borrowing Element) -> Index?? { nil }
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
public subscript(index: Index) -> Element {
|
||||
@@ -269,7 +269,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
@lifetime(borrow self)
|
||||
@@ -287,7 +287,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
|
||||
|
||||
#if false // DEMO
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
// This is just to demo the bulk iteration model
|
||||
func forEachSpan<E: Error>(_ body: (Span<Element>) throws(E) -> Void) throws(E) {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
//MARK: - firstIndex(where:)
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
internal func _containerFirstIndex<E: Error>(
|
||||
@@ -55,7 +55,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Collection {
|
||||
/// Returns the first index that addresses an element of the container that
|
||||
/// satisfies the given predicate.
|
||||
@@ -83,7 +83,7 @@ extension Container where Self: Collection {
|
||||
|
||||
//MARK: - firstIndex(of:)
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Element: Equatable {
|
||||
@inlinable
|
||||
internal func _containerFirstIndex(of element: Element) -> Index? {
|
||||
@@ -110,7 +110,7 @@ extension Container where Element: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Collection, Element: Equatable {
|
||||
/// Returns the first index where the specified value appears in the container.
|
||||
///
|
||||
@@ -131,7 +131,7 @@ extension Container where Self: Collection, Element: Equatable {
|
||||
|
||||
//MARK: - lastIndex(where:)
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension BidirectionalContainer where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
internal func _containerLastIndex<E: Error>(
|
||||
@@ -175,7 +175,7 @@ extension BidirectionalContainer where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension BidirectionalContainer where Self: BidirectionalCollection {
|
||||
/// Returns the first index that addresses an element of the container that
|
||||
/// satisfies the given predicate.
|
||||
@@ -203,7 +203,7 @@ extension BidirectionalContainer where Self: BidirectionalCollection {
|
||||
|
||||
//MARK: - lastIndex(of:)
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension BidirectionalContainer where Element: Equatable {
|
||||
@inlinable
|
||||
internal func _containerLastIndex(of element: Element) -> Index? {
|
||||
@@ -230,7 +230,7 @@ extension BidirectionalContainer where Element: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension BidirectionalContainer where Self: BidirectionalCollection, Element: Equatable {
|
||||
/// Returns the first index where the specified value appears in the container.
|
||||
///
|
||||
@@ -251,7 +251,7 @@ extension BidirectionalContainer where Self: BidirectionalCollection, Element: E
|
||||
|
||||
//MARK: - elementsEqual(_:,by:)
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
internal func _spanwiseZip<Other: Container & ~Copyable & ~Escapable, State: ~Copyable, E: Error>(
|
||||
@@ -345,7 +345,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Sequence {
|
||||
/// Returns a Boolean value indicating whether this container and another
|
||||
/// container contain equivalent elements in the same order, using the given
|
||||
@@ -379,7 +379,7 @@ extension Container where Self: Sequence {
|
||||
//MARK: - elementsEqual(_:)
|
||||
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable, Element: Equatable {
|
||||
/// Returns a Boolean value indicating whether this container and another
|
||||
/// container contain the same elements in the same order.
|
||||
@@ -398,7 +398,7 @@ extension Container where Self: ~Copyable & ~Escapable, Element: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: Sequence, Element: Equatable {
|
||||
/// Returns a Boolean value indicating whether this container and another
|
||||
/// container contain the same elements in the same order.
|
||||
|
||||
@@ -48,8 +48,10 @@ where Self: ~Copyable & ~Escapable, Index == Int {
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Array: ContiguousContainer {}
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence // FIXME: Crashes older 6.2 compilers.
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension ContiguousArray: ContiguousContainer {}
|
||||
#endif
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension CollectionOfOne: ContiguousContainer {}
|
||||
@@ -9,17 +9,26 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public protocol MutableContainer<Element>: Container, ~Copyable, ~Escapable {
|
||||
#if compiler(>=9999) // FIXME: We can't do this yet
|
||||
#if compiler(>=9999) // FIXME: Needs borrow accessors
|
||||
subscript(index: Index) -> Element { borrow mutate }
|
||||
#else
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
@lifetime(self: copy self)
|
||||
mutating func mutateElement(at index: Index) -> Inout<Element>
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
@lifetime(self: copy self)
|
||||
mutating func nextMutableSpan(after index: inout Index) -> MutableSpan<Element>
|
||||
|
||||
@@ -29,39 +38,88 @@ public protocol MutableContainer<Element>: Container, ~Copyable, ~Escapable {
|
||||
mutating func swapAt(_ i: Index, _ j: Index)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension MutableContainer where Self: ~Copyable & ~Escapable {
|
||||
#if false // Hm...
|
||||
#if false // FIXME: This has flagrant exclusivity violations.
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
mutating func nextMutableSpan(
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func nextMutableSpan(
|
||||
after index: inout Index, maximumCount: Int
|
||||
) -> MutableSpan<Element> {
|
||||
let original = index
|
||||
var span = self.nextMutableSpan(after: &index)
|
||||
if span.count > maximumCount {
|
||||
span = span.extracting(first: maximumCount)
|
||||
// Index remains within the same span, so offseting it is expected to be quick
|
||||
index = self.index(original, offsetBy: maximumCount)
|
||||
let start = index
|
||||
do {
|
||||
let span = self.nextMutableSpan(after: &index)
|
||||
guard span.count > maximumCount else { return span }
|
||||
}
|
||||
return span
|
||||
// Index remains within the same span, so offseting it is expected to be quick
|
||||
let end = self.index(start, offsetBy: maximumCount)
|
||||
index = start
|
||||
var span = self.nextMutableSpan(after: &index)
|
||||
let extract = span.extracting(first: maximumCount) // FIXME: Oops
|
||||
index = end
|
||||
return extract
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence // FIXME: Crashes older 6.2 compilers.
|
||||
@lifetime(self: copy self)
|
||||
public mutating func withNextMutableSpan<
|
||||
E: Error, R: ~Copyable
|
||||
>(
|
||||
after index: inout Index, maximumCount: Int,
|
||||
body: (inout MutableSpan<Element>) throws(E) -> R
|
||||
) throws(E) -> R {
|
||||
// FIXME: We don't want this to be closure-based, but MutableSpan cannot be sliced "in place".
|
||||
let start = index
|
||||
do {
|
||||
var span = self.nextMutableSpan(after: &index)
|
||||
if span.count <= maximumCount {
|
||||
return try body(&span)
|
||||
}
|
||||
}
|
||||
// Try again, but figure out what our target index is first.
|
||||
// Index remains within the same span, so offseting it is expected to be quick
|
||||
index = self.index(start, offsetBy: maximumCount)
|
||||
var i = start
|
||||
var span = self.nextMutableSpan(after: &i)
|
||||
var extract = span.extracting(first: maximumCount)
|
||||
return try body(&extract)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@inlinable
|
||||
public subscript(index: Index) -> Element {
|
||||
@lifetime(borrow self)
|
||||
unsafeAddress {
|
||||
unsafe borrowElement(at: index)._pointer
|
||||
}
|
||||
|
||||
|
||||
@lifetime(&self)
|
||||
unsafeMutableAddress {
|
||||
unsafe mutateElement(at: index)._pointer
|
||||
}
|
||||
}
|
||||
#else
|
||||
@inlinable
|
||||
public subscript(index: Index) -> Element {
|
||||
@lifetime(borrow self)
|
||||
unsafeAddress {
|
||||
unsafe borrowElement(at: index)._pointer
|
||||
}
|
||||
|
||||
@lifetime(borrow self)
|
||||
unsafeMutableAddress {
|
||||
unsafe mutateElement(at: index)._pointer
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension MutableContainer where Self: ~Copyable & ~Escapable {
|
||||
/// Moves all elements satisfying `isSuffixElement` into a suffix of the
|
||||
/// container, returning the start position of the resulting suffix.
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public protocol RandomAccessContainer<Element>
|
||||
: BidirectionalContainer, ~Copyable, ~Escapable {}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RandomAccessContainer
|
||||
where Self: ~Copyable & ~Escapable, Index: Strideable, Index.Stride == Int
|
||||
{
|
||||
@@ -83,7 +83,7 @@ where Self: ~Copyable & ~Escapable, Index: Strideable, Index.Stride == Int
|
||||
|
||||
// Disambiguate parallel extensions on RandomAccessContainer and RandomAccessCollection
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RandomAccessCollection
|
||||
where
|
||||
Self: RandomAccessContainer,
|
||||
|
||||
@@ -53,7 +53,7 @@ extension RepeatingContainer where Element: ~Copyable {
|
||||
}
|
||||
|
||||
#if false // FIXME: This is what we'd want
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RepeatingContainer: RandomAccessContainer where Element: ~Copyable {
|
||||
@lifetime(borrow self)
|
||||
public func borrowElement(at index: Int) -> Borrow<Element> {
|
||||
@@ -85,7 +85,7 @@ extension RepeatingContainer: RandomAccessContainer where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension RepeatingContainer: RandomAccessContainer where Element: ~Copyable {
|
||||
@lifetime(borrow self)
|
||||
public func borrowElement(at index: Int) -> Borrow<Element> {
|
||||
|
||||
@@ -53,7 +53,11 @@ public func _overrideLifetime<
|
||||
@_unsafeNonescapableResult
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&source)
|
||||
#else
|
||||
@lifetime(borrow source)
|
||||
#endif
|
||||
public func _overrideLifetime<
|
||||
T: ~Copyable & ~Escapable,
|
||||
U: ~Copyable & ~Escapable
|
||||
|
||||
@@ -363,6 +363,7 @@ extension OutputSpan where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@_alwaysEmitIntoClient
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(&self)
|
||||
@@ -375,6 +376,20 @@ extension OutputSpan where Element: ~Copyable {
|
||||
return unsafe _overrideLifetime(span, mutating: &self)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@_alwaysEmitIntoClient
|
||||
public var mutableSpan: MutableSpan<Element> {
|
||||
@lifetime(borrow self)
|
||||
mutating get {
|
||||
let pointer = unsafe _pointer?.assumingMemoryBound(to: Element.self)
|
||||
let buffer = unsafe UnsafeMutableBufferPointer(
|
||||
start: pointer, count: _initialized
|
||||
)
|
||||
let span = unsafe MutableSpan(_unsafeElements: buffer)
|
||||
return unsafe _overrideLifetime(span, mutating: &self)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@available(macOS 9999, *)
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
@usableFromInline
|
||||
internal let immortalThing: [Void] = []
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Span where Element: ~Copyable {
|
||||
public static var empty: Span {
|
||||
@lifetime(immortal)
|
||||
@@ -32,7 +32,7 @@ extension Span where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Span where Element: Equatable {
|
||||
/// Returns a Boolean value indicating whether this and another span
|
||||
/// contain equal elements in the same order.
|
||||
|
||||
@@ -96,7 +96,7 @@ extension UnsafeMutableBufferPointer {
|
||||
/// The `source` span must fit entirely in `self`.
|
||||
///
|
||||
/// - Returns: The index after the last item that was initialized in this buffer.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal func _initializePrefix(copying source: Span<Element>) -> Int {
|
||||
unsafe source.withUnsafeBufferPointer { unsafe self._initializePrefix(copying: $0) }
|
||||
@@ -114,7 +114,7 @@ extension UnsafeMutableBufferPointer {
|
||||
///
|
||||
/// - Returns: A pair of values `(count, end)`, where `count` is the number of items that were
|
||||
/// successfully initialized, and `end` is the index into `items` after the last copied item.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal func _initializePrefix<
|
||||
C: Container<Element> & ~Copyable & ~Escapable
|
||||
@@ -157,7 +157,7 @@ extension UnsafeMutableBufferPointer {
|
||||
/// entirely uninitialized.
|
||||
///
|
||||
/// The count of `span` must not be greater than `self.count`.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
internal mutating func _initializeAndDropPrefix(copying span: Span<Element>) {
|
||||
unsafe span.withUnsafeBufferPointer { buffer in
|
||||
|
||||
@@ -40,9 +40,9 @@ extension Box where T: ~Copyable {
|
||||
return result
|
||||
}
|
||||
|
||||
@lifetime(immortal)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@lifetime(immortal)
|
||||
public consuming func leak() -> Inout<T> {
|
||||
let result = unsafe Inout<T>(unsafeImmortalAddress: _pointer)
|
||||
discard self
|
||||
@@ -62,16 +62,20 @@ extension Box where T: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@lifetime(borrow self)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
@lifetime(borrow self)
|
||||
public func borrow() -> Borrow<T> {
|
||||
unsafe Borrow(unsafeAddress: UnsafePointer(_pointer), borrowing: self)
|
||||
}
|
||||
|
||||
@lifetime(&self)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func mutate() -> Inout<T> {
|
||||
unsafe Inout(unsafeAddress: _pointer, mutating: &self)
|
||||
}
|
||||
@@ -86,7 +90,7 @@ extension Box where T: Copyable {
|
||||
}
|
||||
|
||||
extension Box where T: ~Copyable {
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var span: Span<T> {
|
||||
@_alwaysEmitIntoClient
|
||||
@lifetime(borrow self)
|
||||
@@ -95,7 +99,8 @@ extension Box where T: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<T> {
|
||||
@_alwaysEmitIntoClient
|
||||
@lifetime(&self)
|
||||
@@ -103,4 +108,14 @@ extension Box where T: ~Copyable {
|
||||
unsafe MutableSpan(_unsafeStart: _pointer, count: 1)
|
||||
}
|
||||
}
|
||||
#else
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public var mutableSpan: MutableSpan<T> {
|
||||
@_alwaysEmitIntoClient
|
||||
@lifetime(borrow self)
|
||||
mutating get {
|
||||
unsafe MutableSpan(_unsafeStart: _pointer, count: 1)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -41,10 +41,14 @@ public struct Inout<T: ~Copyable>: ~Copyable, ~Escapable {
|
||||
/// instance of type 'T'.
|
||||
/// - Parameter owner: The owning instance that this 'Inout' instance's
|
||||
/// lifetime is based on.
|
||||
@lifetime(&owner)
|
||||
@unsafe
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&owner)
|
||||
#else
|
||||
@lifetime(borrow owner)
|
||||
#endif
|
||||
public init<Owner: ~Copyable & ~Escapable>(
|
||||
unsafeAddress: UnsafeMutablePointer<T>,
|
||||
mutating owner: inout Owner
|
||||
|
||||
@@ -109,6 +109,7 @@ extension Shared where Storage: ~Copyable {
|
||||
}
|
||||
|
||||
extension Shared where Storage: ~Copyable {
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public var value: Storage {
|
||||
@@ -122,6 +123,21 @@ extension Shared where Storage: ~Copyable {
|
||||
return unsafe _mutableAddress
|
||||
}
|
||||
}
|
||||
#else
|
||||
@inlinable
|
||||
@inline(__always)
|
||||
public var value: Storage {
|
||||
@lifetime(borrow self)
|
||||
unsafeAddress {
|
||||
unsafe _address
|
||||
}
|
||||
@lifetime(borrow self)
|
||||
unsafeMutableAddress {
|
||||
precondition(isUnique())
|
||||
return unsafe _mutableAddress
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extension Shared where Storage: ~Copyable {
|
||||
@@ -133,9 +149,14 @@ extension Shared where Storage: ~Copyable {
|
||||
// lifetime(self) == lifetime(_box.storage).
|
||||
unsafe Borrow(unsafeAddress: _address, borrowing: self)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@inlinable
|
||||
#if compiler(>=6.2) && $InoutLifetimeDependence
|
||||
@lifetime(&self)
|
||||
#else
|
||||
@lifetime(borrow self)
|
||||
#endif
|
||||
public mutating func mutate() -> Inout<Storage> {
|
||||
// This is gloriously (and very explicitly) unsafe, as it should be.
|
||||
// `Shared` is carefully constructed to guarantee that
|
||||
|
||||
@@ -47,7 +47,7 @@ final class MinimalTypeTests: CollectionTestCase {
|
||||
|
||||
#if false // FIXME: Track down compiler crash
|
||||
func testTestContainer() {
|
||||
guard #available(SwiftCompatibilitySpan 5.0, *) else { return }
|
||||
guard #available(SwiftStdlib 6.2, *) else { return }
|
||||
let a = TestContainer(
|
||||
contents: RigidArray(count: 100, initializedWith: { $0 }),
|
||||
spanCounts: [3, 1, 7])
|
||||
|
||||
@@ -13,6 +13,7 @@ import XCTest
|
||||
import _CollectionsTestSupport
|
||||
import Future
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
class StaccatoContainerTests: CollectionTestCase {
|
||||
func checkStriding<C: Container & ~Copyable & ~Escapable>(
|
||||
_ container: borrowing C,
|
||||
|
||||
@@ -14,6 +14,7 @@ import _CollectionsTestSupport
|
||||
import Future
|
||||
import Synchronization
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
class DynamicArrayTests: CollectionTestCase {
|
||||
func test_validate_Container() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
|
||||
@@ -13,7 +13,7 @@ import XCTest
|
||||
import _CollectionsTestSupport
|
||||
import Future
|
||||
|
||||
@available(SwiftStdlib 6.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
class RigidArrayTests: CollectionTestCase {
|
||||
func test_validate_Container() {
|
||||
withSomeArrayLayouts("layout", ofCapacities: [0, 10, 100]) { layout in
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
import XCTest
|
||||
import Future
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
final class ContiguousStorageTests: XCTestCase {
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
import Future
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public func expectContainersWithEquivalentElements<
|
||||
C1: Container & ~Copyable & ~Escapable,
|
||||
C2: Container & ~Copyable & ~Escapable
|
||||
@@ -32,7 +32,7 @@ public func expectContainersWithEquivalentElements<
|
||||
}
|
||||
|
||||
/// Check if `left` and `right` contain equal elements in the same order.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public func expectContainersWithEqualElements<
|
||||
Element: Equatable,
|
||||
C1: Container<Element> & ~Copyable & ~Escapable,
|
||||
@@ -52,7 +52,7 @@ public func expectContainersWithEqualElements<
|
||||
}
|
||||
|
||||
/// Check if `left` and `right` contain equal elements in the same order.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public func expectContainerContents<
|
||||
Element: Equatable,
|
||||
C1: Container<Element> & ~Copyable & ~Escapable,
|
||||
@@ -92,7 +92,7 @@ public func expectContainerContents<
|
||||
}
|
||||
|
||||
/// Check if `left` and `right` contain equal elements in the same order.
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public func expectContainerContents<
|
||||
C1: Container & ~Copyable & ~Escapable,
|
||||
C2: Collection,
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
import XCTest
|
||||
import Future
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension Container where Self: ~Copyable & ~Escapable {
|
||||
@inlinable
|
||||
internal func _indicesByIndexAfter() -> [Index] {
|
||||
@@ -37,7 +37,7 @@ extension Container where Self: ~Copyable & ~Escapable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public func checkContainer<
|
||||
C: Container & ~Copyable & ~Escapable,
|
||||
@@ -55,7 +55,7 @@ public func checkContainer<
|
||||
file: file, line: line)
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@inlinable
|
||||
public func checkContainer<
|
||||
C: Container & ~Copyable & ~Escapable,
|
||||
|
||||
@@ -80,7 +80,7 @@ extension StaccatoContainer where Element: ~Copyable {
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftCompatibilitySpan 5.0, *)
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
extension StaccatoContainer: Container where Element: ~Copyable {
|
||||
public func formIndex(_ i: inout Index, offsetBy distance: inout Int, limitedBy limit: Index) {
|
||||
precondition(i >= startIndex && i <= endIndex)
|
||||
|
||||
Reference in new issue
Block a user