lazy construction of an immutable object
Jason den Dulk via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 15 20:10:20 PDT 2014
On Tuesday, 15 July 2014 at 12:20:57 UTC, Puming wrote:
> @property immutable(T) freeze(T)(T obj)
> {
> return cast(immutable(T))(obj);
> }
>> What is the idiomatic approach to do this in D?
There is a Phobos function std.exception.assumeUnique which
performs this for arrays. According to the docs, it does what
'freeze' does, and is considered idiomatic.
> But the draw back is that you can't garanteed that the mutable
> object is never used.
I got the impression that assumeUnique has the same problem.
Regards
More information about the Digitalmars-d-learn
mailing list