mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 07:00:37 +03:00
Duplicate pointsTo as "doesPointTo"
This commit is contained in:
parent
b5695d276d
commit
15a9ae7941
1 changed files with 37 additions and 0 deletions
|
@ -945,11 +945,48 @@ bool pointsTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @t
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool mayPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @trusted pure nothrow
|
||||||
|
if (__traits(isRef, source) || isDynamicArray!S ||
|
||||||
|
isPointer!S || is(S == class))
|
||||||
|
{
|
||||||
|
static if (isPointer!S || is(S == class))
|
||||||
|
{
|
||||||
|
const m = cast(void*) source,
|
||||||
|
b = cast(void*) &target, e = b + target.sizeof;
|
||||||
|
return b <= m && m < e;
|
||||||
|
}
|
||||||
|
else static if (is(S == struct) || is(S == union))
|
||||||
|
{
|
||||||
|
foreach (i, Subobj; typeof(source.tupleof))
|
||||||
|
if (mayPointTo(source.tupleof[i], target)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else static if (isStaticArray!S)
|
||||||
|
{
|
||||||
|
foreach (size_t i; 0 .. S.length)
|
||||||
|
if (mayPointTo(source[i], target)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else static if (isDynamicArray!S)
|
||||||
|
{
|
||||||
|
return overlap(cast(void[])source, cast(void[])(&target)[0 .. 1]).length != 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// for shared objects
|
// for shared objects
|
||||||
bool pointsTo(S, T)(auto ref const shared S source, ref const shared T target) @trusted pure nothrow
|
bool pointsTo(S, T)(auto ref const shared S source, ref const shared T target) @trusted pure nothrow
|
||||||
{
|
{
|
||||||
return pointsTo!(shared S, shared T, void)(source, target);
|
return pointsTo!(shared S, shared T, void)(source, target);
|
||||||
}
|
}
|
||||||
|
bool mayPointTo(S, T)(auto ref const shared S source, ref const shared T target) @trusted pure nothrow
|
||||||
|
{
|
||||||
|
return mayPointTo!(shared S, shared T, void)(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
/// Pointers
|
/// Pointers
|
||||||
unittest
|
unittest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue