mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
langref: update splat section
This commit is contained in:
parent
79460d4a3e
commit
5f7dfc3577
2 changed files with 9 additions and 2 deletions
|
|
@ -5498,8 +5498,9 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
|
||||||
{#header_open|@splat#}
|
{#header_open|@splat#}
|
||||||
<pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
|
<pre>{#syntax#}@splat(scalar: anytype) anytype{#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
Produces a vector where each element is the value {#syntax#}scalar{#endsyntax#}.
|
Produces an array or vector where each element is the value
|
||||||
The return type and thus the length of the vector is inferred.
|
{#syntax#}scalar{#endsyntax#}. The return type and thus the length of the
|
||||||
|
vector is inferred.
|
||||||
</p>
|
</p>
|
||||||
{#code|test_splat_builtin.zig#}
|
{#code|test_splat_builtin.zig#}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,10 @@ test "vector @splat" {
|
||||||
try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 }));
|
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
|
// test
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue