I'm running into the following issue when using ref qualifiers with operator()
below. What is the correct syntax to enable the l-value ref overload in this instance?
#include <functional>
struct F {
void operator()() & {}
void operator()() && {} // Commenting this overload enables code to compile
};
int main() {
F f;
std::invoke(&F::operator(), f);
}
Error
<source>: In function 'int main()':
<source>:10:15: error: no matching function for call to 'invoke(<unresolved overloaded function type>, F&)'
10 | std::invoke(&F::operator(), f);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from <source>:1:
/opt/compiler-explorer/gcc-trunk-20220731/include/c++/13.0.0/functional:107:5: note: candidate: 'template<class _Callable, class ... _Args> constexpr std::invoke_result_t<_Fn, _Args ...> std::invoke(_Callable&&, _Args&& ...)'
107 | invoke(_Callable&& __fn, _Args&&... __args)
| ^~~~~~
/opt/compiler-explorer/gcc-trunk-20220731/include/c++/13.0.0/functional:107:5: note: template argument deduction/substitution failed:
<source>:10:15: note: couldn't deduce template parameter '_Callable'
10 | std::invoke(&F::operator(), f);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ASM generation compiler returned: 1
<source>: In function 'int main()':
<source>:10:15: error: no matching function for call to 'invoke(<unresolved overloaded function type>, F&)'
10 | std::invoke(&F::operator(), f);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In file included from <source>:1:
/opt/compiler-explorer/gcc-trunk-20220731/include/c++/13.0.0/functional:107:5: note: candidate: 'template<class _Callable, class ... _Args> constexpr std::invoke_result_t<_Fn, _Args ...> std::invoke(_Callable&&, _Args&& ...)'
107 | invoke(_Callable&& __fn, _Args&&... __args)
| ^~~~~~
/opt/compiler-explorer/gcc-trunk-20220731/include/c++/13.0.0/functional:107:5: note: template argument deduction/substitution failed:
<source>:10:15: note: couldn't deduce template parameter '_Callable'
10 | std::invoke(&F::operator(), f);
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
Execution build compiler returned: 1