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-11156] Add UnsafePointer<Aggregate>[KeyPath] API that applies the field's offset #53553

Closed
atrick opened this issue Jul 18, 2019 · 3 comments
Assignees
Labels
feature A feature request or implementation standard library Area: Standard library umbrella swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented

Comments

@atrick
Copy link
Member

atrick commented Jul 18, 2019

Previous ID SR-11156
Radar rdar://problem/53272880
Original Reporter @atrick
Type New Feature
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels New Feature, LanguageFeatureRequest
Assignee @glessard
Priority Medium

md5: 768476fda63d417c708fa1a0e74fe03b

Issue Description:

Given a pointer to an aggregate, get a pointer to a field. This is necessary to eliminate misuse of

@atrick
Copy link
Member Author

atrick commented Jul 18, 2019

@swift-cicreate

@atrick
Copy link
Member Author

atrick commented Oct 21, 2019

The above example could have been more easily written as

withUnsafePointer(to: val.value) {
 takeIntPtr($0)
}
 

However, if it's necessary to pass pointers to multiple fields of the same struct, then the keypath approach is a better way:

withUnsafePointer(to: val) {
  takeBoolAndIntPtr($0[\.flag]!, $0[\.value]!)
} 

@glessard
Copy link
Contributor

This was part of SE-0334.

#39639

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented and removed new feature labels Nov 11, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request or implementation standard library Area: Standard library umbrella swift evolution implemented Flag → feature: A feature that was approved through the Swift evolution process and implemented
Projects
None yet
Development

No branches or pull requests

3 participants