inline enum in function declaration

Lionello Lunesu lio at lunesu.remove.com
Mon Jun 12 03:31:24 PDT 2006


I'm cutting back on the use of "bool" as a function parameter, since the 
words "true" and "false" are rarely applicable to the respective 
parameter, for example:

#void Invalidate( bool redraw );

This declaration seems ok, but when reading the code:

#Invalidate(true);

you have no idea what that "true" is referring to. I guess everybody 
knows what I'm talking about with "cutting back on the bool".

Obviously "enum" is the right replacement:

#enum redraw_t {
#  no_redraw = 0,	// false
#  redraw		// true
#}
#void Invalidate( redraw_t redraw );
#Invalidate( redraw_t.redraw );

Although nice, it adds quite a lot of overhead. What if you could 
declare the enum inline:

#void Invalidate( enum{no_redraw,redraw} );	// anonymous enum
#Invalidate( redraw );

Or, in case you want to be able to declare variables of the enum type:

#void Invalidate( enum redraw_t{no_redraw,redraw} );
#Invalidate( redraw_t.redraw );

This has the added benefit of being self documenting: you don't have to 
look-up the values of the enum, they are right there in the function 
definition.

Thoughts?

L.



More information about the Digitalmars-d mailing list