[Issue 24688] Parameter by-value keeps const (only in templates)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 24 12:28:01 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24688

--- Comment #4 from Dominikus Dittes Scherkl <dominikus at scherkl.de> ---
So, instead of
```d
T fun(T)(T x) { ... }
```

I have to write

```d
T fun(T)(const T x) { return fun(cast(T)n); }
T fun(T)(T x) if(!is(T==const)) { ... }
```

For all functions that used to get a mutable copy of x, just to allow the
compiler to create a const copy of x where this is never useful.
And I thought D wants the developer to write *less* boilerplate.
sigh.

This is really only a tiny bit better than to write multiple copies of fun()
for each type it can take and renders templates much less useful for me :-(

--


More information about the Digitalmars-d-bugs mailing list