Skip to content

Commit 464e074

Browse files
committed
Add fake concrete iterator for InlineArray
1 parent 5b40a27 commit 464e074

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

stdlib/public/core/BorrowingIteratorProtocol.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,27 @@ extension Span /*: Sequence /* where Element: ~Copyable */ */ {
159159

160160
extension InlineArray: Sequence /* where Element: ~Copyable */ {
161161
public typealias Element = Element
162-
public typealias Iterator = NeverIterator<Element>
162+
// public typealias Iterator = NeverIterator<Element>
163+
public typealias BorrowingIterator = Span<Element>
164+
165+
// This will NOT work once `Element: ~Copyable` is in the works
166+
// Problematic because we can only conform to `Sequence` once, so we
167+
// need to provide a single iterator type, but it can't handle both
168+
// ~Copyable and copyable elements (I think)
169+
public struct Iterator: IteratorProtocol {
170+
var array: [count of Element]
171+
var index: Int = 0
172+
173+
public mutating func next() -> Element? {
174+
guard index < array.count else { return nil }
175+
defer { index &+= 1 }
176+
return array[index]
177+
}
178+
}
179+
180+
public func makeIterator() -> Iterator {
181+
.init(array: self)
182+
}
163183

164184
@_alwaysEmitIntoClient
165185
@_lifetime(borrow self)

0 commit comments

Comments
 (0)