copy must be const?!?

Dom DiSc dominikus at scherkl.de
Thu Jul 25 06:50:04 UTC 2024


On Wednesday, 24 July 2024 at 15:40:28 UTC, Dennis wrote:
>> Is there a way to tell the compiler that it should discard 
>> "const" and "immutable" if it needs to create a copy?
>> Unqual!T doesn't work :-(
>
> When you add `const` or `immutable` before the template type 
> parameter, it will infer T as simply `int`:
>
> ```D
> T test2(T)(immutable T x) { return --T(x); }
> ```

Woah. Is this @safe?
Ok, I know this is a fresh copy, that hopefully doesn't go to 
non-volatile memory, but I'm always sceptical casting away const.


More information about the Digitalmars-d-learn mailing list