Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Instantiating templates with dependent arguments

Hmm interesting, that is really something I can use. I still need to be able to resolve other names than fields. But I guess having a look at the code behind getFields() and the classes ClassTypeHelper and ICPPClassSpecializationScope will help me solve this problem. I didn’t know CDT is able to do such instantiations.
But I also found this line in getFields() „CCorePlugin.log(new Exception("Unsafe method call. Instantiation of dependent expressions may not work."));“. So I’m wondering, what is the current progress of instantiations of dependent expressions?

Thanks anyway! This will help me a lot and is a way better way to get the ICPPSpecializations than our current solution.

On Mon, Apr 20, 2015 at 6:50 PM Nathan Ridge <zeratul976@xxxxxxxxxxx> wrote:
> An example:
> #include <vector>
> template<typename T>
> class Stack {
> std::vector<T> elems;
> };
> int main() {
> Stack<int> intStack;
> Stack<bool> boolStack;
> }
> intStack and boolStack both resolve to my primary template Stack. But
> if I resolve intStack our current context is T=int and I want to be
> able to also resolve the containing std::vector<T> elems to the primary
> template vector. By context I mean the types of all template
> parameters, in the above example T=int.
> But if I resolve boolStack my current context is T=bool so
> std::vector<T> elems should resolve to the fully specialized vector
> template. It should resolve to the same as when I have
> std::vector<bool>.

Suppose you start with the IASTName for 'boolStack'.

  - Calling resolveBinding() should get you an ICPPVariable.
  - Calling getType() on that should get you an ICPPClassSpecialization.
  - Calling getFields() on that should get you an array of fields,
    one of which should be an ICPPSpecialization, also implementing
    ICPPField, corresponding to the 'elems' field.
  - Calling ICPPField.getType() on that should give you an
    ICPPClassSpecialization corresponding to 'std::vector<bool>'.

Is this what you had in mind?

Regards,
Nate

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top