Skip to content

Commit e74424a

Browse files
committed
Implement slice Indices using their base Indices
1 parent ee06256 commit e74424a

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

stdlib/public/core/Indices.swift.gyb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public struct ${Self}<
3434
Elements : ${collectionForTraversal(Traversal)}
3535
> : ${collectionForTraversal(Traversal)} {
3636

37-
// FIXME(compiler limitation): this typealias should be inferred.
3837
public typealias Index = Elements.Index
38+
public typealias Indices = ${Self}<Elements>
3939

4040
@_inlineable
4141
@_versioned
@@ -50,12 +50,12 @@ public struct ${Self}<
5050
}
5151

5252
@_inlineable
53-
public var startIndex: Elements.Index {
53+
public var startIndex: Index {
5454
return _startIndex
5555
}
5656

5757
@_inlineable
58-
public var endIndex: Elements.Index {
58+
public var endIndex: Index {
5959
return _endIndex
6060
}
6161

@@ -65,7 +65,6 @@ public struct ${Self}<
6565
return i
6666
}
6767

68-
// FIXME(compiler limitation): this typealias should be inferred.
6968
public typealias SubSequence = ${Self}<Elements>
7069

7170
@_inlineable
@@ -103,9 +102,6 @@ public struct ${Self}<
103102
}
104103
% end
105104

106-
// FIXME(compiler limitation): this typealias should be inferred.
107-
public typealias Indices = ${Self}<Elements>
108-
109105
@_inlineable
110106
public var indices: Indices {
111107
return self
@@ -120,10 +116,7 @@ public struct ${Self}<
120116
}
121117

122118
extension ${collectionForTraversal(Traversal)}
123-
% if Traversal != 'RandomAccess':
124-
where Indices == ${Self}<Self>
125-
% end
126-
{
119+
where Indices == ${Self}<Self> {
127120
/// The indices that are valid for subscripting the collection, in ascending
128121
/// order.
129122
///

stdlib/public/core/Slice.swift.gyb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
116116
: ${SelfProtocols} {
117117

118118
public typealias Index = Base.Index
119-
public typealias IndexDistance = Base.IndexDistance
120-
public typealias Indices = ${Indices}<${Self}<Base>>
119+
public typealias IndexDistance = Base.IndexDistance
121120

122121
public var _startIndex: Index
123122
public var _endIndex: Index
@@ -164,13 +163,10 @@ public struct ${Self}<Base : ${BaseRequirements}>
164163
% end
165164
}
166165

167-
// FIXME(ABI)#67 (Associated Types with where clauses):
168-
//
169-
// public typealias Indices = Base.Indices
170-
// public var indices: Indices { ... }
171-
//
172-
// We can't do it right now because we don't have enough
173-
// constraints on the Base.Indices type in this context.
166+
public typealias Indices = Base.Indices
167+
public var indices: Indices {
168+
return _base.indices[_startIndex..<_endIndex]
169+
}
174170

175171
@_inlineable // FIXME(sil-serialize-all)
176172
public func index(after i: Index) -> Index {

0 commit comments

Comments
 (0)