#include <iostream>
#include <vector>

bool increment(std::vector<std::size_t>& v, std::size_t maxSize)
{
    for (auto it = v.rbegin(); it != v.rend(); ++it) {
        ++*it;
        if (*it != maxSize) {
            return true;
        }
        *it = 0;
    }
    return false;
}

void print(const std::vector<int>&v, const std::vector<std::size_t>& indexes)
{
    const char* sep = "";
    for (auto index : indexes) {
        std::cout << sep << v[index];
        sep = ".";
    }
    std::cout << std::endl;
}

void print_cartesian_product(const std::vector<int>&v, int n)
{
    std::vector<std::size_t> indexes(n);
    
    do {
        print(v, indexes);
    } while (increment(indexes, v.size()));
    
}

int main()
{
    print_cartesian_product({4, 8, 42}, 3);
}