[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 } guard let unwrapped = from else { return nil }
self.init(unwrapped) self.init(unwrapped)
} }
@_transparent
public static func == (
lhs: AutoreleasingUnsafeMutablePointer,
rhs: AutoreleasingUnsafeMutablePointer
) -> Bool {
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
}
} }
extension UnsafeMutableRawPointer { 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 @_fixed_layout
@_versioned @_versioned
internal struct _CocoaFastEnumerationStackBuf { internal struct _CocoaFastEnumerationStackBuf {

View File

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

View File

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

View File

@@ -427,17 +427,16 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
_headerOffset + MemoryLayout<Header>.size, _headerOffset + MemoryLayout<Header>.size,
toAlignment: MemoryLayout<Element>.alignment) toAlignment: MemoryLayout<Element>.alignment)
} }
public static func == (
lhs: ManagedBufferPointer, rhs: ManagedBufferPointer
) -> Bool {
return lhs._address == rhs._address
}
internal var _nativeBuffer: Builtin.NativeObject 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, // FIXME: when our calling convention changes to pass self at +0,
// inout should be dropped from the arguments to these functions. // inout should be dropped from the arguments to these functions.
// FIXME(docs): isKnownUniquelyReferenced should check weak/unowned counts too, // 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) { internal init(endOf: Base) {
self._value = .pastEnd self._value = .pastEnd
} }
}
public func == <Base>( public static func == (
lhs: LazyPrefixWhileIndex<Base>, lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
rhs: LazyPrefixWhileIndex<Base> ) -> Bool {
) -> Bool { switch (lhs._value, rhs._value) {
switch (lhs._value, rhs._value) { case let (.index(l), .index(r)):
case let (.index(l), .index(r)): return l == r
return l == r case (.pastEnd, .pastEnd):
case (.pastEnd, .pastEnd): return true
return true default:
default: return false
return false }
} }
}
public func < <Base>( public static func < (
lhs: LazyPrefixWhileIndex<Base>, lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
rhs: LazyPrefixWhileIndex<Base> ) -> Bool {
) -> Bool { switch (lhs._value, rhs._value) {
switch (lhs._value, rhs._value) { case let (.index(l), .index(r)):
case let (.index(l), .index(r)): return l < r
return l < r case (.index, .pastEnd):
case (.index, .pastEnd): return true
return true default:
default: return false
return false }
} }
} }

View File

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