pointsTo in D1

Bill Baxter dnewsgroup at billbaxter.com
Thu Mar 6 18:35:30 PST 2008


Does anyone know how to D1-ify this (from D2 std.contracts)

In particular I don't understand what those fancy D2 is-expressions are 
doing.

---------------

bool pointsTo(S, T)(ref S source, ref T target)
{
     static if (is(S P : U*, U))
     {
         const void * m = source, b = &target, e = b + target.sizeof;
         return b <= m && m < e;
     }
     else static if (is(S == struct))
     {
         foreach (i, subobj; source.tupleof)
         {
             if (pointsTo(subobj, target)) return true;
         }
         return false;
     }
     else static if (is(S A : U[], U))
     {
         const void* p1 = source.ptr, p2 = p1 + source.length,
             b = &target, e = b + target.sizeof;
         return overlap(range(p1, p2), range(b, e)).length != 0;
     }
     else
     {
         return false;
     }
}
-----------------

thanks
--bb


More information about the Digitalmars-d-learn mailing list