Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
next_permutation
Prototype

template<class BidirectionalRange>
bool next_permutation(BidirectionalRange& rng);

template<class BidirectionalRange>
bool next_permutation(const BidirectionalRange& rng);

template<class BidirectionalRange, class Compare>
bool next_permutation(BidirectionalRange& rng, Compare pred);

template<class BidirectionalRange, class Compare>
bool next_permutation(const BidirectionalRange& rng, Compare pred);

Description

next_permutation transforms the range of elements rng into the lexicographically next greater permutation of the elements if such a permutation exists. If one does not exist then the range is transformed into the lexicographically smallest permutation and false is returned. true is returned when the next greater permutation is successfully generated.

The ordering relationship is determined by using operator< in the non-predicate versions, and by evaluating pred in the predicate versions.

Definition

Defined in the header file boost/range/algorithm/permutation.hpp

Requirements

For the non-predicate versions:

For the predicate versions:

Complexity

Linear. At most distance(rng) / 2 swaps.


PrevUpHomeNext