Skip to content

Commit eb2d42e

Browse files
author
mkandil
committed
fix iterator implmentation by defining key in protocl cxxDictionary
1 parent 792dce7 commit eb2d42e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

stdlib/public/Cxx/CxxDictionary.swift

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
///
1515
/// C++ standard library types such as `std::map` and `std::unordered_map`
1616
/// conform to this protocol.
17-
public protocol CxxDictionary<Key, Value> {
17+
public protocol CxxDictionary where Key: Hashable {
1818
associatedtype Key
1919
associatedtype Value
2020
associatedtype RawIterator: UnsafeCxxInputIterator
@@ -40,18 +40,20 @@ extension CxxDictionary {
4040
}
4141

4242
func filter(
43-
_ isIncluded: (Key, Value) throws -> Bool
44-
) rethrows -> [Key: Value] {
43+
_ isIncluded: (_ key: Key, _ value: Value) throws -> Bool
44+
) rethrows -> [Key: Value] {
4545
var filteredDictionary: [Key: Value] = [:]
46-
let iterator = __findUnsafe(Key)
46+
var iterator = __findUnsafe(Key)
4747
let endIterator = __endUnsafe()
4848

4949
while iterator != endIterator {
50-
let pair = iterator.pointee
51-
if try isIncluded(pair.first, pair.second) {
52-
filteredDictionary[pair.first] = pair.second
53-
}
54-
iterator.successor()
50+
let pair = iterator.pointee
51+
if try isIncluded(pair.first, pair.second) {
52+
filteredDictionary[pair.first] = pair.second
53+
}
54+
iterator = iterator.successor()
5555
}
56-
}
56+
57+
return filteredDictionary
58+
}
5759
}

0 commit comments

Comments
 (0)