You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] No direct UFCS syntax for (captured function object, dependent base member, function object prvalue) #748
At first, I tried using UFCS.
That doesn't work because the capture is the postfix-expression before the $.
That includes the object argument.
But I just wanted the function object.
Right, I like the call helper well enough that I'm waiting to see if there's really a need to write a new function expression in the middle of a postfix-expression... it's doable but is it needed?
You could say it's needed for #748,
so we could write w: (f) :(x) x.(f$)();
and have x.(f$)() call (f$)(x).
Right, I like the call helper well enough that I'm waiting to see if there's really a need to write a new function expression in the middle of a postfix-expression... it's doable but is it needed?
You could say it's needed for #748,
so we could write w: (f) :(x) x.(f$)();
and have x.(f$)() call (f$)(x).
There is another use case.
In a member function of a type template,
UFCS on a dependent base member requires explicit qualification (https://cpp2.godbolt.org/z/Mff1G9331):
u: @struct <T> type = {
f: (_) true;
}
t: @struct <T> type = {
this: u<T>;
operator(): (this, r: std::span<const int>) -> _ = {
for r do (e) {
// OK.
return this.f(e);
// error: explicit qualification required to use member 'f' from dependent base class
// 16 | return CPP2_UFCS_0(f, e);
// | ^
return e.f();
// error: expected unqualified-id
// 21 | return CPP2_UFCS_0(f, e.(*this));
// | ^
return e.this.f();
// OK.
return e.u<T>::f();
// What I would like to write:
// return e.(this.f)();
// That translates to this:
return (this.f)(e);
}
}
}
main: () = {
r: std::vector = (0, 1, 2);
assert(t<int>()(r));
}
changed the title [-][BUG] Can't capture function object for UFCS[/-][+][BUG] Can't use UFCS on captured function object or dependent base member[/+]on Nov 25, 2023
changed the title [-][BUG] Can't use UFCS on captured function object or dependent base member[/-][+][BUG] No direct UFCS syntax for (captured function object, dependent base member, function object prvalue)[/+]on Nov 26, 2023
Activity
JohelEGP commentedon Nov 11, 2023
From #741 (comment):
JohelEGP commentedon Nov 25, 2023
Also, can't do UFCS on a dependent base member (#741 (comment)):
[-][BUG] Can't capture function object for UFCS[/-][+][BUG] Can't use UFCS on captured function object or dependent base member[/+]JohelEGP commentedon Nov 25, 2023
For now, I can workaround this with
using u<T>::f;, which makesreturn e.f();well-formed: https://cpp2.godbolt.org/z/T5b5sxbYr.JohelEGP commentedon Nov 26, 2023
Function object prvalue
I forgot to mention this other case where you first need to construct a callable.
Consider the call in the
assertin themainabove:t<int>()(r).t<int>()is the function object we want to call.Let's rewrite it in UFCS order:
r.t<int>()().The function to call becomes
t<int>instead.The second
()applies to the result of the UFCS.The
callhelper does help:r.call(t<int>())(https://cpp2.godbolt.org/z/Mfc5TP8xz).[-][BUG] Can't use UFCS on captured function object or dependent base member[/-][+][BUG] No direct UFCS syntax for (captured function object, dependent base member, function object prvalue)[/+]