Type: LanguageService
Describe the bug
Sometimes functions/methods/constructors take a callable object and it's useful and common to write a lambda directly in the call. However, doing so currently requires spelling the type of the argument in full in order to get VS Code's full support for checking and completion. Consider e.g.
some_future.then([](auto const& value) {
// what is `value`?
});
Given that the type of some_future is known (let's call it whatever_future<std::string>) it seems reasonable given an appropriate definition of whatever_future<T>::then that the type of value is correctly deduced to be std::string const&.
A complete example that demonstrates the problem:
#include <string>
template <typename Callable>
auto make_something(Callable&& callable) {
callable(std::string{"foobar"});
};
auto test() {
make_something([](auto const& something) {
something.size(); // here `something` is just `auto`
});
}
The equivalent in TypeScript works fine:
function makeSomething(callable: (_: string) => void) {
callable("foobar");
}
function test() {
makeSomething(something => {
something.length;
});
}
I note however that TypeScript does have a clear interface type for the callable that explains everything that's needed. In the C++ example the actual definition of the templated function needs to be used, because unless I'm missing something new and shiny with regards to Concepts, there is no good way to express the same information. But I may be wrong on that!
Thanks
It comes from our shared code with VS. I've filed a bug at https://developercommunity.visualstudio.com/content/problem/1038917/c-intellisense-auto-lambda-parameters-are-not-dedu.html .
Any progress on this? This issue is quite old and still not fixed
It looks like the linked VS issue might need more upvotes.
Well thats weird regarding that this is quite a "big" bug.
Also I could swear that the issue wasn't present in Visual Studio 2017 so it shouldn't be that big of a deal to fix.
I'll go ahead and upvote all the VS-Issues
Most helpful comment
It comes from our shared code with VS. I've filed a bug at https://developercommunity.visualstudio.com/content/problem/1038917/c-intellisense-auto-lambda-parameters-are-not-dedu.html .