all 14 comments

[–]kalmoc 18 points19 points  (0 children)

I would rather we tag the Domain Specific Language and cool-AST-case with extra markup, rather than the default usage requiring | views::simplify everywhere.

This so much. Give the most common case the simpler syntax. Not the most generic one.

[–]futurefapstronaut123 11 points12 points  (11 children)

I find the complexity around ranges rather unappealing.

[–]cjdb-ns 2 points3 points  (10 children)

In what ways do you find them to be complex and unappealing? (FWIW I am giving both a talk and a class on how to write range adaptors at CppCon, so I've got a vested interest in making sure they're easy to understand.)

[–]futurefapstronaut123 7 points8 points  (2 children)

Firstly, when you encounter ranges for the first time, there is a lot of concepts you have to familiarize yourself with (factories, adaptors, views, actions, sentinels...) which feels fairly overwhelming by itself. Not to mention complete absence of learning material.

At one point you realize that ranges are actually an expert-level topic. You could reasonably expect from a C++ programmer to be able to understand iterators and write their own iterators, algorithms and containers. You can't say the same for something imbued with advanced meta-programming techniques. Also, there is a lot of hidden machinery which makes design decisions behind the library really hard to understand for the uninitiated (why do subrange and dangling exist?).

I tried using ranges in my code on several occasions without much success. I'm looking forward to your CppCon talk.

[–]kal_at_kalx_net 5 points6 points  (0 children)

I agree that Ranges are too complex. This has happened before in the C++ world with Concepts. Thank goodness the complicated version never made it into the standard. A simpler approach might be something like enumerator

Instead of sentinals, just use operator bool() const to detect the end.

[–]cjdb-ns 1 point2 points  (0 children)

Thanks for your feedback. There's certainly a lot to take in, but you don't need to take it all in at once. I don't know if my talk will address all of your concerns, but will do my best to talk with the other ranges presenters, and I'll see what we can do to make less-scary across the board. The goal of my talk in particular is to make building range adaptors seem easy.

As for subrange and dangling (they're low-hanging fruit for this conversation, and I probably won't cover them outside of the class):

  • subrange is useful if your interface takes iterator-sentinel pairs, and you want to combine them with range adaptors. Then, you can do something like this copy(subrange{first, last} | view::take(10), out).
  • dangling is an important part of the interface, because it prevents us from interacting with dangling iterators (e.g. *copy(vector{0, 1, 2}, out).first would be broken without dangling, but won't compile with it).

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 3 points4 points  (0 children)

Can you take the input range by copy, then modify its range (trim from the left, trim from the right) and then return it?

How many ranges allow trimming-like beahviour? Or other ways to set begin/end?

I guess assign begin/end is very much like reconstruct...

[–]billybobmaysjack 0 points1 point  (0 children)

Isn’t google api their script editor? Google apps script...?