AA literals/initialisation
TheFlyingFiddle
theflyingfiddle at gmail.com
Mon Nov 11 16:07:21 PST 2013
On Monday, 11 November 2013 at 12:14:10 UTC, Jonathan M Davis
wrote:
> Every time you use an enum, it's replaced with its value. So,
> if an enum is an
> AA, then that literal is copy-pasted everywhere that the enum
> is used. So, it
> would almost certainly be foolish to use it anywhere other than
> to assign to a
> variable (and then all of the operations are done on the
> variable). Really,
> having an enum that's an AA is almost certainly a foolish thing
> to do. It's
> one case where the behavior of enums doesn't help and
> definitely hurts.
>
> - Jonathan M Davis
I have found it to be kind of usefull atleast when i'm only using
the AA at compiletime. Like a simple vector swizzle like the code
below. I store rgba/xyzw characters in the table with diffrent
offsets into a static array.
Vector!(s.length, T) opDispatch(string s)()
if(s.length > 1)
{
Vector!(s.length, T) res;
foreach(i; staticIota!(0, s.length)) {
enum offset = swizzleTable[s[i]];
res.data[i] = data[offset];
}
return res;
}
However with your statement above i'm now a little worried does
this mean that the line enum offset = swizzleTable[s[i]]; will
not be able to pick the correct constant at compiletime? And will
instead do some runtime AA hash lookup?
More information about the Digitalmars-d
mailing list