-
Notifications
You must be signed in to change notification settings - Fork 76
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
add new_ptr template #905
add new_ptr template #905
Conversation
forwarding does not seem to work when used with some parameters.
::QLabel *cxxbridge1$QLabel_new_builder(::QString const &text, ::QWidget *parent) noexcept {
::QLabel *(*QLabel_new_builder$)(::QString const &, ::QWidget *) = ::new_ptr;
// ^ line with the error
return QLabel_new_builder$(text, parent);
} I was able to reproduce it: https://godbolt.org/z/baoYbaE7v |
Ah, that error. I've encountered something similar when first playing around with make_unique and friends. That's why the current functions aren't using universal references, I hadn't tried it extensively and just used what worked I've now played around with this a bit more. TL;DRReplace Long explanationSee this code: https://godbolt.org/z/nKKd6Wh3q
The reasoning is as follows: C++ needs "universal references" because of it's template argument deduction rules. The issue is that a template like this: template<typename T>
void foo(T t) {
// ...
} when called with That's why C++ introduces a special handling of r-value references in template deduction. That essentialy says However, we don't need this!
This forces Args... to be essentially We then still need Using Damn, C++ is fun, isn't it? 😅 🙈 |
Thank you very much for that deep explanation. Yes, C++ is fun and sometimes cursed. |
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.
@knoxfighter Thank you a lot for this contribution. Happy to see we have this finally done with perfect forwarding 👍
@knoxfighter please rebase this branch onto the main branch, then it should merge automatically. Unfortunately I can't do it for you, as I don't have write access to your repo. |
Head branch was pushed to by a user without write access
the automerge was cancelled by the force-push github did as i rebased the PR onto main. |
This PR also includes small changes to make_unique and make_shared, so they are properly forwarding their arguments.
see #823