Implicit conversion of unique objects to mutable and immutable

bearophile bearophileHUGS at lycsos.com
Tue Jun 21 16:04:11 PDT 2011


Ali Çehreli:

>     char[] result = foo();
>     string immutable_result = assumeUnique(result);
> 
> But that's the wrong thing to do, as foo() may be changed in the future 
> to return a non-unique result.

I think assumeUnique is meant to be used inside foo(), at its end.

Somewhere in Bugzilla (I don't remember the number, sorry, suggestions welcome) there is a bug report (that I think Walter has vaguely accepted, but it's not implemented yet) that asks results of pure functions to be implicitly cast-able to immutable.

This surely doesn't solve the whole situation, but it's a start, and it's a simple but useful thing.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list