Frist Draft (in this forum): Enum Parameters
Paul Backus
snarwin at gmail.com
Mon Apr 29 19:17:47 UTC 2024
On Thursday, 25 April 2024 at 17:56:59 UTC, Quirin Schroll wrote:
> https://github.com/Bolpat/DIPs/blob/2bfef0b05e99c5448b416078da2e743482e3193d/DIPs/1NNN-QFS.md
Yet another non-orthogonal language feature that all generic code
will have to go out of its way to account for until the end of
time. `ref` is already bad enough; the last thing we need is
another feature that repeats the exact same design mistakes.
For example: currently, in order to forward an argument correctly
in generic code, we must write the following:
```d
void forwardTo(alias fun, T)(auto ref T arg)
{
import core.lifetime: forward;
fun(forward!arg);
}
```
Notice how much overhead is required *just* to deal with the
`ref` storage class.
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);
}
```
Needless to say, the vast majority of D programmers are not going
to bother with this, which means that we will forever be plagued
by buggy handling of `enum` parameters in our library code (just
as we are already plagued by buggy handling of `ref` parameters).
I do not think it is a good idea to introduce language features
that set future D programmers up for failure like this.
More information about the dip.development
mailing list