Extracting user defined attributes on function parameters
Jean-Louis Leroy
jl at leroy.nyc
Fri Apr 17 18:05:39 UTC 2020
On Friday, 17 April 2020 at 17:48:06 UTC, Adam D. Ruppe wrote:
> On Friday, 17 April 2020 at 17:31:32 UTC, Jean-Louis Leroy
> wrote:
>> Well, can't do. I need this purely at compile time, and
>> cross-module.
>
> And the CTFE engine gets weird with it too.... dmd will have to
> fix this.
>
> But default parameters might not be possible in general at CT
> anyway... it is actually possible to define it to a variable.
> Observe:
>
> int a;
>
> void f(int arg = a) { // default arg is to use the global...
> import std.stdio; writeln(arg);
> }
>
> void main() {
> f(); // 0 this time
> a = 4; // and it can be changed at runtime!
> f(); // will now say 4
> }
Interesting example, but all hope is not lost. `a` could
(should?) be passed as an alias in __parameters.
More information about the Digitalmars-d-learn
mailing list