This assertion is checked only in the INDEX_CHECKS compilation mode.
Either a reference to a container whose lifetime is not shorter than that of the permutation object, or a "bare" container type for a temporary object. See also the detailed discussion.
Either a functor class satisfying the extended requirements for unary operations, or an untyped template of such a class wrapped into BuildUnary or BuildUnaryIt (preferably expressed via the convenience typedef from namespace polymake::operations.
This is a convenience function, which allows to embed a temporary object into an expression without writing down its exact type. The result is identical to a direct call to the constructor of the corresponding class with the same arguments.
Please note that this and similar convenience functions always create an object parameterized with references to the input data (containers.) Sometimes, especially in a function return statement, you will need a reference-less variant; then you have to use the constructor.
This is a convenience function, which allows to embed a temporary object into an expression without writing down its exact type. The result is identical to a direct call to the constructor of the corresponding class with the same arguments.
Either a functor class satisfying the extended requirements for binary operations, or an untyped template of such a class wrapped into BuildBinary or BuildBinaryIt (preferably expressed via the convenience typedef from namespace polymake::operations.

There is a little collection of enumeration algorithms generating objects of some class in a systematic manner. They are implemented as pseudo-containers, so that you can browse through the class exactly the same you would visit all elements of a standard list.

## Permutations

enum permutation_sequence { permutations_heap, permutations_adjacent, permutations_lex }; template <permutation_sequence kind=permutations_heap> class AllPermutations;

The "source" of all permutations of a fixed length. The elements are permutations of the integer sequence [0..n). The first permutation is always the increasing sequence 0,1,...,n-1.

You have the choice between three different algorithms.

permutations_heap deploys the Heap's generating algorithm (see Heap, B.R., "Permutations by Interchanges," Computer Journal 6 (1963) pp. 293-294), the implementation follows the suggestion of R. Sedgewick. This algorithm guarantees that each two consecutive permutations differ by interchanging exactly one pair of elements. This implies that the permutations in the sequence have alternating evenness.
permutations_adjacent is similar to the first variant, but generates the permutations by interchanging the adjacent elements only. The iterator over the sequence has an additional method next_swap(), returning the index of the right element of the pair which is going to be swapped by the next increment operator.
permutations_lex generates is based on the standard function std::next_permutation, generating the permutations in lexicographical order. This is the slowest of all algorithms.

### Construction

    #include <permutations.h>
    using namespace polymake;

AllPermutations<kind>(int n); AllPermutations<permutations_heap> all_permutations(int n); AllPermutations<kind> all_permutations<kind>(int n);
The kind of the permutation sequence must be specified as an explicit template argument, unless the default Heap's algorithm suffices your needs.

### Cyclic representation

template <typename Permutation> const PermutationCycles<Permutation>& permutation_cycles(const Permutation& perm);
Masquerades the permutation perm (which is supposed to be a dense container of integers) as a pseudo-container of cycles making up the permutation. The elements of type PermutationCycle<Permutation> are structurally equivalent to {std::list<int> } and appear in lexicographical order.

### Miscellaneous tools dealing with permutations

template <typename Permutation> int permutation_sign(const Permutation& perm);
Returns 1 if the permutation is even, -1 if odd. perm is assumed to contain integer numbers from [0..n).
template <typename Permutation, typename InvPermutation> void inverse_permutation(const Permutation& perm, InvPermutation& inv_perm);
Fills inv_perm with the permutation inverse to perm.
template <typename PermutationRef, typename Element=int> class PermutationMatrix; template <typename Element, typename Permutation> PermutationMatrix<const Permutation&, Element> permutation_matrix(const Permutation& perm);
Create a temporary sparse matrix equal to a unary matrix with columns permuted according to perm. The template parameter Element specifies the apparent type of the matrix elements; it must be specified explicitly in the convenience function call, as it can't be deduced from its argument.

### Finding a permutation between two containers

template <typename Container1, typename Container2> Array<int> find_permutation(const Container1& c1, const Container2& c2); throw (no_match); template <typename Container1, typename Container2, typename Comparator> Array<int> find_permutation(const Container1& c1, const Container2& c2, const Comparator& comparator); throw (no_match);
Finds a permutation of indices `0 .. c1.size()-1` which would convert c1 to c2. Raises an exception if no such permutation exists (due to different container sizes or an unmatched element).
The first variant uses the default comparison functor operations::cmp, the second one allows to use a non-standard comparator.

## Integral points in a cuboid

    #include <MultiDimCounter.h>
    using namespace polymake;

template <bool left_to_right=true, typename Element=int> class MultiDimCounter;

The MultiDimCounter is a bidirectional iterator, yielding all integral points in a d-dimensional cuboid. The points are represented by Array<int> objects.

The template parameter left_to_right determines whether coordinate [0] or [d-1] is the least significant (that is, changes first.) Default is true, where the counter is read from left to right and the element [0] is the least significant.

Element is the coordinate type.

MultiDimCounter implements the rewindable and end_sensitive interfaces, as well as several special methods described further.

### Construction

template <typename Container> MultiDimCounter(const Container& limits);
limits are the exclusive upper limits for coordinates in each dimension. The lower limits are assumed to be all zeroes.
template <typename Container1, typename Container2> MultiDimCounter(const Container1& start, const Container2& limits);
The same as above, but with arbitrary inclusive lower limits (start values).

### Modification

MultiDimCounter::operator++ (); MultiDimCounter::operator-- ();
Moves to the next integral point. The least significant digit (as specified by left_to_right) changes first.
template <typename Container> void set(const Container& values);
Moves the iterator to the given integral point.
New values must lie in the intervals set up during the construction.
void set_digit(int digit, Element value);
Sets the specified coordinate to the given value.
The new value must lie in the interval set up during the construction.

## Facets of a cube

    #include <CubeFacets.h>
    using namespace polymake::polytope;

template <typename Element> class CubeFacets;

This is a list of all facets of a d-dimensional cube. The facets are represented combinatorially as sets of vertex indices, the vertices are enumerated contiguously (usually from 0 to 2d-1.) During the iteration the facets do not appear in lexicographical order.

Template parameter Element specifies the type of the vertex indices. For dimensions less than the machine word size (for example, 32 on an usual PC), it can be safely chosen as int.

CubeFacets implements the forward container interface; it is a virtual container, producing its elements "on the fly" just when they are needed.

### Construction

CubeFacets(int dim, Element start=0); dim is the cube dimension, start is the index of the first vertex.