Problem with partial template specialization with CRTP

74 views Asked by At

I can't figure out how to partially specialize a base class that uses the curiously recurring template pattern (CRTP). The specialty of this CRTP is that the derived class itself is a class template. Here's what I try:

#include "iostream"
using namespace std;

template<class T> class Word;

template<class T, template<class> class C>
class BaseView
{
public:
  BaseView() { cout << "normal BaseView" << endl; }
};


#if 0
template<class T, template<class> class C >
class BaseView<Word<T> , C<Word<T> > >
{
public:
  BaseView() { cout << "BaseView specialized on Word" << endl; }
};
#endif


template<class T> class A: public BaseView<T,A>
{
public:
  A():BaseView<T,A>() {}
};





int main()
{
  A<A<Word<int> > > a0;
  A<Word<int> > a1;
}

I'd like the construction of the second object (a1) to use the (partially) specialized base class (the one that's ifdef'd out in the code above).

GCC++ v12 tells me that for the 2nd argument in the template parameter list it expected a class template, got ‘C<Word >. Which makes sense, but I don't know how to change the code to make it work.

0

There are 0 answers