|
14 | 14 | ///
|
15 | 15 | /// C++ standard library types such as `std::map` and `std::unordered_map`
|
16 | 16 | /// conform to this protocol.
|
17 |
| -public protocol CxxDictionary<Key, Value> { |
| 17 | +public protocol CxxDictionary where Key: Hashable { |
18 | 18 | associatedtype Key
|
19 | 19 | associatedtype Value
|
20 | 20 | associatedtype Element: CxxPair<Key, Value>
|
@@ -59,20 +59,22 @@ extension CxxDictionary {
|
59 | 59 | }
|
60 | 60 |
|
61 | 61 | func filter(
|
62 |
| - _ isIncluded: (Key, Value) throws -> Bool |
63 |
| - ) rethrows -> [Key: Value] { |
| 62 | + _ isIncluded: (_ key: Key, _ value: Value) throws -> Bool |
| 63 | +) rethrows -> [Key: Value] { |
64 | 64 | var filteredDictionary: [Key: Value] = [:]
|
65 |
| - let iterator = __findUnsafe(Key) |
| 65 | + var iterator = __findUnsafe(Key) |
66 | 66 | let endIterator = __endUnsafe()
|
67 | 67 |
|
68 | 68 | 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() |
74 | 74 | }
|
75 |
| - } |
| 75 | + |
| 76 | + return filteredDictionary |
| 77 | +} |
76 | 78 | }
|
77 | 79 |
|
78 | 80 | extension CxxDictionary {
|
|
0 commit comments