Frist Draft (in this forum): Enum Parameters

Timon Gehr timon.gehr at gmx.ch
Sun May 5 10:11:59 UTC 2024


On 4/29/24 21:17, Paul Backus wrote:
> 
> If this proposal were accepted, we would have to replace all instances 
> of the above with the following:
> 
> ```d
> void forwardTo(alias fun, T)(auto enum auto ref T arg)
> {
>      import core.lifetime: forward;
>      static if (__traits(isEnum, arg))
>          fun(arg);
>      else
>          fun(fporward!arg);
> }

If the `__traits(isEnum, arg)` is required at all (which I strongly 
doubt), it would be put into `forward`.

The `auto enum` point stands, however, and another issue it causes is 
CTFE and template instantiation overhead even if the final function does 
not even accept `enum` parameters. I don't think this is even perfect 
forwarding, as it may cause CTFE that would not otherwise happen, which 
currently may actually change the observable behavior of the code due to 
e.g. floating-point shenanigans.


More information about the dip.development mailing list