Lambda expressions in combination with parameter packs can be used for complex tasks. In this section, we will implement a function object that accepts an arbitrary number of input parameters and generates the cartesian product of this set with itself.
The cartesian product is a mathematical operation. It is noted as A x B
, meaning the cartesian product of set A
and set B
. The result is another single set, which contains pairs of all item combinations of the sets A
and B
. The operation basically means, combine every item from A with every item from B. The following diagram illustrates the operation:
In the preceding diagram, if A = (x, y, z)
, and B = (1, 2, 3)
, then the cartesian product is (x, 1)
, (x, 2)
, (x, 3)
, (y, 1)
, (y, 2)
, and so on.
If we decide that A
and B
are the same set, say (1, 2)
, then the cartesian product of that is (1, 1)
, (1, 2)
, (2, 1)
, and (2, 2)
. In some cases, this might be declared redundant, because the...