I'm trying to use std::invoke_result_t and it fails when called for nested lambda in function with auto return type. Here is a reproducer:
template <typename T, typename... Args>
auto print_ret_type(T &&t, Args &&... args) {
using ret_type = std::invoke_result_t<T, Args...>;
std::cout << typeid(ret_type).name() << std::endl;
}
int main(int argc, const char **argv) {
auto worker = [](int i) {
auto worker_impl = [](int i, auto &worker) {
print_ret_type(worker, i, worker);
};
worker_impl(i, worker_impl);
};
worker(10);
return 0;
}
I get the following error:
include/c++/9.3.0/type_traits:2783:5: error: no type named 'type' in 'std::invoke_result<(lambda at test.cpp:13:24) &, int &, (lambda at test.cpp:13:24) &>'
using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
If I use void return type for print_ret_type instead of auto the test compiles successfully. There is a returned template structure in my original code, which depends on ret_type. Can anyone explain why I get an error when auto return type is used?