10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ /// A C++ type that represents a set of values, which might be repeating.
14
+ ///
15
+ /// C++ standard library types such as `std::set`, `std::unordered_set` and
16
+ /// `std::multiset` conform to this protocol.
17
+ ///
18
+ /// - SeeAlso: `CxxUniqueSet`
13
19
public protocol CxxSet < Element> {
14
20
associatedtype Element
15
21
associatedtype Size : BinaryInteger
@@ -41,12 +47,18 @@ extension CxxSet {
41
47
}
42
48
}
43
49
50
+ /// Returns a Boolean value that indicates whether the given element exists
51
+ /// in the set.
44
52
@inlinable
45
53
public func contains( _ element: Element ) -> Bool {
46
54
return count ( element) > 0
47
55
}
48
56
}
49
57
58
+ /// A C++ type that represents a set of unique values.
59
+ ///
60
+ /// C++ standard library types such as `std::set` and `std::unordered_set`
61
+ /// conform to this protocol.
50
62
public protocol CxxUniqueSet < Element> : CxxSet {
51
63
override associatedtype Element
52
64
override associatedtype Size : BinaryInteger
@@ -57,12 +69,22 @@ public protocol CxxUniqueSet<Element>: CxxSet {
57
69
}
58
70
59
71
extension CxxUniqueSet {
72
+ /// Inserts the given element in the set if it is not already present.
73
+ ///
74
+ /// If an element equal to `newMember` is already contained in the set, this
75
+ /// method has no effect.
76
+ ///
77
+ /// - Parameter newMember: An element to insert into the set.
78
+ /// - Returns: `(true, newMember)` if `newMember` was not contained in the
79
+ /// set. If an element equal to `newMember` was already contained in the
80
+ /// set, the method returns `(false, oldMember)`, where `oldMember` is the
81
+ /// element that was equal to `newMember`.
60
82
@inlinable
61
83
@discardableResult
62
84
public mutating func insert(
63
- _ element : Element
85
+ _ newMember : Element
64
86
) -> ( inserted: Bool , memberAfterInsert: Element ) {
65
- let insertionResult = self . __insertUnsafe ( element )
87
+ let insertionResult = self . __insertUnsafe ( newMember )
66
88
let rawIterator : RawMutableIterator = insertionResult. first
67
89
let inserted : Bool = insertionResult. second
68
90
return ( inserted, rawIterator. pointee)
0 commit comments