Commit 39915ae086

data-man <datamanrb@gmail.com>
2020-07-17 12:47:51
Add trait.isTuple
1 parent a1e78d0
Changed files (1)
lib
std
lib/std/meta/trait.zig
@@ -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))