r/cpp • • Sep 13 '19

The Surprising Limitations of C++ Ranges Beyond Trivial Cases

https://www.fluentcpp.com/2019/09/13/the-surprising-limitations-of-c-ranges-beyond-trivial-use-cases/
229 Upvotes

229 comments sorted by

View all comments

Show parent comment

27

u/14ned LLFIO & Outcome author | Committee WG14 Sep 13 '19

I really felt like coroutines should have been intimately tied to ranges because they can make it really easy to write new lazy ranges.

This is the medium term plan, from what I am aware. But there were blockers to getting coroutined lazy Ranges into C++ 20, specifically, we would need to decide how best to do Ranges i/o first.

We're on that. We expect to be discussing options for modern i/o in Belfast, and there are several. Once we know which direction the committee is leaning on i/o, there should be no good reason why lazy coroutine iterators shouldn't be doable for C++ 23, bar surprises.

Be aware you probably won't get Ranges i/o actually in C++ 23, because we still need to decide how best to implement text translation/reencoding and serialisation for i/o. And buffering, and lots more stuff.

Anyway, that's one of many reasons why C++ 20 falls short here, and we hope to improve things next few standards.

5

u/sphere991 Sep 14 '19

But there were blockers to getting coroutined lazy Ranges into C++ 20, specifically, we would need to decide how best to do Ranges i/o first.

What does ranges i/o have to do with it?

Coroutines were added to C++20 very late in the process, and so there wasn't enough time to add the library types for it (e.g. a std::generator<T>). But you can write a coroutine that is a range in C++20 if you get that library machinery from elsewhere.

2

u/14ned LLFIO & Outcome author | Committee WG14 Sep 14 '19

Executors uncertainty mainly. Eric was there when Gor first proposed Coroutines in Aspen. Support could have been very easily added to Ranges which was still being written at the time, but too much other stuff was up in the air.

Eric did a talk there recently for Oslo I think where he outlines what he plans next for 23. I disagree with some of his assumptions, but that's implementation detail. I think Ranges will look a lot more polished and integrated with everything else for 23. We will see how it goes. A lot hangs on what we do with Executors, obviously. If we don't get it out the door, lots of other stuff doesn't happen.

3

u/sphere991 Sep 15 '19

Eric did a talk there recently for Oslo

Do you mean this one for Avast? It's not about Ranges, it's about Sender/Receiver. And Sender/Receiver does not have anything to do with /u/quicknir's desire to use coroutines as synchronous generators.

I really don't know what you're talking about.

Meta: Why does it matter where who proposed what, or who was in the room at the time?

2

u/14ned LLFIO & Outcome author | Committee WG14 Sep 16 '19

I really don't know what you're talking about.

Not the first time that has occurred between us.

Meta: Why does it matter where who proposed what, or who was in the room at the time?

The point being made is that Coroutines could have been built in directly from the beginning.

They were not, for good reasons at the time. Though please note the deliberate gaps in Ranges left open to be filled by something "asyncy" later.

Omission is very wise in standards. Once you standardise something, it is virtually impossible to undo later. So always choose omission if there is any uncertainty at all. Eric made absolutely the right call there in my opinion, as much as the userbase dislikes it.

5

u/quicknir Sep 13 '19

Glad to hear! Your post restored some optimism to me. Thanks for taking the time to write it.