This is a significantly faster version of combn. For an integer vector x of length 1000 and m of 3 which results in a matrix of size 3 x 166,167,000, the speed improvement is about 9 times (11 secs vs 99 secs). This code is written using Armadillo C++ and 64 bit unsingned integers.