authorgravatar for kiedtl@tilde.teamKiëd Llaentenn <kiedtl@tilde.team> 2025-03-05 09:08:47-05:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-03-06 07:26:19+01:00
log5f7dfc357740e765fad3d8deb246b6dd9aef3fc0
tree6558502f4bd146f199aed0987ffbc915d078f09e
parent79460d4a3eef8eb927b02a7eda8bc9999a766672

langref: update splat section


2 files changed, 9 insertions(+), 2 deletions(-)

doc/langref.html.in+3-2
...@@ -5498,8 +5498,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val...@@ -5498,8 +5498,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
5498 {#header_open|@splat#}5498 {#header_open|@splat#}
5499 <pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>5499 <pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
5500 <p>5500 <p>
5501 Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.5501 Produces an array or vector where each element is the value
5502 The return type and thus the length of the vector is inferred.5502 {#syntax#}scalar{#endsyntax#}. The return type and thus the length of the
5503 vector is inferred.
5503 </p>5504 </p>
5504 {#code|test_splat_builtin.zig#}5505 {#code|test_splat_builtin.zig#}
55055506
doc/langref/test_splat_builtin.zig+6
...@@ -7,4 +7,10 @@ test "vector @splat" {...@@ -7,4 +7,10 @@ test "vector @splat" {
7 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));7 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
8}8}
99
10test "array @splat" {
11 const scalar: u32 = 5;
12 const result: [4]u32 = @splat(scalar);
13 try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
14}
15
10// test16// test