- Make `nextSpan(after:limitedBy:)` the core iteration interface
- Review default algorithms and update them to use it, speeding them up
- Spin off `Span._nextSpan(after:maxCount)` and `Span._nextSpan(after:limitedBy:)` with copying lifetime semantics. This allows forwarding to these without having to override lifetimes.
- Require Index to be Hashable
- Add strong complexity expectations. Require `isEmpty`, `count` and `endIndex` to have O(1) complexity. Recommend most index navigation methods to be linear in the distance traveled.
- Remove `index(alignedDown:)` and `index(alignedUp:)`; Collection views are far less relevant in this model, so index rounding is mostly unnecessary. (The need can still pop up when indices are shared between several views of layout-compatible Element types — such as a container of UInt64 than can also be interpreted as a container of UInt8; if that becomes a thing, we may need to bring these requirements back.)
- Add `nextSpan(after:limitedBy:)` as an alternative to `nextSpan(after:maximumCount:)`. This makes it possible to provide fast default implementations for `distance(from:to:)` and `formIndex(_:offsetBy:limitedBy:)`.
- Don’t allow `skip(by:)` to skip fewer than the requested number of items, unless it hits the end of the sequence or an error. Remove its Boolean return value.
- Introduce a variant of `skip(by:)` that doesn’t take an inout argument, losing the ability to report which item triggered a throw. This is just a standard algorithm; the protocol continues to require proper reporting of partial success.
- Use the stdlib’s `withTemporaryAllocation` method where possible to create temporary buffers.
This is preparing for switching over to the stdlib’s definition of `protocol Iterable`, assuming it will land with macOS 27/iOS 27 etc availability; `Container` is refining `Iterable`, so it needs matching availability.
If `Iterable` won’t ship in Swift 6.4, then we’ll need to bump this again.
- Introduce easy-to-use `replace(removing:addingFrom:)`, `insert(from:at:)`, and `append(from:)` algorithms that take `CountedProducer` instances, avoiding having to pass explicit counts separately
- Avoid RangeExpression2 helpers from satisfying core protocol requirements, leading to broken conformances
- Add `replace(removing:moving:)`, `replace(removing:consuming:)`, `insert(moving:at:)`, `insert(consuming:at:)`, `append(moving:)`, `append(consuming:)` operations that take range-replaceable containers.
- Reorder some parameters for consistency/readability:
- `insert(addingCount:at:from:)` → `insert(addingCount:from:at:)`
- `insert(at:moving:from:)` → `insert(moving:from:at:)`
Use `override`/`@_nonoverride` to help associated type inference and to allow diverging implementations of select requirements in BidirectionalContainer, RandomAccessContainer, and MutableContainer.
Package traits already pass defines with their trait name when building. Instead of adding our own conditional defines based on the traits we can use the trait provided defines directly. I observed that various tooling behaves better with the trait provided defines.
This slows down the default implementations of `distance(from:to:)` and `index(_:offsetBy:limitedBy:)`, but it allows linked lists to conform to `Container`. The trade off seems fair.
While we’re here, flesh out the `BidirectionalContainer` refinements a little, and add `Container.isEmpty` and `._custom[Last]IndexOfEquatableElement(_:)`.
This code is still untested.