fix issue 18804 - std.algorithm.mutation.copy puts whole source range into target range when it should put elements

This commit is contained in:
aG0aep6G 2018-04-30 03:06:02 +02:00
parent 42e9d6ffb9
commit 19052b08de

View file

@ -414,7 +414,8 @@ if (!areCopyCompatibleArrays!(SourceRange, TargetRange) &&
} }
else else
{ {
put(target, source); foreach (element; source)
put(target, element);
return target; return target;
} }
} }
@ -535,6 +536,24 @@ $(LINK2 http://en.cppreference.com/w/cpp/algorithm/copy_backward, STL's `copy_ba
}} }}
} }
@safe unittest // issue 18804
{
static struct NullSink
{
void put(E)(E) {}
}
int line = 0;
struct R
{
int front;
@property bool empty() { return line == 1; }
void popFront() { line = 1; }
}
R r;
copy(r, NullSink());
assert(line == 1);
}
/** /**
Assigns `value` to each element of input range `range`. Assigns `value` to each element of input range `range`.