-
Notifications
You must be signed in to change notification settings - Fork 261
UFCS: function call starts UFCS chaining #18
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
UFCS: function call starts UFCS chaining #18
Conversation
105feda
to
bb68fd9
Compare
https://github.com/isocpp/CppCoreGuidelines/blob/master/docs/Lifetime.pdf should take care of that. It mentions:
It could do similarly for |
bb68fd9
to
be9ff82
Compare
Another interesting extension can be proposed to make calling functions like visit: (in v:_, in callable:_) -> auto = {
return callable(v);
}
main: () -> int = {
fopen("one_liner.txt", "w").on_scope_exit(fclose).get().visit(:(e:_) = {
e.fprintf("1) This is oneliner!!\n\n");
e.fprintf("2) This is oneliner!!\n\n");
e.fprintf("3) This is oneliner!!\n\n");
e.fprintf("4) This is oneliner!!\n\n");
e.fprintf("5) This is oneliner!!\n\n");
e.fprintf("6) This is oneliner!!\n\n");
});
} |
(Repeating from #17) |
be9ff82
to
7823650
Compare
7823650
to
a3ffe9b
Compare
cea865b
to
62a9472
Compare
62a9472
to
37eb661
Compare
37eb661
to
9b556e4
Compare
9b556e4
to
9f12c53
Compare
f263cba
to
0ff43ba
Compare
0ff43ba
to
ef5f875
Compare
Picking this up: I'm willing to consider UFCS chaining, even as an additional section within the function. Before I look at this more closely... do you want to pursue this now? if yes does it need to be rebased including to mirror the updates I just made to the current UFCS code (we want to stay consistent)? Thanks! |
Adding bidirectional xrefs: How does this relate to #17? |
This is for a case when there is a free function call and the chaining starts on the function result. #17 is for the cases when the first call is done on the object by calling its method. |
I am pretty sure it needs to be rebased. I can do that tomorrow. |
This PR is replaced by: #169 |
On the stdio example there is a call to c-function:
This is great but we can do better than that. What I don't like about this approach is the lost opportunity to save us from resource leak. What I would like to do is to have a possibility to wrap the return
FILE*
into something that will clean things up.I have implemented the feature that starts UFCS chaining on the function call of syntax func1().func2() (it can go recursively further). That brings us more interesting features like wrapping things into smart pointers in one call.
That can go even further. Thanks to #13 the code can be even simpler:
The last use case (one-liner) makes me think that UFCS brings some risk of leaking resources when chained. When results of
fopen
will be used byfprintf
directly the pointer to file will be lost.I will investigate if there is a possibility to block potentially leaking combinations. Smart pointers are safe and we can eliminate cases when rvalue pointers are passed to a chained function.