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

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

Messages

Date: 2024-03-15.00:00:00

[ 2024-03-19; Tokyo: feedback from SG9 ]

SG9 believe that LWG3971 is a use-after-move and is working as intended. We further believe that matching the behavior of `concat_view` (which is the current behavior) is important. This is not a defect.

Date: 2023-10-15.00:00:00

[ 2023-10-30; Reflector poll ]

Set priority to 3 after reflector poll. Send to SG9.

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
2024-03-19 07:22:44adminsetmessages: + msg14021
2023-10-30 16:39:42adminsetmessages: + msg13786
2023-10-30 16:39:42adminsetstatus: new -> open
2023-08-21 00:00:00admincreate