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

Reply via email to