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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 24 13:20:24 UTC 2024


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

--- Comment #6 from Dominikus Dittes Scherkl <dominikus at scherkl.de> ---
Ok, it's possible to optimize it to one extra line:

T tpl(T)(T x)
{
   ...
}

becomes

T tpl(T)(T x)
{
   static if(is(T==const)) return tpl(cast(T)x);
   ...
}

But I have to add this to pretty much *every* template in my code, as this is a
pattern that I use almost always. And I can only hope, the compiler is smart
enough to optimize this extra call and additional copy of x away.

--


More information about the Digitalmars-d-bugs mailing list