On Friday, 3 April 2015 at 00:21:47 UTC, Andrei Alexandrescu wrote:
Hey folks, is there any way to figure out whether a type is immutable or shared given its typeinfo?

Yes: if it is an instance of TypeInfo_Invariant or TypeInfo_Shared.

void main() {
        string s;
        char[] c;
        assert(cast(TypeInfo_Invariant) typeid(s).next !is null);
        assert(cast(TypeInfo_Invariant) typeid(c).next is null);
}

The next is there because the array itself isn't immutable, so we look at the type inside.

Reply via email to