Go: Assigning Constants by Power of Two Using iota

Clever trick using the iota keyword (used for enum-like behavior in Go):

const (
        a = 1 << iota  // a == 1
        b = 1 << iota  // b == 2
        c = 1 << iota  // c == 4
)

Thanks to this related SO post.

Advertisements