mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] add two-operand version of min.
This corresponds to the change on max at r18767. Swift SVN r18769
This commit is contained in:
@@ -299,14 +299,25 @@ func swap<T>(inout a : T, inout b : T) {
|
||||
}
|
||||
|
||||
|
||||
func min<T : Comparable>(x: T, y: T, rest: T...) -> T {
|
||||
func min<T : Comparable>(x: T, y: T) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
r = y
|
||||
}
|
||||
for z in rest {
|
||||
if z < r {
|
||||
r = z
|
||||
return r
|
||||
}
|
||||
|
||||
func min<T : Comparable>(x: T, y: T, z: T, rest: T...) -> T {
|
||||
var r = x
|
||||
if y < x {
|
||||
r = y
|
||||
}
|
||||
if z < r {
|
||||
r = z
|
||||
}
|
||||
for t in rest {
|
||||
if t < r {
|
||||
r = t
|
||||
}
|
||||
}
|
||||
return r
|
||||
|
||||
Reference in New Issue
Block a user