Skip to content

Commit 9d947e4

Browse files
committed
[stdlib] Add missing overload of extracting for UnboundedRange
I keep forgetting that `some RangeExpression<Element>` does not cover the `UnboundedRange` form.
1 parent f2dc894 commit 9d947e4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,25 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
527527
public func extracting(_ bounds: some RangeExpression<Int>) -> Self {
528528
extracting(bounds.relative(to: Range(uncheckedBounds: (0, count))))
529529
}
530+
531+
/// Extracts and returns a copy of the entire buffer.
532+
///
533+
/// When `Element` is copyable, the `extracting` operation is equivalent to
534+
/// slicing the buffer then rebasing the resulting buffer slice:
535+
///
536+
/// let a = buffer
537+
/// let b = buffer.extracting(...)
538+
/// let c = UnsafeBufferPointer(rebasing: buffer[...])
539+
/// // `a`, `b` and `c` are now all referring to the same buffer
540+
///
541+
/// Note that unlike slicing, the `extracting` operation remains available
542+
/// even if `Element` happens to be noncopyable.
543+
//
544+
/// - Returns: The same buffer as `self`.
545+
@_alwaysEmitIntoClient
546+
public func extracting(_ bounds: UnboundedRange) -> Self {
547+
self
548+
}
530549
}
531550

532551
@_disallowFeatureSuppression(NoncopyableGenerics)

0 commit comments

Comments
 (0)