cpp_weekly icon indicating copy to clipboard operation
cpp_weekly copied to clipboard

C++23's `invoke_r` vs `invoke`

Open lefticus opened this issue 3 years ago • 4 comments

lefticus avatar Jun 23 '22 00:06 lefticus

https://en.cppreference.com/w/cpp/utility/functional/invoke

lefticus avatar May 29 '24 23:05 lefticus

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.

LB-- avatar May 30 '24 03:05 LB--

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

lefticus avatar Jun 18 '24 19:06 lefticus

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.

LB-- avatar Jun 20 '24 01:06 LB--

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 avatar Jan 11 '25 23:01 lefticus

Episode 466

lefticus avatar Feb 03 '25 18:02 lefticus