mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
Add trait.isTuple
This commit is contained in:
parent
a1e78d0b06
commit
39915ae086
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user