如何创建一个模板来判断参数是否为结构?即如何使以下代码运行没有错误:
struct X { int a; }
static assert(isStruct!X);
static assert(!isStruct!int);
Run Code Online (Sandbox Code Playgroud)
使用is表达式.
struct X { int a; }
static assert(is(X == struct));
static assert(!is(int == struct));
Run Code Online (Sandbox Code Playgroud)
但如果你真的想要一个模板:
template isStruct(T)
{
enum bool isStruct = is(T == struct);
}
Run Code Online (Sandbox Code Playgroud)