//===----------------------------------------------------------------------===// // // This source file is part of the Swift Collections open source project // // Copyright (c) 2024 - 2026 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 // // SPDX-License-Identifier: Apache-2.0 WITH Swift-exception // //===----------------------------------------------------------------------===// #if COLLECTIONS_FOUNDATION_TOOLCHAIN_MODULE import _FoundationCollections #elseif COLLECTIONS_SINGLE_MODULE import Collections #else import InternalCollectionsUtilities #endif #if compiler(>=6.4) && UnstableContainersPreview @available(SwiftStdlib 6.4, *) extension OutputSpan: RandomAccessContainer, MutableContainer /*where Element: ~Copyable*/ // FIXME: rdar://183153655 OutputSpan's Iterable conformance requires Element to be Copyable { @_alwaysEmitIntoClient @_lifetime(borrow self) public func makeBorrowingIterator( from start: Index, to end: Index ) -> BorrowingIterator { // FIXME: `makeBorrowingIterator` would be borrowing the temporary `span`, not self self.span._makeBorrowingIterator(from: start, to: end) } @_alwaysEmitIntoClient public func currentIndex(of iterator: inout BorrowingIterator) -> Index { self.span.currentIndex(of: &iterator) } @_alwaysEmitIntoClient @inline(__always) public var startIndex: Index { 0 } @_alwaysEmitIntoClient @inline(__always) public var endIndex: Index { count } @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan(after index: inout Index) -> Span { self.span._nextSpan(after: &index) } @_alwaysEmitIntoClient @_lifetime(borrow self) public func nextSpan( after index: inout Index, maxCount: Int, limitedBy limit: Int ) -> Span { self.span._nextSpan(after: &index, maxCount: maxCount, limitedBy: limit) } @_alwaysEmitIntoClient @_lifetime(&self) public mutating func nextMutableSpan( after index: inout Index ) -> MutableSpan { self.mutableSpan._nextMutableSpan(after: &index) } @_alwaysEmitIntoClient @_lifetime(&self) public mutating func nextMutableSpan( after index: inout Index, maxCount: Int, limitedBy limit: Index ) -> MutableSpan { self.mutableSpan._nextMutableSpan(after: &index, maxCount: maxCount, limitedBy: limit) } @_alwaysEmitIntoClient public func spanBoundary(before index: Index) -> (index: Index, distance: Int) { precondition(index >= 0 && index <= count, "Index out of bounds") return (0, index) } @_alwaysEmitIntoClient public func spanBoundary( before index: Index, maxDistance: Int, limitedBy limit: Index ) -> (index: Index, distance: Int) { precondition(index >= 0 && index <= count, "Index out of bounds") precondition(limit >= 0 && limit <= count, "Index out of bounds") precondition(maxDistance > 0, "maxDistance must be positive") let p = index._clampedDown(towards: 0, maxDistance: maxDistance, limitedBy: limit) return (p, index &- p) } } #endif