alias vs enum for lambdas?

monkyyy crazymonkyyy at gmail.com
Mon Apr 28 20:05:34 UTC 2025


On Monday, 28 April 2025 at 04:59:24 UTC, Orion wrote:
> In which programming scenarios should alias be used instead of 
> enum?
>
> So far I have only found a simplified notation of a generic 
> lambda:
> alias id = (x) => x; x; , which does not work in the case of 
> enum.
>
> There is also a difference in overloading a non-generic lambda:
>
> alias m = (int x) => x;
> alias m = (float x) => 0.5 + x;
> - alias overloads a function with the same name.
>
> enum e = (int x) => x;
> ///enum e = (float x) => x; //error
> - enum does not.
>
> At the compiler level, enum lambda is represented as a literal.
> But how is alias represented? As an expression?

aliases for types, overload sets

enum for litterals


More information about the Digitalmars-d-learn mailing list