Skip to content
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

[SR-1238] UnsafePointer and UnsafeMutablePointer should conform to Comparable #43846

Closed
gribozavr opened this issue Apr 14, 2016 · 7 comments
Closed
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella

Comments

@gribozavr
Copy link
Collaborator

Previous ID SR-1238
Radar None
Original Reporter @gribozavr
Type Bug
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, AffectsABI, StarterBug
Assignee None
Priority Medium

md5: 82753c7162ac4d338dd8c3f8e35eecfc

Issue Description:

UnsafePointer and UnsafeMutablePointer already support operators - and +, I think it is only natural for them to also conform to Comparable.

@JaviSoto
Copy link
Contributor

It seems like `UnsafePointer` and `UnsafeMutablePointer` already provide implementations for `<`:

public func <<Memory>(lhs: UnsafePointer<Memory>, rhs: UnsafePointer<Memory>) -> Bool
public func <<Memory>(lhs: UnsafeMutablePointer<Memory>, rhs: UnsafeMutablePointer<Memory>) -> Bool

It seems like they would just need to explicitly conform to `Comparable`. However, there seems to be a conformance somewhere that I can't find. If I write this code:

extension UnsafeMutablePointer: Comparable

Swift says "Redundant conformance of 'UnsafeMutablePointer<Memory>` to protocol `Comparable`".
What am I missing?

@gribozavr
Copy link
Collaborator Author

You're right, Comparable is implied by the Strideable conformance.

If you are still interested in this project, could you add some tests for it? Please use the checkComparable function (example in validation-test/stdlib/CoreMedia.swift). The tests should go into test/1_stdlib/UnsafePointer.swift.gyb.

@JaviSoto
Copy link
Contributor

Oh, right, it's Strideable!

I'll commit the tests 🙂 Thanks for the help dmakarenko (JIRA User)!

@JaviSoto
Copy link
Contributor

Submitted PR here: #2269

@gribozavr
Copy link
Collaborator Author

In #2269 Jordan reports that OpaquePointer isn't Comparable.

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 8, 2020

Comment by Valeriy Van (JIRA)

`UnsafePointer` and `UnsafeMutablePointer` already conform to `Comparable`

1 similar comment
@swift-ci
Copy link
Collaborator

swift-ci commented Jul 8, 2020

Comment by Valeriy Van (JIRA)

`UnsafePointer` and `UnsafeMutablePointer` already conform to `Comparable`

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects ABI Flag: Affects ABI bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants