Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331135 - code assist can treat a template class parameter like a defined class
Summary: code assist can treat a template class parameter like a defined class
Status: RESOLVED WONTFIX
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0.1   Edit
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-25 10:33 EST by Forrest CLA
Modified: 2016-12-29 01:08 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Forrest CLA 2010-11-25 10:33:19 EST
Say you have
class A1
{
void action1();
void action2();
...
};
class A2
{
void action1();
void action2();
};
i.e. two or more classes that have a similar interface.
and then a template class that will use either A1 or A2 as template parameter:
template <class A>
class DoSomethingWithA
{
void do(A a)
{
//now a. will not bring up code assist because obviously A is an unknown class
}
};

I propose that when I write
template <class A /*as A1*/>
class DoSomethingWithA
{
void do(A a)
{
//now code assist "knows" that A has an interface similar to A1
// and can offer completions for a.

// all that has to be done is to parse the class name after "/*as "
// and copy the completions from A1 to A
}
}
Comment 1 Markus Schorn CLA 2010-12-02 05:36:00 EST
This is an interesting idea. Technically, during the lookup for content assist, we'd need to map the template parameters to the specified class. However, currently I don't have time to spend on this.
Comment 2 Nathan Ridge CLA 2013-12-15 15:59:24 EST
I think the proper solution to problems like this is Concepts.

In the C++0x concepts design, you could do something like this:

  concept A
  {
      void action1();
      void action2();
  };

  class A1  // implicitly models A
  {
      void action1();
      void action2();
  };

  class A2  // implicitly models A
  {
      void action1();
      void action2();
  };

  template <A T>  // parameter T must model concept A
  class DoSomethingWithA
  {
      void do(T a)
      {
          a.  // CDT can look in A to see what methods to offer
      }
  };

Unfortunately, this Concepts design did not make it into C++11 and was abandoned.

A new Concepts design is currently in the works [1], with part of it ("Concepts Lite") headed for C++14, and a more complete design hopefully headed for C++17. It is not yet clear to me what the complete design will look like, but hopefully it will also provide a nice solution to problems like this.

[1] http://concepts.axiomatics.org/
Comment 3 Nathan Ridge CLA 2016-12-29 01:08:23 EST
Since Concepts will provide a solution for this, I'm going to close this as WONTFIX.

If someone feels that the original request is worth implementing, feel free to reopen.