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 RawIterator : UnsafeCxxInputIterator
@@ -40,18 +40,20 @@ extension CxxDictionary {
40
40
}
41
41
42
42
func filter(
43
- _ isIncluded: ( Key , Value ) throws -> Bool
44
- ) rethrows -> [ Key : Value ] {
43
+ _ isIncluded: ( _ key : Key , _ value : Value ) throws -> Bool
44
+ ) rethrows -> [ Key : Value ] {
45
45
var filteredDictionary : [ Key : Value ] = [ : ]
46
- let iterator = __findUnsafe ( Key)
46
+ var iterator = __findUnsafe ( Key)
47
47
let endIterator = __endUnsafe ( )
48
48
49
49
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 ( )
55
55
}
56
- }
56
+
57
+ return filteredDictionary
58
+ }
57
59
}
0 commit comments