Feedback Thread: DIP 1044--Enum Type Inference--Community Review Round 1
IchorDev
zxinsworld at gmail.com
Thu Nov 24 09:12:11 UTC 2022
On Wednesday, 23 November 2022 at 16:11:32 UTC, Daniel N wrote:
> 1) using new symbols $(or any other unused symbol) for a minor
> feature is wasteful, compared to adding new meta/codegen
> features etc.
It is a minor feature at the moment. There's nothing stopping it
from becoming more generalised later. `#` is also used
exclusively for `#line`, which prohibits its use almost anywhere
else (except strings), but I am not against that either. `$` can
still be used as a binary operator in the future, or in regular
strings for interpolation or what-have-you.
> 2) Implicit 'with' for switch statements as proposed by Walter
> is more elegant and doesn't require any new symbols/syntax and
> is also more efficient from a compiler performance perspective
> as $ could refer to any enum, whereas the implicit 'with' only
> adds one enum.
If it only works in `case` statements then it does not
functionally replace the usefulness of ETI:
```d
enum MyEnum{ a,b,c,d }
struct Obj{ MyEnum one, two; }
void myFn(MyEnum param){}
void myDefaultFn(MyEnum param=$d){}
void myTempFn(alias x: MyEnum)(){}
void main(){
Obj myS1 = {one: $a, two: $b};
auto myS2 = Obj($a, $b);
myFn($a);
myFn($b + $b);
myDefaultFn();
myDefaultFn($c);
myTempFn($a);
}
```
You might argue that an explicit `with(T)` would be nice in the
above example. Well, it's an example. In my experience, enum
usage tends to be very spread out across codebases. Therefore
using `with(T)` would lead to me doing *more* typing because I
would need 1 `with` per enum use.
More information about the Digitalmars-d
mailing list