Template Function otyca::generate_combinations
Function Documentation
-
template<typename T>
void otyca::generate_combinations(const std::vector<std::vector<T>> &input, std::vector<std::vector<T>> &result, std::vector<T> current = {}, size_t row = 0) Generates all combinations of elements from a 2D vector.
This function generates all possible combinations of elements from a 2D vector. Each combination is formed by selecting one element from each row of the input vector. The result is stored in the
result
vector.The function uses recursion to explore all possible combinations by iterating over the elements in each row and adding them to the current combination.
- Template Parameters:
T – The type of the elements in the 2D vector (e.g., int, float).
- Parameters:
input – A 2D vector containing the input data from which combinations will be generated.
result – A 2D vector where the generated combinations will be stored.
current – A vector representing the current combination being generated. This is passed by reference during the recursion.
row – The current row being processed. It is initially 0 and increments as the recursion proceeds.