判断模板参数是否为结构
Tell whether the template argument is a struct
如何制作一个模板来判断参数是否为结构体? IE。如何使以下代码 运行 不出错:
struct X { int a; }
static assert(isStruct!X);
static assert(!isStruct!int);
使用is
表达式。
struct X { int a; }
static assert(is(X == struct));
static assert(!is(int == struct));
但是如果你真的想要一个模板:
template isStruct(T)
{
enum bool isStruct = is(T == struct);
}
如何制作一个模板来判断参数是否为结构体? IE。如何使以下代码 运行 不出错:
struct X { int a; }
static assert(isStruct!X);
static assert(!isStruct!int);
使用is
表达式。
struct X { int a; }
static assert(is(X == struct));
static assert(!is(int == struct));
但是如果你真的想要一个模板:
template isStruct(T)
{
enum bool isStruct = is(T == struct);
}