Using SFINAE, you can access individual elements of a variation class template. My problem arises when the base class is inherited from the variational class template, and then the derived class is again inherited from the base and from the variational class template (with different template arguments). There is ambiguity as to which chain of inheritance to follow. Is there a way to eliminate the ambiguity?
For instance:
#include <type_traits>
struct A { int x; };
struct B { int x; };
struct C { int x; };
struct D { int x; };
template <class ... Params> class Parameter { };
template <class Param, class ... Tail>
class Parameter<Param, Tail ...> : public Param, public Parameter<Tail ...>
{
public:
template <class Param2>
typename std::enable_if<std::is_same<Param, Param2>::value, int>::type
getParam() const
{ return Param::x; }
template <class Param2>
typename std::enable_if<! std::is_same<Param, Param2>::value, int>::type
getParam() const
{ return Parameter<Tail ...>::template getParam<Param2>(); }
};
class Base : public Parameter<A, B>
{ };
class Derived : public Base, public Parameter<C, D>
{ };
int main(int const argc, char const * argv[])
{
Base base;
int a = base.getParam<A>();
int b = base.getParam<B>();
Derived derived;
int c0 = derived.getParam<C>();
int c1 = derived.Derived::getParam<C>();
int c2 = derived.Parameter<C, D>::getParam<C>();
int a0 = derived.getParam<A>();
int a1 = derived.Base::getParam<A>();
int a2 = derived.Parameter<A, B>::getParam<A>();
return 0;
}
, : 1) , 2) - . , , .