Compile delegate with enum into proper function?

Paul Backus snarwin at gmail.com
Sat May 7 23:30:37 UTC 2022


On Saturday, 7 May 2022 at 20:24:39 UTC, jmh530 wrote:
> On Saturday, 7 May 2022 at 18:46:03 UTC, Paul Backus wrote:
>> ```d
>> import std.functional: partial;
>>
>> enum int a = 1;
>> alias foo2 = partial!(foo, a);
>> ```
>>
>> [snip]
>
> Thanks. This is basically equivalent to
>
> ```d
> int foo(int a)(int x) { return x + a; }
> alias foo2 = foo!a;
> ```
>
> The downside is that you wouldn't be able to `alias foo = 
> foo!a`.

Worth noting that you *can* write

```d
alias foo = partial!(foo, a);
```

...which will add the partially-applied version to `foo`'s 
overload set.


More information about the Digitalmars-d-learn mailing list