digitalmars.D.learn - pointsTo in D1
- Bill Baxter <dnewsgroup billbaxter.com> Mar 06 2008
- Bill Baxter <dnewsgroup billbaxter.com> Mar 07 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
Mar 06 2008
Bill Baxter wrote: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.
I think I got it. This in D2static if (is(S P : U*, U))
Is another way to say this static if (is(S U : U*))else static if (is(S A : U[], U))
Same here -- it's equivalent to "if(is(S U : U[]))" --bb
Mar 07 2008








Bill Baxter <dnewsgroup billbaxter.com>