Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines

This commit is contained in:
Doug Gregor
2015-12-18 10:15:47 -08:00
171 changed files with 1361 additions and 594 deletions

View File

@@ -11,47 +11,50 @@
//===----------------------------------------------------------------------===//
/// Returns the lesser of `x` and `y`.
///
/// If `x == y`, returns `x`.
@warn_unused_result
public func min<T : Comparable>(x: T, _ y: T) -> T {
var r = x
if y < x {
r = y
}
return r
// In case `x == y` we pick `x`.
// This preserves any pre-existing order in case `T` has identity,
// which is important for e.g. the stability of sorting algorithms.
// `(min(x, y), max(x, y))` should return `(x, y)` in case `x == y`.
return y < x ? y : x
}
/// Returns the least argument passed.
///
/// If there are multiple equal least arguments, returns the first one.
@warn_unused_result
public func min<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
var r = x
if y < x {
r = y
var minValue = min(min(x, y), z)
// In case `value == minValue`, we pick `minValue`. See min(_:_:).
for value in rest where value < minValue {
minValue = value
}
if z < r {
r = z
}
for t in rest {
if t < r {
r = t
}
}
return r
return minValue
}
/// Returns the greater of `x` and `y`.
///
/// If `x == y`, returns `y`.
@warn_unused_result
public func max<T : Comparable>(x: T, _ y: T) -> T {
// In case `x == y`, we pick `y`. See min(_:_:).
return y >= x ? y : x
}
/// Returns the greatest argument passed.
///
/// If there are multiple equal greatest arguments, returns the last one.
@warn_unused_result
public func max<T : Comparable>(x: T, _ y: T, _ z: T, _ rest: T...) -> T {
var r = max(max(x, y), z)
for t in rest where t >= r {
r = t
var maxValue = max(max(x, y), z)
// In case `value == maxValue`, we pick `value`. See min(_:_:).
for value in rest where value >= maxValue {
maxValue = value
}
return r
return maxValue
}
/// The iterator for `EnumeratedSequence`. `EnumeratedIterator`