Default argument heuristic for template parameters #1056
Replies: 2 comments 4 replies
-
|
This sounds really useful e.g. for dependency injection via templates: |
Beta Was this translation helpful? Give feedback.
-
|
Yes, it would be very useful. Actually, we just switched from IntelliSense to Clangd and would not switch back due to many great features that clangd provides. But this feature is really missing for us in clangd. We also use inl files to make the implementation separate from the template definition and then you have to jump to another file to find the place where you can jump to the Implementation... What we currently do as workaround is, that we change the template in the inl file to <class Implementation> and then you get the right suggestions. Then when we are finished with programming we switch it back to <class Imp = Implementation>. So this feature would really benefit us! |
Beta Was this translation helpful? Give feedback.
-
Clangd uses heuristics (implemented in the class
HeuristicResolver) to try to resolve dependent names in templates to their declarations.Currently, the main heuristic that's employed is assuming that a dependent template specialization will resolve to the primary template rather than to an explicit or partial specialization, which then allows us to heuristically resolve e.g.
A<T>::foo(whereTis dependent) by looking upfooin the scope of the primary template definition ofA.Another heuristic that's occurred to me recently is that if
Tis a template parameter, and it has a default argument, heuristic resolution could try to replce it with its default argument. So, e.g. if you're trying to resolveAllocator::pointer_typeinsidevector<T, Allocator>, currently we can't resolve that, but with this heuristic, ifAllocatorhas the default arugmentstd::allocator<T>, we'd heuristically resolve it by replacingAllocator::pointer_typewithstd::allocator<T>::pointer_type(and then apply the existing heuristic to look uppointer_typein the primary template definition ofstd::allocator).Thoughts? Does this heuristic seem useful / desirable?
Beta Was this translation helpful? Give feedback.
All reactions