Simple generic cartesian product in C++ The idea is to take a sequence of sequences (of the same type) and use tuples of [iterator, current index, sequence size] to keep track of the current state, such that the cartesian_product object can return one sequence at a time.
General questions:

bugs? (would hope not!)
code quality ok? anything i've missed?
is there a simpler way to keep track of the object state (iterators, counts, etc)
would it make sense to make this into an iterator (it could probably be bidirectional?)

Improvement ideas:

when the number of sequences is known at compile time, maybe it would be better for next() to return a tuple/static array instead of a std::vector&lt;T&gt;?
use a simple aggregate type instead of a tuple to avoid all the std::get ugliness?

Thanks a lot!
#include &lt;iostream&gt;
#include &lt;tuple&gt;
#include &lt;type_traits&gt;
#include &lt;utility&gt;
#include &lt;vector&gt;

template &lt;typename T&gt;
class cartesian_product {
public:
    template &lt;typename... Args, typename = typename std::enable_if&lt;(sizeof...(Args) &gt; 1)&gt;::type&gt;
    cartesian_product(Args&amp;&amp;... args)
        : count(1)
    {
        std::cout &lt;&lt; &quot;constructor 1\n&quot;;
        static_assert(std::is_arithmetic&lt;T&gt;::value, &quot;T must be an arithmetic type.&quot;);
        append(args...);
    }

    cartesian_product(std::vector&lt;std::vector&lt;T&gt;&gt; const&amp; sequences) 
        : count(1)
    {
        std::cout &lt;&lt; &quot;constructor 2\n&quot;;
        tuples.reserve(sequences.size());
        for(auto&amp;&amp; s : sequences) {
            tuples.emplace_back(s.cbegin(), 0ul, s.size());
            count *= s.size();
        }
    }

    cartesian_product(std::vector&lt;std::vector&lt;T&gt;&gt;&amp;&amp; sequences)
        : cartesian_product(sequences)
    {
        std::cout &lt;&lt; &quot;constructor 3\n&quot;;
    }


    bool has_next() { return count &gt; 0; }

    // next combination
    std::vector&lt;T&gt; next()
    {
        std::vector&lt;T&gt; res(tuples.size());
        auto s = res.rbegin();

        for (auto p = tuples.rbegin(); p &lt; tuples.rend(); ++p, ++s) {
            *s = *std::get&lt;0&gt;(*p);

            if (p &gt; tuples.rbegin()) {
                auto q = p - 1;
                if (std::get&lt;1&gt;(*q) == std::get&lt;2&gt;(*q)) {
                    std::get&lt;0&gt;(*q) -= std::get&lt;2&gt;(*q);
                    std::get&lt;1&gt;(*q) = 0;

                    ++std::get&lt;0&gt;(*p);
                    ++std::get&lt;1&gt;(*p);
                }
            } else {
                ++std::get&lt;0&gt;(*p);
                ++std::get&lt;1&gt;(*p);
            }
        }

        --count;
        return res;
    }

private:
    using I = typename std::vector&lt;T&gt;::const_iterator;
    using E = std::tuple&lt;I, std::size_t, std::size_t&gt;;
    std::vector&lt;E&gt; tuples;
    int count;

    template &lt;typename... Args&gt;
    void append(std::vector&lt;T&gt; const&amp; vec, Args&amp;&amp;... args)
    {
        append(vec);
        append(args...);
    }

    void append(std::vector&lt;T&gt; const&amp; vec)
    {
        count *= vec.size();
        tuples.emplace_back(std::cbegin(vec), 0ul, vec.size());
    }
};

int main(int argc, char** argv)
{
    std::vector&lt;int&gt; a { 1, 2 };
    std::vector&lt;int&gt; b { 3, 4 };
    std::vector&lt;int&gt; c { 5, 6 };
    std::vector&lt;int&gt; d { 7, 8, 9 };

    std::vector&lt;std::vector&lt;int&gt;&gt; s{ a, b, c, d };

    cartesian_product&lt;int&gt; p(a, b, c);
    cartesian_product&lt;int&gt; q(s);
    cartesian_product&lt;int&gt; r(std::vector&lt;std::vector&lt;int&gt;&gt;{ a, b, c, d });

    auto print = [](auto&amp;&amp; vec) { for (auto v : vec) std::cout &lt;&lt; v &lt;&lt; &quot; &quot;; std::cout &lt;&lt; &quot;\n&quot;; };

    while (p.has_next())
        print(p.next());

    return 0;
}
Don't limit Cartesian products to arithmetic types
You shouldn't limit your class to only allow products of vectors of a type that satisfies std::is_arithmetic. Why shouldn't I be able to do a Cartesian product of a std::string and a std::chrono::time_point for example? There is no actual multiplication involved in a Cartesian product after all.
Your class will likely force copies of vectors to be made
In this constructor:
cartesian_product(std::vector&lt;std::vector&lt;T&gt;&gt; const&amp; sequences) {...}

The parameter sequences is a reference, so you might think that this doesn't cause any copies to be made. However, that is only true if the caller already has a vector of vectors lying around. In your own example usage in main(), you have four vectors a, b, c and d, but then you create the vector of vectors s which causes a copy to be made of the four original vectors. And the following line constructs a temporary that also makes copies:
cartesian_product&lt;int&gt; r(std::vector&lt;std::vector&lt;int&gt;&gt;{ a, b, c, d });

Support more containers besides std::vector
You only support products of std::vector&lt;T&gt;, but what if I have my data in a regular array, a std::array, a std::list or any other container? Again, it is an unnecessary restriction. Try to rewrite it so any type of container works. Either have it accept a reference to a container object directly, or have it accept iterators like the STL algorithms do.
Return a tuple instead of a vector
A std::vector will allocate memory on the heap, which will impact performance. And since you know the size of the result, you can return a std::tuple instead, which has the advantage that it can be unpacked using C++17's structured bindings. Apart from that, with a std::tuple the value types of each input vector/array/etc can be different, whereas your solution requires all of them to be the same,
Add iterators to your class
Indeed, it makes sense to add iterators to your class. In fact, it already basically keeps track of everything that an iterator would do, and next() is the equivalent of an iterator's operator++(). Ideally, you want to be able to write something like:
std::vector&lt;std::string&gt; a_vector{&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;};
std::list&lt;int&gt; b_vector{4, 5, 6, 7};

for (auto [a_element, b_element]: cartesian_product(a_vector, b_vector))
    std::cout &lt;&lt; a_element &lt;&lt; &quot;, &quot; &lt;&lt; b_element &lt;&lt; &quot;\n&quot;;

And then expect the following result:
foo, 4
foo, 5
foo, 6
foo, 7
bar, 4
bar, 5
...

This also avoids the need for a has_next() function.