-
-
Save lygaret/d09bd3db176a664db593250477171bb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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