Adam D. Ruppe destructionator at gmail.com
Sat Aug 1 18:39:19 UTC 2020

On Saturday, 1 August 2020 at 18:26:54 UTC, Andrei Alexandrescu 
> However, that makes them very unpleasant to use, e.g. you can't 
> use them as out parameters, can't assign them etc.

It seems to me that immutable out params SHOULD work - it would 
follow the same rules as initializing an immutable class member 
in a constructor.

An out param is only actually written once, so the implementation 
just needs to realize it is construction, not assignment, and 
then perhaps it can be made to work.

I suppose the rule would be an out param may be declared before 
use (indeed, it must be), but then it could not actually be 
initialized or assigned outside the function.

void foo(out immutable T t) {
    t = new immutable T; // OK, initial construction

immutable T a;

foo(a); // if a was already initialized, this would be an error.
// but if not it should allow it

We do something similar for classes so it seems doable in theory.

  * * *

Of course we should just have const(Object) ref.

More information about the Digitalmars-d mailing list