-
Notifications
You must be signed in to change notification settings - Fork 261
UFCS: add method chaining #17
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: add method chaining #17
Conversation
6d02e46
to
a254bd3
Compare
Interim ack: Thanks! Yes, I've been meaning to add chaining. I was thinking of implementing it later in the same function and remove this special case part of the function (I dislike that there are two paths that deal with |
One thing I found is that it is not working when called on a constructor call - maybe I will try to add it. std::string("this will not work").method(); and this s := std::string("this will work");
s.method(); will work. |
6d78544
to
055b61e
Compare
b067266
to
8dac3b2
Compare
8dac3b2
to
5e463f0
Compare
5e463f0
to
783312e
Compare
7566599
to
14415a7
Compare
Former implementation was not supporting method chaining ```cpp v.a().b().c(); // failed to use UFCS ``` The change converts above code into nested call of `CPP2_UFCS` macros: ```cpp CPP2_UFCS_0(c, CPP2_UFCS_0(b, CPP2_UFCS_0(a, v) ) ); ``` Functions with expr-list are also handled.
14415a7
to
b035008
Compare
Picking this up: How does this relate to #18? |
It is for the cases when the first call is done on the object by calling its method. #18 is for a case when there is a free function call and the chaining starts on the function result. |
This PR is replaced by: #169 |
I have been playing with UFCS. I found that it doesn't support method chaining yet. So I have added it.
Former implementation was not supporting the method chaining - the below code failed to be compiled
The proposed change converts the above code into a nested call of
CPP2_UFCS
macros:CPP2_UFCS_0(c, CPP2_UFCS_0(b, CPP2_UFCS_0(a, v), 1, "arg" ) );
This allows using ranges library without the need of
operator|
for chaining.operator|
does not work in cppfront at the moment. What I realized is that having UFCS that supports chaining solves the problem.I don't have ranges working on my current system, so I put a custom example in the regression test directory.
Having the possibility of method chaining allows us to use smart pointers and pass them to the functions that need a raw pointers.
smart.get().func(); // UFCS will be executed on raw pointer (thanks to chaining)