Skip to content

Instantly share code, notes, and snippets.

@lygaret
Created May 29, 2019 22:53
Show Gist options
  • Save lygaret/d09bd3db176a664db593250477171bb9 to your computer and use it in GitHub Desktop.
Save lygaret/d09bd3db176a664db593250477171bb9 to your computer and use it in GitHub Desktop.
const std = @import("std");
const Flag = packed enum (u4) {
one = 1,
two = 2,
pub fn with(flags: []const Flag) u4 {
var value: u4 = 0;
for (flags) |flag| {
value = value | @enumToInt(flag);
}
return value;
}
};
pub fn main() anyerror!void {
const flags = []Flag { Flag.one, Flag.two };
const value = Flag.with(flags);
std.debug.warn("flags: {}, value: {}\n", flags, value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment