Re: [go-nuts] How to constrain an integral type's values

2023-09-08 Thread 'Thomas Bushnell BSG' via golang-nuts
I recommend using strings as the base type for things like this, rather than ints. There is no need to use ints, just because that's what C uses. Thomas On Fri, Sep 8, 2023 at 3:24 AM 'Mark' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I often create small multi-value flag types,

Re: [go-nuts] How to constrain an integral type's values

2023-09-08 Thread Jan Mercl
On Fri, Sep 8, 2023 at 9:24 AM 'Mark' via golang-nuts wrote: > Is there a compile-time solution for this that I've missed? No. Go does not have enum types. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and

[go-nuts] How to constrain an integral type's values

2023-09-08 Thread 'Mark' via golang-nuts
I often create small multi-value flag types, e.g. ```go type mode uint8 const ( argMode mode = iota baseMode cmdMode ) ``` The problem is that if I write, say, `m := baseMode`, although `m` has the correct type (`mode`), there is no way to constrain its values to the consts I've declared. In