mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Fix Issue 21724 - std.algorithm.mutation.copy fails on overlapping arrays if the source array's pointer is less than the destination array's pointer
This commit is contained in:
parent
d3a1433921
commit
edd9007c35
1 changed files with 18 additions and 3 deletions
|
@ -374,14 +374,22 @@ if (isInputRange!SourceRange && isOutputRange!(TargetRange, ElementType!SourceRa
|
|||
assert(tlen >= slen,
|
||||
"Cannot copy a source range into a smaller target range.");
|
||||
|
||||
immutable overlaps = __ctfe || () @trusted {
|
||||
immutable overlaps = () @trusted {
|
||||
return source.ptr < target.ptr + tlen &&
|
||||
target.ptr < source.ptr + slen; }();
|
||||
|
||||
if (overlaps)
|
||||
{
|
||||
if (source.ptr < target.ptr)
|
||||
{
|
||||
foreach_reverse (idx; 0 .. slen)
|
||||
target[idx] = source[idx];
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (idx; 0 .. slen)
|
||||
target[idx] = source[idx];
|
||||
}
|
||||
return target[slen .. tlen];
|
||||
}
|
||||
else
|
||||
|
@ -507,6 +515,13 @@ $(LINK2 http://en.cppreference.com/w/cpp/algorithm/copy_backward, STL's `copy_ba
|
|||
assert(a[4 .. 9] == [6, 7, 8, 9, 10]);
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=21724
|
||||
{
|
||||
int[] a = [1, 2, 3, 4];
|
||||
copy(a[0 .. 2], a[1 .. 3]);
|
||||
assert(a == [1, 1, 2, 4]);
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=7898
|
||||
{
|
||||
enum v =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue