In this question, I unsuccessfully asked how to use a different implementation of pimpl depending on the template argument.
Perhaps this example better illustrates what I'm trying to do:
#include <iostream> template< int N, typename T > struct B { B() : c( new C< N > ) {} template< int M > struct C; C< N > *c; }; template< int N, typename T > template< int M > struct B< N, T >::C { int a[M]; }; // version 1 that doesn't work template< int N, typename T > template< > struct B< N, T >::C< 0 > { int a; }; // version 2 that doesn't work template< typename T > template< int M > struct B< 0, T >::C { int a; }; int main() { B< 0, float > b0; B< 1, int > b1; std::cout << "b0 = " << sizeof(b0.c->a) << std::endl; std::cout << "b1 = " << sizeof(b1.c->a) << std::endl; }
It still fails if I try to specialize the C structure (above does not compile)
So can this be done?
I know a job like this:
template< int M > struct D { int a[M]; }; template< > struct D<0> { int a; }; template< int N, typename T > template< int M > struct B< N, T >::C { D< M > helper; };
but if possible i would like to avoid this
source share