Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.range.choose: call payload postblit correctly #8935

Merged
merged 1 commit into from Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 24 additions & 1 deletion std/range/package.d
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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.

Expand Down