Skip to content

Instantly share code, notes, and snippets.

@jrfondren
Created November 14, 2018 03:04
Show Gist options
  • Save jrfondren/9f79f00f7ae055b5eff647f60e3484e5 to your computer and use it in GitHub Desktop.
Save jrfondren/9f79f00f7ae055b5eff647f60e3484e5 to your computer and use it in GitHub Desktop.
concatenating arrays at compile-time
const std = @import("std");
const warn = std.debug.warn;
pub fn main() void {
comptime var x1 = []f64{1, 2, 3};
comptime var x2 = x1 ++ x1; // error to assign x1 here
comptime var x3 = ([]f64{1, 2, 3})[0..];
x3 = x3 ++ x3; // no error
warn("x2: {}\n", @typeName(@typeOf(x2)));
warn("x3: {}\n", @typeName(@typeOf(x3)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment