Question

Consider the following code:

template<typename T, size_t... i>
class Bar{};

template<typename T1, typename T2>
class Foo{};

template<typename T1, size_t... i1>
template<typename T2, size_t... i2>
struct Foo<Bar<T1,i1...>,Bar<T2,i2...>>
{
    struct Eq {};
};

As you see, there is a variadic type Bar<T,size_t...> and a type Foo<T1,T2>. Foo has a specialization in case that two Bars are used as its template parameters. This specialization has an inner type Eq.

However, the following does not work:

typename Foo<Bar<int,2>,Bar<int,3>>::Eq b;

It tells that there is no type Eq in Foo<Bar<int,2>,Bar<int,3>>, i.e., the compiler does not pick the template specialization but the base definition of Foo<T1,T2> which indeed has no inner Eq type.

What am I doing wrong here? Why does the compiler not pick the specialization?

Was it helpful?

Solution

Just get rid of double template argument list:

template<typename T1, size_t... i1>
template<typename T2, size_t... i2>

Change to:

template<typename T1, size_t... i1, typename T2, size_t... i2>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top