Skip to content

Instantly share code, notes, and snippets.

@DutchGhost
Created November 18, 2020 13:14
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 DutchGhost/79055e99aa5544b10d730bbe996b45f6 to your computer and use it in GitHub Desktop.
Save DutchGhost/79055e99aa5544b10d730bbe996b45f6 to your computer and use it in GitHub Desktop.
funny usingnamespcae weirdness
usingnamespace closure: {
var hashes: []const usize = &[0]usize{};
break :closure struct {
pub fn ctStrHash(comptime str: []const u8) usize {
const hash = yourAlgo(str);
comptime {
for (hashes) |existing| {
if (existing == hash) @compileError("collision");
}
hashes = hashes ++ [1]usize{hash};
}
return hash;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment