Skip to content

Commit 9786d11

Browse files
committed
feat: add comparable conformance for C++ strings
1 parent ba585fd commit 9786d11

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,26 @@ extension std.u32string: Equatable {
161161
}
162162
}
163163

164+
// MARK: Comparable conformance for C++ strings
165+
166+
extension std.string: Comparable {
167+
public static func <(lhs: std.string, rhs: std.string) -> Bool {
168+
return lhs.compare(rhs) < 0
169+
}
170+
}
171+
172+
extension std.u16string: Comparable {
173+
public static func <(lhs: std.u16string, rhs: std.u16string) -> Bool {
174+
return lhs.compare(rhs) < 0
175+
}
176+
}
177+
178+
extension std.u32string: Comparable {
179+
public static func <(lhs: std.u32string, rhs: std.u32string) -> Bool {
180+
return lhs.compare(rhs) < 0
181+
}
182+
}
183+
164184
// MARK: Hashing C++ strings
165185

166186
extension std.string: Hashable {

0 commit comments

Comments
 (0)