Skip to content

Commit e30b8fd

Browse files
author
mkandil
committed
fix iterator implmentation by defining key in protocl cxxDictionary
1 parent d8b0d53 commit e30b8fd

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 Element: CxxPair<Key, Value>
@@ -59,20 +59,22 @@ extension CxxDictionary {
5959
}
6060

6161
func filter(
62-
_ isIncluded: (Key, Value) throws -> Bool
63-
) rethrows -> [Key: Value] {
62+
_ isIncluded: (_ key: Key, _ value: Value) throws -> Bool
63+
) rethrows -> [Key: Value] {
6464
var filteredDictionary: [Key: Value] = [:]
65-
let iterator = __findUnsafe(Key)
65+
var iterator = __findUnsafe(Key)
6666
let endIterator = __endUnsafe()
6767

6868
while iterator != endIterator {
69-
let pair = iterator.pointee
70-
if try isIncluded(pair.first, pair.second) {
71-
filteredDictionary[pair.first] = pair.second
72-
}
73-
iterator.successor()
69+
let pair = iterator.pointee
70+
if try isIncluded(pair.first, pair.second) {
71+
filteredDictionary[pair.first] = pair.second
72+
}
73+
iterator = iterator.successor()
7474
}
75-
}
75+
76+
return filteredDictionary
77+
}
7678
}
7779

7880
extension CxxDictionary {

0 commit comments

Comments
 (0)