jeudi 22 février 2018

Extract outer class type from inner class instance passed to template function

I have a group of classes and inside each one is defined a nested class always with the same name.

class A {
public:
    class Common {};
    ...
};

class B {
public:
    class Common {};
    ...
};

I am trying to write a template function like this (NOT compiling code):

template<typename T, typename... ARGS>
void foo(T::Common tc, ARGS... args) {
    T t(tc, args...);
    // do stuff
}

And I would like to use it as follow:

{
    ...
    A::Common ac();
    foo(ac, 42, "Hello");
    ....
}

How could I extract the outer class type from the type on the inner class instance passed to the function? Maybe with <traits>, but I am very newbie about it...

Aucun commentaire:

Enregistrer un commentaire