Pass enum variable as const ref arg
Q. Schroll
qs.il.paperinik at gmail.com
Tue Dec 8 23:39:05 UTC 2020
On Friday, 4 December 2020 at 12:54:25 UTC, Andrey wrote:
> [...]
> WTF?
If you come from a C or C++ background, it's quite reasonable to
think of enum stuff like a #define macro. You're using static
arrays, but note that array literals allocate in many use cases.
It really is like a C/C++ macro. Use n times = allocate n times.
You avoid that with a static immutable completely. That said, if
you use the value of that enum only at compile-time, there's no
need for a static immutable.
Hope that this rule of thumb sheds some more light on how to
achieve certain stuff.
More information about the Digitalmars-d-learn
mailing list