Skip to content

[stdlib] Nest some additional operators #9646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions stdlib/public/core/BridgeObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 10 additions & 12 deletions stdlib/public/core/DropWhile.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
10 changes: 5 additions & 5 deletions stdlib/public/core/FloatingPoint.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions stdlib/public/core/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
46 changes: 22 additions & 24 deletions stdlib/public/core/PrefixWhile.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
17 changes: 9 additions & 8 deletions stdlib/public/core/Stride.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

//===----------------------------------------------------------------------===//
Expand Down