ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.11k stars 440 forks source link

concat of views over move-only type doesn’t compile #1674

Open MichaelWJung opened 2 years ago

MichaelWJung commented 2 years ago

Please consider the following example where I’m trying to concatenate two views over a move-only type:

auto v = views::ints(0, 4) |
         views::transform([](int i) { return std::make_unique<int>(i); });
auto w = views::ints(4, 8) |
         views::transform([](int i) { return std::make_unique<int>(i); });
auto x = views::concat(v, w) | to<std::vector>();

Unfortunately, this doesn’t compile for me and I can’t make much sense of the error message (see https://godbolt.org/z/TcoP8djnz).

If I change make_unique to make_shared, i.e. use a copyable type, the code compiles. Evaluating the views before concat also works:

auto v = views::ints(0, 4) |
         views::transform([](int i) { return std::make_unique<int>(i); }) |
         to<std::vector>();
auto w = views::ints(4, 8) |
         views::transform([](int i) { return std::make_unique<int>(i); }) |
         to<std::vector>();
auto x = views::concat(v | views::move, w | views::move) | to<std::vector>();

I’ve raised this before as a question on StackOverflow where a user suggested that this might be a bug in range-v3.

Is this a bug? Or am I doing something wrong here?

brevzin commented 2 years ago

Is this a bug?

Yes, this is definitely a range-v3 bug.