diff options
| author | data-man <datamanrb@gmail.com> | 2020-01-07 19:14:37 +0500 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-02-13 12:13:55 +0100 |
| commit | 4578d13b49d16463b870119005877f7b6e10092e (patch) | |
| tree | 11279ba404a894022ebc08f401bea6fff89e347c /lib/std/meta.zig | |
| parent | 55304128c086989ad4c08e51c7708d61d544e820 (diff) | |
| download | zig-4578d13b49d16463b870119005877f7b6e10092e.tar.gz zig-4578d13b49d16463b870119005877f7b6e10092e.zip | |
Vector comparison in meta and testing
Diffstat (limited to 'lib/std/meta.zig')
| -rw-r--r-- | lib/std/meta.zig | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 5cb9c6589c..f090e1e8e4 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -433,6 +433,14 @@ pub fn eql(a: var, b: @TypeOf(a)) bool { if (!eql(e, b[i])) return false; return true; }, + builtin.TypeId.Vector => { + const info = @typeInfo(T).Vector; + var i: usize = 0; + while (i < info.len) : (i += 1) { + if (!eql(a[i], b[i])) return false; + } + return true; + }, builtin.TypeId.Pointer => { const info = @typeInfo(T).Pointer; switch (info.size) { @@ -510,6 +518,13 @@ test "std.meta.eql" { testing.expect(eql(EU.tst(true), EU.tst(true))); testing.expect(eql(EU.tst(false), EU.tst(false))); testing.expect(!eql(EU.tst(false), EU.tst(true))); + + var v1 = @splat(4, @as(u32, 1)); + var v2 = @splat(4, @as(u32, 1)); + var v3 = @splat(4, @as(u32, 2)); + + testing.expect(eql(v1, v2)); + testing.expect(!eql(v1, v3)); } test "intToEnum with error return" { |
