Standard algorithms don't operate directly on containers (creating or destroying them, or changing their sizes). They operate on iterator ranges, and the only changes the algorithm make are via assignment through iterators.
So, your proposed operation is entirely outside the scope of the standard algorithms. Maybe there "should" be a large extra set of generic container-operations in the standard, including this one, but the "STL philosophy" is to operate on iterators.
The non-lazy operation you propose can be done using std::back_inserter
and std::copy_if
(optionally using move iterators) or move_if
(if you roll that yourself). std::copy_if
was missing from C++03, but that was an accidental oversight.
The lazy version can't be done just by plugging together standard components -- there's no clean way to chain the "output" of one algorithm straight into the "input" of another algorithm without intermediate storage. That's why Boost provides such an interesting variety of iterators, as well as Ranges.
I don't know why they weren't incorporated into C++11, but one thing to note about C++11 was that it was rather late. Proposals were dropped for lack of time, so the reason might be as simple as "it was never considered important enough to propose, given the known existing workload".
Regarding your particular implementation, not all containers have push_back
, and so you probably shouldn't use Container
as the template parameter name. PushBackSequence
would be more descriptive of the requirements.