C++ CRTP(template pattern) question
- by aaa
following piece of code does not compile, the problem is in T::rank not be inaccessible (I think) or uninitialized in parent template.
Can you tell me exactly what the problem is?
is passing rank explicitly the only way? or is there a way to query tensor class directly?
Thank you
#include <boost/utility/enable_if.hpp>
template<class T, // size_t N,
class enable = void>
struct tensor_operator;
// template<class T, size_t N>
template<class T>
struct tensor_operator<T, typename boost::enable_if_c< T::rank == 4>::type > {
tensor_operator(T &tensor) : tensor_(tensor) {}
T& operator()(int i,int j,int k,int l) {
return tensor_.layout.element_at(i, j, k, l);
}
T &tensor_;
};
template<size_t N, typename T = double>
// struct tensor : tensor_operator<tensor<N,T>, N> {
struct tensor : tensor_operator<tensor<N,T> > {
static const size_t rank = N;
};
I know the workaround, however am interested in mechanics of template instantiation for self-education