[stdlib] Nest some additional operators (#9646)

This commit is contained in:
Nate Cook
2017-05-17 21:44:08 -05:00
committed by Ben Cohen
parent 89515f8485
commit ca5c65f93c
6 changed files with 60 additions and 64 deletions

View File

@@ -469,6 +469,14 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
guard let unwrapped = from else { return nil }
self.init(unwrapped)
}
@_transparent
public static func == (
lhs: AutoreleasingUnsafeMutablePointer,
rhs: AutoreleasingUnsafeMutablePointer
) -> Bool {
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
}
}
extension UnsafeMutableRawPointer {
@@ -523,14 +531,6 @@ extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
}
}
@_transparent
public func == <Pointee>(
lhs: AutoreleasingUnsafeMutablePointer<Pointee>,
rhs: AutoreleasingUnsafeMutablePointer<Pointee>
) -> Bool {
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
}
@_fixed_layout
@_versioned
internal struct _CocoaFastEnumerationStackBuf {

View File

@@ -103,20 +103,18 @@ extension LazySequenceProtocol {
public struct LazyDropWhileIndex<Base : Collection> : Comparable {
/// The position corresponding to `self` in the underlying collection.
public let base: Base.Index
}
public func == <Base>(
lhs: LazyDropWhileIndex<Base>,
rhs: LazyDropWhileIndex<Base>
) -> Bool {
return lhs.base == rhs.base
}
public static func == (
lhs: LazyDropWhileIndex, rhs: LazyDropWhileIndex
) -> Bool {
return lhs.base == rhs.base
}
public func < <Base>(
lhs: LazyDropWhileIndex<Base>,
rhs: LazyDropWhileIndex<Base>
) -> Bool {
return lhs.base < rhs.base
public static func < (
lhs: LazyDropWhileIndex, rhs: LazyDropWhileIndex
) -> Bool {
return lhs.base < rhs.base
}
}
% for Traversal in ['Forward', 'Bidirectional']:

View File

@@ -1424,12 +1424,12 @@ public enum FloatingPointRoundingRule {
case awayFromZero
}
@_transparent
public func == <T : FloatingPoint>(lhs: T, rhs: T) -> Bool {
return lhs.isEqual(to: rhs)
}
extension FloatingPoint {
@_transparent
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.isEqual(to: rhs)
}
@_transparent
public static func < (lhs: Self, rhs: Self) -> Bool {
return lhs.isLess(than: rhs)

View File

@@ -427,17 +427,16 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
_headerOffset + MemoryLayout<Header>.size,
toAlignment: MemoryLayout<Element>.alignment)
}
public static func == (
lhs: ManagedBufferPointer, rhs: ManagedBufferPointer
) -> Bool {
return lhs._address == rhs._address
}
internal var _nativeBuffer: Builtin.NativeObject
}
public func == <Header, Element>(
lhs: ManagedBufferPointer<Header, Element>,
rhs: ManagedBufferPointer<Header, Element>
) -> Bool {
return lhs._address == rhs._address
}
// FIXME: when our calling convention changes to pass self at +0,
// inout should be dropped from the arguments to these functions.
// FIXME(docs): isKnownUniquelyReferenced should check weak/unowned counts too,

View File

@@ -111,33 +111,31 @@ public struct LazyPrefixWhileIndex<Base : Collection> : Comparable {
internal init(endOf: Base) {
self._value = .pastEnd
}
}
public func == <Base>(
lhs: LazyPrefixWhileIndex<Base>,
rhs: LazyPrefixWhileIndex<Base>
) -> Bool {
switch (lhs._value, rhs._value) {
case let (.index(l), .index(r)):
return l == r
case (.pastEnd, .pastEnd):
return true
default:
return false
public static func == (
lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
) -> Bool {
switch (lhs._value, rhs._value) {
case let (.index(l), .index(r)):
return l == r
case (.pastEnd, .pastEnd):
return true
default:
return false
}
}
}
public func < <Base>(
lhs: LazyPrefixWhileIndex<Base>,
rhs: LazyPrefixWhileIndex<Base>
) -> Bool {
switch (lhs._value, rhs._value) {
case let (.index(l), .index(r)):
return l < r
case (.index, .pastEnd):
return true
default:
return false
public static func < (
lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
) -> Bool {
switch (lhs._value, rhs._value) {
case let (.index(l), .index(r)):
return l < r
case (.index, .pastEnd):
return true
default:
return false
}
}
}

View File

@@ -55,15 +55,16 @@ public protocol ${Self} : ${Conformance} {
% end
/// Compare two `Strideable`s.
@_inlineable
public func < <T : Strideable>(x: T, y: T) -> Bool {
return x.distance(to: y) > 0
}
extension Strideable {
@_inlineable
public static func < (x: Self, y: Self) -> Bool {
return x.distance(to: y) > 0
}
@_inlineable
public func == <T : Strideable>(x: T, y: T) -> Bool {
return x.distance(to: y) == 0
@_inlineable
public static func == (x: Self, y: Self) -> Bool {
return x.distance(to: y) == 0
}
}
//===----------------------------------------------------------------------===//