Например, есть шаблон для многомерного массива:
template <typename t, size_t dim>
struct carray_base{
carray_base<t, dim>(t* data, size_t* shape, size_t* offset):
data(data), shape(shape), offset(offset) {}
/*...*/
template <typename num>
inline carray_base<t, dim-1> operator [] (num i){
return carray_base<t, dim-1>(data + (size_t)i*offset[0], shape+1, offset+1);
}
/*...*/
t* data;
size_t* shape;
size_t* offset;
};
template <typename t>
struct carray_base<t, 1>{
/*...*/
template <typename num>
inline t& operator[](num i){
return data[(size_t)i];
}
/*...*/
};