Skip to content

Instantly share code, notes, and snippets.

@marler8997
Created June 16, 2019 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marler8997/21be72451adea88560b0b13c67de0e86 to your computer and use it in GitHub Desktop.
Save marler8997/21be72451adea88560b0b13c67de0e86 to your computer and use it in GitHub Desktop.
const std = @import("std");
pub fn copyVarargs(array: var, args: ...) void {
comptime var i = 0;
inline while (i < args.len) : (i += 1) array[i] = args[i];
}
pub fn allocVarargs(comptime T: type, allocator: *std.mem.Allocator, args: ...) ![]T {
var array = try allocator.alloc(T, args.len);
copyVarargs(array, args);
return array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment