How can I make a template that tells whether the argument is a struct or not? I.e. how to make the following code run without an error:
struct X { int a; }
static assert(isStruct!X);
static assert(!isStruct!int);
Use is
expression.
struct X { int a; }
static assert(is(X == struct));
static assert(!is(int == struct));
But if you really want a template:
template isStruct(T)
{
enum bool isStruct = is(T == struct);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With