doesPointTo

fnbool doesPointTo(S, T, Tdummy = void)(auto ref const S source, ref const T target) if (__traits(isRef, source) || isDynamicArray!S || is(S == U *, U) || is(S == class)) @nogc @trusted pure nothrow

Checks whether a given source object contains pointers or references to a given target object.

Parameters

sourceThe source object
targetThe target object

Bugs

The function is explicitly annotated @nogc because inference could fail,

see Bugzilla issue 17084.

Returns

true if source's representation embeds a pointer

that points to target's representation or somewhere inside it.

If source is or contains a dynamic array, then, then these functions will check if there is overlap between the dynamic array and target's representation.

If source is a class, then it will be handled as a pointer.

If target is a pointer, a dynamic array or a class, then these functions will only check if source points to target, not what target references.

If source is or contains a union or void[n], then there may be either false positives or false negatives:

doesPointTo will return true if it is absolutely certain source points to target. It may produce false negatives, but never false positives. This function should be prefered when trying to validate input data.

mayPointTo will return false if it is absolutely certain source does not point to target. It may produce false positives, but never false negatives. This function should be prefered for defensively choosing a code path.

Note

Evaluating doesPointTo(x, x) checks whether x has

internal pointers. This should only be done as an assertive test, as the language is free to assume objects don't have internal pointers (TDPL 7.1.3.5).

fnbool doesPointTo(S, T)(auto ref const shared S source, ref const shared T target) @trusted pure nothrow

ditto