h-2 / blog-comments

comment repository for my blog
1 stars 0 forks source link

A beginner's guide to C++ Ranges and Views. #6

Open h-2 opened 4 years ago

h-2 commented 4 years ago

See https://hannes.hauswedell.net/post/2019/11/30/range_intro/

mull commented 4 years ago

Great article!

I noticed a problem with the markdown inside the collapsing elements, particularly the last one named "Here is the solution". Just wanted to mention it if it had gone unnoticed so far :-)

NBJack commented 2 years ago

This is honestly the best guide I've found trying to understand Ranges and their relationship to Iterators. Great work.

I did notice a formatting issue in the code samples on my device: line numbers are appearing immediately to the left of the code. This makes it harder to read (though the change in color alleviates it).

CSS Alignment Problem - Iterators and Ranges .

an146 commented 2 years ago

Is there function like std::ranges::uniq :: range -> optional? Motivation: http://movepoint.su/anekforhire/ https://gcc.godbolt.org/z/zv8hbW45n

wxinix commented 2 years ago

Thank you for the article. Would std::views have any performance implications?

h-2 commented 2 years ago

Slowly catching up with the comments 😇


@NBJack :

This is honestly the best guide I've found trying to understand Ranges and their relationship to Iterators. Great work.

Thank you very much!

I did notice a formatting issue in the code samples on my device: line numbers are appearing immediately to the left of the code.

Yeah, I had some trouble with the blog, because I wanted rendering to happen server-side and not via javascript. This is apparently quite difficult in the modern days ™️ . I plan to update the blog system sometime soon and then also improve the code snippets.


@an146 :

Is there function like std::ranges::uniq :: range -> optional?

I am not sure what you want exactly. Are you looking for a view or are you looking for an algorithm that transforms a range into a single value (like a fold)?


@wxinix :

Thank you for the article. Would std::views have any performance implications?

Some of them do, some don't. It depends on the view and also on the type of the underlying range. In my experience, std::views::transform on top of something like a vector or array has almost no impact. The same goes for "slicing" views (take and drop). I have measured a little overhead for filter-views, but this depends also on how predictable the predicate is that you are evaluating. I wrote more on this in my thesis: https://refubium.fu-berlin.de/bitstream/handle/fub188/30952/dissertation_hauswedell_refubium_version2.pdf?sequence=3&isAllowed=y (page 166 and following).

h-2 commented 1 year ago

It took a while, but all formatting issues should be fixed (I hope).

maksverver commented 1 year ago

Very helpful post! I came here searching for the difference between C++ spans, ranges, and views, and this article explained it clearly and succinctly.

One complaint about styling though: in the table under “well-known containers from the standard library” the column headers are very hard to read. There is barely any contrast between the green background and light grey text colors.

h-2 commented 1 year ago

Very helpful post! I came here searching for the difference between C++ spans, ranges, and views, and this article explained it clearly and succinctly.

Thank you!

One complaint about styling though: in the table under “well-known containers from the standard library” the column headers are very hard to read. There is barely any contrast between the green background and light grey text colors.

Fixed it!

alexanderchuranov commented 3 weeks ago

A very useful introduction to C++ ranges! Brief and to the point. Thank you!