How about 'pure' for constants?

Steven Schveighoffer schveiguy at yahoo.com
Tue Dec 11 09:55:40 PST 2007


"Jarrett Billingsley" wrote
> "guslay" wrote
>> Don Clugston Wrote:
>>
>>>
>>> enum SomeEnormousStruct a = SomeFunction(AnotherEnormousStruct(x, 
>>> "abc"));
>>>
>>
>> I thought the enum concept (regardless of the keyword) was for compile 
>> time strings and primitives. Is it also supposed to work with structs?
>>
>>
>
> Why not?  If they're made of strings and primitives, it seems perfectly 
> fine.  They're value types, after all.

What if the struct has methods?  The fact that it has methods is ok as those 
are separate entities, but struct methods require a this pointer.  If this 
is a manifest constant, it's possible that the struct cannot have a pointer 
to the data.

I think this could be averted if the 'this' portion of a struct was not 
passed by reference, but passed by value.  Maybe there should be a way to 
define whether 'this' is a pointer or a value?  This would also allow 
operators to be used in constant expressions (one of the problems with using 
a struct as a replacement for a math type).

I like the pure for manifest constants idea.  However, it implies that only 
pure methods could be called on a struct that is a manifest constant, which 
seems too limited to me.  If structs are allowed as manifest constants, then 
I don't think pure is a good keyword for it (though it's better than enum).

-Steve 





More information about the Digitalmars-d mailing list