Inspired while reading a book about C++'s STL:
extension MutableCollection {
/// Copies elements from the given collection on top of elements of this
/// collection until one runs out.
public mutating func copy<C: Collection>(from collection: C) -> (Index, C.Index) where C.Element == Element
/// Copies elements from the given sequence on top of elements of the
/// collection until one runs out.
@inlinable
public mutating func copy<S: Sequence>(from sequence: S) -> (Index, S.Iterator) where S.Element == Element
/// Overlays elements from the given iterator onto the elements of the
/// collection until one runs out.
public mutating func copy<I: IteratorProtocol>(from iterator: inout I) -> Index where I.Element == Element
}
extension MutableCollection where Self: BidirectionalCollection {
/// Copies elements from the given collection on top of elements of this
/// collection, backwards, until one runs out.
public mutating func copyBackwards<C: BidirectionalCollection>(from collection: C) -> (Index, C.Index) where C.Element == Element
}
Any reason we don't have these already? There are many similar methods for RangeReplaceableCollection
, so it's odd that MutableCollection
has nothing. Maybe I'll add a bug (enhancement) report....