einpoklum
einpoklum

Reputation: 131970

Why does std::partition not have an out-of-place variant?

std::partition is nifty, but it is in-place; and std::partition_copy is also nice, but it takes two output iterators, i.e. you have to at least count in advance the number of elements satisfying the predicate if you want to use the same output array. Why isn't there an out-of-place std::partition, or a single-output-iterator std::partition_copy, in <algorithm>?

Upvotes: 2

Views: 150

Answers (1)

Mark B
Mark B

Reputation: 96281

Presumably because the functionality can already be attained by either:

  • Copying the original container and using in-place partition.
  • Sizing the single destination container to the correct size and using the begin() and rbegin() iterators to fill it from the front and back with partition_copy.

Upvotes: 3

Related Questions