Skip to content
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

Question: What does * and *+ mean for a lambda? #2157

Open
ruiyuanlu opened this issue Mar 9, 2024 · 2 comments
Open

Question: What does * and *+ mean for a lambda? #2157

ruiyuanlu opened this issue Mar 9, 2024 · 2 comments

Comments

@ruiyuanlu
Copy link

ruiyuanlu commented Mar 9, 2024

Hi, I tried to figure out the meaning of *identity and *+identity used in ExceptionTest.cpp but had no idea. I've never seen sth like this brefore. Why are these operators used on the lambda function identity?

Many thx for your help.

auto identity = [](int i) { return i; };
EXPECT_EQ(3, folly::catch_exception<int>(returner(3), +identity));
EXPECT_EQ(3, folly::catch_exception<int>(returner(3), *+identity));
@Orvid
Copy link
Contributor

Orvid commented Mar 21, 2024

@yfeldblum Any comment here?

@yfeldblum
Copy link
Contributor

Every capture-free or static lambda has a built-in conversion to pointer-to-function. IIUC, the use of + triggers conversion because the compiler looks for any intermediate built-in conversion that would allow + on the converted-to type. Unary + of a pointer is a no-op. And *+ is just getting a reference-to-function from pointer-to-function the way * normally does.

https://en.cppreference.com/w/cpp/language/lambda
https://en.cppreference.com/w/cpp/language/implicit_conversion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants