Re: Compile delegate with enum into proper function?

2022-05-08 Thread jmh530 via Digitalmars-d-learn
On Sunday, 8 May 2022 at 03:58:06 UTC, Tejas wrote: [snip] If there is only one possible value for the overload, is there an issue with using default arguments? [snip] Default arguments are intended to be resolved at runtime. That is, if you compile a function with two parameters and one

Re: Compile delegate with enum into proper function?

2022-05-08 Thread Tejas via Digitalmars-d-learn
On Saturday, 7 May 2022 at 18:36:40 UTC, jmh530 wrote: In the code below, there is a two parameter function `foo` and an override of it with only one parameter. In the override case, I force the second one to be 1, but ideally there should be a way to specify it at compile-time. It would be

Re: Compile delegate with enum into proper function?

2022-05-08 Thread Salih Dincer via Digitalmars-d-learn
Either we didn't understand the question, or this is not what you're talking about: On Sunday, 8 May 2022 at 03:58:06 UTC, Tejas wrote: If there is only one possible value for the overload, is there an issue with using default arguments? ```d int foo(int x, int a = 1) { return x + a; }

Re: Compile delegate with enum into proper function?

2022-05-07 Thread Tejas via Digitalmars-d-learn
On Sunday, 8 May 2022 at 01:38:55 UTC, jmh530 wrote: 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?

Re: Compile delegate with enum into proper function?

2022-05-07 Thread jmh530 via Digitalmars-d-learn
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].

Re: Compile delegate with enum into proper function?

2022-05-07 Thread Paul Backus via Digitalmars-d-learn
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 +

Re: Compile delegate with enum into proper function?

2022-05-07 Thread jmh530 via Digitalmars-d-learn
On Saturday, 7 May 2022 at 18:46:03 UTC, Paul Backus wrote: On Saturday, 7 May 2022 at 18:36:40 UTC, jmh530 wrote: In the code below, there is a two parameter function `foo` and an override of it with only one parameter. In the override case, I force the second one to be 1, but ideally there

Re: Compile delegate with enum into proper function?

2022-05-07 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 7 May 2022 at 18:36:40 UTC, jmh530 wrote: In the code below, there is a two parameter function `foo` and an override of it with only one parameter. In the override case, I force the second one to be 1, but ideally there should be a way to specify it at compile-time. Have you