Function concat [src]

Copies each T from slices into a new slice that exactly holds all the elements.

Prototype

pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) Allocator.Error![]T

Parameters

allocator: AllocatorT: typeslices: []const []const T

Example

test concat { { const str = try concat(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }); defer testing.allocator.free(str); try testing.expect(eql(u8, str, "abcdefghi")); } { const str = try concat(testing.allocator, u32, &[_][]const u32{ &[_]u32{ 0, 1 }, &[_]u32{ 2, 3, 4 }, &[_]u32{}, &[_]u32{5}, }); defer testing.allocator.free(str); try testing.expect(eql(u32, str, &[_]u32{ 0, 1, 2, 3, 4, 5 })); } { const str = try concatWithSentinel(testing.allocator, u8, &[_][]const u8{ "abc", "def", "ghi" }, 0); defer testing.allocator.free(str); try testing.expectEqualSentinel(u8, 0, str, "abcdefghi"); } { const slice = try concatWithSentinel(testing.allocator, u8, &[_][]const u8{}, 0); defer testing.allocator.free(slice); try testing.expectEqualSentinel(u8, 0, slice, &[_:0]u8{}); } { const slice = try concatWithSentinel(testing.allocator, u32, &[_][]const u32{ &[_]u32{ 0, 1 }, &[_]u32{ 2, 3, 4 }, &[_]u32{}, &[_]u32{5}, }, 2); defer testing.allocator.free(slice); try testing.expectEqualSentinel(u32, 2, slice, &[_:2]u32{ 0, 1, 2, 3, 4, 5 }); } }

Source

pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) Allocator.Error![]T { return concatMaybeSentinel(allocator, T, slices, null); }