具有依赖名称(类型名称)的部分专业化 [英] partial specialization with dependent name (typename)
本文介绍了具有依赖名称(类型名称)的部分专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下简单的strinToTypeImpl
函数,它将任何类型的字符串转换为模板类型.我担心的问题是编译器告诉我typename MyMatrix<T>::Vector3
的部分专业化的事实:
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 compiler tells me for the partial specialization for typename MyMatrix<T>::Vector3
:
部分特化中未使用的模板参数T
我不能在专业化中使用从属名称吗?
namespace details
{
template<typename T>
struct stringToTypeImpl{
bool operator()(T& t, const std::string& s)
{
std::istringstream iss(s);
return !(iss >> t).fail();
}
};
template<typename T>
struct stringToTypeImpl< typename MyMatrix<T>::Vector3 >{
// Replacing typename MyMatrix<T>::Vector3 by
// Eigen::Matrix<T,3,1> WORKS but why?
bool operator()(typename MyMatrix<PREC>::Vector3 & t, const std::string& s)
{
stringToVector3<PREC>(t,s);
}
};
}
推荐答案
这只是问题的另一种形式,已经讨论了很多次:没有从类型X
到类型T
的一对一映射.这样的MyMatrix<T>::Vector3 == X
.
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
.
简单的例子:
MyMatrix<double> { typedef Vector3 int; };
MyMatrix<float> { typedef Vector3 int; };
stringToTypeImpl<int> // Help, what is "T"?
这篇关于具有依赖名称(类型名称)的部分专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文