ranges/views resources

Now that ranges/views have 'matured' with C++23 with provided functionality and DR's for the C++20 versions, IMO it is 'obvious' that ranges/views are going to be a major component of C++.

As anything other then simply replacing a std::algorithm with a ranges version requires a more detailed understanding of std::ranges/views, then learning resources are going to become crucial for this important C++ area.

As such, does anyone know of 'good' learning resources for ranges/views (I don't mean cppreference.com or individual articles) but something along the lines of either an in-depth book or similar to learncpp.com but just for ranges/views? I was hoping there might be a leanpub.com book on ranges/views (their is one for concepts) but unfortunately I can't find one for ranges.

An Idiots Guide to advanced C++ ranges/views (oxymoron?) anyone?
There is a somewhat close eBook available, though it covers more C++20 ranges:

https://leanpub.com/programming-with-cpp20

C++20 has changed the language in some very fundamental ways almost as radical as C++11 did. I guess the C++ experts who write books are more interested in either "the whole" or in Concepts.

Would a 9-minute single-webpage read work?

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

Probably not, this is an introduction, not an intermediate/advanced "idiots guide".
Probably not, this is an introduction, not an intermediate/advanced "idiots guide".


This is OK as a basic intro to ranges/views. I've come across several articles similar to this. I'd consider it as a basis for 'Chapter 1' of a ranges book. Now for the remaining nn chapters...

The book's not bad as a more in-depth intro. But it doesn't cover things like projections etc nor the additions/changes with C++23...

Bartek's blogs has several articles on ranges:
https://www.cppstories.com/2022/ranges-alg-part-one/
https://www.cppstories.com/2022/ranges-alg-part-two/
https://www.cppstories.com/2022/ranges-alg-part-three/
https://www.cppstories.com/2022/ranges-composition/
https://www.cppstories.com/2020/10/understanding-invoke.html/
https://www.cppstories.com/2023/projections-examples-ranges/

which are quite good as a starting point but IMO more explanation is needed.
Last edited on
I had found the cppstories pages in my search, and discounted mentioning them because they weren't a single article/page.

So far I haven't seen any books that touch on strictly C++23 features in any shape or form. The C++20 standard had several books available even before any compiler supported more than a minor tidbit of a taste of the new features. One or two were published even before the standard was finalized IIRC.

I'd certainly consider buying a C++23 book if it were put together by authors I know and trust to be useful from experience. But not even hack "experts" have stepped upto the challenge AFAIK, even just to cash in. It's a shame.

There are hints that may change in the future, I hope we don't have to wait too long.

A github repository for a C++20 book's source code had some updates a few months back, and a note in one of the READMEs that mentioned in passing something about C++23. Any trace of that is no longer available it seems.
To be perfectly honest I am still trying to wrap my brain around what C++20 added to the programming toolbox. C++23 is still "over the horizon" for me in my tasks of self-learning what I can do. The formatting library and modules I use a lot when doing so would be useful.

Concepts and ranges are still a mystery for the most part to me. I grasp why the features can be useful, but haven't spent any time mucking around with them beyond an occasional cppreference code example, or some programming blog write-up.

Reverse for loops, for example. Nice and neat reversed range-based for loops using a std::ranges::views or std::views range adaptor.

https://www.fluentcpp.com/2020/02/11/reverse-for-loops-in-cpp/

It's a shame Jonathan Boccara seems to have dropped off the face of the Earth since mid-2022.
It's a shame Jonathan Boccara seems to have dropped off the face of the Earth since mid-2022.


I've heard that he changed jobs round about then - but that's all I was told...

I came across this nice 1 liner:

1
2
3
std::map<std::string, int> m;

const auto maxsize {(*(std::ranges::max_element(std::views::keys(m), {}, std::string::length))).length()};


whow... Obtains the maximum number of chars in the key of the std::map m
Last edited on
I've heard that he changed jobs round about then - but that's all I was told...

If true that does kinda help 'splain the lack of blog updates since mid-2022.

IMO compact code has certain advantages, but for me that bit of squashed code is nigh incomprehensible without a lot of skull overheating.
Topic archived. No new replies allowed.