boost::range::prev_permutation

References

Headers

boost::range::prev_permutation is available by including any of the following headers:

  • boost/range/algorithm/permutation.hpp or
  • boost/range/algorithm.hpp

Examples

prev_permutation.cpp

#include <functional>
#include <iostream>
#include <boost/range/algorithm.hpp>

int main() {
    std::string s = "cba";

    // prev_permutation() generates permutations of a sequence.
    // Permutations are generated in lexicographically descending order (or in
    // descending order based on an optional binary predicate).
    // If a smaller permutation could be generated, true is returned, otherwise
    // the largest permutation is generated and false is returned.
    do {
        std::cout << s << " ";
    } while (boost::range::prev_permutation(s));

    std::cout << std::endl;
    return 0;
}

Output:

cba cab bca bac acb abc

 

Boost Range for Humans

This reference is part of Boost Range for Humans. Click the link to the overview.