Class

CGAL::Combination_enumerator<CombinationElement>

Definition

The class Combination_enumerator<CombinationElement> is used to enumerate all fixed-size combinations (subsets) of a source range of elements. For example, it can enumerate all the combinations of 2 elements from the source range [3,7) (7 excluded) which gives the enumeration {3,4}, {3,5}, {3,6}, {4,5}, {4,6}, {5,6}. The source range consists of elements of type CombinationElement and is specified by its first element and the element just beyond its last one.

The template parameter should be a model of the concept CombinationElement.

Each combination is uniquely represented as an increasing sequence of elements. Thus, the combinations can be lexicographically ordered. They are enumerated in that order, so that we can talk about the first or last combination.

#include <CGAL/Combination_enumerator.h>

Creation

Combination_enumerator<CombinationElement> c ( int k, CombinationElement first, CombinationElement beyond);
This constructor initializes c to enumerate the combinations of k elements from the source range [first, beyond). The current combination is set to the first combination of the enumeration.
Precondition: 1 <= k <= beyond - first


Combination_enumerator<CombinationElement> c ( Combination_enumerator combi);
The copy constructor.

Access to the current combination

CombinationElement c [ int i ] Returns the i-th element of the current combination.
Precondition: 0 <= i < c.number_of_elements()

Access to the enumeration

int c.number_of_elements () Returns the size of the enumerated combinations (the parameter k from the class' constructor).

CombinationElement c.min_element () Returns the smallest element of the source range. (the parameter first of the class' constructor).

CombinationElement c.beyond_element () Returns the successor to the largest element of the source range (the parameter beyond of the class' constructor).

bool c.finished () Returns true if and only if all combinations have been enumerated.

Operations

void c.reset () Resets the enumerator. The current combination is set to the first one of the enumeration.

void ++ c Moves c to the next combination.

Combination_enumerator c ++ Post-incrementation. Same as the pre-incrementation above, but returns the original value of c.