digitalmars.D - Alias Vs. Enum?
- Rubn (12/12) Jan 06 2018 Is there a reason for the differences between Enum and Alias? For
- Rubn (11/11) Jan 06 2018 Tab + Enter + No Delete/Edit = :/
- Timon Gehr (5/26) Jan 06 2018 Nobody stepped up and did it, I guess.
- Stefan Koch (5/18) Jan 06 2018 The compiler can only alias to symbols and not to values.
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (6/10) Jan 07 2018 Not only that, but alias can bind to values if they're from a
- sarn (4/6) Jan 07 2018 Also, using "enum" for manifest constants makes sense for people
Is there a reason for the differences between Enum and Alias? For the most part enums are only used for things that have a value, but alias is used more for types. But with templates you can get around this and you basically get the funcitonality of Enum for alias. Oddly enough from the template parameter being "alias". template valueOf(alias v) { } alias aa = AliasSeq!(10 == 10); enum ee = 10 == 10; alias err = 10 == 10; // error What are the actually differences here with aa and ee?
Jan 06 2018
Tab + Enter + No Delete/Edit = :/ template valueOf(alias v) // <-- alias { alias valueOf = v; } alias aa = valueOf!(10 == 10); enum ee = 10 == 10; alias err = 10 == 10; // error Can't alias just be extended to support enum values as well instead of having this workaround with templates? Is there any reason this hasn't already been done?
Jan 06 2018
On 06.01.2018 22:36, Rubn wrote:Tab + Enter + No Delete/Edit = :/ template valueOf(alias v) // <-- alias { alias valueOf = v; } alias aa = valueOf!(10 == 10); enum ee = 10 == 10; alias err = 10 == 10; // error Can't alias just be extended to support enum values as well instead of having this workaround with templates?Yes, it can.Is there any reason this hasn't already been done?Nobody stepped up and did it, I guess. I might write a DIP to clean up the language grammar at some point. (There are a few more cases like this one.)
Jan 06 2018
On Saturday, 6 January 2018 at 21:33:46 UTC, Rubn wrote:Is there a reason for the differences between Enum and Alias? For the most part enums are only used for things that have a value, but alias is used more for types. But with templates you can get around this and you basically get the funcitonality of Enum for alias. Oddly enough from the template parameter being "alias". template valueOf(alias v) { } alias aa = AliasSeq!(10 == 10); enum ee = 10 == 10; alias err = 10 == 10; // error What are the actually differences here with aa and ee?The compiler can only alias to symbols and not to values. therefore enum was chosen for manifest constants. That alias can bind to values in template-parameters is useful but not exactly consistent :)
Jan 06 2018
On Sunday, 7 January 2018 at 03:52:53 UTC, Stefan Koch wrote:The compiler can only alias to symbols and not to values. therefore enum was chosen for manifest constants. That alias can bind to values in template-parameters is useful but not exactly consistent :)Not only that, but alias can bind to values if they're from a template alias parameter, hence std.meta.Alias. Instead of doing that silly dance, alias should simply take values as well. -- Simen
Jan 07 2018
On Sunday, 7 January 2018 at 18:30:17 UTC, Simen Kjærås wrote:Instead of doing that silly dance, alias should simply take values as well.Also, using "enum" for manifest constants makes sense for people familiar with C idiom, but often confuses people coming from different languages.
Jan 07 2018