partial specialization with dependent name (typename)

前端 未结 2 1745
渐次进展
渐次进展 2021-01-25 11:23

I have the following simple strinToTypeImpl function which converts any kind of string into the template type. The problem I am concerned about is the fact that the

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-25 11:49

    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.

提交回复
热议问题