-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Implement Ref<T>::operator=(T*) #38232
Conversation
There are 4 ways to create a Ref: Ref<T> myref; my_ref.instance() Ref<T> my_ref(memnew(T)); Ref<T> my_ref = memnew(T); Ref<T> my_ref = Ref<T>(memnew(T)); All 4 are used in the source code but they do different things. The first straight forward but requires 2 lines. The 4th one is verbose and requires extra ref and unref. The 3rd one is shorter than the 4th but is not as efficent as we don't define operator=(T *from) so it tries to cast the pointer. This PR creates that operator and changes the 4th from to th 3rd in order to have a more compact Ref definition without unneeded casting.
7e733b5
to
2231971
Compare
I think the source of these diverse usages come from both following the existing codebase and poor documentation: likely the |
Are you sure the middle two forms don't call the existing conversion constructor for these initializations? Ref(T *p_reference) That's what the documentation on converting constructors suggests should happen, instead of The 4th form should also perform copy elision for initializations. They seem to fall under mandatory copy elision even. The less verbose forms are nicer though, for sure. It might still be useful to have this operator, of course - are there are non-initialization |
The operator part of this PR seems to have been superseded by #36189, but there are still cases of usage number 4 in the code. |
I prefer not to have this, you currently dont need to do this often so its better for readibility and avoiding mistakes that stays as-is. |
Closing as rejected (and severely outdated). |
There are 4 ways to create a Ref:
Ref<T> my_ref(memnew(T));
Ref<T> my_ref = memnew(T);
Ref<T> my_ref = Ref<T>(memnew(T));
All 4 are used in the source code but they do different things.
The first straight forward but requires 2 lines.
The 4th one is verbose and requires extra ref and unref.
The 3rd one is shorter than the 4th but is not as efficent as
we don't define operator=(T *from) so it tries to cast the pointer.
This PR creates that operator and changes the 4th from to th 3rd
in order to have a more compact Ref definition without unneeded
casting.