-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Add CxxOptional
protocol for std::optional
ergonomics
#63683
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
Conversation
@swift-ci please smoke test |
029f75b
to
e3acf24
Compare
@swift-ci please smoke test |
stdlib/public/Cxx/CxxOptional.swift
Outdated
} | ||
|
||
extension Optional { | ||
public init<O: CxxOptional>(fromCxx value: O) where O.Wrapped == Wrapped { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lorentey Karoy, could you please take a look to see if the signature of this initializer looks reasonable, specifically the fromCxx
label?
I couldn't make this initializer unlabeled, since Swift.Optional
already has an unlabeled initializer that wraps around the passed object, which isn't what we'd like to happen here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks okay! Naming is difficult as usual, but fromCxx
is plausible, and if we figure out a better convention, keeping this one around will not hurt much.
} | ||
|
||
extension CxxOptional { | ||
public var hasValue: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property provides the only way to check if the std::optional
has a value from Swift.
e3acf24
to
6672cd3
Compare
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved with some comments! 👍
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of `std::optional` when used from Swift code. As of now, the overlay adds an initializer of `Swift.Optional` that takes an instance of `CxxOptional` as a parameter.
6672cd3
to
a12986a
Compare
@swift-ci please smoke test |
@swift-ci please smoke test macOS |
This adds a protocol to the C++ standard library overlay which will improve the ergonomics of
std::optional
when used from Swift code.As of now, the overlay adds an initializer of
Swift.Optional
that takes an instance ofCxxOptional
as a parameter.