[stdlib] Remove now-redundant slicing operations

This commit is contained in:
Dave Abrahams
2017-05-22 15:36:22 -07:00
parent 501fcf5a33
commit b677e1d6e4
2 changed files with 2 additions and 102 deletions

View File

@@ -466,106 +466,6 @@ ${orderingExplanation}
}
}
% for Self in '_Indexable', '_MutableIndexable':
%{
subscriptCommentPre = """\
/// Accesses a contiguous subrange of the collection's elements.
///
/// The accessed slice uses the same indices for the same elements as the
/// original collection. Always use the slice's `startIndex` property
/// instead of assuming that its indices start at a particular value.
///
/// This example demonstrates getting a slice of an array of strings, finding
/// the index of one of the strings in the slice, and then using that index
/// in the original array.
///
/// let streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
/// let streetsSlice = streets[2 ..< streets.endIndex]
/// print(streetsSlice)
/// // Prints "["Channing", "Douglas", "Evarts"]"
///
/// let index = streetsSlice.index(of: "Evarts") // 4"""
if 'Mutable' in Self:
subscriptCommentMid = """\
/// streets[index!] = "Eustace"
/// print(streets[index!])
/// // Prints "Eustace\""""
else:
subscriptCommentMid = """\
/// print(streets[index!])
/// // Prints "Evarts\""""
subscriptCommentPost = """\
///
/// - Parameter bounds: A range of the collection's indices. The bounds of
/// the range must be valid indices of the collection."""
}%
// FIXME(ABI)#180 (Type checker)
// WORKAROUND rdar://25214066 - should be on Collection
extension ${Self} {
${subscriptCommentPre}
${subscriptCommentMid}
${subscriptCommentPost}
@_inlineable
public subscript(bounds: ClosedRange<Index>) -> SubSequence {
get {
return self[
Range(
uncheckedBounds: (
lower: bounds.lowerBound,
upper: index(after: bounds.upperBound)))
]
}
% if 'Mutable' in Self:
set {
self[
Range(
uncheckedBounds: (
lower: bounds.lowerBound,
upper: index(after: bounds.upperBound)))
] = newValue
}
% end
}
}
// FIXME(ABI)#180 (Type checker)
// WORKAROUND rdar://25214066 - should be on Collection
extension ${Self} where Index : Strideable, Index.Stride : SignedInteger {
${subscriptCommentPre}
${subscriptCommentMid}
${subscriptCommentPost}
@_inlineable
public subscript(bounds: CountableRange<Index>) -> SubSequence {
get {
return self[Range(bounds)]
}
% if 'Mutable' in Self:
set {
self[Range(bounds)] = newValue
}
% end
}
${subscriptCommentPre}
${subscriptCommentMid}
${subscriptCommentPost}
@_inlineable
public subscript(bounds: CountableClosedRange<Index>) -> SubSequence {
get {
return self[ClosedRange(bounds)]
}
% if 'Mutable' in Self:
set {
self[ClosedRange(bounds)] = newValue
}
% end
}
}
% end
//===--- Unavailable stuff ------------------------------------------------===//
extension MutableCollection where Self : RandomAccessCollection {