Typeinfo
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Thu Apr 2 17:35:47 PDT 2015
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.
More information about the Digitalmars-d
mailing list