The C++ ranges API simplifies standard-library algorithms by accepting a container or range directly. Instead of spelling out begin and end iterators, supply the range and the operation to perform. section 4.6
Prefer the ranges form when it makes existing algorithm calls easier to read and maintain:
- Replace repetitive iterator-pair syntax with the container itself. section 4.6
- Combine the range with a lambda when the comparison is local and used once. section 4.6
- Use established Standard Template Library algorithms such as std::sort rather than writing equivalent functions. section 4.6
Sorting students by GPA
A student collection can be sorted with the ranges API and a comparison function, avoiding separate begin and end arguments. The result is described as more compact, readable, and straightforward than the iterator-based alternative. section 4.6

