-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implementation for std::optional for java code wrappers #3035
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
base: master
Are you sure you want to change the base?
Implementation for std::optional for java code wrappers #3035
Conversation
|
Sorry, but how is it actually used on Java side? You need to add some unit tests checking that this works as expected, and they would be useful to understand this. FWIW I'm surprised that this doesn't seem to use |
|
In my case the returned value to java doesn't have any api as `isPresent()`,
`has_value()` etc.
Ex. function `optional<Point> getPoint()` is generated as `public @nullable
Point getPoint()`, under the hood it checks in cpp generated code if it has
value.
In the end for me java code generated by swig is only a proxy between cpp
and kotlin.
So in final usage in Kotlin I need to use elvis syntax ex.
`rect?.getPoint()` so when `getPoint()` is described as ***@***.***` without
this "elvis check" it won't compile.
In my opinion it is a pretty convenient solution which is natural in
Kotlin.
In the first iteration I added an additional layer with `java.util.Optional`
to generate code, but in the end I decided to skip it.
czw., 26 wrz 2024 o 16:54 VZ ***@***.***> napisał(a):
… Sorry, but how is it actually used on Java side? You need to add some unit
tests checking that this works as expected, and they would be useful to
understand this.
FWIW I'm surprised that this doesn't seem to use java.util.Optional at
all. My own SWIG typemaps for optional map it to this Java type, allowing
to use it naturally (or at least I think so) in Java, e.g. calling
isPresent() on the returned values etc.
—
Reply to this email directly, view it on GitHub
<#3035 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC6MNBMIHMSBI7PVCNS6AYDZYQNZBAVCNFSM6AAAAABO46PK4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZXGIYDMNJRGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Is this Android and/or Kotlin-specific then? |
|
Yeah, It's best adapted to use in kotlin.
czw., 26 wrz 2024 o 17:17 VZ ***@***.***> napisał(a):
… Is this Android and/or Kotlin-specific then?
—
Reply to this email directly, view it on GitHub
<#3035 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC6MNBLMBFXKL6JHP2PJ3X3ZYQQRJAVCNFSM6AAAAABO46PK4CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZXGI3DMOJZG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
std::optional was introduced in c++17, shouldn't your tests in Examples/test-suite be named cpp17_xxx instead of cpp11_xxx? |
|
Thanks @christophe-calmejane , you're right. |
I provided support for wrapping to java std::optional used with types listed below:
|- bool
|- int
|- flaot
|- long
|- double
|- std::string
I'm using it for quite a while in our project without any problems yet.
I'll also try to provide some tests in here for that implementation.