I am trying to specialize a template as follows:
template<size_t _1,size_t _2> // workaround: bool consecutive = (_1 == _2 - 1)> struct integral_index_ {}; ... template<size_t _1> struct integral_index_<_1, _1 + 1> { // cannot do arithmetic? //struct integral_index_<_1, _2, true> { workaround };
however I get a compiler error
the template argument list of the partial specialization includes a non -type argument whose type depends on a template parameter.
what am I doing wrong? thanks
I put a workaround in the comments. Apparently I can't do arithmetic in the template specialization? seems controversial.
here is my final solution to the problem that needs to be solved. In principle, a sequential index requires only one multiplication.
130 template<size_t _1,size_t _2, bool consecutive = (_1 == _2 - 1)> 131 struct integral_index_ { 132 template<typename T, typename U> 133 __device__ 134 static T eval(const T (&N)[4], const U &index) { 135 T j = index/N[_1]; 136 return ((index - j*N[_1])*range<0,_1>::multiply(N) + 137 j*range<0,_2>::multiply(N)); 138 } 139 }; 140 141 template<size_t _1,size_t _2> 142 struct integral_index_<_1, _2, true> { 143 template<typename T, typename U> 144 __device__ 145 static T eval(const T (&N)[4], const U &index) { 146 return index*range<0,_1>::multiply(N); 147 } 148 }; 149 150 template<size_t _1,size_t _2, typename T, typename U> 151 __device__ 152 T integral_index(const T (&N)[4], const U &index) { 153 return integral_index_<_1,_2>::eval(N, index); 154 }
c ++ parameters templates template-specialization
Anycorn
source share