copy must be const?!?

2024-07-24 Thread Dom DiSc via Digitalmars-d-learn
In following code: ```d int test(int x) { return --x; } T test2(T)(T x) { return --x; } void main() { const int v = 3; writeln(test(v)); writeln(test2(v)); // doesn't compile } ``` test2 (just like test) works on a copy of x. Why is this copy const?!? If I copy a const or immutable obj

Re: copy must be const?!?

2024-07-24 Thread Dom DiSc via Digitalmars-d-learn
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 simpl