How do I get the return type of a lambda that has a deducing this signature using std::invoke_result_t.
auto lambda = [](this auto& self, int x) -> int {
return x;
};
auto x = std::invoke_result_t<decltype(lambda), int>{}; //won't compile
Do I need to somehow specify the self argument inside the std::invoke_result_t ?
I've tried without "deducing this" and the above sample works.
Edit: compiler explorer link
In your lambda,
this auto& selfactually takes an lvalue reference tothis, butstd::invoke_result_t<decltype(lambda), int>invokes the rvalue lambda.Since the rvalue cannot be bound to the lvalue reference,
invoke_resulthas no valid membertype, just asstd::move(lambda)(0)is ill-formed.You should invoke the lambda with an lvalue, e.g.
Or make the lambda accept a forward reference to
this