langref: update splat section

This commit is contained in:
Kiëd Llaentenn 2025-03-05 09:08:47 -05:00 committed by Alex Rønne Petersen
parent 79460d4a3e
commit 5f7dfc3577
2 changed files with 9 additions and 2 deletions

View file

@ -5498,8 +5498,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
{#header_open|@splat#}
<pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
<p>
Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.
The return type and thus the length of the vector is inferred.
Produces an array or vector where each element is the value
{#syntax#}scalar{#endsyntax#}. The return type and thus the length of the
vector is inferred.
</p>
{#code|test_splat_builtin.zig#}

View file

@ -7,4 +7,10 @@ test "vector @splat" {
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
test "array @splat" {
const scalar: u32 = 5;
const result: [4]u32 = @splat(scalar);
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
}
// test