Actions work like standard STL algorithms, but instead of using iterators as input/output, they take containers and return new modified containers.
Unlike STL algorithms, the actions of ranges modify the size of the container, that is, ranges::action::remove_if() returns a container where the elements have been erased from the container, whereas std::remove_if(...) simply returns an iterator to the last unique element and leaves it to the programmer to actually erase the elements. Same goes with std::unique; a new range containing only the unique values are returned:
Erasing duplicates using STL algorithms | Erasing duplicates using the ranges library |
auto a = std::vector<int>{ 1, 2, 1, 3, 2, 4};std::sort(a.begin(),a.end()); |