The OpenD Programming Language

overlap

Returns the overlapping portion, if any, of two arrays. Unlike equal, overlap only compares the pointers and lengths in the ranges, not the values referred by them. If r1 and r2 have an overlapping slice, returns that slice. Otherwise, returns the null slice.

@trusted
CommonType!(T[], U[])
overlap
(
T
U
)
(
T[] a
,
U[] b
)
if (
is(typeof(a.ptr < b.ptr) == bool)
)

Parameters

a T[]

The first array to compare

b U[]

The second array to compare

Return Value

Type: CommonType!(T[], U[])

The overlapping portion of the two arrays.

Examples

int[] a = [ 10, 11, 12, 13, 14 ];
int[] b = a[1 .. 3];
assert(overlap(a, b) == [ 11, 12 ]);
b = b.dup;
// overlap disappears even though the content is the same
assert(overlap(a, b).empty);

static test()() @nogc
{
    auto a = "It's three o'clock"d;
    auto b = a[5 .. 10];
    return b.overlap(a);
}

//works at compile-time
static assert(test == "three"d);

Meta