swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.61k stars 10.37k forks source link

`Unsafe[Mutable]BufferPointer` should provide `indices` and/or `forEach` even when `Element: ~Copyable` #76509

Open grynspan opened 2 months ago

grynspan commented 2 months ago

Motivation

It's a pain in the patella to iterate over a buffer pointer containing non-copyable values. Seems like indices and/or a borrowing forEach(_:) ought to be possible to implement even for non-copyable values.

Proposed solution

Implement indices and forEach(_:) when Self doesn't conform to Sequence or Collection.

Alternatives considered

There's probably a dozen other ways to accomplish iteration here that would be concise and "Swifty".

Additional information

No response

stephentyrone commented 2 months ago

This is really a sub-task of "design protocols and language integration that support containers of ~Copyable", which @lorentey has been working on. I don't think we need a separate issue tracking it, but I'll let Karoy figure that out.

grynspan commented 2 months ago

That's fair. I'm focused right now on the ergonomics of what we do have: is there something smaller we can do to improve them before we get anything resembling full collection type support?