Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

insertAssumeCapacity

Public Function
std.multi_array_list.MultiArrayList.insertAssumeCapacity
pub fn insertAssumeCapacity(self: *Self, index: usize, elem: T) void

Inserts an item into the list. Shifts all elements after and including the specified index back by one and sets the given index to the specified element.

Asserts that capacity is sufficient to hold an additional item.

Params

  • self: *Self
  • index: usize
  • elem: T

File

multi_array_list.zig:353
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
        pub fn insertAssumeCapacity(self: *Self, index: usize, elem: T) void {
            assert(self.len < self.capacity);
            assert(index <= self.len);
            self.len += 1;
            const entry = switch (@typeInfo(T)) {
                .@"struct" => elem,
                .@"union" => Elem.fromT(elem),
                else => unreachable,
            };
            const slices = self.slice();
            inline for (field_names, 0..) |field_name, field_index| {
                const field_slice = slices.items(@as(Field, @fromBackingInt(@intCast(field_index))));
                var i: usize = self.len - 1;
                while (i > index) : (i -= 1) {
                    field_slice[i] = field_slice[i - 1];
                }
                field_slice[index] = @field(entry, field_name);
            }
        }