View source code
Display the source code in std/array.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.array.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.
CommonType!(T[],U[]) overlap(T, U)
(
T[] a,
U[] b
) @trusted
if (is(typeof(a .ptr < b .ptr) == bool));
Parameters
Name | Description |
---|---|
a | The first array to compare |
b | The second array to compare |
Returns
The overlapping portion of the two arrays.
Example
int[] a = [ 10, 11, 12, 13, 14 ];
int[] b = a[1 .. 3];
writeln(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);
Authors
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.