Re: max enum value +1
In article <l2sigh$cb9$1@dont-email.me>, daniel.kruegler@googlemail.com
(Daniel Kr?gler) wrote:
Am 06.10.2013 21:26, schrieb fmatthew5876:
It would anyway have to handle this case:
Color white = red|green|blue;
This fails to compile because (red | green | blue) is of type
int, not Color. You need a cast to do this.
Yet still the problem described by Bo Persson does exist: It is OK
to define enumeration values "out-of-line" such that they would
have an underlying value that does not exist in any of the
enumerators of the enumeration definition provided it is within
the required limits denoted as "b_min" and "b_max" in 7.2
[dcl.enum] p8.
I know. I identified that as a problem with the original request in
my previous post. It's OK for the language, but need not be OK for
the interface. If the enum only has three values, we should be able
to write code that only handles those three values. If someone uses
a cast to create a value outside those the interface is documented
as handling, it's their problem. Same as if they pass a value larger
than vector::size() to vector::operator[](), or if they cast away
const.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]