#include <iterator>

template<class it, class mather=std::plus<typename std::iterator_traits<it>::value_type> >
bool next_increasing(it start, it end, typename std::iterator_traits<it>::value_type limit, mather plus={}) {
    bool n = true;
    it c = std::prev(end);
    *c = plus(*c, 1);
    if (*c == limit) {
        if (c == start)
            return false;
        n = next_increasing<it>(start, c, plus(limit,-1));
        it prev = std::prev(c);
        *c = plus(*prev,1);
    }
    return n;
}
template<class it, class mather=std::plus<typename std::iterator_traits<it>::value_type> >
bool next_increasing_eq(it start, it end, typename std::iterator_traits<it>::value_type limit, mather plus={}) {
    bool n = true;
    it c = std::prev(end);
    *c = plus(*c, 1);
    if (*c == limit) {
        if (c == start)
            return false;
        n = next_increasing_eq<it>(start, c, limit);
        it prev = std::prev(c);
        *c = *prev;
    }
    return n;
}

#include <iostream>

int main() {
	int data[5] = {0,1,2,3,4};
	do {
		std::cout << data[0]<<data[1]<<data[2]<<data[3]<<data[4]<<'\n';
	}while(next_increasing(data+0,data+5,10));
}