std.range.choose: call payload postblit correctly

Fixes bugzilla issue 15708
This commit is contained in:
Paul Backus 2024-03-03 17:56:32 -05:00 committed by The Dlang Bot
parent bfe2a18389
commit 837b7deb7d

View file

@ -1882,7 +1882,7 @@ private struct ChooseResult(Ranges...)
this(this)
{
actOnChosen!((ref r) {
static if (hasElaborateCopyConstructor!(typeof(r))) r.__postblit();
static if (hasElaborateCopyConstructor!(typeof(r))) r.__xpostblit();
})(this);
}
@ -2177,6 +2177,29 @@ pure @safe nothrow unittest
assert(chosen2.front.v == 4);
}
// https://issues.dlang.org/show_bug.cgi?id=15708
@safe unittest
{
static struct HasPostblit
{
this(this) {}
}
static struct Range
{
bool empty;
int front;
void popFront() {}
HasPostblit member;
}
Range range;
int[] arr;
auto chosen = choose(true, range, arr);
auto copy = chosen;
}
/**
Choose one of multiple ranges at runtime.