mirror of
https://github.com/apple/swift-collections
synced 2026-11-24 04:27:53 +00:00
References to Span types trigger an issue where SwiftPM isn’t able to run command line executable targets or tests on older OSes. Set the availability of everything that needs span types to the most recent Apple OS releases. Hopefully we’ll be able to revert this once we figure out a better workaround.
92 lines
2.5 KiB
Swift
92 lines
2.5 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if !COLLECTIONS_SINGLE_MODULE
|
|
import InternalCollectionsUtilities
|
|
import ContainersPreview
|
|
#endif
|
|
|
|
#if compiler(>=6.2)
|
|
|
|
@available(SpanAvailability 1.0, *)
|
|
extension UniqueArray where Element: ~Copyable {
|
|
@inlinable
|
|
public init<E: Error>(
|
|
capacity: Int,
|
|
initializingWith body: (inout OutputSpan<Element>) throws(E) -> Void
|
|
) throws(E) {
|
|
self.init(capacity: capacity)
|
|
try edit(body)
|
|
}
|
|
}
|
|
|
|
@available(SpanAvailability 1.0, *)
|
|
extension UniqueArray /*where Element: Copyable*/ {
|
|
/// Creates a new array containing the specified number of a single,
|
|
/// repeated value.
|
|
///
|
|
/// - Parameters:
|
|
/// - repeatedValue: The element to repeat.
|
|
/// - count: The number of times to repeat the value passed in the
|
|
/// `repeating` parameter. `count` must be zero or greater.
|
|
public init(repeating repeatedValue: Element, count: Int) {
|
|
self.init(consuming: RigidArray(repeating: repeatedValue, count: count))
|
|
}
|
|
}
|
|
|
|
@available(SpanAvailability 1.0, *)
|
|
extension UniqueArray where Element: ~Copyable {
|
|
@inlinable
|
|
public init(consuming storage: consuming RigidArray<Element>) {
|
|
self._storage = storage
|
|
}
|
|
}
|
|
|
|
@available(SpanAvailability 1.0, *)
|
|
extension UniqueArray /*where Element: Copyable*/ {
|
|
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
|
@_alwaysEmitIntoClient
|
|
@inline(__always)
|
|
public init<Source: Container<Element> & ~Copyable & ~Escapable>(
|
|
capacity: Int? = nil,
|
|
copying contents: borrowing Source
|
|
) {
|
|
self.init(capacity: capacity ?? 0)
|
|
self.append(copying: contents)
|
|
}
|
|
#endif
|
|
|
|
@_alwaysEmitIntoClient
|
|
@inline(__always)
|
|
public init(
|
|
capacity: Int? = nil,
|
|
copying contents: some Sequence<Element>
|
|
) {
|
|
self.init(capacity: capacity ?? 0)
|
|
self.append(copying: contents)
|
|
}
|
|
|
|
#if COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
|
|
@_alwaysEmitIntoClient
|
|
@inline(__always)
|
|
public init<Source: Container<Element> & Sequence<Element>>(
|
|
capacity: Int? = nil,
|
|
copying contents: Source
|
|
) {
|
|
self.init(capacity: capacity ?? 0)
|
|
self.append(copying: contents)
|
|
}
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|