fenbf / cppstories-discussions

4 stars 1 forks source link

2023/cpp20-understanding-views-impl/ #125

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Understanding Ranges Views and View Adaptors Objects in C++20/C++23 - C++ Stories

In this article, we’d shed some light on the implementation of ranges::reverse_view and std::views::reverse. We’ll compare them to understand the differences between views and their adaptor objects. Let’s jump in. ranges::reverse_view and std::views::reverse in Action   Let’s look at an example to understand how these views work. Assume we have a range r of integers from 1 to 5.

https://www.cppstories.com/2023/cpp20-understanding-views-impl/

2kaud commented 1 year ago

Confucius says "Life is really simple, but we insist on making it complicated" ...

2kaud commented 1 year ago

I remember this simply as 'if using | then use std::views else use std::ranges::xxx_view'

rmerriam commented 1 year ago

Reading the range.adaptor section of the C++ standard is interesting because it lays out all the options a has available before it invokes the underlying algorithm.

roibarkan commented 1 year ago

Very nice post. I think many’s people are unaware of subrange and subrange_kind. In particular, views::split and views::chunk_by make use of subrange, and I personally think should also allow their caller to specify their subrange_kind. Does anyone think it’s worth writing a wg21 paper on this?

VioletGiraffe commented 1 year ago

This is extremely confusing and difficult to remember (let alone - to understand). I was looking forward to ranges, but now that they're finally here you can't use them without help from ChatGPT or StackOverflow. Not a good design.