How to create an empty slice of slices

Viewed 397

How do I construct []const []const u8 without using an allocator?

I can do

var slice: []const []const u8 = undefined;
slice.len = 0;
// use slice

But there surely must be a better way.

1 Answers

You can do:

var foo: []const []const u8 = &.{};

I leave it to you to judge if this is better and by how much.

Related