Standard ISO C++ has a rich algorithm library including plenty of syntactic sugar like std::max_element
, std::fill
, std::count
, etc.
I'm having a hard time understanding why ISO saw fit to standardize many such trivial algorithms, yet not overloads of algorithms which operate on whole containers.
I don't really understand why they added such basic things when we're left without whole container versions (surely by far the most common case) or similarly left with the atrocity that is the vector erase-remove idiom:
v.erase(std::remove(v.begin(), v.end(), elem), v.end());
It seems that every project I write in C++, I end up including my own custom header file which includes basic syntactic sugar for things like this.
Of course, any of the trivial whole-container overloads could be included in a custom header. That's also true of the many of the simple algorithms which were standardized.
What I'm trying to understand is why there's a good reason for things in the standard like std::max_element
and std::fill
on ranges, but not versions that operate on whole containers, or for other syntactic sugar that reduces the verbosity of writing C++ code.