4 ms·
> They aren't, but without ranges, things that accept iterators are more general than things that accept only containers (e.g. you can't iterate over half a con
by Aardwolf 8y ago
> They aren't, but without ranges, things that accept iterators are more general than things that accept only containers (e.g. you can't iterate over half a container without a range, iterators, or copying to another container through other means defeating which would defeat the whole point.)
Yes but they could have provided both a single-container-parameter version and a two-iterator-parameter version of all those functions like sort and transform. Templates and SFINAE support that, and the single parameter one would call the two parameter one with .begin() and .end() for you.
They should try to make the std library such that you type shorter code, not longer code, imho: longer expressions are less readable. But well, it looks like ranges mostly do that for the user side (except that it uses std::ranges:: instead of just std:: as prefix) so at least that's nice.
- MaulingMonkey 8y ago> Yes but they could have provided both a single-container-parameter version and a two-iterator-parameter version of all those functions like sort and transform. For my own libraries I'd skip the iterator accepting version. Implementing one range type is way easier / less prone to oversights and other mistakes than double implementing every algorithm. Or more than double implementing, if you need perfect forwarding for non-copyable functors without std::forward pre-C++11. Even though all they do is forward. SC++L doesn't get much choice since they started with iterators only, but even there, I'm not sure how much time skipping std::range saves you. You can't even take a plain C style array without either a range type, free-form std::begin/std::end, or the iterator variant.
- deleted 8y ago[deleted]
- int_19h 8y ago> and the single parameter one would call the two parameter one with .begin() and .end() for you. Doesn't work with arrays, since they don't have member functions.