Skip to content

C++23's invoke_r: the library function that shouldn't exist #51

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

Closed
lefticus opened this issue Jun 23, 2022 · 6 comments
Closed

C++23's invoke_r: the library function that shouldn't exist #51

lefticus opened this issue Jun 23, 2022 · 6 comments

Comments

@lefticus
Copy link
Owner

No description provided.

@lefticus
Copy link
Owner Author

@LB--
Copy link

LB-- commented May 30, 2024

Interestingly, it appears to be possible to implement std::reference_converts_from_temporary in C++11, so the fact it took until C++23 is a bit surprising. Or maybe there is some part of it that requires compiler support, but I'm not sure what.

@lefticus
Copy link
Owner Author

@LB-- I'm confused by your reference to reference_converts_from_temporary I don't see how that comes into play for this episode

@LB--
Copy link

LB-- commented Jun 20, 2024

It's used in the definition of the INVOKE<R> exposition-only operation: https://en.cppreference.com/w/cpp/utility/functional
image
In particular this means std::invoke_r protects you from creating dangling references in some cases.

@lefticus
Copy link
Owner Author

invoke_r can only invoke implicit conversions, and we know that we don't want implicit conversions.

Worse, because it's a stdlib header file, any warnings that would have been generated are hidden by the compiler (gcc and clang, only MSVC is good enough to not exclude itself from these warnings)

https://compiler-explorer.com/z/8rYnjea1e

@lefticus lefticus changed the title C++23's invoke_r vs invoke C++23's invoke_r: the library function that shouldn't exist Jan 11, 2025
@lefticus
Copy link
Owner Author

lefticus commented Feb 3, 2025

Episode 466

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

No branches or pull requests

2 participants