d - 检查是否从类型构造函数创建了完整类型

标签 d

我想检查是否从类型构造函数创建了一些完整的类型,例如在 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/

相关文章:

c - 如何避免不支持的帧速率错误?

caching - D中缓存友好的多维数组迭代

d - 如何在 Windows 下反汇编 .obj 文件?

reference-counting - 使用 RefCounted!(T) 在 D 中创建引用计数对象

unit-testing - 为什么 rdmd 可能不会运行所有单元测试?

caching - D 中内存函数的纯度

windows - 为导致崩溃的非静态函数指针赋值 - 为什么?

functional-programming - 返回 D 中函数的函数的纯函数

D是否通过副本传递值?

arrays - 语: Construct an array from a pointer and length