PhobosWatch: manifest => enum

Bruce Adams tortoise_74 at yeah.who.co.uk
Fri Dec 28 13:03:42 PST 2007


On Fri, 28 Dec 2007 18:43:38 -0000, Walter Bright  
<newshound1 at digitalmars.com> wrote:

> Sean Kelly wrote:
>> err... make that unnamed and named.  One could argue that support for  
>> unnamed enums is simply for ease of porting from C rather than because  
>> it's a feature that really makes sense in a new language.  So making it  
>> even more entrenched is undesirable.  But we need the feature and if  
>> "enum" is it then...
>
> Right. Anonymous enums are already conventionally used not to declare  
> enums, but a bunch of (not necessarily related) manifest constants. In  
> fact, in C++ we see:
>
> template<> class factorial<1>
> {
>    public:
>      enum { result = 1 };
> };
>
> where anonymous enums are clearly used to declare manifest constants.

That looks similar to the workaround for old compilers which didn't  
support static consts.

template<> class factorial<1>
{
    public:
      static const int result = 1;
};

I can see the desire for manifest constants here. You particularly don't  
want to bloat your code
with each intermediate value in a compile time computed expression.
I've just tried an experiment on gcc (cygming 3.4.4). Compiled objects are  
the same size whether
enum or static const is used in a factorial template. I see this as  
evidence that the enum hack
is still just that, a hack to workaround dodgey compilers. So you are  
propagating a hack into D
if the C++ example is one of your primary reasons.



More information about the Digitalmars-d mailing list