Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library Reference Guide

partition()

Library:  Algorithms


Function

Local Index

No Entries

Summary

Algorithm that places all of the entities that satisfy the given predicate before all of the entities that do not

Synopsis

#include <algorithm>

namespace std {
  template <class BidirectionalIterator, class Predicate>
  BidirectionalIterator
  partition(BidirectionalIterator start,
            BidirectionalIterator finish,
            Predicate pred);
}

Description

For the range [start, finish), the partition() algorithm places all elements that satisfy the predicate pred before all elements that do not satisfy pred. It returns an iterator that is one past the end of the group of elements that satisfy pred. In other words, partition() returns i such that for any iterator j in the range [start, i), pred(*j) == true, and, for any iterator k in the range [i, finish), pred(*j) == false.

Note that partition() does not necessarily maintain the relative order of the elements that match and elements that do not match the predicate. Use the algorithm stable_partition() if relative order is important.

Complexity

The partition() algorithm does at most (finish - start)/2 swaps, and applies the predicate exactly finish - start times.

Example

See Also

stable_partition()

Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 25.2.12



Previous fileTop of DocumentContentsIndex pageNext file