Add trait.isTuple

This commit is contained in:
data-man 2020-07-17 15:47:51 +05:00 committed by Veikka Tuominen
parent a1e78d0b06
commit 39915ae086

View File

@ -342,6 +342,19 @@ test "std.meta.trait.isContainer" {
testing.expect(!isContainer(u8));
}
pub fn isTuple(comptime T: type) bool {
return is(.Struct)(T) and @typeInfo(T).Struct.is_tuple;
}
test "std.meta.trait.isTuple" {
const t1 = struct {};
const t2 = .{ .a = 0 };
const t3 = .{ 1, 2, 3 };
testing.expect(!isTuple(t1));
testing.expect(!isTuple(@TypeOf(t2)));
testing.expect(isTuple(@TypeOf(t3)));
}
pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
inline for (names) |name| {
if (!@hasDecl(T, name))