Compile delegate with enum into proper function?

jmh530 john.michael.hall at gmail.com
Sun May 8 01:38:55 UTC 2022


On Saturday, 7 May 2022 at 23:30:37 UTC, Paul Backus wrote:
> [snip]
>
> Worth noting that you *can* write
>
> ```d
> alias foo = partial!(foo, a);
> ```
>
> ...which will add the partially-applied version to `foo`'s 
> overload set.

You sure about that? Below fails to compile on godbolt with ldc 
1.27.1 [1]. For some reason run.dlang.org is just hanging...

```d
import core.stdc.stdio: printf;
import std: partial;

int foo(int x, int a) {
  	return x + a;
}
enum int a = 2;

alias foo = partial!(foo, a);

void main() {
     int x = 2;
     int y = foo(x, a);
     printf("the value of y is %i", y);
     auto z = foo(x);
     printf("the value of z is %i", z);
}
```

[1] https://d.godbolt.org/z/dx8aWfjYW


More information about the Digitalmars-d-learn mailing list