Title
Join ranges of rvalue references with ranges of prvalues
Status
new
Section
[range.join.with.view]
Submitter
Hewill Kang

Created on 2023-08-21.00:00:00 last changed 1 month ago

Messages

Date: 2023-08-21.00:00:00

The issue that concat_view implicitly breaks equality-preserving by concatenating range of references with range of prvalues seems to be reflected in join_view as well.

When the reference of the inner range is string&& and the reference of the pattern range is prvalue string, dereferencing its iterator will move the elements of the inner range to the returned string, which makes the second dereference get an empty string (demo):

vector v1{"hello"s};
vector v2{"world"s};
vector v{v1 | views::as_rvalue, v2 | views::as_rvalue};
auto pattern = views::iota(0, 1) | views::transform([](int) { return ", "s; });
ranges::forward_range auto joined = v | views::join_with(pattern);
fmt::print("{}\n", joined); // ["hello", ", ", "world"]
fmt::print("{}\n", joined); // ["", ", ", ""]

Not sure if we should ban such less common case.

History
Date User Action Args
2023-08-21 00:00:00admincreate