Function Vector.ownsElement

Returns true if element referenced by p is owned by vector. Similar to owns but check if p has right alignment.

bool ownsElement (
  scope const Vector.ElementType* p
) const pure nothrow @nogc scope @trusted;

Examples

Vector!(int, 6) vec = Vector!(int, 6).build(1, 2, 3, 4, 5, 6);

{
    assert(vec.ownsElement(vec.ptr + 3));
    assert(!vec.ownsElement(cast(int*)null));
    assert(!vec.ownsElement(vec.ptr + 100));
}

{
    const int* p = cast(int*)((cast(byte*)vec.ptr) + 1);
    assert(vec.owns(p));
    assert(!vec.ownsElement(p));
}