Files
swift-collections/Sources/ContainersPreview/Protocols/Container
Karoy Lorentey 29148932ec [ContainersPreview] Add a Producer.collect(into:) that takes a RangeReplaceableContainer
This is getting into dangerous territory, as RRC allows fixed-capacity conformers, where appending a producer must be done extremely carefully. We should be using bulk append operations, but never ask the container to reserve any more slots than the producer is able to actually generate. (When the fixed-capacity RRC was carefully sized to precisely fit the generator’s contents, asking it to provide space for even a single item more would lead to a runtime trap.)

Additionally, the algorithm should work (and be reasonably efficient) even if the RRC happens to be a dynamically sizing container type.

It would be nice if we had a Producer protocol flavor with an exact count; failing that, we can still do this with a bit of acrobatics, as implemented here.  (The `DynamicContainer.append(from:)` algorithm was already implemented this way in a previous commit, with an eye towards this case.)
2026-03-17 13:32:11 -07:00
..