我想检查是否从类型构造函数创建了一些完整的类型,例如在 C++ 中我可以这样做
#include <vector>
#include <iostream>
template<class T>
struct is_vector{
static constexpr bool value = false;
};
template<class A,class B>
struct is_vector<std::vector<A,B>>{
static constexpr bool value = true;
};
int main(){
int i;
std::vector<int> iv;
std::cout << is_vector<int>::value << std::endl;
std::cout << is_vector<std::vector<int>>::value << std::endl;
}
现在我想在 D 中做同样的事情
struct ShaderType(T,string s){
alias Type = T;
enum string stringType = s;
}
template isShaderType(T){
enum isShaderType = false;
}
template isShaderType(A,string s, T: ShaderType!(A,s) ){
enum isShaderType = true;
}
void main(){
writeln(isShaderType!(ShaderType!(int,"int")));
}
遗憾的是,这打印错误,我不知道为什么。
最佳答案
隐式模板参数位于 D: 列表的末尾
template isShaderType(T: ShaderType!(A,s), A, string s){
另请查看std.traits.isInstanceOf
.
关于d - 检查是否从类型构造函数创建了完整类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33694276/