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

ranges::back is really hard to use #1590

Open TheThief opened 3 years ago

TheThief commented 3 years ago

It doesn't seem to work with any_view, even if sized and random_access categories are both specified. Note: any_view::back() does not work in this case either, which it probably should.

Using views::common on an any_view to circumvent the restriction that it must be a common range, my_sized_random_any_view | ranges::views::common | ranges::back does not compile. However, (my_sized_random_any_view | ranges::views::common).back() works.

Similarly, if I instead make my function a template instead of using any_view, calling it with a single ranges::sliding_view (so the type of my_range is sliding_view instead of any_view), then again my_range | ranges::back does not work but my_range.back() does.

ranges::back should probably work in the same conditions view_interface::back does. Additionally, it would be nice if any_view::back() worked for any_view with random_access | sized category.