I\'m wondering why the STL doesn\'t overload their algorithm functions such that I can call them by simply providing a container and not taking the more verbose way to pass
Obviously, as other users mentioned, it's a tricky problem, so unfortunately it's been a long time and there's still no solution in the standard library. There are, however, already range libraries available such as Boost::Range and the one in the Adobe Source Libraries that provide not only the simplicity of the interface you describe in your question, but some fancier features as well.
Your example works perfectly with Boost (we are using namespace boost::range::adaptors
below):
boost::for_each(myVector, doSomething);
We can also slice myVector
quickly and easily:
boost::for_each(myVector | sliced(10, 20), doSomething)
We can even zip myVector
with another, filter by a predicate, and sample every other element of the resulting pairs in a single, simple statement (this requires that you unpack in doSomethingElse the tuples produced by boost::combined
):
boost::for_each(
boost::combined(myVector, myOtherVector) | strided(2), doSomethingElse)