partial specialization with dependent name (typename)

纵然是瞬间 提交于 2019-12-02 04:44:55

This is just another form of the problem that has been discussed many times: There's no one-to-one mapping from types X to types T such that MyMatrix<T>::Vector3 == X.

Simple example:

MyMatrix<double> { typedef Vector3 int; };
MyMatrix<float> { typedef Vector3 int; };

stringToTypeImpl<int> // Help, what is "T"?

Kerreck's answer and my comment there explain the problem. There is no way for the type system to map a member to a parent-of-member, so the :: operator stops the deduction process which needs to match T.

The simple way to a solution would be to bring Vector3 outside and specialize it on the matrix type, then make the member MyMatrix< T >::Vector3 a typedef.

template< typename Matrix >
struct Vector3 {
    typename Matrix::ValueType x, y, z;
};

template< typename T >
struct MyMatrix {
    typedef Vector3< MyMatrix > Vector3;
};

The partial specialization of StringToTypeImpl needs to be on the final template type, not the typedef. Partial specialization cannot match across a set of typedefs, although specialization can match type to the type aliased by a single typedef name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!