mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
stdlib: Make data structure protocols ready for future move-only types.
We would like to eventually extend Array, Dictionary, and Set to support move-only element types when the language does. To that end, we need to get the `consuming`-ness of protocol requirements on Sequence, Collection, and related protocols right for forward compatibility so that a future version of Swift that extends these types to support move-only data structures remains ABI- and API-compatible with older versions of the language. Mark requirements as `__consuming` where it would be necessary for a move-only implementation of one of these types.
This commit is contained in:
@@ -336,7 +336,7 @@ public protocol Sequence {
|
||||
SubSequence.SubSequence == SubSequence
|
||||
|
||||
/// Returns an iterator over the elements of this sequence.
|
||||
func makeIterator() -> Iterator
|
||||
__consuming func makeIterator() -> Iterator
|
||||
|
||||
/// A value less than or equal to the number of elements in the sequence,
|
||||
/// calculated nondestructively.
|
||||
@@ -384,7 +384,7 @@ public protocol Sequence {
|
||||
/// sequence as its argument and returns a Boolean value indicating
|
||||
/// whether the element should be included in the returned array.
|
||||
/// - Returns: An array of the elements that `isIncluded` allowed.
|
||||
func filter(
|
||||
__consuming func filter(
|
||||
_ isIncluded: (Element) throws -> Bool
|
||||
) rethrows -> [Element]
|
||||
|
||||
@@ -442,7 +442,7 @@ public protocol Sequence {
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the number of elements to drop from
|
||||
/// the beginning of the sequence.
|
||||
func dropFirst(_ n: Int) -> SubSequence
|
||||
__consuming func dropFirst(_ n: Int) -> SubSequence
|
||||
|
||||
/// Returns a subsequence containing all but the specified number of final
|
||||
/// elements.
|
||||
@@ -462,7 +462,7 @@ public protocol Sequence {
|
||||
/// - Returns: A subsequence leaving off the specified number of elements.
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the length of the sequence.
|
||||
func dropLast(_ n: Int) -> SubSequence
|
||||
__consuming func dropLast(_ n: Int) -> SubSequence
|
||||
|
||||
/// Returns a subsequence by skipping elements while `predicate` returns
|
||||
/// `true` and returning the remaining elements.
|
||||
@@ -472,7 +472,7 @@ public protocol Sequence {
|
||||
/// whether the element is a match.
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the length of the collection.
|
||||
func drop(
|
||||
__consuming func drop(
|
||||
while predicate: (Element) throws -> Bool
|
||||
) rethrows -> SubSequence
|
||||
|
||||
@@ -492,7 +492,7 @@ public protocol Sequence {
|
||||
/// `maxLength` must be greater than or equal to zero.
|
||||
/// - Returns: A subsequence starting at the beginning of this sequence
|
||||
/// with at most `maxLength` elements.
|
||||
func prefix(_ maxLength: Int) -> SubSequence
|
||||
__consuming func prefix(_ maxLength: Int) -> SubSequence
|
||||
|
||||
/// Returns a subsequence containing the initial, consecutive elements that
|
||||
/// satisfy the given predicate.
|
||||
@@ -516,7 +516,7 @@ public protocol Sequence {
|
||||
/// satisfy `predicate`.
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the length of the collection.
|
||||
func prefix(
|
||||
__consuming func prefix(
|
||||
while predicate: (Element) throws -> Bool
|
||||
) rethrows -> SubSequence
|
||||
|
||||
@@ -539,7 +539,7 @@ public protocol Sequence {
|
||||
/// at most `maxLength` elements.
|
||||
///
|
||||
/// - Complexity: O(*n*), where *n* is the length of the sequence.
|
||||
func suffix(_ maxLength: Int) -> SubSequence
|
||||
__consuming func suffix(_ maxLength: Int) -> SubSequence
|
||||
|
||||
/// Returns the longest possible subsequences of the sequence, in order, that
|
||||
/// don't contain elements satisfying the given predicate.
|
||||
@@ -590,7 +590,7 @@ public protocol Sequence {
|
||||
/// - isSeparator: A closure that returns `true` if its argument should be
|
||||
/// used to split the sequence; otherwise, `false`.
|
||||
/// - Returns: An array of subsequences, split from this sequence's elements.
|
||||
func split(
|
||||
__consuming func split(
|
||||
maxSplits: Int, omittingEmptySubsequences: Bool,
|
||||
whereSeparator isSeparator: (Element) throws -> Bool
|
||||
) rethrows -> [SubSequence]
|
||||
@@ -607,11 +607,11 @@ public protocol Sequence {
|
||||
|
||||
/// Create a native array buffer containing the elements of `self`,
|
||||
/// in the same order.
|
||||
func _copyToContiguousArray() -> ContiguousArray<Element>
|
||||
__consuming func _copyToContiguousArray() -> ContiguousArray<Element>
|
||||
|
||||
/// Copy `self` into an unsafe buffer, returning a partially-consumed
|
||||
/// iterator with any elements that didn't fit remaining.
|
||||
func _copyContents(
|
||||
__consuming func _copyContents(
|
||||
initializing ptr: UnsafeMutableBufferPointer<Element>
|
||||
) -> (Iterator,UnsafeMutableBufferPointer<Element>.Index)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user