authorgravatar for datamanrb@gmail.comdata-man <datamanrb@gmail.com> 2020-07-17 15:47:51+05:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-07-17 17:55:55+03:00
log39915ae08668884f51071feb4b1132b1903f0abb
tree6c32c594b3271f2a145c269f39173ed5ef212b3b
parenta1e78d0b0631885b95dfa80ab617818d1fd61277

Add trait.isTuple


1 files changed, 13 insertions(+), 0 deletions(-)

lib/std/meta/trait.zig+13
......@@ -342,6 +342,19 @@ test "std.meta.trait.isContainer" {
342342 testing.expect(!isContainer(u8));
343343}
344344
345pub fn isTuple(comptime T: type) bool {
346 return is(.Struct)(T) and @typeInfo(T).Struct.is_tuple;
347}
348
349test "std.meta.trait.isTuple" {
350 const t1 = struct {};
351 const t2 = .{ .a = 0 };
352 const t3 = .{ 1, 2, 3 };
353 testing.expect(!isTuple(t1));
354 testing.expect(!isTuple(@TypeOf(t2)));
355 testing.expect(isTuple(@TypeOf(t3)));
356}
357
345358pub fn hasDecls(comptime T: type, comptime names: anytype) bool {
346359 inline for (names) |name| {
347360 if (!@hasDecl(T, name))