Now that we’re using C++17, we can use the decltype(auto) return type for functions and lambda expressions.
As demonstrated in this commit, this can simplify cases where previously the compiler failed to deduce the correct return type.
Just for reference, for the “assign to ref” cases fixed here, there are 3 possible solutions:
- Return a pointer and immediately deref as used before this commit
- Make sure the function/lambda returns declspec(auto) as used after this commit
- Class& i = WITH_LOCK(…, return std::ref(…));
References:
- https://en.cppreference.com/w/cpp/language/function#Return_type_deduction
- https://en.cppreference.com/w/cpp/language/template_argument_deduction#Other_contexts
- https://en.cppreference.com/w/cpp/language/auto
- https://en.cppreference.com/w/cpp/language/decltype
Explanations:
Thanks to sipa and ryanofsky for helping me understand this