Last active
December 13, 2015 21:58
-
-
Save bickfordb/4980899 to your computer and use it in GitHub Desktop.
lvals can update themselves in Go
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
package main | |
type Flag uint32 | |
const ( | |
X0 Flag = 1 << iota | |
X1 | |
X2 | |
X3 | |
X4 | |
) | |
type G struct { | |
Flags Flag | |
} | |
func (f *Flag) Set(flags ...Flag) { | |
for _, i := range flags { | |
*f = *f | i | |
} | |
} | |
func (f *Flag) Test(o Flag) bool { | |
return (*f & o) != 0 | |
} | |
func main() { | |
println(X0) | |
println(X1) | |
println(X2) | |
println(X3) | |
println(X4) | |
g := &G{} | |
g.Flags.Set(X0) | |
g.Flags.Set(X1) | |
println("flags:",g.Flags) | |
println(g.Flags.Test(X0)) | |
println(g.Flags.Test(X1)) | |
println(g.Flags.Test(X2)) | |
println(g.Flags.Test(X3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment