#Is it possible to know wether a type `type` is primive or not ?

1 messages · Page 1 of 1 (latest)

red helm
#

For example

fn is_primitive(comptime T: type) bool {
    return @typeInfo(T).isPrimivie;
}
#

Yeah actually what I wanted to do is a bad idea x)

#

But still, it'd be cool to know if you can get this info :3

wicked mica
#

what do you mean by primitive?

#

as opposed to struct, enum or union?

red helm
#

Yes

short isle
#

You can just check for those types in @typeInfo:

fn isPrimitive(comptime T: type) bool {
    return switch (@typeInfo(T)) {
        .Struct, .Union, .Enum, .Opaque => false,
        else => true,
    };
}