On Wed, Jan 28, 2009 at 11:11 AM, dsimcha <[email protected]> wrote: > == Quote from dsimcha ([email protected])'s article >> == Quote from Bill Baxter ([email protected])'s article >> > Does anyone have a good template for checking if a struct is >> > semantically a pure value type or not? >> > I found "hasAliasing" in D2 which is close, but it seems to report >> > true even for static arrays. >> > struct X { float[3] vals; } >> > pragma(msg, hasAliasing!(X)?"true":"false"); --> true >> > Maybe that's just a bug in hasAliasing? >> > What I want to know is if X=Y will give me an X that is >> > independent of Y. I think that is the same question hasAliasing is >> > trying to answer. If so then it's a bug. >> > --bb >> Here's a really ugly, brute force hack that does what you need: >> http://dsource.org/projects/dstats/browser/trunk/alloc.d >> I actually needed it in dstats to support newVoid(), which is a speed hack to >> allocate arrays w/o initializing the contents, to tell the GC whether to >> scan for >> pointers. Actually, on looking at it again, it should probably be changed >> to make >> function pointers and delegates return false. >> Not sure if this is what you were looking for. By semantically a pure value >> type, >> do you mean that immutable reference data should or sould not be included? > > Forgot to mention: It's isReferenceType, about 1/3 of the way down. >
Got it. I see looking there that my one line fix to hasAliasing above won't work. It ignores the possibility that the T in a static array T[3] itself may have references. --bb
