commit 5f7dfc357740e765fad3d8deb246b6dd9aef3fc0 (tree)
parent 79460d4a3eef8eb927b02a7eda8bc9999a766672
Author: Kiƫd Llaentenn <kiedtl@tilde.team>
Date: Wed, 5 Mar 2025 09:08:47 -0500
langref: update splat section
Diffstat:
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/doc/langref.html.in b/doc/langref.html.in
@@ -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#}
diff --git a/doc/langref/test_splat_builtin.zig b/doc/langref/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 }));
}
+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